diff options
author | Juan Linietsky <reduzio@gmail.com> | 2014-02-10 22:37:07 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2014-02-10 22:37:07 -0300 |
commit | abb985e755ccf858149294868eff8a9a9feca67e (patch) | |
tree | 2a82fd9f87ddecfb14b08d8599bb2417b3cea7ff /drivers/webp/mux/muxinternal.c | |
parent | 1c7726820ec53b486e946bb42cac98a600c5bdb5 (diff) |
Reverted to older version of WebP, newer one crashed on Android.
Diffstat (limited to 'drivers/webp/mux/muxinternal.c')
-rw-r--r-- | drivers/webp/mux/muxinternal.c | 323 |
1 files changed, 174 insertions, 149 deletions
diff --git a/drivers/webp/mux/muxinternal.c b/drivers/webp/mux/muxinternal.c index 3f992ce130..6c3c4fe60a 100644 --- a/drivers/webp/mux/muxinternal.c +++ b/drivers/webp/mux/muxinternal.c @@ -1,10 +1,8 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// Use of this source code is governed by a BSD-style license -// that can be found in the COPYING file in the root of the source -// tree. An additional intellectual property rights grant can be found -// in the file PATENTS. All contributing project authors may -// be found in the AUTHORS file in the root of the source tree. +// 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/ // ----------------------------------------------------------------------------- // // Internal objects and utils for mux. @@ -14,33 +12,29 @@ #include <assert.h> #include "./muxi.h" -#include "../utils/utils.h" + +#if defined(__cplusplus) || defined(c_plusplus) +extern "C" { +#endif #define UNDEFINED_CHUNK_SIZE (-1) const ChunkInfo kChunks[] = { { MKFOURCC('V', 'P', '8', 'X'), WEBP_CHUNK_VP8X, VP8X_CHUNK_SIZE }, { MKFOURCC('I', 'C', 'C', 'P'), WEBP_CHUNK_ICCP, UNDEFINED_CHUNK_SIZE }, - { MKFOURCC('A', 'N', 'I', 'M'), WEBP_CHUNK_ANIM, ANIM_CHUNK_SIZE }, - { MKFOURCC('A', 'N', 'M', 'F'), WEBP_CHUNK_ANMF, ANMF_CHUNK_SIZE }, - { MKFOURCC('F', 'R', 'G', 'M'), WEBP_CHUNK_FRGM, FRGM_CHUNK_SIZE }, + { MKFOURCC('L', 'O', 'O', 'P'), WEBP_CHUNK_LOOP, LOOP_CHUNK_SIZE }, + { MKFOURCC('F', 'R', 'M', ' '), WEBP_CHUNK_FRAME, FRAME_CHUNK_SIZE }, + { MKFOURCC('T', 'I', 'L', 'E'), WEBP_CHUNK_TILE, TILE_CHUNK_SIZE }, { MKFOURCC('A', 'L', 'P', 'H'), WEBP_CHUNK_ALPHA, UNDEFINED_CHUNK_SIZE }, { MKFOURCC('V', 'P', '8', ' '), WEBP_CHUNK_IMAGE, UNDEFINED_CHUNK_SIZE }, { MKFOURCC('V', 'P', '8', 'L'), WEBP_CHUNK_IMAGE, UNDEFINED_CHUNK_SIZE }, - { MKFOURCC('E', 'X', 'I', 'F'), WEBP_CHUNK_EXIF, UNDEFINED_CHUNK_SIZE }, - { MKFOURCC('X', 'M', 'P', ' '), WEBP_CHUNK_XMP, UNDEFINED_CHUNK_SIZE }, - { NIL_TAG, WEBP_CHUNK_UNKNOWN, UNDEFINED_CHUNK_SIZE }, + { MKFOURCC('M', 'E', 'T', 'A'), WEBP_CHUNK_META, UNDEFINED_CHUNK_SIZE }, + { MKFOURCC('U', 'N', 'K', 'N'), WEBP_CHUNK_UNKNOWN, UNDEFINED_CHUNK_SIZE }, - { NIL_TAG, WEBP_CHUNK_NIL, UNDEFINED_CHUNK_SIZE } + { NIL_TAG, WEBP_CHUNK_NIL, UNDEFINED_CHUNK_SIZE } }; //------------------------------------------------------------------------------ - -int WebPGetMuxVersion(void) { - return (MUX_MAJ_VERSION << 16) | (MUX_MIN_VERSION << 8) | MUX_REV_VERSION; -} - -//------------------------------------------------------------------------------ // Life of a chunk object. void ChunkInit(WebPChunk* const chunk) { @@ -66,9 +60,9 @@ WebPChunk* ChunkRelease(WebPChunk* const chunk) { CHUNK_INDEX ChunkGetIndexFromTag(uint32_t tag) { int i; for (i = 0; kChunks[i].tag != NIL_TAG; ++i) { - if (tag == kChunks[i].tag) return (CHUNK_INDEX)i; + if (tag == kChunks[i].tag) return i; } - return IDX_UNKNOWN; + return IDX_NIL; } WebPChunkId ChunkGetIdFromTag(uint32_t tag) { @@ -76,16 +70,7 @@ WebPChunkId ChunkGetIdFromTag(uint32_t tag) { for (i = 0; kChunks[i].tag != NIL_TAG; ++i) { if (tag == kChunks[i].tag) return kChunks[i].id; } - return WEBP_CHUNK_UNKNOWN; -} - -uint32_t ChunkGetTagFromFourCC(const char fourcc[4]) { - return MKFOURCC(fourcc[0], fourcc[1], fourcc[2], fourcc[3]); -} - -CHUNK_INDEX ChunkGetIndexFromFourCC(const char fourcc[4]) { - const uint32_t tag = ChunkGetTagFromFourCC(fourcc); - return ChunkGetIndexFromTag(tag); + return WEBP_CHUNK_NIL; } //------------------------------------------------------------------------------ @@ -93,7 +78,7 @@ CHUNK_INDEX ChunkGetIndexFromFourCC(const char fourcc[4]) { // Returns next chunk in the chunk list with the given tag. static WebPChunk* ChunkSearchNextInList(WebPChunk* chunk, uint32_t tag) { - while (chunk != NULL && chunk->tag_ != tag) { + while (chunk && chunk->tag_ != tag) { chunk = chunk->next_; } return chunk; @@ -102,7 +87,7 @@ static WebPChunk* ChunkSearchNextInList(WebPChunk* chunk, uint32_t tag) { WebPChunk* ChunkSearchList(WebPChunk* first, uint32_t nth, uint32_t tag) { uint32_t iter = nth; first = ChunkSearchNextInList(first, tag); - if (first == NULL) return NULL; + if (!first) return NULL; while (--iter != 0) { WebPChunk* next_chunk = ChunkSearchNextInList(first->next_, tag); @@ -114,14 +99,14 @@ WebPChunk* ChunkSearchList(WebPChunk* first, uint32_t nth, uint32_t tag) { // Outputs a pointer to 'prev_chunk->next_', // where 'prev_chunk' is the pointer to the chunk at position (nth - 1). -// Returns true if nth chunk was found. +// Returns 1 if nth chunk was found, 0 otherwise. static int ChunkSearchListToSet(WebPChunk** chunk_list, uint32_t nth, WebPChunk*** const location) { uint32_t count = 0; - assert(chunk_list != NULL); + assert(chunk_list); *location = chunk_list; - while (*chunk_list != NULL) { + while (*chunk_list) { WebPChunk* const cur_chunk = *chunk_list; ++count; if (count == nth) return 1; // Found. @@ -139,25 +124,34 @@ static int ChunkSearchListToSet(WebPChunk** chunk_list, uint32_t nth, WebPMuxError ChunkAssignData(WebPChunk* chunk, const WebPData* const data, int copy_data, uint32_t tag) { // For internally allocated chunks, always copy data & make it owner of data. - if (tag == kChunks[IDX_VP8X].tag || tag == kChunks[IDX_ANIM].tag) { + if (tag == kChunks[IDX_VP8X].tag || tag == kChunks[IDX_LOOP].tag) { copy_data = 1; } ChunkRelease(chunk); if (data != NULL) { - if (copy_data) { // Copy data. - if (!WebPDataCopy(data, &chunk->data_)) return WEBP_MUX_MEMORY_ERROR; - chunk->owner_ = 1; // Chunk is owner of data. - } else { // Don't copy data. + if (copy_data) { + // Copy data. + chunk->data_.bytes_ = (uint8_t*)malloc(data->size_); + if (chunk->data_.bytes_ == NULL) return WEBP_MUX_MEMORY_ERROR; + memcpy((uint8_t*)chunk->data_.bytes_, data->bytes_, data->size_); + chunk->data_.size_ = data->size_; + + // Chunk is owner of data. + chunk->owner_ = 1; + } else { + // Don't copy data. chunk->data_ = *data; } } + chunk->tag_ = tag; + return WEBP_MUX_OK; } -WebPMuxError ChunkSetNth(WebPChunk* chunk, WebPChunk** chunk_list, +WebPMuxError ChunkSetNth(const WebPChunk* chunk, WebPChunk** chunk_list, uint32_t nth) { WebPChunk* new_chunk; @@ -168,7 +162,6 @@ WebPMuxError ChunkSetNth(WebPChunk* chunk, WebPChunk** chunk_list, new_chunk = (WebPChunk*)malloc(sizeof(*new_chunk)); if (new_chunk == NULL) return WEBP_MUX_MEMORY_ERROR; *new_chunk = *chunk; - chunk->owner_ = 0; new_chunk->next_ = *chunk_list; *chunk_list = new_chunk; return WEBP_MUX_OK; @@ -183,43 +176,66 @@ WebPChunk* ChunkDelete(WebPChunk* const chunk) { return next; } -void ChunkListDelete(WebPChunk** const chunk_list) { - while (*chunk_list != NULL) { - *chunk_list = ChunkDelete(*chunk_list); - } -} - //------------------------------------------------------------------------------ // Chunk serialization methods. +size_t ChunksListDiskSize(const WebPChunk* chunk_list) { + size_t size = 0; + while (chunk_list) { + size += ChunkDiskSize(chunk_list); + chunk_list = chunk_list->next_; + } + return size; +} + static uint8_t* ChunkEmit(const WebPChunk* const chunk, uint8_t* dst) { - const size_t chunk_size = chunk->data_.size; + const size_t chunk_size = chunk->data_.size_; assert(chunk); assert(chunk->tag_ != NIL_TAG); PutLE32(dst + 0, chunk->tag_); PutLE32(dst + TAG_SIZE, (uint32_t)chunk_size); assert(chunk_size == (uint32_t)chunk_size); - memcpy(dst + CHUNK_HEADER_SIZE, chunk->data_.bytes, chunk_size); + memcpy(dst + CHUNK_HEADER_SIZE, chunk->data_.bytes_, chunk_size); if (chunk_size & 1) dst[CHUNK_HEADER_SIZE + chunk_size] = 0; // Add padding. return dst + ChunkDiskSize(chunk); } uint8_t* ChunkListEmit(const WebPChunk* chunk_list, uint8_t* dst) { - while (chunk_list != NULL) { + while (chunk_list) { dst = ChunkEmit(chunk_list, dst); chunk_list = chunk_list->next_; } return dst; } -size_t ChunkListDiskSize(const WebPChunk* chunk_list) { - size_t size = 0; - while (chunk_list != NULL) { - size += ChunkDiskSize(chunk_list); - chunk_list = chunk_list->next_; +//------------------------------------------------------------------------------ +// Manipulation of a WebPData object. + +void WebPDataInit(WebPData* webp_data) { + if (webp_data != NULL) { + memset(webp_data, 0, sizeof(*webp_data)); } - return size; +} + +void WebPDataClear(WebPData* webp_data) { + if (webp_data != NULL) { + free((void*)webp_data->bytes_); + WebPDataInit(webp_data); + } +} + +int WebPDataCopy(const WebPData* src, WebPData* dst) { + if (src == NULL || dst == NULL) return 0; + + WebPDataInit(dst); + if (src->bytes_ != NULL && src->size_ != 0) { + dst->bytes_ = (uint8_t*)malloc(src->size_); + if (dst->bytes_ == NULL) return 0; + memcpy((void*)dst->bytes_, src->bytes_, src->size_); + dst->size_ = src->size_; + } + return 1; } //------------------------------------------------------------------------------ @@ -236,7 +252,6 @@ WebPMuxImage* MuxImageRelease(WebPMuxImage* const wpi) { ChunkDelete(wpi->header_); ChunkDelete(wpi->alpha_); ChunkDelete(wpi->img_); - ChunkListDelete(&wpi->unknown_); next = wpi->next_; MuxImageInit(wpi); @@ -246,31 +261,14 @@ WebPMuxImage* MuxImageRelease(WebPMuxImage* const wpi) { //------------------------------------------------------------------------------ // MuxImage search methods. -// Get a reference to appropriate chunk list within an image given chunk tag. -static WebPChunk** GetChunkListFromId(const WebPMuxImage* const wpi, - WebPChunkId id) { - assert(wpi != NULL); - switch (id) { - case WEBP_CHUNK_ANMF: - case WEBP_CHUNK_FRGM: return (WebPChunk**)&wpi->header_; - case WEBP_CHUNK_ALPHA: return (WebPChunk**)&wpi->alpha_; - case WEBP_CHUNK_IMAGE: return (WebPChunk**)&wpi->img_; - default: return NULL; - } -} - int MuxImageCount(const WebPMuxImage* wpi_list, WebPChunkId id) { int count = 0; const WebPMuxImage* current; for (current = wpi_list; current != NULL; current = current->next_) { - if (id == WEBP_CHUNK_NIL) { - ++count; // Special case: count all images. - } else { - const WebPChunk* const wpi_chunk = *GetChunkListFromId(current, id); - if (wpi_chunk != NULL) { - const WebPChunkId wpi_chunk_id = ChunkGetIdFromTag(wpi_chunk->tag_); - if (wpi_chunk_id == id) ++count; // Count images with a matching 'id'. - } + const WebPChunk* const wpi_chunk = *MuxImageGetListFromId(current, id); + if (wpi_chunk != NULL) { + const WebPChunkId wpi_chunk_id = ChunkGetIdFromTag(wpi_chunk->tag_); + if (wpi_chunk_id == id) ++count; } } return count; @@ -278,22 +276,34 @@ int MuxImageCount(const WebPMuxImage* wpi_list, WebPChunkId id) { // Outputs a pointer to 'prev_wpi->next_', // where 'prev_wpi' is the pointer to the image at position (nth - 1). -// Returns true if nth image was found. +// Returns 1 if nth image with given id was found, 0 otherwise. static int SearchImageToGetOrDelete(WebPMuxImage** wpi_list, uint32_t nth, + WebPChunkId id, WebPMuxImage*** const location) { uint32_t count = 0; assert(wpi_list); *location = wpi_list; + // Search makes sense only for the following. + assert(id == WEBP_CHUNK_FRAME || id == WEBP_CHUNK_TILE || + id == WEBP_CHUNK_IMAGE); + assert(id != WEBP_CHUNK_IMAGE || nth == 1); + if (nth == 0) { - nth = MuxImageCount(*wpi_list, WEBP_CHUNK_NIL); + nth = MuxImageCount(*wpi_list, id); if (nth == 0) return 0; // Not found. } - while (*wpi_list != NULL) { + while (*wpi_list) { WebPMuxImage* const cur_wpi = *wpi_list; - ++count; - if (count == nth) return 1; // Found. + const WebPChunk* const wpi_chunk = *MuxImageGetListFromId(cur_wpi, id); + if (wpi_chunk != NULL) { + const WebPChunkId wpi_chunk_id = ChunkGetIdFromTag(wpi_chunk->tag_); + if (wpi_chunk_id == id) { + ++count; + if (count == nth) return 1; // Found. + } + } wpi_list = &cur_wpi->next_; *location = wpi_list; } @@ -335,9 +345,16 @@ WebPMuxImage* MuxImageDelete(WebPMuxImage* const wpi) { return next; } -WebPMuxError MuxImageDeleteNth(WebPMuxImage** wpi_list, uint32_t nth) { +void MuxImageDeleteAll(WebPMuxImage** const wpi_list) { + while (*wpi_list) { + *wpi_list = MuxImageDelete(*wpi_list); + } +} + +WebPMuxError MuxImageDeleteNth(WebPMuxImage** wpi_list, uint32_t nth, + WebPChunkId id) { assert(wpi_list); - if (!SearchImageToGetOrDelete(wpi_list, nth, &wpi_list)) { + if (!SearchImageToGetOrDelete(wpi_list, nth, id, &wpi_list)) { return WEBP_MUX_NOT_FOUND; } *wpi_list = MuxImageDelete(*wpi_list); @@ -348,10 +365,10 @@ WebPMuxError MuxImageDeleteNth(WebPMuxImage** wpi_list, uint32_t nth) { // MuxImage reader methods. WebPMuxError MuxImageGetNth(const WebPMuxImage** wpi_list, uint32_t nth, - WebPMuxImage** wpi) { + WebPChunkId id, WebPMuxImage** wpi) { assert(wpi_list); assert(wpi); - if (!SearchImageToGetOrDelete((WebPMuxImage**)wpi_list, nth, + if (!SearchImageToGetOrDelete((WebPMuxImage**)wpi_list, nth, id, (WebPMuxImage***)&wpi_list)) { return WEBP_MUX_NOT_FOUND; } @@ -368,48 +385,47 @@ size_t MuxImageDiskSize(const WebPMuxImage* const wpi) { if (wpi->header_ != NULL) size += ChunkDiskSize(wpi->header_); if (wpi->alpha_ != NULL) size += ChunkDiskSize(wpi->alpha_); if (wpi->img_ != NULL) size += ChunkDiskSize(wpi->img_); - if (wpi->unknown_ != NULL) size += ChunkListDiskSize(wpi->unknown_); return size; } -// Special case as ANMF/FRGM chunk encapsulates other image chunks. -static uint8_t* ChunkEmitSpecial(const WebPChunk* const header, - size_t total_size, uint8_t* dst) { - const size_t header_size = header->data_.size; - const size_t offset_to_next = total_size - CHUNK_HEADER_SIZE; - assert(header->tag_ == kChunks[IDX_ANMF].tag || - header->tag_ == kChunks[IDX_FRGM].tag); - PutLE32(dst + 0, header->tag_); - PutLE32(dst + TAG_SIZE, (uint32_t)offset_to_next); - assert(header_size == (uint32_t)header_size); - memcpy(dst + CHUNK_HEADER_SIZE, header->data_.bytes, header_size); - if (header_size & 1) { - dst[CHUNK_HEADER_SIZE + header_size] = 0; // Add padding. +size_t MuxImageListDiskSize(const WebPMuxImage* wpi_list) { + size_t size = 0; + while (wpi_list) { + size += MuxImageDiskSize(wpi_list); + wpi_list = wpi_list->next_; } - return dst + ChunkDiskSize(header); + return size; } uint8_t* MuxImageEmit(const WebPMuxImage* const wpi, uint8_t* dst) { // Ordering of chunks to be emitted is strictly as follows: - // 1. ANMF/FRGM chunk (if present). - // 2. ALPH chunk (if present). + // 1. Frame/Tile chunk (if present). + // 2. Alpha chunk (if present). // 3. VP8/VP8L chunk. assert(wpi); - if (wpi->header_ != NULL) { - dst = ChunkEmitSpecial(wpi->header_, MuxImageDiskSize(wpi), dst); - } + if (wpi->header_ != NULL) dst = ChunkEmit(wpi->header_, dst); if (wpi->alpha_ != NULL) dst = ChunkEmit(wpi->alpha_, dst); if (wpi->img_ != NULL) dst = ChunkEmit(wpi->img_, dst); - if (wpi->unknown_ != NULL) dst = ChunkListEmit(wpi->unknown_, dst); + return dst; +} + +uint8_t* MuxImageListEmit(const WebPMuxImage* wpi_list, uint8_t* dst) { + while (wpi_list) { + dst = MuxImageEmit(wpi_list, dst); + wpi_list = wpi_list->next_; + } return dst; } //------------------------------------------------------------------------------ // Helper methods for mux. -int MuxHasAlpha(const WebPMuxImage* images) { +int MuxHasLosslessImages(const WebPMuxImage* images) { while (images != NULL) { - if (images->has_alpha_) return 1; + assert(images->img_ != NULL); + if (images->img_->tag_ == kChunks[IDX_VP8L].tag) { + return 1; + } images = images->next_; } return 0; @@ -425,13 +441,30 @@ uint8_t* MuxEmitRiffHeader(uint8_t* const data, size_t size) { WebPChunk** MuxGetChunkListFromId(const WebPMux* mux, WebPChunkId id) { assert(mux != NULL); - switch (id) { + switch(id) { case WEBP_CHUNK_VP8X: return (WebPChunk**)&mux->vp8x_; case WEBP_CHUNK_ICCP: return (WebPChunk**)&mux->iccp_; - case WEBP_CHUNK_ANIM: return (WebPChunk**)&mux->anim_; - case WEBP_CHUNK_EXIF: return (WebPChunk**)&mux->exif_; - case WEBP_CHUNK_XMP: return (WebPChunk**)&mux->xmp_; - default: return (WebPChunk**)&mux->unknown_; + case WEBP_CHUNK_LOOP: return (WebPChunk**)&mux->loop_; + case WEBP_CHUNK_META: return (WebPChunk**)&mux->meta_; + case WEBP_CHUNK_UNKNOWN: return (WebPChunk**)&mux->unknown_; + default: return NULL; + } +} + +WebPMuxError MuxValidateForImage(const WebPMux* const mux) { + const int num_images = MuxImageCount(mux->images_, WEBP_CHUNK_IMAGE); + const int num_frames = MuxImageCount(mux->images_, WEBP_CHUNK_FRAME); + const int num_tiles = MuxImageCount(mux->images_, WEBP_CHUNK_TILE); + + if (num_images == 0) { + // No images in mux. + return WEBP_MUX_NOT_FOUND; + } else if (num_images == 1 && num_frames == 0 && num_tiles == 0) { + // Valid case (single image). + return WEBP_MUX_OK; + } else { + // Frame/Tile case OR an invalid mux. + return WEBP_MUX_INVALID_ARGUMENT; } } @@ -447,7 +480,7 @@ static int IsNotCompatible(int feature, int num_items) { // On success returns WEBP_MUX_OK and stores the chunk count in *num. static WebPMuxError ValidateChunk(const WebPMux* const mux, CHUNK_INDEX idx, WebPFeatureFlags feature, - uint32_t vp8x_flags, + WebPFeatureFlags vp8x_flags, int max, int* num) { const WebPMuxError err = WebPMuxNumChunks(mux, kChunks[idx].id, num); @@ -461,11 +494,10 @@ static WebPMuxError ValidateChunk(const WebPMux* const mux, CHUNK_INDEX idx, WebPMuxError MuxValidate(const WebPMux* const mux) { int num_iccp; - int num_exif; - int num_xmp; - int num_anim; + int num_meta; + int num_loop_chunks; int num_frames; - int num_fragments; + int num_tiles; int num_vp8x; int num_images; int num_alpha; @@ -485,33 +517,29 @@ WebPMuxError MuxValidate(const WebPMux* const mux) { err = ValidateChunk(mux, IDX_ICCP, ICCP_FLAG, flags, 1, &num_iccp); if (err != WEBP_MUX_OK) return err; - // At most one EXIF metadata. - err = ValidateChunk(mux, IDX_EXIF, EXIF_FLAG, flags, 1, &num_exif); - if (err != WEBP_MUX_OK) return err; - // At most one XMP metadata. - err = ValidateChunk(mux, IDX_XMP, XMP_FLAG, flags, 1, &num_xmp); + err = ValidateChunk(mux, IDX_META, META_FLAG, flags, 1, &num_meta); if (err != WEBP_MUX_OK) return err; - // Animation: ANIMATION_FLAG, ANIM chunk and ANMF chunk(s) are consistent. - // At most one ANIM chunk. - err = ValidateChunk(mux, IDX_ANIM, NO_FLAG, flags, 1, &num_anim); + // Animation: ANIMATION_FLAG, loop chunk and frame chunk(s) are consistent. + // At most one loop chunk. + err = ValidateChunk(mux, IDX_LOOP, NO_FLAG, flags, 1, &num_loop_chunks); if (err != WEBP_MUX_OK) return err; - err = ValidateChunk(mux, IDX_ANMF, NO_FLAG, flags, -1, &num_frames); + err = ValidateChunk(mux, IDX_FRAME, NO_FLAG, flags, -1, &num_frames); if (err != WEBP_MUX_OK) return err; { const int has_animation = !!(flags & ANIMATION_FLAG); - if (has_animation && (num_anim == 0 || num_frames == 0)) { + if (has_animation && (num_loop_chunks == 0 || num_frames == 0)) { return WEBP_MUX_INVALID_ARGUMENT; } - if (!has_animation && (num_anim == 1 || num_frames > 0)) { + if (!has_animation && (num_loop_chunks == 1 || num_frames > 0)) { return WEBP_MUX_INVALID_ARGUMENT; } } - // Fragmentation: FRAGMENTS_FLAG and FRGM chunk(s) are consistent. - err = ValidateChunk(mux, IDX_FRGM, FRAGMENTS_FLAG, flags, -1, &num_fragments); + // Tiling: TILE_FLAG and tile chunk(s) are consistent. + err = ValidateChunk(mux, IDX_TILE, TILE_FLAG, flags, -1, &num_tiles); if (err != WEBP_MUX_OK) return err; // Verify either VP8X chunk is present OR there is only one elem in @@ -523,22 +551,16 @@ WebPMuxError MuxValidate(const WebPMux* const mux) { if (num_vp8x == 0 && num_images != 1) return WEBP_MUX_INVALID_ARGUMENT; // ALPHA_FLAG & alpha chunk(s) are consistent. - if (MuxHasAlpha(mux->images_)) { - if (num_vp8x > 0) { - // VP8X chunk is present, so it should contain ALPHA_FLAG. - if (!(flags & ALPHA_FLAG)) return WEBP_MUX_INVALID_ARGUMENT; - } else { - // VP8X chunk is not present, so ALPH chunks should NOT be present either. - err = WebPMuxNumChunks(mux, WEBP_CHUNK_ALPHA, &num_alpha); - if (err != WEBP_MUX_OK) return err; - if (num_alpha > 0) return WEBP_MUX_INVALID_ARGUMENT; - } - } else { // Mux doesn't need alpha. So, ALPHA_FLAG should NOT be present. - if (flags & ALPHA_FLAG) return WEBP_MUX_INVALID_ARGUMENT; + if (num_vp8x > 0 && MuxHasLosslessImages(mux->images_)) { + // Special case: we have a VP8X chunk as well as some lossless images. + if (!(flags & ALPHA_FLAG)) return WEBP_MUX_INVALID_ARGUMENT; + } else { + err = ValidateChunk(mux, IDX_ALPHA, ALPHA_FLAG, flags, -1, &num_alpha); + if (err != WEBP_MUX_OK) return err; } - // num_fragments & num_images are consistent. - if (num_fragments > 0 && num_images != num_fragments) { + // num_tiles & num_images are consistent. + if (num_tiles > 0 && num_images != num_tiles) { return WEBP_MUX_INVALID_ARGUMENT; } @@ -549,3 +571,6 @@ WebPMuxError MuxValidate(const WebPMux* const mux) { //------------------------------------------------------------------------------ +#if defined(__cplusplus) || defined(c_plusplus) +} // extern "C" +#endif |