Browse Source

reduce to a single par of clamping operations

pull/2610/head
Scott Williams 2 years ago
parent
commit
6c7b59fc06
  1. 16
      src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs

16
src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs

@ -96,19 +96,9 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
top = 0;
}
if (left > source.Width - foregroundRectangle.Width)
{
// will overhange, lets trim it down
int diff = (left + foregroundRectangle.Width) - source.Width;
foregroundRectangle.Width -= diff;
}
if (top > source.Height - foregroundRectangle.Height)
{
// will overhange, lets trim it down
int diff = (top + foregroundRectangle.Height) - source.Height;
foregroundRectangle.Height -= diff;
}
// clamp the height/width to the availible space left to prevent overflowing
foregroundRectangle.Width = Math.Min(source.Width - left, foregroundRectangle.Width);
foregroundRectangle.Height = Math.Min(source.Height - top, foregroundRectangle.Height);
int width = foregroundRectangle.Width;
int height = foregroundRectangle.Height;

Loading…
Cancel
Save