From 221a06bb16c9b2584de8c9b9a5ca9991ad4a7957 Mon Sep 17 00:00:00 2001 From: Vikas Arora Date: Mon, 9 Jan 2012 14:05:28 +0530 Subject: [PATCH] Fix bug for Alpha in RGBA_4444 color-mode. Fix bug for Alpha data in RGBA_4444 color-mode. The Alpha data is required to be clipped [0, 15] while converting from 8 bits to 4 bits. Change-Id: I80705d575c35121beb9633a05ec8823435c79586 --- src/dec/io.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dec/io.c b/src/dec/io.c index a6a20e94..ed8eb7f6 100644 --- a/src/dec/io.c +++ b/src/dec/io.c @@ -202,6 +202,10 @@ static int EmitAlphaRGB(const VP8Io* const io, WebPDecParams* const p) { return 0; } +static WEBP_INLINE uint32_t clip(uint32_t v, uint32_t max_value) { + return (v > max_value) ? max_value : v; +} + static int EmitAlphaRGBA4444(const VP8Io* const io, WebPDecParams* const p) { const int mb_w = io->mb_w; const int mb_h = io->mb_h; @@ -213,7 +217,7 @@ static int EmitAlphaRGBA4444(const VP8Io* const io, WebPDecParams* const p) { for (j = 0; j < mb_h; ++j) { for (i = 0; i < mb_w; ++i) { // Fill in the alpha value (converted to 4 bits). - const uint8_t alpha_val = (alpha[i] + 8) >> 4; + const uint32_t alpha_val = clip((alpha[i] + 8) >> 4, 15); dst[2 * i] = (dst[2 * i] & 0xf0) | alpha_val; } alpha += io->width; @@ -490,7 +494,7 @@ static int ExportAlphaRGBA4444(WebPDecParams* const p, int y_pos) { ExportRow(&p->scaler_a); for (i = 0; i < p->scaler_a.dst_width; ++i) { // Fill in the alpha value (converted to 4 bits). - const uint8_t alpha_val = (p->scaler_a.dst[i] + 8) >> 4; + const uint32_t alpha_val = clip((p->scaler_a.dst[i] + 8) >> 4, 15); dst[2 * i] = (dst[2 * i] & 0xf0) | alpha_val; } dst += buf->stride;