Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: third_party/libwebp/webp/decode.h

Issue 10832153: libwebp: update snapshot to v0.2.0-rc1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2010 Google Inc. 1 // Copyright 2010 Google Inc. All Rights Reserved.
2 // 2 //
3 // This code is licensed under the same terms as WebM: 3 // This code is licensed under the same terms as WebM:
4 // Software License Agreement: http://www.webmproject.org/license/software/ 4 // Software License Agreement: http://www.webmproject.org/license/software/
5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/
6 // ----------------------------------------------------------------------------- 6 // -----------------------------------------------------------------------------
7 // 7 //
8 // Main decoding functions for WEBP images. 8 // Main decoding functions for WebP images.
9 // 9 //
10 // Author: Skal (pascal.massimino@gmail.com) 10 // Author: Skal (pascal.massimino@gmail.com)
11 11
12 #ifndef WEBP_WEBP_DECODE_H_ 12 #ifndef WEBP_WEBP_DECODE_H_
13 #define WEBP_WEBP_DECODE_H_ 13 #define WEBP_WEBP_DECODE_H_
14 14
15 #include "./types.h" 15 #include "./types.h"
16 16
17 #if defined(__cplusplus) || defined(c_plusplus) 17 #if defined(__cplusplus) || defined(c_plusplus)
18 extern "C" { 18 extern "C" {
19 #endif 19 #endif
20 20
21 #define WEBP_DECODER_ABI_VERSION 0x0002 21 #define WEBP_DECODER_ABI_VERSION 0x0200 // MAJOR(8b) + MINOR(8b)
22 22
23 // Return the decoder's version number, packed in hexadecimal using 8bits for 23 // Return the decoder's version number, packed in hexadecimal using 8bits for
24 // each of major/minor/revision. E.g: v2.5.7 is 0x020507. 24 // each of major/minor/revision. E.g: v2.5.7 is 0x020507.
25 WEBP_EXTERN(int) WebPGetDecoderVersion(void); 25 WEBP_EXTERN(int) WebPGetDecoderVersion(void);
26 26
27 // Retrieve basic header information: width, height. 27 // Retrieve basic header information: width, height.
28 // This function will also validate the header and return 0 in 28 // This function will also validate the header and return 0 in
29 // case of formatting error. 29 // case of formatting error.
30 // Pointers *width/*height can be passed NULL if deemed irrelevant. 30 // Pointers 'width' and 'height' can be passed NULL if deemed irrelevant.
31 WEBP_EXTERN(int) WebPGetInfo(const uint8_t* data, uint32_t data_size, 31 WEBP_EXTERN(int) WebPGetInfo(const uint8_t* data, size_t data_size,
32 int* width, int* height); 32 int* width, int* height);
33 33
34 // Decodes WEBP images pointed to by *data and returns RGB samples, along 34 // Decodes WebP images pointed to by 'data' and returns RGBA samples, along
35 // with the dimensions in *width and *height. 35 // with the dimensions in *width and *height. The ordering of samples in
36 // memory is R, G, B, A, R, G, B, A... in scan order (endian-independent).
36 // The returned pointer should be deleted calling free(). 37 // The returned pointer should be deleted calling free().
37 // Returns NULL in case of error. 38 // Returns NULL in case of error.
38 WEBP_EXTERN(uint8_t*) WebPDecodeRGB(const uint8_t* data, uint32_t data_size, 39 WEBP_EXTERN(uint8_t*) WebPDecodeRGBA(const uint8_t* data, size_t data_size,
40 int* width, int* height);
41
42 // Same as WebPDecodeRGBA, but returning A, R, G, B, A, R, G, B... ordered data.
43 WEBP_EXTERN(uint8_t*) WebPDecodeARGB(const uint8_t* data, size_t data_size,
44 int* width, int* height);
45
46 // Same as WebPDecodeRGBA, but returning B, G, R, A, B, G, R, A... ordered data.
47 WEBP_EXTERN(uint8_t*) WebPDecodeBGRA(const uint8_t* data, size_t data_size,
48 int* width, int* height);
49
50 // Same as WebPDecodeRGBA, but returning R, G, B, R, G, B... ordered data.
51 // If the bitstream contains transparency, it is ignored.
52 WEBP_EXTERN(uint8_t*) WebPDecodeRGB(const uint8_t* data, size_t data_size,
39 int* width, int* height); 53 int* width, int* height);
40 54
41 // Same as WebPDecodeRGB, but returning RGBA data. 55 // Same as WebPDecodeRGB, but returning B, G, R, B, G, R... ordered data.
42 WEBP_EXTERN(uint8_t*) WebPDecodeRGBA(const uint8_t* data, uint32_t data_size, 56 WEBP_EXTERN(uint8_t*) WebPDecodeBGR(const uint8_t* data, size_t data_size,
43 int* width, int* height); 57 int* width, int* height);
44 58
45 // Same as WebPDecodeRGBA, but returning ARGB data.
46 WEBP_EXTERN(uint8_t*) WebPDecodeARGB(const uint8_t* data, uint32_t data_size,
47 int* width, int* height);
48 59
49 // This variant decode to BGR instead of RGB. 60 // Decode WebP images pointed to by 'data' to Y'UV format(*). The pointer
50 WEBP_EXTERN(uint8_t*) WebPDecodeBGR(const uint8_t* data, uint32_t data_size, 61 // returned is the Y samples buffer. Upon return, *u and *v will point to
51 int* width, int* height); 62 // the U and V chroma data. These U and V buffers need NOT be free()'d,
52 // This variant decodes to BGRA instead of RGBA. 63 // unlike the returned Y luma one. The dimension of the U and V planes
53 WEBP_EXTERN(uint8_t*) WebPDecodeBGRA(const uint8_t* data, uint32_t data_size, 64 // are both (*width + 1) / 2 and (*height + 1)/ 2.
54 int* width, int* height);
55
56 // Decode WEBP images stored in *data in Y'UV format(*). The pointer returned is
57 // the Y samples buffer. Upon return, *u and *v will point to the U and V
58 // chroma data. These U and V buffers need NOT be free()'d, unlike the returned
59 // Y luma one. The dimension of the U and V planes are both (*width + 1) / 2
60 // and (*height + 1)/ 2.
61 // Upon return, the Y buffer has a stride returned as '*stride', while U and V 65 // Upon return, the Y buffer has a stride returned as '*stride', while U and V
62 // have a common stride returned as '*uv_stride'. 66 // have a common stride returned as '*uv_stride'.
63 // Return NULL in case of error. 67 // Return NULL in case of error.
64 // (*) Also named Y'CbCr. See: http://en.wikipedia.org/wiki/YCbCr 68 // (*) Also named Y'CbCr. See: http://en.wikipedia.org/wiki/YCbCr
65 WEBP_EXTERN(uint8_t*) WebPDecodeYUV(const uint8_t* data, uint32_t data_size, 69 WEBP_EXTERN(uint8_t*) WebPDecodeYUV(const uint8_t* data, size_t data_size,
66 int* width, int* height, 70 int* width, int* height,
67 uint8_t** u, uint8_t** v, 71 uint8_t** u, uint8_t** v,
68 int* stride, int* uv_stride); 72 int* stride, int* uv_stride);
69 73
70 // These five functions are variants of the above ones, that decode the image 74 // These five functions are variants of the above ones, that decode the image
71 // directly into a pre-allocated buffer 'output_buffer'. The maximum storage 75 // directly into a pre-allocated buffer 'output_buffer'. The maximum storage
72 // available in this buffer is indicated by 'output_buffer_size'. If this 76 // available in this buffer is indicated by 'output_buffer_size'. If this
73 // storage is not sufficient (or an error occurred), NULL is returned. 77 // storage is not sufficient (or an error occurred), NULL is returned.
74 // Otherwise, output_buffer is returned, for convenience. 78 // Otherwise, output_buffer is returned, for convenience.
75 // The parameter 'output_stride' specifies the distance (in bytes) 79 // The parameter 'output_stride' specifies the distance (in bytes)
76 // between scanlines. Hence, output_buffer_size is expected to be at least 80 // between scanlines. Hence, output_buffer_size is expected to be at least
77 // output_stride x picture-height. 81 // output_stride x picture-height.
82 WEBP_EXTERN(uint8_t*) WebPDecodeRGBAInto(
83 const uint8_t* data, size_t data_size,
84 uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
85 WEBP_EXTERN(uint8_t*) WebPDecodeARGBInto(
86 const uint8_t* data, size_t data_size,
87 uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
88 WEBP_EXTERN(uint8_t*) WebPDecodeBGRAInto(
89 const uint8_t* data, size_t data_size,
90 uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
91
92 // RGB and BGR variants. Here too the transparency information, if present,
93 // will be dropped and ignored.
78 WEBP_EXTERN(uint8_t*) WebPDecodeRGBInto( 94 WEBP_EXTERN(uint8_t*) WebPDecodeRGBInto(
79 const uint8_t* data, uint32_t data_size, 95 const uint8_t* data, size_t data_size,
80 uint8_t* output_buffer, int output_buffer_size, int output_stride); 96 uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
81 WEBP_EXTERN(uint8_t*) WebPDecodeRGBAInto(
82 const uint8_t* data, uint32_t data_size,
83 uint8_t* output_buffer, int output_buffer_size, int output_stride);
84 WEBP_EXTERN(uint8_t*) WebPDecodeARGBInto(
85 const uint8_t* data, uint32_t data_size,
86 uint8_t* output_buffer, int output_buffer_size, int output_stride);
87 // BGR variants
88 WEBP_EXTERN(uint8_t*) WebPDecodeBGRInto( 97 WEBP_EXTERN(uint8_t*) WebPDecodeBGRInto(
89 const uint8_t* data, uint32_t data_size, 98 const uint8_t* data, size_t data_size,
90 uint8_t* output_buffer, int output_buffer_size, int output_stride); 99 uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
91 WEBP_EXTERN(uint8_t*) WebPDecodeBGRAInto(
92 const uint8_t* data, uint32_t data_size,
93 uint8_t* output_buffer, int output_buffer_size, int output_stride);
94 100
95 // WebPDecodeYUVInto() is a variant of WebPDecodeYUV() that operates directly 101 // WebPDecodeYUVInto() is a variant of WebPDecodeYUV() that operates directly
96 // into pre-allocated luma/chroma plane buffers. This function requires the 102 // into pre-allocated luma/chroma plane buffers. This function requires the
97 // strides to be passed: one for the luma plane and one for each of the 103 // strides to be passed: one for the luma plane and one for each of the
98 // chroma ones. The size of each plane buffer is passed as 'luma_size', 104 // chroma ones. The size of each plane buffer is passed as 'luma_size',
99 // 'u_size' and 'v_size' respectively. 105 // 'u_size' and 'v_size' respectively.
100 // Pointer to the luma plane ('*luma') is returned or NULL if an error occurred 106 // Pointer to the luma plane ('*luma') is returned or NULL if an error occurred
101 // during decoding (or because some buffers were found to be too small). 107 // during decoding (or because some buffers were found to be too small).
102 WEBP_EXTERN(uint8_t*) WebPDecodeYUVInto( 108 WEBP_EXTERN(uint8_t*) WebPDecodeYUVInto(
103 const uint8_t* data, uint32_t data_size, 109 const uint8_t* data, size_t data_size,
104 uint8_t* luma, int luma_size, int luma_stride, 110 uint8_t* luma, size_t luma_size, int luma_stride,
105 uint8_t* u, int u_size, int u_stride, 111 uint8_t* u, size_t u_size, int u_stride,
106 uint8_t* v, int v_size, int v_stride); 112 uint8_t* v, size_t v_size, int v_stride);
107 113
108 //------------------------------------------------------------------------------ 114 //------------------------------------------------------------------------------
109 // Output colorspaces and buffer 115 // Output colorspaces and buffer
110 116
111 // Colorspaces 117 // Colorspaces
118 // Note: the naming describes the byte-ordering of packed samples in memory.
119 // For instance, MODE_BGRA relates to samples ordered as B,G,R,A,B,G,R,A,...
120 // Non-capital names (e.g.:MODE_Argb) relates to pre-multiplied RGB channels.
121 // RGB-565 and RGBA-4444 are also endian-agnostic and byte-oriented.
112 typedef enum { MODE_RGB = 0, MODE_RGBA = 1, 122 typedef enum { MODE_RGB = 0, MODE_RGBA = 1,
113 MODE_BGR = 2, MODE_BGRA = 3, 123 MODE_BGR = 2, MODE_BGRA = 3,
114 MODE_ARGB = 4, MODE_RGBA_4444 = 5, 124 MODE_ARGB = 4, MODE_RGBA_4444 = 5,
115 MODE_RGB_565 = 6, 125 MODE_RGB_565 = 6,
126 // RGB-premultiplied transparent modes (alpha value is preserved)
127 MODE_rgbA = 7,
128 MODE_bgrA = 8,
129 MODE_Argb = 9,
130 MODE_rgbA_4444 = 10,
116 // YUV modes must come after RGB ones. 131 // YUV modes must come after RGB ones.
117 MODE_YUV = 7, MODE_YUVA = 8, // yuv 4:2:0 132 MODE_YUV = 11, MODE_YUVA = 12, // yuv 4:2:0
118 MODE_LAST = 9 133 MODE_LAST = 13
119 } WEBP_CSP_MODE; 134 } WEBP_CSP_MODE;
120 135
121 // Generic structure for describing the sample buffer. 136 // Some useful macros:
137 static WEBP_INLINE int WebPIsPremultipliedMode(WEBP_CSP_MODE mode) {
138 return (mode == MODE_rgbA || mode == MODE_bgrA || mode == MODE_Argb ||
139 mode == MODE_rgbA_4444);
140 }
141
142 static WEBP_INLINE int WebPIsAlphaMode(WEBP_CSP_MODE mode) {
143 return (mode == MODE_RGBA || mode == MODE_BGRA || mode == MODE_ARGB ||
144 mode == MODE_RGBA_4444 || mode == MODE_YUVA ||
145 WebPIsPremultipliedMode(mode));
146 }
147
148 static WEBP_INLINE int WebPIsRGBMode(WEBP_CSP_MODE mode) {
149 return (mode < MODE_YUV);
150 }
151
152 //------------------------------------------------------------------------------
153 // WebPDecBuffer: Generic structure for describing the output sample buffer.
154
122 typedef struct { // view as RGBA 155 typedef struct { // view as RGBA
123 uint8_t* rgba; // pointer to RGBA samples 156 uint8_t* rgba; // pointer to RGBA samples
124 int stride; // stride in bytes from one scanline to the next. 157 int stride; // stride in bytes from one scanline to the next.
125 size_t size; // total size of the *rgba buffer. 158 size_t size; // total size of the *rgba buffer.
126 } WebPRGBABuffer; 159 } WebPRGBABuffer;
127 160
128 typedef struct { // view as YUVA 161 typedef struct { // view as YUVA
129 uint8_t* y, *u, *v, *a; // pointer to luma, chroma U/V, alpha samples 162 uint8_t* y, *u, *v, *a; // pointer to luma, chroma U/V, alpha samples
130 int y_stride; // luma stride 163 int y_stride; // luma stride
131 int u_stride, v_stride; // chroma strides 164 int u_stride, v_stride; // chroma strides
132 int a_stride; // alpha stride 165 int a_stride; // alpha stride
133 size_t y_size; // luma plane size 166 size_t y_size; // luma plane size
134 size_t u_size, v_size; // chroma planes size 167 size_t u_size, v_size; // chroma planes size
135 size_t a_size; // alpha-plane size 168 size_t a_size; // alpha-plane size
136 } WebPYUVABuffer; 169 } WebPYUVABuffer;
137 170
138 // Output buffer 171 // Output buffer
139 typedef struct { 172 typedef struct {
140 WEBP_CSP_MODE colorspace; // Colorspace. 173 WEBP_CSP_MODE colorspace; // Colorspace.
141 int width, height; // Dimensions. 174 int width, height; // Dimensions.
142 int is_external_memory; // If true, 'internal_memory' pointer is not used. 175 int is_external_memory; // If true, 'internal_memory' pointer is not used.
143 union { 176 union {
144 WebPRGBABuffer RGBA; 177 WebPRGBABuffer RGBA;
145 WebPYUVABuffer YUVA; 178 WebPYUVABuffer YUVA;
146 } u; // Nameless union of buffer parameters. 179 } u; // Nameless union of buffer parameters.
180 uint32_t pad[4]; // padding for later use
181
147 uint8_t* private_memory; // Internally allocated memory (only when 182 uint8_t* private_memory; // Internally allocated memory (only when
148 // is_external_memory is false). Should not be used 183 // is_external_memory is false). Should not be used
149 // externally, but accessed via the buffer union. 184 // externally, but accessed via the buffer union.
150 } WebPDecBuffer; 185 } WebPDecBuffer;
151 186
152 // Internal, version-checked, entry point 187 // Internal, version-checked, entry point
153 WEBP_EXTERN(int) WebPInitDecBufferInternal(WebPDecBuffer* const, int); 188 WEBP_EXTERN(int) WebPInitDecBufferInternal(WebPDecBuffer*, int);
154 189
155 // Initialize the structure as empty. Must be called before any other use. 190 // Initialize the structure as empty. Must be called before any other use.
156 // Returns false in case of version mismatch 191 // Returns false in case of version mismatch
157 static inline int WebPInitDecBuffer(WebPDecBuffer* const buffer) { 192 static WEBP_INLINE int WebPInitDecBuffer(WebPDecBuffer* buffer) {
158 return WebPInitDecBufferInternal(buffer, WEBP_DECODER_ABI_VERSION); 193 return WebPInitDecBufferInternal(buffer, WEBP_DECODER_ABI_VERSION);
159 } 194 }
160 195
161 // Free any memory associated with the buffer. Must always be called last. 196 // Free any memory associated with the buffer. Must always be called last.
162 // Note: doesn't free the 'buffer' structure itself. 197 // Note: doesn't free the 'buffer' structure itself.
163 WEBP_EXTERN(void) WebPFreeDecBuffer(WebPDecBuffer* const buffer); 198 WEBP_EXTERN(void) WebPFreeDecBuffer(WebPDecBuffer* buffer);
164 199
165 //------------------------------------------------------------------------------ 200 //------------------------------------------------------------------------------
166 // Enumeration of the status codes 201 // Enumeration of the status codes
167 202
168 typedef enum { 203 typedef enum {
169 VP8_STATUS_OK = 0, 204 VP8_STATUS_OK = 0,
170 VP8_STATUS_OUT_OF_MEMORY, 205 VP8_STATUS_OUT_OF_MEMORY,
171 VP8_STATUS_INVALID_PARAM, 206 VP8_STATUS_INVALID_PARAM,
172 VP8_STATUS_BITSTREAM_ERROR, 207 VP8_STATUS_BITSTREAM_ERROR,
173 VP8_STATUS_UNSUPPORTED_FEATURE, 208 VP8_STATUS_UNSUPPORTED_FEATURE,
174 VP8_STATUS_SUSPENDED, 209 VP8_STATUS_SUSPENDED,
175 VP8_STATUS_USER_ABORT, 210 VP8_STATUS_USER_ABORT,
176 VP8_STATUS_NOT_ENOUGH_DATA 211 VP8_STATUS_NOT_ENOUGH_DATA
177 } VP8StatusCode; 212 } VP8StatusCode;
178 213
179 //------------------------------------------------------------------------------ 214 //------------------------------------------------------------------------------
180 // Incremental decoding 215 // Incremental decoding
181 // 216 //
182 // This API allows streamlined decoding of partial data. 217 // This API allows streamlined decoding of partial data.
183 // Picture can be incrementally decoded as data become available thanks to the 218 // Picture can be incrementally decoded as data become available thanks to the
184 // WebPIDecoder object. This object can be left in a SUSPENDED state if the 219 // WebPIDecoder object. This object can be left in a SUSPENDED state if the
185 // picture is only partially decoded, pending additional input. 220 // picture is only partially decoded, pending additional input.
186 // Code example: 221 // Code example:
187 // 222 //
188 // WebPIDecoder* const idec = WebPINew(mode); 223 // WebPInitDecBuffer(&buffer);
224 // buffer.colorspace = mode;
225 // ...
226 // WebPIDecoder* idec = WebPINewDecoder(&buffer);
189 // while (has_more_data) { 227 // while (has_more_data) {
190 // // ... (get additional data) 228 // // ... (get additional data)
191 // status = WebPIAppend(idec, new_data, new_data_size); 229 // status = WebPIAppend(idec, new_data, new_data_size);
192 // if (status != VP8_STATUS_SUSPENDED || 230 // if (status != VP8_STATUS_SUSPENDED ||
193 // break; 231 // break;
194 // } 232 // }
195 // 233 //
196 // // The above call decodes the current available buffer. 234 // // The above call decodes the current available buffer.
197 // // Part of the image can now be refreshed by calling to 235 // // Part of the image can now be refreshed by calling to
198 // // WebPIDecGetRGB()/WebPIDecGetYUV() etc. 236 // // WebPIDecGetRGB()/WebPIDecGetYUVA() etc.
199 // } 237 // }
200 // WebPIDelete(idec); 238 // WebPIDelete(idec);
201 239
202 typedef struct WebPIDecoder WebPIDecoder; 240 typedef struct WebPIDecoder WebPIDecoder;
203 241
204 // Creates a new incremental decoder with the supplied buffer parameter. 242 // Creates a new incremental decoder with the supplied buffer parameter.
205 // This output_buffer can be passed NULL, in which case a default output buffer 243 // This output_buffer can be passed NULL, in which case a default output buffer
206 // is used (with MODE_RGB). Otherwise, an internal reference to 'output_buffer' 244 // is used (with MODE_RGB). Otherwise, an internal reference to 'output_buffer'
207 // is kept, which means that the lifespan of 'output_buffer' must be larger than 245 // is kept, which means that the lifespan of 'output_buffer' must be larger than
208 // that of the returned WebPIDecoder object. 246 // that of the returned WebPIDecoder object.
209 // Returns NULL if the allocation failed. 247 // Returns NULL if the allocation failed.
210 WEBP_EXTERN(WebPIDecoder*) WebPINewDecoder(WebPDecBuffer* const output_buffer); 248 WEBP_EXTERN(WebPIDecoder*) WebPINewDecoder(WebPDecBuffer* output_buffer);
211
212 // Creates a WebPIDecoder object. Returns NULL in case of failure.
213 // TODO(skal): DEPRECATED. Prefer using WebPINewDecoder().
214 WEBP_EXTERN(WebPIDecoder*) WebPINew(WEBP_CSP_MODE mode);
215 249
216 // This function allocates and initializes an incremental-decoder object, which 250 // This function allocates and initializes an incremental-decoder object, which
217 // will output the r/g/b(/a) samples specified by 'mode' into a preallocated 251 // will output the RGB/A samples specified by 'csp' into a preallocated
218 // buffer 'output_buffer'. The size of this buffer is at least 252 // buffer 'output_buffer'. The size of this buffer is at least
219 // 'output_buffer_size' and the stride (distance in bytes between two scanlines) 253 // 'output_buffer_size' and the stride (distance in bytes between two scanlines)
220 // is specified by 'output_stride'. Returns NULL if the allocation failed. 254 // is specified by 'output_stride'. Returns NULL if the allocation failed.
221 WEBP_EXTERN(WebPIDecoder*) WebPINewRGB( 255 WEBP_EXTERN(WebPIDecoder*) WebPINewRGB(
222 WEBP_CSP_MODE mode, 256 WEBP_CSP_MODE csp,
223 uint8_t* output_buffer, int output_buffer_size, int output_stride); 257 uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
224 258
225 // This function allocates and initializes an incremental-decoder object, which 259 // This function allocates and initializes an incremental-decoder object, which
226 // will output the raw luma/chroma samples into a preallocated planes. The luma 260 // will output the raw luma/chroma samples into a preallocated planes. The luma
227 // plane is specified by its pointer 'luma', its size 'luma_size' and its stride 261 // plane is specified by its pointer 'luma', its size 'luma_size' and its stride
228 // 'luma_stride'. Similarly, the chroma-u plane is specified by the 'u', 262 // 'luma_stride'. Similarly, the chroma-u plane is specified by the 'u',
229 // 'u_size' and 'u_stride' parameters, and the chroma-v plane by 'v', 'v_size' 263 // 'u_size' and 'u_stride' parameters, and the chroma-v plane by 'v'
230 // and 'v_size'. 264 // and 'v_size'. And same for the alpha-plane. The 'a' pointer can be pass
265 // NULL in case one is not interested in the transparency plane.
231 // Returns NULL if the allocation failed. 266 // Returns NULL if the allocation failed.
267 WEBP_EXTERN(WebPIDecoder*) WebPINewYUVA(
268 uint8_t* luma, size_t luma_size, int luma_stride,
269 uint8_t* u, size_t u_size, int u_stride,
270 uint8_t* v, size_t v_size, int v_stride,
271 uint8_t* a, size_t a_size, int a_stride);
272
273 // Deprecated version of the above, without the alpha plane.
274 // Kept for backward compatibility.
232 WEBP_EXTERN(WebPIDecoder*) WebPINewYUV( 275 WEBP_EXTERN(WebPIDecoder*) WebPINewYUV(
233 uint8_t* luma, int luma_size, int luma_stride, 276 uint8_t* luma, size_t luma_size, int luma_stride,
234 uint8_t* u, int u_size, int u_stride, 277 uint8_t* u, size_t u_size, int u_stride,
235 uint8_t* v, int v_size, int v_stride); 278 uint8_t* v, size_t v_size, int v_stride);
236 279
237 // Deletes the WebPIDecoder object and associated memory. Must always be called 280 // Deletes the WebPIDecoder object and associated memory. Must always be called
238 // if WebPINew, WebPINewRGB or WebPINewYUV succeeded. 281 // if WebPINewDecoder, WebPINewRGB or WebPINewYUV succeeded.
239 WEBP_EXTERN(void) WebPIDelete(WebPIDecoder* const idec); 282 WEBP_EXTERN(void) WebPIDelete(WebPIDecoder* idec);
240 283
241 // Copies and decodes the next available data. Returns VP8_STATUS_OK when 284 // Copies and decodes the next available data. Returns VP8_STATUS_OK when
242 // the image is successfully decoded. Returns VP8_STATUS_SUSPENDED when more 285 // the image is successfully decoded. Returns VP8_STATUS_SUSPENDED when more
243 // data is expected. Returns error in other cases. 286 // data is expected. Returns error in other cases.
244 WEBP_EXTERN(VP8StatusCode) WebPIAppend( 287 WEBP_EXTERN(VP8StatusCode) WebPIAppend(
245 WebPIDecoder* const idec, const uint8_t* data, uint32_t data_size); 288 WebPIDecoder* idec, const uint8_t* data, size_t data_size);
246 289
247 // A variant of the above function to be used when data buffer contains 290 // A variant of the above function to be used when data buffer contains
248 // partial data from the beginning. In this case data buffer is not copied 291 // partial data from the beginning. In this case data buffer is not copied
249 // to the internal memory. 292 // to the internal memory.
250 // Note that the value of the 'data' pointer can change between calls to 293 // Note that the value of the 'data' pointer can change between calls to
251 // WebPIUpdate, for instance when the data buffer is resized to fit larger data. 294 // WebPIUpdate, for instance when the data buffer is resized to fit larger data.
252 WEBP_EXTERN(VP8StatusCode) WebPIUpdate( 295 WEBP_EXTERN(VP8StatusCode) WebPIUpdate(
253 WebPIDecoder* const idec, const uint8_t* data, uint32_t data_size); 296 WebPIDecoder* idec, const uint8_t* data, size_t data_size);
254 297
255 // Returns the r/g/b/(a) image decoded so far. Returns NULL if output params 298 // Returns the RGB/A image decoded so far. Returns NULL if output params
256 // are not initialized yet. The r/g/b/(a) output type corresponds to the mode 299 // are not initialized yet. The RGB/A output type corresponds to the colorspace
257 // specified in WebPINew()/WebPINewRGB(). *last_y is the index of last decoded 300 // specified during call to WebPINewDecoder() or WebPINewRGB().
258 // row in raster scan order. Some pointers (*last_y, *width etc.) can be NULL if 301 // *last_y is the index of last decoded row in raster scan order. Some pointers
259 // corresponding information is not needed. 302 // (*last_y, *width etc.) can be NULL if corresponding information is not
303 // needed.
260 WEBP_EXTERN(uint8_t*) WebPIDecGetRGB( 304 WEBP_EXTERN(uint8_t*) WebPIDecGetRGB(
261 const WebPIDecoder* const idec, int* last_y, 305 const WebPIDecoder* idec, int* last_y,
262 int* width, int* height, int* stride); 306 int* width, int* height, int* stride);
263 307
264 // Same as above function to get YUV image. Returns pointer to the luma plane 308 // Same as above function to get a YUVA image. Returns pointer to the luma
265 // or NULL in case of error. 309 // plane or NULL in case of error. If there is no alpha information
266 WEBP_EXTERN(uint8_t*) WebPIDecGetYUV( 310 // the alpha pointer '*a' will be returned NULL.
267 const WebPIDecoder* const idec, int* last_y, 311 WEBP_EXTERN(uint8_t*) WebPIDecGetYUVA(
268 uint8_t** u, uint8_t** v, 312 const WebPIDecoder* idec, int* last_y,
269 int* width, int* height, int* stride, int* uv_stride); 313 uint8_t** u, uint8_t** v, uint8_t** a,
314 int* width, int* height, int* stride, int* uv_stride, int* a_stride);
315
316 // Deprecated alpha-less version of WebPIDecGetYUVA(): it will ignore the
317 // alpha information (if present). Kept for backward compatibility.
318 static WEBP_INLINE uint8_t* WebPIDecGetYUV(
319 const WebPIDecoder* idec, int* last_y, uint8_t** u, uint8_t** v,
320 int* width, int* height, int* stride, int* uv_stride) {
321 return WebPIDecGetYUVA(idec, last_y, u, v, NULL, width, height,
322 stride, uv_stride, NULL);
323 }
270 324
271 // Generic call to retrieve information about the displayable area. 325 // Generic call to retrieve information about the displayable area.
272 // If non NULL, the left/right/width/height pointers are filled with the visible 326 // If non NULL, the left/right/width/height pointers are filled with the visible
273 // rectangular area so far. 327 // rectangular area so far.
274 // Returns NULL in case the incremental decoder object is in an invalid state. 328 // Returns NULL in case the incremental decoder object is in an invalid state.
275 // Otherwise returns the pointer to the internal representation. This structure 329 // Otherwise returns the pointer to the internal representation. This structure
276 // is read-only, tied to WebPIDecoder's lifespan and should not be modified. 330 // is read-only, tied to WebPIDecoder's lifespan and should not be modified.
277 WEBP_EXTERN(const WebPDecBuffer*) WebPIDecodedArea( 331 WEBP_EXTERN(const WebPDecBuffer*) WebPIDecodedArea(
278 const WebPIDecoder* const idec, 332 const WebPIDecoder* idec, int* left, int* top, int* width, int* height);
279 int* const left, int* const top,
280 int* const width, int* const height);
281 333
282 //------------------------------------------------------------------------------ 334 //------------------------------------------------------------------------------
283 // Advanced decoding parametrization 335 // Advanced decoding parametrization
284 // 336 //
285 // Code sample for using the advanced decoding API 337 // Code sample for using the advanced decoding API
286 /* 338 /*
287 // A) Init a configuration object 339 // A) Init a configuration object
288 WebPDecoderConfig config; 340 WebPDecoderConfig config;
289 CHECK(WebPInitDecoderConfig(&config)); 341 CHECK(WebPInitDecoderConfig(&config));
290 342
(...skipping 16 matching lines...) Expand all
307 // E) Decoded image is now in config.output (and config.output.u.RGBA) 359 // E) Decoded image is now in config.output (and config.output.u.RGBA)
308 360
309 // F) Reclaim memory allocated in config's object. It's safe to call 361 // F) Reclaim memory allocated in config's object. It's safe to call
310 // this function even if the memory is external and wasn't allocated 362 // this function even if the memory is external and wasn't allocated
311 // by WebPDecode(). 363 // by WebPDecode().
312 WebPFreeDecBuffer(&config.output); 364 WebPFreeDecBuffer(&config.output);
313 */ 365 */
314 366
315 // Features gathered from the bitstream 367 // Features gathered from the bitstream
316 typedef struct { 368 typedef struct {
317 int width; // the original width, as read from the bitstream 369 int width; // Width in pixels, as read from the bitstream.
318 int height; // the original height, as read from the bitstream 370 int height; // Height in pixels, as read from the bitstream.
319 int has_alpha; // true if bitstream contains an alpha channel 371 int has_alpha; // True if the bitstream contains an alpha channel.
372
373 // Unused for now:
374 int bitstream_version; // should be 0 for now. TODO(later)
320 int no_incremental_decoding; // if true, using incremental decoding is not 375 int no_incremental_decoding; // if true, using incremental decoding is not
321 // recommended. 376 // recommended.
322 int rotate; // TODO(later) 377 int rotate; // TODO(later)
323 int uv_sampling; // should be 0 for now. TODO(later) 378 int uv_sampling; // should be 0 for now. TODO(later)
324 int bitstream_version; // should be 0 for now. TODO(later) 379 uint32_t pad[3]; // padding for later use
325 } WebPBitstreamFeatures; 380 } WebPBitstreamFeatures;
326 381
327 // Internal, version-checked, entry point 382 // Internal, version-checked, entry point
328 WEBP_EXTERN(VP8StatusCode) WebPGetFeaturesInternal( 383 WEBP_EXTERN(VP8StatusCode) WebPGetFeaturesInternal(
329 const uint8_t*, uint32_t, WebPBitstreamFeatures* const, int); 384 const uint8_t*, size_t, WebPBitstreamFeatures*, int);
330 385
331 // Retrieve features from the bitstream. The *features structure is filled 386 // Retrieve features from the bitstream. The *features structure is filled
332 // with information gathered from the bitstream. 387 // with information gathered from the bitstream.
333 // Returns false in case of error or version mismatch. 388 // Returns false in case of error or version mismatch.
334 // In case of error, features->bitstream_status will reflect the error code. 389 // In case of error, features->bitstream_status will reflect the error code.
335 static inline 390 static WEBP_INLINE VP8StatusCode WebPGetFeatures(
336 VP8StatusCode WebPGetFeatures(const uint8_t* data, uint32_t data_size, 391 const uint8_t* data, size_t data_size,
337 WebPBitstreamFeatures* const features) { 392 WebPBitstreamFeatures* features) {
338 return WebPGetFeaturesInternal(data, data_size, features, 393 return WebPGetFeaturesInternal(data, data_size, features,
339 WEBP_DECODER_ABI_VERSION); 394 WEBP_DECODER_ABI_VERSION);
340 } 395 }
341 396
342 // Decoding options 397 // Decoding options
343 typedef struct { 398 typedef struct {
344 int bypass_filtering; // if true, skip the in-loop filtering 399 int bypass_filtering; // if true, skip the in-loop filtering
345 int no_fancy_upsampling; // if true, use faster pointwise upsampler 400 int no_fancy_upsampling; // if true, use faster pointwise upsampler
346 int use_cropping; // if true, cropping is applied _first_ 401 int use_cropping; // if true, cropping is applied _first_
347 int crop_left, crop_top; // top-left position for cropping. 402 int crop_left, crop_top; // top-left position for cropping.
348 // Will be snapped to even values. 403 // Will be snapped to even values.
349 int crop_width, crop_height; // dimension of the cropping area 404 int crop_width, crop_height; // dimension of the cropping area
350 int use_scaling; // if true, scaling is applied _afterward_ 405 int use_scaling; // if true, scaling is applied _afterward_
351 int scaled_width, scaled_height; // final resolution 406 int scaled_width, scaled_height; // final resolution
407 int use_threads; // if true, use multi-threaded decoding
408
409 // Unused for now:
352 int force_rotation; // forced rotation (to be applied _last_) 410 int force_rotation; // forced rotation (to be applied _last_)
353 int no_enhancement; // if true, discard enhancement layer 411 int no_enhancement; // if true, discard enhancement layer
354 int use_threads; // if true, use multi-threaded decoding 412 uint32_t pad[6]; // padding for later use
355 } WebPDecoderOptions; 413 } WebPDecoderOptions;
356 414
357 // Main object storing the configuration for advanced decoding. 415 // Main object storing the configuration for advanced decoding.
358 typedef struct { 416 typedef struct {
359 WebPBitstreamFeatures input; // Immutable bitstream features (optional) 417 WebPBitstreamFeatures input; // Immutable bitstream features (optional)
360 WebPDecBuffer output; // Output buffer (can point to external mem) 418 WebPDecBuffer output; // Output buffer (can point to external mem)
361 WebPDecoderOptions options; // Decoding options 419 WebPDecoderOptions options; // Decoding options
362 } WebPDecoderConfig; 420 } WebPDecoderConfig;
363 421
364 // Internal, version-checked, entry point 422 // Internal, version-checked, entry point
365 WEBP_EXTERN(int) WebPInitDecoderConfigInternal(WebPDecoderConfig* const, int); 423 WEBP_EXTERN(int) WebPInitDecoderConfigInternal(WebPDecoderConfig*, int);
366 424
367 // Initialize the configuration as empty. This function must always be 425 // Initialize the configuration as empty. This function must always be
368 // called first, unless WebPGetFeatures() is to be called. 426 // called first, unless WebPGetFeatures() is to be called.
369 // Returns false in case of mismatched version. 427 // Returns false in case of mismatched version.
370 static inline int WebPInitDecoderConfig(WebPDecoderConfig* const config) { 428 static WEBP_INLINE int WebPInitDecoderConfig(WebPDecoderConfig* config) {
371 return WebPInitDecoderConfigInternal(config, WEBP_DECODER_ABI_VERSION); 429 return WebPInitDecoderConfigInternal(config, WEBP_DECODER_ABI_VERSION);
372 } 430 }
373 431
374 // Instantiate a new incremental decoder object with requested configuration. 432 // Instantiate a new incremental decoder object with the requested
375 // The bitstream can be passed using *data and data_size parameter, 433 // configuration. The bitstream can be passed using 'data' and 'data_size'
376 // in which case the features will be parsed and stored into config->input. 434 // parameter, in which case the features will be parsed and stored into
377 // Otherwise, 'data' can be NULL and now parsing will occur. 435 // config->input. Otherwise, 'data' can be NULL and no parsing will occur.
378 // Note that 'config' can be NULL too, in which case a default configuration is 436 // Note that 'config' can be NULL too, in which case a default configuration
379 // used. 437 // is used.
380 // The return WebPIDecoder object must always be deleted calling WebPIDelete(). 438 // The return WebPIDecoder object must always be deleted calling WebPIDelete().
381 // Returns NULL in case of error (and config->status will then reflect 439 // Returns NULL in case of error (and config->status will then reflect
382 // the error condition). 440 // the error condition).
383 WEBP_EXTERN(WebPIDecoder*) WebPIDecode(const uint8_t* data, uint32_t data_size, 441 WEBP_EXTERN(WebPIDecoder*) WebPIDecode(const uint8_t* data, size_t data_size,
384 WebPDecoderConfig* const config); 442 WebPDecoderConfig* config);
385 443
386 // Non-incremental version. This version decodes the full data at once, taking 444 // Non-incremental version. This version decodes the full data at once, taking
387 // 'config' into account. Return decoding status (VP8_STATUS_OK if decoding 445 // 'config' into account. Returns decoding status (which should be VP8_STATUS_OK
388 // was successful). 446 // if the decoding was successful).
389 WEBP_EXTERN(VP8StatusCode) WebPDecode(const uint8_t* data, uint32_t data_size, 447 WEBP_EXTERN(VP8StatusCode) WebPDecode(const uint8_t* data, size_t data_size,
390 WebPDecoderConfig* const config); 448 WebPDecoderConfig* config);
391 449
392 #if defined(__cplusplus) || defined(c_plusplus) 450 #if defined(__cplusplus) || defined(c_plusplus)
393 } // extern "C" 451 } // extern "C"
394 #endif 452 #endif
395 453
396 #endif /* WEBP_WEBP_DECODE_H_ */ 454 #endif /* WEBP_WEBP_DECODE_H_ */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698