mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 22:28:22 +01:00
make WebPCleanupTransparentArea work with argb picture
the -alpha_cleanup flag was ineffective since we switched cwebp to using ARGB input always. Original idea by David Eckel (dvdckl at gmail dot com) Change-Id: I0917a8b91ce15a43199728ff4ee2a163be443bab
This commit is contained in:
parent
5da185522b
commit
c741183c10
@ -992,7 +992,20 @@ static int is_transparent_area(const uint8_t* ptr, int stride, int size) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static WEBP_INLINE void flatten(uint8_t* ptr, int v, int stride, int size) {
|
||||
static int is_transparent_argb_area(const uint32_t* ptr, int stride, int size) {
|
||||
int y, x;
|
||||
for (y = 0; y < size; ++y) {
|
||||
for (x = 0; x < size; ++x) {
|
||||
if (ptr[x] & 0xff000000u) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
ptr += stride;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void flatten(uint8_t* ptr, int v, int stride, int size) {
|
||||
int y;
|
||||
for (y = 0; y < size; ++y) {
|
||||
memset(ptr, v, size);
|
||||
@ -1000,18 +1013,42 @@ static WEBP_INLINE void flatten(uint8_t* ptr, int v, int stride, int size) {
|
||||
}
|
||||
}
|
||||
|
||||
static void flatten_argb(uint32_t* ptr, uint32_t v, int stride, int size) {
|
||||
int x, y;
|
||||
for (y = 0; y < size; ++y) {
|
||||
for (x = 0; x < size; ++x) ptr[x] = v;
|
||||
ptr += stride;
|
||||
}
|
||||
}
|
||||
|
||||
void WebPCleanupTransparentArea(WebPPicture* pic) {
|
||||
int x, y, w, h;
|
||||
const uint8_t* a_ptr;
|
||||
int values[3] = { 0 };
|
||||
|
||||
if (pic == NULL) return;
|
||||
|
||||
a_ptr = pic->a;
|
||||
if (a_ptr == NULL) return; // nothing to do
|
||||
|
||||
w = pic->width / SIZE;
|
||||
h = pic->height / SIZE;
|
||||
|
||||
// note: we ignore the left-overs on right/bottom
|
||||
if (pic->use_argb) {
|
||||
uint32_t argb_value = 0;
|
||||
for (y = 0; y < h; ++y) {
|
||||
int need_reset = 1;
|
||||
for (x = 0; x < w; ++x) {
|
||||
const int off = (y * pic->argb_stride + x) * SIZE;
|
||||
if (is_transparent_argb_area(pic->argb + off, pic->argb_stride, SIZE)) {
|
||||
if (need_reset) {
|
||||
argb_value = pic->argb[off];
|
||||
need_reset = 0;
|
||||
}
|
||||
flatten_argb(pic->argb + off, argb_value, pic->argb_stride, SIZE);
|
||||
} else {
|
||||
need_reset = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const uint8_t* const a_ptr = pic->a;
|
||||
int values[3] = { 0 };
|
||||
if (a_ptr == NULL) return; // nothing to do
|
||||
for (y = 0; y < h; ++y) {
|
||||
int need_reset = 1;
|
||||
for (x = 0; x < w; ++x) {
|
||||
@ -1032,7 +1069,7 @@ void WebPCleanupTransparentArea(WebPPicture* pic) {
|
||||
need_reset = 1;
|
||||
}
|
||||
}
|
||||
// ignore the left-overs on right/bottom
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -459,9 +459,9 @@ WEBP_EXTERN(int) WebPPictureARGBToYUVADithered(
|
||||
// Returns false in case of error.
|
||||
WEBP_EXTERN(int) WebPPictureYUVAToARGB(WebPPicture* picture);
|
||||
|
||||
// Helper function: given a width x height plane of YUV(A) samples
|
||||
// (with stride 'stride'), clean-up the YUV samples under fully transparent
|
||||
// area, to help compressibility (no guarantee, though).
|
||||
// Helper function: given a width x height plane of RGBA or YUV(A) samples
|
||||
// clean-up the YUV or RGB samples under fully transparent area, to help
|
||||
// compressibility (no guarantee, though).
|
||||
WEBP_EXTERN(void) WebPCleanupTransparentArea(WebPPicture* picture);
|
||||
|
||||
// Scan the picture 'picture' for the presence of non fully opaque alpha values.
|
||||
|
Loading…
Reference in New Issue
Block a user