@@ -630,45 +630,25 @@ def test_skip_vertical(self, flt: Image.Resampling) -> None:
630630
631631
632632class TestCoreResample16bpc :
633- def test_resampling_clamp_overflow (self ) -> None :
634- # Lanczos weighting during downsampling can push accumulated float sums
635- # above 65535. These must be clamped to 65535, not corrupted byte-by-byte.
636- ims = {}
637- width , height = 100 , 10
638- for mode in ("I;16" , "F" ):
639- # Left half = 0, right half = 65535
640- im = Image .new (mode , (width , height ))
641- for y in range (height ):
642- for x in range (width // 2 , width ):
643- im .putpixel ((x , y ), 65535 )
644-
645- # 5x downsampling with Lanczos creates ~8.7% overshoot at the step edge
646- ims [mode ] = im .resize ((20 , height ), Image .Resampling .LANCZOS )
647-
648- for y in range (height ):
649- for x in range (20 ):
650- v = ims ["F" ].getpixel ((x , y ))
651- assert isinstance (v , float )
652- expected = max (0 , min (65535 , round (v )))
653-
654- value = ims ["I;16" ].getpixel ((x , y ))
655- assert (
656- value == expected
657- ), f"Pixel ({ x } , { y } ): expected { expected } , got { value } "
658-
659- def test_resampling_clamp_underflow (self ) -> None :
660- # Lanczos weighting during downsampling can push accumulated float sums
661- # below 0. These must be clamped to 0, not corrupted byte-by-byte.
633+ # Lanczos weighting during downsampling can push accumulated float sums
634+ @pytest .mark .parametrize (
635+ "offset" ,
636+ (
637+ # below 0. These must be clamped to 0, not corrupted byte-by-byte.
638+ 0 , # Left half = 65535, right half = 0
639+ # above 65535. These must be clamped to 65535, not corrupted byte-by-byte.
640+ 50 , # # Left half = 0, right half = 65535
641+ ),
642+ )
643+ def test_resampling_clamp_overflow (self , offset : int ) -> None :
662644 ims = {}
663645 width , height = 100 , 10
664646 for mode in ("I;16" , "F" ):
665- # Left half = 65535, right half = 0
666647 im = Image .new (mode , (width , height ))
667- for y in range (height ):
668- for x in range (width // 2 ):
669- im .putpixel ((x , y ), 65535 )
648+ im .paste (65535 , (offset , 0 , offset + width // 2 , height ))
670649
671- # 5x downsampling with Lanczos creates ~8.7% undershoot at the step edge
650+ # 5x downsampling with Lanczos
651+ # creates ~8.7% overshoot or undershoot at the step edge
672652 ims [mode ] = im .resize ((20 , height ), Image .Resampling .LANCZOS )
673653
674654 for y in range (height ):
0 commit comments