annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/webp/mux.h @ 69:33d812a61356

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