diff --git a/Tests/test_image_resample.py b/Tests/test_image_resample.py index c891ae34e..28568038e 100644 --- a/Tests/test_image_resample.py +++ b/Tests/test_image_resample.py @@ -179,7 +179,6 @@ class TestImagingCoreResampleAccuracy: for channel in case.split(): self.check_case(channel, self.make_sample(data, (10, 10))) - @pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L")) def test_enlarge_box(self, mode: str) -> None: case = self.make_case(mode, (2, 2), 0xE1) @@ -341,7 +340,9 @@ class TestCoreResampleAlphaCorrect: self.run_levels_case(case.resize((512, 32), Image.Resampling.HAMMING)) self.run_levels_case(case.resize((512, 32), Image.Resampling.BICUBIC)) self.run_levels_case(case.resize((512, 32), Image.Resampling.LANCZOS)) - self.run_levels_case(case.resize((512, 32), Image.Resampling.MAGIC_KERNEL_SHARP_2021)) + self.run_levels_case( + case.resize((512, 32), Image.Resampling.MAGIC_KERNEL_SHARP_2021) + ) @pytest.mark.xfail(reason="Current implementation isn't precise enough") def test_levels_la(self) -> None: @@ -351,7 +352,9 @@ class TestCoreResampleAlphaCorrect: self.run_levels_case(case.resize((512, 32), Image.Resampling.HAMMING)) self.run_levels_case(case.resize((512, 32), Image.Resampling.BICUBIC)) self.run_levels_case(case.resize((512, 32), Image.Resampling.LANCZOS)) - self.run_levels_case(case.resize((512, 32), Image.Resampling.MAGIC_KERNEL_SHARP_2021)) + self.run_levels_case( + case.resize((512, 32), Image.Resampling.MAGIC_KERNEL_SHARP_2021) + ) def make_dirty_case( self, mode: str, clean_pixel: tuple[int, ...], dirty_pixel: tuple[int, ...] @@ -395,7 +398,8 @@ class TestCoreResampleAlphaCorrect: case.resize((20, 20), Image.Resampling.LANCZOS), (255, 255, 0) ) self.run_dirty_case( - case.resize((20, 20), Image.Resampling.MAGIC_KERNEL_SHARP_2021), (255, 255, 0) + case.resize((20, 20), Image.Resampling.MAGIC_KERNEL_SHARP_2021), + (255, 255, 0), ) def test_dirty_pixels_la(self) -> None: @@ -405,7 +409,9 @@ class TestCoreResampleAlphaCorrect: self.run_dirty_case(case.resize((20, 20), Image.Resampling.HAMMING), (255,)) self.run_dirty_case(case.resize((20, 20), Image.Resampling.BICUBIC), (255,)) self.run_dirty_case(case.resize((20, 20), Image.Resampling.LANCZOS), (255,)) - self.run_dirty_case(case.resize((20, 20), Image.Resampling.MAGIC_KERNEL_SHARP_2021), (255,)) + self.run_dirty_case( + case.resize((20, 20), Image.Resampling.MAGIC_KERNEL_SHARP_2021), (255,) + ) class TestCoreResamplePasses: diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 23a7b8b0f..662e6c0bc 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2259,7 +2259,10 @@ class Image: for filter in ( (Resampling.NEAREST, "Image.Resampling.NEAREST"), (Resampling.LANCZOS, "Image.Resampling.LANCZOS"), - (Resampling.MAGIC_KERNEL_SHARP_2021, "Image.Resampling.MAGIC_KERNEL_SHARP_2021"), + ( + Resampling.MAGIC_KERNEL_SHARP_2021, + "Image.Resampling.MAGIC_KERNEL_SHARP_2021", + ), (Resampling.BILINEAR, "Image.Resampling.BILINEAR"), (Resampling.BICUBIC, "Image.Resampling.BICUBIC"), (Resampling.BOX, "Image.Resampling.BOX"), @@ -2930,7 +2933,12 @@ class Image: Resampling.BILINEAR, Resampling.BICUBIC, ): - if resample in (Resampling.BOX, Resampling.HAMMING, Resampling.LANCZOS, Resampling.MAGIC_KERNEL_SHARP_2021): + if resample in ( + Resampling.BOX, + Resampling.HAMMING, + Resampling.LANCZOS, + Resampling.MAGIC_KERNEL_SHARP_2021, + ): unusable: dict[int, str] = { Resampling.BOX: "Image.Resampling.BOX", Resampling.HAMMING: "Image.Resampling.HAMMING", diff --git a/src/libImaging/Resample.c b/src/libImaging/Resample.c index 43b3f2088..3c3e96b52 100644 --- a/src/libImaging/Resample.c +++ b/src/libImaging/Resample.c @@ -83,7 +83,7 @@ static inline double magic_kernel_sharp_2021_filter(double x) { x = fabs(x); if (x < 0.5) { - return 577.0 / 576.0 - 239.0 / 144.0 * x *x; + return 577.0 / 576.0 - 239.0 / 144.0 * x * x; } if (x < 1.5) { return 35.0 / 36.0 * (x - 1.0) * (x - 239.0 / 140.0);