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