Update WebP encoder (cwebp) to support Alpha.

Updated cwebp (Webp Encoder) binary to support Alpha encoding.
Modified man page and WebP container spec appropriately.

Change-Id: I52f6a5cb3e870c386591e9a7776293fa6a8fb04b
This commit is contained in:
Vikas Arora 2011-12-01 15:11:34 +05:30
parent 667b769aee
commit a0ec9aace9
3 changed files with 27 additions and 28 deletions

View File

@ -526,7 +526,7 @@ The contents of such a chunk are as follows:
* 0 --> No compression
* 1 --> Zlib compression.
* 1 --> Backward reference counts encoded with arithmetic encoder.
* Byte 1: _Reserved_. **Should** be 0.

View File

@ -199,11 +199,6 @@ static HRESULT ReadPictureWithWIC(const char* filename,
// WebP conversion.
if (SUCCEEDED(hr)) {
int ok;
#ifdef WEBP_EXPERIMENTAL_FEATURES
if (has_alpha) {
pic->colorspace |= WEBP_CSP_ALPHA_BIT;
}
#endif
pic->width = width;
pic->height = height;
ok = has_alpha ? WebPPictureImportRGBA(pic, rgb, stride)
@ -400,11 +395,6 @@ static int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha) {
png_set_strip_alpha(png);
has_alpha = 0;
}
#ifdef WEBP_EXPERIMENTAL_FEATURES
if (has_alpha) {
pic->colorspace |= WEBP_CSP_ALPHA_BIT;
}
#endif
num_passes = png_set_interlace_handling(png);
png_read_update_info(png, info);
@ -671,6 +661,8 @@ static void HelpLong(void) {
printf(" -h / -help ............ short help\n");
printf(" -H / -longhelp ........ long help\n");
printf(" -q <float> ............. quality factor (0:small..100:big)\n");
printf(" -alpha_q <int> ......... Transparency-compression quality "
"(0..100).\n");
printf(" -preset <string> ....... Preset setting, one of:\n");
printf(" default, photo, picture,\n");
printf(" drawing, icon, text\n");
@ -690,10 +682,6 @@ static void HelpLong(void) {
printf(" -partition_limit <int> . limit quality to fit the 512k limit on\n");
printf(" "
"the first partition (0=no degradation ... 100=full)\n");
#ifdef WEBP_EXPERIMENTAL_FEATURES
printf(" -alpha_comp <int> ...... set the transparency-compression\n");
printf(" -noalpha ............... discard any transparency information.\n");
#endif
printf(" -pass <int> ............ analysis pass number (1..10)\n");
printf(" -crop <x> <y> <w> <h> .. crop picture with the given rectangle\n");
printf(" -resize <w> <h> ........ resize picture (after any cropping)\n");
@ -702,6 +690,8 @@ static void HelpLong(void) {
#endif
printf(" -map <int> ............. print map of extra info.\n");
printf(" -d <file.pgm> .......... dump the compressed output (PGM file).\n");
printf(" -alpha_method <int> .... Transparency-compression method (0..1)\n");
printf(" -noalpha ............... discard any transparency information.\n");
printf("\n");
printf(" -short ................. condense printed message\n");
@ -748,7 +738,7 @@ int main(int argc, const char *argv[]) {
int c;
int short_output = 0;
int quiet = 0;
int keep_alpha = 0;
int keep_alpha = 1;
int crop = 0, crop_x = 0, crop_y = 0, crop_w = 0, crop_h = 0;
int resize_w = 0, resize_h = 0;
WebPPicture picture;
@ -756,10 +746,6 @@ int main(int argc, const char *argv[]) {
WebPAuxStats stats;
Stopwatch stop_watch;
#ifdef WEBP_EXPERIMENTAL_FEATURES
keep_alpha = 1;
#endif
if (!WebPPictureInit(&picture) || !WebPConfigInit(&config)) {
fprintf(stderr, "Error! Version mismatch!\n");
goto Error;
@ -791,6 +777,12 @@ int main(int argc, const char *argv[]) {
config.method = strtol(argv[++c], NULL, 0);
} else if (!strcmp(argv[c], "-q") && c < argc - 1) {
config.quality = (float)strtod(argv[++c], NULL);
} 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) {
config.alpha_compression = strtol(argv[++c], NULL, 0);
} else if (!strcmp(argv[c], "-noalpha")) {
keep_alpha = 0;
} else if (!strcmp(argv[c], "-size") && c < argc - 1) {
config.target_size = strtol(argv[++c], NULL, 0);
} else if (!strcmp(argv[c], "-psnr") && c < argc - 1) {
@ -813,12 +805,6 @@ int main(int argc, const char *argv[]) {
config.segments = strtol(argv[++c], NULL, 0);
} else if (!strcmp(argv[c], "-partition_limit") && c < argc - 1) {
config.partition_limit = strtol(argv[++c], NULL, 0);
#ifdef WEBP_EXPERIMENTAL_FEATURES
} else if (!strcmp(argv[c], "-alpha_comp") && c < argc - 1) {
config.alpha_compression = strtol(argv[++c], NULL, 0);
} else if (!strcmp(argv[c], "-noalpha")) {
keep_alpha = 0;
#endif
} else if (!strcmp(argv[c], "-map") && c < argc - 1) {
picture.extra_info_type = strtol(argv[++c], NULL, 0);
#ifdef WEBP_EXPERIMENTAL_FEATURES

View File

@ -32,10 +32,15 @@ A summary of all the possible options.
Print the version number (as major.minor.revision) and exit.
.TP
.B \-q float
Specify the compression factor between 0 and 100. A small factor
produces a smaller file with lower quality. Best quality is achieved
Specify the compression factor for RGB channels between 0 and 100. A small
factor produces a smaller file with lower quality. Best quality is achieved
using a value of 100. The default is 75.
.TP
.B \-alpha_q int
Specify the compression factor for alpha compression between 0 and 100.
Lossless compression of alpha is achieved using a value of 100, while the lower
values result in a lossy compression. The default is 100.
.TP
.B \-f int
Specify the strength of the deblocking filter, between 0 (no filtering)
and 100 (maximum filtering). A value of 0 will turn off any filtering.
@ -137,6 +142,14 @@ range from 1 to 6. This is only meant to help debugging.
Specify a pre-processing filter. This option is a placeholder
and has currently no effect.
.TP
.B \-alpha_method int
Specify the algorithm used for alpha compression: 0 or 1. Algorithm 0 denotes
no compression, 1 uses uses backward reference counts encoded with arithmetic
encoder. The default is 1.
.TP
.B \-noalpha
Using this option will discard the alpha channel.
.TP
.B \-noasm
Disable all assembly optimizations.
.TP