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