mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 06:24:27 +02:00
gif2webp: Add a mixed compression mode
When '-mixed' option is given, each frame would be heuristically chosen to be encoded using lossy or lossless compression. The heuristic is based on the number of colors in the image: - If num_colors <= 31, pick lossless compression - If num_colors >= 194, pick lossy compression - Otherwise, try both and pick the one that compresses better. Change-Id: I908c73493ddc38e8db35b7b1959300569e6d3a97
This commit is contained in:
@ -212,6 +212,8 @@ static void Help(void) {
|
||||
printf("options:\n");
|
||||
printf(" -h / -help ............ this help\n");
|
||||
printf(" -lossy ................. Encode image using lossy compression.\n");
|
||||
printf(" -mixed ................. For each frame in the image, pick lossy\n"
|
||||
" or lossless compression heuristically.\n");
|
||||
printf(" -q <float> ............. quality factor (0:small..100:big)\n");
|
||||
printf(" -m <int> ............... compression method (0=fast, 6=slowest)\n");
|
||||
printf(" -kmin <int> ............ Min distance between key frames\n");
|
||||
@ -253,6 +255,7 @@ int main(int argc, const char *argv[]) {
|
||||
int default_kmax = 1;
|
||||
size_t kmin = 0;
|
||||
size_t kmax = 0;
|
||||
int allow_mixed = 0; // If true, each frame can be lossy or lossless.
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
info.id = WEBP_CHUNK_ANMF;
|
||||
@ -279,6 +282,9 @@ int main(int argc, const char *argv[]) {
|
||||
out_file = argv[++c];
|
||||
} else if (!strcmp(argv[c], "-lossy")) {
|
||||
config.lossless = 0;
|
||||
} else if (!strcmp(argv[c], "-mixed")) {
|
||||
allow_mixed = 1;
|
||||
config.lossless = 0;
|
||||
} else if (!strcmp(argv[c], "-q") && c < argc - 1) {
|
||||
config.quality = (float)strtod(argv[++c], NULL);
|
||||
} else if (!strcmp(argv[c], "-m") && c < argc - 1) {
|
||||
@ -348,7 +354,7 @@ int main(int argc, const char *argv[]) {
|
||||
if (!WebPPictureAlloc(&frame)) goto End;
|
||||
|
||||
// Initialize cache
|
||||
cache = WebPFrameCacheNew(frame.width, frame.height, kmin, kmax);
|
||||
cache = WebPFrameCacheNew(frame.width, frame.height, kmin, kmax, allow_mixed);
|
||||
if (cache == NULL) goto End;
|
||||
|
||||
mux = WebPMuxNew();
|
||||
|
Reference in New Issue
Block a user