diff --git a/README b/README index a686d1a1..6ff280c7 100644 --- a/README +++ b/README @@ -181,7 +181,7 @@ Options: -alpha_method .... transparency-compression method (0..1) -alpha_filter . predictive filtering for alpha plane, one of: none, fast (default) or best - -alpha_cleanup ......... clean RGB values in transparent area + -exact ................. preserve RGB values in transparent area -blend_alpha ..... blend colors against background color expressed as RGB values written in hexadecimal, e.g. 0xc0e0d0 for red=0xc0 diff --git a/examples/cwebp.c b/examples/cwebp.c index 84547278..d7f8a7c0 100644 --- a/examples/cwebp.c +++ b/examples/cwebp.c @@ -611,7 +611,8 @@ static void HelpLong(void) { printf(" -alpha_method .... transparency-compression method (0..1)\n"); printf(" -alpha_filter . predictive filtering for alpha plane,\n"); printf(" one of: none, fast (default) or best\n"); - printf(" -alpha_cleanup ......... clean RGB values in transparent area\n"); + printf(" -exact ................. preserve RGB values in transparent area" + "\n"); printf(" -blend_alpha ..... blend colors against background color\n" " expressed as RGB values written in\n" " hexadecimal, e.g. 0xc0e0d0 for red=0xc0\n" @@ -763,7 +764,10 @@ int main(int argc, const char *argv[]) { } else if (!strcmp(argv[c], "-alpha_method") && c < argc - 1) { config.alpha_compression = ExUtilGetInt(argv[++c], 0, &parse_error); } else if (!strcmp(argv[c], "-alpha_cleanup")) { - keep_alpha = keep_alpha ? 2 : 0; + // This flag is obsolete, does opposite of -exact. + config.exact = 0; + } else if (!strcmp(argv[c], "-exact")) { + config.exact = 1; } else if (!strcmp(argv[c], "-blend_alpha") && c < argc - 1) { blend_alpha = 1; // background color is given in hex with an optional '0x' prefix @@ -996,10 +1000,6 @@ int main(int argc, const char *argv[]) { WebPBlendAlpha(&picture, background_color); } - if (keep_alpha == 2) { - WebPCleanupTransparentArea(&picture); - } - if (verbose) { const double read_time = StopwatchReadAndReset(&stop_watch); fprintf(stderr, "Time to read input: %.3fs\n", read_time); diff --git a/man/cwebp.1 b/man/cwebp.1 index 8748c4f3..44e0dbaa 100644 --- a/man/cwebp.1 +++ b/man/cwebp.1 @@ -247,9 +247,9 @@ mode will just try to form an a priori guess without testing all modes. Specify the algorithm used for alpha compression: 0 or 1. Algorithm 0 denotes no compression, 1 uses WebP lossless format for compression. The default is 1. .TP -.B \-alpha_cleanup -Modify unseen RGB values under fully transparent area, to help compressibility. -The default is off. +.B \-exact +Preserve RGB values in transparent area. The default is off, to help +compressibility. .TP .BI \-blend_alpha " int This option blends the alpha channel (if present) with the source using the diff --git a/src/enc/config.c b/src/enc/config.c index 3c313e4d..f9f7961d 100644 --- a/src/enc/config.c +++ b/src/enc/config.c @@ -43,6 +43,7 @@ int WebPConfigInitInternal(WebPConfig* config, config->alpha_filtering = 1; config->alpha_quality = 100; config->lossless = 0; + config->exact = 0; config->image_hint = WEBP_HINT_DEFAULT; config->emulate_jpeg_size = 0; config->thread_level = 0; @@ -139,6 +140,8 @@ int WebPValidateConfig(const WebPConfig* config) { return 0; if (config->low_memory < 0 || config->low_memory > 1) return 0; + if (config->exact < 0 || config->exact > 1) + return 0; #ifdef WEBP_EXPERIMENTAL_FEATURES if (config->delta_palettization < 0 || config->delta_palettization > 1) return 0; diff --git a/src/enc/webpenc.c b/src/enc/webpenc.c index f9a17c39..8ced07a2 100644 --- a/src/enc/webpenc.c +++ b/src/enc/webpenc.c @@ -321,6 +321,10 @@ int WebPEncode(const WebPConfig* config, WebPPicture* pic) { if (pic->width > WEBP_MAX_DIMENSION || pic->height > WEBP_MAX_DIMENSION) return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION); + if (!config->exact) { + WebPCleanupTransparentArea(pic); + } + if (pic->stats != NULL) memset(pic->stats, 0, sizeof(*pic->stats)); if (!config->lossless) { diff --git a/src/webp/encode.h b/src/webp/encode.h index 020795fb..c382ea76 100644 --- a/src/webp/encode.h +++ b/src/webp/encode.h @@ -20,7 +20,7 @@ extern "C" { #endif -#define WEBP_ENCODER_ABI_VERSION 0x0208 // MAJOR(8b) + MINOR(8b) +#define WEBP_ENCODER_ABI_VERSION 0x0209 // MAJOR(8b) + MINOR(8b) // Note: forward declaring enumerations is not allowed in (strict) C and C++, // the types are left here for reference. @@ -136,12 +136,16 @@ struct WebPConfig { int near_lossless; // Near lossless encoding [0 = off(default) .. 100]. // This feature is experimental. + int exact; // if non-zero, preserve the exact RGB values under + // transparent area. Otherwise, discard this invisible + // RGB information for better compression. The default + // value is 0. #ifdef WEBP_EXPERIMENTAL_FEATURES int delta_palettization; - uint32_t pad[3]; // padding for later use + uint32_t pad[2]; // padding for later use #else - uint32_t pad[4]; // padding for later use + uint32_t pad[3]; // padding for later use #endif // WEBP_EXPERIMENTAL_FEATURES };