Skip to content

Commit

Permalink
use mode enums in _imagingcms.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed Oct 7, 2024
1 parent 9c0dccd commit 254367a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ def debug_build() -> bool:
ext_modules = [
Extension("PIL._imaging", files, libraries=["pil_imaging_mode"]),
Extension("PIL._imagingft", ["src/_imagingft.c"], libraries=["pil_imaging_mode"]),
Extension("PIL._imagingcms", ["src/_imagingcms.c"]),
Extension("PIL._imagingcms", ["src/_imagingcms.c"], libraries=["pil_imaging_mode"]),
Extension("PIL._webp", ["src/_webp.c"], libraries=["pil_imaging_mode"]),
Extension("PIL._imagingtk", ["src/_imagingtk.c", "src/Tk/tkImaging.c"]),
Extension("PIL._imagingmath", ["src/_imagingmath.c"]),
Expand Down
43 changes: 25 additions & 18 deletions src/_imagingcms.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,32 +212,39 @@ cms_transform_dealloc(CmsTransformObject *self) {
/* internal functions */

static cmsUInt32Number
findLCMStype(char *PILmode) {
if (strcmp(PILmode, "RGB") == 0 || strcmp(PILmode, "RGBA") == 0 ||
strcmp(PILmode, "RGBX") == 0) {
return TYPE_RGBA_8;
}
if (strcmp(PILmode, "RGBA;16B") == 0) {
findLCMStype(const char * const mode_name) {
const ModeID mode = findModeID(mode_name);
switch (mode) {

Check warning on line 217 in src/_imagingcms.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.12

enumeration value ‘IMAGING_MODE_UNKNOWN’ not handled in switch [-Wswitch]

Check warning on line 217 in src/_imagingcms.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.12

enumeration value ‘IMAGING_MODE_1’ not handled in switch [-Wswitch]

Check warning on line 217 in src/_imagingcms.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.12

enumeration value ‘IMAGING_MODE_F’ not handled in switch [-Wswitch]

Check warning on line 217 in src/_imagingcms.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.12

enumeration value ‘IMAGING_MODE_HSV’ not handled in switch [-Wswitch]

Check warning on line 217 in src/_imagingcms.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.12

enumeration value ‘IMAGING_MODE_I’ not handled in switch [-Wswitch]

Check warning on line 217 in src/_imagingcms.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.12

enumeration value ‘IMAGING_MODE_L’ not handled in switch [-Wswitch]

Check warning on line 217 in src/_imagingcms.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.12

enumeration value ‘IMAGING_MODE_LA’ not handled in switch [-Wswitch]

Check warning on line 217 in src/_imagingcms.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.12

enumeration value ‘IMAGING_MODE_La’ not handled in switch [-Wswitch]

Check warning on line 217 in src/_imagingcms.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.12

enumeration value ‘IMAGING_MODE_P’ not handled in switch [-Wswitch]

Check warning on line 217 in src/_imagingcms.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.12

enumeration value ‘IMAGING_MODE_PA’ not handled in switch [-Wswitch]
case IMAGING_MODE_RGB:
case IMAGING_MODE_RGBA:
case IMAGING_MODE_RGBX:
return TYPE_RGBA_8;
case IMAGING_MODE_CMYK:
return TYPE_CMYK_8;
case IMAGING_MODE_I_16:
case IMAGING_MODE_I_16L:
return TYPE_GRAY_16;
case IMAGING_MODE_I_16B:
return TYPE_GRAY_16_SE;
case IMAGING_MODE_YCbCr:
return TYPE_YCbCr_8;
case IMAGING_MODE_LAB:
// LabX equivalent like ALab, but not reversed -- no #define in lcms2
return (COLORSPACE_SH(PT_LabV2) | CHANNELS_SH(3) | BYTES_SH(1) | EXTRA_SH(1));
}
// The following modes are not valid PIL Image modes.
if (strcmp(mode_name, "RGBA;16B") == 0) {
return TYPE_RGBA_16;
}
if (strcmp(PILmode, "CMYK") == 0) {
return TYPE_CMYK_8;
}
if (strcmp(PILmode, "I;16") == 0 || strcmp(PILmode, "I;16L") == 0 ||
strcmp(PILmode, "L;16") == 0) {
if (strcmp(mode_name, "L;16") == 0) {
return TYPE_GRAY_16;
}
if (strcmp(PILmode, "I;16B") == 0 || strcmp(PILmode, "L;16B") == 0) {
if (strcmp(mode_name, "L;16B") == 0) {
return TYPE_GRAY_16_SE;
}
if (strcmp(PILmode, "YCbCr") == 0 || strcmp(PILmode, "YCCA") == 0 ||
strcmp(PILmode, "YCC") == 0) {
if (strcmp(mode_name, "YCCA") == 0 || strcmp(mode_name, "YCC") == 0) {
return TYPE_YCbCr_8;
}
if (strcmp(PILmode, "LAB") == 0) {
// LabX equivalent like ALab, but not reversed -- no #define in lcms2
return (COLORSPACE_SH(PT_LabV2) | CHANNELS_SH(3) | BYTES_SH(1) | EXTRA_SH(1));
}
/* presume "1" or "L" by default */
return TYPE_GRAY_8;
}
Expand Down

0 comments on commit 254367a

Please sign in to comment.