From 4d02d5863f5a818b4c4f6abb812b4067441c6a1a Mon Sep 17 00:00:00 2001 From: Urvang Joshi Date: Fri, 20 Apr 2012 14:43:01 +0000 Subject: [PATCH] Lossless encoder: correction in Palette storage (Essentially, there was no need of a separate 'argb_palette' array. And argb_palette[0] was never being set). Change-Id: Id0a8c7e063d3af41e39fc9b8661611b51ccc55cd --- src/enc/vp8l.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/enc/vp8l.c b/src/enc/vp8l.c index 98bcee4b..dffcd778 100644 --- a/src/enc/vp8l.c +++ b/src/enc/vp8l.c @@ -1068,10 +1068,10 @@ static WebPEncodingError ApplyPalette(VP8LBitWriter* const bw, WebPEncodingError err = VP8_ENC_OK; int i; uint32_t* argb = enc->pic_->argb; - const uint32_t* const palette = enc->palette_; + uint32_t* const palette = enc->palette_; const int palette_size = enc->palette_size_; - uint32_t argb_palette[MAX_PALETTE_SIZE]; + // Replace each input pixel by corresponding palette index. for (i = 0; i < width * height; ++i) { int k; for (k = 0; k < palette_size; ++k) { @@ -1082,26 +1082,27 @@ static WebPEncodingError ApplyPalette(VP8LBitWriter* const bw, } } } + + // Save palette to bitstream. VP8LWriteBits(bw, 1, 1); VP8LWriteBits(bw, 2, 3); VP8LWriteBits(bw, 8, palette_size - 1); for (i = palette_size - 1; i >= 1; --i) { - argb_palette[i] = VP8LSubPixels(palette[i], palette[i - 1]); + palette[i] = VP8LSubPixels(palette[i], palette[i - 1]); } - if (!EncodeImageInternal(bw, argb_palette, palette_size, 1, quality, - 0, 0)) { + if (!EncodeImageInternal(bw, palette, palette_size, 1, quality, 0, 0)) { err = VP8_ENC_ERROR_INVALID_CONFIGURATION; goto Error; } + if (palette_size <= 16) { + // Image can be packed (multiple pixels per uint32_t). int xbits = 1; if (palette_size <= 2) { xbits = 3; } else if (palette_size <= 4) { xbits = 2; } - - // Image can be packed (multiple pixels per uint32). err = AllocateTransformBuffer(enc, height, VP8LSubSampleSize(width, xbits)); if (err != VP8_ENC_OK) goto Error; BundleColorMap(argb, width, height, xbits, enc->argb_, enc->current_width_);