diff --git a/README b/README index e9eeb5a5..42c09091 100644 --- a/README +++ b/README @@ -152,8 +152,6 @@ Options: default, photo, picture, drawing, icon, text -preset must come first, as it overwrites other parameters - -z ............... activates lossless preset with given - level in [0:fast, ..., 9:slowest] -m ............... compression method (0=fast, 6=slowest) -segments ........ number of segments to use (1..4) @@ -270,11 +268,9 @@ Use following options to convert into alternate image formats: -nofilter .... disable in-loop filtering -nodither .... disable dithering -dither .. dithering strength (in 0..100) - -alpha_dither use alpha-plane dithering if needed -mt .......... use multi-threading -crop ... crop output with the given rectangle -scale .......... scale the output (*after* any cropping) - -flip ........ flip the output vertically -alpha ....... only save the alpha plane -incremental . use incremental decoding (useful for tests) -h ....... this help message diff --git a/examples/cwebp.c b/examples/cwebp.c index d789c031..fc3302c3 100644 --- a/examples/cwebp.c +++ b/examples/cwebp.c @@ -573,8 +573,10 @@ static void HelpLong(void) { printf(" default, photo, picture,\n"); printf(" drawing, icon, text\n"); printf(" -preset must come first, as it overwrites other parameters\n"); +#if WEBP_ENCODER_ABI_VERSION > 0x0202 printf(" -z ............... activates lossless preset with given\n" " level in [0:fast, ..., 9:slowest]\n"); +#endif printf("\n"); printf(" -m ............... compression method (0=fast, 6=slowest)\n"); printf(" -segments ........ number of segments to use (1..4)\n"); @@ -676,8 +678,10 @@ 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; +#if WEBP_ENCODER_ABI_VERSION > 0x0202 int lossless_preset = 6; int use_lossless_preset = -1; // -1=unset, 0=don't use, 1=use it +#endif int show_progress = 0; int keep_metadata = 0; int metadata_written = 0; @@ -732,13 +736,17 @@ 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); +#if WEBP_ENCODER_ABI_VERSION > 0x0202 use_lossless_preset = 0; // disable -z option +#endif } else if (!strcmp(argv[c], "-q") && c < argc - 1) { config.quality = (float)strtod(argv[++c], NULL); +#if WEBP_ENCODER_ABI_VERSION > 0x0202 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; +#endif } 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) { @@ -919,12 +927,14 @@ int main(int argc, const char *argv[]) { goto Error; } +#if WEBP_ENCODER_ABI_VERSION > 0x0202 if (use_lossless_preset == 1) { if (!WebPConfigLosslessPreset(&config, lossless_preset)) { fprintf(stderr, "Invalid lossless preset (-z %d)\n", lossless_preset); goto Error; } } +#endif // Check for unsupported command line options for lossless mode and log // warning for such options. @@ -1116,7 +1126,11 @@ int main(int argc, const char *argv[]) { return_value = 0; Error: +#if WEBP_ENCODER_ABI_VERSION > 0x0202 WebPMemoryWriterClear(&memory_writer); +#else + free(memory_writer.mem); +#endif free(picture.extra_info); MetadataFree(&metadata); WebPPictureFree(&picture); diff --git a/examples/dwebp.c b/examples/dwebp.c index a37b05ed..a5ed60b0 100644 --- a/examples/dwebp.c +++ b/examples/dwebp.c @@ -557,11 +557,15 @@ static void Help(void) { " -nofilter .... disable in-loop filtering\n" " -nodither .... disable dithering\n" " -dither .. dithering strength (in 0..100)\n" +#if WEBP_DECODER_ABI_VERSION > 0x0203 " -alpha_dither use alpha-plane dithering if needed\n" +#endif " -mt .......... use multi-threading\n" " -crop ... crop output with the given rectangle\n" " -scale .......... scale the output (*after* any cropping)\n" +#if WEBP_DECODER_ABI_VERSION > 0x0203 " -flip ........ flip the output vertically\n" +#endif " -alpha ....... only save the alpha plane\n" " -incremental . use incremental decoding (useful for tests)\n" " -h ....... this help message\n" @@ -624,8 +628,10 @@ int main(int argc, const char *argv[]) { format = YUV; } else if (!strcmp(argv[c], "-mt")) { config.options.use_threads = 1; +#if WEBP_DECODER_ABI_VERSION > 0x0203 } else if (!strcmp(argv[c], "-alpha_dither")) { config.options.alpha_dithering_strength = 100; +#endif } else if (!strcmp(argv[c], "-nodither")) { config.options.dithering_strength = 0; } else if (!strcmp(argv[c], "-dither") && c < argc - 1) { @@ -640,8 +646,10 @@ int main(int argc, const char *argv[]) { config.options.use_scaling = 1; config.options.scaled_width = strtol(argv[++c], NULL, 0); config.options.scaled_height = strtol(argv[++c], NULL, 0); +#if WEBP_DECODER_ABI_VERSION > 0x0203 } else if (!strcmp(argv[c], "-flip")) { config.options.flip = 1; +#endif } else if (!strcmp(argv[c], "-v")) { verbose = 1; #ifndef WEBP_DLL diff --git a/examples/gif2webp_util.c b/examples/gif2webp_util.c index e2555f5f..697df0b4 100644 --- a/examples/gif2webp_util.c +++ b/examples/gif2webp_util.c @@ -475,10 +475,20 @@ static WebPEncodingError SetFrame(const WebPConfig* const config, // TODO(later): Perhaps a rough SSIM/PSNR produced by the encoder should // also be a criteria, in addition to sizes. if (mem1.size <= mem2.size) { +#if WEBP_ENCODER_ABI_VERSION > 0x0202 WebPMemoryWriterClear(&mem2); +#else + free(mem2.mem); + memset(&mem2, 0, sizeof(mem2)); +#endif GetEncodedData(&mem1, encoded_data); } else { +#if WEBP_ENCODER_ABI_VERSION > 0x0202 WebPMemoryWriterClear(&mem1); +#else + free(mem1.mem); + memset(&mem1, 0, sizeof(mem1)); +#endif GetEncodedData(&mem2, encoded_data); } } else { @@ -487,8 +497,13 @@ static WebPEncodingError SetFrame(const WebPConfig* const config, return error_code; Err: +#if WEBP_ENCODER_ABI_VERSION > 0x0202 WebPMemoryWriterClear(&mem1); WebPMemoryWriterClear(&mem2); +#else + free(mem1.mem); + free(mem2.mem); +#endif return error_code; } diff --git a/examples/vwebp.c b/examples/vwebp.c index 589f0832..c56ad40e 100644 --- a/examples/vwebp.c +++ b/examples/vwebp.c @@ -400,7 +400,9 @@ int main(int argc, char *argv[]) { return -1; } config->options.dithering_strength = 50; +#if WEBP_DECODER_ABI_VERSION > 0x0203 config->options.alpha_dithering_strength = 100; +#endif kParams.use_color_profile = 1; for (c = 1; c < argc; ++c) { @@ -413,8 +415,10 @@ int main(int argc, char *argv[]) { config->options.no_fancy_upsampling = 1; } else if (!strcmp(argv[c], "-nofilter")) { config->options.bypass_filtering = 1; +#if WEBP_DECODER_ABI_VERSION > 0x0203 } else if (!strcmp(argv[c], "-noalphadither")) { config->options.alpha_dithering_strength = 0; +#endif } else if (!strcmp(argv[c], "-dither") && c + 1 < argc) { config->options.dithering_strength = strtol(argv[++c], NULL, 0); } else if (!strcmp(argv[c], "-info")) { diff --git a/man/cwebp.1 b/man/cwebp.1 index f98fbc48..5aaf0fd5 100644 --- a/man/cwebp.1 +++ b/man/cwebp.1 @@ -1,5 +1,5 @@ .\" Hey, EMACS: -*- nroff -*- -.TH CWEBP 1 "April 19, 2014" +.TH CWEBP 1 "July 22, 2014" .SH NAME cwebp \- compress an image file to a WebP file .SH SYNOPSIS @@ -38,21 +38,22 @@ Print the version number (as major.minor.revision) and exit. .BI \-q " float Specify the compression factor for RGB channels between 0 and 100. The default is 75. -.TP -.BI \-z " int -Switch on \fBlossless\fP compression mode with the specified level between 0 -and 9, with level 0 being the fastest, 9 being the slowest. Fast mode -produces larger file size than slower ones. A good default is \-z 6. -This option is actually a shortcut for some predefined settings for quality -and method. If options \-q or \-m are subsequently used, they will invalidate -the effect of this \-z option. -.br -In case of lossy compression (default), a small factor produces a smaller file -with lower quality. Best quality is achieved by using a value of 100. -.br -In case of lossless compression (specified by the \-lossless option), a small -factor enables faster compression speed, but produces a larger file. Maximum -compression is achieved by using a value of 100. +.\" TODO(jzern): restore post-v0.4.1 +.\" .TP +.\" .BI \-z " int +.\" Switch on \fBlossless\fP compression mode with the specified level between 0 +.\" and 9, with level 0 being the fastest, 9 being the slowest. Fast mode +.\" produces larger file size than slower ones. A good default is \-z 6. +.\" This option is actually a shortcut for some predefined settings for quality +.\" and method. If options \-q or \-m are subsequently used, they will invalidate +.\" the effect of this \-z option. +.\" .br +.\" In case of lossy compression (default), a small factor produces a smaller file +.\" with lower quality. Best quality is achieved by using a value of 100. +.\" .br +.\" In case of lossless compression (specified by the \-lossless option), a small +.\" factor enables faster compression speed, but produces a larger file. Maximum +.\" compression is achieved by using a value of 100. .TP .BI \-alpha_q " int Specify the compression factor for alpha compression between 0 and 100. diff --git a/man/dwebp.1 b/man/dwebp.1 index 5741be6a..2393c0f5 100644 --- a/man/dwebp.1 +++ b/man/dwebp.1 @@ -1,5 +1,5 @@ .\" Hey, EMACS: -*- nroff -*- -.TH DWEBP 1 "June 13, 2014" +.TH DWEBP 1 "July 22, 2014" .SH NAME dwebp \- decompress a WebP file to an image file .SH SYNOPSIS @@ -67,11 +67,12 @@ but it will make the decoding faster. Specify a dithering \fBstrength\fP between 0 and 100. Dithering is a post-processing effect applied to chroma components in lossy compression. It helps by smoothing gradients and avoiding banding artifacts. -.TP -.BI \-alpha_dither -If the compressed file contains a transparency plane that was quantized -during compression, this flag will allow dithering the reconstructed plane -in order to generate smoother transparency gradients. +.\" TODO(jzern): restore post-v0.4.1 +.\" .TP +.\" .BI \-alpha_dither +.\" If the compressed file contains a transparency plane that was quantized +.\" during compression, this flag will allow dithering the reconstructed plane +.\" in order to generate smoother transparency gradients. .TP .B \-nodither Disable all dithering (default). @@ -86,9 +87,10 @@ This cropping area must be fully contained within the source rectangle. The top-left corner will be snapped to even coordinates if needed. This option is meant to reduce the memory needed for cropping large images. Note: the cropping is applied \fIbefore\fP any scaling. -.TP -.B \-flip -Flip decoded image vertically (can be useful for OpenGL textures for instance). +.\" TODO(jzern): restore post-v0.4.1 +.\" .TP +.\" .B \-flip +.\" Flip decoded image vertically (can be useful for OpenGL textures for instance). .TP .BI \-scale " width height Rescale the decoded picture to dimension \fBwidth\fP x \fBheight\fP. This diff --git a/src/dec/buffer.c b/src/dec/buffer.c index c6e4eb84..42feac74 100644 --- a/src/dec/buffer.c +++ b/src/dec/buffer.c @@ -195,10 +195,12 @@ VP8StatusCode WebPAllocateDecBuffer(int w, int h, status = AllocateBuffer(out); if (status != VP8_STATUS_OK) return status; +#if WEBP_DECODER_ABI_VERSION > 0x0203 // Use the stride trick if vertical flip is needed. if (options != NULL && options->flip) { status = WebPFlipBuffer(out); } +#endif return status; } diff --git a/src/dec/frame.c b/src/dec/frame.c index efe886b1..f7a0d1d8 100644 --- a/src/dec/frame.c +++ b/src/dec/frame.c @@ -177,6 +177,7 @@ void VP8InitDithering(const WebPDecoderOptions* const options, dec->dither_ = 1; } } +#if WEBP_DECODER_ABI_VERSION > 0x0203 // potentially allow alpha dithering dec->alpha_dithering_ = options->alpha_dithering_strength; if (dec->alpha_dithering_ > 100) { @@ -184,6 +185,7 @@ void VP8InitDithering(const WebPDecoderOptions* const options, } else if (dec->alpha_dithering_ < 0) { dec->alpha_dithering_ = 0; } +#endif } } diff --git a/src/dec/idec.c b/src/dec/idec.c index 6e8d5985..7bab1eab 100644 --- a/src/dec/idec.c +++ b/src/dec/idec.c @@ -240,15 +240,17 @@ static int CheckMemBufferMode(MemBuffer* const mem, MemBufferMode expected) { // To be called last. static VP8StatusCode FinishDecoding(WebPIDecoder* const idec) { +#if WEBP_DECODER_ABI_VERSION > 0x0203 const WebPDecoderOptions* const options = idec->params_.options; WebPDecBuffer* const output = idec->params_.output; idec->state_ = STATE_DONE; if (options != NULL && options->flip) { return WebPFlipBuffer(output); - } else { - return VP8_STATUS_OK; } +#endif + idec->state_ = STATE_DONE; + return VP8_STATUS_OK; } //------------------------------------------------------------------------------ diff --git a/src/dec/webp.c b/src/dec/webp.c index c76a704b..59e21a9d 100644 --- a/src/dec/webp.c +++ b/src/dec/webp.c @@ -521,9 +521,11 @@ static VP8StatusCode DecodeInto(const uint8_t* const data, size_t data_size, WebPFreeDecBuffer(params->output); } +#if WEBP_DECODER_ABI_VERSION > 0x0203 if (params->options != NULL && params->options->flip) { status = WebPFlipBuffer(params->output); } +#endif return status; } diff --git a/src/enc/config.c b/src/enc/config.c index 6531438f..4b7aa0f8 100644 --- a/src/enc/config.c +++ b/src/enc/config.c @@ -138,6 +138,7 @@ int WebPValidateConfig(const WebPConfig* config) { //------------------------------------------------------------------------------ +#if WEBP_ENCODER_ABI_VERSION > 0x0202 #define MAX_LEVEL 9 // Mapping between -z level and -m / -q parameter settings. @@ -156,5 +157,6 @@ int WebPConfigLosslessPreset(WebPConfig* config, int level) { config->quality = kLosslessPresets[level].quality_; return 1; } +#endif //------------------------------------------------------------------------------ diff --git a/src/enc/vp8enci.h b/src/enc/vp8enci.h index 5848e996..a08b8e3b 100644 --- a/src/enc/vp8enci.h +++ b/src/enc/vp8enci.h @@ -571,6 +571,10 @@ int WebPPictureAllocYUVA(WebPPicture* const picture, int width, int height); //------------------------------------------------------------------------------ +#if WEBP_ENCODER_ABI_VERSION <= 0x0202 +void WebPMemoryWriterClear(WebPMemoryWriter* writer); +#endif + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/webp/decode.h b/src/webp/decode.h index e0dd5703..36c27c37 100644 --- a/src/webp/decode.h +++ b/src/webp/decode.h @@ -20,7 +20,7 @@ extern "C" { #endif -#define WEBP_DECODER_ABI_VERSION 0x0205 // MAJOR(8b) + MINOR(8b) +#define WEBP_DECODER_ABI_VERSION 0x0203 // MAJOR(8b) + MINOR(8b) // Note: forward declaring enumerations is not allowed in (strict) C and C++, // the types are left here for reference. @@ -442,13 +442,19 @@ struct WebPDecoderOptions { int scaled_width, scaled_height; // final resolution int use_threads; // if true, use multi-threaded decoding int dithering_strength; // dithering strength (0=Off, 100=full) +#if WEBP_DECODER_ABI_VERSION > 0x0203 int flip; // flip output vertically int alpha_dithering_strength; // alpha dithering strength in [0..100] +#endif // Unused for now: int force_rotation; // forced rotation (to be applied _last_) int no_enhancement; // if true, discard enhancement layer +#if WEBP_DECODER_ABI_VERSION > 0x0203 uint32_t pad[3]; // padding for later use +#else + uint32_t pad[5]; // padding for later use +#endif }; // Main object storing the configuration for advanced decoding. diff --git a/src/webp/encode.h b/src/webp/encode.h index ccd2bd66..dd600568 100644 --- a/src/webp/encode.h +++ b/src/webp/encode.h @@ -20,7 +20,7 @@ extern "C" { #endif -#define WEBP_ENCODER_ABI_VERSION 0x0205 // MAJOR(8b) + MINOR(8b) +#define WEBP_ENCODER_ABI_VERSION 0x0202 // MAJOR(8b) + MINOR(8b) // Note: forward declaring enumerations is not allowed in (strict) C and C++, // the types are left here for reference. @@ -167,6 +167,7 @@ static WEBP_INLINE int WebPConfigPreset(WebPConfig* config, WEBP_ENCODER_ABI_VERSION); } +#if WEBP_ENCODER_ABI_VERSION > 0x0202 // Activate the lossless compression mode with the desired efficiency level // between 0 (fastest, lowest compression) and 9 (slower, best compression). // A good default level is '6', providing a fair tradeoff between compression @@ -174,6 +175,7 @@ static WEBP_INLINE int WebPConfigPreset(WebPConfig* config, // This function will overwrite several fields from config: 'method', 'quality' // and 'lossless'. Returns false in case of parameter error. WEBP_EXTERN(int) WebPConfigLosslessPreset(WebPConfig* config, int level); +#endif // Returns true if 'config' is non-NULL and all configuration parameters are // within their valid ranges. @@ -229,12 +231,18 @@ struct WebPMemoryWriter { // The following must be called first before any use. WEBP_EXTERN(void) WebPMemoryWriterInit(WebPMemoryWriter* writer); +#if WEBP_ENCODER_ABI_VERSION > 0x0202 // The following must be called to deallocate writer->mem memory. The 'writer' // object itself is not deallocated. WEBP_EXTERN(void) WebPMemoryWriterClear(WebPMemoryWriter* writer); +#endif // The custom writer to be used with WebPMemoryWriter as custom_ptr. Upon // completion, writer.mem and writer.size will hold the coded data. +#if WEBP_ENCODER_ABI_VERSION > 0x0202 // writer.mem must be freed by calling WebPMemoryWriterClear. +#else +// writer.mem must be freed by calling 'free(writer.mem)'. +#endif WEBP_EXTERN(int) WebPMemoryWrite(const uint8_t* data, size_t data_size, const WebPPicture* picture);