mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 06:08:21 +01:00
restore decode API compatibility
protect flip/alpha_dither w/a WEBP_DECODER_ABI_VERSION check Change-Id: I437a5d5f78800f71b7e7e323faa321f946bf9515
This commit is contained in:
parent
d2cc61b7dd
commit
793368e8c6
2
README
2
README
@ -270,11 +270,9 @@ Use following options to convert into alternate image formats:
|
|||||||
-nofilter .... disable in-loop filtering
|
-nofilter .... disable in-loop filtering
|
||||||
-nodither .... disable dithering
|
-nodither .... disable dithering
|
||||||
-dither <d> .. dithering strength (in 0..100)
|
-dither <d> .. dithering strength (in 0..100)
|
||||||
-alpha_dither use alpha-plane dithering if needed
|
|
||||||
-mt .......... use multi-threading
|
-mt .......... use multi-threading
|
||||||
-crop <x> <y> <w> <h> ... crop output with the given rectangle
|
-crop <x> <y> <w> <h> ... crop output with the given rectangle
|
||||||
-scale <w> <h> .......... scale the output (*after* any cropping)
|
-scale <w> <h> .......... scale the output (*after* any cropping)
|
||||||
-flip ........ flip the output vertically
|
|
||||||
-alpha ....... only save the alpha plane
|
-alpha ....... only save the alpha plane
|
||||||
-incremental . use incremental decoding (useful for tests)
|
-incremental . use incremental decoding (useful for tests)
|
||||||
-h ....... this help message
|
-h ....... this help message
|
||||||
|
@ -557,11 +557,15 @@ static void Help(void) {
|
|||||||
" -nofilter .... disable in-loop filtering\n"
|
" -nofilter .... disable in-loop filtering\n"
|
||||||
" -nodither .... disable dithering\n"
|
" -nodither .... disable dithering\n"
|
||||||
" -dither <d> .. dithering strength (in 0..100)\n"
|
" -dither <d> .. dithering strength (in 0..100)\n"
|
||||||
|
#if WEBP_DECODER_ABI_VERSION > 0x0203
|
||||||
" -alpha_dither use alpha-plane dithering if needed\n"
|
" -alpha_dither use alpha-plane dithering if needed\n"
|
||||||
|
#endif
|
||||||
" -mt .......... use multi-threading\n"
|
" -mt .......... use multi-threading\n"
|
||||||
" -crop <x> <y> <w> <h> ... crop output with the given rectangle\n"
|
" -crop <x> <y> <w> <h> ... crop output with the given rectangle\n"
|
||||||
" -scale <w> <h> .......... scale the output (*after* any cropping)\n"
|
" -scale <w> <h> .......... scale the output (*after* any cropping)\n"
|
||||||
|
#if WEBP_DECODER_ABI_VERSION > 0x0203
|
||||||
" -flip ........ flip the output vertically\n"
|
" -flip ........ flip the output vertically\n"
|
||||||
|
#endif
|
||||||
" -alpha ....... only save the alpha plane\n"
|
" -alpha ....... only save the alpha plane\n"
|
||||||
" -incremental . use incremental decoding (useful for tests)\n"
|
" -incremental . use incremental decoding (useful for tests)\n"
|
||||||
" -h ....... this help message\n"
|
" -h ....... this help message\n"
|
||||||
@ -624,8 +628,10 @@ int main(int argc, const char *argv[]) {
|
|||||||
format = YUV;
|
format = YUV;
|
||||||
} else if (!strcmp(argv[c], "-mt")) {
|
} else if (!strcmp(argv[c], "-mt")) {
|
||||||
config.options.use_threads = 1;
|
config.options.use_threads = 1;
|
||||||
|
#if WEBP_DECODER_ABI_VERSION > 0x0203
|
||||||
} else if (!strcmp(argv[c], "-alpha_dither")) {
|
} else if (!strcmp(argv[c], "-alpha_dither")) {
|
||||||
config.options.alpha_dithering_strength = 100;
|
config.options.alpha_dithering_strength = 100;
|
||||||
|
#endif
|
||||||
} else if (!strcmp(argv[c], "-nodither")) {
|
} else if (!strcmp(argv[c], "-nodither")) {
|
||||||
config.options.dithering_strength = 0;
|
config.options.dithering_strength = 0;
|
||||||
} else if (!strcmp(argv[c], "-dither") && c < argc - 1) {
|
} 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.use_scaling = 1;
|
||||||
config.options.scaled_width = strtol(argv[++c], NULL, 0);
|
config.options.scaled_width = strtol(argv[++c], NULL, 0);
|
||||||
config.options.scaled_height = 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")) {
|
} else if (!strcmp(argv[c], "-flip")) {
|
||||||
config.options.flip = 1;
|
config.options.flip = 1;
|
||||||
|
#endif
|
||||||
} else if (!strcmp(argv[c], "-v")) {
|
} else if (!strcmp(argv[c], "-v")) {
|
||||||
verbose = 1;
|
verbose = 1;
|
||||||
#ifndef WEBP_DLL
|
#ifndef WEBP_DLL
|
||||||
|
@ -400,7 +400,9 @@ int main(int argc, char *argv[]) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
config->options.dithering_strength = 50;
|
config->options.dithering_strength = 50;
|
||||||
|
#if WEBP_DECODER_ABI_VERSION > 0x0203
|
||||||
config->options.alpha_dithering_strength = 100;
|
config->options.alpha_dithering_strength = 100;
|
||||||
|
#endif
|
||||||
kParams.use_color_profile = 1;
|
kParams.use_color_profile = 1;
|
||||||
|
|
||||||
for (c = 1; c < argc; ++c) {
|
for (c = 1; c < argc; ++c) {
|
||||||
@ -413,8 +415,10 @@ int main(int argc, char *argv[]) {
|
|||||||
config->options.no_fancy_upsampling = 1;
|
config->options.no_fancy_upsampling = 1;
|
||||||
} else if (!strcmp(argv[c], "-nofilter")) {
|
} else if (!strcmp(argv[c], "-nofilter")) {
|
||||||
config->options.bypass_filtering = 1;
|
config->options.bypass_filtering = 1;
|
||||||
|
#if WEBP_DECODER_ABI_VERSION > 0x0203
|
||||||
} else if (!strcmp(argv[c], "-noalphadither")) {
|
} else if (!strcmp(argv[c], "-noalphadither")) {
|
||||||
config->options.alpha_dithering_strength = 0;
|
config->options.alpha_dithering_strength = 0;
|
||||||
|
#endif
|
||||||
} else if (!strcmp(argv[c], "-dither") && c + 1 < argc) {
|
} else if (!strcmp(argv[c], "-dither") && c + 1 < argc) {
|
||||||
config->options.dithering_strength = strtol(argv[++c], NULL, 0);
|
config->options.dithering_strength = strtol(argv[++c], NULL, 0);
|
||||||
} else if (!strcmp(argv[c], "-info")) {
|
} else if (!strcmp(argv[c], "-info")) {
|
||||||
|
20
man/dwebp.1
20
man/dwebp.1
@ -1,5 +1,5 @@
|
|||||||
.\" Hey, EMACS: -*- nroff -*-
|
.\" Hey, EMACS: -*- nroff -*-
|
||||||
.TH DWEBP 1 "June 13, 2014"
|
.TH DWEBP 1 "July 22, 2014"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
dwebp \- decompress a WebP file to an image file
|
dwebp \- decompress a WebP file to an image file
|
||||||
.SH SYNOPSIS
|
.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
|
Specify a dithering \fBstrength\fP between 0 and 100. Dithering is a
|
||||||
post-processing effect applied to chroma components in lossy compression.
|
post-processing effect applied to chroma components in lossy compression.
|
||||||
It helps by smoothing gradients and avoiding banding artifacts.
|
It helps by smoothing gradients and avoiding banding artifacts.
|
||||||
.TP
|
.\" TODO(jzern): restore post-v0.4.1
|
||||||
.BI \-alpha_dither
|
.\" .TP
|
||||||
If the compressed file contains a transparency plane that was quantized
|
.\" .BI \-alpha_dither
|
||||||
during compression, this flag will allow dithering the reconstructed plane
|
.\" If the compressed file contains a transparency plane that was quantized
|
||||||
in order to generate smoother transparency gradients.
|
.\" during compression, this flag will allow dithering the reconstructed plane
|
||||||
|
.\" in order to generate smoother transparency gradients.
|
||||||
.TP
|
.TP
|
||||||
.B \-nodither
|
.B \-nodither
|
||||||
Disable all dithering (default).
|
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.
|
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.
|
This option is meant to reduce the memory needed for cropping large images.
|
||||||
Note: the cropping is applied \fIbefore\fP any scaling.
|
Note: the cropping is applied \fIbefore\fP any scaling.
|
||||||
.TP
|
.\" TODO(jzern): restore post-v0.4.1
|
||||||
.B \-flip
|
.\" .TP
|
||||||
Flip decoded image vertically (can be useful for OpenGL textures for instance).
|
.\" .B \-flip
|
||||||
|
.\" Flip decoded image vertically (can be useful for OpenGL textures for instance).
|
||||||
.TP
|
.TP
|
||||||
.BI \-scale " width height
|
.BI \-scale " width height
|
||||||
Rescale the decoded picture to dimension \fBwidth\fP x \fBheight\fP. This
|
Rescale the decoded picture to dimension \fBwidth\fP x \fBheight\fP. This
|
||||||
|
@ -195,10 +195,12 @@ VP8StatusCode WebPAllocateDecBuffer(int w, int h,
|
|||||||
status = AllocateBuffer(out);
|
status = AllocateBuffer(out);
|
||||||
if (status != VP8_STATUS_OK) return status;
|
if (status != VP8_STATUS_OK) return status;
|
||||||
|
|
||||||
|
#if WEBP_DECODER_ABI_VERSION > 0x0203
|
||||||
// Use the stride trick if vertical flip is needed.
|
// Use the stride trick if vertical flip is needed.
|
||||||
if (options != NULL && options->flip) {
|
if (options != NULL && options->flip) {
|
||||||
status = WebPFlipBuffer(out);
|
status = WebPFlipBuffer(out);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +177,7 @@ void VP8InitDithering(const WebPDecoderOptions* const options,
|
|||||||
dec->dither_ = 1;
|
dec->dither_ = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if WEBP_DECODER_ABI_VERSION > 0x0203
|
||||||
// potentially allow alpha dithering
|
// potentially allow alpha dithering
|
||||||
dec->alpha_dithering_ = options->alpha_dithering_strength;
|
dec->alpha_dithering_ = options->alpha_dithering_strength;
|
||||||
if (dec->alpha_dithering_ > 100) {
|
if (dec->alpha_dithering_ > 100) {
|
||||||
@ -184,6 +185,7 @@ void VP8InitDithering(const WebPDecoderOptions* const options,
|
|||||||
} else if (dec->alpha_dithering_ < 0) {
|
} else if (dec->alpha_dithering_ < 0) {
|
||||||
dec->alpha_dithering_ = 0;
|
dec->alpha_dithering_ = 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,15 +240,17 @@ static int CheckMemBufferMode(MemBuffer* const mem, MemBufferMode expected) {
|
|||||||
|
|
||||||
// To be called last.
|
// To be called last.
|
||||||
static VP8StatusCode FinishDecoding(WebPIDecoder* const idec) {
|
static VP8StatusCode FinishDecoding(WebPIDecoder* const idec) {
|
||||||
|
#if WEBP_DECODER_ABI_VERSION > 0x0203
|
||||||
const WebPDecoderOptions* const options = idec->params_.options;
|
const WebPDecoderOptions* const options = idec->params_.options;
|
||||||
WebPDecBuffer* const output = idec->params_.output;
|
WebPDecBuffer* const output = idec->params_.output;
|
||||||
|
|
||||||
idec->state_ = STATE_DONE;
|
idec->state_ = STATE_DONE;
|
||||||
if (options != NULL && options->flip) {
|
if (options != NULL && options->flip) {
|
||||||
return WebPFlipBuffer(output);
|
return WebPFlipBuffer(output);
|
||||||
} else {
|
|
||||||
return VP8_STATUS_OK;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
idec->state_ = STATE_DONE;
|
||||||
|
return VP8_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
@ -521,9 +521,11 @@ static VP8StatusCode DecodeInto(const uint8_t* const data, size_t data_size,
|
|||||||
WebPFreeDecBuffer(params->output);
|
WebPFreeDecBuffer(params->output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if WEBP_DECODER_ABI_VERSION > 0x0203
|
||||||
if (params->options != NULL && params->options->flip) {
|
if (params->options != NULL && params->options->flip) {
|
||||||
status = WebPFlipBuffer(params->output);
|
status = WebPFlipBuffer(params->output);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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++,
|
// Note: forward declaring enumerations is not allowed in (strict) C and C++,
|
||||||
// the types are left here for reference.
|
// the types are left here for reference.
|
||||||
@ -442,13 +442,19 @@ struct WebPDecoderOptions {
|
|||||||
int scaled_width, scaled_height; // final resolution
|
int scaled_width, scaled_height; // final resolution
|
||||||
int use_threads; // if true, use multi-threaded decoding
|
int use_threads; // if true, use multi-threaded decoding
|
||||||
int dithering_strength; // dithering strength (0=Off, 100=full)
|
int dithering_strength; // dithering strength (0=Off, 100=full)
|
||||||
|
#if WEBP_DECODER_ABI_VERSION > 0x0203
|
||||||
int flip; // flip output vertically
|
int flip; // flip output vertically
|
||||||
int alpha_dithering_strength; // alpha dithering strength in [0..100]
|
int alpha_dithering_strength; // alpha dithering strength in [0..100]
|
||||||
|
#endif
|
||||||
|
|
||||||
// Unused for now:
|
// Unused for now:
|
||||||
int force_rotation; // forced rotation (to be applied _last_)
|
int force_rotation; // forced rotation (to be applied _last_)
|
||||||
int no_enhancement; // if true, discard enhancement layer
|
int no_enhancement; // if true, discard enhancement layer
|
||||||
|
#if WEBP_DECODER_ABI_VERSION > 0x0203
|
||||||
uint32_t pad[3]; // padding for later use
|
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.
|
// Main object storing the configuration for advanced decoding.
|
||||||
|
Loading…
Reference in New Issue
Block a user