diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index ccef7a5137d..81872fdc80c 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -877,11 +877,18 @@ def test_oom(self, test_file: str) -> None: def test_open_tiff_uint16_multiband(self): """Test opening multiband TIFFs and reading all channels.""" - def getpixel00(im: Image.Image): + def check_pixel(im: Image.Image, expected_pixel, pos: tuple[int, int]): actual_pixel = im.getpixel((0, 0)) if isinstance(actual_pixel, int): actual_pixel = (actual_pixel,) - return actual_pixel + assert actual_pixel == expected_pixel + + def check_image(im: Image.Image, width: int, height: int, expected_pixel): + assert im.width == width + assert im.height == height + for x in range(im.width): + for y in range(im.height): + check_pixel(im, expected_pixel, (x, y)) base_value = 4660 for i in range(1, 6): @@ -890,10 +897,13 @@ def getpixel00(im: Image.Image): im = Image.open(infile) im.load() - assert getpixel00(im) == pixel + check_image(im, 10, 10, pixel) + + im1 = im.copy() + check_image(im1, 10, 10, pixel) - im.copy() - assert getpixel00(im) == pixel + im2 = im.crop((2, 2, 7, 7)) + check_image(im2, 5, 5, pixel) @pytest.mark.skipif(not is_win32(), reason="Windows only") diff --git a/src/libImaging/Crop.c b/src/libImaging/Crop.c index 630028d0e16..52f9b0a431f 100644 --- a/src/libImaging/Crop.c +++ b/src/libImaging/Crop.c @@ -37,7 +37,8 @@ ImagingCrop(Imaging imIn, int sx0, int sy0, int sx1, int sy1) { ysize = 0; } - imOut = ImagingNewDirty(imIn->mode, (ImagingNewParams){xsize, ysize}); + imOut = ImagingNewDirty( + imIn->mode, (ImagingNewParams){xsize, ysize, imIn->depth, imIn->bands}); if (!imOut) { return NULL; }