Browse Source

inline division as it's only used in some cases (and done at most once)

pull/771/head
Peter Amrehn 7 years ago
committed by Unknown
parent
commit
ea6fc641c3
  1. 6
      src/ImageSharp/Processing/ResizeHelper.cs

6
src/ImageSharp/Processing/ResizeHelper.cs

@ -337,21 +337,19 @@ namespace SixLabors.ImageSharp.Processing
float percentHeight = MathF.Abs(height / (float)sourceHeight);
float percentWidth = MathF.Abs(width / (float)sourceWidth);
float sourceRatio = (float)sourceHeight / sourceWidth;
// Find the shortest distance to go.
int widthDiff = sourceWidth - width;
int heightDiff = sourceHeight - height;
if (widthDiff < heightDiff)
{
destinationHeight = (int)MathF.Round(width * sourceRatio);
destinationHeight = (int)MathF.Round(width * ((float)sourceHeight / sourceWidth));
height = destinationHeight;
destinationWidth = width;
}
else if (widthDiff > heightDiff)
{
destinationWidth = (int)MathF.Round(height / sourceRatio);
destinationWidth = (int)MathF.Round(height * ((float)sourceWidth / sourceHeight));
destinationHeight = height;
width = destinationWidth;
}

Loading…
Cancel
Save