Run TraceBackwards for higher qualities.

Also reduce the iteration count in function VP8LHashChain_FindCopy.

Change-Id: I73e3811e142e81314515587fd655ab3bfa74d099
This commit is contained in:
Vikas Arora 2012-04-24 09:55:19 +00:00 committed by James Zern
parent 412222c88c
commit c6ac4dfbb4
2 changed files with 33 additions and 29 deletions

View File

@ -121,7 +121,7 @@ static int VP8LHashChain_FindCopy(VP8LHashChain* p,
const uint64_t hash_code = GetHash64(next_two_pixels);
int prev_length = 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;
int32_t pos;
int64_t length;
@ -134,8 +134,7 @@ static int VP8LHashChain_FindCopy(VP8LHashChain* p,
pos >= min_pos;
pos = p->chain_[pos]) {
if (give_up < 0) {
if (give_up < -quality * 8 ||
best_val >= 0xff0000) {
if (give_up < -quality * 2 || best_val >= 0xff0000) {
break;
}
}
@ -219,9 +218,9 @@ int VP8LBackwardReferencesHashChain(int xsize, int ysize, int use_palette,
const uint32_t* argb, int palette_bits,
int quality, PixOrCopy* stream,
int* stream_size) {
const int pix_count = xsize * ysize;
int i;
int ok = 0;
const int pix_count = xsize * ysize;
VP8LHashChain* hash_chain = (VP8LHashChain*)malloc(sizeof(*hash_chain));
VP8LColorCache hashers;
if (!hash_chain ||

View File

@ -217,35 +217,40 @@ static int GetBackwardReferences(int width, int height,
VP8LHistogramEstimateBits(histo_lz77));
// Choose appropriate backward reference.
if (quality >= 50 && lz77_is_useful) {
const int recursion_level = (num_pix < 320 * 200) ? 1 : 0;
int backward_refs_trace_size;
PixOrCopy* backward_refs_trace;
if (lz77_is_useful) {
// TraceBackwards is costly. Run it for higher qualities.
const int try_lz77_trace_backwards = (quality >= 75);
free(backward_refs_rle);
free(backward_refs_lz77);
backward_refs_trace =
(PixOrCopy*)malloc(num_pix * sizeof(*backward_refs_trace));
if (backward_refs_trace == NULL ||
!VP8LBackwardReferencesTraceBackwards(width, height,
recursion_level, use_color_cache,
argb, cache_bits,
backward_refs_trace,
&backward_refs_trace_size)) {
free(backward_refs_trace);
goto End;
}
*backward_refs = backward_refs_trace;
*backward_refs_size = backward_refs_trace_size;
} else {
if (lz77_is_useful) {
if (try_lz77_trace_backwards) {
const int recursion_level = (num_pix < 320 * 200) ? 1 : 0;
int backward_refs_trace_size;
PixOrCopy* backward_refs_trace;
backward_refs_trace =
(PixOrCopy*)malloc(num_pix * sizeof(*backward_refs_trace));
if (backward_refs_trace == NULL) {
free(backward_refs_lz77);
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_size = backward_refs_trace_size;
} else {
free(backward_refs_trace);
*backward_refs = backward_refs_lz77;
*backward_refs_size = backward_refs_lz77_size;
}
} else {
*backward_refs = backward_refs_lz77;
*backward_refs_size = backward_refs_lz77_size;
free(backward_refs_rle);
} else {
*backward_refs = backward_refs_rle;
*backward_refs_size = backward_refs_rle_size;
free(backward_refs_lz77);
}
} else {
free(backward_refs_lz77);
*backward_refs = backward_refs_rle;
*backward_refs_size = backward_refs_rle_size;
}
if (use_2d_locality) {