Coverage Report

Created: 2025-12-31 07:15

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