replace some string function usage with imaging mode checks

This commit is contained in:
Yay295 2024-04-22 19:47:58 -05:00
parent 05d7b313c6
commit 7bd8041087
2 changed files with 12 additions and 2 deletions

View File

@ -1771,7 +1771,13 @@ _putpalette(ImagingObject *self, PyObject *args) {
ImagingPaletteDelete(self->image->palette); ImagingPaletteDelete(self->image->palette);
self->image->mode = strlen(self->image->mode->name) == 2 ? IMAGING_MODE_PA : IMAGING_MODE_P; if (self->image->mode == IMAGING_MODE_LA) {
self->image->mode = IMAGING_MODE_PA;
} else if (self->image->mode == IMAGING_MODE_L) {
self->image->mode = IMAGING_MODE_P;
} else {
// The image already has a palette mode so we don't need to change it.
}
self->image->palette = ImagingPaletteNew(palette_mode); self->image->palette = ImagingPaletteNew(palette_mode);

View File

@ -46,7 +46,11 @@ ImagingConvertMatrix(Imaging im, const Mode *mode, float m[]) {
} }
} }
ImagingSectionLeave(&cookie); ImagingSectionLeave(&cookie);
} else if (strlen(mode->name) == 3) { } else if (
mode == IMAGING_MODE_HSV ||
mode == IMAGING_MODE_LAB ||
mode == IMAGING_MODE_RGB
) {
imOut = ImagingNewDirty(mode, im->xsize, im->ysize); imOut = ImagingNewDirty(mode, im->xsize, im->ysize);
if (!imOut) { if (!imOut) {
return NULL; return NULL;