use RawMode struct for jpegmode

This commit is contained in:
Yay295 2024-04-22 20:16:28 -05:00
parent 7bd8041087
commit e53aa29d20
3 changed files with 11 additions and 14 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -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;
}