From a926d2e16f87068a75ec9a2a5c9a888bad7d6ec9 Mon Sep 17 00:00:00 2001 From: homm Date: Mon, 27 Jun 2016 02:11:34 +0300 Subject: [PATCH] use RGBX raw mode for RGB JPEG images --- decode.c | 9 +++++++++ libImaging/JpegDecode.c | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/decode.c b/decode.c index f700747e1..47ba08455 100644 --- a/decode.c +++ b/decode.c @@ -752,6 +752,15 @@ PyImaging_TgaRleDecoderNew(PyObject* self, PyObject* args) if (decoder == NULL) return NULL; +#if defined(JCS_EXTENSIONS) + // libjpeg-turbo supports different output formats. + // We are choosing Pillow's native format (3 color bytes + 1 padding) + // to avoid extra conversion in Unpack.c. + if (strcmp(rawmode, "RGB") == 0) { + rawmode = "RGBX"; + } +#endif + if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; diff --git a/libImaging/JpegDecode.c b/libImaging/JpegDecode.c index 6ebdb8f93..9496cc522 100644 --- a/libImaging/JpegDecode.c +++ b/libImaging/JpegDecode.c @@ -189,6 +189,10 @@ ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) context->cinfo.out_color_space = JCS_GRAYSCALE; else if (strcmp(context->rawmode, "RGB") == 0) context->cinfo.out_color_space = JCS_RGB; + #if defined(JCS_EXTENSIONS) + else if (strcmp(context->rawmode, "RGBX") == 0) + context->cinfo.out_color_space = JCS_EXT_RGBX; + #endif else if (strcmp(context->rawmode, "CMYK") == 0 || strcmp(context->rawmode, "CMYK;I") == 0) context->cinfo.out_color_space = JCS_CMYK;