mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-26 13:48:21 +01:00
Use integers for kmin/kmax for simplicity.
Change-Id: I62237975d663641552107759af8d2d329b70a7c4
This commit is contained in:
parent
b9df35f714
commit
fe42739cc8
@ -158,10 +158,10 @@ int main(int argc, const char *argv[]) {
|
||||
} else if (!strcmp(argv[c], "-min_size")) {
|
||||
enc_options.minimize_size = 1;
|
||||
} else if (!strcmp(argv[c], "-kmax") && c < argc - 1) {
|
||||
enc_options.kmax = ExUtilGetUInt(argv[++c], 0, &parse_error);
|
||||
enc_options.kmax = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
default_kmax = 0;
|
||||
} else if (!strcmp(argv[c], "-kmin") && c < argc - 1) {
|
||||
enc_options.kmin = ExUtilGetUInt(argv[++c], 0, &parse_error);
|
||||
enc_options.kmin = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
default_kmin = 0;
|
||||
} else if (!strcmp(argv[c], "-f") && c < argc - 1) {
|
||||
config.filter_strength = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
|
@ -11,6 +11,7 @@
|
||||
//
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../utils/utils.h"
|
||||
@ -67,7 +68,7 @@ struct WebPAnimEncoder {
|
||||
// Can be negative in certain cases due to
|
||||
// transparent pixels in a frame.
|
||||
int keyframe_; // Index of selected key-frame relative to 'start_'.
|
||||
size_t count_since_key_frame_; // Frames seen since the last key-frame.
|
||||
int count_since_key_frame_; // Frames seen since the last key-frame.
|
||||
int prev_candidate_undecided_; // True if it's not yet decided if previous
|
||||
// frame would be a sub-frame or a key-frame.
|
||||
|
||||
@ -94,7 +95,7 @@ static void ResetCounters(WebPAnimEncoder* const enc) {
|
||||
}
|
||||
|
||||
static void DisableKeyframes(WebPAnimEncoderOptions* const enc_options) {
|
||||
enc_options->kmax = ~0;
|
||||
enc_options->kmax = INT_MAX;
|
||||
enc_options->kmin = enc_options->kmax - 1;
|
||||
}
|
||||
|
||||
@ -107,12 +108,13 @@ static void SanitizeEncoderOptions(WebPAnimEncoderOptions* const enc_options) {
|
||||
DisableKeyframes(enc_options);
|
||||
}
|
||||
|
||||
if (enc_options->kmin == 0) {
|
||||
if (enc_options->kmin <= 0) {
|
||||
DisableKeyframes(enc_options);
|
||||
print_warning = 0;
|
||||
}
|
||||
if (enc_options->kmax == 0) { // All frames will be key-frames.
|
||||
if (enc_options->kmax <= 0) { // All frames will be key-frames.
|
||||
enc_options->kmin = 0;
|
||||
enc_options->kmax = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -120,10 +122,10 @@ static void SanitizeEncoderOptions(WebPAnimEncoderOptions* const enc_options) {
|
||||
enc_options->kmin = enc_options->kmax - 1;
|
||||
if (print_warning) {
|
||||
fprintf(stderr, "WARNING: Setting kmin = %d, so that kmin < kmax.\n",
|
||||
(int)enc_options->kmin);
|
||||
enc_options->kmin);
|
||||
}
|
||||
} else {
|
||||
const size_t kmin_limit = enc_options->kmax / 2 + 1;
|
||||
const int 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.
|
||||
@ -131,7 +133,7 @@ static void SanitizeEncoderOptions(WebPAnimEncoderOptions* const enc_options) {
|
||||
if (print_warning) {
|
||||
fprintf(stderr,
|
||||
"WARNING: Setting kmin = %d, so that kmin >= kmax / 2 + 1.\n",
|
||||
(int)enc_options->kmin);
|
||||
enc_options->kmin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -141,7 +143,7 @@ static void SanitizeEncoderOptions(WebPAnimEncoderOptions* const enc_options) {
|
||||
if (print_warning) {
|
||||
fprintf(stderr,
|
||||
"WARNING: Setting kmin = %d, so that kmax - kmin <= %d.\n",
|
||||
(int)enc_options->kmin, MAX_CACHED_FRAMES);
|
||||
enc_options->kmin, MAX_CACHED_FRAMES);
|
||||
}
|
||||
}
|
||||
assert(enc_options->kmin < enc_options->kmax);
|
||||
|
@ -421,8 +421,8 @@ typedef struct {
|
||||
WebPMuxAnimParams anim_params; // Animation parameters.
|
||||
int minimize_size; // If true, minimize the output size (slow). Implicitly
|
||||
// disables key-frame insertion.
|
||||
size_t kmin;
|
||||
size_t kmax; // Minimum and maximum distance between consecutive key
|
||||
int kmin;
|
||||
int kmax; // Minimum and maximum distance between consecutive key
|
||||
// frames in the output. The library may insert some key
|
||||
// frames as needed to satisfy this criteria.
|
||||
// Note that these conditions should hold: kmax > kmin
|
||||
|
Loading…
Reference in New Issue
Block a user