Create WebPMuxFrameInfo struct for Mux APIs

Change-Id: I1f3b15d679280b5347124e1d59865a3df089043b
This commit is contained in:
Urvang Joshi
2012-08-23 15:18:51 +05:30
parent e3990fd8e4
commit ab3234ae6b
4 changed files with 102 additions and 119 deletions

View File

@ -317,8 +317,10 @@ WebPMuxError WebPMuxSetLoopCount(WebPMux* mux, int loop_count) {
}
static WebPMuxError MuxPushFrameTileInternal(
WebPMux* const mux, const WebPData* const bitstream, int x_offset,
int y_offset, int duration, int copy_data, uint32_t tag) {
WebPMux* const mux, const WebPMuxFrameInfo* const frame_tile_info,
int copy_data, uint32_t tag) {
const WebPData* bitstream;
int x_offset, y_offset, duration;
WebPChunk chunk;
WebPData image;
WebPData alpha;
@ -330,13 +332,21 @@ static WebPMuxError MuxPushFrameTileInternal(
int image_tag;
// Sanity checks.
if (mux == NULL || bitstream == NULL || bitstream->bytes_ == NULL ||
bitstream->size_ > MAX_CHUNK_PAYLOAD) {
if (mux == NULL || frame_tile_info == NULL) {
return WEBP_MUX_INVALID_ARGUMENT;
}
bitstream = &frame_tile_info->bitstream_;
x_offset = frame_tile_info->x_offset_;
y_offset = frame_tile_info->y_offset_;
duration = is_frame ? frame_tile_info->duration_ : 1 /* unused */;
if (bitstream->bytes_ == NULL || bitstream->size_ > MAX_CHUNK_PAYLOAD) {
return WEBP_MUX_INVALID_ARGUMENT;
}
if (x_offset < 0 || x_offset >= MAX_POSITION_OFFSET ||
y_offset < 0 || y_offset >= MAX_POSITION_OFFSET ||
duration <= 0 || duration > MAX_DURATION) {
(is_frame && (duration <= 0 || duration > MAX_DURATION))) {
return WEBP_MUX_INVALID_ARGUMENT;
}
@ -397,18 +407,17 @@ static WebPMuxError MuxPushFrameTileInternal(
return err;
}
WebPMuxError WebPMuxPushFrame(WebPMux* mux, const WebPData* bitstream,
int x_offset, int y_offset,
int duration, int copy_data) {
return MuxPushFrameTileInternal(mux, bitstream, x_offset, y_offset,
duration, copy_data, kChunks[IDX_FRAME].tag);
WebPMuxError WebPMuxPushFrame(WebPMux* mux,
const WebPMuxFrameInfo* frame,
int copy_data) {
return MuxPushFrameTileInternal(mux, frame, copy_data,
kChunks[IDX_FRAME].tag);
}
WebPMuxError WebPMuxPushTile(WebPMux* mux, const WebPData* bitstream,
int x_offset, int y_offset,
WebPMuxError WebPMuxPushTile(WebPMux* mux,
const WebPMuxFrameInfo* tile,
int copy_data) {
return MuxPushFrameTileInternal(mux, bitstream, x_offset, y_offset,
1 /* unused duration */, copy_data,
return MuxPushFrameTileInternal(mux, tile /*unused duration*/, copy_data,
kChunks[IDX_TILE].tag);
}

View File

@ -315,9 +315,8 @@ WebPMuxError WebPMuxGetLoopCount(const WebPMux* mux, int* loop_count) {
}
static WebPMuxError MuxGetFrameTileInternal(
const WebPMux* const mux, uint32_t nth, WebPData* const bitstream,
int* const x_offset, int* const y_offset, int* const duration,
uint32_t tag) {
const WebPMux* const mux, uint32_t nth,
WebPMuxFrameInfo* const frame_tile_info, uint32_t tag) {
const WebPData* frame_tile_data;
WebPMuxError err;
WebPMuxImage* wpi;
@ -326,8 +325,7 @@ static WebPMuxError MuxGetFrameTileInternal(
const CHUNK_INDEX idx = is_frame ? IDX_FRAME : IDX_TILE;
const WebPChunkId id = kChunks[idx].id;
if (mux == NULL || bitstream == NULL ||
x_offset == NULL || y_offset == NULL || (is_frame && duration == NULL)) {
if (mux == NULL || frame_tile_info == NULL) {
return WEBP_MUX_INVALID_ARGUMENT;
}
@ -340,25 +338,23 @@ static WebPMuxError MuxGetFrameTileInternal(
frame_tile_data = &wpi->header_->data_;
if (frame_tile_data->size_ < kChunks[idx].size) return WEBP_MUX_BAD_DATA;
*x_offset = 2 * GetLE24(frame_tile_data->bytes_ + 0);
*y_offset = 2 * GetLE24(frame_tile_data->bytes_ + 3);
if (is_frame) *duration = 1 + GetLE24(frame_tile_data->bytes_ + 12);
frame_tile_info->x_offset_ = 2 * GetLE24(frame_tile_data->bytes_ + 0);
frame_tile_info->y_offset_ = 2 * GetLE24(frame_tile_data->bytes_ + 3);
if (is_frame) {
frame_tile_info->duration_ = 1 + GetLE24(frame_tile_data->bytes_ + 12);
}
return SynthesizeBitstream(wpi, bitstream);
return SynthesizeBitstream(wpi, &frame_tile_info->bitstream_);
}
WebPMuxError WebPMuxGetFrame(const WebPMux* mux, uint32_t nth,
WebPData* bitstream,
int* x_offset, int* y_offset, int* duration) {
return MuxGetFrameTileInternal(mux, nth, bitstream, x_offset, y_offset,
duration, kChunks[IDX_FRAME].tag);
WebPMuxFrameInfo* frame) {
return MuxGetFrameTileInternal(mux, nth, frame, kChunks[IDX_FRAME].tag);
}
WebPMuxError WebPMuxGetTile(const WebPMux* mux, uint32_t nth,
WebPData* bitstream,
int* x_offset, int* y_offset) {
return MuxGetFrameTileInternal(mux, nth, bitstream, x_offset, y_offset, NULL,
kChunks[IDX_TILE].tag);
WebPMuxFrameInfo* tile) {
return MuxGetFrameTileInternal(mux, nth, tile, kChunks[IDX_TILE].tag);
}
// Get chunk index from chunk id. Returns IDX_NIL if not found.

View File

@ -174,7 +174,7 @@ WEBP_EXTERN(WebPMuxError) WebPMuxSetImage(WebPMux* mux,
// bitstream - (out) the image data
// Returns:
// WEBP_MUX_INVALID_ARGUMENT - if either mux or bitstream is NULL
// OR mux contains animation/tiling.
// or if mux contains animation/tiling.
// WEBP_MUX_NOT_FOUND - if image is not present in mux object.
// WEBP_MUX_OK - on success.
WEBP_EXTERN(WebPMuxError) WebPMuxGetImage(const WebPMux* mux,
@ -185,7 +185,7 @@ WEBP_EXTERN(WebPMuxError) WebPMuxGetImage(const WebPMux* mux,
// mux - (in/out) object from which the image is to be deleted
// Returns:
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL
// OR if mux contains animation/tiling.
// or if mux contains animation/tiling.
// WEBP_MUX_NOT_FOUND - if image is not present in mux object.
// WEBP_MUX_OK - on success.
WEBP_EXTERN(WebPMuxError) WebPMuxDeleteImage(WebPMux* mux);
@ -271,55 +271,48 @@ WEBP_EXTERN(WebPMuxError) WebPMuxDeleteColorProfile(WebPMux* mux);
//------------------------------------------------------------------------------
// Animation.
// Encapsulates data about a single frame/tile.
typedef struct {
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).
uint32_t pad[3]; // padding for later use
} WebPMuxFrameInfo;
// Adds an animation frame at the end of the mux object.
// Note: 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 an animation frame is to be added
// bitstream - (in) the image data corresponding to the frame. It can either
// be a raw VP8/VP8L bitstream or a single-image WebP file
// (non-animated and non-tiled)
// x_offset - (in) x-offset of the frame to be added
// y_offset - (in) y-offset of the frame to be added
// duration - (in) duration of the frame to be added (in milliseconds)
// frame - (in) frame data.
// copy_data - (in) value 1 indicates given data WILL 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_INVALID_ARGUMENT - if mux or frame is NULL
// or if content of 'frame' is invalid.
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
// WEBP_MUX_OK - on success.
WEBP_EXTERN(WebPMuxError) WebPMuxPushFrame(
WebPMux* mux, const WebPData* bitstream,
int x_offset, int y_offset, int duration, int copy_data);
// TODO(urvang): Create a struct as follows to reduce argument list size:
// typedef struct {
// WebPData bitstream;
// int x_offset, y_offset;
// int duration;
// } FrameInfo;
WebPMux* mux, const WebPMuxFrameInfo* frame, int copy_data);
// Gets the nth animation frame from the mux object.
// The content of 'bitstream' is allocated using malloc(), and NOT
// The content of 'frame->bitstream_' is allocated using malloc(), and NOT
// owned by the 'mux' object. It MUST be deallocated by the caller by calling
// WebPDataClear().
// nth=0 has a special meaning - last position.
// Parameters:
// mux - (in) object from which the info is to be fetched
// nth - (in) index of the frame in the mux object
// bitstream - (out) the image data
// x_offset - (out) x-offset of the returned frame
// y_offset - (out) y-offset of the returned frame
// duration - (out) duration of the returned frame (in milliseconds)
// frame - (out) data of the returned frame
// Returns:
// WEBP_MUX_INVALID_ARGUMENT - if either mux, bitstream, x_offset,
// y_offset, or duration is NULL
// WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL
// 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.
// WEBP_MUX_OK - on success.
WEBP_EXTERN(WebPMuxError) WebPMuxGetFrame(
const WebPMux* mux, uint32_t nth, WebPData* bitstream,
int* x_offset, int* y_offset, int* duration);
const WebPMux* mux, uint32_t nth, WebPMuxFrameInfo* frame);
// Deletes an animation frame from the mux object.
// nth=0 has a special meaning - last position.
@ -364,41 +357,33 @@ WEBP_EXTERN(WebPMuxError) WebPMuxGetLoopCount(const WebPMux* mux,
// an even location using: offset &= ~1
// Parameters:
// mux - (in/out) object to which a tile is to be added.
// bitstream - (in) the image data corresponding to the frame. It can either
// be a raw VP8/VP8L bitstream or a single-image WebP file
// (non-animated and non-tiled)
// x_offset - (in) x-offset of the tile to be added
// y_offset - (in) y-offset of the tile to be added
// tile - (in) tile data.
// copy_data - (in) value 1 indicates given data WILL 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_INVALID_ARGUMENT - if mux or tile is NULL
// or if content of 'tile' is invalid.
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
// WEBP_MUX_OK - on success.
WEBP_EXTERN(WebPMuxError) WebPMuxPushTile(
WebPMux* mux, const WebPData* bitstream,
int x_offset, int y_offset, int copy_data);
WebPMux* mux, const WebPMuxFrameInfo* tile, int copy_data);
// Gets the nth tile from the mux object.
// The content of 'bitstream' is allocated using malloc(), and NOT
// The content of 'tile->bitstream_' is allocated using malloc(), and NOT
// owned by the 'mux' object. It MUST be deallocated by the caller by calling
// WebPDataClear().
// nth=0 has a special meaning - last position.
// Parameters:
// mux - (in) object from which the info is to be fetched
// nth - (in) index of the tile in the mux object
// bitstream - (out) the image data
// x_offset - (out) x-offset of the returned tile
// y_offset - (out) y-offset of the returned tile
// tile - (out) data of the returned tile
// Returns:
// WEBP_MUX_INVALID_ARGUMENT - if either mux, bitstream, x_offset or
// y_offset is NULL
// WEBP_MUX_INVALID_ARGUMENT - if either mux or tile is NULL
// WEBP_MUX_NOT_FOUND - if there are less than nth tiles in the mux object.
// WEBP_MUX_BAD_DATA - if nth tile chunk in mux is invalid.
// WEBP_MUX_OK - on success.
WEBP_EXTERN(WebPMuxError) WebPMuxGetTile(
const WebPMux* mux, uint32_t nth, WebPData* bitstream,
int* x_offset, int* y_offset);
const WebPMux* mux, uint32_t nth, WebPMuxFrameInfo* tile);
// Deletes a tile from the mux object.
// nth=0 has a special meaning - last position