Blame src/webp/mux.h

Packit 9c6abc
// Copyright 2011 Google Inc. All Rights Reserved.
Packit 9c6abc
//
Packit 9c6abc
// Use of this source code is governed by a BSD-style license
Packit 9c6abc
// that can be found in the COPYING file in the root of the source
Packit 9c6abc
// tree. An additional intellectual property rights grant can be found
Packit 9c6abc
// in the file PATENTS. All contributing project authors may
Packit 9c6abc
// be found in the AUTHORS file in the root of the source tree.
Packit 9c6abc
// -----------------------------------------------------------------------------
Packit 9c6abc
//
Packit 9c6abc
//  RIFF container manipulation and encoding for WebP images.
Packit 9c6abc
//
Packit 9c6abc
// Authors: Urvang (urvang@google.com)
Packit 9c6abc
//          Vikas (vikasa@google.com)
Packit 9c6abc
Packit 9c6abc
#ifndef WEBP_WEBP_MUX_H_
Packit 9c6abc
#define WEBP_WEBP_MUX_H_
Packit 9c6abc
Packit 9c6abc
#include "./mux_types.h"
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
extern "C" {
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
#define WEBP_MUX_ABI_VERSION 0x0108        // MAJOR(8b) + MINOR(8b)
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Mux API
Packit 9c6abc
//
Packit 9c6abc
// This API allows manipulation of WebP container images containing features
Packit 9c6abc
// like color profile, metadata, animation.
Packit 9c6abc
//
Packit 9c6abc
// Code Example#1: Create a WebPMux object with image data, color profile and
Packit 9c6abc
// XMP metadata.
Packit 9c6abc
/*
Packit 9c6abc
  int copy_data = 0;
Packit 9c6abc
  WebPMux* mux = WebPMuxNew();
Packit 9c6abc
  // ... (Prepare image data).
Packit 9c6abc
  WebPMuxSetImage(mux, &image, copy_data);
Packit 9c6abc
  // ... (Prepare ICCP color profile data).
Packit 9c6abc
  WebPMuxSetChunk(mux, "ICCP", &icc_profile, copy_data);
Packit 9c6abc
  // ... (Prepare XMP metadata).
Packit 9c6abc
  WebPMuxSetChunk(mux, "XMP ", &xmp, copy_data);
Packit 9c6abc
  // Get data from mux in WebP RIFF format.
Packit 9c6abc
  WebPMuxAssemble(mux, &output_data);
Packit 9c6abc
  WebPMuxDelete(mux);
Packit 9c6abc
  // ... (Consume output_data; e.g. write output_data.bytes to file).
Packit 9c6abc
  WebPDataClear(&output_data);
Packit 9c6abc
*/
Packit 9c6abc
Packit 9c6abc
// Code Example#2: Get image and color profile data from a WebP file.
Packit 9c6abc
/*
Packit 9c6abc
  int copy_data = 0;
Packit 9c6abc
  // ... (Read data from file).
Packit 9c6abc
  WebPMux* mux = WebPMuxCreate(&data, copy_data);
Packit 9c6abc
  WebPMuxGetFrame(mux, 1, &image);
Packit 9c6abc
  // ... (Consume image; e.g. call WebPDecode() to decode the data).
Packit 9c6abc
  WebPMuxGetChunk(mux, "ICCP", &icc_profile);
Packit 9c6abc
  // ... (Consume icc_data).
Packit 9c6abc
  WebPMuxDelete(mux);
Packit 9c6abc
  free(data);
Packit 9c6abc
*/
Packit 9c6abc
Packit 9c6abc
// Note: forward declaring enumerations is not allowed in (strict) C and C++,
Packit 9c6abc
// the types are left here for reference.
Packit 9c6abc
// typedef enum WebPMuxError WebPMuxError;
Packit 9c6abc
// typedef enum WebPChunkId WebPChunkId;
Packit 9c6abc
typedef struct WebPMux WebPMux;   // main opaque object.
Packit 9c6abc
typedef struct WebPMuxFrameInfo WebPMuxFrameInfo;
Packit 9c6abc
typedef struct WebPMuxAnimParams WebPMuxAnimParams;
Packit 9c6abc
typedef struct WebPAnimEncoderOptions WebPAnimEncoderOptions;
Packit 9c6abc
Packit 9c6abc
// Error codes
Packit 9c6abc
typedef enum WebPMuxError {
Packit 9c6abc
  WEBP_MUX_OK                 =  1,
Packit 9c6abc
  WEBP_MUX_NOT_FOUND          =  0,
Packit 9c6abc
  WEBP_MUX_INVALID_ARGUMENT   = -1,
Packit 9c6abc
  WEBP_MUX_BAD_DATA           = -2,
Packit 9c6abc
  WEBP_MUX_MEMORY_ERROR       = -3,
Packit 9c6abc
  WEBP_MUX_NOT_ENOUGH_DATA    = -4
Packit 9c6abc
} WebPMuxError;
Packit 9c6abc
Packit 9c6abc
// IDs for different types of chunks.
Packit 9c6abc
typedef enum WebPChunkId {
Packit 9c6abc
  WEBP_CHUNK_VP8X,        // VP8X
Packit 9c6abc
  WEBP_CHUNK_ICCP,        // ICCP
Packit 9c6abc
  WEBP_CHUNK_ANIM,        // ANIM
Packit 9c6abc
  WEBP_CHUNK_ANMF,        // ANMF
Packit 9c6abc
  WEBP_CHUNK_DEPRECATED,  // (deprecated from FRGM)
Packit 9c6abc
  WEBP_CHUNK_ALPHA,       // ALPH
Packit 9c6abc
  WEBP_CHUNK_IMAGE,       // VP8/VP8L
Packit 9c6abc
  WEBP_CHUNK_EXIF,        // EXIF
Packit 9c6abc
  WEBP_CHUNK_XMP,         // XMP
Packit 9c6abc
  WEBP_CHUNK_UNKNOWN,     // Other chunks.
Packit 9c6abc
  WEBP_CHUNK_NIL
Packit 9c6abc
} WebPChunkId;
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
Packit 9c6abc
// Returns the version number of the mux library, packed in hexadecimal using
Packit 9c6abc
// 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507.
Packit 9c6abc
WEBP_EXTERN int WebPGetMuxVersion(void);
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Life of a Mux object
Packit 9c6abc
Packit 9c6abc
// Internal, version-checked, entry point
Packit 9c6abc
WEBP_EXTERN WebPMux* WebPNewInternal(int);
Packit 9c6abc
Packit 9c6abc
// Creates an empty mux object.
Packit 9c6abc
// Returns:
Packit 9c6abc
//   A pointer to the newly created empty mux object.
Packit 9c6abc
//   Or NULL in case of memory error.
Packit 9c6abc
static WEBP_INLINE WebPMux* WebPMuxNew(void) {
Packit 9c6abc
  return WebPNewInternal(WEBP_MUX_ABI_VERSION);
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
// Deletes the mux object.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in/out) object to be deleted
Packit 9c6abc
WEBP_EXTERN void WebPMuxDelete(WebPMux* mux);
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Mux creation.
Packit 9c6abc
Packit 9c6abc
// Internal, version-checked, entry point
Packit 9c6abc
WEBP_EXTERN WebPMux* WebPMuxCreateInternal(const WebPData*, int, int);
Packit 9c6abc
Packit 9c6abc
// Creates a mux object from raw data given in WebP RIFF format.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   bitstream - (in) the bitstream data in WebP RIFF format
Packit 9c6abc
//   copy_data - (in) value 1 indicates given data WILL be copied to the mux
Packit 9c6abc
//               object and value 0 indicates data will NOT be copied.
Packit 9c6abc
// Returns:
Packit 9c6abc
//   A pointer to the mux object created from given data - on success.
Packit 9c6abc
//   NULL - In case of invalid data or memory error.
Packit 9c6abc
static WEBP_INLINE WebPMux* WebPMuxCreate(const WebPData* bitstream,
Packit 9c6abc
                                          int copy_data) {
Packit 9c6abc
  return WebPMuxCreateInternal(bitstream, copy_data, WEBP_MUX_ABI_VERSION);
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Non-image chunks.
Packit 9c6abc
Packit 9c6abc
// Note: Only non-image related chunks should be managed through chunk APIs.
Packit 9c6abc
// (Image related chunks are: "ANMF", "VP8 ", "VP8L" and "ALPH").
Packit 9c6abc
// To add, get and delete images, use WebPMuxSetImage(), WebPMuxPushFrame(),
Packit 9c6abc
// WebPMuxGetFrame() and WebPMuxDeleteFrame().
Packit 9c6abc
Packit 9c6abc
// Adds a chunk with id 'fourcc' and data 'chunk_data' in the mux object.
Packit 9c6abc
// Any existing chunk(s) with the same id will be removed.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in/out) object to which the chunk is to be added
Packit 9c6abc
//   fourcc - (in) a character array containing the fourcc of the given chunk;
Packit 9c6abc
//                 e.g., "ICCP", "XMP ", "EXIF" etc.
Packit 9c6abc
//   chunk_data - (in) the chunk data to be added
Packit 9c6abc
//   copy_data - (in) value 1 indicates given data WILL be copied to the mux
Packit 9c6abc
//               object and value 0 indicates data will NOT be copied.
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL
Packit 9c6abc
//                               or if fourcc corresponds to an image chunk.
Packit 9c6abc
//   WEBP_MUX_MEMORY_ERROR - on memory allocation error.
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxSetChunk(
Packit 9c6abc
    WebPMux* mux, const char fourcc[4], const WebPData* chunk_data,
Packit 9c6abc
    int copy_data);
Packit 9c6abc
Packit 9c6abc
// Gets a reference to the data of the chunk with id 'fourcc' in the mux object.
Packit 9c6abc
// The caller should NOT free the returned data.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in) object from which the chunk data is to be fetched
Packit 9c6abc
//   fourcc - (in) a character array containing the fourcc of the chunk;
Packit 9c6abc
//                 e.g., "ICCP", "XMP ", "EXIF" etc.
Packit 9c6abc
//   chunk_data - (out) returned chunk data
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL
Packit 9c6abc
//                               or if fourcc corresponds to an image chunk.
Packit 9c6abc
//   WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given id.
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxGetChunk(
Packit 9c6abc
    const WebPMux* mux, const char fourcc[4], WebPData* chunk_data);
Packit 9c6abc
Packit 9c6abc
// Deletes the chunk with the given 'fourcc' from the mux object.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in/out) object from which the chunk is to be deleted
Packit 9c6abc
//   fourcc - (in) a character array containing the fourcc of the chunk;
Packit 9c6abc
//                 e.g., "ICCP", "XMP ", "EXIF" etc.
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux or fourcc is NULL
Packit 9c6abc
//                               or if fourcc corresponds to an image chunk.
Packit 9c6abc
//   WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given fourcc.
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxDeleteChunk(
Packit 9c6abc
    WebPMux* mux, const char fourcc[4]);
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Images.
Packit 9c6abc
Packit 9c6abc
// Encapsulates data about a single frame.
Packit 9c6abc
struct WebPMuxFrameInfo {
Packit 9c6abc
  WebPData    bitstream;  // image data: can be a raw VP8/VP8L bitstream
Packit 9c6abc
                          // or a single-image WebP file.
Packit 9c6abc
  int         x_offset;   // x-offset of the frame.
Packit 9c6abc
  int         y_offset;   // y-offset of the frame.
Packit 9c6abc
  int         duration;   // duration of the frame (in milliseconds).
Packit 9c6abc
Packit 9c6abc
  WebPChunkId id;         // frame type: should be one of WEBP_CHUNK_ANMF
Packit 9c6abc
                          // or WEBP_CHUNK_IMAGE
Packit 9c6abc
  WebPMuxAnimDispose dispose_method;  // Disposal method for the frame.
Packit 9c6abc
  WebPMuxAnimBlend   blend_method;    // Blend operation for the frame.
Packit 9c6abc
  uint32_t    pad[1];     // padding for later use
Packit 9c6abc
};
Packit 9c6abc
Packit 9c6abc
// Sets the (non-animated) image in the mux object.
Packit 9c6abc
// Note: Any existing images (including frames) will be removed.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in/out) object in which the image is to be set
Packit 9c6abc
//   bitstream - (in) can be a raw VP8/VP8L bitstream or a single-image
Packit 9c6abc
//               WebP file (non-animated)
Packit 9c6abc
//   copy_data - (in) value 1 indicates given data WILL be copied to the mux
Packit 9c6abc
//               object and value 0 indicates data will NOT be copied.
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or bitstream is NULL.
Packit 9c6abc
//   WEBP_MUX_MEMORY_ERROR - on memory allocation error.
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxSetImage(
Packit 9c6abc
    WebPMux* mux, const WebPData* bitstream, int copy_data);
Packit 9c6abc
Packit 9c6abc
// Adds a frame at the end of the mux object.
Packit 9c6abc
// Notes: (1) frame.id should be WEBP_CHUNK_ANMF
Packit 9c6abc
//        (2) For setting a non-animated image, use WebPMuxSetImage() instead.
Packit 9c6abc
//        (3) Type of frame being pushed must be same as the frames in mux.
Packit 9c6abc
//        (4) As WebP only supports even offsets, any odd offset will be snapped
Packit 9c6abc
//            to an even location using: offset &= ~1
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in/out) object to which the frame is to be added
Packit 9c6abc
//   frame - (in) frame data.
Packit 9c6abc
//   copy_data - (in) value 1 indicates given data WILL be copied to the mux
Packit 9c6abc
//               object and value 0 indicates data will NOT be copied.
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL
Packit 9c6abc
//                               or if content of 'frame' is invalid.
Packit 9c6abc
//   WEBP_MUX_MEMORY_ERROR - on memory allocation error.
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxPushFrame(
Packit 9c6abc
    WebPMux* mux, const WebPMuxFrameInfo* frame, int copy_data);
Packit 9c6abc
Packit 9c6abc
// Gets the nth frame from the mux object.
Packit 9c6abc
// The content of 'frame->bitstream' is allocated using malloc(), and NOT
Packit 9c6abc
// owned by the 'mux' object. It MUST be deallocated by the caller by calling
Packit 9c6abc
// WebPDataClear().
Packit 9c6abc
// nth=0 has a special meaning - last position.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in) object from which the info is to be fetched
Packit 9c6abc
//   nth - (in) index of the frame in the mux object
Packit 9c6abc
//   frame - (out) data of the returned frame
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL.
Packit 9c6abc
//   WEBP_MUX_NOT_FOUND - if there are less than nth frames in the mux object.
Packit 9c6abc
//   WEBP_MUX_BAD_DATA - if nth frame chunk in mux is invalid.
Packit 9c6abc
//   WEBP_MUX_MEMORY_ERROR - on memory allocation error.
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxGetFrame(
Packit 9c6abc
    const WebPMux* mux, uint32_t nth, WebPMuxFrameInfo* frame);
Packit 9c6abc
Packit 9c6abc
// Deletes a frame from the mux object.
Packit 9c6abc
// nth=0 has a special meaning - last position.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in/out) object from which a frame is to be deleted
Packit 9c6abc
//   nth - (in) The position from which the frame is to be deleted
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux is NULL.
Packit 9c6abc
//   WEBP_MUX_NOT_FOUND - If there are less than nth frames in the mux object
Packit 9c6abc
//                        before deletion.
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxDeleteFrame(WebPMux* mux, uint32_t nth);
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Animation.
Packit 9c6abc
Packit 9c6abc
// Animation parameters.
Packit 9c6abc
struct WebPMuxAnimParams {
Packit 9c6abc
  uint32_t bgcolor;  // Background color of the canvas stored (in MSB order) as:
Packit 9c6abc
                     // Bits 00 to 07: Alpha.
Packit 9c6abc
                     // Bits 08 to 15: Red.
Packit 9c6abc
                     // Bits 16 to 23: Green.
Packit 9c6abc
                     // Bits 24 to 31: Blue.
Packit 9c6abc
  int loop_count;    // Number of times to repeat the animation [0 = infinite].
Packit 9c6abc
};
Packit 9c6abc
Packit 9c6abc
// Sets the animation parameters in the mux object. Any existing ANIM chunks
Packit 9c6abc
// will be removed.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in/out) object in which ANIM chunk is to be set/added
Packit 9c6abc
//   params - (in) animation parameters.
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL.
Packit 9c6abc
//   WEBP_MUX_MEMORY_ERROR - on memory allocation error.
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxSetAnimationParams(
Packit 9c6abc
    WebPMux* mux, const WebPMuxAnimParams* params);
Packit 9c6abc
Packit 9c6abc
// Gets the animation parameters from the mux object.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in) object from which the animation parameters to be fetched
Packit 9c6abc
//   params - (out) animation parameters extracted from the ANIM chunk
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL.
Packit 9c6abc
//   WEBP_MUX_NOT_FOUND - if ANIM chunk is not present in mux object.
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxGetAnimationParams(
Packit 9c6abc
    const WebPMux* mux, WebPMuxAnimParams* params);
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Misc Utilities.
Packit 9c6abc
Packit 9c6abc
// Sets the canvas size for the mux object. The width and height can be
Packit 9c6abc
// specified explicitly or left as zero (0, 0).
Packit 9c6abc
// * When width and height are specified explicitly, then this frame bound is
Packit 9c6abc
//   enforced during subsequent calls to WebPMuxAssemble() and an error is
Packit 9c6abc
//   reported if any animated frame does not completely fit within the canvas.
Packit 9c6abc
// * When unspecified (0, 0), the constructed canvas will get the frame bounds
Packit 9c6abc
//   from the bounding-box over all frames after calling WebPMuxAssemble().
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in) object to which the canvas size is to be set
Packit 9c6abc
//   width - (in) canvas width
Packit 9c6abc
//   height - (in) canvas height
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux is NULL; or
Packit 9c6abc
//                               width or height are invalid or out of bounds
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxSetCanvasSize(WebPMux* mux,
Packit 9c6abc
                                              int width, int height);
Packit 9c6abc
Packit 9c6abc
// Gets the canvas size from the mux object.
Packit 9c6abc
// Note: This method assumes that the VP8X chunk, if present, is up-to-date.
Packit 9c6abc
// That is, the mux object hasn't been modified since the last call to
Packit 9c6abc
// WebPMuxAssemble() or WebPMuxCreate().
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in) object from which the canvas size is to be fetched
Packit 9c6abc
//   width - (out) canvas width
Packit 9c6abc
//   height - (out) canvas height
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux, width or height is NULL.
Packit 9c6abc
//   WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid.
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxGetCanvasSize(const WebPMux* mux,
Packit 9c6abc
                                              int* width, int* height);
