diff options
author | jzern@chromium.org <jzern@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-20 17:23:14 +0000 |
---|---|---|
committer | jzern@chromium.org <jzern@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-20 17:23:14 +0000 |
commit | 97f8a48ec3d16c16bc966063f745b1fc1b45dac7 (patch) | |
tree | 9cd29705cbaee0bcffa3fe2385f6a7b51d787092 /third_party/libwebp/enc | |
parent | 0323baf298763af020217eb11b0e86ac7a0e260a (diff) | |
download | chromium_src-97f8a48ec3d16c16bc966063f745b1fc1b45dac7.zip chromium_src-97f8a48ec3d16c16bc966063f745b1fc1b45dac7.tar.gz chromium_src-97f8a48ec3d16c16bc966063f745b1fc1b45dac7.tar.bz2 |
libwebp-0.3.1
Bug fix rollup + incremental decode support for extended format files
(alpha/icc + vp8).
BUG=
Review URL: https://chromiumcodereview.appspot.com/16871017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207471 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/libwebp/enc')
-rw-r--r-- | third_party/libwebp/enc/alpha.c | 75 | ||||
-rw-r--r-- | third_party/libwebp/enc/analysis.c | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/backward_references.c | 84 | ||||
-rw-r--r-- | third_party/libwebp/enc/backward_references.h | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/config.c | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/cost.c | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/cost.h | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/filter.c | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/frame.c | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/histogram.c | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/histogram.h | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/iterator.c | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/layer.c | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/picture.c | 12 | ||||
-rw-r--r-- | third_party/libwebp/enc/quant.c | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/syntax.c | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/token.c | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/tree.c | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/vp8enci.h | 10 | ||||
-rw-r--r-- | third_party/libwebp/enc/vp8l.c | 114 | ||||
-rw-r--r-- | third_party/libwebp/enc/vp8li.h | 8 | ||||
-rw-r--r-- | third_party/libwebp/enc/webpenc.c | 12 |
22 files changed, 268 insertions, 167 deletions
diff --git a/third_party/libwebp/enc/alpha.c b/third_party/libwebp/enc/alpha.c index aadf88f..e636c96 100644 --- a/third_party/libwebp/enc/alpha.c +++ b/third_party/libwebp/enc/alpha.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Alpha-plane compression. @@ -80,7 +82,7 @@ static int EncodeLossless(const uint8_t* const data, int width, int height, config.lossless = 1; config.method = effort_level; // impact is very small // Set a moderate default quality setting for alpha. - config.quality = 5.f * effort_level; + config.quality = 10.f * effort_level; assert(config.quality >= 0 && config.quality <= 100.f); ok = VP8LBitWriterInit(&tmp_bw, (width * height) >> 3); @@ -156,6 +158,25 @@ static void CopyPlane(const uint8_t* src, int src_stride, } } +static int GetNumColors(const uint8_t* data, int width, int height, + int stride) { + int j; + int colors = 0; + uint8_t color[256] = { 0 }; + + for (j = 0; j < height; ++j) { + int i; + const uint8_t* const p = data + j * stride; + for (i = 0; i < width; ++i) { + color[p[i]] = 1; + } + } + for (j = 0; j < 256; ++j) { + if (color[j] > 0) ++colors; + } + return colors; +} + static int EncodeAlpha(VP8Encoder* const enc, int quality, int method, int filter, int effort_level, @@ -207,18 +228,32 @@ static int EncodeAlpha(VP8Encoder* const enc, VP8BitWriter bw; int test_filter; uint8_t* filtered_alpha = NULL; - - // We always test WEBP_FILTER_NONE first. - ok = EncodeAlphaInternal(quant_alpha, width, height, - method, WEBP_FILTER_NONE, reduce_levels, - effort_level, NULL, &bw, pic->stats); - if (!ok) { - VP8BitWriterWipeOut(&bw); - goto End; + int try_filter_none = (effort_level > 3); + + if (filter == WEBP_FILTER_FAST) { // Quick estimate of the best candidate. + const int kMinColorsForFilterNone = 16; + const int kMaxColorsForFilterNone = 192; + const int num_colors = GetNumColors(quant_alpha, width, height, width); + // For low number of colors, NONE yeilds better compression. + filter = (num_colors <= kMinColorsForFilterNone) ? WEBP_FILTER_NONE : + EstimateBestFilter(quant_alpha, width, height, width); + // For large number of colors, try FILTER_NONE in addition to the best + // filter as well. + if (num_colors > kMaxColorsForFilterNone) { + try_filter_none = 1; + } } - if (filter == WEBP_FILTER_FAST) { // Quick estimate of a second candidate? - filter = EstimateBestFilter(quant_alpha, width, height, width); + // Test for WEBP_FILTER_NONE for higher effort levels. + if (try_filter_none || filter == WEBP_FILTER_NONE) { + ok = EncodeAlphaInternal(quant_alpha, width, height, + method, WEBP_FILTER_NONE, reduce_levels, + effort_level, NULL, &bw, pic->stats); + + if (!ok) { + VP8BitWriterWipeOut(&bw); + goto End; + } } // Stop? if (filter == WEBP_FILTER_NONE) { @@ -234,11 +269,14 @@ static int EncodeAlpha(VP8Encoder* const enc, // Try the other mode(s). { WebPAuxStats best_stats; - size_t best_score = VP8BitWriterSize(&bw); + size_t best_score = try_filter_none ? + VP8BitWriterSize(&bw) : (size_t)~0U; + int wipe_tmp_bw = try_filter_none; memset(&best_stats, 0, sizeof(best_stats)); // prevent spurious warning if (pic->stats != NULL) best_stats = *pic->stats; - for (test_filter = WEBP_FILTER_HORIZONTAL; + for (test_filter = + try_filter_none ? WEBP_FILTER_HORIZONTAL : WEBP_FILTER_NONE; ok && (test_filter <= WEBP_FILTER_GRADIENT); ++test_filter) { VP8BitWriter tmp_bw; @@ -262,7 +300,10 @@ static int EncodeAlpha(VP8Encoder* const enc, } else { VP8BitWriterWipeOut(&bw); } - VP8BitWriterWipeOut(&tmp_bw); + if (wipe_tmp_bw) { + VP8BitWriterWipeOut(&tmp_bw); + } + wipe_tmp_bw = 1; // For next filter trial for WEBP_FILTER_BEST. } if (pic->stats != NULL) *pic->stats = best_stats; } diff --git a/third_party/libwebp/enc/analysis.c b/third_party/libwebp/enc/analysis.c index 221e9d0..4ff3edd 100644 --- a/third_party/libwebp/enc/analysis.c +++ b/third_party/libwebp/enc/analysis.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Macroblock analysis diff --git a/third_party/libwebp/enc/backward_references.c b/third_party/libwebp/enc/backward_references.c index cf02787..db4f430 100644 --- a/third_party/libwebp/enc/backward_references.c +++ b/third_party/libwebp/enc/backward_references.c @@ -1,8 +1,10 @@ // Copyright 2012 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Author: Jyrki Alakuijala (jyrki@google.com) @@ -142,9 +144,10 @@ static void HashChainInsert(HashChain* const p, } static void GetParamsForHashChainFindCopy(int quality, int xsize, - int* window_size, int* iter_pos, - int* iter_limit) { + int cache_bits, int* window_size, + int* iter_pos, int* iter_limit) { const int iter_mult = (quality < 27) ? 1 : 1 + ((quality - 27) >> 4); + const int iter_neg = -iter_mult * (quality >> 1); // Limit the backward-ref window size for lower qualities. const int max_window_size = (quality > 50) ? WINDOW_SIZE : (quality > 25) ? (xsize << 8) @@ -152,77 +155,74 @@ static void GetParamsForHashChainFindCopy(int quality, int xsize, assert(xsize > 0); *window_size = (max_window_size > WINDOW_SIZE) ? WINDOW_SIZE : max_window_size; - *iter_pos = 5 + (quality >> 3); - *iter_limit = -quality * iter_mult; + *iter_pos = 8 + (quality >> 3); + // For lower entropy images, the rigourous search loop in HashChainFindCopy + // can be relaxed. + *iter_limit = (cache_bits > 0) ? iter_neg : iter_neg / 2; } static int HashChainFindCopy(const HashChain* const p, - int base_position, int xsize, + int base_position, int xsize_signed, const uint32_t* const argb, int maxlen, int window_size, int iter_pos, int iter_limit, int* const distance_ptr, int* const length_ptr) { - const uint64_t hash_code = GetPixPairHash64(&argb[base_position]); - int prev_length = 0; - int64_t best_val = 0; - int best_length = 0; - int best_distance = 0; const uint32_t* const argb_start = argb + base_position; + uint64_t best_val = 0; + uint32_t best_length = 1; + uint32_t best_distance = 0; + const uint32_t xsize = (uint32_t)xsize_signed; const int min_pos = (base_position > window_size) ? base_position - window_size : 0; int pos; - assert(xsize > 0); - for (pos = p->hash_to_first_index_[hash_code]; + for (pos = p->hash_to_first_index_[GetPixPairHash64(argb_start)]; pos >= min_pos; pos = p->chain_[pos]) { - int64_t val; - int curr_length; + uint64_t val; + uint32_t curr_length; + uint32_t distance; if (iter_pos < 0) { if (iter_pos < iter_limit || best_val >= 0xff0000) { break; } } --iter_pos; - if (best_length != 0 && - argb[pos + best_length - 1] != argb_start[best_length - 1]) { + if (argb[pos + best_length - 1] != argb_start[best_length - 1]) { continue; } curr_length = FindMatchLength(argb + pos, argb_start, maxlen); - if (curr_length < prev_length) { + if (curr_length < best_length) { continue; } - val = 65536 * curr_length; + distance = (uint32_t)(base_position - pos); + val = curr_length << 16; // Favoring 2d locality here gives savings for certain images. - if (base_position - pos < 9 * xsize) { - const int y = (base_position - pos) / xsize; - int x = (base_position - pos) % xsize; - if (x > xsize / 2) { + if (distance < 9 * xsize) { + const uint32_t y = distance / xsize; + uint32_t x = distance % xsize; + if (x > (xsize >> 1)) { x = xsize - x; } - if (x <= 7 && x >= -8) { + if (x <= 7) { + val += 9 * 9 + 9 * 9; val -= y * y + x * x; - } else { - val -= 9 * 9 + 9 * 9; } - } else { - val -= 9 * 9 + 9 * 9; } if (best_val < val) { - prev_length = curr_length; best_val = val; best_length = curr_length; - best_distance = base_position - pos; + best_distance = distance; if (curr_length >= MAX_LENGTH) { break; } - if ((best_distance == 1 || best_distance == xsize) && + if ((best_distance == 1 || distance == xsize) && best_length >= 128) { break; } } } - *distance_ptr = best_distance; + *distance_ptr = (int)best_distance; *length_ptr = best_length; return (best_length >= MIN_LENGTH); } @@ -284,8 +284,8 @@ static int BackwardReferencesHashChain(int xsize, int ysize, if (!HashChainInit(hash_chain, pix_count)) goto Error; refs->size = 0; - GetParamsForHashChainFindCopy(quality, xsize, &window_size, &iter_pos, - &iter_limit); + GetParamsForHashChainFindCopy(quality, xsize, cache_bits, + &window_size, &iter_pos, &iter_limit); for (i = 0; i < pix_count; ) { // Alternative#1: Code the pixels starting at 'i' using backward reference. int offset = 0; @@ -510,8 +510,8 @@ static int BackwardReferencesHashChainDistanceOnly( // We loop one pixel at a time, but store all currently best points to // non-processed locations from this point. dist_array[0] = 0; - GetParamsForHashChainFindCopy(quality, xsize, &window_size, &iter_pos, - &iter_limit); + GetParamsForHashChainFindCopy(quality, xsize, cache_bits, + &window_size, &iter_pos, &iter_limit); for (i = 0; i < pix_count; ++i) { double prev_cost = 0.0; int shortmax; @@ -645,8 +645,8 @@ static int BackwardReferencesHashChainFollowChosenPath( } refs->size = 0; - GetParamsForHashChainFindCopy(quality, xsize, &window_size, &iter_pos, - &iter_limit); + GetParamsForHashChainFindCopy(quality, xsize, cache_bits, + &window_size, &iter_pos, &iter_limit); for (ix = 0; ix < chosen_path_size; ++ix, ++size) { int offset = 0; int len = 0; @@ -785,7 +785,9 @@ int VP8LGetBackwardReferences(int width, int height, *best = refs_lz77; // default guess: lz77 is better VP8LClearBackwardRefs(&refs_rle); if (try_lz77_trace_backwards) { - const int recursion_level = (num_pix < 320 * 200) ? 1 : 0; + // Set recursion level for large images using a color cache. + const int recursion_level = + (num_pix < 320 * 200) && (cache_bits > 0) ? 1 : 0; VP8LBackwardRefs refs_trace; if (!VP8LBackwardRefsAlloc(&refs_trace, num_pix)) { goto End; diff --git a/third_party/libwebp/enc/backward_references.h b/third_party/libwebp/enc/backward_references.h index 8cb1a7a..b0d1813 100644 --- a/third_party/libwebp/enc/backward_references.h +++ b/third_party/libwebp/enc/backward_references.h @@ -1,8 +1,10 @@ // Copyright 2012 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Author: Jyrki Alakuijala (jyrki@google.com) diff --git a/third_party/libwebp/enc/config.c b/third_party/libwebp/enc/config.c index bb88111..acf96b0 100644 --- a/third_party/libwebp/enc/config.c +++ b/third_party/libwebp/enc/config.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Coding tools configuration diff --git a/third_party/libwebp/enc/cost.c b/third_party/libwebp/enc/cost.c index 89b60ba..d4916d7 100644 --- a/third_party/libwebp/enc/cost.c +++ b/third_party/libwebp/enc/cost.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Cost tables for level and modes diff --git a/third_party/libwebp/enc/cost.h b/third_party/libwebp/enc/cost.h index e264d32..7d7c2c7 100644 --- a/third_party/libwebp/enc/cost.h +++ b/third_party/libwebp/enc/cost.h @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Cost tables for level and modes. diff --git a/third_party/libwebp/enc/filter.c b/third_party/libwebp/enc/filter.c index 7fb78a3..aae2723d 100644 --- a/third_party/libwebp/enc/filter.c +++ b/third_party/libwebp/enc/filter.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Selecting filter level diff --git a/third_party/libwebp/enc/frame.c b/third_party/libwebp/enc/frame.c index 9520618..c56abed 100644 --- a/third_party/libwebp/enc/frame.c +++ b/third_party/libwebp/enc/frame.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // frame coding and analysis diff --git a/third_party/libwebp/enc/histogram.c b/third_party/libwebp/enc/histogram.c index 69e5fa3..787ea5d 100644 --- a/third_party/libwebp/enc/histogram.c +++ b/third_party/libwebp/enc/histogram.c @@ -1,8 +1,10 @@ // Copyright 2012 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Author: Jyrki Alakuijala (jyrki@google.com) diff --git a/third_party/libwebp/enc/histogram.h b/third_party/libwebp/enc/histogram.h index fe7cea6..583b5a4 100644 --- a/third_party/libwebp/enc/histogram.h +++ b/third_party/libwebp/enc/histogram.h @@ -1,8 +1,10 @@ // Copyright 2012 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Author: Jyrki Alakuijala (jyrki@google.com) diff --git a/third_party/libwebp/enc/iterator.c b/third_party/libwebp/enc/iterator.c index 86e473b..0746659 100644 --- a/third_party/libwebp/enc/iterator.c +++ b/third_party/libwebp/enc/iterator.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // VP8Iterator: block iterator diff --git a/third_party/libwebp/enc/layer.c b/third_party/libwebp/enc/layer.c index 423127d..fa89660 100644 --- a/third_party/libwebp/enc/layer.c +++ b/third_party/libwebp/enc/layer.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Enhancement layer (for YUV444/422) diff --git a/third_party/libwebp/enc/picture.c b/third_party/libwebp/enc/picture.c index 1e51a8d..5aaa385 100644 --- a/third_party/libwebp/enc/picture.c +++ b/third_party/libwebp/enc/picture.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // WebPPicture utils: colorspace conversion, crop, ... @@ -709,7 +711,7 @@ static int Import(WebPPicture* const picture, for (y = 0; y < height; ++y) { for (x = 0; x < width; ++x) { const int offset = step * x + y * rgb_stride; - const uint32_t argb = (a_ptr[offset] << 24) | + const uint32_t argb = ((uint32_t)a_ptr[offset] << 24) | (r_ptr[offset] << 16) | (g_ptr[offset] << 8) | (b_ptr[offset]); @@ -809,7 +811,7 @@ int WebPPictureYUVAToARGB(WebPPicture* picture) { const uint8_t* const src = picture->a + y * picture->a_stride; int x; for (x = 0; x < width; ++x) { - argb_dst[x] = (argb_dst[x] & 0x00ffffffu) | (src[x] << 24); + argb_dst[x] = (argb_dst[x] & 0x00ffffffu) | ((uint32_t)src[x] << 24); } } } diff --git a/third_party/libwebp/enc/quant.c b/third_party/libwebp/enc/quant.c index dcfd4d16..462d4e9 100644 --- a/third_party/libwebp/enc/quant.c +++ b/third_party/libwebp/enc/quant.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Quantization diff --git a/third_party/libwebp/enc/syntax.c b/third_party/libwebp/enc/syntax.c index e81fa2b..b0f7676 100644 --- a/third_party/libwebp/enc/syntax.c +++ b/third_party/libwebp/enc/syntax.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Header syntax writing diff --git a/third_party/libwebp/enc/token.c b/third_party/libwebp/enc/token.c index 4e2f6c0..6a63371 100644 --- a/third_party/libwebp/enc/token.c +++ b/third_party/libwebp/enc/token.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Paginated token buffer diff --git a/third_party/libwebp/enc/tree.c b/third_party/libwebp/enc/tree.c index 8b25e5e..ecd8fb9 100644 --- a/third_party/libwebp/enc/tree.c +++ b/third_party/libwebp/enc/tree.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Token probabilities diff --git a/third_party/libwebp/enc/vp8enci.h b/third_party/libwebp/enc/vp8enci.h index 6aa3f43..61d56be 100644 --- a/third_party/libwebp/enc/vp8enci.h +++ b/third_party/libwebp/enc/vp8enci.h @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // WebP encoder: internal header. @@ -28,7 +30,7 @@ extern "C" { // version numbers #define ENC_MAJ_VERSION 0 #define ENC_MIN_VERSION 3 -#define ENC_REV_VERSION 0 +#define ENC_REV_VERSION 1 // intra prediction modes enum { B_DC_PRED = 0, // 4x4 modes diff --git a/third_party/libwebp/enc/vp8l.c b/third_party/libwebp/enc/vp8l.c index 5077167..945870c 100644 --- a/third_party/libwebp/enc/vp8l.c +++ b/third_party/libwebp/enc/vp8l.c @@ -1,8 +1,10 @@ // Copyright 2012 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // main entry for the lossless encoder. @@ -86,7 +88,7 @@ static int AnalyzeAndCreatePalette(const WebPPicture* const pic, argb += pic->argb_stride; } - // TODO(skal): could we reuse in_use[] to speed up ApplyPalette()? + // TODO(skal): could we reuse in_use[] to speed up EncodePalette()? num_colors = 0; for (i = 0; i < (int)(sizeof(in_use) / sizeof(in_use[0])); ++i) { if (in_use[i]) { @@ -811,34 +813,66 @@ static WebPEncodingError AllocateTransformBuffer(VP8LEncoder* const enc, return err; } -// Bundles multiple (1, 2, 4 or 8) pixels into a single pixel. -static void BundleColorMap(const uint8_t* const row, int width, - int xbits, uint32_t* const dst) { - int x; - if (xbits > 0) { - const int bit_depth = 1 << (3 - xbits); - const int mask = (1 << xbits) - 1; - uint32_t code = 0xff000000; - for (x = 0; x < width; ++x) { - const int xsub = x & mask; - if (xsub == 0) { - code = 0xff000000; +static void ApplyPalette(uint32_t* src, uint32_t* dst, + uint32_t src_stride, uint32_t dst_stride, + const uint32_t* palette, int palette_size, + int width, int height, int xbits, uint8_t* row) { + int i, x, y; + int use_LUT = 1; + for (i = 0; i < palette_size; ++i) { + if ((palette[i] & 0xffff00ffu) != 0) { + use_LUT = 0; + break; + } + } + + if (use_LUT) { + int inv_palette[MAX_PALETTE_SIZE] = { 0 }; + for (i = 0; i < palette_size; ++i) { + const int color = (palette[i] >> 8) & 0xff; + inv_palette[color] = i; + } + for (y = 0; y < height; ++y) { + for (x = 0; x < width; ++x) { + const int color = (src[x] >> 8) & 0xff; + row[x] = inv_palette[color]; } - code |= row[x] << (8 + bit_depth * xsub); - dst[x >> xbits] = code; + VP8LBundleColorMap(row, width, xbits, dst); + src += src_stride; + dst += dst_stride; } } else { - for (x = 0; x < width; ++x) dst[x] = 0xff000000 | (row[x] << 8); + // Use 1 pixel cache for ARGB pixels. + uint32_t last_pix = palette[0]; + int last_idx = 0; + for (y = 0; y < height; ++y) { + for (x = 0; x < width; ++x) { + const uint32_t pix = src[x]; + if (pix != last_pix) { + for (i = 0; i < palette_size; ++i) { + if (pix == palette[i]) { + last_idx = i; + last_pix = pix; + break; + } + } + } + row[x] = last_idx; + } + VP8LBundleColorMap(row, width, xbits, dst); + src += src_stride; + dst += dst_stride; + } } } // Note: Expects "enc->palette_" to be set properly. // Also, "enc->palette_" will be modified after this call and should not be used // later. -static WebPEncodingError ApplyPalette(VP8LBitWriter* const bw, - VP8LEncoder* const enc, int quality) { +static WebPEncodingError EncodePalette(VP8LBitWriter* const bw, + VP8LEncoder* const enc, int quality) { WebPEncodingError err = VP8_ENC_OK; - int i, x, y; + int i; const WebPPicture* const pic = enc->pic_; uint32_t* src = pic->argb; uint32_t* dst; @@ -864,20 +898,8 @@ static WebPEncodingError ApplyPalette(VP8LBitWriter* const bw, row = WebPSafeMalloc((uint64_t)width, sizeof(*row)); if (row == NULL) return VP8_ENC_ERROR_OUT_OF_MEMORY; - for (y = 0; y < height; ++y) { - for (x = 0; x < width; ++x) { - const uint32_t pix = src[x]; - for (i = 0; i < palette_size; ++i) { - if (pix == palette[i]) { - row[x] = i; - break; - } - } - } - BundleColorMap(row, width, xbits, dst); - src += pic->argb_stride; - dst += enc->current_width_; - } + ApplyPalette(src, dst, pic->argb_stride, enc->current_width_, + palette, palette_size, width, height, xbits, row); // Save palette to bitstream. VP8LWriteBits(bw, 1, TRANSFORM_PRESENT); @@ -899,13 +921,10 @@ static WebPEncodingError ApplyPalette(VP8LBitWriter* const bw, // ----------------------------------------------------------------------------- -static int GetHistoBits(const WebPConfig* const config, - const WebPPicture* const pic) { - const int width = pic->width; - const int height = pic->height; +static int GetHistoBits(int method, int use_palette, int width, int height) { const uint64_t hist_size = sizeof(VP8LHistogram); // Make tile size a function of encoding method (Range: 0 to 6). - int histo_bits = 7 - config->method; + int histo_bits = (use_palette ? 9 : 7) - method; while (1) { const uint64_t huff_image_size = VP8LSubSampleSize(width, histo_bits) * VP8LSubSampleSize(height, histo_bits) * @@ -917,13 +936,14 @@ static int GetHistoBits(const WebPConfig* const config, (histo_bits > MAX_HUFFMAN_BITS) ? MAX_HUFFMAN_BITS : histo_bits; } -static void InitEncParams(VP8LEncoder* const enc) { +static void FinishEncParams(VP8LEncoder* const enc) { const WebPConfig* const config = enc->config_; - const WebPPicture* const picture = enc->pic_; + const WebPPicture* const pic = enc->pic_; const int method = config->method; const float quality = config->quality; + const int use_palette = enc->use_palette_; enc->transform_bits_ = (method < 4) ? 5 : (method > 4) ? 3 : 4; - enc->histo_bits_ = GetHistoBits(config, picture); + enc->histo_bits_ = GetHistoBits(method, use_palette, pic->width, pic->height); enc->cache_bits_ = (quality <= 25.f) ? 0 : 7; } @@ -965,8 +985,6 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config, goto Error; } - InitEncParams(enc); - // --------------------------------------------------------------------------- // Analyze image (entropy, num_palettes etc) @@ -975,8 +993,10 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config, goto Error; } + FinishEncParams(enc); + if (enc->use_palette_) { - err = ApplyPalette(bw, enc, quality); + err = EncodePalette(bw, enc, quality); if (err != VP8_ENC_OK) goto Error; // Color cache is disabled for palette. enc->cache_bits_ = 0; diff --git a/third_party/libwebp/enc/vp8li.h b/third_party/libwebp/enc/vp8li.h index eae90dd..01f01f5 100644 --- a/third_party/libwebp/enc/vp8li.h +++ b/third_party/libwebp/enc/vp8li.h @@ -1,8 +1,10 @@ // Copyright 2012 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Lossless encoder: internal header. diff --git a/third_party/libwebp/enc/webpenc.c b/third_party/libwebp/enc/webpenc.c index 20fbac4..d420d06 100644 --- a/third_party/libwebp/enc/webpenc.c +++ b/third_party/libwebp/enc/webpenc.c @@ -1,8 +1,10 @@ // Copyright 2011 Google Inc. All Rights Reserved. // -// This code is licensed under the same terms as WebM: -// Software License Agreement: http://www.webmproject.org/license/software/ -// Additional IP Rights Grant: http://www.webmproject.org/license/additional/ +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // WebP encoder: main entry point @@ -386,9 +388,9 @@ int WebPEncode(const WebPConfig* config, WebPPicture* pic) { // Analysis is done, proceed to actual coding. ok = ok && VP8EncStartAlpha(enc); // possibly done in parallel if (!enc->use_tokens_) { - ok = VP8EncLoop(enc); + ok = ok && VP8EncLoop(enc); } else { - ok = VP8EncTokenLoop(enc); + ok = ok && VP8EncTokenLoop(enc); } ok = ok && VP8EncFinishAlpha(enc); #ifdef WEBP_EXPERIMENTAL_FEATURES |