Coverage Report

Created: 2025-11-16 06:41

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