introduce a generic WebPPictureHasTransparency() function

VP8-lossy will now avoid writing an ALPH chunk if the
alpha values are trivial.

+ changed DumpPicture() accordingly in cwebp
+ prevented the -d option to be active with lossless
 (DumpPicture wouldn't work).

Change-Id: I34fdb108a2b6207e93fa6cd00b1d2509a8e1dc4b
This commit is contained in:
Pascal Massimino
2012-06-04 15:50:05 -07:00
parent d2b6c6c03b
commit 437999fb77
5 changed files with 41 additions and 13 deletions

View File

@ -42,15 +42,6 @@ static int CompareColors(const void* p1, const void* p2) {
return (a < b) ? -1 : (a > b) ? 1 : 0;
}
static int HasRealAlpha(const uint32_t* const argb, int num_pix) {
int i;
for (i = 0; i < num_pix; ++i) {
// Checking for the presence of non-opaque alpha.
if (argb[i] < ARGB_BLACK) return 1;
}
return 0;
}
// If number of colors in the image is less than or equal to MAX_PALETTE_SIZE,
// creates a palette and returns true, else returns false.
static int AnalyzeAndCreatePalette(const uint32_t* const argb, int num_pix,
@ -983,7 +974,7 @@ int VP8LEncodeImage(const WebPConfig* const config,
goto Error;
}
has_alpha = HasRealAlpha(picture->argb, width * height);
has_alpha = WebPPictureHasTransparency(picture);
// Write the non-trivial Alpha flag and lossless version.
if (!WriteRealAlphaAndVersion(&bw, has_alpha)) {
err = VP8_ENC_ERROR_OUT_OF_MEMORY;