use RGBX rawmode for JPEG encoding as well

This commit is contained in:
Alexander 2017-08-11 04:10:55 +03:00
parent 7725d281a5
commit 3aea175141
4 changed files with 17 additions and 1 deletions

View File

@ -691,6 +691,13 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
if (encoder == NULL) if (encoder == NULL)
return NULL; return NULL;
// libjpeg-turbo supports different output formats.
// We are choosing Pillow's native format (3 color bytes + 1 padding)
// to avoid extra conversion in Pack.c.
if (ImagingJpegUseJCSExtensions() && strcmp(rawmode, "RGB") == 0) {
rawmode = "RGBX";
}
if (get_packer(encoder, mode, rawmode) < 0) if (get_packer(encoder, mode, rawmode) < 0)
return NULL; return NULL;
@ -719,6 +726,8 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
encoder->encode = ImagingJpegEncode; encoder->encode = ImagingJpegEncode;
strncpy(((JPEGENCODERSTATE*)encoder->state.context)->rawmode, rawmode, 8);
((JPEGENCODERSTATE*)encoder->state.context)->quality = quality; ((JPEGENCODERSTATE*)encoder->state.context)->quality = quality;
((JPEGENCODERSTATE*)encoder->state.context)->qtables = qarrays; ((JPEGENCODERSTATE*)encoder->state.context)->qtables = qarrays;
((JPEGENCODERSTATE*)encoder->state.context)->qtablesLen = qtablesLen; ((JPEGENCODERSTATE*)encoder->state.context)->qtablesLen = qtablesLen;

View File

@ -88,6 +88,9 @@ typedef struct {
/* Chroma Subsampling (-1=default, 0=none, 1=medium, 2=high) */ /* Chroma Subsampling (-1=default, 0=none, 1=medium, 2=high) */
int subsampling; int subsampling;
/* Converter input mode (input to the shuffler) */
char rawmode[8+1];
/* Custom quantization tables () */ /* Custom quantization tables () */
unsigned int *qtables; unsigned int *qtables;

View File

@ -218,7 +218,7 @@ ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
context->cinfo.out_color_space = JCS_GRAYSCALE; context->cinfo.out_color_space = JCS_GRAYSCALE;
else if (strcmp(context->rawmode, "RGB") == 0) else if (strcmp(context->rawmode, "RGB") == 0)
context->cinfo.out_color_space = JCS_RGB; context->cinfo.out_color_space = JCS_RGB;
#if defined(JCS_EXTENSIONS) #ifdef JCS_EXTENSIONS
else if (strcmp(context->rawmode, "RGBX") == 0) else if (strcmp(context->rawmode, "RGBX") == 0)
context->cinfo.out_color_space = JCS_EXT_RGBX; context->cinfo.out_color_space = JCS_EXT_RGBX;
#endif #endif

View File

@ -135,6 +135,10 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
case 32: case 32:
context->cinfo.input_components = 4; context->cinfo.input_components = 4;
context->cinfo.in_color_space = JCS_CMYK; context->cinfo.in_color_space = JCS_CMYK;
#ifdef JCS_EXTENSIONS
if (strcmp(context->rawmode, "RGBX") == 0)
context->cinfo.in_color_space = JCS_EXT_RGBX;
#endif
break; break;
default: default:
state->errcode = IMAGING_CODEC_CONFIG; state->errcode = IMAGING_CODEC_CONFIG;