Coverage Report

Created: 2025-08-12 07:37

/work/include/webp/mux.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2011 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
//  RIFF container manipulation and encoding for WebP images.
11
//
12
// Authors: Urvang (urvang@google.com)
13
//          Vikas (vikasa@google.com)
14
15
#ifndef WEBP_WEBP_MUX_H_
16
#define WEBP_WEBP_MUX_H_
17
18
#include "./mux_types.h"
19
#include "./types.h"
20
21
#ifdef __cplusplus
22
extern "C" {
23
#endif
24
25
1.44k
#define WEBP_MUX_ABI_VERSION 0x0109  // MAJOR(8b) + MINOR(8b)
26
27
//------------------------------------------------------------------------------
28
// Mux API
29
//
30
// This API allows manipulation of WebP container images containing features
31
// like color profile, metadata, animation.
32
//
33
// Code Example#1: Create a WebPMux object with image data, color profile and
34
// XMP metadata.
35
/*
36
  int copy_data = 0;
37
  WebPMux* mux = WebPMuxNew();
38
  // ... (Prepare image data).
39
  WebPMuxSetImage(mux, &image, copy_data);
40
  // ... (Prepare ICCP color profile data).
41
  WebPMuxSetChunk(mux, "ICCP", &icc_profile, copy_data);
42
  // ... (Prepare XMP metadata).
43
  WebPMuxSetChunk(mux, "XMP ", &xmp, copy_data);
44
  // Get data from mux in WebP RIFF format.
45
  WebPMuxAssemble(mux, &output_data);
46
  WebPMuxDelete(mux);
47
  // ... (Consume output_data; e.g. write output_data.bytes to file).
48
  WebPDataClear(&output_data);
49
*/
50
51
// Code Example#2: Get image and color profile data from a WebP file.
52
/*
53
  int copy_data = 0;
54
  // ... (Read data from file).
55
  WebPMux* mux = WebPMuxCreate(&data, copy_data);
56
  WebPMuxGetFrame(mux, 1, &image);
57
  // ... (Consume image; e.g. call WebPDecode() to decode the data).
58
  WebPMuxGetChunk(mux, "ICCP", &icc_profile);
59
  // ... (Consume icc_data).
60
  WebPMuxDelete(mux);
61
  WebPFree(data);
62
*/
63
64
// Note: forward declaring enumerations is not allowed in (strict) C and C++,
65
// the types are left here for reference.
66
// typedef enum WebPMuxError WebPMuxError;
67
// typedef enum WebPChunkId WebPChunkId;
68
typedef struct WebPMux WebPMux;  // main opaque object.
69
typedef struct WebPMuxFrameInfo WebPMuxFrameInfo;
70
typedef struct WebPMuxAnimParams WebPMuxAnimParams;
71
typedef struct WebPAnimEncoderOptions WebPAnimEncoderOptions;
72
73
// Error codes
74
typedef enum WEBP_NODISCARD WebPMuxError {
75
  WEBP_MUX_OK = 1,
76
  WEBP_MUX_NOT_FOUND = 0,
77
  WEBP_MUX_INVALID_ARGUMENT = -1,
78
  WEBP_MUX_BAD_DATA = -2,
79
  WEBP_MUX_MEMORY_ERROR = -3,
80
  WEBP_MUX_NOT_ENOUGH_DATA = -4
81
} WebPMuxError;
82
83
// IDs for different types of chunks.
84
typedef enum WebPChunkId {
85
  WEBP_CHUNK_VP8X,        // VP8X
86
  WEBP_CHUNK_ICCP,        // ICCP
87
  WEBP_CHUNK_ANIM,        // ANIM
88
  WEBP_CHUNK_ANMF,        // ANMF
89
  WEBP_CHUNK_DEPRECATED,  // (deprecated from FRGM)
90
  WEBP_CHUNK_ALPHA,       // ALPH
91
  WEBP_CHUNK_IMAGE,       // VP8/VP8L
92
  WEBP_CHUNK_EXIF,        // EXIF
93
  WEBP_CHUNK_XMP,         // XMP
94
  WEBP_CHUNK_UNKNOWN,     // Other chunks.
95
  WEBP_CHUNK_NIL
96
} WebPChunkId;
97
98
//------------------------------------------------------------------------------
99
100
// Returns the version number of the mux library, packed in hexadecimal using
101
// 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507.
102
WEBP_EXTERN int WebPGetMuxVersion(void);
103
104
//------------------------------------------------------------------------------
105
// Life of a Mux object
106
107
// Internal, version-checked, entry point
108
WEBP_NODISCARD WEBP_EXTERN WebPMux* WebPNewInternal(int);
109
110
// Creates an empty mux object.
111
// Returns:
112
//   A pointer to the newly created empty mux object.
113
//   Or NULL in case of memory error.
114
0
WEBP_NODISCARD static WEBP_INLINE WebPMux* WebPMuxNew(void) {
115
0
  return WebPNewInternal(WEBP_MUX_ABI_VERSION);
116
0
}
117
118
// Deletes the mux object.
119
// Parameters:
120
//   mux - (in/out) object to be deleted
121
WEBP_EXTERN void WebPMuxDelete(WebPMux* mux);
122
123
//------------------------------------------------------------------------------
124
// Mux creation.
125
126
// Internal, version-checked, entry point
127
WEBP_NODISCARD WEBP_EXTERN WebPMux* WebPMuxCreateInternal(const WebPData*, int,
128
                                                          int);
129
130
// Creates a mux object from raw data given in WebP RIFF format.
131
// Parameters:
132
//   bitstream - (in) the bitstream data in WebP RIFF format
133
//   copy_data - (in) value 1 indicates given data WILL be copied to the mux
134
//               object and value 0 indicates data will NOT be copied. If the
135
//               data is not copied, it must exist for the lifetime of the
136
//               mux object.
137
// Returns:
138
//   A pointer to the mux object created from given data - on success.
139
//   NULL - In case of invalid data or memory error.
140
WEBP_NODISCARD static WEBP_INLINE WebPMux* WebPMuxCreate(
141
1.44k
    const WebPData* bitstream, int copy_data) {
142
1.44k
  return WebPMuxCreateInternal(bitstream, copy_data, WEBP_MUX_ABI_VERSION);
143
1.44k
}
144
145
//------------------------------------------------------------------------------
146
// Non-image chunks.
147
148
// Note: Only non-image related chunks should be managed through chunk APIs.
149
// (Image related chunks are: "ANMF", "VP8 ", "VP8L" and "ALPH").
150
// To add, get and delete images, use WebPMuxSetImage(), WebPMuxPushFrame(),
151
// WebPMuxGetFrame() and WebPMuxDeleteFrame().
152
153
// Adds a chunk with id 'fourcc' and data 'chunk_data' in the mux object.
154
// Any existing chunk(s) with the same id will be removed.
155
// Parameters:
156
//   mux - (in/out) object to which the chunk is to be added
157
//   fourcc - (in) a character array containing the fourcc of the given chunk;
158
//                 e.g., "ICCP", "XMP ", "EXIF" etc.
159
//   chunk_data - (in) the chunk data to be added
160
//   copy_data - (in) value 1 indicates given data WILL be copied to the mux
161
//               object and value 0 indicates data will NOT be copied. If the
162
//               data is not copied, it must exist until a call to
163
//               WebPMuxAssemble() is made.
164
// Returns:
165
//   WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL
166
//                               or if fourcc corresponds to an image chunk.
167
//   WEBP_MUX_MEMORY_ERROR - on memory allocation error.
168
//   WEBP_MUX_OK - on success.
169
WEBP_EXTERN WebPMuxError WebPMuxSetChunk(WebPMux* mux, const char fourcc[4],
170
                                         const WebPData* chunk_data,
171
                                         int copy_data);
172
173
// Gets a reference to the data of the chunk with id 'fourcc' in the mux object.
174
// The caller should NOT free the returned data.
175
// Parameters:
176
//   mux - (in) object from which the chunk data is to be fetched
177
//   fourcc - (in) a character array containing the fourcc of the chunk;
178
//                 e.g., "ICCP", "XMP ", "EXIF" etc.
179
//   chunk_data - (out) returned chunk data
180
// Returns:
181
//   WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL
182
//                               or if fourcc corresponds to an image chunk.
183
//   WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given id.
184
//   WEBP_MUX_OK - on success.
185
WEBP_EXTERN WebPMuxError WebPMuxGetChunk(const WebPMux* mux,
186
                                         const char fourcc[4],
187
                                         WebPData* chunk_data);
188
189
// Deletes the chunk with the given 'fourcc' from the mux object.
190
// Parameters:
191
//   mux - (in/out) object from which the chunk is to be deleted
192
//   fourcc - (in) a character array containing the fourcc of the chunk;
193
//                 e.g., "ICCP", "XMP ", "EXIF" etc.
194
// Returns:
195
//   WEBP_MUX_INVALID_ARGUMENT - if mux or fourcc is NULL
196
//                               or if fourcc corresponds to an image chunk.
197
//   WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given fourcc.
198
//   WEBP_MUX_OK - on success.
199
WEBP_EXTERN WebPMuxError WebPMuxDeleteChunk(WebPMux* mux, const char fourcc[4]);
200
201
//------------------------------------------------------------------------------
202
// Images.
203
204
// Encapsulates data about a single frame.
205
struct WebPMuxFrameInfo {
206
  WebPData bitstream;  // image data: can be a raw VP8/VP8L bitstream
207
                       // or a single-image WebP file.
208
  int x_offset;        // x-offset of the frame.
209
  int y_offset;        // y-offset of the frame.
210
  int duration;        // duration of the frame (in milliseconds).
211
212
  WebPChunkId id;  // frame type: should be one of WEBP_CHUNK_ANMF
213
                   // or WEBP_CHUNK_IMAGE
214
  WebPMuxAnimDispose dispose_method;  // Disposal method for the frame.
215
  WebPMuxAnimBlend blend_method;      // Blend operation for the frame.
216
  uint32_t pad[1];                    // padding for later use
217
};
218
219
// Sets the (non-animated) image in the mux object.
220
// Note: Any existing images (including frames) will be removed.
221
// Parameters:
222
//   mux - (in/out) object in which the image is to be set
223
//   bitstream - (in) can be a raw VP8/VP8L bitstream or a single-image
224
//               WebP file (non-animated)
225
//   copy_data - (in) value 1 indicates given data WILL be copied to the mux
226
//               object and value 0 indicates data will NOT be copied. If the
227
//               data is not copied, it must exist until a call to
228
//               WebPMuxAssemble() is made.
229
// Returns:
230
//   WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or bitstream is NULL.
231
//   WEBP_MUX_MEMORY_ERROR - on memory allocation error.
232
//   WEBP_MUX_OK - on success.
233
WEBP_EXTERN WebPMuxError WebPMuxSetImage(WebPMux* mux,
234
                                         const WebPData* bitstream,
235
                                         int copy_data);
236
237
// Adds a frame at the end of the mux object.
238
// Notes: (1) frame.id should be WEBP_CHUNK_ANMF
239
//        (2) For setting a non-animated image, use WebPMuxSetImage() instead.
240
//        (3) Type of frame being pushed must be same as the frames in mux.
241
//        (4) As WebP only supports even offsets, any odd offset will be snapped
242
//            to an even location using: offset &= ~1
243
// Parameters:
244
//   mux - (in/out) object to which the frame is to be added
245
//   frame - (in) frame data.
246
//   copy_data - (in) value 1 indicates given data WILL be copied to the mux
247
//               object and value 0 indicates data will NOT be copied. If the
248
//               data is not copied, it must exist until a call to
249
//               WebPMuxAssemble() is made.
250
// Returns:
251
//   WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL
252
//                               or if content of 'frame' is invalid.
253
//   WEBP_MUX_MEMORY_ERROR - on memory allocation error.
254
//   WEBP_MUX_OK - on success.
255
WEBP_EXTERN WebPMuxError WebPMuxPushFrame(WebPMux* mux,
256
                                          const WebPMuxFrameInfo* frame,
257
                                          int copy_data);
258
259
// Gets the nth frame from the mux object.
260
// The content of 'frame->bitstream' is allocated using WebPMalloc(), and NOT
261
// owned by the 'mux' object. It MUST be deallocated by the caller by calling
262
// WebPDataClear().
263
// nth=0 has a special meaning - last position.
264
// Parameters:
265
//   mux - (in) object from which the info is to be fetched
266
//   nth - (in) index of the frame in the mux object
267
//   frame - (out) data of the returned frame
268
// Returns:
269
//   WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL.
270
//   WEBP_MUX_NOT_FOUND - if there are less than nth frames in the mux object.
271
//   WEBP_MUX_BAD_DATA - if nth frame chunk in mux is invalid.
272
//   WEBP_MUX_MEMORY_ERROR - on memory allocation error.
273
//   WEBP_MUX_OK - on success.
274
WEBP_EXTERN WebPMuxError WebPMuxGetFrame(const WebPMux* mux, uint32_t nth,
275
                                         WebPMuxFrameInfo* frame);
276
277
// Deletes a frame from the mux object.
278
// nth=0 has a special meaning - last position.
279
// Parameters:
280
//   mux - (in/out) object from which a frame is to be deleted
281
//   nth - (in) The position from which the frame is to be deleted
282
// Returns:
283
//   WEBP_MUX_INVALID_ARGUMENT - if mux is NULL.
284
//   WEBP_MUX_NOT_FOUND - If there are less than nth frames in the mux object
285
//                        before deletion.
286
//   WEBP_MUX_OK - on success.
287
WEBP_EXTERN WebPMuxError WebPMuxDeleteFrame(WebPMux* mux, uint32_t nth);
288
289
//------------------------------------------------------------------------------
290
// Animation.
291
292
// Animation parameters.
293
struct WebPMuxAnimParams {
294
  uint32_t bgcolor;  // Background color of the canvas stored (in MSB order) as:
295
                     // Bits 00 to 07: Alpha.
296
                     // Bits 08 to 15: Red.
297
                     // Bits 16 to 23: Green.
298
                     // Bits 24 to 31: Blue.
299
  int loop_count;    // Number of times to repeat the animation [0 = infinite].
300
};
301
302
// Sets the animation parameters in the mux object. Any existing ANIM chunks
303
// will be removed.
304
// Parameters:
305
//   mux - (in/out) object in which ANIM chunk is to be set/added
306
//   params - (in) animation parameters.
307
// Returns:
308
//   WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL.
309
//   WEBP_MUX_MEMORY_ERROR - on memory allocation error.
310
//   WEBP_MUX_OK - on success.
311
WEBP_EXTERN WebPMuxError
312
WebPMuxSetAnimationParams(WebPMux* mux, const WebPMuxAnimParams* params);
313
314
// Gets the animation parameters from the mux object.
315
// Parameters:
316
//   mux - (in) object from which the animation parameters to be fetched
317
//   params - (out) animation parameters extracted from the ANIM chunk
318
// Returns:
319
//   WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL.
320
//   WEBP_MUX_NOT_FOUND - if ANIM chunk is not present in mux object.
321
//   WEBP_MUX_OK - on success.
322
WEBP_EXTERN WebPMuxError WebPMuxGetAnimationParams(const WebPMux* mux,
323
                                                   WebPMuxAnimParams* params);
324
325
//------------------------------------------------------------------------------
326
// Misc Utilities.
327
328
// Sets the canvas size for the mux object. The width and height can be
329
// specified explicitly or left as zero (0, 0).
330
// * When width and height are specified explicitly, then this frame bound is
331
//   enforced during subsequent calls to WebPMuxAssemble() and an error is
332
//   reported if any animated frame does not completely fit within the canvas.
333
// * When unspecified (0, 0), the constructed canvas will get the frame bounds
334
//   from the bounding-box over all frames after calling WebPMuxAssemble().
335
// Parameters:
336
//   mux - (in) object to which the canvas size is to be set
337
//   width - (in) canvas width
338
//   height - (in) canvas height
339
// Returns:
340
//   WEBP_MUX_INVALID_ARGUMENT - if mux is NULL; or
341
//                               width or height are invalid or out of bounds
342
//   WEBP_MUX_OK - on success.
343
WEBP_EXTERN WebPMuxError WebPMuxSetCanvasSize(WebPMux* mux, int width,
344
                                              int height);
345
346
// Gets the canvas size from the mux object.
347
// Note: This method assumes that the VP8X chunk, if present, is up-to-date.
348
// That is, the mux object hasn't been modified since the last call to
349
// WebPMuxAssemble() or WebPMuxCreate().
350
// Parameters:
351
//   mux - (in) object from which the canvas size is to be fetched
352
//   width - (out) canvas width
353
//   height - (out) canvas height
354
// Returns:
355
//   WEBP_MUX_INVALID_ARGUMENT - if mux, width or height is NULL.
356
//   WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid.
357
//   WEBP_MUX_OK - on success.
358
WEBP_EXTERN WebPMuxError WebPMuxGetCanvasSize(const WebPMux* mux, int* width,
359
                                              int* height);
360
361
// Gets the feature flags from the mux object.
362
// Note: This method assumes that the VP8X chunk, if present, is up-to-date.
363
// That is, the mux object hasn't been modified since the last call to
364
// WebPMuxAssemble() or WebPMuxCreate().
365
// Parameters:
366
//   mux - (in) object from which the features are to be fetched
367
//   flags - (out) the flags specifying which features are present in the
368
//           mux object. This will be an OR of various flag values.
369
//           Enum 'WebPFeatureFlags' can be used to test individual flag values.
370
// Returns:
371
//   WEBP_MUX_INVALID_ARGUMENT - if mux or flags is NULL.
372
//   WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid.
373
//   WEBP_MUX_OK - on success.
374
WEBP_EXTERN WebPMuxError WebPMuxGetFeatures(const WebPMux* mux,
375
                                            uint32_t* flags);
376
377
// Gets number of chunks with the given 'id' in the mux object.
378
// Parameters:
379
//   mux - (in) object from which the info is to be fetched
380
//   id - (in) chunk id specifying the type of chunk
381
//   num_elements - (out) number of chunks with the given chunk id
382
// Returns:
383
//   WEBP_MUX_INVALID_ARGUMENT - if mux, or num_elements is NULL.
384
//   WEBP_MUX_OK - on success.
385
WEBP_EXTERN WebPMuxError WebPMuxNumChunks(const WebPMux* mux, WebPChunkId id,
386
                                          int* num_elements);
387
388
// Assembles all chunks in WebP RIFF format and returns in 'assembled_data'.
389
// This function also validates the mux object.
390
// Note: The content of 'assembled_data' will be ignored and overwritten.
391
// Also, the content of 'assembled_data' is allocated using WebPMalloc(), and
392
// NOT owned by the 'mux' object. It MUST be deallocated by the caller by
393
// calling WebPDataClear(). It's always safe to call WebPDataClear() upon
394
// return, even in case of error.
395
// Parameters:
396
//   mux - (in/out) object whose chunks are to be assembled
397
//   assembled_data - (out) assembled WebP data
398
// Returns:
399
//   WEBP_MUX_BAD_DATA - if mux object is invalid.
400
//   WEBP_MUX_INVALID_ARGUMENT - if mux or assembled_data is NULL.
401
//   WEBP_MUX_MEMORY_ERROR - on memory allocation error.
402
//   WEBP_MUX_OK - on success.
403
WEBP_EXTERN WebPMuxError WebPMuxAssemble(WebPMux* mux,
404
                                         WebPData* assembled_data);
405
406
//------------------------------------------------------------------------------
407
// WebPAnimEncoder API
408
//
409
// This API allows encoding (possibly) animated WebP images.
410
//
411
// Code Example:
412
/*
413
  WebPAnimEncoderOptions enc_options;
414
  WebPAnimEncoderOptionsInit(&enc_options);
415
  // Tune 'enc_options' as needed.
416
  WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, &enc_options);
417
  while(<there are more frames>) {
418
    WebPConfig config;
419
    WebPConfigInit(&config);
420
    // Tune 'config' as needed.
421
    WebPAnimEncoderAdd(enc, frame, timestamp_ms, &config);
422
  }
423
  WebPAnimEncoderAdd(enc, NULL, timestamp_ms, NULL);
424
  WebPAnimEncoderAssemble(enc, webp_data);
425
  WebPAnimEncoderDelete(enc);
426
  // Write the 'webp_data' to a file, or re-mux it further.
427
*/
428
429
typedef struct WebPAnimEncoder WebPAnimEncoder;  // Main opaque object.
430
431
// Forward declarations. Defined in encode.h.
432
struct WebPPicture;
433
struct WebPConfig;
434
435
// Global options.
436
struct WebPAnimEncoderOptions {
437
  WebPMuxAnimParams anim_params;  // Animation parameters.
438
  int minimize_size;  // If true, minimize the output size (slow). Implicitly
439
                      // disables key-frame insertion.
440
  int kmin;
441
  int kmax;         // Minimum and maximum distance between consecutive key
442
                    // frames in the output. The library may insert some key
443
                    // frames as needed to satisfy this criteria.
444
                    // Note that these conditions should hold: kmax > kmin
445
                    // and kmin >= kmax / 2 + 1. Also, if kmax <= 0, then
446
                    // key-frame insertion is disabled; and if kmax == 1,
447
                    // then all frames will be key-frames (kmin value does
448
                    // not matter for these special cases).
449
  int allow_mixed;  // If true, use mixed compression mode; may choose
450
                    // either lossy and lossless for each frame.
451
  int verbose;      // If true, print info and warning messages to stderr.
452
453
  uint32_t padding[4];  // Padding for later use.
454
};
455
456
// Internal, version-checked, entry point.
457
WEBP_EXTERN int WebPAnimEncoderOptionsInitInternal(WebPAnimEncoderOptions*,
458
                                                   int);
459
460
// Should always be called, to initialize a fresh WebPAnimEncoderOptions
461
// structure before modification. Returns false in case of version mismatch.
462
// WebPAnimEncoderOptionsInit() must have succeeded before using the
463
// 'enc_options' object.
464
WEBP_NODISCARD static WEBP_INLINE int WebPAnimEncoderOptionsInit(
465
0
    WebPAnimEncoderOptions* enc_options) {
466
0
  return WebPAnimEncoderOptionsInitInternal(enc_options, WEBP_MUX_ABI_VERSION);
467
0
}
468
469
// Internal, version-checked, entry point.
470
WEBP_EXTERN WebPAnimEncoder* WebPAnimEncoderNewInternal(
471
    int, int, const WebPAnimEncoderOptions*, int);
472
473
// Creates and initializes a WebPAnimEncoder object.
474
// Parameters:
475
//   width/height - (in) canvas width and height of the animation.
476
//   enc_options - (in) encoding options; can be passed NULL to pick
477
//                      reasonable defaults.
478
// Returns:
479
//   A pointer to the newly created WebPAnimEncoder object.
480
//   Or NULL in case of memory error.
481
static WEBP_INLINE WebPAnimEncoder* WebPAnimEncoderNew(
482
0
    int width, int height, const WebPAnimEncoderOptions* enc_options) {
483
0
  return WebPAnimEncoderNewInternal(width, height, enc_options,
484
0
                                    WEBP_MUX_ABI_VERSION);
485
0
}
486
487
// Optimize the given frame for WebP, encode it and add it to the
488
// WebPAnimEncoder object.
489
// The last call to 'WebPAnimEncoderAdd' should be with frame = NULL, which
490
// indicates that no more frames are to be added. This call is also used to
491
// determine the duration of the last frame.
492
// Parameters:
493
//   enc - (in/out) object to which the frame is to be added.
494
//   frame - (in/out) frame data in ARGB or YUV(A) format. If it is in YUV(A)
495
//           format, it will be converted to ARGB, which incurs a small loss.
496
//   timestamp_ms - (in) timestamp of this frame in milliseconds.
497
//                       Duration of a frame would be calculated as
498
//                       "timestamp of next frame - timestamp of this frame".
499
//                       Hence, timestamps should be in non-decreasing order.
500
//   config - (in) encoding options; can be passed NULL to pick
501
//            reasonable defaults.
502
// Returns:
503
//   On error, returns false and frame->error_code is set appropriately.
504
//   Otherwise, returns true.
505
WEBP_NODISCARD WEBP_EXTERN int WebPAnimEncoderAdd(
506
    WebPAnimEncoder* enc, struct WebPPicture* frame, int timestamp_ms,
507
    const struct WebPConfig* config);
508
509
// Assemble all frames added so far into a WebP bitstream.
510
// This call should be preceded by  a call to 'WebPAnimEncoderAdd' with
511
// frame = NULL; if not, the duration of the last frame will be internally
512
// estimated.
513
// Parameters:
514
//   enc - (in/out) object from which the frames are to be assembled.
515
//   webp_data - (out) generated WebP bitstream.
516
// Returns:
517
//   True on success.
518
WEBP_NODISCARD WEBP_EXTERN int WebPAnimEncoderAssemble(WebPAnimEncoder* enc,
519
                                                       WebPData* webp_data);
520
521
// Get error string corresponding to the most recent call using 'enc'. The
522
// returned string is owned by 'enc' and is valid only until the next call to
523
// WebPAnimEncoderAdd() or WebPAnimEncoderAssemble() or WebPAnimEncoderDelete().
524
// Parameters:
525
//   enc - (in/out) object from which the error string is to be fetched.
526
// Returns:
527
//   NULL if 'enc' is NULL. Otherwise, returns the error string if the last call
528
//   to 'enc' had an error, or an empty string if the last call was a success.
529
WEBP_EXTERN const char* WebPAnimEncoderGetError(WebPAnimEncoder* enc);
530
531
// Deletes the WebPAnimEncoder object.
532
// Parameters:
533
//   enc - (in/out) object to be deleted
534
WEBP_EXTERN void WebPAnimEncoderDelete(WebPAnimEncoder* enc);
535
536
//------------------------------------------------------------------------------
537
// Non-image chunks.
538
539
// Note: Only non-image related chunks should be managed through chunk APIs.
540
// (Image related chunks are: "ANMF", "VP8 ", "VP8L" and "ALPH").
541
542
// Adds a chunk with id 'fourcc' and data 'chunk_data' in the enc object.
543
// Any existing chunk(s) with the same id will be removed.
544
// Parameters:
545
//   enc - (in/out) object to which the chunk is to be added
546
//   fourcc - (in) a character array containing the fourcc of the given chunk;
547
//                 e.g., "ICCP", "XMP ", "EXIF", etc.
548
//   chunk_data - (in) the chunk data to be added
549
//   copy_data - (in) value 1 indicates given data WILL be copied to the enc
550
//               object and value 0 indicates data will NOT be copied. If the
551
//               data is not copied, it must exist until a call to
552
//               WebPAnimEncoderAssemble() is made.
553
// Returns:
554
//   WEBP_MUX_INVALID_ARGUMENT - if enc, fourcc or chunk_data is NULL.
555
//   WEBP_MUX_MEMORY_ERROR - on memory allocation error.
556
//   WEBP_MUX_OK - on success.
557
WEBP_EXTERN WebPMuxError WebPAnimEncoderSetChunk(WebPAnimEncoder* enc,
558
                                                 const char fourcc[4],
559
                                                 const WebPData* chunk_data,
560
                                                 int copy_data);
561
562
// Gets a reference to the data of the chunk with id 'fourcc' in the enc object.
563
// The caller should NOT free the returned data.
564
// Parameters:
565
//   enc - (in) object from which the chunk data is to be fetched
566
//   fourcc - (in) a character array containing the fourcc of the chunk;
567
//                 e.g., "ICCP", "XMP ", "EXIF", etc.
568
//   chunk_data - (out) returned chunk data
569
// Returns:
570
//   WEBP_MUX_INVALID_ARGUMENT - if enc, fourcc or chunk_data is NULL.
571
//   WEBP_MUX_NOT_FOUND - If enc does not contain a chunk with the given id.
572
//   WEBP_MUX_OK - on success.
573
WEBP_EXTERN WebPMuxError WebPAnimEncoderGetChunk(const WebPAnimEncoder* enc,
574
                                                 const char fourcc[4],
575
                                                 WebPData* chunk_data);
576
577
// Deletes the chunk with the given 'fourcc' from the enc object.
578
// Parameters:
579
//   enc - (in/out) object from which the chunk is to be deleted
580
//   fourcc - (in) a character array containing the fourcc of the chunk;
581
//                 e.g., "ICCP", "XMP ", "EXIF", etc.
582
// Returns:
583
//   WEBP_MUX_INVALID_ARGUMENT - if enc or fourcc is NULL.
584
//   WEBP_MUX_NOT_FOUND - If enc does not contain a chunk with the given fourcc.
585
//   WEBP_MUX_OK - on success.
586
WEBP_EXTERN WebPMuxError WebPAnimEncoderDeleteChunk(WebPAnimEncoder* enc,
587
                                                    const char fourcc[4]);
588
589
//------------------------------------------------------------------------------
590
591
#ifdef __cplusplus
592
}  // extern "C"
593
#endif
594
595
#endif  // WEBP_WEBP_MUX_H_