decode.h 23 KB

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