mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-12 22:14:29 +02:00
add a -z option to cwebp, and WebPConfigLosslessPreset() function
These are presets for lossless coding, similar to zlib. The shortcut for lossless coding is now, e.g.: cwebp -z 5 in.png -o out_lossless.webp There are 10 possible values for -z parameter: 0 (fastest, lowest compression) to 9 (slowest, best compression) A reasonable tradeoff is -z 6, e.g. -z 9 can be quite slow, so use with care. This -z option is just a shortcut for some pre-defined '-lossless -m xx -q yy' combinations. Change-Id: I6ae716456456aea065469c916c2d5ca4d6c6cf04
This commit is contained in:
@ -568,6 +568,8 @@ static void HelpLong(void) {
|
||||
printf(" default, photo, picture,\n");
|
||||
printf(" drawing, icon, text\n");
|
||||
printf(" -preset must come first, as it overwrites other parameters.");
|
||||
printf(" -z <int> ............... Activates lossless preset with given "
|
||||
" level in [0:fast, ..., 9:slowest]\n");
|
||||
printf("\n");
|
||||
printf(" -m <int> ............... compression method (0=fast, 6=slowest)\n");
|
||||
printf(" -segments <int> ........ number of segments to use (1..4)\n");
|
||||
@ -672,6 +674,8 @@ int main(int argc, const char *argv[]) {
|
||||
uint32_t background_color = 0xffffffu;
|
||||
int crop = 0, crop_x = 0, crop_y = 0, crop_w = 0, crop_h = 0;
|
||||
int resize_w = 0, resize_h = 0;
|
||||
int lossless_preset = 6;
|
||||
int use_lossless_preset = -1; // -1=unset, 0=don't use, 1=use it
|
||||
int show_progress = 0;
|
||||
int keep_metadata = 0;
|
||||
int metadata_written = 0;
|
||||
@ -726,8 +730,13 @@ int main(int argc, const char *argv[]) {
|
||||
picture.height = strtol(argv[++c], NULL, 0);
|
||||
} else if (!strcmp(argv[c], "-m") && c < argc - 1) {
|
||||
config.method = strtol(argv[++c], NULL, 0);
|
||||
use_lossless_preset = 0; // disable -z option
|
||||
} else if (!strcmp(argv[c], "-q") && c < argc - 1) {
|
||||
config.quality = (float)strtod(argv[++c], NULL);
|
||||
use_lossless_preset = 0; // disable -z option
|
||||
} else if (!strcmp(argv[c], "-z") && c < argc - 1) {
|
||||
lossless_preset = strtol(argv[++c], NULL, 0);
|
||||
if (use_lossless_preset != 0) use_lossless_preset = 1;
|
||||
} else if (!strcmp(argv[c], "-alpha_q") && c < argc - 1) {
|
||||
config.alpha_quality = strtol(argv[++c], NULL, 0);
|
||||
} else if (!strcmp(argv[c], "-alpha_method") && c < argc - 1) {
|
||||
@ -916,6 +925,13 @@ int main(int argc, const char *argv[]) {
|
||||
goto Error;
|
||||
}
|
||||
|
||||
if (use_lossless_preset == 1) {
|
||||
if (!WebPConfigLosslessPreset(&config, lossless_preset)) {
|
||||
fprintf(stderr, "Invalid lossless preset (-z %d)\n", lossless_preset);
|
||||
goto Error;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for unsupported command line options for lossless mode and log
|
||||
// warning for such options.
|
||||
if (!quiet && config.lossless == 1) {
|
||||
|
Reference in New Issue
Block a user