mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 14:34:33 +02:00
Mux: Allow only some frames/tiles to have alpha.
And related const fixes. Change-Id: I79f6f1b9f8c6faac8cc4ef24b58edff6d90de045
This commit is contained in:
@ -613,9 +613,8 @@ static WebPMuxError CreateVP8XChunk(WebPMux* const mux) {
|
||||
}
|
||||
}
|
||||
|
||||
if (images->alpha_ != NULL && images->alpha_->data_.bytes_ != NULL) {
|
||||
// This is an image with alpha channel.
|
||||
flags |= ALPHA_FLAG;
|
||||
if (MuxImageCount(images, WEBP_CHUNK_ALPHA) > 0) {
|
||||
flags |= ALPHA_FLAG; // Some images have an alpha channel.
|
||||
}
|
||||
|
||||
if (flags == 0) {
|
||||
|
@ -194,7 +194,7 @@ WebPMuxImage* MuxImageDelete(WebPMuxImage* const wpi);
|
||||
void MuxImageDeleteAll(WebPMuxImage** const wpi_list);
|
||||
|
||||
// Count number of images matching the given tag id in the 'wpi_list'.
|
||||
int MuxImageCount(WebPMuxImage* const wpi_list, WebPChunkId id);
|
||||
int MuxImageCount(const WebPMuxImage* wpi_list, WebPChunkId id);
|
||||
|
||||
// Check if given ID corresponds to an image related chunk.
|
||||
static WEBP_INLINE int IsWPI(WebPChunkId id) {
|
||||
@ -208,14 +208,14 @@ static WEBP_INLINE int IsWPI(WebPChunkId id) {
|
||||
}
|
||||
|
||||
// Get a reference to appropriate chunk list within an image given chunk tag.
|
||||
static WEBP_INLINE WebPChunk** MuxImageGetListFromId(WebPMuxImage* wpi,
|
||||
WebPChunkId id) {
|
||||
static WEBP_INLINE WebPChunk** MuxImageGetListFromId(
|
||||
const WebPMuxImage* const wpi, WebPChunkId id) {
|
||||
assert(wpi != NULL);
|
||||
switch (id) {
|
||||
case WEBP_CHUNK_FRAME:
|
||||
case WEBP_CHUNK_TILE: return &wpi->header_;
|
||||
case WEBP_CHUNK_ALPHA: return &wpi->alpha_;
|
||||
case WEBP_CHUNK_IMAGE: return &wpi->img_;
|
||||
case WEBP_CHUNK_TILE: return (WebPChunk**)&wpi->header_;
|
||||
case WEBP_CHUNK_ALPHA: return (WebPChunk**)&wpi->alpha_;
|
||||
case WEBP_CHUNK_IMAGE: return (WebPChunk**)&wpi->img_;
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -262,9 +262,9 @@ WebPMuxImage* MuxImageRelease(WebPMuxImage* const wpi) {
|
||||
//------------------------------------------------------------------------------
|
||||
// MuxImage search methods.
|
||||
|
||||
int MuxImageCount(WebPMuxImage* const wpi_list, WebPChunkId id) {
|
||||
int MuxImageCount(const WebPMuxImage* wpi_list, WebPChunkId id) {
|
||||
int count = 0;
|
||||
WebPMuxImage* current;
|
||||
const WebPMuxImage* current;
|
||||
for (current = wpi_list; current != NULL; current = current->next_) {
|
||||
const WebPChunk* const wpi_chunk = *MuxImageGetListFromId(current, id);
|
||||
if (wpi_chunk != NULL) {
|
||||
@ -558,13 +558,6 @@ WebPMuxError MuxValidate(const WebPMux* const mux) {
|
||||
} else {
|
||||
err = ValidateChunk(mux, IDX_ALPHA, ALPHA_FLAG, flags, -1, &num_alpha);
|
||||
if (err != WEBP_MUX_OK) return err;
|
||||
|
||||
// num_images & num_alpha_chunks are consistent.
|
||||
if (num_alpha > 0 && num_alpha != num_images) {
|
||||
// Note that "num_alpha > 0" is the correct test but "flags && ALPHA_FLAG"
|
||||
// is NOT, because ALPHA_FLAG is based on first image only.
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
|
||||
// num_tiles & num_images are consistent.
|
||||
|
Reference in New Issue
Block a user