AnimEncoder: Bugfix for kmin = 1 and kmax = 2.

SanitizeEncoderOptions() was changing kmin to 2 too, which resulted in a
bad state with kmin == kmax.

Change-Id: Ie7273f1949bac469e7e6c8efbc98b154caf6de0f
This commit is contained in:
Urvang Joshi 2015-01-23 10:48:59 -08:00
parent 0f027a72bf
commit 9a062b8ea6

View File

@ -122,16 +122,19 @@ static void SanitizeEncoderOptions(WebPAnimEncoderOptions* const enc_options) {
fprintf(stderr, "WARNING: Setting kmin = %d, so that kmin < kmax.\n",
(int)enc_options->kmin);
}
} else if (enc_options->kmin < (enc_options->kmax / 2 + 1)) {
} else {
const size_t kmin_limit = enc_options->kmax / 2 + 1;
if (enc_options->kmin < kmin_limit && kmin_limit < enc_options->kmax) {
// This ensures that enc.keyframe + kmin >= kmax is always true. So, we
// can flush all the frames in the 'count_since_key_frame == kmax' case.
enc_options->kmin = (enc_options->kmax / 2 + 1);
enc_options->kmin = kmin_limit;
if (print_warning) {
fprintf(stderr,
"WARNING: Setting kmin = %d, so that kmin >= kmax / 2 + 1.\n",
(int)enc_options->kmin);
}
}
}
// Limit the max number of frames that are allocated.
if (enc_options->kmax - enc_options->kmin > MAX_CACHED_FRAMES) {
enc_options->kmin = enc_options->kmax - MAX_CACHED_FRAMES;
@ -141,6 +144,7 @@ static void SanitizeEncoderOptions(WebPAnimEncoderOptions* const enc_options) {
(int)enc_options->kmin, MAX_CACHED_FRAMES);
}
}
assert(enc_options->kmin <= enc_options->kmax);
}
#undef MAX_CACHED_FRAMES