mirror of
https://github.com/webmproject/libwebp.git
synced 2025-02-13 15:32:53 +01:00
WebPAnimEncoder: choose max diff for framerect based on quality.
We pick a mapping with quality 0 mapping to max diff 32, to quality 100 mapping to max_diff 1. For 6k GIF image set, this improves compression by: 4% at quality 0 0.05% at quality 75 Benefits the MovingThumbnailer test videos too. Change-Id: I6838ce864d41e1e65311d26b9b8115a12390a253
This commit is contained in:
parent
ff0a94beda
commit
eb423903a4
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <math.h> // for pow()
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h> // for abs()
|
#include <stdlib.h> // for abs()
|
||||||
|
|
||||||
@ -400,6 +401,12 @@ static int IsEmptyRect(const FrameRect* const rect) {
|
|||||||
return (rect->width_ == 0) || (rect->height_ == 0);
|
return (rect->width_ == 0) || (rect->height_ == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int QualityToMaxDiff(float quality) {
|
||||||
|
const double val = pow(quality / 100., 0.5);
|
||||||
|
const double max_diff = 31 * (1 - val) + 1 * val;
|
||||||
|
return (int)(max_diff + 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
// Assumes that an initial valid guess of change rectangle 'rect' is passed.
|
// Assumes that an initial valid guess of change rectangle 'rect' is passed.
|
||||||
static void MinimizeChangeRectangle(const WebPPicture* const src,
|
static void MinimizeChangeRectangle(const WebPPicture* const src,
|
||||||
const WebPPicture* const dst,
|
const WebPPicture* const dst,
|
||||||
@ -408,10 +415,8 @@ static void MinimizeChangeRectangle(const WebPPicture* const src,
|
|||||||
int i, j;
|
int i, j;
|
||||||
const ComparePixelsFunc compare_pixels =
|
const ComparePixelsFunc compare_pixels =
|
||||||
is_lossless ? ComparePixelsLossless : ComparePixelsLossy;
|
is_lossless ? ComparePixelsLossless : ComparePixelsLossy;
|
||||||
// TODO(urvang): For lossy, pick max_allowed_diff based on quality.
|
const int max_allowed_diff_lossy = QualityToMaxDiff(quality);
|
||||||
const int max_allowed_diff_lossy = 0;
|
|
||||||
const int max_allowed_diff = is_lossless ? 0 : max_allowed_diff_lossy;
|
const int max_allowed_diff = is_lossless ? 0 : max_allowed_diff_lossy;
|
||||||
(void)quality;
|
|
||||||
|
|
||||||
// Sanity checks.
|
// Sanity checks.
|
||||||
assert(src->width == dst->width && src->height == dst->height);
|
assert(src->width == dst->width && src->height == dst->height);
|
||||||
@ -1335,6 +1340,10 @@ int WebPAnimEncoderAdd(WebPAnimEncoder* enc, WebPPicture* frame, int timestamp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (encoder_config != NULL) {
|
if (encoder_config != NULL) {
|
||||||
|
if (!WebPValidateConfig(encoder_config)) {
|
||||||
|
MarkError(enc, "ERROR adding frame: Invalid WebPConfig");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
config = *encoder_config;
|
config = *encoder_config;
|
||||||
} else {
|
} else {
|
||||||
WebPConfigInit(&config);
|
WebPConfigInit(&config);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user