mux.h (25966B)
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 #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 WEBP_NODISCARD static WEBP_INLINE WebPMux* WebPMuxNew(void) { 115 return WebPNewInternal(WEBP_MUX_ABI_VERSION); 116 } 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 const WebPData* bitstream, int copy_data) { 142 return WebPMuxCreateInternal(bitstream, copy_data, WEBP_MUX_ABI_VERSION); 143 } 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( 170 WebPMux* mux, const char fourcc[4], 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( 186 const WebPMux* mux, const char fourcc[4], WebPData* chunk_data); 187 188 // Deletes the chunk with the given 'fourcc' from the mux object. 189 // Parameters: 190 // mux - (in/out) object from which the chunk is to be deleted 191 // fourcc - (in) a character array containing the fourcc of the chunk; 192 // e.g., "ICCP", "XMP ", "EXIF" etc. 193 // Returns: 194 // WEBP_MUX_INVALID_ARGUMENT - if mux or fourcc is NULL 195 // or if fourcc corresponds to an image chunk. 196 // WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given fourcc. 197 // WEBP_MUX_OK - on success. 198 WEBP_EXTERN WebPMuxError WebPMuxDeleteChunk( 199 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( 234 WebPMux* mux, const WebPData* bitstream, int copy_data); 235 236 // Adds a frame at the end of the mux object. 237 // Notes: (1) frame.id should be WEBP_CHUNK_ANMF 238 // (2) For setting a non-animated image, use WebPMuxSetImage() instead. 239 // (3) Type of frame being pushed must be same as the frames in mux. 240 // (4) As WebP only supports even offsets, any odd offset will be snapped 241 // to an even location using: offset &= ~1 242 // Parameters: 243 // mux - (in/out) object to which the frame is to be added 244 // frame - (in) frame data. 245 // copy_data - (in) value 1 indicates given data WILL be copied to the mux 246 // object and value 0 indicates data will NOT be copied. If the 247 // data is not copied, it must exist until a call to 248 // WebPMuxAssemble() is made. 249 // Returns: 250 // WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL 251 // or if content of 'frame' is invalid. 252 // WEBP_MUX_MEMORY_ERROR - on memory allocation error. 253 // WEBP_MUX_OK - on success. 254 WEBP_EXTERN WebPMuxError WebPMuxPushFrame( 255 WebPMux* mux, const WebPMuxFrameInfo* frame, int copy_data); 256 257 // Gets the nth frame from the mux object. 258 // The content of 'frame->bitstream' is allocated using WebPMalloc(), and NOT 259 // owned by the 'mux' object. It MUST be deallocated by the caller by calling 260 // WebPDataClear(). 261 // nth=0 has a special meaning - last position. 262 // Parameters: 263 // mux - (in) object from which the info is to be fetched 264 // nth - (in) index of the frame in the mux object 265 // frame - (out) data of the returned frame 266 // Returns: 267 // WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL. 268 // WEBP_MUX_NOT_FOUND - if there are less than nth frames in the mux object. 269 // WEBP_MUX_BAD_DATA - if nth frame chunk in mux is invalid. 270 // WEBP_MUX_MEMORY_ERROR - on memory allocation error. 271 // WEBP_MUX_OK - on success. 272 WEBP_EXTERN WebPMuxError WebPMuxGetFrame( 273 const WebPMux* mux, uint32_t nth, WebPMuxFrameInfo* frame); 274 275 // Deletes a frame from the mux object. 276 // nth=0 has a special meaning - last position. 277 // Parameters: 278 // mux - (in/out) object from which a frame is to be deleted 279 // nth - (in) The position from which the frame is to be deleted 280 // Returns: 281 // WEBP_MUX_INVALID_ARGUMENT - if mux is NULL. 282 // WEBP_MUX_NOT_FOUND - If there are less than nth frames in the mux object 283 // before deletion. 284 // WEBP_MUX_OK - on success. 285 WEBP_EXTERN WebPMuxError WebPMuxDeleteFrame(WebPMux* mux, uint32_t nth); 286 287 //------------------------------------------------------------------------------ 288 // Animation. 289 290 // Animation parameters. 291 struct WebPMuxAnimParams { 292 uint32_t bgcolor; // Background color of the canvas stored (in MSB order) as: 293 // Bits 00 to 07: Alpha. 294 // Bits 08 to 15: Red. 295 // Bits 16 to 23: Green. 296 // Bits 24 to 31: Blue. 297 int loop_count; // Number of times to repeat the animation [0 = infinite]. 298 }; 299 300 // Sets the animation parameters in the mux object. Any existing ANIM chunks 301 // will be removed. 302 // Parameters: 303 // mux - (in/out) object in which ANIM chunk is to be set/added 304 // params - (in) animation parameters. 305 // Returns: 306 // WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL. 307 // WEBP_MUX_MEMORY_ERROR - on memory allocation error. 308 // WEBP_MUX_OK - on success. 309 WEBP_EXTERN WebPMuxError WebPMuxSetAnimationParams( 310 WebPMux* mux, const WebPMuxAnimParams* params); 311 312 // Gets the animation parameters from the mux object. 313 // Parameters: 314 // mux - (in) object from which the animation parameters to be fetched 315 // params - (out) animation parameters extracted from the ANIM chunk 316 // Returns: 317 // WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL. 318 // WEBP_MUX_NOT_FOUND - if ANIM chunk is not present in mux object. 319 // WEBP_MUX_OK - on success. 320 WEBP_EXTERN WebPMuxError WebPMuxGetAnimationParams( 321 const WebPMux* mux, WebPMuxAnimParams* params); 322 323 //------------------------------------------------------------------------------ 324 // Misc Utilities. 325 326 // Sets the canvas size for the mux object. The width and height can be 327 // specified explicitly or left as zero (0, 0). 328 // * When width and height are specified explicitly, then this frame bound is 329 // enforced during subsequent calls to WebPMuxAssemble() and an error is 330 // reported if any animated frame does not completely fit within the canvas. 331 // * When unspecified (0, 0), the constructed canvas will get the frame bounds 332 // from the bounding-box over all frames after calling WebPMuxAssemble(). 333 // Parameters: 334 // mux - (in) object to which the canvas size is to be set 335 // width - (in) canvas width 336 // height - (in) canvas height 337 // Returns: 338 // WEBP_MUX_INVALID_ARGUMENT - if mux is NULL; or 339 // width or height are invalid or out of bounds 340 // WEBP_MUX_OK - on success. 341 WEBP_EXTERN WebPMuxError WebPMuxSetCanvasSize(WebPMux* mux, 342 int width, int height); 343 344 // Gets the canvas size from the mux object. 345 // Note: This method assumes that the VP8X chunk, if present, is up-to-date. 346 // That is, the mux object hasn't been modified since the last call to 347 // WebPMuxAssemble() or WebPMuxCreate(). 348 // Parameters: 349 // mux - (in) object from which the canvas size is to be fetched 350 // width - (out) canvas width 351 // height - (out) canvas height 352 // Returns: 353 // WEBP_MUX_INVALID_ARGUMENT - if mux, width or height is NULL. 354 // WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid. 355 // WEBP_MUX_OK - on success. 356 WEBP_EXTERN WebPMuxError WebPMuxGetCanvasSize(const WebPMux* mux, 357 int* width, int* height); 358 359 // Gets the feature flags from the mux object. 360 // Note: This method assumes that the VP8X chunk, if present, is up-to-date. 361 // That is, the mux object hasn't been modified since the last call to 362 // WebPMuxAssemble() or WebPMuxCreate(). 363 // Parameters: 364 // mux - (in) object from which the features are to be fetched 365 // flags - (out) the flags specifying which features are present in the 366 // mux object. This will be an OR of various flag values. 367 // Enum 'WebPFeatureFlags' can be used to test individual flag values. 368 // Returns: 369 // WEBP_MUX_INVALID_ARGUMENT - if mux or flags is NULL. 370 // WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid. 371 // WEBP_MUX_OK - on success. 372 WEBP_EXTERN WebPMuxError WebPMuxGetFeatures(const WebPMux* mux, 373 uint32_t* flags); 374 375 // Gets number of chunks with the given 'id' in the mux object. 376 // Parameters: 377 // mux - (in) object from which the info is to be fetched 378 // id - (in) chunk id specifying the type of chunk 379 // num_elements - (out) number of chunks with the given chunk id 380 // Returns: 381 // WEBP_MUX_INVALID_ARGUMENT - if mux, or num_elements is NULL. 382 // WEBP_MUX_OK - on success. 383 WEBP_EXTERN WebPMuxError WebPMuxNumChunks(const WebPMux* mux, 384 WebPChunkId id, int* num_elements); 385 386 // Assembles all chunks in WebP RIFF format and returns in 'assembled_data'. 387 // This function also validates the mux object. 388 // Note: The content of 'assembled_data' will be ignored and overwritten. 389 // Also, the content of 'assembled_data' is allocated using WebPMalloc(), and 390 // NOT owned by the 'mux' object. It MUST be deallocated by the caller by 391 // calling WebPDataClear(). It's always safe to call WebPDataClear() upon 392 // return, even in case of error. 393 // Parameters: 394 // mux - (in/out) object whose chunks are to be assembled 395 // assembled_data - (out) assembled WebP data 396 // Returns: 397 // WEBP_MUX_BAD_DATA - if mux object is invalid. 398 // WEBP_MUX_INVALID_ARGUMENT - if mux or assembled_data is NULL. 399 // WEBP_MUX_MEMORY_ERROR - on memory allocation error. 400 // WEBP_MUX_OK - on success. 401 WEBP_EXTERN WebPMuxError WebPMuxAssemble(WebPMux* mux, 402 WebPData* assembled_data); 403 404 //------------------------------------------------------------------------------ 405 // WebPAnimEncoder API 406 // 407 // This API allows encoding (possibly) animated WebP images. 408 // 409 // Code Example: 410 /* 411 WebPAnimEncoderOptions enc_options; 412 WebPAnimEncoderOptionsInit(&enc_options); 413 // Tune 'enc_options' as needed. 414 WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, &enc_options); 415 while(<there are more frames>) { 416 WebPConfig config; 417 WebPConfigInit(&config); 418 // Tune 'config' as needed. 419 WebPAnimEncoderAdd(enc, frame, timestamp_ms, &config); 420 } 421 WebPAnimEncoderAdd(enc, NULL, timestamp_ms, NULL); 422 WebPAnimEncoderAssemble(enc, webp_data); 423 WebPAnimEncoderDelete(enc); 424 // Write the 'webp_data' to a file, or re-mux it further. 425 */ 426 427 typedef struct WebPAnimEncoder WebPAnimEncoder; // Main opaque object. 428 429 // Forward declarations. Defined in encode.h. 430 struct WebPPicture; 431 struct WebPConfig; 432 433 // Global options. 434 struct WebPAnimEncoderOptions { 435 WebPMuxAnimParams anim_params; // Animation parameters. 436 int minimize_size; // If true, minimize the output size (slow). Implicitly 437 // disables key-frame insertion. 438 int kmin; 439 int kmax; // Minimum and maximum distance between consecutive key 440 // frames in the output. The library may insert some key 441 // frames as needed to satisfy this criteria. 442 // Note that these conditions should hold: kmax > kmin 443 // and kmin >= kmax / 2 + 1. Also, if kmax <= 0, then 444 // key-frame insertion is disabled; and if kmax == 1, 445 // then all frames will be key-frames (kmin value does 446 // not matter for these special cases). 447 int allow_mixed; // If true, use mixed compression mode; may choose 448 // either lossy and lossless for each frame. 449 int verbose; // If true, print info and warning messages to stderr. 450 451 uint32_t padding[4]; // Padding for later use. 452 }; 453 454 // Internal, version-checked, entry point. 455 WEBP_EXTERN int WebPAnimEncoderOptionsInitInternal( 456 WebPAnimEncoderOptions*, int); 457 458 // Should always be called, to initialize a fresh WebPAnimEncoderOptions 459 // structure before modification. Returns false in case of version mismatch. 460 // WebPAnimEncoderOptionsInit() must have succeeded before using the 461 // 'enc_options' object. 462 WEBP_NODISCARD static WEBP_INLINE int WebPAnimEncoderOptionsInit( 463 WebPAnimEncoderOptions* enc_options) { 464 return WebPAnimEncoderOptionsInitInternal(enc_options, WEBP_MUX_ABI_VERSION); 465 } 466 467 // Internal, version-checked, entry point. 468 WEBP_EXTERN WebPAnimEncoder* WebPAnimEncoderNewInternal( 469 int, int, const WebPAnimEncoderOptions*, int); 470 471 // Creates and initializes a WebPAnimEncoder object. 472 // Parameters: 473 // width/height - (in) canvas width and height of the animation. 474 // enc_options - (in) encoding options; can be passed NULL to pick 475 // reasonable defaults. 476 // Returns: 477 // A pointer to the newly created WebPAnimEncoder object. 478 // Or NULL in case of memory error. 479 static WEBP_INLINE WebPAnimEncoder* WebPAnimEncoderNew( 480 int width, int height, const WebPAnimEncoderOptions* enc_options) { 481 return WebPAnimEncoderNewInternal(width, height, enc_options, 482 WEBP_MUX_ABI_VERSION); 483 } 484 485 // Optimize the given frame for WebP, encode it and add it to the 486 // WebPAnimEncoder object. 487 // The last call to 'WebPAnimEncoderAdd' should be with frame = NULL, which 488 // indicates that no more frames are to be added. This call is also used to 489 // determine the duration of the last frame. 490 // Parameters: 491 // enc - (in/out) object to which the frame is to be added. 492 // frame - (in/out) frame data in ARGB or YUV(A) format. If it is in YUV(A) 493 // format, it will be converted to ARGB, which incurs a small loss. 494 // timestamp_ms - (in) timestamp of this frame in milliseconds. 495 // Duration of a frame would be calculated as 496 // "timestamp of next frame - timestamp of this frame". 497 // Hence, timestamps should be in non-decreasing order. 498 // config - (in) encoding options; can be passed NULL to pick 499 // reasonable defaults. 500 // Returns: 501 // On error, returns false and frame->error_code is set appropriately. 502 // Otherwise, returns true. 503 WEBP_NODISCARD WEBP_EXTERN int WebPAnimEncoderAdd( 504 WebPAnimEncoder* enc, struct WebPPicture* frame, int timestamp_ms, 505 const struct WebPConfig* config); 506 507 // Assemble all frames added so far into a WebP bitstream. 508 // This call should be preceded by a call to 'WebPAnimEncoderAdd' with 509 // frame = NULL; if not, the duration of the last frame will be internally 510 // estimated. 511 // Parameters: 512 // enc - (in/out) object from which the frames are to be assembled. 513 // webp_data - (out) generated WebP bitstream. 514 // Returns: 515 // True on success. 516 WEBP_NODISCARD WEBP_EXTERN int WebPAnimEncoderAssemble(WebPAnimEncoder* enc, 517 WebPData* webp_data); 518 519 // Get error string corresponding to the most recent call using 'enc'. The 520 // returned string is owned by 'enc' and is valid only until the next call to 521 // WebPAnimEncoderAdd() or WebPAnimEncoderAssemble() or WebPAnimEncoderDelete(). 522 // Parameters: 523 // enc - (in/out) object from which the error string is to be fetched. 524 // Returns: 525 // NULL if 'enc' is NULL. Otherwise, returns the error string if the last call 526 // to 'enc' had an error, or an empty string if the last call was a success. 527 WEBP_EXTERN const char* WebPAnimEncoderGetError(WebPAnimEncoder* enc); 528 529 // Deletes the WebPAnimEncoder object. 530 // Parameters: 531 // enc - (in/out) object to be deleted 532 WEBP_EXTERN void WebPAnimEncoderDelete(WebPAnimEncoder* enc); 533 534 //------------------------------------------------------------------------------ 535 // Non-image chunks. 536 537 // Note: Only non-image related chunks should be managed through chunk APIs. 538 // (Image related chunks are: "ANMF", "VP8 ", "VP8L" and "ALPH"). 539 540 // Adds a chunk with id 'fourcc' and data 'chunk_data' in the enc object. 541 // Any existing chunk(s) with the same id will be removed. 542 // Parameters: 543 // enc - (in/out) object to which the chunk is to be added 544 // fourcc - (in) a character array containing the fourcc of the given chunk; 545 // e.g., "ICCP", "XMP ", "EXIF", etc. 546 // chunk_data - (in) the chunk data to be added 547 // copy_data - (in) value 1 indicates given data WILL be copied to the enc 548 // object and value 0 indicates data will NOT be copied. If the 549 // data is not copied, it must exist until a call to 550 // WebPAnimEncoderAssemble() is made. 551 // Returns: 552 // WEBP_MUX_INVALID_ARGUMENT - if enc, fourcc or chunk_data is NULL. 553 // WEBP_MUX_MEMORY_ERROR - on memory allocation error. 554 // WEBP_MUX_OK - on success. 555 WEBP_EXTERN WebPMuxError WebPAnimEncoderSetChunk( 556 WebPAnimEncoder* enc, const char fourcc[4], const WebPData* chunk_data, 557 int copy_data); 558 559 // Gets a reference to the data of the chunk with id 'fourcc' in the enc object. 560 // The caller should NOT free the returned data. 561 // Parameters: 562 // enc - (in) object from which the chunk data is to be fetched 563 // fourcc - (in) a character array containing the fourcc of the chunk; 564 // e.g., "ICCP", "XMP ", "EXIF", etc. 565 // chunk_data - (out) returned chunk data 566 // Returns: 567 // WEBP_MUX_INVALID_ARGUMENT - if enc, fourcc or chunk_data is NULL. 568 // WEBP_MUX_NOT_FOUND - If enc does not contain a chunk with the given id. 569 // WEBP_MUX_OK - on success. 570 WEBP_EXTERN WebPMuxError WebPAnimEncoderGetChunk( 571 const WebPAnimEncoder* enc, const char fourcc[4], WebPData* chunk_data); 572 573 // Deletes the chunk with the given 'fourcc' from the enc object. 574 // Parameters: 575 // enc - (in/out) object from which the chunk is to be deleted 576 // fourcc - (in) a character array containing the fourcc of the chunk; 577 // e.g., "ICCP", "XMP ", "EXIF", etc. 578 // Returns: 579 // WEBP_MUX_INVALID_ARGUMENT - if enc or fourcc is NULL. 580 // WEBP_MUX_NOT_FOUND - If enc does not contain a chunk with the given fourcc. 581 // WEBP_MUX_OK - on success. 582 WEBP_EXTERN WebPMuxError WebPAnimEncoderDeleteChunk( 583 WebPAnimEncoder* enc, const char fourcc[4]); 584 585 //------------------------------------------------------------------------------ 586 587 #ifdef __cplusplus 588 } // extern "C" 589 #endif 590 591 #endif // WEBP_WEBP_MUX_H_