Packit 9c6abc
Packit 9c6abc
// Gets the feature flags from the mux object.
Packit 9c6abc
// Note: This method assumes that the VP8X chunk, if present, is up-to-date.
Packit 9c6abc
// That is, the mux object hasn't been modified since the last call to
Packit 9c6abc
// WebPMuxAssemble() or WebPMuxCreate().
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in) object from which the features are to be fetched
Packit 9c6abc
//   flags - (out) the flags specifying which features are present in the
Packit 9c6abc
//           mux object. This will be an OR of various flag values.
Packit 9c6abc
//           Enum 'WebPFeatureFlags' can be used to test individual flag values.
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux or flags is NULL.
Packit 9c6abc
//   WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid.
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxGetFeatures(const WebPMux* mux,
Packit 9c6abc
                                            uint32_t* flags);
Packit 9c6abc
Packit 9c6abc
// Gets number of chunks with the given 'id' in the mux object.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in) object from which the info is to be fetched
Packit 9c6abc
//   id - (in) chunk id specifying the type of chunk
Packit 9c6abc
//   num_elements - (out) number of chunks with the given chunk id
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux, or num_elements is NULL.
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxNumChunks(const WebPMux* mux,
Packit 9c6abc
                                          WebPChunkId id, int* num_elements);
