Fix decode bug for rgbA_4444/RGBA_4444 color-modes.

The WEBP_SWAP_16BIT_CSP flag needs to be honored while filling the Alpha (4 bits)
data in the destination buffer and while pre-multiplying the alpha to RGB colors.

Change-Id: I3b07307d60963db8d09c3b078888a839cefb35ba
This commit is contained in:
Vikas Arora 2014-02-03 09:19:22 -08:00
parent 939e70e7d3
commit 1d1cd3bbd6
2 changed files with 18 additions and 0 deletions

View File

@ -250,7 +250,11 @@ static int EmitAlphaRGBA4444(const VP8Io* const io, WebPDecParams* const p) {
int num_rows;
const int start_y = GetAlphaSourceRow(io, &alpha, &num_rows);
uint8_t* const base_rgba = buf->rgba + start_y * buf->stride;
#ifdef WEBP_SWAP_16BIT_CSP
uint8_t* alpha_dst = base_rgba;
#else
uint8_t* alpha_dst = base_rgba + 1;
#endif
uint32_t alpha_mask = 0x0f;
int i, j;
@ -435,7 +439,11 @@ static int ExportAlpha(WebPDecParams* const p, int y_pos) {
static int ExportAlphaRGBA4444(WebPDecParams* const p, int y_pos) {
const WebPRGBABuffer* const buf = &p->output->u.RGBA;
uint8_t* const base_rgba = buf->rgba + (p->last_y + y_pos) * buf->stride;
#ifdef WEBP_SWAP_16BIT_CSP
uint8_t* alpha_dst = base_rgba;
#else
uint8_t* alpha_dst = base_rgba + 1;
#endif
int num_lines_out = 0;
const WEBP_CSP_MODE colorspace = p->output->colorspace;
const int width = p->scaler_a.dst_width;

View File

@ -281,6 +281,15 @@ static void ApplyAlphaMultiply4444(uint8_t* rgba4444,
while (h-- > 0) {
int i;
for (i = 0; i < w; ++i) {
#ifdef WEBP_SWAP_16BIT_CSP
const uint8_t a = (rgba4444[2 * i + 0] & 0x0f);
const uint32_t mult = MULTIPLIER(a);
const uint8_t r = multiply(dither_hi(rgba4444[2 * i + 1]), mult);
const uint8_t g = multiply(dither_lo(rgba4444[2 * i + 1]), mult);
const uint8_t b = multiply(dither_hi(rgba4444[2 * i + 0]), mult);
rgba4444[2 * i + 1] = (r & 0xf0) | ((g >> 4) & 0x0f);
rgba4444[2 * i + 0] = (b & 0xf0) | a;
#else
const uint8_t a = (rgba4444[2 * i + 1] & 0x0f);
const uint32_t mult = MULTIPLIER(a);
const uint8_t r = multiply(dither_hi(rgba4444[2 * i + 0]), mult);
@ -288,6 +297,7 @@ static void ApplyAlphaMultiply4444(uint8_t* rgba4444,
const uint8_t b = multiply(dither_hi(rgba4444[2 * i + 1]), mult);
rgba4444[2 * i + 0] = (r & 0xf0) | ((g >> 4) & 0x0f);
rgba4444[2 * i + 1] = (b & 0xf0) | a;
#endif
}
rgba4444 += stride;
}