mirror of
https://github.com/webmproject/libwebp.git
synced 2025-02-13 07:22:52 +01:00
Speedup AnalyzeAndInit for low effort compression.
AnalyzeSubtractGreen constitutes about 8-10% of the comression CPU cycles. Statistically, subtract-green is proved to be useful for most of the non-palette compression. So instead of evaluating the entropy (by calling AnalyzeSubtractGreen) apply subtract-green transform for the low-effort compression. This changes speeds up the compression at m=0 by 8-10% (with very slight loss of 0.07% in the compression density). Change-Id: I9797dc39437ae089716acb14631bbc77d367acf4
This commit is contained in:
parent
a6597483af
commit
72831f6b28
@ -305,7 +305,9 @@ static int AnalyzeAndInit(VP8LEncoder* const enc, WebPImageHint image_hint) {
|
|||||||
const int method = config->method;
|
const int method = config->method;
|
||||||
const int low_effort = (config->method == 0);
|
const int low_effort = (config->method == 0);
|
||||||
const float quality = config->quality;
|
const float quality = config->quality;
|
||||||
double subtract_green_score = 10.f;
|
double subtract_green_score = 10.0;
|
||||||
|
const double subtract_green_threshold_palette = 0.80;
|
||||||
|
const double subtract_green_threshold_non_palette = 1.0;
|
||||||
// we round the block size up, so we're guaranteed to have
|
// we round the block size up, so we're guaranteed to have
|
||||||
// at max MAX_REFS_BLOCK_PER_IMAGE blocks used:
|
// at max MAX_REFS_BLOCK_PER_IMAGE blocks used:
|
||||||
int refs_block_size = (pix_cnt - 1) / MAX_REFS_BLOCK_PER_IMAGE + 1;
|
int refs_block_size = (pix_cnt - 1) / MAX_REFS_BLOCK_PER_IMAGE + 1;
|
||||||
@ -316,11 +318,18 @@ static int AnalyzeAndInit(VP8LEncoder* const enc, WebPImageHint image_hint) {
|
|||||||
|
|
||||||
if (!enc->use_palette_ ||
|
if (!enc->use_palette_ ||
|
||||||
EvalSubtractGreenForPalette(enc->palette_size_, quality)) {
|
EvalSubtractGreenForPalette(enc->palette_size_, quality)) {
|
||||||
|
if (low_effort) {
|
||||||
|
// For low effort compression, avoid calling (costly) method
|
||||||
|
// AnalyzeSubtractGreen and enable the subtract-green transform
|
||||||
|
// for non-palette images.
|
||||||
|
subtract_green_score = subtract_green_threshold_non_palette * 0.99;
|
||||||
|
} else {
|
||||||
if (!AnalyzeSubtractGreen(pic->argb, width, height,
|
if (!AnalyzeSubtractGreen(pic->argb, width, height,
|
||||||
&subtract_green_score)) {
|
&subtract_green_score)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Evaluate histogram bits based on the original value of use_palette flag.
|
// Evaluate histogram bits based on the original value of use_palette flag.
|
||||||
enc->histo_bits_ = GetHistoBits(method, enc->use_palette_, pic->width,
|
enc->histo_bits_ = GetHistoBits(method, enc->use_palette_, pic->width,
|
||||||
@ -330,13 +339,13 @@ static int AnalyzeAndInit(VP8LEncoder* const enc, WebPImageHint image_hint) {
|
|||||||
enc->use_subtract_green_ = 0;
|
enc->use_subtract_green_ = 0;
|
||||||
if (enc->use_palette_) {
|
if (enc->use_palette_) {
|
||||||
// Check if other transforms (subtract green etc) are potentially better.
|
// Check if other transforms (subtract green etc) are potentially better.
|
||||||
if (subtract_green_score < 0.80f) {
|
if (subtract_green_score < subtract_green_threshold_palette) {
|
||||||
enc->use_subtract_green_ = 1;
|
enc->use_subtract_green_ = 1;
|
||||||
enc->use_palette_ = 0;
|
enc->use_palette_ = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Non-palette case, check if subtract-green optimizes the entropy.
|
// Non-palette case, check if subtract-green optimizes the entropy.
|
||||||
if (subtract_green_score < 1.0f) {
|
if (subtract_green_score < subtract_green_threshold_non_palette) {
|
||||||
enc->use_subtract_green_ = 1;
|
enc->use_subtract_green_ = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user