Make discarding invisible RGB values (cleanup alpha) the default.

Rename the flag to exact instead of the opposite cleanup_alpha. Add the flag to
WebPConfig. Do the cleanup in the webp encoder library rather than the cwebp
binary, this will be needed for the next stage: smarter alpha cleanup for
better compression which cannot be done as a preprocessing due to depending on
predictor choices in the encoder.

Change-Id: I2fbf57f918a35f2da6186ef0b5d85e5fd0020eef
This commit is contained in:
Lode Vandevenne
2015-11-16 13:14:57 +00:00
committed by James Zern
parent b37b0179c5
commit 1f9be97c22
6 changed files with 24 additions and 13 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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
};