From 0e6fa06595801872aa7b01fbf0a76cdb03f9d830 Mon Sep 17 00:00:00 2001 From: Urvang Joshi Date: Mon, 23 Apr 2012 12:15:39 +0000 Subject: [PATCH] cache_bits passed to EncodeImageInternal() should be 0 when not using color cache. Change-Id: Id15c9b6bfbeb7c69a0189fa4c411df2763f9dead --- src/enc/vp8l.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/enc/vp8l.c b/src/enc/vp8l.c index e7cceeef..b1c0fcd3 100644 --- a/src/enc/vp8l.c +++ b/src/enc/vp8l.c @@ -1113,8 +1113,7 @@ static WebPEncodingError ApplyPalette(VP8LBitWriter* const bw, int VP8LEncodeImage(const WebPConfig* const config, WebPPicture* const picture) { int ok = 0; - int use_color_cache = 1; - int cache_bits = 7; + int cache_bits = 7; // If equal to 0, don't use color cache. int width, height, quality; VP8LEncoder* enc = NULL; WebPEncodingError err = VP8_ENC_OK; @@ -1152,7 +1151,7 @@ int VP8LEncodeImage(const WebPConfig* const config, if (enc->use_palette_) { err = ApplyPalette(&bw, enc, width, height, quality); if (err != VP8_ENC_OK) goto Error; - use_color_cache = 0; + cache_bits = 0; // Don't use color cache. } // In case image is not packed. @@ -1187,18 +1186,23 @@ int VP8LEncodeImage(const WebPConfig* const config, } } - if (use_color_cache) { + VP8LWriteBits(&bw, 1, 0); // No more transforms. + + // --------------------------------------------------------------------------- + // Estimate the color cache size. + + if (cache_bits > 0) { if (quality > 25) { if (!VP8LCalculateEstimateForPaletteSize(enc->argb_, enc->current_width_, height, &cache_bits)) { err = VP8_ENC_ERROR_INVALID_CONFIGURATION; goto Error; } + } else { + cache_bits = 0; // Don't use color cache. } } - VP8LWriteBits(&bw, 1, 0); // No more transforms. - // --------------------------------------------------------------------------- // Encode and write the transformed image.