2012-01-06 23:49:06 +01:00
|
|
|
// Copyright 2011 Google Inc. All Rights Reserved.
|
2011-02-19 08:33:46 +01:00
|
|
|
//
|
|
|
|
// This code is licensed under the same terms as WebM:
|
|
|
|
// Software License Agreement: http://www.webmproject.org/license/software/
|
|
|
|
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Coding tools configuration
|
|
|
|
//
|
|
|
|
// Author: Skal (pascal.massimino@gmail.com)
|
|
|
|
|
2011-05-03 02:19:00 +02:00
|
|
|
#include "../webp/encode.h"
|
2011-02-19 08:33:46 +01:00
|
|
|
|
2011-03-10 06:25:53 +01:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2011-08-25 23:22:32 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2011-02-19 08:33:46 +01:00
|
|
|
// WebPConfig
|
2011-08-25 23:22:32 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2011-02-19 08:33:46 +01:00
|
|
|
|
2012-07-18 00:01:30 +02:00
|
|
|
int WebPConfigInitInternal(WebPConfig* config,
|
2011-02-19 08:33:46 +01:00
|
|
|
WebPPreset preset, float quality, int version) {
|
2012-07-19 07:24:33 +02:00
|
|
|
if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_ENCODER_ABI_VERSION)) {
|
2011-02-19 08:33:46 +01:00
|
|
|
return 0; // caller/system version mismatch!
|
|
|
|
}
|
|
|
|
if (config == NULL) return 0;
|
|
|
|
|
|
|
|
config->quality = quality;
|
|
|
|
config->target_size = 0;
|
|
|
|
config->target_PSNR = 0.;
|
|
|
|
config->method = 4;
|
|
|
|
config->sns_strength = 50;
|
|
|
|
config->filter_strength = 20; // default: light filtering
|
|
|
|
config->filter_sharpness = 0;
|
|
|
|
config->filter_type = 0; // default: simple
|
|
|
|
config->partitions = 0;
|
|
|
|
config->segments = 4;
|
|
|
|
config->pass = 1;
|
|
|
|
config->show_compressed = 0;
|
|
|
|
config->preprocessing = 0;
|
|
|
|
config->autofilter = 0;
|
2011-08-24 00:58:22 +02:00
|
|
|
config->partition_limit = 0;
|
2011-12-01 07:44:15 +01:00
|
|
|
config->alpha_compression = 1;
|
2012-01-09 04:27:21 +01:00
|
|
|
config->alpha_filtering = 1;
|
2011-12-01 07:44:15 +01:00
|
|
|
config->alpha_quality = 100;
|
2012-03-28 13:07:42 +02:00
|
|
|
config->lossless = 0;
|
2012-06-22 08:44:48 +02:00
|
|
|
config->image_hint = WEBP_HINT_DEFAULT;
|
2011-02-19 08:33:46 +01:00
|
|
|
|
|
|
|
// TODO(skal): tune.
|
|
|
|
switch (preset) {
|
|
|
|
case WEBP_PRESET_PICTURE:
|
|
|
|
config->sns_strength = 80;
|
|
|
|
config->filter_sharpness = 4;
|
|
|
|
config->filter_strength = 35;
|
|
|
|
break;
|
|
|
|
case WEBP_PRESET_PHOTO:
|
|
|
|
config->sns_strength = 80;
|
|
|
|
config->filter_sharpness = 3;
|
|
|
|
config->filter_strength = 30;
|
|
|
|
break;
|
|
|
|
case WEBP_PRESET_DRAWING:
|
|
|
|
config->sns_strength = 25;
|
|
|
|
config->filter_sharpness = 6;
|
|
|
|
config->filter_strength = 10;
|
|
|
|
break;
|
|
|
|
case WEBP_PRESET_ICON:
|
|
|
|
config->sns_strength = 0;
|
|
|
|
config->filter_strength = 0; // disable filtering to retain sharpness
|
|
|
|
break;
|
|
|
|
case WEBP_PRESET_TEXT:
|
|
|
|
config->sns_strength = 0;
|
|
|
|
config->filter_strength = 0; // disable filtering to retain sharpness
|
|
|
|
config->segments = 2;
|
|
|
|
break;
|
|
|
|
case WEBP_PRESET_DEFAULT:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return WebPValidateConfig(config);
|
|
|
|
}
|
|
|
|
|
2012-07-18 00:01:30 +02:00
|
|
|
int WebPValidateConfig(const WebPConfig* config) {
|
2011-02-19 08:33:46 +01:00
|
|
|
if (config == NULL) return 0;
|
|
|
|
if (config->quality < 0 || config->quality > 100)
|
|
|
|
return 0;
|
|
|
|
if (config->target_size < 0)
|
|
|
|
return 0;
|
|
|
|
if (config->target_PSNR < 0)
|
|
|
|
return 0;
|
|
|
|
if (config->method < 0 || config->method > 6)
|
|
|
|
return 0;
|
|
|
|
if (config->segments < 1 || config->segments > 4)
|
|
|
|
return 0;
|
|
|
|
if (config->sns_strength < 0 || config->sns_strength > 100)
|
|
|
|
return 0;
|
|
|
|
if (config->filter_strength < 0 || config->filter_strength > 100)
|
|
|
|
return 0;
|
|
|
|
if (config->filter_sharpness < 0 || config->filter_sharpness > 7)
|
|
|
|
return 0;
|
|
|
|
if (config->filter_type < 0 || config->filter_type > 1)
|
|
|
|
return 0;
|
|
|
|
if (config->autofilter < 0 || config->autofilter > 1)
|
|
|
|
return 0;
|
|
|
|
if (config->pass < 1 || config->pass > 10)
|
|
|
|
return 0;
|
|
|
|
if (config->show_compressed < 0 || config->show_compressed > 1)
|
|
|
|
return 0;
|
|
|
|
if (config->preprocessing < 0 || config->preprocessing > 1)
|
|
|
|
return 0;
|
|
|
|
if (config->partitions < 0 || config->partitions > 3)
|
|
|
|
return 0;
|
2011-08-24 00:58:22 +02:00
|
|
|
if (config->partition_limit < 0 || config->partition_limit > 100)
|
|
|
|
return 0;
|
EXPERIMENTAL: add support for alpha channel
This is a (minor) bitstream change: if the 'color_space' bit is set to '1'
(which is normally an undefined/invalid behaviour), we add extra data at the
end of partition #0 (so-called 'extensions')
Namely, we add the size of the extension data as 3 bytes (little-endian),
followed by a set of bits telling which extensions we're incorporating.
The data then _preceeds_ this trailing tags.
This is all experimental, and you'll need to have
'#define WEBP_EXPERIMENTAL_FEATURES' in webp/types.h to enable this code
(at your own risk! :))
Still, this hack produces almost-valid WebP file for decoders that don't
check this color_space bit. In particular, previous 'dwebp' (and for instance
Chrome) will recognize this files and decode them, but without the alpha
of course. Other decoder will just see random extra stuff at the end of
partition #0.
To experiment with the alpha-channel, you need to compile on Unix platform
and use PNGs for input/output.
If 'alpha.png' is a source with alpha channel, then you can try (on Unix):
cwebp alpha.png -o alpha.webp
dwebp alpha.webp -o test.png
cwebp now has a '-noalpha' flag to ignore any alpha information from the
source, if present.
More hacking and experimenting welcome!
Change-Id: I3c7b1fd8411c9e7a9f77690e898479ad85c52f3e
2011-04-26 01:58:04 +02:00
|
|
|
if (config->alpha_compression < 0)
|
|
|
|
return 0;
|
2012-01-05 08:34:30 +01:00
|
|
|
if (config->alpha_filtering < 0)
|
|
|
|
return 0;
|
2011-12-01 07:44:15 +01:00
|
|
|
if (config->alpha_quality < 0 || config->alpha_quality > 100)
|
2011-12-01 22:05:31 +01:00
|
|
|
return 0;
|
2012-03-28 13:07:42 +02:00
|
|
|
if (config->lossless < 0 || config->lossless > 1)
|
|
|
|
return 0;
|
2012-06-22 08:44:48 +02:00
|
|
|
if (config->image_hint > WEBP_HINT_PHOTO)
|
|
|
|
return 0;
|
2011-02-19 08:33:46 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-08-25 23:22:32 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2011-03-10 06:25:53 +01:00
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|