Skip to content

Commit

Permalink
Merge pull request #1655 from SixLabors/js/fix-1616
Browse files Browse the repository at this point in the history
Use GreatestCommonDivisor to prevent overflow
  • Loading branch information
JimBobSquarePants committed Jun 11, 2021
2 parents 11e31ed + 87aec89 commit 381dff8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public static ResizeKernelMap Calculate<TResampler>(
int radius = (int)TolerantMath.Ceiling(scale * sampler.Radius);

// 'ratio' is a rational number.
// Multiplying it by LCM(sourceSize, destSize)/sourceSize will result in a whole number "again".
// Multiplying it by destSize/GCD(sourceSize, destSize) will result in a whole number "again".
// This value is determining the length of the periods in repeating kernel map rows.
int period = Numerics.LeastCommonMultiple(sourceSize, destinationSize) / sourceSize;
int period = destinationSize / Numerics.GreatestCommonDivisor(sourceSize, destinationSize);

// the center position at i == 0:
double center0 = (ratio - 1) * 0.5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public static readonly TheoryData<IResampler, int, int> KernelMapData
{ KnownResamplers.Bicubic, 1680, 1200 },
{ KnownResamplers.Box, 13, 299 },
{ KnownResamplers.Lanczos5, 3032, 600 },

// Large number. https://github.com/SixLabors/ImageSharp/issues/1616
{ KnownResamplers.Bicubic, 207773, 51943 }
};

public static TheoryData<string, int, int> GeneratedImageResizeData =
Expand Down

0 comments on commit 381dff8

Please sign in to comment.