1 // Copyright 2012 Google Inc. All Rights Reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the COPYING file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 // -----------------------------------------------------------------------------
10 // Lossless decoder: internal header.
12 // Author: Skal (pascal.massimino@gmail.com)
13 // Vikas Arora(vikaas.arora@gmail.com)
15 #ifndef WEBP_DEC_VP8LI_H_
16 #define WEBP_DEC_VP8LI_H_
18 #include <string.h> // for memcpy()
20 #include "../utils/bit_reader.h"
21 #include "../utils/color_cache.h"
22 #include "../utils/huffman.h"
34 typedef struct VP8LTransform VP8LTransform
;
35 struct VP8LTransform
{
36 VP8LImageTransformType type_
; // transform type.
37 int bits_
; // subsampling bits defining transform window.
38 int xsize_
; // transform window X index.
39 int ysize_
; // transform window Y index.
40 uint32_t *data_
; // transform data.
44 int color_cache_size_
;
45 VP8LColorCache color_cache_
;
48 int huffman_subsample_bits_
;
50 uint32_t *huffman_image_
;
51 int num_htree_groups_
;
52 HTreeGroup
*htree_groups_
;
55 typedef struct VP8LDecoder VP8LDecoder
;
57 VP8StatusCode status_
;
58 VP8LDecodeState action_
;
59 VP8LDecodeState state_
;
62 const WebPDecBuffer
*output_
; // shortcut to io->opaque->output
64 uint32_t *pixels_
; // Internal data: either uint8_t* for alpha
65 // or uint32_t* for BGRA.
66 uint32_t *argb_cache_
; // Scratch buffer for temporary BGRA storage.
72 int last_row_
; // last input row decoded so far.
73 int last_pixel_
; // last pixel decoded so far. However, it may
74 // not be transformed, scaled and
75 // color-converted yet.
76 int last_out_row_
; // last row output so far.
81 VP8LTransform transforms_
[NUM_TRANSFORMS
];
82 // or'd bitset storing the transforms types.
83 uint32_t transforms_seen_
;
85 uint8_t *rescaler_memory
; // Working memory for rescaling work.
86 WebPRescaler
*rescaler
; // Common rescaler for all channels.
89 //------------------------------------------------------------------------------
90 // internal functions. Not public.
92 struct ALPHDecoder
; // Defined in dec/alphai.h.
96 // Decodes image header for alpha data stored using lossless compression.
97 // Returns false in case of error.
98 int VP8LDecodeAlphaHeader(struct ALPHDecoder
* const alph_dec
,
99 const uint8_t* const data
, size_t data_size
,
100 uint8_t* const output
);
102 // Decodes *at least* 'last_row' rows of alpha. If some of the initial rows are
103 // already decoded in previous call(s), it will resume decoding from where it
105 // Returns false in case of bitstream error.
106 int VP8LDecodeAlphaImageStream(struct ALPHDecoder
* const alph_dec
,
109 // Allocates and initialize a new lossless decoder instance.
110 VP8LDecoder
* VP8LNew(void);
112 // Decodes the image header. Returns false in case of error.
113 int VP8LDecodeHeader(VP8LDecoder
* const dec
, VP8Io
* const io
);
115 // Decodes an image. It's required to decode the lossless header before calling
116 // this function. Returns false in case of error, with updated dec->status_.
117 int VP8LDecodeImage(VP8LDecoder
* const dec
);
119 // Resets the decoder in its initial state, reclaiming memory.
120 // Preserves the dec->status_ value.
121 void VP8LClear(VP8LDecoder
* const dec
);
123 // Clears and deallocate a lossless decoder instance.
124 void VP8LDelete(VP8LDecoder
* const dec
);
126 //------------------------------------------------------------------------------
132 #endif /* WEBP_DEC_VP8LI_H_ */