From ef987500270daf67ed9fe65f93c8f9f42e78db13 Mon Sep 17 00:00:00 2001 From: Vikas Arora Date: Fri, 20 Feb 2015 09:45:32 -0800 Subject: [PATCH] Speedup method StoreImageToBitMask by 5%. Speedup method StoreImageToBitMask by replacing the code to find histogram index and Huffman tree codes at every iteration to a more optimal code that updates these only when the current pixel (to write) crosses the histogram tile-row boundary. This change speeds up the StoreImageToBitMask method by 5%. Change-Id: If01a1ccd7820f9a3a3e5bc449d070defa51be14b --- src/enc/vp8l.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/enc/vp8l.c b/src/enc/vp8l.c index 11da0993..d96935ce 100644 --- a/src/enc/vp8l.c +++ b/src/enc/vp8l.c @@ -628,17 +628,25 @@ static WebPEncodingError StoreImageToBitMask( VP8LBackwardRefs* const refs, const uint16_t* histogram_symbols, const HuffmanTreeCode* const huffman_codes) { + const int histo_xsize = histo_bits ? VP8LSubSampleSize(width, histo_bits) : 1; + const int tile_mask = (histo_bits == 0) ? 0 : -(1 << histo_bits); // x and y trace the position in the image. int x = 0; int y = 0; - const int histo_xsize = histo_bits ? VP8LSubSampleSize(width, histo_bits) : 1; + int tile_x = x & tile_mask; + int tile_y = y & tile_mask; + int histogram_ix = histogram_symbols[0]; + const HuffmanTreeCode* codes = huffman_codes + 5 * histogram_ix; VP8LRefsCursor c = VP8LRefsCursorInit(refs); while (VP8LRefsCursorOk(&c)) { const PixOrCopy* const v = c.cur_pos; - const int histogram_ix = histogram_symbols[histo_bits ? - (y >> histo_bits) * histo_xsize + - (x >> histo_bits) : 0]; - const HuffmanTreeCode* const codes = huffman_codes + 5 * histogram_ix; + if ((tile_x != (x & tile_mask)) || (tile_y != (y & tile_mask))) { + tile_x = x & tile_mask; + tile_y = y & tile_mask; + histogram_ix = histogram_symbols[(y >> histo_bits) * histo_xsize + + (x >> histo_bits)]; + codes = huffman_codes + 5 * histogram_ix; + } if (PixOrCopyIsCacheIdx(v)) { const int code = PixOrCopyCacheIdx(v); const int literal_ix = 256 + NUM_LENGTH_CODES + code;