2012-01-06 23:49:06 +01:00
|
|
|
// Copyright 2011 Google Inc. All Rights Reserved.
|
2011-09-22 12:55:23 +02:00
|
|
|
//
|
|
|
|
// This code is licensed under the same terms as WebM:
|
|
|
|
// Software License Agreement: http://www.webmproject.org/license/software/
|
|
|
|
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// RIFF container manipulation for WEBP images.
|
|
|
|
//
|
2011-09-28 05:46:09 +02:00
|
|
|
// Authors: Urvang (urvang@google.com)
|
|
|
|
// Vikas (vikasa@google.com)
|
|
|
|
|
|
|
|
// This API allows manipulation of WebP container images containing features
|
2012-06-20 19:59:40 +02:00
|
|
|
// like Color profile, XMP metadata, Animation and Tiling.
|
2011-09-28 05:46:09 +02:00
|
|
|
//
|
2012-06-20 19:59:40 +02:00
|
|
|
// Code Example#1: Creating a MUX with image data, color profile and XMP
|
|
|
|
// metadata.
|
2011-09-28 05:46:09 +02:00
|
|
|
//
|
|
|
|
// int copy_data = 0;
|
|
|
|
// WebPMux* mux = WebPMuxNew();
|
|
|
|
// // ... (Prepare image data).
|
2012-06-20 19:59:40 +02:00
|
|
|
// WebPMuxSetImage(mux, &image, copy_data);
|
2011-09-28 05:46:09 +02:00
|
|
|
// // ... (Prepare ICCP color profile data).
|
2012-08-23 11:58:20 +02:00
|
|
|
// WebPMuxSetChunk(mux, "ICCP", &icc_profile, copy_data);
|
2011-09-28 05:46:09 +02:00
|
|
|
// // ... (Prepare XMP metadata).
|
2012-08-23 11:58:20 +02:00
|
|
|
// WebPMuxSetChunk(mux, "META", &xmp, copy_data);
|
2011-09-28 05:46:09 +02:00
|
|
|
// // Get data from mux in WebP RIFF format.
|
2012-06-07 07:34:57 +02:00
|
|
|
// WebPMuxAssemble(mux, &output_data);
|
2011-09-28 05:46:09 +02:00
|
|
|
// WebPMuxDelete(mux);
|
2012-10-30 22:54:46 +01:00
|
|
|
// // ... (Consume output_data; e.g. write output_data.bytes to file).
|
2012-06-07 07:34:57 +02:00
|
|
|
// WebPDataClear(&output_data);
|
2011-09-28 05:46:09 +02:00
|
|
|
//
|
2012-06-20 19:59:40 +02:00
|
|
|
// Code Example#2: Get image and color profile data from a WebP file.
|
2011-09-28 05:46:09 +02:00
|
|
|
//
|
|
|
|
// int copy_data = 0;
|
|
|
|
// // ... (Read data from file).
|
2012-06-07 10:15:06 +02:00
|
|
|
// WebPMux* mux = WebPMuxCreate(&data, copy_data);
|
2012-08-23 12:58:36 +02:00
|
|
|
// WebPMuxGetFrame(mux, 1, &image);
|
2012-01-07 21:44:01 +01:00
|
|
|
// // ... (Consume image; e.g. call WebPDecode() to decode the data).
|
2012-08-23 11:58:20 +02:00
|
|
|
// WebPMuxGetChunk(mux, "ICCP", &icc_profile);
|
2011-09-28 05:46:09 +02:00
|
|
|
// // ... (Consume icc_data).
|
|
|
|
// WebPMuxDelete(mux);
|
|
|
|
// free(data);
|
2011-09-22 12:55:23 +02:00
|
|
|
|
|
|
|
#ifndef WEBP_WEBP_MUX_H_
|
|
|
|
#define WEBP_WEBP_MUX_H_
|
|
|
|
|
2011-12-01 09:15:01 +01:00
|
|
|
#include "./types.h"
|
2011-09-22 12:55:23 +02:00
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-07-18 20:53:25 +02:00
|
|
|
#define WEBP_MUX_ABI_VERSION 0x0100 // MAJOR(8b) + MINOR(8b)
|
2012-04-26 02:27:16 +02:00
|
|
|
|
2012-09-25 18:39:22 +02:00
|
|
|
typedef struct WebPMux WebPMux; // main opaque object.
|
|
|
|
typedef struct WebPData WebPData;
|
2012-09-29 06:21:41 +02:00
|
|
|
#if !(defined(__cplusplus) || defined(c_plusplus))
|
2012-09-25 18:39:22 +02:00
|
|
|
typedef enum WebPMuxError WebPMuxError;
|
|
|
|
typedef enum WebPFeatureFlags WebPFeatureFlags;
|
|
|
|
typedef enum WebPChunkId WebPChunkId;
|
2012-09-29 06:21:41 +02:00
|
|
|
#endif
|
2012-09-25 18:39:22 +02:00
|
|
|
typedef struct WebPMuxFrameInfo WebPMuxFrameInfo;
|
|
|
|
|
|
|
|
typedef struct WebPDemuxer WebPDemuxer;
|
2012-09-29 06:21:41 +02:00
|
|
|
#if !(defined(__cplusplus) || defined(c_plusplus))
|
2012-09-25 18:39:22 +02:00
|
|
|
typedef enum WebPDemuxState WebPDemuxState;
|
|
|
|
typedef enum WebPFormatFeature WebPFormatFeature;
|
2012-09-29 06:21:41 +02:00
|
|
|
#endif
|
2012-09-25 18:39:22 +02:00
|
|
|
typedef struct WebPIterator WebPIterator;
|
|
|
|
typedef struct WebPChunkIterator WebPChunkIterator;
|
|
|
|
|
2011-09-22 12:55:23 +02:00
|
|
|
// Error codes
|
2012-09-25 18:39:22 +02:00
|
|
|
enum WebPMuxError {
|
2011-09-22 12:55:23 +02:00
|
|
|
WEBP_MUX_OK = 1,
|
2012-07-06 14:03:59 +02:00
|
|
|
WEBP_MUX_NOT_FOUND = 0,
|
|
|
|
WEBP_MUX_INVALID_ARGUMENT = -1,
|
|
|
|
WEBP_MUX_BAD_DATA = -2,
|
|
|
|
WEBP_MUX_MEMORY_ERROR = -3,
|
|
|
|
WEBP_MUX_NOT_ENOUGH_DATA = -4
|
2012-09-25 18:39:22 +02:00
|
|
|
};
|
2011-09-22 12:55:23 +02:00
|
|
|
|
|
|
|
// Flag values for different features used in VP8X chunk.
|
2012-09-25 18:39:22 +02:00
|
|
|
enum WebPFeatureFlags {
|
2011-09-22 12:55:23 +02:00
|
|
|
TILE_FLAG = 0x00000001,
|
|
|
|
ANIMATION_FLAG = 0x00000002,
|
|
|
|
ICCP_FLAG = 0x00000004,
|
2011-11-22 10:10:41 +01:00
|
|
|
META_FLAG = 0x00000008,
|
|
|
|
ALPHA_FLAG = 0x00000010
|
2012-09-25 18:39:22 +02:00
|
|
|
};
|
2011-09-22 12:55:23 +02:00
|
|
|
|
2012-06-11 08:54:45 +02:00
|
|
|
// IDs for different types of chunks.
|
2012-09-25 18:39:22 +02:00
|
|
|
enum WebPChunkId {
|
2012-06-11 08:54:45 +02:00
|
|
|
WEBP_CHUNK_VP8X, // VP8X
|
|
|
|
WEBP_CHUNK_ICCP, // ICCP
|
|
|
|
WEBP_CHUNK_LOOP, // LOOP
|
2012-10-30 20:14:10 +01:00
|
|
|
WEBP_CHUNK_ANMF, // ANMF
|
|
|
|
WEBP_CHUNK_FRGM, // FRGM
|
2012-06-11 08:54:45 +02:00
|
|
|
WEBP_CHUNK_ALPHA, // ALPH
|
|
|
|
WEBP_CHUNK_IMAGE, // VP8/VP8L
|
|
|
|
WEBP_CHUNK_META, // META
|
|
|
|
WEBP_CHUNK_UNKNOWN, // Other chunks.
|
|
|
|
WEBP_CHUNK_NIL
|
2012-09-25 18:39:22 +02:00
|
|
|
};
|
2011-09-22 12:55:23 +02:00
|
|
|
|
2012-01-07 21:44:01 +01:00
|
|
|
// Data type used to describe 'raw' data, e.g., chunk data
|
|
|
|
// (ICC profile, metadata) and WebP compressed image data.
|
2012-09-25 18:39:22 +02:00
|
|
|
struct WebPData {
|
2012-10-30 22:54:46 +01:00
|
|
|
const uint8_t* bytes;
|
|
|
|
size_t size;
|
2012-09-25 18:39:22 +02:00
|
|
|
};
|
2012-01-07 21:44:01 +01:00
|
|
|
|
2012-06-07 07:34:57 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2012-06-20 19:59:40 +02:00
|
|
|
// Manipulation of a WebPData object.
|
2012-06-07 07:34:57 +02:00
|
|
|
|
2012-07-06 10:59:35 +02:00
|
|
|
// Initializes the contents of the 'webp_data' object with default values.
|
2012-07-21 21:20:19 +02:00
|
|
|
WEBP_EXTERN(void) WebPDataInit(WebPData* webp_data);
|
2012-07-06 10:59:35 +02:00
|
|
|
|
2012-06-07 07:34:57 +02:00
|
|
|
// Clears the contents of the 'webp_data' object by calling free(). Does not
|
|
|
|
// deallocate the object itself.
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(void) WebPDataClear(WebPData* webp_data);
|
2012-06-07 07:34:57 +02:00
|
|
|
|
2012-06-20 19:59:40 +02:00
|
|
|
// Allocates necessary storage for 'dst' and copies the contents of 'src'.
|
|
|
|
// Returns true on success.
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(int) WebPDataCopy(const WebPData* src, WebPData* dst);
|
2012-06-20 19:59:40 +02:00
|
|
|
|
2011-09-22 12:55:23 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Life of a Mux object
|
|
|
|
|
2012-04-26 02:27:16 +02:00
|
|
|
// Internal, version-checked, entry point
|
|
|
|
WEBP_EXTERN(WebPMux*) WebPNewInternal(int);
|
|
|
|
|
2011-09-22 12:55:23 +02:00
|
|
|
// Creates an empty mux object.
|
|
|
|
// Returns:
|
|
|
|
// A pointer to the newly created empty mux object.
|
2012-04-26 02:27:16 +02:00
|
|
|
static WEBP_INLINE WebPMux* WebPMuxNew(void) {
|
|
|
|
return WebPNewInternal(WEBP_MUX_ABI_VERSION);
|
|
|
|
}
|
2011-09-22 12:55:23 +02:00
|
|
|
|
|
|
|
// Deletes the mux object.
|
2011-09-28 05:46:09 +02:00
|
|
|
// Parameters:
|
|
|
|
// mux - (in/out) object to be deleted
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(void) WebPMuxDelete(WebPMux* mux);
|
2011-09-22 12:55:23 +02:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2011-09-28 05:46:09 +02:00
|
|
|
// Mux creation.
|
2011-09-22 12:55:23 +02:00
|
|
|
|
2012-04-26 02:27:16 +02:00
|
|
|
// Internal, version-checked, entry point
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(WebPMux*) WebPMuxCreateInternal(const WebPData*, int, int);
|
2012-04-26 02:27:16 +02:00
|
|
|
|
2011-09-22 12:55:23 +02:00
|
|
|
// Creates a mux object from raw data given in WebP RIFF format.
|
2011-09-28 05:46:09 +02:00
|
|
|
// Parameters:
|
2012-06-05 10:50:45 +02:00
|
|
|
// bitstream - (in) the bitstream data in WebP RIFF format
|
2012-08-23 12:58:36 +02:00
|
|
|
// copy_data - (in) value 1 indicates given data WILL be copied to the mux
|
|
|
|
// and value 0 indicates data will NOT be copied.
|
2011-09-22 12:55:23 +02:00
|
|
|
// Returns:
|
2011-09-28 05:46:09 +02:00
|
|
|
// A pointer to the mux object created from given data - on success.
|
|
|
|
// NULL - In case of invalid data or memory error.
|
2012-07-18 00:01:30 +02:00
|
|
|
static WEBP_INLINE WebPMux* WebPMuxCreate(const WebPData* bitstream,
|
2012-06-07 10:15:06 +02:00
|
|
|
int copy_data) {
|
|
|
|
return WebPMuxCreateInternal(bitstream, copy_data, WEBP_MUX_ABI_VERSION);
|
2012-04-26 02:27:16 +02:00
|
|
|
}
|
2011-09-28 05:46:09 +02:00
|
|
|
|
2011-11-22 10:10:41 +01:00
|
|
|
//------------------------------------------------------------------------------
|
2012-08-23 12:58:36 +02:00
|
|
|
// Non-image chunks.
|
2011-09-22 12:55:23 +02:00
|
|
|
|
2012-08-23 11:58:20 +02:00
|
|
|
// Note: Only non-image related chunks should be managed through chunk APIs.
|
2012-10-30 20:14:10 +01:00
|
|
|
// (Image related chunks are: "ANMF", "FRGM", "VP8 ", "VP8L" and "ALPH").
|
2012-08-23 12:58:36 +02:00
|
|
|
// To add, get and delete images, use APIs WebPMuxSetImage(),
|
|
|
|
// WebPMuxPushFrame(), WebPMuxGetFrame() and WebPMuxDeleteFrame().
|
2012-08-23 11:58:20 +02:00
|
|
|
|
|
|
|
// Adds a chunk with id 'fourcc' and data 'chunk_data' in the mux object.
|
|
|
|
// Any existing chunk(s) with the same id will be removed.
|
2011-09-28 05:46:09 +02:00
|
|
|
// Parameters:
|
2012-08-23 11:58:20 +02:00
|
|
|
// mux - (in/out) object to which the chunk is to be added
|
|
|
|
// fourcc - (in) a character array containing the fourcc of the given chunk;
|
|
|
|
// e.g., "ICCP", "META" etc.
|
|
|
|
// chunk_data - (in) the chunk data to be added
|
2012-08-23 12:58:36 +02:00
|
|
|
// copy_data - (in) value 1 indicates given data WILL be copied to the mux
|
|
|
|
// and value 0 indicates data will NOT be copied.
|
2011-09-22 12:55:23 +02:00
|
|
|
// Returns:
|
2012-10-30 23:50:47 +01:00
|
|
|
// WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL
|
2012-08-23 11:58:20 +02:00
|
|
|
// or if fourcc corresponds to an image chunk.
|
2011-09-22 12:55:23 +02:00
|
|
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
|
|
|
// WEBP_MUX_OK - on success.
|
2012-08-23 11:58:20 +02:00
|
|
|
WEBP_EXTERN(WebPMuxError) WebPMuxSetChunk(
|
|
|
|
WebPMux* mux, const char fourcc[4], const WebPData* chunk_data,
|
|
|
|
int copy_data);
|
2011-09-28 05:46:09 +02:00
|
|
|
|
2012-08-23 11:58:20 +02:00
|
|
|
// Gets a reference to the data of the chunk with id 'fourcc' in the mux object.
|
2011-09-28 05:46:09 +02:00
|
|
|
// The caller should NOT free the returned data.
|
|
|
|
// Parameters:
|
2012-08-23 11:58:20 +02:00
|
|
|
// mux - (in) object from which the chunk data is to be fetched
|
|
|
|
// fourcc - (in) a character array containing the fourcc of the chunk;
|
|
|
|
// e.g., "ICCP", "META" etc.
|
|
|
|
// chunk_data - (out) returned chunk data
|
2011-09-28 05:46:09 +02:00
|
|
|
// Returns:
|
2012-10-30 23:50:47 +01:00
|
|
|
// WEBP_MUX_INVALID_ARGUMENT - if either mux, fourcc or chunk_data is NULL
|
2012-08-23 11:58:20 +02:00
|
|
|
// or if fourcc corresponds to an image chunk.
|
|
|
|
// WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given id.
|
2011-09-28 05:46:09 +02:00
|
|
|
// WEBP_MUX_OK - on success.
|
2012-08-23 11:58:20 +02:00
|
|
|
WEBP_EXTERN(WebPMuxError) WebPMuxGetChunk(
|
|
|
|
const WebPMux* mux, const char fourcc[4], WebPData* chunk_data);
|
2011-09-28 05:46:09 +02:00
|
|
|
|
2012-08-23 11:58:20 +02:00
|
|
|
// Deletes the chunk with the given 'fourcc' from the mux object.
|
2011-09-28 05:46:09 +02:00
|
|
|
// Parameters:
|
2012-08-23 11:58:20 +02:00
|
|
|
// mux - (in/out) object from which the chunk is to be deleted
|
|
|
|
// fourcc - (in) a character array containing the fourcc of the chunk;
|
|
|
|
// e.g., "ICCP", "META" etc.
|
2011-09-22 12:55:23 +02:00
|
|
|
// Returns:
|
2012-10-30 23:50:47 +01:00
|
|
|
// WEBP_MUX_INVALID_ARGUMENT - if mux or fourcc is NULL
|
2012-08-23 11:58:20 +02:00
|
|
|
// or if fourcc corresponds to an image chunk.
|
|
|
|
// WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given fourcc.
|
2011-09-22 12:55:23 +02:00
|
|
|
// WEBP_MUX_OK - on success.
|
2012-08-23 11:58:20 +02:00
|
|
|
WEBP_EXTERN(WebPMuxError) WebPMuxDeleteChunk(
|
|
|
|
WebPMux* mux, const char fourcc[4]);
|
2011-09-28 05:46:09 +02:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2012-08-23 12:58:36 +02:00
|
|
|
// Images.
|
2011-09-22 12:55:23 +02:00
|
|
|
|
2012-08-23 11:48:51 +02:00
|
|
|
// Encapsulates data about a single frame/tile.
|
2012-09-25 18:39:22 +02:00
|
|
|
struct WebPMuxFrameInfo {
|
2012-10-30 22:54:46 +01:00
|
|
|
WebPData bitstream; // image data: can either be a raw VP8/VP8L bitstream
|
|
|
|
// or a single-image WebP file.
|
|
|
|
int x_offset; // x-offset of the frame.
|
|
|
|
int y_offset; // y-offset of the frame.
|
|
|
|
int duration; // duration of the frame (in milliseconds).
|
|
|
|
|
|
|
|
WebPChunkId id; // frame type: should be one of WEBP_CHUNK_ANMF,
|
|
|
|
// WEBP_CHUNK_FRGM or WEBP_CHUNK_IMAGE
|
|
|
|
uint32_t pad[3]; // padding for later use
|
2012-09-25 18:39:22 +02:00
|
|
|
};
|
2012-08-23 11:48:51 +02:00
|
|
|
|
2012-08-23 12:58:36 +02:00
|
|
|
// Sets the (non-animated and non-tiled) image in the mux object.
|
|
|
|
// Note: Any existing images (including frames/tiles) will be removed.
|
2011-09-28 05:46:09 +02:00
|
|
|
// Parameters:
|
2012-08-23 12:58:36 +02:00
|
|
|
// mux - (in/out) object in which the image is to be set
|
|
|
|
// bitstream - (in) can either be a raw VP8/VP8L bitstream or a single-image
|
|
|
|
// WebP file (non-animated and non-tiled)
|
|
|
|
// copy_data - (in) value 1 indicates given data WILL be copied to the mux
|
|
|
|
// and value 0 indicates data will NOT be copied.
|
|
|
|
// Returns:
|
|
|
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or bitstream is NULL.
|
|
|
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
|
|
|
// WEBP_MUX_OK - on success.
|
|
|
|
WEBP_EXTERN(WebPMuxError) WebPMuxSetImage(
|
|
|
|
WebPMux* mux, const WebPData* bitstream, int copy_data);
|
|
|
|
|
|
|
|
// Adds a frame at the end of the mux object.
|
2012-10-30 20:14:10 +01:00
|
|
|
// Notes: (1) frame.id should be one of WEBP_CHUNK_ANMF or WEBP_CHUNK_FRGM
|
2012-08-23 12:58:36 +02:00
|
|
|
// (2) For setting a non-animated non-tiled image, use WebPMuxSetImage()
|
|
|
|
// instead.
|
|
|
|
// (3) Type of frame being pushed must be same as the frames in mux.
|
|
|
|
// (4) As WebP only supports even offsets, any odd offset will be snapped
|
|
|
|
// to an even location using: offset &= ~1
|
|
|
|
// Parameters:
|
|
|
|
// mux - (in/out) object to which the frame is to be added
|
2012-08-23 11:48:51 +02:00
|
|
|
// frame - (in) frame data.
|
2012-08-23 12:58:36 +02:00
|
|
|
// copy_data - (in) value 1 indicates given data WILL be copied to the mux
|
|
|
|
// and value 0 indicates data will NOT be copied.
|
2011-09-22 12:55:23 +02:00
|
|
|
// Returns:
|
2012-08-23 11:48:51 +02:00
|
|
|
// WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL
|
|
|
|
// or if content of 'frame' is invalid.
|
2011-09-22 12:55:23 +02:00
|
|
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
|
|
|
// WEBP_MUX_OK - on success.
|
2012-06-22 20:17:02 +02:00
|
|
|
WEBP_EXTERN(WebPMuxError) WebPMuxPushFrame(
|
2012-08-23 11:48:51 +02:00
|
|
|
WebPMux* mux, const WebPMuxFrameInfo* frame, int copy_data);
|
2011-11-22 10:10:41 +01:00
|
|
|
|
2012-08-23 12:58:36 +02:00
|
|
|
// Gets the nth frame from the mux object.
|
2012-10-30 22:54:46 +01:00
|
|
|
// The content of 'frame->bitstream' is allocated using malloc(), and NOT
|
2012-06-20 19:59:40 +02:00
|
|
|
// owned by the 'mux' object. It MUST be deallocated by the caller by calling
|
|
|
|
// WebPDataClear().
|
2011-09-22 12:55:23 +02:00
|
|
|
// nth=0 has a special meaning - last position.
|
2011-09-28 05:46:09 +02:00
|
|
|
// Parameters:
|
|
|
|
// mux - (in) object from which the info is to be fetched
|
|
|
|
// nth - (in) index of the frame in the mux object
|
2012-08-23 11:48:51 +02:00
|
|
|
// frame - (out) data of the returned frame
|
2011-09-22 12:55:23 +02:00
|
|
|
// Returns:
|
2012-08-23 12:58:36 +02:00
|
|
|
// WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL.
|
2011-09-28 05:46:09 +02:00
|
|
|
// WEBP_MUX_NOT_FOUND - if there are less than nth frames in the mux object.
|
|
|
|
// WEBP_MUX_BAD_DATA - if nth frame chunk in mux is invalid.
|
2011-09-22 12:55:23 +02:00
|
|
|
// WEBP_MUX_OK - on success.
|
2012-02-18 00:13:09 +01:00
|
|
|
WEBP_EXTERN(WebPMuxError) WebPMuxGetFrame(
|
2012-08-23 11:48:51 +02:00
|
|
|
const WebPMux* mux, uint32_t nth, WebPMuxFrameInfo* frame);
|
2011-09-22 12:55:23 +02:00
|
|
|
|
2012-08-23 12:58:36 +02:00
|
|
|
// Deletes a frame from the mux object.
|
2011-09-22 12:55:23 +02:00
|
|
|
// nth=0 has a special meaning - last position.
|
2011-09-28 05:46:09 +02:00
|
|
|
// Parameters:
|
|
|
|
// mux - (in/out) object from which a frame is to be deleted
|
|
|
|
// nth - (in) The position from which the frame is to be deleted
|
2011-09-22 12:55:23 +02:00
|
|
|
// Returns:
|
2012-08-23 12:58:36 +02:00
|
|
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL.
|
2011-09-22 12:55:23 +02:00
|
|
|
// WEBP_MUX_NOT_FOUND - If there are less than nth frames in the mux object
|
|
|
|
// before deletion.
|
|
|
|
// WEBP_MUX_OK - on success.
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(WebPMuxError) WebPMuxDeleteFrame(WebPMux* mux, uint32_t nth);
|
2011-09-22 12:55:23 +02:00
|
|
|
|
2012-08-23 12:58:36 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Animation.
|
|
|
|
|
2011-09-28 05:46:09 +02:00
|
|
|
// Sets the animation loop count in the mux object. Any existing loop count
|
|
|
|
// value(s) will be removed.
|
|
|
|
// Parameters:
|
|
|
|
// mux - (in/out) object in which loop chunk is to be set/added
|
|
|
|
// loop_count - (in) animation loop count value.
|
|
|
|
// Note that loop_count of zero denotes infinite loop.
|
2011-09-22 12:55:23 +02:00
|
|
|
// Returns:
|
|
|
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL
|
|
|
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
|
|
|
// WEBP_MUX_OK - on success.
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(WebPMuxError) WebPMuxSetLoopCount(WebPMux* mux, int loop_count);
|
2011-09-22 12:55:23 +02:00
|
|
|
|
|
|
|
// Gets the animation loop count from the mux object.
|
2011-09-28 05:46:09 +02:00
|
|
|
// Parameters:
|
|
|
|
// mux - (in) object from which the loop count is to be fetched
|
|
|
|
// loop_count - (out) the loop_count value present in the LOOP chunk
|
2011-09-22 12:55:23 +02:00
|
|
|
// Returns:
|
|
|
|
// WEBP_MUX_INVALID_ARGUMENT - if either of mux or loop_count is NULL
|
|
|
|
// WEBP_MUX_NOT_FOUND - if loop chunk is not present in mux object.
|
|
|
|
// WEBP_MUX_OK - on success.
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(WebPMuxError) WebPMuxGetLoopCount(const WebPMux* mux,
|
|
|
|
int* loop_count);
|
2011-09-22 12:55:23 +02:00
|
|
|
|
2011-09-28 05:46:09 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Misc Utilities.
|
|
|
|
|
|
|
|
// Gets the feature flags from the mux object.
|
|
|
|
// Parameters:
|
|
|
|
// mux - (in) object from which the features are to be fetched
|
|
|
|
// flags - (out) the flags specifying which features are present in the
|
|
|
|
// mux object. This will be an OR of various flag values.
|
2012-05-23 11:31:25 +02:00
|
|
|
// Enum 'WebPFeatureFlags' can be used to test individual flag values.
|
2011-09-28 05:46:09 +02:00
|
|
|
// Returns:
|
2012-06-20 19:59:40 +02:00
|
|
|
// WEBP_MUX_INVALID_ARGUMENT - if mux or flags is NULL
|
2011-09-28 05:46:09 +02:00
|
|
|
// WEBP_MUX_NOT_FOUND - if VP8X chunk is not present in mux object.
|
|
|
|
// WEBP_MUX_BAD_DATA - if VP8X chunk in mux is invalid.
|
|
|
|
// WEBP_MUX_OK - on success.
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(WebPMuxError) WebPMuxGetFeatures(const WebPMux* mux,
|
2011-09-28 05:46:09 +02:00
|
|
|
uint32_t* flags);
|
|
|
|
|
|
|
|
// Gets number of chunks having tag value tag in the mux object.
|
|
|
|
// Parameters:
|
|
|
|
// mux - (in) object from which the info is to be fetched
|
2012-06-11 08:54:45 +02:00
|
|
|
// id - (in) chunk id specifying the type of chunk
|
|
|
|
// num_elements - (out) number of chunks with the given chunk id
|
2011-09-28 05:46:09 +02:00
|
|
|
// Returns:
|
2012-06-11 08:54:45 +02:00
|
|
|
// WEBP_MUX_INVALID_ARGUMENT - if either mux, or num_elements is NULL
|
2011-09-28 05:46:09 +02:00
|
|
|
// WEBP_MUX_OK - on success.
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(WebPMuxError) WebPMuxNumChunks(const WebPMux* mux,
|
2012-06-11 08:54:45 +02:00
|
|
|
WebPChunkId id, int* num_elements);
|
2011-09-28 05:46:09 +02:00
|
|
|
|
2012-06-07 07:34:57 +02:00
|
|
|
// Assembles all chunks in WebP RIFF format and returns in 'assembled_data'.
|
2011-09-28 05:46:09 +02:00
|
|
|
// This function also validates the mux object.
|
2012-06-07 07:34:57 +02:00
|
|
|
// Note: The content of 'assembled_data' will be ignored and overwritten.
|
|
|
|
// Also, the content of 'assembled_data' is allocated using malloc(), and NOT
|
|
|
|
// owned by the 'mux' object. It MUST be deallocated by the caller by calling
|
|
|
|
// WebPDataClear().
|
2011-09-28 05:46:09 +02:00
|
|
|
// Parameters:
|
|
|
|
// mux - (in/out) object whose chunks are to be assembled
|
2012-06-07 07:34:57 +02:00
|
|
|
// assembled_data - (out) assembled WebP data
|
2011-09-28 05:46:09 +02:00
|
|
|
// Returns:
|
|
|
|
// WEBP_MUX_BAD_DATA - if mux object is invalid.
|
|
|
|
// WEBP_MUX_INVALID_ARGUMENT - if either mux, output_data or output_size is
|
|
|
|
// NULL.
|
|
|
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
|
|
|
// WEBP_MUX_OK - on success
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(WebPMuxError) WebPMuxAssemble(WebPMux* mux,
|
|
|
|
WebPData* assembled_data);
|
2011-09-28 05:46:09 +02:00
|
|
|
|
2012-06-02 21:49:53 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Demux API.
|
|
|
|
// Enables extraction of image and extended format data from WebP files.
|
|
|
|
|
2012-07-18 20:53:25 +02:00
|
|
|
#define WEBP_DEMUX_ABI_VERSION 0x0100 // MAJOR(8b) + MINOR(8b)
|
2012-06-02 21:49:53 +02:00
|
|
|
|
2012-09-25 18:39:22 +02:00
|
|
|
enum WebPDemuxState {
|
2012-06-02 21:49:53 +02:00
|
|
|
WEBP_DEMUX_PARSING_HEADER, // Not enough data to parse full header.
|
|
|
|
WEBP_DEMUX_PARSED_HEADER, // Header parsing complete, data may be available.
|
|
|
|
WEBP_DEMUX_DONE // Entire file has been parsed.
|
2012-09-25 18:39:22 +02:00
|
|
|
};
|
2012-06-02 21:49:53 +02:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Life of a Demux object
|
|
|
|
|
|
|
|
// Internal, version-checked, entry point
|
|
|
|
WEBP_EXTERN(WebPDemuxer*) WebPDemuxInternal(
|
2012-07-18 00:01:30 +02:00
|
|
|
const WebPData*, int, WebPDemuxState*, int);
|
2012-06-02 21:49:53 +02:00
|
|
|
|
|
|
|
// Parses the WebP file given by 'data'.
|
|
|
|
// A complete WebP file must be present in 'data' for the function to succeed.
|
|
|
|
// Returns a WebPDemuxer object on successful parse, NULL otherwise.
|
2012-07-18 00:01:30 +02:00
|
|
|
static WEBP_INLINE WebPDemuxer* WebPDemux(const WebPData* data) {
|
2012-06-02 21:49:53 +02:00
|
|
|
return WebPDemuxInternal(data, 0, NULL, WEBP_DEMUX_ABI_VERSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parses the WebP file given by 'data'.
|
|
|
|
// If 'state' is non-NULL it will be set to indicate the status of the demuxer.
|
|
|
|
// Returns a WebPDemuxer object on successful parse, NULL otherwise.
|
|
|
|
static WEBP_INLINE WebPDemuxer* WebPDemuxPartial(
|
2012-07-18 00:01:30 +02:00
|
|
|
const WebPData* data, WebPDemuxState* state) {
|
2012-06-02 21:49:53 +02:00
|
|
|
return WebPDemuxInternal(data, 1, state, WEBP_DEMUX_ABI_VERSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Frees memory associated with 'dmux'.
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(void) WebPDemuxDelete(WebPDemuxer* dmux);
|
2012-06-02 21:49:53 +02:00
|
|
|
|
2012-06-07 08:56:08 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Data/information extraction.
|
|
|
|
|
2012-09-25 18:39:22 +02:00
|
|
|
enum WebPFormatFeature {
|
2012-06-07 08:56:08 +02:00
|
|
|
WEBP_FF_FORMAT_FLAGS, // Extended format flags present in the 'VP8X' chunk.
|
|
|
|
WEBP_FF_CANVAS_WIDTH,
|
|
|
|
WEBP_FF_CANVAS_HEIGHT,
|
|
|
|
WEBP_FF_LOOP_COUNT
|
2012-09-25 18:39:22 +02:00
|
|
|
};
|
2012-06-07 08:56:08 +02:00
|
|
|
|
|
|
|
// Get the 'feature' value from the 'dmux'.
|
|
|
|
// NOTE: values are only valid if WebPDemux() was used or WebPDemuxPartial()
|
|
|
|
// returned a state > WEBP_DEMUX_PARSING_HEADER.
|
|
|
|
WEBP_EXTERN(uint32_t) WebPDemuxGetI(
|
2012-07-18 00:01:30 +02:00
|
|
|
const WebPDemuxer* dmux, WebPFormatFeature feature);
|
2012-06-07 08:56:08 +02:00
|
|
|
|
2012-06-10 21:44:32 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Frame iteration.
|
|
|
|
|
2012-09-25 18:39:22 +02:00
|
|
|
struct WebPIterator {
|
2012-10-30 22:54:46 +01:00
|
|
|
int frame_num;
|
|
|
|
int num_frames;
|
|
|
|
int tile_num;
|
|
|
|
int num_tiles;
|
|
|
|
int x_offset, y_offset; // offset relative to the canvas.
|
|
|
|
int width, height; // dimensions of this frame or tile.
|
|
|
|
int duration; // display duration in milliseconds.
|
|
|
|
int complete; // true if 'tile_' contains a full frame. partial images may
|
|
|
|
// still be decoded with the WebP incremental decoder.
|
|
|
|
WebPData tile; // The frame or tile given by 'frame_num_' and 'tile_num_'.
|
2012-06-10 21:44:32 +02:00
|
|
|
|
2012-07-18 02:44:27 +02:00
|
|
|
uint32_t pad[4]; // padding for later use
|
2012-10-30 22:54:46 +01:00
|
|
|
void* private_; // for internal use only.
|
2012-09-25 18:39:22 +02:00
|
|
|
};
|
2012-06-10 21:44:32 +02:00
|
|
|
|
|
|
|
// Retrieves frame 'frame_number' from 'dmux'.
|
|
|
|
// 'iter->tile_' points to the first tile on return from this function.
|
|
|
|
// Individual tiles may be extracted using WebPDemuxSetTile().
|
|
|
|
// Setting 'frame_number' equal to 0 will return the last frame of the image.
|
|
|
|
// Returns false if 'dmux' is NULL or frame 'frame_number' is not present.
|
|
|
|
// Call WebPDemuxReleaseIterator() when use of the iterator is complete.
|
|
|
|
// NOTE: 'dmux' must persist for the lifetime of 'iter'.
|
|
|
|
WEBP_EXTERN(int) WebPDemuxGetFrame(
|
2012-07-18 00:01:30 +02:00
|
|
|
const WebPDemuxer* dmux, int frame_number, WebPIterator* iter);
|
2012-06-10 21:44:32 +02:00
|
|
|
|
2012-06-15 01:59:58 +02:00
|
|
|
// Sets 'iter->tile_' to point to the next ('iter->frame_num_' + 1) or previous
|
|
|
|
// ('iter->frame_num_' - 1) frame. These functions do not loop.
|
2012-06-10 21:44:32 +02:00
|
|
|
// Returns true on success, false otherwise.
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(int) WebPDemuxNextFrame(WebPIterator* iter);
|
|
|
|
WEBP_EXTERN(int) WebPDemuxPrevFrame(WebPIterator* iter);
|
2012-06-10 21:44:32 +02:00
|
|
|
|
|
|
|
// Sets 'iter->tile_' to reflect tile number 'tile_number'.
|
|
|
|
// Returns true if tile 'tile_number' is present, false otherwise.
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(int) WebPDemuxSelectTile(WebPIterator* iter, int tile_number);
|
2012-06-10 21:44:32 +02:00
|
|
|
|
|
|
|
// Releases any memory associated with 'iter'.
|
|
|
|
// Must be called before destroying the associated WebPDemuxer with
|
|
|
|
// WebPDemuxDelete().
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(void) WebPDemuxReleaseIterator(WebPIterator* iter);
|
2012-06-10 21:44:32 +02:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Chunk iteration.
|
|
|
|
|
2012-09-25 18:39:22 +02:00
|
|
|
struct WebPChunkIterator {
|
2012-06-10 21:44:32 +02:00
|
|
|
// The current and total number of chunks with the fourcc given to
|
|
|
|
// WebPDemuxGetChunk().
|
2012-10-30 22:54:46 +01:00
|
|
|
int chunk_num;
|
|
|
|
int num_chunks;
|
|
|
|
WebPData chunk; // The payload of the chunk.
|
2012-06-10 21:44:32 +02:00
|
|
|
|
2012-10-30 22:54:46 +01:00
|
|
|
uint32_t pad[6]; // padding for later use
|
2012-06-10 21:44:32 +02:00
|
|
|
void* private_;
|
2012-09-25 18:39:22 +02:00
|
|
|
};
|
2012-06-10 21:44:32 +02:00
|
|
|
|
|
|
|
// Retrieves the 'chunk_number' instance of the chunk with id 'fourcc' from
|
|
|
|
// 'dmux'.
|
|
|
|
// 'fourcc' is a character array containing the fourcc of the chunk to return,
|
|
|
|
// e.g., "ICCP", "META", "EXIF", etc.
|
|
|
|
// Setting 'chunk_number' equal to 0 will return the last chunk in a set.
|
|
|
|
// Returns true if the chunk is found, false otherwise. Image related chunk
|
|
|
|
// payloads are accessed through WebPDemuxGetFrame() and related functions.
|
|
|
|
// Call WebPDemuxReleaseChunkIterator() when use of the iterator is complete.
|
|
|
|
// NOTE: 'dmux' must persist for the lifetime of the iterator.
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(int) WebPDemuxGetChunk(const WebPDemuxer* dmux,
|
2012-06-10 21:44:32 +02:00
|
|
|
const char fourcc[4], int chunk_number,
|
2012-07-18 00:01:30 +02:00
|
|
|
WebPChunkIterator* iter);
|
2012-06-10 21:44:32 +02:00
|
|
|
|
2012-06-22 03:27:54 +02:00
|
|
|
// Sets 'iter->chunk_' to point to the next ('iter->chunk_num_' + 1) or previous
|
|
|
|
// ('iter->chunk_num_' - 1) chunk. These functions do not loop.
|
2012-06-10 21:44:32 +02:00
|
|
|
// Returns true on success, false otherwise.
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(int) WebPDemuxNextChunk(WebPChunkIterator* iter);
|
|
|
|
WEBP_EXTERN(int) WebPDemuxPrevChunk(WebPChunkIterator* iter);
|
2012-06-10 21:44:32 +02:00
|
|
|
|
|
|
|
// Releases any memory associated with 'iter'.
|
|
|
|
// Must be called before destroying the associated WebPDemuxer with
|
|
|
|
// WebPDemuxDelete().
|
2012-07-18 00:01:30 +02:00
|
|
|
WEBP_EXTERN(void) WebPDemuxReleaseChunkIterator(WebPChunkIterator* iter);
|
2012-06-10 21:44:32 +02:00
|
|
|
|
2011-09-22 12:55:23 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* WEBP_WEBP_MUX_H_ */
|