mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-20 04:18:26 +01:00
Speedup TrellisQuantizeBlock().
-Skip examining quantized levels that are too high. -Calculate last_pos_cost only when needed. Encoding speed for m6 is increased by about 3%; Compression performance is neutral. Change-Id: I8af70b049587cca0375d9b3eb00479ec7c0c842a
This commit is contained in:
parent
573cce270e
commit
a2fe9bf404
@ -643,6 +643,8 @@ static int TrellisQuantizeBlock(const VP8Encoder* const enc,
|
||||
const int sign = (in[j] < 0);
|
||||
const uint32_t coeff0 = (sign ? -in[j] : in[j]) + mtx->sharpen_[j];
|
||||
int level0 = QUANTDIV(coeff0, iQ, B);
|
||||
int thresh_level = QUANTDIV(coeff0, iQ, BIAS(0x80));
|
||||
if (thresh_level > MAX_LEVEL) thresh_level = MAX_LEVEL;
|
||||
if (level0 > MAX_LEVEL) level0 = MAX_LEVEL;
|
||||
|
||||
{ // Swap current and previous score states
|
||||
@ -657,23 +659,17 @@ static int TrellisQuantizeBlock(const VP8Encoder* const enc,
|
||||
int level = level0 + m;
|
||||
const int ctx = (level > 2) ? 2 : level;
|
||||
const int band = VP8EncBands[n + 1];
|
||||
score_t base_score, last_pos_score;
|
||||
score_t base_score;
|
||||
score_t best_cur_score = MAX_COST;
|
||||
int best_prev = 0; // default, in case
|
||||
|
||||
ss_cur[m].score = MAX_COST;
|
||||
ss_cur[m].costs = costs[n + 1][ctx];
|
||||
if (level > MAX_LEVEL || level < 0) { // node is dead?
|
||||
if (level < 0 || level > thresh_level) {
|
||||
// Node is dead.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Compute extra rate cost if last coeff's position is < 15
|
||||
{
|
||||
const score_t last_pos_cost =
|
||||
(n < 15) ? VP8BitCost(0, probas[band][ctx][0]) : 0;
|
||||
last_pos_score = RDScoreTrellis(lambda, last_pos_cost, 0);
|
||||
}
|
||||
|
||||
{
|
||||
// Compute delta_error = how much coding this level will
|
||||
// subtract to max_error as distortion.
|
||||
@ -705,6 +701,9 @@ static int TrellisQuantizeBlock(const VP8Encoder* const enc,
|
||||
|
||||
// Now, record best terminal node (and thus best entry in the graph).
|
||||
if (level != 0) {
|
||||
const score_t last_pos_cost =
|
||||
(n < 15) ? VP8BitCost(0, probas[band][ctx][0]) : 0;
|
||||
const score_t last_pos_score = RDScoreTrellis(lambda, last_pos_cost, 0);
|
||||
const score_t score = best_cur_score + last_pos_score;
|
||||
if (score < best_score) {
|
||||
best_score = score;
|
||||
|
Loading…
Reference in New Issue
Block a user