@@ -318,17 +318,18 @@ PyObject *
318
318
PyImaging_BitDecoderNew (PyObject * self , PyObject * args ) {
319
319
ImagingDecoderObject * decoder ;
320
320
321
- char * mode ;
321
+ const char * mode_name ;
322
322
int bits = 8 ;
323
323
int pad = 8 ;
324
324
int fill = 0 ;
325
325
int sign = 0 ;
326
326
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 )) {
328
328
return NULL ;
329
329
}
330
330
331
- if (strcmp (mode , "F" ) != 0 ) {
331
+ const ModeID mode = findModeID (mode_name );
332
+ if (mode != IMAGING_MODE_F ) {
332
333
PyErr_SetString (PyExc_ValueError , "bad image mode" );
333
334
return NULL ;
334
335
}
@@ -358,34 +359,36 @@ PyObject *
358
359
PyImaging_BcnDecoderNew (PyObject * self , PyObject * args ) {
359
360
ImagingDecoderObject * decoder ;
360
361
361
- char * mode ;
362
- char * actual ;
362
+ char * mode_name ;
363
363
int n = 0 ;
364
364
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 )) {
366
366
return NULL ;
367
367
}
368
368
369
+ const ModeID mode = findModeID (mode_name );
370
+ ModeID actual ;
371
+
369
372
switch (n ) {
370
373
case 1 : /* BC1: 565 color, 1-bit alpha */
371
374
case 2 : /* BC2: 565 color, 4-bit alpha */
372
375
case 3 : /* BC3: 565 color, 2-endpoint 8-bit interpolated alpha */
373
376
case 7 : /* BC7: 4-channel 8-bit via everything */
374
- actual = "RGBA" ;
377
+ actual = IMAGING_MODE_RGBA ;
375
378
break ;
376
379
case 4 : /* BC4: 1-channel 8-bit via 1 BC3 alpha block */
377
- actual = "L" ;
380
+ actual = IMAGING_MODE_L ;
378
381
break ;
379
382
case 5 : /* BC5: 2-channel 8-bit via 2 BC3 alpha blocks */
380
383
case 6 : /* BC6: 3-channel 16-bit float */
381
- actual = "RGB" ;
384
+ actual = IMAGING_MODE_RGB ;
382
385
break ;
383
386
default :
384
387
PyErr_SetString (PyExc_ValueError , "block compression type unknown" );
385
388
return NULL ;
386
389
}
387
390
388
- if (strcmp ( mode , actual ) != 0 ) {
391
+ if (mode != actual ) {
389
392
PyErr_SetString (PyExc_ValueError , "bad image mode" );
390
393
return NULL ;
391
394
}
@@ -428,15 +431,16 @@ PyObject *
428
431
PyImaging_GifDecoderNew (PyObject * self , PyObject * args ) {
429
432
ImagingDecoderObject * decoder ;
430
433
431
- char * mode ;
434
+ const char * mode_name ;
432
435
int bits = 8 ;
433
436
int interlace = 0 ;
434
437
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 )) {
436
439
return NULL ;
437
440
}
438
441
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 ) {
440
444
PyErr_SetString (PyExc_ValueError , "bad image mode" );
441
445
return NULL ;
442
446
}
0 commit comments