Packit 9c6abc
Packit 9c6abc
// Assembles all chunks in WebP RIFF format and returns in 'assembled_data'.
Packit 9c6abc
// This function also validates the mux object.
Packit 9c6abc
// Note: The content of 'assembled_data' will be ignored and overwritten.
Packit 9c6abc
// Also, the content of 'assembled_data' is allocated using malloc(), and NOT
Packit 9c6abc
// owned by the 'mux' object. It MUST be deallocated by the caller by calling
Packit 9c6abc
// WebPDataClear(). It's always safe to call WebPDataClear() upon return,
Packit 9c6abc
// even in case of error.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   mux - (in/out) object whose chunks are to be assembled
Packit 9c6abc
//   assembled_data - (out) assembled WebP data
Packit 9c6abc
// Returns:
Packit 9c6abc
//   WEBP_MUX_BAD_DATA - if mux object is invalid.
Packit 9c6abc
//   WEBP_MUX_INVALID_ARGUMENT - if mux or assembled_data is NULL.
Packit 9c6abc
//   WEBP_MUX_MEMORY_ERROR - on memory allocation error.
Packit 9c6abc
//   WEBP_MUX_OK - on success.
Packit 9c6abc
WEBP_EXTERN WebPMuxError WebPMuxAssemble(WebPMux* mux,
Packit 9c6abc
                                         WebPData* assembled_data);
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// WebPAnimEncoder API
Packit 9c6abc
//
Packit 9c6abc
// This API allows encoding (possibly) animated WebP images.
Packit 9c6abc
//
Packit 9c6abc
// Code Example:
Packit 9c6abc
/*
Packit 9c6abc
  WebPAnimEncoderOptions enc_options;
Packit 9c6abc
  WebPAnimEncoderOptionsInit(&enc_options);
Packit 9c6abc
  // Tune 'enc_options' as needed.
Packit 9c6abc
  WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, &enc_options);
Packit 9c6abc
  while(<there are more frames>) {
Packit 9c6abc
    WebPConfig config;
Packit 9c6abc
    WebPConfigInit(&config);
Packit 9c6abc
    // Tune 'config' as needed.
Packit 9c6abc
    WebPAnimEncoderAdd(enc, frame, timestamp_ms, &config);
Packit 9c6abc
  }
Packit 9c6abc
  WebPAnimEncoderAdd(enc, NULL, timestamp_ms, NULL);
Packit 9c6abc
  WebPAnimEncoderAssemble(enc, webp_data);
Packit 9c6abc
  WebPAnimEncoderDelete(enc);
Packit 9c6abc
  // Write the 'webp_data' to a file, or re-mux it further.
Packit 9c6abc
*/
Packit 9c6abc
Packit 9c6abc
typedef struct WebPAnimEncoder WebPAnimEncoder;  // Main opaque object.
Packit 9c6abc
Packit 9c6abc
// Forward declarations. Defined in encode.h.
Packit 9c6abc
struct WebPPicture;
Packit 9c6abc
struct WebPConfig;
Packit 9c6abc
Packit 9c6abc
// Global options.
Packit 9c6abc
struct WebPAnimEncoderOptions {
Packit 9c6abc
  WebPMuxAnimParams anim_params;  // Animation parameters.
Packit 9c6abc
  int minimize_size;    // If true, minimize the output size (slow). Implicitly
Packit 9c6abc
                        // disables key-frame insertion.
Packit 9c6abc
  int kmin;
Packit 9c6abc
  int kmax;             // Minimum and maximum distance between consecutive key
Packit 9c6abc
                        // frames in the output. The library may insert some key
Packit 9c6abc
                        // frames as needed to satisfy this criteria.
Packit 9c6abc
                        // Note that these conditions should hold: kmax > kmin
Packit 9c6abc
                        // and kmin >= kmax / 2 + 1. Also, if kmax <= 0, then
Packit 9c6abc
                        // key-frame insertion is disabled; and if kmax == 1,
Packit 9c6abc
                        // then all frames will be key-frames (kmin value does
Packit 9c6abc
                        // not matter for these special cases).
Packit 9c6abc
  int allow_mixed;      // If true, use mixed compression mode; may choose
Packit 9c6abc
                        // either lossy and lossless for each frame.
Packit 9c6abc
  int verbose;          // If true, print info and warning messages to stderr.
Packit 9c6abc
Packit 9c6abc
  uint32_t padding[4];  // Padding for later use.
Packit 9c6abc
};
Packit 9c6abc
Packit 9c6abc
// Internal, version-checked, entry point.
Packit 9c6abc
WEBP_EXTERN int WebPAnimEncoderOptionsInitInternal(
Packit 9c6abc
    WebPAnimEncoderOptions*, int);
