diff --git a/src/decode.c b/src/decode.c index 1e9906ae7..df5fb08ae 100644 --- a/src/decode.c +++ b/src/decode.c @@ -847,20 +847,17 @@ PyImaging_JpegDecoderNew(PyObject *self, PyObject *args) { char *mode_name; char *rawmode_name; /* what we want from the decoder */ - char *jpegmode; /* what's in the file */ + char *jpegmode_name; /* what's in the file */ int scale = 1; int draft = 0; - if (!PyArg_ParseTuple(args, "ssz|ii", &mode_name, &rawmode_name, &jpegmode, &scale, &draft)) { + if (!PyArg_ParseTuple(args, "ssz|ii", &mode_name, &rawmode_name, &jpegmode_name, &scale, &draft)) { return NULL; } const Mode * const mode = findMode(mode_name); const RawMode * rawmode = findRawMode(rawmode_name); - - if (!jpegmode) { - jpegmode = ""; - } + const RawMode * const jpegmode = findRawMode(jpegmode_name); decoder = PyImaging_DecoderNew(sizeof(JPEGSTATE)); if (decoder == NULL) { @@ -884,7 +881,7 @@ PyImaging_JpegDecoderNew(PyObject *self, PyObject *args) { JPEGSTATE *jpeg_decoder_state_context = (JPEGSTATE *)decoder->state.context; jpeg_decoder_state_context->rawmode = rawmode; - strncpy(jpeg_decoder_state_context->jpegmode, jpegmode, 8); + jpeg_decoder_state_context->jpegmode = jpegmode; jpeg_decoder_state_context->scale = scale; jpeg_decoder_state_context->draft = draft; diff --git a/src/libImaging/Jpeg.h b/src/libImaging/Jpeg.h index 35df91d7f..48c6c6184 100644 --- a/src/libImaging/Jpeg.h +++ b/src/libImaging/Jpeg.h @@ -28,8 +28,8 @@ typedef struct { typedef struct { /* CONFIGURATION */ - /* Jpeg file mode (empty if not known) */ - char jpegmode[8 + 1]; + /* Jpeg file mode (NULL if not known) */ + const RawMode *jpegmode; /* Converter output mode (input to the shuffler) */ /* If NULL, convert conversions are disabled */ diff --git a/src/libImaging/JpegDecode.c b/src/libImaging/JpegDecode.c index 36eb7835a..49d4fcb2f 100644 --- a/src/libImaging/JpegDecode.c +++ b/src/libImaging/JpegDecode.c @@ -182,15 +182,15 @@ ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t by /* jpegmode indicates what's in the file; if not set, we'll trust the decoder */ - if (strcmp(context->jpegmode, "L") == 0) { + if (context->jpegmode == IMAGING_RAWMODE_L) { context->cinfo.jpeg_color_space = JCS_GRAYSCALE; - } else if (strcmp(context->jpegmode, "RGB") == 0) { + } else if (context->jpegmode == IMAGING_RAWMODE_RGB) { context->cinfo.jpeg_color_space = JCS_RGB; - } else if (strcmp(context->jpegmode, "CMYK") == 0) { + } else if (context->jpegmode == IMAGING_RAWMODE_CMYK) { context->cinfo.jpeg_color_space = JCS_CMYK; - } else if (strcmp(context->jpegmode, "YCbCr") == 0) { + } else if (context->jpegmode == IMAGING_RAWMODE_YCbCr) { context->cinfo.jpeg_color_space = JCS_YCbCr; - } else if (strcmp(context->jpegmode, "YCbCrK") == 0) { + } else if (context->jpegmode == IMAGING_RAWMODE_YCbCrK) { context->cinfo.jpeg_color_space = JCS_YCCK; }