Rectify WebPMuxGetFeatures:

It should return ALPHA_FLAG for lossless bit-stream

Change-Id: I900bd5b58bf75bc25fca1abf4ecc12aea26eac1c
This commit is contained in:
Urvang Joshi 2012-11-09 14:37:20 -08:00
parent 7caab1d8f6
commit 2ca642e02a
2 changed files with 24 additions and 17 deletions

View File

@ -578,12 +578,14 @@ WebPMuxError MuxValidate(const WebPMux* const mux) {
if (num_vp8x == 0 && num_images != 1) return WEBP_MUX_INVALID_ARGUMENT; if (num_vp8x == 0 && num_images != 1) return WEBP_MUX_INVALID_ARGUMENT;
// ALPHA_FLAG & alpha chunk(s) are consistent. // ALPHA_FLAG & alpha chunk(s) are consistent.
if (num_vp8x > 0 && MuxHasLosslessImages(mux->images_)) { if (MuxHasLosslessImages(mux->images_)) {
// Special case: we have a VP8X chunk as well as some lossless images. if (num_vp8x > 0) {
if (!(flags & ALPHA_FLAG)) return WEBP_MUX_INVALID_ARGUMENT; // Special case: we have a VP8X chunk as well as some lossless images.
if (!(flags & ALPHA_FLAG)) return WEBP_MUX_INVALID_ARGUMENT;
}
} else { } else {
err = ValidateChunk(mux, IDX_ALPHA, ALPHA_FLAG, flags, -1, &num_alpha); err = ValidateChunk(mux, IDX_ALPHA, ALPHA_FLAG, flags, -1, &num_alpha);
if (err != WEBP_MUX_OK) return err; if (err != WEBP_MUX_OK) return err;
} }
// num_fragments & num_images are consistent. // num_fragments & num_images are consistent.

View File

@ -254,27 +254,32 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Get API(s). // Get API(s).
// TODO(urvang): Change the behavior of this to return ALPHA_FLAG when the mux
// doesn't contain a VP8X chunk, but does contain a VP8L chunk with real alpha.
WebPMuxError WebPMuxGetFeatures(const WebPMux* mux, uint32_t* flags) { WebPMuxError WebPMuxGetFeatures(const WebPMux* mux, uint32_t* flags) {
WebPData data; WebPData data;
WebPMuxError err;
if (mux == NULL || flags == NULL) return WEBP_MUX_INVALID_ARGUMENT; if (mux == NULL || flags == NULL) return WEBP_MUX_INVALID_ARGUMENT;
*flags = 0; *flags = 0;
// Check if VP8X chunk is present. // Check if VP8X chunk is present.
err = MuxGet(mux, IDX_VP8X, 1, &data); if (MuxGet(mux, IDX_VP8X, 1, &data) == WEBP_MUX_OK) {
if (err == WEBP_MUX_NOT_FOUND) { if (data.size < CHUNK_SIZE_BYTES) return WEBP_MUX_BAD_DATA;
return MuxValidateForImage(mux); // Check if a single image is present. *flags = GetLE32(data.bytes); // All OK. Fill up flags.
} else if (err != WEBP_MUX_OK) { } else {
return err; WebPMuxError err = MuxValidateForImage(mux); // Check for single image.
if (err != WEBP_MUX_OK) return err;
if (MuxHasLosslessImages(mux->images_)) {
const WebPData* const vp8l_data = &mux->images_->img_->data_;
int has_alpha = 0;
if (!VP8LGetInfo(vp8l_data->bytes, vp8l_data->size, NULL, NULL,
&has_alpha)) {
return WEBP_MUX_BAD_DATA;
}
if (has_alpha) {
*flags = ALPHA_FLAG;
}
}
} }
if (data.size < CHUNK_SIZE_BYTES) return WEBP_MUX_BAD_DATA;
// All OK. Fill up flags.
*flags = GetLE32(data.bytes);
return WEBP_MUX_OK; return WEBP_MUX_OK;
} }