Packit 9c6abc
Packit 9c6abc
// Should always be called, to initialize a fresh WebPAnimEncoderOptions
Packit 9c6abc
// structure before modification. Returns false in case of version mismatch.
Packit 9c6abc
// WebPAnimEncoderOptionsInit() must have succeeded before using the
Packit 9c6abc
// 'enc_options' object.
Packit 9c6abc
static WEBP_INLINE int WebPAnimEncoderOptionsInit(
Packit 9c6abc
    WebPAnimEncoderOptions* enc_options) {
Packit 9c6abc
  return WebPAnimEncoderOptionsInitInternal(enc_options, WEBP_MUX_ABI_VERSION);
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
// Internal, version-checked, entry point.
Packit 9c6abc
WEBP_EXTERN WebPAnimEncoder* WebPAnimEncoderNewInternal(
Packit 9c6abc
    int, int, const WebPAnimEncoderOptions*, int);
Packit 9c6abc
Packit 9c6abc
// Creates and initializes a WebPAnimEncoder object.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   width/height - (in) canvas width and height of the animation.
Packit 9c6abc
//   enc_options - (in) encoding options; can be passed NULL to pick
Packit 9c6abc
//                      reasonable defaults.
Packit 9c6abc
// Returns:
Packit 9c6abc
//   A pointer to the newly created WebPAnimEncoder object.
Packit 9c6abc
//   Or NULL in case of memory error.
Packit 9c6abc
static WEBP_INLINE WebPAnimEncoder* WebPAnimEncoderNew(
Packit 9c6abc
    int width, int height, const WebPAnimEncoderOptions* enc_options) {
Packit 9c6abc
  return WebPAnimEncoderNewInternal(width, height, enc_options,
Packit 9c6abc
                                    WEBP_MUX_ABI_VERSION);
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
// Optimize the given frame for WebP, encode it and add it to the
Packit 9c6abc
// WebPAnimEncoder object.
Packit 9c6abc
// The last call to 'WebPAnimEncoderAdd' should be with frame = NULL, which
Packit 9c6abc
// indicates that no more frames are to be added. This call is also used to
Packit 9c6abc
// determine the duration of the last frame.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   enc - (in/out) object to which the frame is to be added.
Packit 9c6abc
//   frame - (in/out) frame data in ARGB or YUV(A) format. If it is in YUV(A)
Packit 9c6abc
//           format, it will be converted to ARGB, which incurs a small loss.
Packit 9c6abc
//   timestamp_ms - (in) timestamp of this frame in milliseconds.
Packit 9c6abc
//                       Duration of a frame would be calculated as
Packit 9c6abc
//                       "timestamp of next frame - timestamp of this frame".
Packit 9c6abc
//                       Hence, timestamps should be in non-decreasing order.
Packit 9c6abc
//   config - (in) encoding options; can be passed NULL to pick
Packit 9c6abc
//            reasonable defaults.
Packit 9c6abc
// Returns:
Packit 9c6abc
//   On error, returns false and frame->error_code is set appropriately.
Packit 9c6abc
//   Otherwise, returns true.
Packit 9c6abc
WEBP_EXTERN int WebPAnimEncoderAdd(
Packit 9c6abc
    WebPAnimEncoder* enc, struct WebPPicture* frame, int timestamp_ms,
Packit 9c6abc
    const struct WebPConfig* config);
Packit 9c6abc
Packit 9c6abc
// Assemble all frames added so far into a WebP bitstream.
Packit 9c6abc
// This call should be preceded by  a call to 'WebPAnimEncoderAdd' with
Packit 9c6abc
// frame = NULL; if not, the duration of the last frame will be internally
Packit 9c6abc
// estimated.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   enc - (in/out) object from which the frames are to be assembled.
Packit 9c6abc
//   webp_data - (out) generated WebP bitstream.
Packit 9c6abc
// Returns:
Packit 9c6abc
//   True on success.
Packit 9c6abc
WEBP_EXTERN int WebPAnimEncoderAssemble(WebPAnimEncoder* enc,
Packit 9c6abc
                                        WebPData* webp_data);
Packit 9c6abc
Packit 9c6abc
// Get error string corresponding to the most recent call using 'enc'. The
Packit 9c6abc
// returned string is owned by 'enc' and is valid only until the next call to
Packit 9c6abc
// WebPAnimEncoderAdd() or WebPAnimEncoderAssemble() or WebPAnimEncoderDelete().
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   enc - (in/out) object from which the error string is to be fetched.
Packit 9c6abc
// Returns:
Packit 9c6abc
//   NULL if 'enc' is NULL. Otherwise, returns the error string if the last call
Packit 9c6abc
//   to 'enc' had an error, or an empty string if the last call was a success.
Packit 9c6abc
WEBP_EXTERN const char* WebPAnimEncoderGetError(WebPAnimEncoder* enc);
Packit 9c6abc
Packit 9c6abc
// Deletes the WebPAnimEncoder object.
Packit 9c6abc
// Parameters:
Packit 9c6abc
//   enc - (in/out) object to be deleted
Packit 9c6abc
WEBP_EXTERN void WebPAnimEncoderDelete(WebPAnimEncoder* enc);
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
}    // extern "C"
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
#endif  /* WEBP_WEBP_MUX_H_ */