New comit of SDL2
[supertux.git] / src / SDL2 / external / libwebp-0.3.0 / src / dec / vp8li.h
1 // Copyright 2012 Google Inc. All Rights Reserved.
2 //
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 // -----------------------------------------------------------------------------
7 //
8 // Lossless decoder: internal header.
9 //
10 // Author: Skal (pascal.massimino@gmail.com)
11 //         Vikas Arora(vikaas.arora@gmail.com)
12
13 #ifndef WEBP_DEC_VP8LI_H_
14 #define WEBP_DEC_VP8LI_H_
15
16 #include <string.h>     // for memcpy()
17 #include "./webpi.h"
18 #include "../utils/bit_reader.h"
19 #include "../utils/color_cache.h"
20 #include "../utils/huffman.h"
21 #include "../webp/format_constants.h"
22
23 #if defined(__cplusplus) || defined(c_plusplus)
24 extern "C" {
25 #endif
26
27 typedef enum {
28   READ_DATA = 0,
29   READ_HDR = 1,
30   READ_DIM = 2
31 } VP8LDecodeState;
32
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.
40 };
41
42 typedef struct {
43   HuffmanTree htrees_[HUFFMAN_CODES_PER_META_CODE];
44 } HTreeGroup;
45
46 typedef struct {
47   int             color_cache_size_;
48   VP8LColorCache  color_cache_;
49
50   int             huffman_mask_;
51   int             huffman_subsample_bits_;
52   int             huffman_xsize_;
53   uint32_t       *huffman_image_;
54   int             num_htree_groups_;
55   HTreeGroup     *htree_groups_;
56 } VP8LMetadata;
57
58 typedef struct {
59   VP8StatusCode    status_;
60   VP8LDecodeState  action_;
61   VP8LDecodeState  state_;
62   VP8Io           *io_;
63
64   const WebPDecBuffer *output_;    // shortcut to io->opaque->output
65
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.
69
70   VP8LBitReader    br_;
71
72   int              width_;
73   int              height_;
74   int              last_row_;      // last input row decoded so far.
75   int              last_out_row_;  // last row output so far.
76
77   VP8LMetadata     hdr_;
78
79   int              next_transform_;
80   VP8LTransform    transforms_[NUM_TRANSFORMS];
81   // or'd bitset storing the transforms types.
82   uint32_t         transforms_seen_;
83
84   uint8_t         *rescaler_memory;  // Working memory for rescaling work.
85   WebPRescaler    *rescaler;         // Common rescaler for all channels.
86 } VP8LDecoder;
87
88 //------------------------------------------------------------------------------
89 // internal functions. Not public.
90
91 // in vp8l.c
92
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
95 // of error.
96 int VP8LDecodeAlphaImageStream(int width, int height, const uint8_t* const data,
97                                size_t data_size, uint8_t* const output);
98
99 // Allocates and initialize a new lossless decoder instance.
100 VP8LDecoder* VP8LNew(void);
101
102 // Decodes the image header. Returns false in case of error.
103 int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io);
104
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);
108
109 // Resets the decoder in its initial state, reclaiming memory.
110 // Preserves the dec->status_ value.
111 void VP8LClear(VP8LDecoder* const dec);
112
113 // Clears and deallocate a lossless decoder instance.
114 void VP8LDelete(VP8LDecoder* const dec);
115
116 //------------------------------------------------------------------------------
117
118 #if defined(__cplusplus) || defined(c_plusplus)
119 }    // extern "C"
120 #endif
121
122 #endif  /* WEBP_DEC_VP8LI_H_ */