decode.h 22 KB

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