From 857650c8fcc4804c7a7b873e70f9ac0f23ef5383 Mon Sep 17 00:00:00 2001 From: Urvang Joshi Date: Fri, 6 Jul 2012 14:29:35 +0530 Subject: [PATCH] Mux: Add WebPDataInit() and remove WebPImageInfo Change-Id: If661f7d198e284a103a53a451e9f74805119fcf9 --- src/mux/muxedit.c | 53 ++++++++++++++----------------------------- src/mux/muxinternal.c | 10 ++++++-- src/mux/muxread.c | 2 +- src/webp/mux.h | 3 +++ 4 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/mux/muxedit.c b/src/mux/muxedit.c index 8e163a97..882ae708 100644 --- a/src/mux/muxedit.c +++ b/src/mux/muxedit.c @@ -17,15 +17,6 @@ extern "C" { #endif -// Object to store metadata about images. -typedef struct { - int x_offset_; - int y_offset_; - int duration_; - int width_; - int height_; -} WebPImageInfo; - //------------------------------------------------------------------------------ // Life of a mux object. @@ -155,7 +146,7 @@ static WebPMuxError CreateFrameTileData(const WebPData* const image, static WebPMuxError GetImageData(const WebPData* const bitstream, WebPData* const image, WebPData* const alpha, int* const is_lossless) { - memset(alpha, 0, sizeof(*alpha)); // Default: no alpha. + WebPDataInit(alpha); // Default: no alpha. if (bitstream->size_ < TAG_SIZE || memcmp(bitstream->bytes_, "RIFF", TAG_SIZE)) { // It is NOT webp file data. Return input data as is. @@ -359,7 +350,7 @@ static WebPMuxError MuxPushFrameTileInternal( if (err != WEBP_MUX_OK) return err; image_tag = is_lossless ? kChunks[IDX_VP8L].tag : kChunks[IDX_VP8].tag; - memset(&frame_tile, 0, sizeof(frame_tile)); + WebPDataInit(&frame_tile); ChunkInit(&chunk); MuxImageInit(&wpi); @@ -506,30 +497,19 @@ WebPMuxError MuxGetImageWidthHeight(const WebPChunk* const image_chunk, } static WebPMuxError GetImageInfo(const WebPMuxImage* const wpi, - WebPImageInfo* const image_info) { + int* const x_offset, int* const y_offset, + int* const duration, + int* const width, int* const height) { const WebPChunk* const image_chunk = wpi->img_; const WebPChunk* const frame_tile_chunk = wpi->header_; - WebPMuxError err; - int x_offset, y_offset, duration; - int width, height; - - memset(image_info, 0, sizeof(*image_info)); // Get offsets and duration from FRM/TILE chunk. - err = GetFrameTileInfo(frame_tile_chunk, &x_offset, &y_offset, &duration); + const WebPMuxError err = + GetFrameTileInfo(frame_tile_chunk, x_offset, y_offset, duration); if (err != WEBP_MUX_OK) return err; // Get width and height from VP8/VP8L chunk. - err = MuxGetImageWidthHeight(image_chunk, &width, &height); - if (err != WEBP_MUX_OK) return err; - - // All OK: fill up image_info. - image_info->x_offset_ = x_offset; - image_info->y_offset_ = y_offset; - image_info->duration_ = duration; - image_info->width_ = width; - image_info->height_ = height; - return WEBP_MUX_OK; + return MuxGetImageWidthHeight(image_chunk, width, height); } static WebPMuxError GetImageCanvasWidthHeight( @@ -537,7 +517,7 @@ static WebPMuxError GetImageCanvasWidthHeight( int* const width, int* const height) { WebPMuxImage* wpi = NULL; assert(mux != NULL); - assert(width && height); + assert(width != NULL && height != NULL); wpi = mux->images_; assert(wpi != NULL); @@ -549,17 +529,18 @@ static WebPMuxError GetImageCanvasWidthHeight( int64_t image_area = 0; // Aggregate the bounding box for animation frames & tiled images. for (; wpi != NULL; wpi = wpi->next_) { - WebPImageInfo image_info; - const WebPMuxError err = GetImageInfo(wpi, &image_info); - const int max_x_pos = image_info.x_offset_ + image_info.width_; - const int max_y_pos = image_info.y_offset_ + image_info.height_; + int x_offset, y_offset, duration, w, h; + const WebPMuxError err = GetImageInfo(wpi, &x_offset, &y_offset, + &duration, &w, &h); + const int max_x_pos = x_offset + w; + const int max_y_pos = y_offset + h; if (err != WEBP_MUX_OK) return err; - assert(image_info.x_offset_ < MAX_POSITION_OFFSET); - assert(image_info.y_offset_ < MAX_POSITION_OFFSET); + assert(x_offset < MAX_POSITION_OFFSET); + assert(y_offset < MAX_POSITION_OFFSET); if (max_x_pos > max_x) max_x = max_x_pos; if (max_y_pos > max_y) max_y = max_y_pos; - image_area += (image_info.width_ * image_info.height_); + image_area += w * h; } *width = max_x; *height = max_y; diff --git a/src/mux/muxinternal.c b/src/mux/muxinternal.c index ce3cb6f1..a2e60ca7 100644 --- a/src/mux/muxinternal.c +++ b/src/mux/muxinternal.c @@ -212,17 +212,23 @@ uint8_t* ChunkListEmit(const WebPChunk* chunk_list, uint8_t* dst) { //------------------------------------------------------------------------------ // Manipulation of a WebPData object. +void WebPDataInit(WebPData* const webp_data) { + if (webp_data != NULL) { + memset(webp_data, 0, sizeof(*webp_data)); + } +} + void WebPDataClear(WebPData* const webp_data) { if (webp_data != NULL) { free((void*)webp_data->bytes_); - memset(webp_data, 0, sizeof(*webp_data)); + WebPDataInit(webp_data); } } int WebPDataCopy(const WebPData* const src, WebPData* const dst) { if (src == NULL || dst == NULL) return 0; - memset(dst, 0, sizeof(*dst)); + WebPDataInit(dst); if (src->bytes_ != NULL && src->size_ != 0) { dst->bytes_ = (uint8_t*)malloc(src->size_); if (dst->bytes_ == NULL) return 0; diff --git a/src/mux/muxread.c b/src/mux/muxread.c index 4562bc9e..b0e86a6b 100644 --- a/src/mux/muxread.c +++ b/src/mux/muxread.c @@ -37,7 +37,7 @@ static WebPMuxError MuxGet(const WebPMux* const mux, CHUNK_INDEX idx, uint32_t nth, WebPData* const data) { assert(mux != NULL); assert(!IsWPI(kChunks[idx].id)); - memset(data, 0, sizeof(*data)); + WebPDataInit(data); SWITCH_ID_LIST(IDX_VP8X, mux->vp8x_); SWITCH_ID_LIST(IDX_ICCP, mux->iccp_); diff --git a/src/webp/mux.h b/src/webp/mux.h index c028f019..40a86756 100644 --- a/src/webp/mux.h +++ b/src/webp/mux.h @@ -100,6 +100,9 @@ typedef struct { //------------------------------------------------------------------------------ // Manipulation of a WebPData object. +// Initializes the contents of the 'webp_data' object with default values. +WEBP_EXTERN(void) WebPDataInit(WebPData* const webp_data); + // Clears the contents of the 'webp_data' object by calling free(). Does not // deallocate the object itself. WEBP_EXTERN(void) WebPDataClear(WebPData* const webp_data);