From 185dc9647fc1cb620eb1e40b1da647897e91d403 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 3 Dec 2026 00:21:31 +1100 Subject: [PATCH] Add custom error message Co-authored-by: Aarni Koskela --- src/PIL/Image.py | 5 ++--- src/libImaging/Effects.c | 4 +++- src/libImaging/Point.c | 20 ++++++++++---------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index cba9083b871..b696f80d3a5 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2083,7 +2083,7 @@ def point(self, im: Image) -> Image: if callable(lut): # if it isn't a list, it should be a function - if self.mode in ("I", "I;16", "I;16L", "I;16B", "I;16N", "F"): + if self.mode in {"I", "I;16", "I;16L", "I;16B", "I;16N", "F"}: # check if the function can be used with point_transform # UNDONE wiredfool -- I think this prevents us from ever doing # a gamma function point transform on > 8bit images. @@ -2094,8 +2094,7 @@ def point(self, im: Image) -> Image: else: flatLut = lut - if self.mode == "F": - # FIXME: _imaging returns a confusing error message for this case + if self.mode in {"I;16", "I;16L", "I;16B", "I;16N", "F"}: msg = "point operation not supported for this mode" raise ValueError(msg) diff --git a/src/libImaging/Effects.c b/src/libImaging/Effects.c index c4efaef3de3..c5d2836b49e 100644 --- a/src/libImaging/Effects.c +++ b/src/libImaging/Effects.c @@ -43,7 +43,9 @@ ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality) { width = extent[2] - extent[0]; height = extent[3] - extent[1]; if (width < 0.0 || height < 0.0 || quality < 2) { - return (Imaging)ImagingError_ValueError(NULL); + return (Imaging)ImagingError_ValueError( + "extent width and height must be >= 0 and quality must be >= 2" + ); } im = ImagingNewDirty(IMAGING_MODE_L, xsize, ysize); diff --git a/src/libImaging/Point.c b/src/libImaging/Point.c index 18326ca240d..4730d45caca 100644 --- a/src/libImaging/Point.c +++ b/src/libImaging/Point.c @@ -178,16 +178,21 @@ ImagingPoint(Imaging imIn, ModeID mode, const void *table) { if (imIn->type == IMAGING_TYPE_UINT8) { if (imIn->mode != mode && !imIn->image8) { - goto mode_mismatch; + return (Imaging)ImagingError_ValueError( + "modes LA, La, PA, RGB, RGBX, RGBA, RGBa, CMYK, YCbCr, LAB or HSV only " + "supported for matching output modes" + ); } } else if (imIn->type == IMAGING_TYPE_INT32) { if (mode != IMAGING_MODE_L) { - // I images can only be used with L output mode - goto mode_mismatch; + return (Imaging)ImagingError_ValueError( + "mode I only supported for L output mode" + ); } } else { - // Reject F modes and modes based on I;16 - goto mode_mismatch; + return (Imaging)ImagingError_ValueError( + "modes F and I;16 variants not supported" + ); } imOut = ImagingNewDirty(mode, imIn->xsize, imIn->ysize); @@ -229,11 +234,6 @@ ImagingPoint(Imaging imIn, ModeID mode, const void *table) { ImagingSectionLeave(&cookie); return imOut; - -mode_mismatch: - return (Imaging)ImagingError_ValueError( - "point operation not supported for this mode" - ); } /**