mirror of
https://github.com/webmproject/libwebp.git
synced 2025-02-13 07:22:52 +01:00
Run TraceBackwards for higher qualities.
Also reduce the iteration count in function VP8LHashChain_FindCopy. Change-Id: I73e3811e142e81314515587fd655ab3bfa74d099
This commit is contained in:
parent
412222c88c
commit
c6ac4dfbb4
@ -121,7 +121,7 @@ static int VP8LHashChain_FindCopy(VP8LHashChain* p,
|
|||||||
const uint64_t hash_code = GetHash64(next_two_pixels);
|
const uint64_t hash_code = GetHash64(next_two_pixels);
|
||||||
int prev_length = 0;
|
int prev_length = 0;
|
||||||
int64_t best_val = 0;
|
int64_t best_val = 0;
|
||||||
int give_up = quality * 3 / 4 + 25;
|
int give_up = 10 + (quality >> 1);
|
||||||
const int min_pos = (index > kWindowSize) ? index - kWindowSize : 0;
|
const int min_pos = (index > kWindowSize) ? index - kWindowSize : 0;
|
||||||
int32_t pos;
|
int32_t pos;
|
||||||
int64_t length;
|
int64_t length;
|
||||||
@ -134,8 +134,7 @@ static int VP8LHashChain_FindCopy(VP8LHashChain* p,
|
|||||||
pos >= min_pos;
|
pos >= min_pos;
|
||||||
pos = p->chain_[pos]) {
|
pos = p->chain_[pos]) {
|
||||||
if (give_up < 0) {
|
if (give_up < 0) {
|
||||||
if (give_up < -quality * 8 ||
|
if (give_up < -quality * 2 || best_val >= 0xff0000) {
|
||||||
best_val >= 0xff0000) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,9 +218,9 @@ int VP8LBackwardReferencesHashChain(int xsize, int ysize, int use_palette,
|
|||||||
const uint32_t* argb, int palette_bits,
|
const uint32_t* argb, int palette_bits,
|
||||||
int quality, PixOrCopy* stream,
|
int quality, PixOrCopy* stream,
|
||||||
int* stream_size) {
|
int* stream_size) {
|
||||||
const int pix_count = xsize * ysize;
|
|
||||||
int i;
|
int i;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
const int pix_count = xsize * ysize;
|
||||||
VP8LHashChain* hash_chain = (VP8LHashChain*)malloc(sizeof(*hash_chain));
|
VP8LHashChain* hash_chain = (VP8LHashChain*)malloc(sizeof(*hash_chain));
|
||||||
VP8LColorCache hashers;
|
VP8LColorCache hashers;
|
||||||
if (!hash_chain ||
|
if (!hash_chain ||
|
||||||
|
@ -217,35 +217,40 @@ static int GetBackwardReferences(int width, int height,
|
|||||||
VP8LHistogramEstimateBits(histo_lz77));
|
VP8LHistogramEstimateBits(histo_lz77));
|
||||||
|
|
||||||
// Choose appropriate backward reference.
|
// Choose appropriate backward reference.
|
||||||
if (quality >= 50 && lz77_is_useful) {
|
if (lz77_is_useful) {
|
||||||
|
// TraceBackwards is costly. Run it for higher qualities.
|
||||||
|
const int try_lz77_trace_backwards = (quality >= 75);
|
||||||
|
free(backward_refs_rle);
|
||||||
|
if (try_lz77_trace_backwards) {
|
||||||
const int recursion_level = (num_pix < 320 * 200) ? 1 : 0;
|
const int recursion_level = (num_pix < 320 * 200) ? 1 : 0;
|
||||||
int backward_refs_trace_size;
|
int backward_refs_trace_size;
|
||||||
PixOrCopy* backward_refs_trace;
|
PixOrCopy* backward_refs_trace;
|
||||||
free(backward_refs_rle);
|
|
||||||
free(backward_refs_lz77);
|
|
||||||
backward_refs_trace =
|
backward_refs_trace =
|
||||||
(PixOrCopy*)malloc(num_pix * sizeof(*backward_refs_trace));
|
(PixOrCopy*)malloc(num_pix * sizeof(*backward_refs_trace));
|
||||||
if (backward_refs_trace == NULL ||
|
if (backward_refs_trace == NULL) {
|
||||||
!VP8LBackwardReferencesTraceBackwards(width, height,
|
free(backward_refs_lz77);
|
||||||
recursion_level, use_color_cache,
|
|
||||||
argb, cache_bits,
|
|
||||||
backward_refs_trace,
|
|
||||||
&backward_refs_trace_size)) {
|
|
||||||
free(backward_refs_trace);
|
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
|
if (VP8LBackwardReferencesTraceBackwards(width, height, recursion_level,
|
||||||
|
use_color_cache, argb,
|
||||||
|
cache_bits, backward_refs_trace,
|
||||||
|
&backward_refs_trace_size)) {
|
||||||
|
free(backward_refs_lz77);
|
||||||
*backward_refs = backward_refs_trace;
|
*backward_refs = backward_refs_trace;
|
||||||
*backward_refs_size = backward_refs_trace_size;
|
*backward_refs_size = backward_refs_trace_size;
|
||||||
} else {
|
} else {
|
||||||
if (lz77_is_useful) {
|
free(backward_refs_trace);
|
||||||
*backward_refs = backward_refs_lz77;
|
*backward_refs = backward_refs_lz77;
|
||||||
*backward_refs_size = backward_refs_lz77_size;
|
*backward_refs_size = backward_refs_lz77_size;
|
||||||
free(backward_refs_rle);
|
}
|
||||||
} else {
|
} else {
|
||||||
|
*backward_refs = backward_refs_lz77;
|
||||||
|
*backward_refs_size = backward_refs_lz77_size;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
free(backward_refs_lz77);
|
||||||
*backward_refs = backward_refs_rle;
|
*backward_refs = backward_refs_rle;
|
||||||
*backward_refs_size = backward_refs_rle_size;
|
*backward_refs_size = backward_refs_rle_size;
|
||||||
free(backward_refs_lz77);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (use_2d_locality) {
|
if (use_2d_locality) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user