From eec4b87718595e5c633d9452c7ffc6a31d5b2c0f Mon Sep 17 00:00:00 2001 From: James Zern Date: Sat, 7 Jan 2012 12:44:01 -0800 Subject: [PATCH] mux: add WebPData type slightly simplifies Get process Change-Id: I9db365da29038e02a032494e0ef3d8a0d7515210 --- README.mux | 9 ++-- examples/webpmux.c | 82 +++++++++++++++++------------------- src/mux/muxedit.c | 31 ++++++-------- src/mux/muxread.c | 103 ++++++++++++++++++++------------------------- src/webp/mux.h | 73 +++++++++++++++----------------- 5 files changed, 135 insertions(+), 163 deletions(-) diff --git a/README.mux b/README.mux index b9473d8f..5cf182e1 100644 --- a/README.mux +++ b/README.mux @@ -91,11 +91,10 @@ Example#2 (pseudo code): Get image & color profile data from a WebP file. int copy_data = 0; // ... (Read data from file). WebPMux* mux = WebPMuxCreate(data, data_size, copy_data); - WebPMuxGetImage(mux, &image_data, &image_data_size, - &alpha_data, &alpha_size); - // ... (Consume image_data; e.g. call WebPDecode() to decode the data). - WebPMuxGetColorProfile(mux, &icc_data, &icc_data_size); - // ... (Consume icc_data). + WebPMuxGetImage(mux, &image, &alpha); + // ... (Consume image; e.g. call WebPDecode() to decode the data). + WebPMuxGetColorProfile(mux, &icc_chunkdata); + // ... (Consume icc_chunkdata). WebPMuxDelete(mux); free(data); diff --git a/examples/webpmux.c b/examples/webpmux.c index 0f6d12a9..50eef1a5 100644 --- a/examples/webpmux.c +++ b/examples/webpmux.c @@ -153,12 +153,6 @@ static int IsNotCompatible(int count1, int count2) { } while (0) static WebPMuxError DisplayInfo(const WebPMux* mux) { - int nFrames; - int nTiles; - const uint8_t* data = NULL; - uint32_t size = 0; - const uint8_t* alpha_data; - uint32_t alpha_size; uint32_t flag; WebPMuxError err = WebPMuxGetFeatures(mux, &flag); @@ -179,6 +173,7 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) { fprintf(stderr, "\n"); if (flag & ANIMATION_FLAG) { + int nFrames; uint32_t loop_count; err = WebPMuxGetLoopCount(mux, &loop_count); RETURN_IF_ERROR("Failed to retrieve loop count\n"); @@ -195,17 +190,19 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) { if (flag & ALPHA_FLAG) fprintf(stderr, " alpha_size"); fprintf(stderr, "\n"); for (i = 1; i <= nFrames; i++) { - err = WebPMuxGetFrame(mux, i, &data, &size, &alpha_data, &alpha_size, + WebPData image, alpha; + err = WebPMuxGetFrame(mux, i, &image, &alpha, &x_offset, &y_offset, &duration); RETURN_IF_ERROR2("Failed to retrieve frame#%d\n", i); fprintf(stderr, "%3d: %8d %8d %8d", i, x_offset, y_offset, duration); - if (flag & ALPHA_FLAG) fprintf(stderr, " %10d", alpha_size); + if (flag & ALPHA_FLAG) fprintf(stderr, " %10u", alpha.size_); fprintf(stderr, "\n"); } } } if (flag & TILE_FLAG) { + int nTiles; err = WebPMuxNumNamedElements(mux, "tile", &nTiles); RETURN_IF_ERROR("Failed to retrieve number of tiles\n"); @@ -217,32 +214,35 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) { if (flag & ALPHA_FLAG) fprintf(stderr, " alpha_size"); fprintf(stderr, "\n"); for (i = 1; i <= nTiles; i++) { - err = WebPMuxGetTile(mux, i, &data, &size, &alpha_data, &alpha_size, - &x_offset, &y_offset); + WebPData image, alpha; + err = WebPMuxGetTile(mux, i, &image, &alpha, &x_offset, &y_offset); RETURN_IF_ERROR2("Failed to retrieve tile#%d\n", i); fprintf(stderr, "%3d: %8d %8d", i, x_offset, y_offset); - if (flag & ALPHA_FLAG) fprintf(stderr, " %10d", alpha_size); + if (flag & ALPHA_FLAG) fprintf(stderr, " %10u", alpha.size_); fprintf(stderr, "\n"); } } } if (flag & ICCP_FLAG) { - err = WebPMuxGetColorProfile(mux, &data, &size); + WebPData icc_profile; + err = WebPMuxGetColorProfile(mux, &icc_profile); RETURN_IF_ERROR("Failed to retrieve the color profile\n"); - fprintf(stderr, "Size of the color profile data: %d\n", size); + fprintf(stderr, "Size of the color profile data: %u\n", icc_profile.size_); } if (flag & META_FLAG) { - err = WebPMuxGetMetadata(mux, &data, &size); + WebPData metadata; + err = WebPMuxGetMetadata(mux, &metadata); RETURN_IF_ERROR("Failed to retrieve the XMP metadata\n"); - fprintf(stderr, "Size of the XMP metadata: %d\n", size); + fprintf(stderr, "Size of the XMP metadata: %u\n", metadata.size_); } if ((flag & ALPHA_FLAG) && !(flag & (ANIMATION_FLAG | TILE_FLAG))) { - err = WebPMuxGetImage(mux, &data, &size, &alpha_data, &alpha_size); + WebPData image, alpha; + err = WebPMuxGetImage(mux, &image, &alpha); RETURN_IF_ERROR("Failed to retrieve the image\n"); - fprintf(stderr, "Size of the alpha data: %d\n", alpha_size); + fprintf(stderr, "Size of the alpha data: %u\n", alpha.size_); } return WEBP_MUX_OK; @@ -373,8 +373,7 @@ static int ReadImage(const char* filename, const uint8_t** alpha_data_ptr, uint32_t* alpha_size_ptr) { void* data = NULL; uint32_t size = 0; - const uint8_t* alpha_data = NULL; - uint32_t alpha_size = 0; + WebPData image, alpha; WebPMux* mux; WebPMuxError err; int ok = 0; @@ -390,25 +389,25 @@ static int ReadImage(const char* filename, filename, mux_state); return 0; } - err = WebPMuxGetImage(mux, (const uint8_t**)&data, &size, - &alpha_data, &alpha_size); + err = WebPMuxGetImage(mux, &image, &alpha); if (err == WEBP_MUX_OK) { - uint8_t* const data_mem = (uint8_t*)malloc(size); - uint8_t* const alpha_mem = (uint8_t*)malloc(alpha_size); + uint8_t* const data_mem = (uint8_t*)malloc(image.size_); + uint8_t* const alpha_mem = (uint8_t*)malloc(alpha.size_); if ((data_mem != NULL) && (alpha_mem != NULL)) { - memcpy(data_mem, data, size); - memcpy(alpha_mem, alpha_data, alpha_size); + memcpy(data_mem, image.bytes_, image.size_); + memcpy(alpha_mem, alpha.bytes_, alpha.size_); *data_ptr = data_mem; - *size_ptr = size; + *size_ptr = image.size_; *alpha_data_ptr = alpha_mem; - *alpha_size_ptr = alpha_size; + *alpha_size_ptr = alpha.size_; ok = 1; } else { free(data_mem); free(alpha_mem); err = WEBP_MUX_MEMORY_ERROR; - fprintf(stderr, "Failed to allocate %d bytes to extract image data from" - " file %s. Error: %d\n", size + alpha_size, filename, err); + fprintf(stderr, "Failed to allocate %u bytes to extract image data from" + " file %s. Error: %d\n", + image.size_ + alpha.size_, filename, err); } } else { fprintf(stderr, "Failed to extract image data from file %s. Error: %d\n", @@ -418,7 +417,7 @@ static int ReadImage(const char* filename, return ok; } -static int WriteData(const char* filename, void* data, uint32_t size) { +static int WriteData(const char* filename, const void* data, uint32_t size) { int ok = 0; FILE* fout = strcmp(filename, "-") ? fopen(filename, "wb") : stdout; if (!fout) { @@ -783,10 +782,7 @@ static int InitializeConfig(int argc, const char* argv[], static int GetFrameTile(const WebPMux* mux, const WebPMuxConfig* config, int isFrame) { - const uint8_t* data = NULL; - uint32_t size = 0; - const uint8_t* alpha_data = NULL; - uint32_t alpha_size = 0; + WebPData image, alpha; uint32_t x_offset = 0; uint32_t y_offset = 0; uint32_t duration = 0; @@ -801,14 +797,13 @@ static int GetFrameTile(const WebPMux* mux, } if (isFrame) { - err = WebPMuxGetFrame(mux, num, &data, &size, &alpha_data, &alpha_size, + err = WebPMuxGetFrame(mux, num, &image, &alpha, &x_offset, &y_offset, &duration); if (err != WEBP_MUX_OK) { ERROR_GOTO3("ERROR#%d: Could not get frame %ld.\n", err, num, ErrGet); } } else { - err = WebPMuxGetTile(mux, num, &data, &size, &alpha_data, &alpha_size, - &x_offset, &y_offset); + err = WebPMuxGetTile(mux, num, &image, &alpha, &x_offset, &y_offset); if (err != WEBP_MUX_OK) { ERROR_GOTO3("ERROR#%d: Could not get frame %ld.\n", err, num, ErrGet); } @@ -819,7 +814,8 @@ static int GetFrameTile(const WebPMux* mux, err = WEBP_MUX_MEMORY_ERROR; ERROR_GOTO2("ERROR#%d: Could not allocate a mux object.\n", err, ErrGet); } - err = WebPMuxSetImage(mux_single, data, size, alpha_data, alpha_size, 1); + err = WebPMuxSetImage(mux_single, image.bytes_, image.size_, + alpha.bytes_, alpha.size_, 1); if (err != WEBP_MUX_OK) { ERROR_GOTO2("ERROR#%d: Could not create single image mux object.\n", err, ErrGet); @@ -834,6 +830,7 @@ static int GetFrameTile(const WebPMux* mux, // Read and process config. static int Process(const WebPMuxConfig* config) { WebPMux* mux = NULL; + WebPData webpdata; const uint8_t* data = NULL; uint32_t size = 0; const uint8_t* alpha_data = NULL; @@ -862,19 +859,18 @@ static int Process(const WebPMuxConfig* config) { break; case FEATURE_ICCP: - err = WebPMuxGetColorProfile(mux, &data, &size); + err = WebPMuxGetColorProfile(mux, &webpdata); if (err != WEBP_MUX_OK) { ERROR_GOTO2("ERROR#%d: Could not get color profile.\n", err, Err2); } - ok = WriteData(config->output_, (void*)data, size); + ok = WriteData(config->output_, webpdata.bytes_, webpdata.size_); break; - case FEATURE_XMP: - err = WebPMuxGetMetadata(mux, &data, &size); + err = WebPMuxGetMetadata(mux, &webpdata); if (err != WEBP_MUX_OK) { ERROR_GOTO2("ERROR#%d: Could not get XMP metadata.\n", err, Err2); } - ok = WriteData(config->output_, (void*)data, size); + ok = WriteData(config->output_, webpdata.bytes_, webpdata.size_); break; default: diff --git a/src/mux/muxedit.c b/src/mux/muxedit.c index 848df856..3fd6c464 100644 --- a/src/mux/muxedit.c +++ b/src/mux/muxedit.c @@ -167,14 +167,11 @@ static WebPMuxError CreateDataFromImageInfo(WebPImageInfo* image_info, // Outputs image data given data from a webp file (including RIFF header). static WebPMuxError GetImageData(const uint8_t* data, uint32_t size, - const uint8_t** image_data, - uint32_t* image_size, - const uint8_t** alpha_data, - uint32_t* alpha_size) { + WebPData* const image, WebPData* const alpha) { if ((size < TAG_SIZE) || (memcmp(data, "RIFF", TAG_SIZE))) { // It is NOT webp file data. Return input data as is. - *image_data = data; - *image_size = size; + image->bytes_ = data; + image->size_ = size; return WEBP_MUX_OK; } else { // It is webp file data. Extract image data from it. @@ -186,7 +183,7 @@ static WebPMuxError GetImageData(const uint8_t* data, uint32_t size, return WEBP_MUX_BAD_DATA; } - err = WebPMuxGetImage(mux, image_data, image_size, alpha_data, alpha_size); + err = WebPMuxGetImage(mux, image, alpha); WebPMuxDelete(mux); return err; } @@ -237,8 +234,7 @@ WebPMuxError WebPMuxSetImage(WebPMux* const mux, WebPMuxError err; WebPChunk chunk; WebPMuxImage wpi; - const uint8_t* vp8_data; - uint32_t vp8_size; + WebPData image; const int has_alpha = (alpha_data != NULL && alpha_size != 0); if ((mux == NULL) || (data == NULL) || (size > MAX_CHUNK_PAYLOAD)) { @@ -246,7 +242,7 @@ WebPMuxError WebPMuxSetImage(WebPMux* const mux, } // If given data is for a whole webp file, extract only the VP8 data from it. - err = GetImageData(data, size, &vp8_data, &vp8_size, NULL, NULL); + err = GetImageData(data, size, &image, NULL); if (err != WEBP_MUX_OK) return err; // Delete the existing images. @@ -265,8 +261,8 @@ WebPMuxError WebPMuxSetImage(WebPMux* const mux, // Add image chunk. ChunkInit(&chunk); - err = ChunkAssignDataImageInfo(&chunk, vp8_data, vp8_size, NULL, copy_data, - kChunks[IMAGE_ID].chunkTag); + err = ChunkAssignDataImageInfo(&chunk, image.bytes_, image.size_, NULL, + copy_data, kChunks[IMAGE_ID].chunkTag); if (err != WEBP_MUX_OK) return err; err = ChunkSetNth(&chunk, &wpi.vp8_, 1); if (err != WEBP_MUX_OK) return err; @@ -337,13 +333,12 @@ static WebPMuxError MuxAddFrameTileInternal(WebPMux* const mux, uint32_t nth, uint32_t duration, int copy_data, uint32_t tag) { WebPChunk chunk; + WebPData image; WebPMuxImage wpi; WebPMuxError err; WebPImageInfo* image_info = NULL; uint8_t* frame_tile_data = NULL; uint32_t frame_tile_data_size = 0; - const uint8_t* vp8_data = NULL; - uint32_t vp8_size = 0; const int is_frame = (tag == kChunks[FRAME_ID].chunkTag) ? 1 : 0; const int has_alpha = (alpha_data != NULL && alpha_size != 0); @@ -352,7 +347,7 @@ static WebPMuxError MuxAddFrameTileInternal(WebPMux* const mux, uint32_t nth, } // If given data is for a whole webp file, extract only the VP8 data from it. - err = GetImageData(data, size, &vp8_data, &vp8_size, NULL, NULL); + err = GetImageData(data, size, &image, NULL); if (err != WEBP_MUX_OK) return err; ChunkInit(&chunk); @@ -369,15 +364,15 @@ static WebPMuxError MuxAddFrameTileInternal(WebPMux* const mux, uint32_t nth, } // Create image_info object. - image_info = CreateImageInfo(x_offset, y_offset, duration, vp8_data, - vp8_size); + image_info = CreateImageInfo(x_offset, y_offset, duration, image.bytes_, + image.size_); if (image_info == NULL) { MuxImageRelease(&wpi); return WEBP_MUX_MEMORY_ERROR; } // Add image chunk. - err = ChunkAssignDataImageInfo(&chunk, vp8_data, vp8_size, image_info, + err = ChunkAssignDataImageInfo(&chunk, image.bytes_, image.size_, image_info, copy_data, kChunks[IMAGE_ID].chunkTag); if (err != WEBP_MUX_OK) goto Err; image_info = NULL; // Owned by 'chunk' now. diff --git a/src/mux/muxread.c b/src/mux/muxread.c index 31b85cb1..e920a8c7 100644 --- a/src/mux/muxread.c +++ b/src/mux/muxread.c @@ -26,8 +26,8 @@ extern "C" { const WebPChunk* const chunk = ChunkSearchList((LIST), nth, \ kChunks[(ID)].chunkTag); \ if (chunk) { \ - *data = chunk->data_; \ - *data_size = chunk->payload_size_; \ + data->bytes_ = chunk->data_; \ + data->size_ = chunk->payload_size_; \ return WEBP_MUX_OK; \ } else { \ return WEBP_MUX_NOT_FOUND; \ @@ -35,10 +35,9 @@ extern "C" { } static WebPMuxError MuxGet(const WebPMux* const mux, TAG_ID id, uint32_t nth, - const uint8_t** data, uint32_t* data_size) { + WebPData* const data) { assert(mux != NULL); - *data = NULL; - *data_size = 0; + memset(data, 0, sizeof(*data)); assert(!IsWPI(id)); SWITCH_ID_LIST(VP8X_ID, mux->vp8x_); @@ -196,18 +195,17 @@ WebPMux* WebPMuxCreate(const uint8_t* data, uint32_t size, int copy_data, // Get API(s). WebPMuxError WebPMuxGetFeatures(const WebPMux* const mux, uint32_t* flags) { - const uint8_t* data; - uint32_t data_size; + WebPData data; WebPMuxError err; if (mux == NULL || flags == NULL) return WEBP_MUX_INVALID_ARGUMENT; *flags = 0; // Check if VP8X chunk is present. - err = MuxGet(mux, VP8X_ID, 1, &data, &data_size); + err = MuxGet(mux, VP8X_ID, 1, &data); if (err == WEBP_MUX_NOT_FOUND) { // Check if VP8 chunk is present. - err = WebPMuxGetImage(mux, &data, &data_size, NULL, NULL); + err = WebPMuxGetImage(mux, &data, NULL); if (err == WEBP_MUX_NOT_FOUND && // Data not available (yet). mux->state_ == WEBP_MUX_STATE_PARTIAL) { // Incremental case. return WEBP_MUX_NOT_ENOUGH_DATA; @@ -220,25 +218,24 @@ WebPMuxError WebPMuxGetFeatures(const WebPMux* const mux, uint32_t* flags) { // TODO(urvang): Add a '#define CHUNK_SIZE_BYTES 4' and use it instead of // hard-coded value of 4 everywhere. - if (data_size < 4) return WEBP_MUX_BAD_DATA; + if (data.size_ < 4) return WEBP_MUX_BAD_DATA; // All OK. Fill up flags. - *flags = GetLE32(data); + *flags = GetLE32(data.bytes_); return WEBP_MUX_OK; } WebPMuxError WebPMuxGetImage(const WebPMux* const mux, - const uint8_t** data, uint32_t* size, - const uint8_t** alpha_data, uint32_t* alpha_size) { + WebPData* const image, + WebPData* const alpha) { WebPMuxError err; WebPMuxImage* wpi = NULL; - if (mux == NULL || data == NULL || size == NULL) { + if (mux == NULL || image == NULL) { return WEBP_MUX_INVALID_ARGUMENT; } - *data = NULL; - *size = 0; + memset(image, 0, sizeof(*image)); err = ValidateForImage(mux); if (err != WEBP_MUX_OK) return err; @@ -248,63 +245,59 @@ WebPMuxError WebPMuxGetImage(const WebPMux* const mux, assert(err == WEBP_MUX_OK); // Already tested above. // Get alpha chunk (if present & requested). - if (alpha_data != NULL && alpha_size != NULL) { - *alpha_data = NULL; - *alpha_size = 0; - if (wpi->alpha_ != NULL) { - *alpha_data = wpi->alpha_->data_; - *alpha_size = wpi->alpha_->payload_size_; - } + if (alpha != NULL) { + memset(alpha, 0, sizeof(*alpha)); + if (wpi->alpha_ != NULL) { + alpha->bytes_ = wpi->alpha_->data_; + alpha->size_ = wpi->alpha_->payload_size_; + } } // Get image chunk. if (wpi->vp8_ != NULL) { - *data = wpi->vp8_->data_; - *size = wpi->vp8_->payload_size_; + image->bytes_ = wpi->vp8_->data_; + image->size_ = wpi->vp8_->payload_size_; } return WEBP_MUX_OK; } -WebPMuxError WebPMuxGetMetadata(const WebPMux* const mux, const uint8_t** data, - uint32_t* size) { - if (mux == NULL || data == NULL || size == NULL) { +WebPMuxError WebPMuxGetMetadata(const WebPMux* const mux, + WebPData* const metadata) { + if (mux == NULL || metadata == NULL) { return WEBP_MUX_INVALID_ARGUMENT; } - return MuxGet(mux, META_ID, 1, data, size); + return MuxGet(mux, META_ID, 1, metadata); } WebPMuxError WebPMuxGetColorProfile(const WebPMux* const mux, - const uint8_t** data, uint32_t* size) { - if (mux == NULL || data == NULL || size == NULL) { + WebPData* const color_profile) { + if (mux == NULL || color_profile == NULL) { return WEBP_MUX_INVALID_ARGUMENT; } - return MuxGet(mux, ICCP_ID, 1, data, size); + return MuxGet(mux, ICCP_ID, 1, color_profile); } WebPMuxError WebPMuxGetLoopCount(const WebPMux* const mux, uint32_t* loop_count) { - const uint8_t* data; - uint32_t data_size; + WebPData image; WebPMuxError err; if (mux == NULL || loop_count == NULL) return WEBP_MUX_INVALID_ARGUMENT; - err = MuxGet(mux, LOOP_ID, 1, &data, &data_size); + err = MuxGet(mux, LOOP_ID, 1, &image); if (err != WEBP_MUX_OK) return err; - if (data_size < kChunks[LOOP_ID].chunkSize) return WEBP_MUX_BAD_DATA; - *loop_count = GetLE32(data); + if (image.size_ < kChunks[LOOP_ID].chunkSize) return WEBP_MUX_BAD_DATA; + *loop_count = GetLE32(image.bytes_); return WEBP_MUX_OK; } static WebPMuxError MuxGetFrameTileInternal(const WebPMux* const mux, uint32_t nth, - const uint8_t** data, - uint32_t* size, - const uint8_t** alpha_data, - uint32_t* alpha_size, + WebPData* const image, + WebPData* const alpha, uint32_t* x_offset, uint32_t* y_offset, uint32_t* duration, uint32_t tag) { @@ -316,7 +309,7 @@ static WebPMuxError MuxGetFrameTileInternal(const WebPMux* const mux, const int is_frame = (tag == kChunks[FRAME_ID].chunkTag) ? 1 : 0; const TAG_ID id = is_frame ? FRAME_ID : TILE_ID; - if (mux == NULL || data == NULL || size == NULL || + if (mux == NULL || image == NULL || x_offset == NULL || y_offset == NULL || (is_frame && duration == NULL)) { return WEBP_MUX_INVALID_ARGUMENT; } @@ -336,41 +329,37 @@ static WebPMuxError MuxGetFrameTileInternal(const WebPMux* const mux, if (is_frame) *duration = GetLE32(frame_tile_data + 16); // Get alpha chunk (if present & requested). - if (alpha_data != NULL && alpha_size != NULL) { - *alpha_data = NULL; - *alpha_size = 0; + if (alpha != NULL) { + memset(alpha, 0, sizeof(*alpha)); if (wpi->alpha_ != NULL) { - *alpha_data = wpi->alpha_->data_; - *alpha_size = wpi->alpha_->payload_size_; + alpha->bytes_ = wpi->alpha_->data_; + alpha->size_ = wpi->alpha_->payload_size_; } } // Get image chunk. - *data = NULL; - *size = 0; + memset(image, 0, sizeof(*image)); if (wpi->vp8_ != NULL) { - *data = wpi->vp8_->data_; - *size = wpi->vp8_->payload_size_; + image->bytes_ = wpi->vp8_->data_; + image->size_ = wpi->vp8_->payload_size_; } return WEBP_MUX_OK; } WebPMuxError WebPMuxGetFrame(const WebPMux* const mux, uint32_t nth, - const uint8_t** data, uint32_t* size, - const uint8_t** alpha_data, uint32_t* alpha_size, + WebPData* const image, WebPData* const alpha, uint32_t* x_offset, uint32_t* y_offset, uint32_t* duration) { - return MuxGetFrameTileInternal(mux, nth, data, size, alpha_data, alpha_size, + return MuxGetFrameTileInternal(mux, nth, image, alpha, x_offset, y_offset, duration, kChunks[FRAME_ID].chunkTag); } WebPMuxError WebPMuxGetTile(const WebPMux* const mux, uint32_t nth, - const uint8_t** data, uint32_t* size, - const uint8_t** alpha_data, uint32_t* alpha_size, + WebPData* const image, WebPData* const alpha, uint32_t* x_offset, uint32_t* y_offset) { - return MuxGetFrameTileInternal(mux, nth, data, size, alpha_data, alpha_size, + return MuxGetFrameTileInternal(mux, nth, image, alpha, x_offset, y_offset, NULL, kChunks[TILE_ID].chunkTag); } diff --git a/src/webp/mux.h b/src/webp/mux.h index 5c62bd9f..7d2b1a11 100644 --- a/src/webp/mux.h +++ b/src/webp/mux.h @@ -35,10 +35,9 @@ // int copy_data = 0; // // ... (Read data from file). // WebPMux* mux = WebPMuxCreate(data, data_size, copy_data, NULL); -// WebPMuxGetImage(mux, &image_data, &image_data_size, -// &alpha_data, &alpha_size); -// // ... (Consume image_data; e.g. call WebPDecode() to decode the data). -// WebPMuxGetColorProfile(mux, &icc_data, &icc_data_size); +// WebPMuxGetImage(mux, &image, &alpha); +// // ... (Consume image; e.g. call WebPDecode() to decode the data). +// WebPMuxGetColorProfile(mux, &icc_profile); // // ... (Consume icc_data). // WebPMuxDelete(mux); // free(data); @@ -81,6 +80,13 @@ typedef enum { typedef struct WebPMux WebPMux; // main opaque object. +// Data type used to describe 'raw' data, e.g., chunk data +// (ICC profile, metadata) and WebP compressed image data. +typedef struct { + const uint8_t* bytes_; + uint32_t size_; +} WebPData; + //------------------------------------------------------------------------------ // Life of a Mux object @@ -138,19 +144,16 @@ WEBP_EXTERN(WebPMuxError) WebPMuxSetImage(WebPMux* const mux, // The caller should NOT free the returned data. // Parameters: // mux - (in) object from which the image is to be fetched -// data - (out) the returned image data -// size - (out) size of the returned image data -// alpha_data - (in) the returned alpha data of the image (if present) -// alpha_size - (in) size of alpha chunk data +// image - (out) the image data +// alpha - (out) the alpha data of the image (if present) // Returns: -// WEBP_MUX_INVALID_ARGUMENT - if either of mux, data or size is NULL +// WEBP_MUX_INVALID_ARGUMENT - if either mux or image is NULL // 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* const mux, - const uint8_t** data, uint32_t* size, - const uint8_t** alpha_data, - uint32_t* alpha_size); + WebPData* const image, + WebPData* const alpha); // Deletes the image in the mux object. // Parameters: @@ -185,15 +188,13 @@ WEBP_EXTERN(WebPMuxError) WebPMuxSetMetadata(WebPMux* const mux, // The caller should NOT free the returned data. // Parameters: // mux - (in) object from which the XMP metadata is to be fetched -// data - (out) the returned XMP metadata -// size - (out) size of the returned XMP metadata +// metadata - (out) XMP metadata // Returns: -// WEBP_MUX_INVALID_ARGUMENT - if either of mux, data or size is NULL +// WEBP_MUX_INVALID_ARGUMENT - if either mux or metadata is NULL. // WEBP_MUX_NOT_FOUND - if metadata is not present in mux object. // WEBP_MUX_OK - on success. -WEBP_EXTERN(WebPMuxError) WebPMuxGetMetadata(const WebPMux* const mux, - const uint8_t** data, - uint32_t* size); +WEBP_EXTERN(WebPMuxError) WebPMuxGetMetadata( + const WebPMux* const mux, WebPData* const metadata); // Deletes the XMP metadata in the mux object. // Parameters: @@ -227,15 +228,13 @@ WEBP_EXTERN(WebPMuxError) WebPMuxSetColorProfile(WebPMux* const mux, // The caller should NOT free the returned data. // Parameters: // mux - (in) object from which the color profile data is to be fetched -// data - (out) the returned color profile data -// size - (out) size of the returned color profile data +// color_profile - (out) color profile data // Returns: -// WEBP_MUX_INVALID_ARGUMENT - if either of mux, data or size is NULL +// WEBP_MUX_INVALID_ARGUMENT - if either mux or color_profile is NULL. // WEBP_MUX_NOT_FOUND - if color profile is not present in mux object. // WEBP_MUX_OK - on success. -WEBP_EXTERN(WebPMuxError) WebPMuxGetColorProfile(const WebPMux* const mux, - const uint8_t** data, - uint32_t* size); +WEBP_EXTERN(WebPMuxError) WebPMuxGetColorProfile( + const WebPMux* const mux, WebPData* const color_profile); // Deletes the color profile in the mux object. // Parameters: @@ -294,24 +293,21 @@ WEBP_EXTERN(WebPMuxError) WebPMuxAddFrame(WebPMux* const mux, uint32_t nth, // Parameters: // mux - (in) object from which the info is to be fetched // nth - (in) index of the frame in the mux object -// data - (out) the returned image data -// size - (out) size of the returned image data -// alpha_data - (in) the alpha data corresponding to frame image (if present) -// alpha_size - (in) size of alpha chunk data +// image - (out) the image data +// alpha - (out) the alpha data corresponding to frame image (if present) // 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) // Returns: -// WEBP_MUX_INVALID_ARGUMENT - if either mux, data, size, x_offset, +// WEBP_MUX_INVALID_ARGUMENT - if either mux, image, x_offset, // y_offset, or duration 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* const mux, uint32_t nth, - const uint8_t** data, uint32_t* size, - const uint8_t** alpha_data, - uint32_t* alpha_size, + WebPData* const image, + WebPData* const alpha, uint32_t* x_offset, uint32_t* y_offset, uint32_t* duration); @@ -388,22 +384,19 @@ WEBP_EXTERN(WebPMuxError) WebPMuxAddTile(WebPMux* const mux, uint32_t nth, // Parameters: // mux - (in) object from which the info is to be fetched // nth - (in) index of the tile in the mux object -// data - (out) the returned image data -// size - (out) size of the returned image data -// alpha_data - (in) the alpha data corresponding to tile image (if present) -// alpha_size - (in) size of alpha chunk data +// image - (out) the image data +// alpha - (out) the alpha data corresponding to tile image (if present) // x_offset - (out) x-offset of the returned tile // y_offset - (out) y-offset of the returned tile // Returns: -// WEBP_MUX_INVALID_ARGUMENT - if either mux, data, size, x_offset or +// WEBP_MUX_INVALID_ARGUMENT - if either mux, image, x_offset or // y_offset 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* const mux, uint32_t nth, - const uint8_t** data, uint32_t* size, - const uint8_t** alpha_data, - uint32_t* alpha_size, + WebPData* const image, + WebPData* const alpha, uint32_t* x_offset, uint32_t* y_offset);