| 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 // Use of this source code is governed by a BSD-style license | 
| 4 //  Software License Agreement:  http://www.webmproject.org/license/software/ | 4 // that can be found in the COPYING file in the root of the source | 
| 5 //  Additional IP Rights Grant:  http://www.webmproject.org/license/additional/ | 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. | 
| 6 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- | 
| 7 // | 9 // | 
| 8 //  Main decoding functions for WebP images. | 10 //  Main decoding functions for WebP images. | 
| 9 // | 11 // | 
| 10 // Author: Skal (pascal.massimino@gmail.com) | 12 // Author: Skal (pascal.massimino@gmail.com) | 
| 11 | 13 | 
| 12 #ifndef WEBP_WEBP_DECODE_H_ | 14 #ifndef WEBP_WEBP_DECODE_H_ | 
| 13 #define WEBP_WEBP_DECODE_H_ | 15 #define WEBP_WEBP_DECODE_H_ | 
| 14 | 16 | 
| 15 #include "./types.h" | 17 #include "./types.h" | 
| 16 | 18 | 
| 17 #if defined(__cplusplus) || defined(c_plusplus) | 19 #if defined(__cplusplus) || defined(c_plusplus) | 
| 18 extern "C" { | 20 extern "C" { | 
| 19 #endif | 21 #endif | 
| 20 | 22 | 
| 21 #define WEBP_DECODER_ABI_VERSION 0x0201    // MAJOR(8b) + MINOR(8b) | 23 #define WEBP_DECODER_ABI_VERSION 0x0201    // MAJOR(8b) + MINOR(8b) | 
| 22 | 24 | 
|  | 25 // Note: forward declaring enumerations is not allowed in (strict) C and C++, | 
|  | 26 // the types are left here for reference. | 
|  | 27 // typedef enum VP8StatusCode VP8StatusCode; | 
|  | 28 // typedef enum WEBP_CSP_MODE WEBP_CSP_MODE; | 
| 23 typedef struct WebPRGBABuffer WebPRGBABuffer; | 29 typedef struct WebPRGBABuffer WebPRGBABuffer; | 
| 24 typedef struct WebPYUVABuffer WebPYUVABuffer; | 30 typedef struct WebPYUVABuffer WebPYUVABuffer; | 
| 25 typedef struct WebPDecBuffer WebPDecBuffer; | 31 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; | 32 typedef struct WebPIDecoder WebPIDecoder; | 
| 31 typedef struct WebPBitstreamFeatures WebPBitstreamFeatures; | 33 typedef struct WebPBitstreamFeatures WebPBitstreamFeatures; | 
| 32 typedef struct WebPDecoderOptions WebPDecoderOptions; | 34 typedef struct WebPDecoderOptions WebPDecoderOptions; | 
| 33 typedef struct WebPDecoderConfig WebPDecoderConfig; | 35 typedef struct WebPDecoderConfig WebPDecoderConfig; | 
| 34 | 36 | 
| 35 // Return the decoder's version number, packed in hexadecimal using 8bits for | 37 // Return the decoder's version number, packed in hexadecimal using 8bits for | 
| 36 // each of major/minor/revision. E.g: v2.5.7 is 0x020507. | 38 // each of major/minor/revision. E.g: v2.5.7 is 0x020507. | 
| 37 WEBP_EXTERN(int) WebPGetDecoderVersion(void); | 39 WEBP_EXTERN(int) WebPGetDecoderVersion(void); | 
| 38 | 40 | 
| 39 // Retrieve basic header information: width, height. | 41 // Retrieve basic header information: width, height. | 
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 131 // For instance, MODE_BGRA relates to samples ordered as B,G,R,A,B,G,R,A,... | 133 // For instance, MODE_BGRA relates to samples ordered as B,G,R,A,B,G,R,A,... | 
| 132 // Non-capital names (e.g.:MODE_Argb) relates to pre-multiplied RGB channels. | 134 // Non-capital names (e.g.:MODE_Argb) relates to pre-multiplied RGB channels. | 
| 133 // RGBA-4444 and RGB-565 colorspaces are represented by following byte-order: | 135 // RGBA-4444 and RGB-565 colorspaces are represented by following byte-order: | 
| 134 // RGBA-4444: [r3 r2 r1 r0 g3 g2 g1 g0], [b3 b2 b1 b0 a3 a2 a1 a0], ... | 136 // RGBA-4444: [r3 r2 r1 r0 g3 g2 g1 g0], [b3 b2 b1 b0 a3 a2 a1 a0], ... | 
| 135 // RGB-565: [r4 r3 r2 r1 r0 g5 g4 g3], [g2 g1 g0 b4 b3 b2 b1 b0], ... | 137 // RGB-565: [r4 r3 r2 r1 r0 g5 g4 g3], [g2 g1 g0 b4 b3 b2 b1 b0], ... | 
| 136 // In the case WEBP_SWAP_16BITS_CSP is defined, the bytes are swapped for | 138 // In the case WEBP_SWAP_16BITS_CSP is defined, the bytes are swapped for | 
| 137 // these two modes: | 139 // these two modes: | 
| 138 // RGBA-4444: [b3 b2 b1 b0 a3 a2 a1 a0], [r3 r2 r1 r0 g3 g2 g1 g0], ... | 140 // RGBA-4444: [b3 b2 b1 b0 a3 a2 a1 a0], [r3 r2 r1 r0 g3 g2 g1 g0], ... | 
| 139 // RGB-565: [g2 g1 g0 b4 b3 b2 b1 b0], [r4 r3 r2 r1 r0 g5 g4 g3], ... | 141 // RGB-565: [g2 g1 g0 b4 b3 b2 b1 b0], [r4 r3 r2 r1 r0 g5 g4 g3], ... | 
| 140 | 142 | 
| 141 enum WEBP_CSP_MODE { | 143 typedef enum WEBP_CSP_MODE { | 
| 142   MODE_RGB = 0, MODE_RGBA = 1, | 144   MODE_RGB = 0, MODE_RGBA = 1, | 
| 143   MODE_BGR = 2, MODE_BGRA = 3, | 145   MODE_BGR = 2, MODE_BGRA = 3, | 
| 144   MODE_ARGB = 4, MODE_RGBA_4444 = 5, | 146   MODE_ARGB = 4, MODE_RGBA_4444 = 5, | 
| 145   MODE_RGB_565 = 6, | 147   MODE_RGB_565 = 6, | 
| 146   // RGB-premultiplied transparent modes (alpha value is preserved) | 148   // RGB-premultiplied transparent modes (alpha value is preserved) | 
| 147   MODE_rgbA = 7, | 149   MODE_rgbA = 7, | 
| 148   MODE_bgrA = 8, | 150   MODE_bgrA = 8, | 
| 149   MODE_Argb = 9, | 151   MODE_Argb = 9, | 
| 150   MODE_rgbA_4444 = 10, | 152   MODE_rgbA_4444 = 10, | 
| 151   // YUV modes must come after RGB ones. | 153   // YUV modes must come after RGB ones. | 
| 152   MODE_YUV = 11, MODE_YUVA = 12,  // yuv 4:2:0 | 154   MODE_YUV = 11, MODE_YUVA = 12,  // yuv 4:2:0 | 
| 153   MODE_LAST = 13 | 155   MODE_LAST = 13 | 
| 154 }; | 156 } WEBP_CSP_MODE; | 
| 155 | 157 | 
| 156 // Some useful macros: | 158 // Some useful macros: | 
| 157 static WEBP_INLINE int WebPIsPremultipliedMode(WEBP_CSP_MODE mode) { | 159 static WEBP_INLINE int WebPIsPremultipliedMode(WEBP_CSP_MODE mode) { | 
| 158   return (mode == MODE_rgbA || mode == MODE_bgrA || mode == MODE_Argb || | 160   return (mode == MODE_rgbA || mode == MODE_bgrA || mode == MODE_Argb || | 
| 159           mode == MODE_rgbA_4444); | 161           mode == MODE_rgbA_4444); | 
| 160 } | 162 } | 
| 161 | 163 | 
| 162 static WEBP_INLINE int WebPIsAlphaMode(WEBP_CSP_MODE mode) { | 164 static WEBP_INLINE int WebPIsAlphaMode(WEBP_CSP_MODE mode) { | 
| 163   return (mode == MODE_RGBA || mode == MODE_BGRA || mode == MODE_ARGB || | 165   return (mode == MODE_RGBA || mode == MODE_BGRA || mode == MODE_ARGB || | 
| 164           mode == MODE_RGBA_4444 || mode == MODE_YUVA || | 166           mode == MODE_RGBA_4444 || mode == MODE_YUVA || | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 213   return WebPInitDecBufferInternal(buffer, WEBP_DECODER_ABI_VERSION); | 215   return WebPInitDecBufferInternal(buffer, WEBP_DECODER_ABI_VERSION); | 
| 214 } | 216 } | 
| 215 | 217 | 
| 216 // Free any memory associated with the buffer. Must always be called last. | 218 // Free any memory associated with the buffer. Must always be called last. | 
| 217 // Note: doesn't free the 'buffer' structure itself. | 219 // Note: doesn't free the 'buffer' structure itself. | 
| 218 WEBP_EXTERN(void) WebPFreeDecBuffer(WebPDecBuffer* buffer); | 220 WEBP_EXTERN(void) WebPFreeDecBuffer(WebPDecBuffer* buffer); | 
| 219 | 221 | 
| 220 //------------------------------------------------------------------------------ | 222 //------------------------------------------------------------------------------ | 
| 221 // Enumeration of the status codes | 223 // Enumeration of the status codes | 
| 222 | 224 | 
| 223 enum VP8StatusCode { | 225 typedef enum VP8StatusCode { | 
| 224   VP8_STATUS_OK = 0, | 226   VP8_STATUS_OK = 0, | 
| 225   VP8_STATUS_OUT_OF_MEMORY, | 227   VP8_STATUS_OUT_OF_MEMORY, | 
| 226   VP8_STATUS_INVALID_PARAM, | 228   VP8_STATUS_INVALID_PARAM, | 
| 227   VP8_STATUS_BITSTREAM_ERROR, | 229   VP8_STATUS_BITSTREAM_ERROR, | 
| 228   VP8_STATUS_UNSUPPORTED_FEATURE, | 230   VP8_STATUS_UNSUPPORTED_FEATURE, | 
| 229   VP8_STATUS_SUSPENDED, | 231   VP8_STATUS_SUSPENDED, | 
| 230   VP8_STATUS_USER_ABORT, | 232   VP8_STATUS_USER_ABORT, | 
| 231   VP8_STATUS_NOT_ENOUGH_DATA | 233   VP8_STATUS_NOT_ENOUGH_DATA | 
| 232 }; | 234 } VP8StatusCode; | 
| 233 | 235 | 
| 234 //------------------------------------------------------------------------------ | 236 //------------------------------------------------------------------------------ | 
| 235 // Incremental decoding | 237 // Incremental decoding | 
| 236 // | 238 // | 
| 237 // This API allows streamlined decoding of partial data. | 239 // This API allows streamlined decoding of partial data. | 
| 238 // Picture can be incrementally decoded as data become available thanks to the | 240 // Picture can be incrementally decoded as data become available thanks to the | 
| 239 // WebPIDecoder object. This object can be left in a SUSPENDED state if the | 241 // WebPIDecoder object. This object can be left in a SUSPENDED state if the | 
| 240 // picture is only partially decoded, pending additional input. | 242 // picture is only partially decoded, pending additional input. | 
| 241 // Code example: | 243 // Code example: | 
| 242 // | 244 // | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 255 //     // Part of the image can now be refreshed by calling to | 257 //     // Part of the image can now be refreshed by calling to | 
| 256 //     // WebPIDecGetRGB()/WebPIDecGetYUVA() etc. | 258 //     // WebPIDecGetRGB()/WebPIDecGetYUVA() etc. | 
| 257 //   } | 259 //   } | 
| 258 //   WebPIDelete(idec); | 260 //   WebPIDelete(idec); | 
| 259 | 261 | 
| 260 // Creates a new incremental decoder with the supplied buffer parameter. | 262 // Creates a new incremental decoder with the supplied buffer parameter. | 
| 261 // This output_buffer can be passed NULL, in which case a default output buffer | 263 // This output_buffer can be passed NULL, in which case a default output buffer | 
| 262 // is used (with MODE_RGB). Otherwise, an internal reference to 'output_buffer' | 264 // is used (with MODE_RGB). Otherwise, an internal reference to 'output_buffer' | 
| 263 // is kept, which means that the lifespan of 'output_buffer' must be larger than | 265 // is kept, which means that the lifespan of 'output_buffer' must be larger than | 
| 264 // that of the returned WebPIDecoder object. | 266 // that of the returned WebPIDecoder object. | 
|  | 267 // The supplied 'output_buffer' content MUST NOT be changed between calls to | 
|  | 268 // WebPIAppend() or WebPIUpdate() unless 'output_buffer.is_external_memory' is | 
|  | 269 // set to 1. In such a case, it is allowed to modify the pointers, size and | 
|  | 270 // stride of output_buffer.u.RGBA or output_buffer.u.YUVA, provided they remain | 
|  | 271 // within valid bounds. | 
|  | 272 // All other fields of WebPDecBuffer MUST remain constant between calls. | 
| 265 // Returns NULL if the allocation failed. | 273 // Returns NULL if the allocation failed. | 
| 266 WEBP_EXTERN(WebPIDecoder*) WebPINewDecoder(WebPDecBuffer* output_buffer); | 274 WEBP_EXTERN(WebPIDecoder*) WebPINewDecoder(WebPDecBuffer* output_buffer); | 
| 267 | 275 | 
| 268 // This function allocates and initializes an incremental-decoder object, which | 276 // This function allocates and initializes an incremental-decoder object, which | 
| 269 // will output the RGB/A samples specified by 'csp' into a preallocated | 277 // will output the RGB/A samples specified by 'csp' into a preallocated | 
| 270 // buffer 'output_buffer'. The size of this buffer is at least | 278 // buffer 'output_buffer'. The size of this buffer is at least | 
| 271 // 'output_buffer_size' and the stride (distance in bytes between two scanlines) | 279 // 'output_buffer_size' and the stride (distance in bytes between two scanlines) | 
| 272 // is specified by 'output_stride'. | 280 // is specified by 'output_stride'. | 
| 273 // Additionally, output_buffer can be passed NULL in which case the output | 281 // Additionally, output_buffer can be passed NULL in which case the output | 
| 274 // buffer will be allocated automatically when the decoding starts. The | 282 // buffer will be allocated automatically when the decoding starts. The | 
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 473 // 'config' into account. Returns decoding status (which should be VP8_STATUS_OK | 481 // 'config' into account. Returns decoding status (which should be VP8_STATUS_OK | 
| 474 // if the decoding was successful). | 482 // if the decoding was successful). | 
| 475 WEBP_EXTERN(VP8StatusCode) WebPDecode(const uint8_t* data, size_t data_size, | 483 WEBP_EXTERN(VP8StatusCode) WebPDecode(const uint8_t* data, size_t data_size, | 
| 476                                       WebPDecoderConfig* config); | 484                                       WebPDecoderConfig* config); | 
| 477 | 485 | 
| 478 #if defined(__cplusplus) || defined(c_plusplus) | 486 #if defined(__cplusplus) || defined(c_plusplus) | 
| 479 }    // extern "C" | 487 }    // extern "C" | 
| 480 #endif | 488 #endif | 
| 481 | 489 | 
| 482 #endif  /* WEBP_WEBP_DECODE_H_ */ | 490 #endif  /* WEBP_WEBP_DECODE_H_ */ | 
| OLD | NEW | 
|---|