Skip to content

Commit 4f9b68c

Browse files
committed
use more mode enums in decode.c
1 parent cb68244 commit 4f9b68c

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/decode.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -318,17 +318,18 @@ PyObject *
318318
PyImaging_BitDecoderNew(PyObject *self, PyObject *args) {
319319
ImagingDecoderObject *decoder;
320320

321-
char *mode;
321+
const char *mode_name;
322322
int bits = 8;
323323
int pad = 8;
324324
int fill = 0;
325325
int sign = 0;
326326
int ystep = 1;
327-
if (!PyArg_ParseTuple(args, "s|iiiii", &mode, &bits, &pad, &fill, &sign, &ystep)) {
327+
if (!PyArg_ParseTuple(args, "s|iiiii", &mode_name, &bits, &pad, &fill, &sign, &ystep)) {
328328
return NULL;
329329
}
330330

331-
if (strcmp(mode, "F") != 0) {
331+
const ModeID mode = findModeID(mode_name);
332+
if (mode != IMAGING_MODE_F) {
332333
PyErr_SetString(PyExc_ValueError, "bad image mode");
333334
return NULL;
334335
}
@@ -358,34 +359,36 @@ PyObject *
358359
PyImaging_BcnDecoderNew(PyObject *self, PyObject *args) {
359360
ImagingDecoderObject *decoder;
360361

361-
char *mode;
362-
char *actual;
362+
char *mode_name;
363363
int n = 0;
364364
char *pixel_format = "";
365-
if (!PyArg_ParseTuple(args, "si|s", &mode, &n, &pixel_format)) {
365+
if (!PyArg_ParseTuple(args, "si|s", &mode_name, &n, &pixel_format)) {
366366
return NULL;
367367
}
368368

369+
const ModeID mode = findModeID(mode_name);
370+
ModeID actual;
371+
369372
switch (n) {
370373
case 1: /* BC1: 565 color, 1-bit alpha */
371374
case 2: /* BC2: 565 color, 4-bit alpha */
372375
case 3: /* BC3: 565 color, 2-endpoint 8-bit interpolated alpha */
373376
case 7: /* BC7: 4-channel 8-bit via everything */
374-
actual = "RGBA";
377+
actual = IMAGING_MODE_RGBA;
375378
break;
376379
case 4: /* BC4: 1-channel 8-bit via 1 BC3 alpha block */
377-
actual = "L";
380+
actual = IMAGING_MODE_L;
378381
break;
379382
case 5: /* BC5: 2-channel 8-bit via 2 BC3 alpha blocks */
380383
case 6: /* BC6: 3-channel 16-bit float */
381-
actual = "RGB";
384+
actual = IMAGING_MODE_RGB;
382385
break;
383386
default:
384387
PyErr_SetString(PyExc_ValueError, "block compression type unknown");
385388
return NULL;
386389
}
387390

388-
if (strcmp(mode, actual) != 0) {
391+
if (mode != actual) {
389392
PyErr_SetString(PyExc_ValueError, "bad image mode");
390393
return NULL;
391394
}
@@ -428,15 +431,16 @@ PyObject *
428431
PyImaging_GifDecoderNew(PyObject *self, PyObject *args) {
429432
ImagingDecoderObject *decoder;
430433

431-
char *mode;
434+
const char *mode_name;
432435
int bits = 8;
433436
int interlace = 0;
434437
int transparency = -1;
435-
if (!PyArg_ParseTuple(args, "s|iii", &mode, &bits, &interlace, &transparency)) {
438+
if (!PyArg_ParseTuple(args, "s|iii", &mode_name, &bits, &interlace, &transparency)) {
436439
return NULL;
437440
}
438441

439-
if (strcmp(mode, "L") != 0 && strcmp(mode, "P") != 0) {
442+
const ModeID mode = findModeID(mode_name);
443+
if (mode != IMAGING_MODE_L && mode != IMAGING_MODE_P) {
440444
PyErr_SetString(PyExc_ValueError, "bad image mode");
441445
return NULL;
442446
}

0 commit comments

Comments
 (0)