mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-15 21:39:59 +02:00
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:
@ -669,6 +669,33 @@ void WebPCleanupTransparentArea(WebPPicture* const pic) {
|
||||
#undef SIZE
|
||||
#undef SIZE2
|
||||
|
||||
// Checking for the presence of non-opaque alpha.
|
||||
int WebPPictureHasTransparency(const WebPPicture* const pic) {
|
||||
if (pic == NULL) return 0;
|
||||
if (!pic->use_argb_input) {
|
||||
int x, y;
|
||||
const uint8_t* alpha = pic->a;
|
||||
if (alpha == NULL) return 0;
|
||||
for (y = 0; y < pic->height; ++y) {
|
||||
for (x = 0; x < pic->width; ++x) {
|
||||
if (alpha[x] != 0xff) return 1;
|
||||
}
|
||||
alpha += pic->a_stride;
|
||||
}
|
||||
} else {
|
||||
int x, y;
|
||||
const uint32_t* argb = pic->argb;
|
||||
if (argb == NULL) return 1;
|
||||
for (y = 0; y < pic->height; ++y) {
|
||||
for (x = 0; x < pic->width; ++x) {
|
||||
if (argb[x] < 0xff000000) return 1; // test any alpha values != 0xff
|
||||
}
|
||||
argb += pic->argb_stride;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Distortion
|
||||
|
||||
|
Reference in New Issue
Block a user