diff --git a/src/mux/muxedit.c b/src/mux/muxedit.c index 791a5d0c..cf3df63a 100644 --- a/src/mux/muxedit.c +++ b/src/mux/muxedit.c @@ -64,7 +64,7 @@ void WebPMuxDelete(WebPMux* const mux) { if (id == (ID)) { \ err = ChunkAssignDataImageInfo(&chunk, data, size, \ image_info, \ - copy_data, kChunks[(ID)].chunkTag); \ + copy_data, kChunks[(ID)].tag); \ if (err == WEBP_MUX_OK) { \ err = ChunkSetNth(&chunk, (LIST), nth); \ } \ @@ -146,7 +146,7 @@ static WebPMuxError CreateDataFromImageInfo(const WebPImageInfo* image_info, assert(size); assert(image_info); - *size = kChunks[is_frame ? FRAME_ID : TILE_ID].chunkSize; + *size = kChunks[is_frame ? FRAME_ID : TILE_ID].size; *data = (uint8_t*)malloc(*size); if (*data == NULL) return WEBP_MUX_MEMORY_ERROR; @@ -211,11 +211,11 @@ static WebPMuxError MuxDeleteAllNamedData(WebPMux* const mux, chunk_list = GetChunkListFromId(mux, id); if (chunk_list == NULL) return WEBP_MUX_INVALID_ARGUMENT; - return DeleteChunks(chunk_list, kChunks[id].chunkTag); + return DeleteChunks(chunk_list, kChunks[id].tag); } static WebPMuxError DeleteLoopCount(WebPMux* const mux) { - return MuxDeleteAllNamedData(mux, kChunks[LOOP_ID].chunkName); + return MuxDeleteAllNamedData(mux, kChunks[LOOP_ID].name); } //------------------------------------------------------------------------------ @@ -247,7 +247,7 @@ WebPMuxError WebPMuxSetImage(WebPMux* const mux, if (has_alpha) { // Add alpha chunk. ChunkInit(&chunk); err = ChunkAssignDataImageInfo(&chunk, alpha_data, alpha_size, NULL, - copy_data, kChunks[ALPHA_ID].chunkTag); + copy_data, kChunks[ALPHA_ID].tag); if (err != WEBP_MUX_OK) return err; err = ChunkSetNth(&chunk, &wpi.alpha_, 1); if (err != WEBP_MUX_OK) return err; @@ -256,7 +256,7 @@ WebPMuxError WebPMuxSetImage(WebPMux* const mux, // Add image chunk. ChunkInit(&chunk); err = ChunkAssignDataImageInfo(&chunk, image.bytes_, image.size_, NULL, - copy_data, kChunks[IMAGE_ID].chunkTag); + copy_data, kChunks[IMAGE_ID].tag); if (err != WEBP_MUX_OK) return err; err = ChunkSetNth(&chunk, &wpi.vp8_, 1); if (err != WEBP_MUX_OK) return err; @@ -310,12 +310,12 @@ WebPMuxError WebPMuxSetLoopCount(WebPMux* const mux, uint32_t loop_count) { if (err != WEBP_MUX_OK && err != WEBP_MUX_NOT_FOUND) return err; // Add the given loop count. - data = (uint8_t*)malloc(kChunks[LOOP_ID].chunkSize); + data = (uint8_t*)malloc(kChunks[LOOP_ID].size); if (data == NULL) return WEBP_MUX_MEMORY_ERROR; PutLE32(data, loop_count); - err = MuxAddChunk(mux, 1, kChunks[LOOP_ID].chunkTag, data, - kChunks[LOOP_ID].chunkSize, NULL, 1); + err = MuxAddChunk(mux, 1, kChunks[LOOP_ID].tag, data, + kChunks[LOOP_ID].size, NULL, 1); free(data); return err; } @@ -333,7 +333,7 @@ static WebPMuxError MuxAddFrameTileInternal( WebPImageInfo* image_info = NULL; uint8_t* frame_tile_data = NULL; size_t frame_tile_data_size = 0; - const int is_frame = (tag == kChunks[FRAME_ID].chunkTag) ? 1 : 0; + const int is_frame = (tag == kChunks[FRAME_ID].tag) ? 1 : 0; const int has_alpha = (alpha_data != NULL && alpha_size != 0); if (mux == NULL || data == NULL || size > MAX_CHUNK_PAYLOAD) { @@ -350,7 +350,7 @@ static WebPMuxError MuxAddFrameTileInternal( if (has_alpha) { // Add alpha chunk. err = ChunkAssignDataImageInfo(&chunk, alpha_data, alpha_size, NULL, - copy_data, kChunks[ALPHA_ID].chunkTag); + copy_data, kChunks[ALPHA_ID].tag); if (err != WEBP_MUX_OK) return err; err = ChunkSetNth(&chunk, &wpi.alpha_, 1); if (err != WEBP_MUX_OK) return err; @@ -367,7 +367,7 @@ static WebPMuxError MuxAddFrameTileInternal( // Add image chunk. err = ChunkAssignDataImageInfo(&chunk, image.bytes_, image.size_, image_info, - copy_data, kChunks[IMAGE_ID].chunkTag); + copy_data, kChunks[IMAGE_ID].tag); if (err != WEBP_MUX_OK) goto Err; image_info = NULL; // Owned by 'chunk' now. err = ChunkSetNth(&chunk, &wpi.vp8_, 1); @@ -413,7 +413,7 @@ WebPMuxError WebPMuxAddFrame(WebPMux* const mux, uint32_t nth, uint32_t duration, int copy_data) { return MuxAddFrameTileInternal(mux, nth, data, size, alpha_data, alpha_size, x_offset, y_offset, duration, - copy_data, kChunks[FRAME_ID].chunkTag); + copy_data, kChunks[FRAME_ID].tag); } WebPMuxError WebPMuxAddTile(WebPMux* const mux, uint32_t nth, @@ -423,7 +423,7 @@ WebPMuxError WebPMuxAddTile(WebPMux* const mux, uint32_t nth, int copy_data) { return MuxAddFrameTileInternal(mux, nth, data, size, alpha_data, alpha_size, x_offset, y_offset, 1, - copy_data, kChunks[TILE_ID].chunkTag); + copy_data, kChunks[TILE_ID].tag); } //------------------------------------------------------------------------------ @@ -443,11 +443,11 @@ WebPMuxError WebPMuxDeleteImage(WebPMux* const mux) { } WebPMuxError WebPMuxDeleteMetadata(WebPMux* const mux) { - return MuxDeleteAllNamedData(mux, kChunks[META_ID].chunkName); + return MuxDeleteAllNamedData(mux, kChunks[META_ID].name); } WebPMuxError WebPMuxDeleteColorProfile(WebPMux* const mux) { - return MuxDeleteAllNamedData(mux, kChunks[ICCP_ID].chunkName); + return MuxDeleteAllNamedData(mux, kChunks[ICCP_ID].name); } static WebPMuxError DeleteFrameTileInternal(WebPMux* const mux, @@ -461,11 +461,11 @@ static WebPMuxError DeleteFrameTileInternal(WebPMux* const mux, } WebPMuxError WebPMuxDeleteFrame(WebPMux* const mux, uint32_t nth) { - return DeleteFrameTileInternal(mux, nth, kChunks[FRAME_ID].chunkName); + return DeleteFrameTileInternal(mux, nth, kChunks[FRAME_ID].name); } WebPMuxError WebPMuxDeleteTile(WebPMux* const mux, uint32_t nth) { - return DeleteFrameTileInternal(mux, nth, kChunks[TILE_ID].chunkName); + return DeleteFrameTileInternal(mux, nth, kChunks[TILE_ID].name); } //------------------------------------------------------------------------------ @@ -551,7 +551,7 @@ static WebPMuxError CreateVP8XChunk(WebPMux* const mux) { // If VP8X chunk(s) is(are) already present, remove them (and later add new // VP8X chunk with updated flags). - err = MuxDeleteAllNamedData(mux, kChunks[VP8X_ID].chunkName); + err = MuxDeleteAllNamedData(mux, kChunks[VP8X_ID].name); if (err != WEBP_MUX_OK && err != WEBP_MUX_NOT_FOUND) return err; // Set flags. @@ -564,10 +564,10 @@ static WebPMuxError CreateVP8XChunk(WebPMux* const mux) { } if (images->header_ != NULL) { - if (images->header_->tag_ == kChunks[TILE_ID].chunkTag) { + if (images->header_->tag_ == kChunks[TILE_ID].tag) { // This is a tiled image. flags |= TILE_FLAG; - } else if (images->header_->tag_ == kChunks[FRAME_ID].chunkTag) { + } else if (images->header_->tag_ == kChunks[FRAME_ID].tag) { // This is an image with animation. flags |= ANIMATION_FLAG; } @@ -590,7 +590,7 @@ static WebPMuxError CreateVP8XChunk(WebPMux* const mux) { PutLE32(data + 4, width); // canvas width. PutLE32(data + 8, height); // canvas height. - err = MuxAddChunk(mux, 1, kChunks[VP8X_ID].chunkTag, data, data_size, + err = MuxAddChunk(mux, 1, kChunks[VP8X_ID].tag, data, data_size, NULL, 1); return err; } @@ -612,11 +612,11 @@ WebPMuxError WebPMuxAssemble(WebPMux* const mux, *output_size = 0; // Remove LOOP chunk if unnecessary. - err = WebPMuxNumNamedElements(mux, kChunks[LOOP_ID].chunkName, + err = WebPMuxNumNamedElements(mux, kChunks[LOOP_ID].name, &num_loop_chunks); if (err != WEBP_MUX_OK) return err; if (num_loop_chunks >= 1) { - err = WebPMuxNumNamedElements(mux, kChunks[FRAME_ID].chunkName, + err = WebPMuxNumNamedElements(mux, kChunks[FRAME_ID].name, &num_frames); if (err != WEBP_MUX_OK) return err; if (num_frames == 0) { diff --git a/src/mux/muxi.h b/src/mux/muxi.h index 76ff2cbf..cbb3b33e 100644 --- a/src/mux/muxi.h +++ b/src/mux/muxi.h @@ -69,9 +69,6 @@ struct WebPMux { WebPChunk* unknown_; }; -#define CHUNKS_PER_FRAME 2 -#define CHUNKS_PER_TILE 2 - typedef enum { VP8X_ID = 0, ICCP_ID, @@ -97,10 +94,10 @@ typedef enum { ((uint32_t)c1 | (c2 << 8) | (c3 << 16) | (c4 << 24)) typedef struct { - const char* chunkName; - uint32_t chunkTag; - TAG_ID chunkId; - uint32_t chunkSize; + const char* name; + uint32_t tag; + TAG_ID id; + uint32_t size; } ChunkInfo; extern const ChunkInfo kChunks[LAST_TAG_ID]; diff --git a/src/mux/muxinternal.c b/src/mux/muxinternal.c index b6cfc3c8..6217001e 100644 --- a/src/mux/muxinternal.c +++ b/src/mux/muxinternal.c @@ -60,16 +60,16 @@ WebPChunk* ChunkRelease(WebPChunk* const chunk) { TAG_ID ChunkGetIdFromName(const char* const what) { int i; if (what == NULL) return -1; - for (i = 0; kChunks[i].chunkName != NULL; ++i) { - if (!strcmp(what, kChunks[i].chunkName)) return i; + for (i = 0; kChunks[i].name != NULL; ++i) { + if (!strcmp(what, kChunks[i].name)) return i; } return NIL_ID; } TAG_ID ChunkGetIdFromTag(uint32_t tag) { int i; - for (i = 0; kChunks[i].chunkTag != NIL_TAG; ++i) { - if (tag == kChunks[i].chunkTag) return i; + for (i = 0; kChunks[i].tag != NIL_TAG; ++i) { + if (tag == kChunks[i].tag) return i; } return NIL_ID; } @@ -127,7 +127,7 @@ WebPMuxError ChunkAssignDataImageInfo(WebPChunk* chunk, WebPImageInfo* image_info, int copy_data, uint32_t tag) { // For internally allocated chunks, always copy data & make it owner of data. - if (tag == kChunks[VP8X_ID].chunkTag || tag == kChunks[LOOP_ID].chunkTag) { + if (tag == kChunks[VP8X_ID].tag || tag == kChunks[LOOP_ID].tag) { copy_data = 1; } @@ -155,7 +155,7 @@ WebPMuxError ChunkAssignDataImageInfo(WebPChunk* chunk, } } - if (tag == kChunks[IMAGE_ID].chunkTag) { + if (tag == kChunks[IMAGE_ID].tag) { chunk->image_info_ = image_info; } @@ -249,7 +249,7 @@ int MuxImageCount(WebPMuxImage* const wpi_list, TAG_ID id) { WebPMuxImage* current; for (current = wpi_list; current != NULL; current = current->next_) { const WebPChunk* const wpi_chunk = *MuxImageGetListFromId(current, id); - if (wpi_chunk != NULL && wpi_chunk->tag_ == kChunks[id].chunkTag) { + if (wpi_chunk != NULL && wpi_chunk->tag_ == kChunks[id].tag) { ++count; } } @@ -298,7 +298,7 @@ static int SearchImageToGetOrDelete(WebPMuxImage** wpi_list, uint32_t nth, while (*wpi_list) { WebPMuxImage* const cur_wpi = *wpi_list; const WebPChunk* const wpi_chunk = *MuxImageGetListFromId(cur_wpi, id); - if (wpi_chunk != NULL && wpi_chunk->tag_ == kChunks[id].chunkTag) { + if (wpi_chunk != NULL && wpi_chunk->tag_ == kChunks[id].tag) { ++count; if (count == nth) return 1; // Found. } @@ -455,8 +455,8 @@ static WebPMuxError ValidateChunk(const WebPMux* const mux, TAG_ID id, FeatureFlags feature, FeatureFlags vp8x_flags, int max, int* num) { const WebPMuxError err = - WebPMuxNumNamedElements(mux, kChunks[id].chunkName, num); - assert(id == kChunks[id].chunkId); + WebPMuxNumNamedElements(mux, kChunks[id].name, num); + assert(id == kChunks[id].id); if (err != WEBP_MUX_OK) return err; if (max > -1 && *num > max) return WEBP_MUX_INVALID_ARGUMENT; diff --git a/src/mux/muxread.c b/src/mux/muxread.c index 3c969ce4..fdc8c847 100644 --- a/src/mux/muxread.c +++ b/src/mux/muxread.c @@ -24,7 +24,7 @@ extern "C" { #define SWITCH_ID_LIST(ID, LIST) \ if (id == (ID)) { \ const WebPChunk* const chunk = ChunkSearchList((LIST), nth, \ - kChunks[(ID)].chunkTag); \ + kChunks[(ID)].tag); \ if (chunk) { \ data->bytes_ = chunk->data_; \ data->size_ = chunk->payload_size_; \ @@ -102,7 +102,7 @@ WebPMux* WebPMuxCreateInternal(const uint8_t* data, size_t size, int copy_data, } tag = GetLE32(data + RIFF_HEADER_SIZE); - if (tag != kChunks[IMAGE_ID].chunkTag && tag != kChunks[VP8X_ID].chunkTag) { + if (tag != kChunks[IMAGE_ID].tag && tag != kChunks[VP8X_ID].tag) { // First chunk should be either VP8X or VP8. goto Err; } @@ -282,7 +282,7 @@ WebPMuxError WebPMuxGetLoopCount(const WebPMux* const mux, err = MuxGet(mux, LOOP_ID, 1, &image); if (err != WEBP_MUX_OK) return err; - if (image.size_ < kChunks[LOOP_ID].chunkSize) return WEBP_MUX_BAD_DATA; + if (image.size_ < kChunks[LOOP_ID].size) return WEBP_MUX_BAD_DATA; *loop_count = GetLE32(image.bytes_); return WEBP_MUX_OK; @@ -297,7 +297,7 @@ static WebPMuxError MuxGetFrameTileInternal( WebPMuxError err; WebPMuxImage* wpi; - const int is_frame = (tag == kChunks[FRAME_ID].chunkTag) ? 1 : 0; + const int is_frame = (tag == kChunks[FRAME_ID].tag) ? 1 : 0; const TAG_ID id = is_frame ? FRAME_ID : TILE_ID; if (mux == NULL || image == NULL || @@ -314,7 +314,7 @@ static WebPMuxError MuxGetFrameTileInternal( frame_tile_data = wpi->header_->data_; frame_tile_size = wpi->header_->payload_size_; - if (frame_tile_size < kChunks[id].chunkSize) return WEBP_MUX_BAD_DATA; + if (frame_tile_size < kChunks[id].size) return WEBP_MUX_BAD_DATA; *x_offset = GetLE32(frame_tile_data + 0); *y_offset = GetLE32(frame_tile_data + 4); if (is_frame) *duration = GetLE32(frame_tile_data + 16); @@ -344,7 +344,7 @@ WebPMuxError WebPMuxGetFrame(const WebPMux* const mux, uint32_t nth, uint32_t* duration) { return MuxGetFrameTileInternal(mux, nth, image, alpha, x_offset, y_offset, duration, - kChunks[FRAME_ID].chunkTag); + kChunks[FRAME_ID].tag); } WebPMuxError WebPMuxGetTile(const WebPMux* const mux, uint32_t nth, @@ -352,7 +352,7 @@ WebPMuxError WebPMuxGetTile(const WebPMux* const mux, uint32_t nth, uint32_t* x_offset, uint32_t* y_offset) { return MuxGetFrameTileInternal(mux, nth, image, alpha, x_offset, y_offset, NULL, - kChunks[TILE_ID].chunkTag); + kChunks[TILE_ID].tag); } // Count number of chunks matching 'tag' in the 'chunk_list'. @@ -383,7 +383,7 @@ WebPMuxError WebPMuxNumNamedElements(const WebPMux* const mux, const char* tag, if (chunk_list == NULL) { *num_elements = 0; } else { - *num_elements = CountChunks(*chunk_list, kChunks[id].chunkTag); + *num_elements = CountChunks(*chunk_list, kChunks[id].tag); } }