1 // Copyright 2012 Google Inc. All Rights Reserved.
3 // This code is licensed under the same terms as WebM:
4 // Software License Agreement: http://www.webmproject.org/license/software/
5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/
6 // -----------------------------------------------------------------------------
8 // Lossless decoder: internal header.
10 // Author: Skal (pascal.massimino@gmail.com)
11 // Vikas Arora(vikaas.arora@gmail.com)
13 #ifndef WEBP_DEC_VP8LI_H_
14 #define WEBP_DEC_VP8LI_H_
16 #include <string.h> // for memcpy()
18 #include "../utils/bit_reader.h"
19 #include "../utils/color_cache.h"
20 #include "../utils/huffman.h"
21 #include "../webp/format_constants.h"
23 #if defined(__cplusplus) || defined(c_plusplus)
33 typedef struct VP8LTransform VP8LTransform;
34 struct VP8LTransform {
35 VP8LImageTransformType type_; // transform type.
36 int bits_; // subsampling bits defining transform window.
37 int xsize_; // transform window X index.
38 int ysize_; // transform window Y index.
39 uint32_t *data_; // transform data.
43 HuffmanTree htrees_[HUFFMAN_CODES_PER_META_CODE];
47 int color_cache_size_;
48 VP8LColorCache color_cache_;
51 int huffman_subsample_bits_;
53 uint32_t *huffman_image_;
54 int num_htree_groups_;
55 HTreeGroup *htree_groups_;
59 VP8StatusCode status_;
60 VP8LDecodeState action_;
61 VP8LDecodeState state_;
64 const WebPDecBuffer *output_; // shortcut to io->opaque->output
66 uint32_t *pixels_; // Internal data: either uint8_t* for alpha
67 // or uint32_t* for BGRA.
68 uint32_t *argb_cache_; // Scratch buffer for temporary BGRA storage.
74 int last_row_; // last input row decoded so far.
75 int last_out_row_; // last row output so far.
80 VP8LTransform transforms_[NUM_TRANSFORMS];
81 // or'd bitset storing the transforms types.
82 uint32_t transforms_seen_;
84 uint8_t *rescaler_memory; // Working memory for rescaling work.
85 WebPRescaler *rescaler; // Common rescaler for all channels.
88 //------------------------------------------------------------------------------
89 // internal functions. Not public.
93 // Decodes a raw image stream (without header) and store the alpha data
94 // into *output, which must be of size width x height. Returns false in case
96 int VP8LDecodeAlphaImageStream(int width, int height, const uint8_t* const data,
97 size_t data_size, uint8_t* const output);
99 // Allocates and initialize a new lossless decoder instance.
100 VP8LDecoder* VP8LNew(void);
102 // Decodes the image header. Returns false in case of error.
103 int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io);
105 // Decodes an image. It's required to decode the lossless header before calling
106 // this function. Returns false in case of error, with updated dec->status_.
107 int VP8LDecodeImage(VP8LDecoder* const dec);
109 // Resets the decoder in its initial state, reclaiming memory.
110 // Preserves the dec->status_ value.
111 void VP8LClear(VP8LDecoder* const dec);
113 // Clears and deallocate a lossless decoder instance.
114 void VP8LDelete(VP8LDecoder* const dec);
116 //------------------------------------------------------------------------------
118 #if defined(__cplusplus) || defined(c_plusplus)
122 #endif /* WEBP_DEC_VP8LI_H_ */