mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-15 21:39:59 +02:00
Stricter check for presence of alpha when writing lossless images
Earlier, all lossless images were assumed to contain alpha. Now, we use the 'alpha_is_used' bit from the VP8L bitstream to determine the same. Detecting an absence of alpha can sometimes lead to much more efficient rendering, especially for animated images. Related: refine mux code to read width/height/has_alpha information only once per frame/fragment. This avoid frequent calls to VP8(L)GetInfo(). Change-Id: I4e0eef4db7d94425396c7dff6ca5599d5bca8297
This commit is contained in:
@ -48,6 +48,9 @@ struct WebPMuxImage {
|
||||
WebPChunk* header_; // Corresponds to WEBP_CHUNK_ANMF/WEBP_CHUNK_FRGM.
|
||||
WebPChunk* alpha_; // Corresponds to WEBP_CHUNK_ALPHA.
|
||||
WebPChunk* img_; // Corresponds to WEBP_CHUNK_IMAGE.
|
||||
int width_;
|
||||
int height_;
|
||||
int has_alpha_; // Through ALPH chunk or as part of VP8L.
|
||||
int is_partial_; // True if only some of the chunks are filled.
|
||||
WebPMuxImage* next_;
|
||||
};
|
||||
@ -148,11 +151,6 @@ static WEBP_INLINE size_t ChunkDiskSize(const WebPChunk* chunk) {
|
||||
// Write out the given list of chunks into 'dst'.
|
||||
uint8_t* ChunkListEmit(const WebPChunk* chunk_list, uint8_t* dst);
|
||||
|
||||
// Get the width, height and has_alpha info of image stored in 'image_chunk'.
|
||||
WebPMuxError MuxGetImageInfo(const WebPChunk* const image_chunk,
|
||||
int* const width, int* const height,
|
||||
int* const has_alpha);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// MuxImage object management.
|
||||
|
||||
@ -170,6 +168,10 @@ WebPMuxImage* MuxImageDelete(WebPMuxImage* const wpi);
|
||||
// If id == WEBP_CHUNK_NIL, all images will be matched.
|
||||
int MuxImageCount(const WebPMuxImage* wpi_list, WebPChunkId id);
|
||||
|
||||
// Update width/height/has_alpha info from chunks within wpi.
|
||||
// Also remove ALPH chunk if not needed.
|
||||
int MuxImageFinalize(WebPMuxImage* const wpi);
|
||||
|
||||
// Check if given ID corresponds to an image related chunk.
|
||||
static WEBP_INLINE int IsWPI(WebPChunkId id) {
|
||||
switch (id) {
|
||||
@ -200,8 +202,8 @@ uint8_t* MuxImageEmit(const WebPMuxImage* const wpi, uint8_t* dst);
|
||||
//------------------------------------------------------------------------------
|
||||
// Helper methods for mux.
|
||||
|
||||
// Checks if the given image list contains at least one lossless image.
|
||||
int MuxHasLosslessImages(const WebPMuxImage* images);
|
||||
// Checks if the given image list contains at least one image with alpha.
|
||||
int MuxHasAlpha(const WebPMuxImage* images);
|
||||
|
||||
// Write out RIFF header into 'data', given total data size 'size'.
|
||||
uint8_t* MuxEmitRiffHeader(uint8_t* const data, size_t size);
|
||||
|
Reference in New Issue
Block a user