|
|
@ -29,6 +29,22 @@ namespace SixLabors.ImageSharp |
|
|
return (x ^ y) - y; |
|
|
return (x ^ y) - y; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns a specified number raised to the power of 2
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="x">A single-precision floating-point number</param>
|
|
|
|
|
|
/// <returns>The number <paramref name="x" /> raised to the power of 2.</returns>
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
|
|
public static float Pow2(float x) => x * x; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns a specified number raised to the power of 3
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="x">A single-precision floating-point number</param>
|
|
|
|
|
|
/// <returns>The number <paramref name="x" /> raised to the power of 3.</returns>
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
|
|
public static float Pow3(float x) => x * x * x; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Returns how many bits are required to store the specified number of colors.
|
|
|
/// Returns how many bits are required to store the specified number of colors.
|
|
|
/// Performs a Log2() on the value.
|
|
|
/// Performs a Log2() on the value.
|
|
|
@ -38,10 +54,7 @@ namespace SixLabors.ImageSharp |
|
|
/// The <see cref="int"/>
|
|
|
/// The <see cref="int"/>
|
|
|
/// </returns>
|
|
|
/// </returns>
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static int GetBitsNeededForColorDepth(int colors) |
|
|
public static int GetBitsNeededForColorDepth(int colors) => (int)Math.Ceiling(Math.Log(colors, 2)); |
|
|
{ |
|
|
|
|
|
return (int)Math.Ceiling(Math.Log(colors, 2)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Implementation of 1D Gaussian G(x) function
|
|
|
/// Implementation of 1D Gaussian G(x) function
|
|
|
@ -56,7 +69,7 @@ namespace SixLabors.ImageSharp |
|
|
float denominator = MathF.Sqrt(2 * MathF.PI) * sigma; |
|
|
float denominator = MathF.Sqrt(2 * MathF.PI) * sigma; |
|
|
|
|
|
|
|
|
float exponentNumerator = -x * x; |
|
|
float exponentNumerator = -x * x; |
|
|
float exponentDenominator = (float)(2 * Math.Pow(sigma, 2)); |
|
|
float exponentDenominator = 2 * Pow2(sigma); |
|
|
|
|
|
|
|
|
float left = Numerator / denominator; |
|
|
float left = Numerator / denominator; |
|
|
float right = MathF.Exp(exponentNumerator / exponentDenominator); |
|
|
float right = MathF.Exp(exponentNumerator / exponentDenominator); |
|
|
@ -98,14 +111,12 @@ namespace SixLabors.ImageSharp |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static float GetBcValue(float x, float b, float c) |
|
|
public static float GetBcValue(float x, float b, float c) |
|
|
{ |
|
|
{ |
|
|
float temp; |
|
|
|
|
|
|
|
|
|
|
|
if (x < 0F) |
|
|
if (x < 0F) |
|
|
{ |
|
|
{ |
|
|
x = -x; |
|
|
x = -x; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
temp = x * x; |
|
|
float temp = x * x; |
|
|
if (x < 1F) |
|
|
if (x < 1F) |
|
|
{ |
|
|
{ |
|
|
x = ((12 - (9 * b) - (6 * c)) * (x * temp)) + ((-18 + (12 * b) + (6 * c)) * temp) + (6 - (2 * b)); |
|
|
x = ((12 - (9 * b) - (6 * c)) * (x * temp)) + ((-18 + (12 * b) + (6 * c)) * temp) + (6 - (2 * b)); |
|
|
@ -134,10 +145,7 @@ namespace SixLabors.ImageSharp |
|
|
/// The bounding <see cref="Rectangle"/>.
|
|
|
/// The bounding <see cref="Rectangle"/>.
|
|
|
/// </returns>
|
|
|
/// </returns>
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public static Rectangle GetBoundingRectangle(Point topLeft, Point bottomRight) |
|
|
public static Rectangle GetBoundingRectangle(Point topLeft, Point bottomRight) => new Rectangle(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y); |
|
|
{ |
|
|
|
|
|
return new Rectangle(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Finds the bounding rectangle based on the first instance of any color component other
|
|
|
/// Finds the bounding rectangle based on the first instance of any color component other
|
|
|
|