mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 22:28:22 +01:00
take colorspace into account when cropping
(cherry picked from commit 4e33653b52637c74ae30adde7990265d1d43994b) Conflicts: src/dec/vp8l.c
This commit is contained in:
parent
61c2d51fd7
commit
1db888ba40
14
src/dec/io.c
14
src/dec/io.c
@ -468,12 +468,14 @@ static int InitRGBRescaler(const VP8Io* const io, WebPDecParams* const p) {
|
|||||||
|
|
||||||
static int CustomSetup(VP8Io* io) {
|
static int CustomSetup(VP8Io* io) {
|
||||||
WebPDecParams* const p = (WebPDecParams*)io->opaque;
|
WebPDecParams* const p = (WebPDecParams*)io->opaque;
|
||||||
const int is_rgb = (p->output->colorspace < MODE_YUV);
|
const WEBP_CSP_MODE colorspace = p->output->colorspace;
|
||||||
|
const int is_rgb = (colorspace < MODE_YUV);
|
||||||
|
const int is_alpha = IsAlphaMode(colorspace);
|
||||||
|
|
||||||
p->memory = NULL;
|
p->memory = NULL;
|
||||||
p->emit = NULL;
|
p->emit = NULL;
|
||||||
p->emit_alpha = NULL;
|
p->emit_alpha = NULL;
|
||||||
if (!WebPIoInitFromOptions(p->options, io)) {
|
if (!WebPIoInitFromOptions(p->options, io, is_alpha ? MODE_YUV : MODE_YUVA)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,11 +504,11 @@ static int CustomSetup(VP8Io* io) {
|
|||||||
} else {
|
} else {
|
||||||
p->emit = EmitYUV;
|
p->emit = EmitYUV;
|
||||||
}
|
}
|
||||||
if (IsAlphaMode(p->output->colorspace)) {
|
if (is_alpha) { // need transparency output
|
||||||
// We need transparency output
|
|
||||||
p->emit_alpha =
|
p->emit_alpha =
|
||||||
is_rgb ? (p->output->colorspace == MODE_RGBA_4444 ?
|
is_rgb ? (colorspace == MODE_RGBA_4444 ? EmitAlphaRGBA4444
|
||||||
EmitAlphaRGBA4444 : EmitAlphaRGB) : EmitAlphaYUV;
|
: EmitAlphaRGB)
|
||||||
|
: EmitAlphaYUV;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,7 +613,7 @@ VP8StatusCode WebPDecode(const uint8_t* data, uint32_t data_size,
|
|||||||
// Cropping and rescaling.
|
// Cropping and rescaling.
|
||||||
|
|
||||||
int WebPIoInitFromOptions(const WebPDecoderOptions* const options,
|
int WebPIoInitFromOptions(const WebPDecoderOptions* const options,
|
||||||
VP8Io* const io) {
|
VP8Io* const io, WEBP_CSP_MODE src_colorspace) {
|
||||||
const int W = io->width;
|
const int W = io->width;
|
||||||
const int H = io->height;
|
const int H = io->height;
|
||||||
int x = 0, y = 0, w = W, h = H;
|
int x = 0, y = 0, w = W, h = H;
|
||||||
@ -623,9 +623,12 @@ int WebPIoInitFromOptions(const WebPDecoderOptions* const options,
|
|||||||
if (io->use_cropping) {
|
if (io->use_cropping) {
|
||||||
w = options->crop_width;
|
w = options->crop_width;
|
||||||
h = options->crop_height;
|
h = options->crop_height;
|
||||||
// TODO(skal): take colorspace into account. Don't assume YUV420.
|
x = options->crop_left;
|
||||||
x = options->crop_left & ~1;
|
y = options->crop_top;
|
||||||
y = options->crop_top & ~1;
|
if (src_colorspace >= MODE_YUV) { // only snap for YUV420 or YUV422
|
||||||
|
x &= ~1;
|
||||||
|
y &= ~1; // TODO(later): only for YUV420, not YUV422.
|
||||||
|
}
|
||||||
if (x < 0 || y < 0 || w <= 0 || h <= 0 || x + w > W || y + h > H) {
|
if (x < 0 || y < 0 || w <= 0 || h <= 0 || x + w > W || y + h > H) {
|
||||||
return 0; // out of frame boundary error
|
return 0; // out of frame boundary error
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,11 @@ VP8StatusCode WebPParseHeaders(const uint8_t** data, uint32_t* data_size,
|
|||||||
// hooks will use the supplied 'params' as io->opaque handle.
|
// hooks will use the supplied 'params' as io->opaque handle.
|
||||||
void WebPInitCustomIo(WebPDecParams* const params, VP8Io* const io);
|
void WebPInitCustomIo(WebPDecParams* const params, VP8Io* const io);
|
||||||
|
|
||||||
|
// Setup crop_xxx fields, mb_w and mb_h in io. 'src_colorspace' refers
|
||||||
|
// to the *compressed* format, not the output one.
|
||||||
|
int WebPIoInitFromOptions(const WebPDecoderOptions* const options,
|
||||||
|
VP8Io* const io, WEBP_CSP_MODE src_colorspace);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Internal functions regarding WebPDecBuffer memory (in buffer.c).
|
// Internal functions regarding WebPDecBuffer memory (in buffer.c).
|
||||||
// Don't really need to be externally visible for now.
|
// Don't really need to be externally visible for now.
|
||||||
@ -144,12 +149,7 @@ void WebPCopyDecBuffer(const WebPDecBuffer* const src,
|
|||||||
// Copy and transfer ownership from src to dst (beware of parameter order!)
|
// Copy and transfer ownership from src to dst (beware of parameter order!)
|
||||||
void WebPGrabDecBuffer(WebPDecBuffer* const src, WebPDecBuffer* const dst);
|
void WebPGrabDecBuffer(WebPDecBuffer* const src, WebPDecBuffer* const dst);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Cropping and rescaling.
|
|
||||||
|
|
||||||
// Setup crop_xxx fields, mb_w and mb_h
|
|
||||||
int WebPIoInitFromOptions(const WebPDecoderOptions* const options,
|
|
||||||
VP8Io* const io);
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user