@@ -148,12 +148,11 @@ public static (bool Difference, Rectangle Bounds) DeDuplicatePixels<TPixel>(
148148 PixelOperations < TPixel > . Instance . FromVector4Destructive ( configuration , result , resultFrame . DangerousGetPixelRowMemory ( y ) . Span , PixelConversionModifiers . Scale ) ;
149149 }
150150
151- left = Math . Max ( 0 , Math . Min ( left , resultFrame . Width - 1 ) ) ;
152- top = Math . Max ( 0 , Math . Min ( top , resultFrame . Height - 1 ) ) ;
153- right = Math . Max ( left + 1 , Math . Min ( right , resultFrame . Width ) ) ;
154- bottom = Math . Max ( top + 1 , Math . Min ( bottom , resultFrame . Height ) ) ;
155-
156- Rectangle bounds = Rectangle . FromLTRB ( left , top , right , bottom ) ;
151+ Rectangle bounds = Rectangle . FromLTRB (
152+ left = Numerics . Clamp ( left , 0 , resultFrame . Width - 1 ) ,
153+ top = Numerics . Clamp ( top , 0 , resultFrame . Height - 1 ) ,
154+ Numerics . Clamp ( right , left + 1 , resultFrame . Width ) ,
155+ Numerics . Clamp ( bottom , top + 1 , resultFrame . Height ) ) ;
157156
158157 // Webp requires even bounds
159158 if ( clampingMode == ClampingMode . Even )
@@ -172,7 +171,7 @@ public static void CopySource<TPixel>(ImageFrame<TPixel> source, ImageFrame<TPix
172171 {
173172 Buffer2DRegion < TPixel > sourceBuffer = source . PixelBuffer . GetRegion ( bounds ) ;
174173 Buffer2DRegion < TPixel > destBuffer = destination . PixelBuffer . GetRegion ( bounds ) ;
175- for ( int y = 0 ; y < destination . Height ; y ++ )
174+ for ( int y = 0 ; y < destBuffer . Height ; y ++ )
176175 {
177176 Span < TPixel > sourceRow = sourceBuffer . DangerousGetRowSpan ( y ) ;
178177 Span < TPixel > destRow = destBuffer . DangerousGetRowSpan ( y ) ;
0 commit comments