OLD | NEW |
1 // Copyright 2010 Google Inc. All Rights Reserved. | 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 0x0200 // MAJOR(8b) + MINOR(8b) | 21 #define WEBP_DECODER_ABI_VERSION 0x0201 // MAJOR(8b) + MINOR(8b) |
| 22 |
| 23 typedef struct WebPRGBABuffer WebPRGBABuffer; |
| 24 typedef struct WebPYUVABuffer WebPYUVABuffer; |
| 25 typedef struct WebPDecBuffer WebPDecBuffer; |
| 26 #if !(defined(__cplusplus) || defined(c_plusplus)) |
| 27 typedef enum VP8StatusCode VP8StatusCode; |
| 28 typedef enum WEBP_CSP_MODE WEBP_CSP_MODE; |
| 29 #endif |
| 30 typedef struct WebPIDecoder WebPIDecoder; |
| 31 typedef struct WebPBitstreamFeatures WebPBitstreamFeatures; |
| 32 typedef struct WebPDecoderOptions WebPDecoderOptions; |
| 33 typedef struct WebPDecoderConfig WebPDecoderConfig; |
22 | 34 |
23 // Return the decoder's version number, packed in hexadecimal using 8bits for | 35 // 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. | 36 // each of major/minor/revision. E.g: v2.5.7 is 0x020507. |
25 WEBP_EXTERN(int) WebPGetDecoderVersion(void); | 37 WEBP_EXTERN(int) WebPGetDecoderVersion(void); |
26 | 38 |
27 // Retrieve basic header information: width, height. | 39 // Retrieve basic header information: width, height. |
28 // This function will also validate the header and return 0 in | 40 // This function will also validate the header and return 0 in |
29 // case of formatting error. | 41 // case of formatting error. |
30 // Pointers 'width' and 'height' can be passed NULL if deemed irrelevant. | 42 // Pointers 'width' and 'height' can be passed NULL if deemed irrelevant. |
31 WEBP_EXTERN(int) WebPGetInfo(const uint8_t* data, size_t data_size, | 43 WEBP_EXTERN(int) WebPGetInfo(const uint8_t* data, size_t data_size, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 uint8_t* u, size_t u_size, int u_stride, | 123 uint8_t* u, size_t u_size, int u_stride, |
112 uint8_t* v, size_t v_size, int v_stride); | 124 uint8_t* v, size_t v_size, int v_stride); |
113 | 125 |
114 //------------------------------------------------------------------------------ | 126 //------------------------------------------------------------------------------ |
115 // Output colorspaces and buffer | 127 // Output colorspaces and buffer |
116 | 128 |
117 // Colorspaces | 129 // Colorspaces |
118 // Note: the naming describes the byte-ordering of packed samples in memory. | 130 // 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,... | 131 // 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. | 132 // 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. | 133 // RGBA-4444 and RGB-565 colorspaces are represented by following byte-order: |
122 typedef enum { MODE_RGB = 0, MODE_RGBA = 1, | 134 // RGBA-4444: [r3 r2 r1 r0 g3 g2 g1 g0], [b3 b2 b1 b0 a3 a2 a1 a0], ... |
123 MODE_BGR = 2, MODE_BGRA = 3, | 135 // RGB-565: [r4 r3 r2 r1 r0 g5 g4 g3], [g2 g1 g0 b4 b3 b2 b1 b0], ... |
124 MODE_ARGB = 4, MODE_RGBA_4444 = 5, | 136 // In the case WEBP_SWAP_16BITS_CSP is defined, the bytes are swapped for |
125 MODE_RGB_565 = 6, | 137 // these two modes: |
126 // RGB-premultiplied transparent modes (alpha value is preserved) | 138 // RGBA-4444: [b3 b2 b1 b0 a3 a2 a1 a0], [r3 r2 r1 r0 g3 g2 g1 g0], ... |
127 MODE_rgbA = 7, | 139 // RGB-565: [g2 g1 g0 b4 b3 b2 b1 b0], [r4 r3 r2 r1 r0 g5 g4 g3], ... |
128 MODE_bgrA = 8, | 140 |
129 MODE_Argb = 9, | 141 enum WEBP_CSP_MODE { |
130 MODE_rgbA_4444 = 10, | 142 MODE_RGB = 0, MODE_RGBA = 1, |
131 // YUV modes must come after RGB ones. | 143 MODE_BGR = 2, MODE_BGRA = 3, |
132 MODE_YUV = 11, MODE_YUVA = 12, // yuv 4:2:0 | 144 MODE_ARGB = 4, MODE_RGBA_4444 = 5, |
133 MODE_LAST = 13 | 145 MODE_RGB_565 = 6, |
134 } WEBP_CSP_MODE; | 146 // RGB-premultiplied transparent modes (alpha value is preserved) |
| 147 MODE_rgbA = 7, |
| 148 MODE_bgrA = 8, |
| 149 MODE_Argb = 9, |
| 150 MODE_rgbA_4444 = 10, |
| 151 // YUV modes must come after RGB ones. |
| 152 MODE_YUV = 11, MODE_YUVA = 12, // yuv 4:2:0 |
| 153 MODE_LAST = 13 |
| 154 }; |
135 | 155 |
136 // Some useful macros: | 156 // Some useful macros: |
137 static WEBP_INLINE int WebPIsPremultipliedMode(WEBP_CSP_MODE mode) { | 157 static WEBP_INLINE int WebPIsPremultipliedMode(WEBP_CSP_MODE mode) { |
138 return (mode == MODE_rgbA || mode == MODE_bgrA || mode == MODE_Argb || | 158 return (mode == MODE_rgbA || mode == MODE_bgrA || mode == MODE_Argb || |
139 mode == MODE_rgbA_4444); | 159 mode == MODE_rgbA_4444); |
140 } | 160 } |
141 | 161 |
142 static WEBP_INLINE int WebPIsAlphaMode(WEBP_CSP_MODE mode) { | 162 static WEBP_INLINE int WebPIsAlphaMode(WEBP_CSP_MODE mode) { |
143 return (mode == MODE_RGBA || mode == MODE_BGRA || mode == MODE_ARGB || | 163 return (mode == MODE_RGBA || mode == MODE_BGRA || mode == MODE_ARGB || |
144 mode == MODE_RGBA_4444 || mode == MODE_YUVA || | 164 mode == MODE_RGBA_4444 || mode == MODE_YUVA || |
145 WebPIsPremultipliedMode(mode)); | 165 WebPIsPremultipliedMode(mode)); |
146 } | 166 } |
147 | 167 |
148 static WEBP_INLINE int WebPIsRGBMode(WEBP_CSP_MODE mode) { | 168 static WEBP_INLINE int WebPIsRGBMode(WEBP_CSP_MODE mode) { |
149 return (mode < MODE_YUV); | 169 return (mode < MODE_YUV); |
150 } | 170 } |
151 | 171 |
152 //------------------------------------------------------------------------------ | 172 //------------------------------------------------------------------------------ |
153 // WebPDecBuffer: Generic structure for describing the output sample buffer. | 173 // WebPDecBuffer: Generic structure for describing the output sample buffer. |
154 | 174 |
155 typedef struct { // view as RGBA | 175 struct WebPRGBABuffer { // view as RGBA |
156 uint8_t* rgba; // pointer to RGBA samples | 176 uint8_t* rgba; // pointer to RGBA samples |
157 int stride; // stride in bytes from one scanline to the next. | 177 int stride; // stride in bytes from one scanline to the next. |
158 size_t size; // total size of the *rgba buffer. | 178 size_t size; // total size of the *rgba buffer. |
159 } WebPRGBABuffer; | 179 }; |
160 | 180 |
161 typedef struct { // view as YUVA | 181 struct WebPYUVABuffer { // view as YUVA |
162 uint8_t* y, *u, *v, *a; // pointer to luma, chroma U/V, alpha samples | 182 uint8_t* y, *u, *v, *a; // pointer to luma, chroma U/V, alpha samples |
163 int y_stride; // luma stride | 183 int y_stride; // luma stride |
164 int u_stride, v_stride; // chroma strides | 184 int u_stride, v_stride; // chroma strides |
165 int a_stride; // alpha stride | 185 int a_stride; // alpha stride |
166 size_t y_size; // luma plane size | 186 size_t y_size; // luma plane size |
167 size_t u_size, v_size; // chroma planes size | 187 size_t u_size, v_size; // chroma planes size |
168 size_t a_size; // alpha-plane size | 188 size_t a_size; // alpha-plane size |
169 } WebPYUVABuffer; | 189 }; |
170 | 190 |
171 // Output buffer | 191 // Output buffer |
172 typedef struct { | 192 struct WebPDecBuffer { |
173 WEBP_CSP_MODE colorspace; // Colorspace. | 193 WEBP_CSP_MODE colorspace; // Colorspace. |
174 int width, height; // Dimensions. | 194 int width, height; // Dimensions. |
175 int is_external_memory; // If true, 'internal_memory' pointer is not used. | 195 int is_external_memory; // If true, 'internal_memory' pointer is not used. |
176 union { | 196 union { |
177 WebPRGBABuffer RGBA; | 197 WebPRGBABuffer RGBA; |
178 WebPYUVABuffer YUVA; | 198 WebPYUVABuffer YUVA; |
179 } u; // Nameless union of buffer parameters. | 199 } u; // Nameless union of buffer parameters. |
180 uint32_t pad[4]; // padding for later use | 200 uint32_t pad[4]; // padding for later use |
181 | 201 |
182 uint8_t* private_memory; // Internally allocated memory (only when | 202 uint8_t* private_memory; // Internally allocated memory (only when |
183 // is_external_memory is false). Should not be used | 203 // is_external_memory is false). Should not be used |
184 // externally, but accessed via the buffer union. | 204 // externally, but accessed via the buffer union. |
185 } WebPDecBuffer; | 205 }; |
186 | 206 |
187 // Internal, version-checked, entry point | 207 // Internal, version-checked, entry point |
188 WEBP_EXTERN(int) WebPInitDecBufferInternal(WebPDecBuffer*, int); | 208 WEBP_EXTERN(int) WebPInitDecBufferInternal(WebPDecBuffer*, int); |
189 | 209 |
190 // Initialize the structure as empty. Must be called before any other use. | 210 // Initialize the structure as empty. Must be called before any other use. |
191 // Returns false in case of version mismatch | 211 // Returns false in case of version mismatch |
192 static WEBP_INLINE int WebPInitDecBuffer(WebPDecBuffer* buffer) { | 212 static WEBP_INLINE int WebPInitDecBuffer(WebPDecBuffer* buffer) { |
193 return WebPInitDecBufferInternal(buffer, WEBP_DECODER_ABI_VERSION); | 213 return WebPInitDecBufferInternal(buffer, WEBP_DECODER_ABI_VERSION); |
194 } | 214 } |
195 | 215 |
196 // Free any memory associated with the buffer. Must always be called last. | 216 // Free any memory associated with the buffer. Must always be called last. |
197 // Note: doesn't free the 'buffer' structure itself. | 217 // Note: doesn't free the 'buffer' structure itself. |
198 WEBP_EXTERN(void) WebPFreeDecBuffer(WebPDecBuffer* buffer); | 218 WEBP_EXTERN(void) WebPFreeDecBuffer(WebPDecBuffer* buffer); |
199 | 219 |
200 //------------------------------------------------------------------------------ | 220 //------------------------------------------------------------------------------ |
201 // Enumeration of the status codes | 221 // Enumeration of the status codes |
202 | 222 |
203 typedef enum { | 223 enum VP8StatusCode { |
204 VP8_STATUS_OK = 0, | 224 VP8_STATUS_OK = 0, |
205 VP8_STATUS_OUT_OF_MEMORY, | 225 VP8_STATUS_OUT_OF_MEMORY, |
206 VP8_STATUS_INVALID_PARAM, | 226 VP8_STATUS_INVALID_PARAM, |
207 VP8_STATUS_BITSTREAM_ERROR, | 227 VP8_STATUS_BITSTREAM_ERROR, |
208 VP8_STATUS_UNSUPPORTED_FEATURE, | 228 VP8_STATUS_UNSUPPORTED_FEATURE, |
209 VP8_STATUS_SUSPENDED, | 229 VP8_STATUS_SUSPENDED, |
210 VP8_STATUS_USER_ABORT, | 230 VP8_STATUS_USER_ABORT, |
211 VP8_STATUS_NOT_ENOUGH_DATA | 231 VP8_STATUS_NOT_ENOUGH_DATA |
212 } VP8StatusCode; | 232 }; |
213 | 233 |
214 //------------------------------------------------------------------------------ | 234 //------------------------------------------------------------------------------ |
215 // Incremental decoding | 235 // Incremental decoding |
216 // | 236 // |
217 // This API allows streamlined decoding of partial data. | 237 // This API allows streamlined decoding of partial data. |
218 // Picture can be incrementally decoded as data become available thanks to the | 238 // Picture can be incrementally decoded as data become available thanks to the |
219 // WebPIDecoder object. This object can be left in a SUSPENDED state if the | 239 // WebPIDecoder object. This object can be left in a SUSPENDED state if the |
220 // picture is only partially decoded, pending additional input. | 240 // picture is only partially decoded, pending additional input. |
221 // Code example: | 241 // Code example: |
222 // | 242 // |
223 // WebPInitDecBuffer(&buffer); | 243 // WebPInitDecBuffer(&buffer); |
224 // buffer.colorspace = mode; | 244 // buffer.colorspace = mode; |
225 // ... | 245 // ... |
226 // WebPIDecoder* idec = WebPINewDecoder(&buffer); | 246 // WebPIDecoder* idec = WebPINewDecoder(&buffer); |
227 // while (has_more_data) { | 247 // while (has_more_data) { |
228 // // ... (get additional data) | 248 // // ... (get additional data) |
229 // status = WebPIAppend(idec, new_data, new_data_size); | 249 // status = WebPIAppend(idec, new_data, new_data_size); |
230 // if (status != VP8_STATUS_SUSPENDED || | 250 // if (status != VP8_STATUS_SUSPENDED || |
231 // break; | 251 // break; |
232 // } | 252 // } |
233 // | 253 // |
234 // // The above call decodes the current available buffer. | 254 // // The above call decodes the current available buffer. |
235 // // Part of the image can now be refreshed by calling to | 255 // // Part of the image can now be refreshed by calling to |
236 // // WebPIDecGetRGB()/WebPIDecGetYUVA() etc. | 256 // // WebPIDecGetRGB()/WebPIDecGetYUVA() etc. |
237 // } | 257 // } |
238 // WebPIDelete(idec); | 258 // WebPIDelete(idec); |
239 | 259 |
240 typedef struct WebPIDecoder WebPIDecoder; | |
241 | |
242 // Creates a new incremental decoder with the supplied buffer parameter. | 260 // Creates a new incremental decoder with the supplied buffer parameter. |
243 // This output_buffer can be passed NULL, in which case a default output buffer | 261 // This output_buffer can be passed NULL, in which case a default output buffer |
244 // is used (with MODE_RGB). Otherwise, an internal reference to 'output_buffer' | 262 // is used (with MODE_RGB). Otherwise, an internal reference to 'output_buffer' |
245 // is kept, which means that the lifespan of 'output_buffer' must be larger than | 263 // is kept, which means that the lifespan of 'output_buffer' must be larger than |
246 // that of the returned WebPIDecoder object. | 264 // that of the returned WebPIDecoder object. |
247 // Returns NULL if the allocation failed. | 265 // Returns NULL if the allocation failed. |
248 WEBP_EXTERN(WebPIDecoder*) WebPINewDecoder(WebPDecBuffer* output_buffer); | 266 WEBP_EXTERN(WebPIDecoder*) WebPINewDecoder(WebPDecBuffer* output_buffer); |
249 | 267 |
250 // This function allocates and initializes an incremental-decoder object, which | 268 // This function allocates and initializes an incremental-decoder object, which |
251 // will output the RGB/A samples specified by 'csp' into a preallocated | 269 // will output the RGB/A samples specified by 'csp' into a preallocated |
252 // buffer 'output_buffer'. The size of this buffer is at least | 270 // buffer 'output_buffer'. The size of this buffer is at least |
253 // 'output_buffer_size' and the stride (distance in bytes between two scanlines) | 271 // 'output_buffer_size' and the stride (distance in bytes between two scanlines) |
254 // is specified by 'output_stride'. Returns NULL if the allocation failed. | 272 // is specified by 'output_stride'. |
| 273 // Additionally, output_buffer can be passed NULL in which case the output |
| 274 // buffer will be allocated automatically when the decoding starts. The |
| 275 // colorspace 'csp' is taken into account for allocating this buffer. All other |
| 276 // parameters are ignored. |
| 277 // Returns NULL if the allocation failed, or if some parameters are invalid. |
255 WEBP_EXTERN(WebPIDecoder*) WebPINewRGB( | 278 WEBP_EXTERN(WebPIDecoder*) WebPINewRGB( |
256 WEBP_CSP_MODE csp, | 279 WEBP_CSP_MODE csp, |
257 uint8_t* output_buffer, size_t output_buffer_size, int output_stride); | 280 uint8_t* output_buffer, size_t output_buffer_size, int output_stride); |
258 | 281 |
259 // This function allocates and initializes an incremental-decoder object, which | 282 // This function allocates and initializes an incremental-decoder object, which |
260 // will output the raw luma/chroma samples into a preallocated planes. The luma | 283 // will output the raw luma/chroma samples into a preallocated planes if |
261 // plane is specified by its pointer 'luma', its size 'luma_size' and its stride | 284 // supplied. The luma plane is specified by its pointer 'luma', its size |
262 // 'luma_stride'. Similarly, the chroma-u plane is specified by the 'u', | 285 // 'luma_size' and its stride 'luma_stride'. Similarly, the chroma-u plane |
263 // 'u_size' and 'u_stride' parameters, and the chroma-v plane by 'v' | 286 // is specified by the 'u', 'u_size' and 'u_stride' parameters, and the chroma-v |
264 // and 'v_size'. And same for the alpha-plane. The 'a' pointer can be pass | 287 // plane by 'v' and 'v_size'. And same for the alpha-plane. The 'a' pointer |
265 // NULL in case one is not interested in the transparency plane. | 288 // can be pass NULL in case one is not interested in the transparency plane. |
266 // Returns NULL if the allocation failed. | 289 // Conversely, 'luma' can be passed NULL if no preallocated planes are supplied. |
| 290 // In this case, the output buffer will be automatically allocated (using |
| 291 // MODE_YUVA) when decoding starts. All parameters are then ignored. |
| 292 // Returns NULL if the allocation failed or if a parameter is invalid. |
267 WEBP_EXTERN(WebPIDecoder*) WebPINewYUVA( | 293 WEBP_EXTERN(WebPIDecoder*) WebPINewYUVA( |
268 uint8_t* luma, size_t luma_size, int luma_stride, | 294 uint8_t* luma, size_t luma_size, int luma_stride, |
269 uint8_t* u, size_t u_size, int u_stride, | 295 uint8_t* u, size_t u_size, int u_stride, |
270 uint8_t* v, size_t v_size, int v_stride, | 296 uint8_t* v, size_t v_size, int v_stride, |
271 uint8_t* a, size_t a_size, int a_stride); | 297 uint8_t* a, size_t a_size, int a_stride); |
272 | 298 |
273 // Deprecated version of the above, without the alpha plane. | 299 // Deprecated version of the above, without the alpha plane. |
274 // Kept for backward compatibility. | 300 // Kept for backward compatibility. |
275 WEBP_EXTERN(WebPIDecoder*) WebPINewYUV( | 301 WEBP_EXTERN(WebPIDecoder*) WebPINewYUV( |
276 uint8_t* luma, size_t luma_size, int luma_stride, | 302 uint8_t* luma, size_t luma_size, int luma_stride, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // Code sample for using the advanced decoding API | 363 // Code sample for using the advanced decoding API |
338 /* | 364 /* |
339 // A) Init a configuration object | 365 // A) Init a configuration object |
340 WebPDecoderConfig config; | 366 WebPDecoderConfig config; |
341 CHECK(WebPInitDecoderConfig(&config)); | 367 CHECK(WebPInitDecoderConfig(&config)); |
342 | 368 |
343 // B) optional: retrieve the bitstream's features. | 369 // B) optional: retrieve the bitstream's features. |
344 CHECK(WebPGetFeatures(data, data_size, &config.input) == VP8_STATUS_OK); | 370 CHECK(WebPGetFeatures(data, data_size, &config.input) == VP8_STATUS_OK); |
345 | 371 |
346 // C) Adjust 'config', if needed | 372 // C) Adjust 'config', if needed |
347 config.no_fancy = 1; | 373 config.no_fancy_upsampling = 1; |
348 config.output.colorspace = MODE_BGRA; | 374 config.output.colorspace = MODE_BGRA; |
349 // etc. | 375 // etc. |
350 | 376 |
351 // Note that you can also make config.output point to an externally | 377 // Note that you can also make config.output point to an externally |
352 // supplied memory buffer, provided it's big enough to store the decoded | 378 // supplied memory buffer, provided it's big enough to store the decoded |
353 // picture. Otherwise, config.output will just be used to allocate memory | 379 // picture. Otherwise, config.output will just be used to allocate memory |
354 // and store the decoded picture. | 380 // and store the decoded picture. |
355 | 381 |
356 // D) Decode! | 382 // D) Decode! |
357 CHECK(WebPDecode(data, data_size, &config) == VP8_STATUS_OK); | 383 CHECK(WebPDecode(data, data_size, &config) == VP8_STATUS_OK); |
358 | 384 |
359 // E) Decoded image is now in config.output (and config.output.u.RGBA) | 385 // E) Decoded image is now in config.output (and config.output.u.RGBA) |
360 | 386 |
361 // F) Reclaim memory allocated in config's object. It's safe to call | 387 // F) Reclaim memory allocated in config's object. It's safe to call |
362 // this function even if the memory is external and wasn't allocated | 388 // this function even if the memory is external and wasn't allocated |
363 // by WebPDecode(). | 389 // by WebPDecode(). |
364 WebPFreeDecBuffer(&config.output); | 390 WebPFreeDecBuffer(&config.output); |
365 */ | 391 */ |
366 | 392 |
367 // Features gathered from the bitstream | 393 // Features gathered from the bitstream |
368 typedef struct { | 394 struct WebPBitstreamFeatures { |
369 int width; // Width in pixels, as read from the bitstream. | 395 int width; // Width in pixels, as read from the bitstream. |
370 int height; // Height in pixels, as read from the bitstream. | 396 int height; // Height in pixels, as read from the bitstream. |
371 int has_alpha; // True if the bitstream contains an alpha channel. | 397 int has_alpha; // True if the bitstream contains an alpha channel. |
| 398 int has_animation; // True if the bitstream is an animation. |
372 | 399 |
373 // Unused for now: | 400 // Unused for now: |
374 int bitstream_version; // should be 0 for now. TODO(later) | 401 int bitstream_version; // should be 0 for now. TODO(later) |
375 int no_incremental_decoding; // if true, using incremental decoding is not | 402 int no_incremental_decoding; // if true, using incremental decoding is not |
376 // recommended. | 403 // recommended. |
377 int rotate; // TODO(later) | 404 int rotate; // TODO(later) |
378 int uv_sampling; // should be 0 for now. TODO(later) | 405 int uv_sampling; // should be 0 for now. TODO(later) |
379 uint32_t pad[3]; // padding for later use | 406 uint32_t pad[2]; // padding for later use |
380 } WebPBitstreamFeatures; | 407 }; |
381 | 408 |
382 // Internal, version-checked, entry point | 409 // Internal, version-checked, entry point |
383 WEBP_EXTERN(VP8StatusCode) WebPGetFeaturesInternal( | 410 WEBP_EXTERN(VP8StatusCode) WebPGetFeaturesInternal( |
384 const uint8_t*, size_t, WebPBitstreamFeatures*, int); | 411 const uint8_t*, size_t, WebPBitstreamFeatures*, int); |
385 | 412 |
386 // Retrieve features from the bitstream. The *features structure is filled | 413 // Retrieve features from the bitstream. The *features structure is filled |
387 // with information gathered from the bitstream. | 414 // with information gathered from the bitstream. |
388 // Returns false in case of error or version mismatch. | 415 // Returns VP8_STATUS_OK when the features are successfully retrieved. Returns |
389 // In case of error, features->bitstream_status will reflect the error code. | 416 // VP8_STATUS_NOT_ENOUGH_DATA when more data is needed to retrieve the |
| 417 // features from headers. Returns error in other cases. |
390 static WEBP_INLINE VP8StatusCode WebPGetFeatures( | 418 static WEBP_INLINE VP8StatusCode WebPGetFeatures( |
391 const uint8_t* data, size_t data_size, | 419 const uint8_t* data, size_t data_size, |
392 WebPBitstreamFeatures* features) { | 420 WebPBitstreamFeatures* features) { |
393 return WebPGetFeaturesInternal(data, data_size, features, | 421 return WebPGetFeaturesInternal(data, data_size, features, |
394 WEBP_DECODER_ABI_VERSION); | 422 WEBP_DECODER_ABI_VERSION); |
395 } | 423 } |
396 | 424 |
397 // Decoding options | 425 // Decoding options |
398 typedef struct { | 426 struct WebPDecoderOptions { |
399 int bypass_filtering; // if true, skip the in-loop filtering | 427 int bypass_filtering; // if true, skip the in-loop filtering |
400 int no_fancy_upsampling; // if true, use faster pointwise upsampler | 428 int no_fancy_upsampling; // if true, use faster pointwise upsampler |
401 int use_cropping; // if true, cropping is applied _first_ | 429 int use_cropping; // if true, cropping is applied _first_ |
402 int crop_left, crop_top; // top-left position for cropping. | 430 int crop_left, crop_top; // top-left position for cropping. |
403 // Will be snapped to even values. | 431 // Will be snapped to even values. |
404 int crop_width, crop_height; // dimension of the cropping area | 432 int crop_width, crop_height; // dimension of the cropping area |
405 int use_scaling; // if true, scaling is applied _afterward_ | 433 int use_scaling; // if true, scaling is applied _afterward_ |
406 int scaled_width, scaled_height; // final resolution | 434 int scaled_width, scaled_height; // final resolution |
407 int use_threads; // if true, use multi-threaded decoding | 435 int use_threads; // if true, use multi-threaded decoding |
408 | 436 |
409 // Unused for now: | 437 // Unused for now: |
410 int force_rotation; // forced rotation (to be applied _last_) | 438 int force_rotation; // forced rotation (to be applied _last_) |
411 int no_enhancement; // if true, discard enhancement layer | 439 int no_enhancement; // if true, discard enhancement layer |
412 uint32_t pad[6]; // padding for later use | 440 uint32_t pad[6]; // padding for later use |
413 } WebPDecoderOptions; | 441 }; |
414 | 442 |
415 // Main object storing the configuration for advanced decoding. | 443 // Main object storing the configuration for advanced decoding. |
416 typedef struct { | 444 struct WebPDecoderConfig { |
417 WebPBitstreamFeatures input; // Immutable bitstream features (optional) | 445 WebPBitstreamFeatures input; // Immutable bitstream features (optional) |
418 WebPDecBuffer output; // Output buffer (can point to external mem) | 446 WebPDecBuffer output; // Output buffer (can point to external mem) |
419 WebPDecoderOptions options; // Decoding options | 447 WebPDecoderOptions options; // Decoding options |
420 } WebPDecoderConfig; | 448 }; |
421 | 449 |
422 // Internal, version-checked, entry point | 450 // Internal, version-checked, entry point |
423 WEBP_EXTERN(int) WebPInitDecoderConfigInternal(WebPDecoderConfig*, int); | 451 WEBP_EXTERN(int) WebPInitDecoderConfigInternal(WebPDecoderConfig*, int); |
424 | 452 |
425 // Initialize the configuration as empty. This function must always be | 453 // Initialize the configuration as empty. This function must always be |
426 // called first, unless WebPGetFeatures() is to be called. | 454 // called first, unless WebPGetFeatures() is to be called. |
427 // Returns false in case of mismatched version. | 455 // Returns false in case of mismatched version. |
428 static WEBP_INLINE int WebPInitDecoderConfig(WebPDecoderConfig* config) { | 456 static WEBP_INLINE int WebPInitDecoderConfig(WebPDecoderConfig* config) { |
429 return WebPInitDecoderConfigInternal(config, WEBP_DECODER_ABI_VERSION); | 457 return WebPInitDecoderConfigInternal(config, WEBP_DECODER_ABI_VERSION); |
430 } | 458 } |
(...skipping 14 matching lines...) Expand all Loading... |
445 // 'config' into account. Returns decoding status (which should be VP8_STATUS_OK | 473 // 'config' into account. Returns decoding status (which should be VP8_STATUS_OK |
446 // if the decoding was successful). | 474 // if the decoding was successful). |
447 WEBP_EXTERN(VP8StatusCode) WebPDecode(const uint8_t* data, size_t data_size, | 475 WEBP_EXTERN(VP8StatusCode) WebPDecode(const uint8_t* data, size_t data_size, |
448 WebPDecoderConfig* config); | 476 WebPDecoderConfig* config); |
449 | 477 |
450 #if defined(__cplusplus) || defined(c_plusplus) | 478 #if defined(__cplusplus) || defined(c_plusplus) |
451 } // extern "C" | 479 } // extern "C" |
452 #endif | 480 #endif |
453 | 481 |
454 #endif /* WEBP_WEBP_DECODE_H_ */ | 482 #endif /* WEBP_WEBP_DECODE_H_ */ |
OLD | NEW |