diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
index 6045a9c6a..eb3c29dd9 100644
--- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
+++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
@@ -1,54 +1,54 @@
-
- An extension to ImageSharp that allows the drawing of images, paths, and text.
- SixLabors.ImageSharp.Drawing
- $(packageversion)
- 0.0.1
- Six Labor and contributors
- netstandard1.1
- true
- true
- SixLabors.ImageSharp.Drawing
- SixLabors.ImageSharp.Drawing
- Image Draw Shape Path Font
- https://raw.githubusercontent.com/SixLabors/ImageSharp/master/build/icons/imagesharp-logo-128.png
- https://github.com/SixLabors/ImageSharp
- http://www.apache.org/licenses/LICENSE-2.0
- git
- https://github.com/SixLabors/ImageSharp
- false
- false
- false
- false
- false
- false
- false
- false
- false
- full
- portable
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
- All
-
-
-
- ..\..\ImageSharp.ruleset
- SixLabors.ImageSharp.Drawing
-
-
- true
-
+
+ An extension to ImageSharp that allows the drawing of images, paths, and text.
+ SixLabors.ImageSharp.Drawing
+ $(packageversion)
+ 0.0.1
+ SixLabors and contributors
+ netstandard1.1;netstandard2.0
+ true
+ true
+ SixLabors.ImageSharp.Drawing
+ SixLabors.ImageSharp.Drawing
+ Image Draw Shape Path Font
+ https://raw.githubusercontent.com/SixLabors/ImageSharp/master/build/icons/imagesharp-logo-128.png
+ https://github.com/SixLabors/ImageSharp
+ http://www.apache.org/licenses/LICENSE-2.0
+ git
+ https://github.com/SixLabors/ImageSharp
+ false
+ false
+ false
+ false
+ false
+ false
+ false
+ false
+ false
+ full
+ portable
+ True
+
+
+
+
+
+
+
+
+
+
+
+
+
+ All
+
+
+
+ ..\..\ImageSharp.ruleset
+ SixLabors.ImageSharp.Drawing
+
+
+ true
+
\ No newline at end of file
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieLabToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieLabToCieXyzConverter.cs
index 75689d997..0a5ae3627 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieLabToCieXyzConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieLabToCieXyzConverter.cs
@@ -1,8 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
-using SixLabors.ImageSharp.ColorSpaces;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLabColorSapce
{
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieXyzToCieLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieXyzToCieLabConverter.cs
index 33a8dc7c8..22308260c 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieXyzToCieLabConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLab/CieXyzToCieLabConverter.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CIeLchToCieLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CIeLchToCieLabConverter.cs
index 3884d9480..35fae30e8 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CIeLchToCieLabConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CIeLchToCieLabConverter.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces;
@@ -20,7 +21,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchColor
// Conversion algorithm described here:
// https://en.wikipedia.org/wiki/Lab_color_space#Cylindrical_representation:_CIELCh_or_CIEHLC
float l = input.L, c = input.C, hDegrees = input.H;
- float hRadians = MathF.DegreeToRadian(hDegrees);
+ float hRadians = MathFExtensions.DegreeToRadian(hDegrees);
float a = c * MathF.Cos(hRadians);
float b = c * MathF.Sin(hRadians);
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CieLabToCieLchConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CieLabToCieLchConverter.cs
index 50332ebdc..aa4614f9c 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CieLabToCieLchConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLch/CieLabToCieLchConverter.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces;
@@ -22,7 +23,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchColor
float l = input.L, a = input.A, b = input.B;
float c = MathF.Sqrt((a * a) + (b * b));
float hRadians = MathF.Atan2(b, a);
- float hDegrees = MathF.RadianToDegree(hRadians);
+ float hDegrees = MathFExtensions.RadianToDegree(hRadians);
// Wrap the angle round at 360.
hDegrees = hDegrees % 360;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLchuvToCieLuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLchuvToCieLuvConverter.cs
index ceadb0195..fc6554a90 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLchuvToCieLuvConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLchuvToCieLuvConverter.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces;
@@ -20,7 +21,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuvCol
// Conversion algorithm described here:
// https://en.wikipedia.org/wiki/CIELUV#Cylindrical_representation_.28CIELCH.29
float l = input.L, c = input.C, hDegrees = input.H;
- float hRadians = MathF.DegreeToRadian(hDegrees);
+ float hRadians = MathFExtensions.DegreeToRadian(hDegrees);
float u = c * MathF.Cos(hRadians);
float v = c * MathF.Sin(hRadians);
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLuvToCieLchuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLuvToCieLchuvConverter.cs
index d30151920..f0d7a80a2 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLuvToCieLchuvConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLchuv/CieLuvToCieLchuvConverter.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces;
@@ -22,7 +23,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.CieLchuvCol
float l = input.L, a = input.U, b = input.V;
float c = MathF.Sqrt((a * a) + (b * b));
float hRadians = MathF.Atan2(b, a);
- float hDegrees = MathF.RadianToDegree(hRadians);
+ float hDegrees = MathFExtensions.RadianToDegree(hRadians);
// Wrap the angle round at 360.
hDegrees = hDegrees % 360;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieLuvToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieLuvToCieXyzConverter.cs
index 4fb8fdc80..50e8335ed 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieLuvToCieXyzConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieLuvToCieXyzConverter.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieXyzToCieLuvConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieXyzToCieLuvConverter.cs
index 82b1b1d3f..709d8d426 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieXyzToCieLuvConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieLuv/CieXyzToCieLuvConverter.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyy/CieXyzAndCieXyyConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyy/CieXyzAndCieXyyConverter.cs
index 31868ec11..64fc84b1d 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyy/CieXyzAndCieXyyConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/CieXyy/CieXyzAndCieXyyConverter.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsl/HslAndRgbConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsl/HslAndRgbConverter.cs
index 917cd3bf8..3de3baddd 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsl/HslAndRgbConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Hsl/HslAndRgbConverter.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzToHunterLabConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzToHunterLabConverter.cs
index 8905a0a30..7faf03c9a 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzToHunterLabConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/CieXyzToHunterLabConverter.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/HunterLabToCieXyzConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/HunterLabToCieXyzConverter.cs
index 2cd379d85..7e7c536e3 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/HunterLabToCieXyzConverter.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/HunterLab/HunterLabToCieXyzConverter.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.ColorSpaces;
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LCompanding.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LCompanding.cs
index c73a3486e..132861b47 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LCompanding.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/LCompanding.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec2020Companding.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec2020Companding.cs
index f393b133c..11761f0e4 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec2020Companding.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec2020Companding.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec709Companding.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec709Companding.cs
index ba1b1379e..ccda6bf52 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec709Companding.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/Rec709Companding.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce
diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/SRgbCompanding.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/SRgbCompanding.cs
index 1e49c1159..ce8ea7c6e 100644
--- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/SRgbCompanding.cs
+++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/SRgbCompanding.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce
diff --git a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs
index 5fbc3960a..7cb193e82 100644
--- a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs
+++ b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs
@@ -1,9 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Numerics;
using System.Runtime.CompilerServices;
-using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
{
diff --git a/src/ImageSharp/Common/Helpers/ImageMaths.cs b/src/ImageSharp/Common/Helpers/ImageMaths.cs
index 8717fa987..7d781e77f 100644
--- a/src/ImageSharp/Common/Helpers/ImageMaths.cs
+++ b/src/ImageSharp/Common/Helpers/ImageMaths.cs
@@ -64,6 +64,27 @@ namespace SixLabors.ImageSharp
return left * right;
}
+ ///
+ /// Returns the result of a normalized sine cardinal function for the given value.
+ /// SinC(x) = sin(pi*x)/(pi*x).
+ ///
+ /// A single-precision floating-point number to calculate the result for.
+ ///
+ /// The sine cardinal of .
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static float SinC(float f)
+ {
+ if (MathF.Abs(f) > Constants.Epsilon)
+ {
+ f *= MathF.PI;
+ float result = MathF.Sin(f) / f;
+ return MathF.Abs(result) < Constants.Epsilon ? 0F : result;
+ }
+
+ return 1F;
+ }
+
///
/// Returns the result of a B-C filter against the given value.
///
diff --git a/src/ImageSharp/Common/Helpers/MathF.cs b/src/ImageSharp/Common/Helpers/MathF.cs
deleted file mode 100644
index 7d2f8063f..000000000
--- a/src/ImageSharp/Common/Helpers/MathF.cs
+++ /dev/null
@@ -1,291 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Runtime.CompilerServices;
-
-namespace SixLabors.ImageSharp
-{
- ///
- /// Provides single-precision floating point constants and static methods for trigonometric, logarithmic, and other common mathematical functions.
- ///
- // ReSharper disable InconsistentNaming
- internal static class MathF
- {
- ///
- /// Represents the ratio of the circumference of a circle to its diameter, specified by the constant, π.
- ///
- public const float PI = (float)Math.PI;
-
- ///
- /// Returns the absolute value of a single-precision floating-point number.
- ///
- ///
- /// A number that is greater than or equal to , but less than or equal to .
- ///
- ///
- /// A single-precision floating-point number, x, such that 0 ≤ x ≤.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Abs(float f)
- {
- return Math.Abs(f);
- }
-
- ///
- /// Returns the angle whose tangent is the quotient of two specified numbers.
- ///
- /// The y coordinate of a point.
- /// The x coordinate of a point.
- ///
- /// An angle, θ, measured in radians, such that -π≤θ≤π, and tan(θ) = y / x, where
- /// (x, y) is a point in the Cartesian plane. Observe the following: For (x, y) in
- /// quadrant 1, 0 < θ < π/2.For (x, y) in quadrant 2, π/2 < θ≤π.For (x, y) in quadrant
- /// 3, -π < θ < -π/2.For (x, y) in quadrant 4, -π/2 < θ < 0.For points on the boundaries
- /// of the quadrants, the return value is the following:If y is 0 and x is not negative,
- /// θ = 0.If y is 0 and x is negative, θ = π.If y is positive and x is 0, θ = π/2.If
- /// y is negative and x is 0, θ = -π/2.If y is 0 and x is 0, θ = 0. If x or y is
- /// , or if x and y are either or
- /// , the method returns .
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Atan2(float y, float x)
- {
- return (float)Math.Atan2(y, x);
- }
-
- ///
- /// Returns the smallest integral value that is greater than or equal to the specified single-precision floating-point number.
- ///
- /// A single-precision floating-point number.
- ///
- /// The smallest integral value that is greater than or equal to .
- /// If is equal to , ,
- /// or , that value is returned.
- /// Note that this method returns a instead of an integral type.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Ceiling(float f)
- {
- return (float)Math.Ceiling(f);
- }
-
- ///
- /// Returns the cosine of the specified angle.
- ///
- /// An angle, measured in radians.
- ///
- /// The cosine of . If is equal to , ,
- /// or , this method returns .
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Cos(float f)
- {
- return (float)Math.Cos(f);
- }
-
- ///
- /// Converts a degree (360-periodic) angle to a radian (2*Pi-periodic) angle.
- ///
- /// The angle in degrees.
- ///
- /// The representing the degree as radians.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float DegreeToRadian(float degree)
- {
- return degree * (PI / 180F);
- }
-
- ///
- /// Returns e raised to the specified power.
- ///
- /// A number specifying a power.
- ///
- /// The number e raised to the power .
- /// If equals or , that value is returned.
- /// If equals , 0 is returned.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Exp(float f)
- {
- return (float)Math.Exp(f);
- }
-
- ///
- /// Returns the largest integer less than or equal to the specified single-precision floating-point number.
- ///
- /// A single-precision floating-point number.
- ///
- /// The largest integer less than or equal to .
- /// If is equal to , ,
- /// or , that value is returned.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Floor(float f)
- {
- return (float)Math.Floor(f);
- }
-
- ///
- /// Returns the larger of two single-precision floating-point numbers.
- ///
- /// The first of two single-precision floating-point numbers to compare.
- /// The second of two single-precision floating-point numbers to compare.
- ///
- /// Parameter or , whichever is larger.
- /// If , or , or both and are
- /// equal to , is returned.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Max(float val1, float val2)
- {
- return Math.Max(val1, val2);
- }
-
- ///
- /// Returns the smaller of two single-precision floating-point numbers.
- ///
- /// The first of two single-precision floating-point numbers to compare.
- /// The second of two single-precision floating-point numbers to compare.
- ///
- /// Parameter or , whichever is smaller.
- /// If , , or both and are equal
- /// to , is returned.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Min(float val1, float val2)
- {
- return Math.Min(val1, val2);
- }
-
- ///
- /// Returns a specified number raised to the specified power.
- ///
- /// A single-precision floating-point number to be raised to a power.
- /// A single-precision floating-point number that specifies a power.
- /// The number raised to the power .
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Pow(float x, float y)
- {
- return (float)Math.Pow(x, y);
- }
-
- ///
- /// Converts a radian (2*Pi-periodic) angle to a degree (360-periodic) angle.
- ///
- /// The angle in radians.
- ///
- /// The representing the degree as radians.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float RadianToDegree(float radian)
- {
- return radian / (PI / 180F);
- }
-
- ///
- /// Rounds a single-precision floating-point value to the nearest integral value.
- ///
- /// A single-precision floating-point number to be rounded.
- ///
- /// The integer nearest .
- /// If the fractional component of is halfway between two integers, one of which is even and the other odd, then the even number is returned.
- /// Note that this method returns a instead of an integral type.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Round(float f)
- {
- return (float)Math.Round(f);
- }
-
- ///
- /// Rounds a single-precision floating-point value to the nearest integer.
- /// A parameter specifies how to round the value if it is midway between two numbers.
- ///
- /// A single-precision floating-point number to be rounded.
- /// Specification for how to round if it is midway between two other numbers.
- ///
- /// The integer nearest . If is halfway between two integers, one of which is even
- /// and the other odd, then determines which of the two is returned.
- /// Note that this method returns a instead of an integral type.
- ///
- ///
- /// is not a valid value of .
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Round(float f, MidpointRounding mode)
- {
- return (float)Math.Round(f, mode);
- }
-
- ///
- /// Returns the sine of the specified angle.
- ///
- /// An angle, measured in radians.
- ///
- /// The sine of .
- /// If is equal to , ,
- /// or , this method returns .
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Sin(float f)
- {
- return (float)Math.Sin(f);
- }
-
- ///
- /// Returns the result of a normalized sine cardinal function for the given value.
- /// SinC(x) = sin(pi*x)/(pi*x).
- ///
- /// A single-precision floating-point number to calculate the result for.
- ///
- /// The sine cardinal of .
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float SinC(float f)
- {
- if (Abs(f) > Constants.Epsilon)
- {
- f *= PI;
- return Clean(Sin(f) / f);
- }
-
- return 1F;
- }
-
- ///
- /// Returns the square root of a specified number.
- ///
- /// The number whose square root is to be found.
- ///
- /// One of the values in the following table.
- /// parameter Return value Zero or positive The positive square root of .
- /// Negative Equals
- /// Equals
- ///
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Sqrt(float f)
- {
- return (float)Math.Sqrt(f);
- }
-
- ///
- /// Ensures that any passed float is correctly rounded to zero
- ///
- /// The value to clean.
- ///
- /// The
- /// .
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static float Clean(float x)
- {
- if (Abs(x) < Constants.Epsilon)
- {
- return 0F;
- }
-
- return x;
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs b/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs
index e0e11ad9e..689c9a85b 100644
--- a/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs
+++ b/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs
@@ -17,12 +17,12 @@ namespace SixLabors.ImageSharp.Dithering
/// The source pixel
/// The color to apply to the pixels above the threshold.
/// The color to apply to the pixels below the threshold.
- /// The byte array to pack/unpack to. Must have a length of 4. Bytes are unpacked to Xyzw order.
+ /// The to pack/unpack to.
/// The component index to test the threshold against. Must range from 0 to 3.
/// The column index.
/// The row index.
/// The pixel format.
- void Dither(ImageFrame image, TPixel source, TPixel upper, TPixel lower, byte[] bytes, int index, int x, int y)
+ void Dither(ImageFrame image, TPixel source, TPixel upper, TPixel lower, ref Rgba32 rgba, int index, int x, int y)
where TPixel : struct, IPixel;
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Dithering/Ordered/OrderedDitherBase.cs b/src/ImageSharp/Dithering/Ordered/OrderedDitherBase.cs
index 09c30eb27..818a24d5d 100644
--- a/src/ImageSharp/Dithering/Ordered/OrderedDitherBase.cs
+++ b/src/ImageSharp/Dithering/Ordered/OrderedDitherBase.cs
@@ -1,13 +1,14 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Dithering.Base
{
///
- /// The base class for performing ordered ditheroing using a 4x4 matrix.
+ /// The base class for performing ordered dithering using a 4x4 matrix.
///
public abstract class OrderedDitherBase : IOrderedDither
{
@@ -26,14 +27,27 @@ namespace SixLabors.ImageSharp.Dithering.Base
}
///
- public void Dither(ImageFrame image, TPixel source, TPixel upper, TPixel lower, byte[] bytes, int index, int x, int y)
+ public void Dither(ImageFrame image, TPixel source, TPixel upper, TPixel lower, ref Rgba32 rgba, int index, int x, int y)
where TPixel : struct, IPixel
{
- // TODO: This doesn't really cut it for me.
- // I'd rather be using float but we need to add some sort of normalization vector methods to all IPixel implementations
- // before we can do that as the vectors all cover different ranges.
- source.ToXyzwBytes(bytes, 0);
- image[x, y] = this.matrix[y % 3, x % 3] >= bytes[index] ? lower : upper;
+ source.ToRgba32(ref rgba);
+ switch (index)
+ {
+ case 0:
+ image[x, y] = this.matrix[y % 3, x % 3] >= rgba.R ? lower : upper;
+ return;
+ case 1:
+ image[x, y] = this.matrix[y % 3, x % 3] >= rgba.G ? lower : upper;
+ return;
+ case 2:
+ image[x, y] = this.matrix[y % 3, x % 3] >= rgba.B ? lower : upper;
+ return;
+ case 3:
+ image[x, y] = this.matrix[y % 3, x % 3] >= rgba.A ? lower : upper;
+ return;
+ }
+
+ throw new ArgumentOutOfRangeException(nameof(index), "Index should be between 0 and 3 inclusive.");
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
index 1b145a79e..41c8e944d 100644
--- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
@@ -351,16 +351,16 @@ namespace SixLabors.ImageSharp.Formats.Gif
// Get max colors for bit depth.
int colorTableLength = (int)Math.Pow(2, this.bitDepth) * 3;
byte[] colorTable = ArrayPool.Shared.Rent(colorTableLength);
-
+ var rgb = default(Rgb24);
try
{
for (int i = 0; i < pixelCount; i++)
{
int offset = i * 3;
- image.Palette[i].ToXyzBytes(this.buffer, 0);
- colorTable[offset] = this.buffer[0];
- colorTable[offset + 1] = this.buffer[1];
- colorTable[offset + 2] = this.buffer[2];
+ image.Palette[i].ToRgb24(ref rgb);
+ colorTable[offset] = rgb.R;
+ colorTable[offset + 1] = rgb.G;
+ colorTable[offset + 2] = rgb.B;
}
writer.Write(colorTable, 0, colorTableLength);
diff --git a/src/ImageSharp/Formats/Jpeg/Common/SizeExtensions.cs b/src/ImageSharp/Formats/Jpeg/Common/SizeExtensions.cs
index f6b02bbaf..978688673 100644
--- a/src/ImageSharp/Formats/Jpeg/Common/SizeExtensions.cs
+++ b/src/ImageSharp/Formats/Jpeg/Common/SizeExtensions.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Numerics;
using SixLabors.Primitives;
diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
index 86a63f5b4..0efd46ec7 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
@@ -318,6 +318,7 @@ namespace SixLabors.ImageSharp.Formats.Png
where TPixel : struct, IPixel
{
byte[] rawScanlineArray = this.rawScanline.Array;
+ var rgba = default(Rgba32);
// Copy the pixels across from the image.
// Reuse the chunk type buffer.
@@ -326,8 +327,8 @@ namespace SixLabors.ImageSharp.Formats.Png
// Convert the color to YCbCr and store the luminance
// Optionally store the original color alpha.
int offset = x * this.bytesPerPixel;
- rowSpan[x].ToXyzwBytes(this.chunkTypeBuffer, 0);
- byte luminance = (byte)((0.299F * this.chunkTypeBuffer[0]) + (0.587F * this.chunkTypeBuffer[1]) + (0.114F * this.chunkTypeBuffer[2]));
+ rowSpan[x].ToRgba32(ref rgba);
+ byte luminance = (byte)((0.299F * rgba.R) + (0.587F * rgba.G) + (0.114F * rgba.B));
for (int i = 0; i < this.bytesPerPixel; i++)
{
@@ -337,7 +338,7 @@ namespace SixLabors.ImageSharp.Formats.Png
}
else
{
- rawScanlineArray[offset + i] = this.chunkTypeBuffer[3];
+ rawScanlineArray[offset + i] = rgba.A;
}
}
}
@@ -518,7 +519,7 @@ namespace SixLabors.ImageSharp.Formats.Png
int colorTableLength = (int)Math.Pow(2, header.BitDepth) * 3;
byte[] colorTable = ArrayPool.Shared.Rent(colorTableLength);
byte[] alphaTable = ArrayPool.Shared.Rent(pixelCount);
- byte[] bytes = ArrayPool.Shared.Rent(4);
+ var rgba = default(Rgba32);
bool anyAlpha = false;
try
{
@@ -527,13 +528,13 @@ namespace SixLabors.ImageSharp.Formats.Png
if (quantized.Pixels.Contains(i))
{
int offset = i * 3;
- palette[i].ToXyzwBytes(bytes, 0);
+ palette[i].ToRgba32(ref rgba);
- byte alpha = bytes[3];
+ byte alpha = rgba.A;
- colorTable[offset] = bytes[0];
- colorTable[offset + 1] = bytes[1];
- colorTable[offset + 2] = bytes[2];
+ colorTable[offset] = rgba.R;
+ colorTable[offset + 1] = rgba.G;
+ colorTable[offset + 2] = rgba.B;
if (alpha > this.threshold)
{
@@ -557,7 +558,6 @@ namespace SixLabors.ImageSharp.Formats.Png
{
ArrayPool.Shared.Return(colorTable);
ArrayPool.Shared.Return(alphaTable);
- ArrayPool.Shared.Return(bytes);
}
return quantized;
diff --git a/src/ImageSharp/Image/PixelAccessorExtensions.cs b/src/ImageSharp/Image/PixelAccessorExtensions.cs
index 9146ef48d..b628c05f8 100644
--- a/src/ImageSharp/Image/PixelAccessorExtensions.cs
+++ b/src/ImageSharp/Image/PixelAccessorExtensions.cs
@@ -1,14 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using System;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
-using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
-using Unsafe = System.Runtime.CompilerServices.Unsafe;
namespace SixLabors.ImageSharp
{
diff --git a/src/ImageSharp/Image/PixelAccessor{TPixel}.cs b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs
index 3abe28aca..8dcb1f760 100644
--- a/src/ImageSharp/Image/PixelAccessor{TPixel}.cs
+++ b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs
@@ -7,7 +7,6 @@ using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
-using Unsafe = System.Runtime.CompilerServices.Unsafe;
namespace SixLabors.ImageSharp
{
diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj
index 45d0a70b8..8c22237cf 100644
--- a/src/ImageSharp/ImageSharp.csproj
+++ b/src/ImageSharp/ImageSharp.csproj
@@ -1,118 +1,120 @@
-
- A cross-platform library for the processing of image files; written in C#
- SixLabors.ImageSharp
- $(packageversion)
- 0.0.1
- Six Labors and contributors
- netstandard1.1;netstandard1.3
- true
- true
- SixLabors.ImageSharp
- SixLabors.ImageSharp
- Image Resize Crop Gif Jpg Jpeg Bitmap Png Core
- https://raw.githubusercontent.com/SixLabors/ImageSharp/master/build/icons/imagesharp-logo-128.png
- https://github.com/SixLabors/ImageSharp
- http://www.apache.org/licenses/LICENSE-2.0
- git
- https://github.com/SixLabors/ImageSharp
- false
- false
- false
- false
- false
- false
- false
- false
- false
- full
- portable
- True
- IOperation
-
-
-
-
-
-
-
-
- All
-
-
-
-
-
-
-
-
-
-
- ..\..\ImageSharp.ruleset
- SixLabors.ImageSharp
-
-
- true
-
-
-
- TextTemplatingFileGenerator
- Block8x8F.Generated.cs
-
-
- TextTemplatingFileGenerator
- Block8x8F.Generated.cs
-
-
- TextTemplatingFileGenerator
- PixelOperations{TPixel}.Generated.cs
-
-
- TextTemplatingFileGenerator
- Rgba32.PixelOperations.Generated.cs
-
-
- PorterDuffFunctions.Generated.cs
- TextTemplatingFileGenerator
-
-
- DefaultPixelBlenders.Generated.cs
- TextTemplatingFileGenerator
-
-
-
-
-
-
-
- True
- True
- Block8x8F.Generated.tt
-
-
- True
- True
- Block8x8F.Generated.tt
-
-
- True
- True
- PixelOperations{TPixel}.Generated.tt
-
-
- True
- True
- Rgba32.PixelOperations.Generated.tt
-
-
- True
- True
- DefaultPixelBlenders.Generated.tt
-
-
- True
- True
- PorterDuffFunctions.Generated.tt
-
-
+
+ A cross-platform library for the processing of image files; written in C#
+ SixLabors.ImageSharp
+ $(packageversion)
+ 0.0.1
+ Six Labors and contributors
+ netstandard1.1;netstandard1.3;netstandard2.0
+ true
+ true
+ SixLabors.ImageSharp
+ SixLabors.ImageSharp
+ Image Resize Crop Gif Jpg Jpeg Bitmap Png Core
+ https://raw.githubusercontent.com/SixLabors/ImageSharp/master/build/icons/imagesharp-logo-128.png
+ https://github.com/SixLabors/ImageSharp
+ http://www.apache.org/licenses/LICENSE-2.0
+ git
+ https://github.com/SixLabors/ImageSharp
+ false
+ false
+ false
+ false
+ false
+ false
+ false
+ false
+ false
+ full
+ portable
+ True
+ IOperation
+
+
+
+
+
+
+
+
+ All
+
+
+
+
+
+
+
+
+
+
+
+
+ ..\..\ImageSharp.ruleset
+ SixLabors.ImageSharp
+
+
+ true
+
+
+
+ TextTemplatingFileGenerator
+ Block8x8F.Generated.cs
+
+
+ TextTemplatingFileGenerator
+ Block8x8F.Generated.cs
+
+
+ TextTemplatingFileGenerator
+ PixelOperations{TPixel}.Generated.cs
+
+
+ TextTemplatingFileGenerator
+ Rgba32.PixelOperations.Generated.cs
+
+
+ PorterDuffFunctions.Generated.cs
+ TextTemplatingFileGenerator
+
+
+ DefaultPixelBlenders.Generated.cs
+ TextTemplatingFileGenerator
+
+
+
+
+
+
+
+ True
+ True
+ Block8x8F.Generated.tt
+
+
+ True
+ True
+ Block8x8F.Generated.tt
+
+
+ True
+ True
+ PixelOperations{TPixel}.Generated.tt
+
+
+ True
+ True
+ Rgba32.PixelOperations.Generated.tt
+
+
+ True
+ True
+ DefaultPixelBlenders.Generated.tt
+
+
+ True
+ True
+ PorterDuffFunctions.Generated.tt
+
+
\ No newline at end of file
diff --git a/src/ImageSharp/Memory/SpanHelper.cs b/src/ImageSharp/Memory/SpanHelper.cs
index 8b9fad522..73bc5f55d 100644
--- a/src/ImageSharp/Memory/SpanHelper.cs
+++ b/src/ImageSharp/Memory/SpanHelper.cs
@@ -4,7 +4,6 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
-using Unsafe = System.Runtime.CompilerServices.Unsafe;
namespace SixLabors.ImageSharp.Memory
{
diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs
index efdd275b4..21ae335be 100644
--- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs
@@ -2,11 +2,13 @@
// Licensed under the Apache License, Version 2.0.
//
+
+using System;
+using System.Numerics;
+using System.Runtime.CompilerServices;
+
namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
{
- using System.Numerics;
- using System.Runtime.CompilerServices;
-
internal static partial class PorterDuffFunctions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt
index e6a2ca3eb..c92ab6dd6 100644
--- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt
+++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt
@@ -12,11 +12,13 @@
// Licensed under the Apache License, Version 2.0.
//
+
+using System;
+using System.Numerics;
+using System.Runtime.CompilerServices;
+
namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
{
- using System.Numerics;
- using System.Runtime.CompilerServices;
-
internal static partial class PorterDuffFunctions
{
<#
diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs
index 04c750255..f09d6d51c 100644
--- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs
+++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Numerics;
using System.Runtime.CompilerServices;
diff --git a/src/ImageSharp/PixelFormats/PixelConversionExtensions.cs b/src/ImageSharp/PixelFormats/PixelConversionExtensions.cs
deleted file mode 100644
index 37b225d2e..000000000
--- a/src/ImageSharp/PixelFormats/PixelConversionExtensions.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Runtime.CompilerServices;
-
-namespace SixLabors.ImageSharp.PixelFormats
-{
- ///
- /// Extension methods for copying single pixel data into byte Spans.
- /// TODO: This utility class exists for legacy reasons. Need to do a lot of chore work to remove it (mostly in test classes).
- ///
- internal static class PixelConversionExtensions
- {
- ///
- /// Expands the packed representation into a given byte array.
- /// Output is expanded to X-> Y-> Z order. Equivalent to R-> G-> B in
- ///
- /// The pixel type.
- /// The pixel to copy the data from.
- /// The bytes to set the color in.
- /// The starting index of the .
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void ToXyzBytes(this TPixel pixel, Span bytes, int startIndex)
- where TPixel : struct, IPixel
- {
- ref Rgb24 dest = ref bytes.GetRgb24(startIndex);
- pixel.ToRgb24(ref dest);
- }
-
- ///
- /// Expands the packed representation into a given byte array.
- /// Output is expanded to X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in
- ///
- /// The pixel type.
- /// The pixel to copy the data from.
- /// The bytes to set the color in.
- /// The starting index of the .
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void ToXyzwBytes(this TPixel pixel, Span bytes, int startIndex)
- where TPixel : struct, IPixel
- {
- ref Rgba32 dest = ref Unsafe.As(ref bytes[startIndex]);
- pixel.ToRgba32(ref dest);
- }
-
- ///
- /// Expands the packed representation into a given byte array.
- /// Output is expanded to Z-> Y-> X order. Equivalent to B-> G-> R in
- ///
- /// The pixel type.
- /// The pixel to copy the data from.
- /// The bytes to set the color in.
- /// The starting index of the .
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void ToZyxBytes(this TPixel pixel, Span bytes, int startIndex)
- where TPixel : struct, IPixel
- {
- ref Bgr24 dest = ref Unsafe.As(ref bytes[startIndex]);
- pixel.ToBgr24(ref dest);
- }
-
- ///
- /// Expands the packed representation into a given byte array.
- /// Output is expanded to Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in
- ///
- /// The pixel type.
- /// The pixel to copy the data from.
- /// The bytes to set the color in.
- /// The starting index of the .
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void ToZyxwBytes(this TPixel pixel, Span bytes, int startIndex)
- where TPixel : struct, IPixel
- {
- ref Bgra32 dest = ref Unsafe.As(ref bytes[startIndex]);
- pixel.ToBgra32(ref dest);
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs
index 203a64cf1..a2fd17c94 100644
--- a/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs
@@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
int startX = interest.X;
int endX = interest.Right;
- byte[] bytes = new byte[4];
+ var rgba = default(Rgba32);
for (int y = startY; y < endY; y++)
{
Span row = source.GetPixelRowSpan(y);
@@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
for (int x = startX; x < endX; x++)
{
TPixel sourceColor = row[x];
- this.Dither.Dither(source, sourceColor, this.UpperColor, this.LowerColor, bytes, this.Index, x, y);
+ this.Dither.Dither(source, sourceColor, this.UpperColor, this.LowerColor, ref rgba, this.Index, x, y);
}
}
}
diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs
index 9a40bfca8..adfdb6a78 100644
--- a/src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@@ -30,7 +31,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
this.Angle = angle;
- float radians = MathF.DegreeToRadian(angle);
+ float radians = MathFExtensions.DegreeToRadian(angle);
float cosradians = MathF.Cos(radians);
float sinradians = MathF.Sin(radians);
diff --git a/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs b/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs
index 152b451e2..17a0cc428 100644
--- a/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs
+++ b/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Linq;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs
index deaa0ccb9..29568db02 100644
--- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs
+++ b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos2Resampler.cs
@@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Processing
if (x < 2F)
{
- return MathF.SinC(x) * MathF.SinC(x / 2F);
+ return ImageMaths.SinC(x) * ImageMaths.SinC(x / 2F);
}
return 0F;
diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs
index 2673c3491..492ef69e4 100644
--- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs
+++ b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos3Resampler.cs
@@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Processing
if (x < 3F)
{
- return MathF.SinC(x) * MathF.SinC(x / 3F);
+ return ImageMaths.SinC(x) * ImageMaths.SinC(x / 3F);
}
return 0F;
diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs
index c52670e2d..cae152a53 100644
--- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs
+++ b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos5Resampler.cs
@@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Processing
if (x < 5F)
{
- return MathF.SinC(x) * MathF.SinC(x / 5F);
+ return ImageMaths.SinC(x) * ImageMaths.SinC(x / 5F);
}
return 0F;
diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs
index 552d3065b..b390c5541 100644
--- a/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs
+++ b/src/ImageSharp/Processing/Transforms/Resamplers/Lanczos8Resampler.cs
@@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Processing
if (x < 8F)
{
- return MathF.SinC(x) * MathF.SinC(x / 8F);
+ return ImageMaths.SinC(x) * ImageMaths.SinC(x / 8F);
}
return 0F;
diff --git a/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs b/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs
index e154d5483..acb74a8ec 100644
--- a/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs
+++ b/src/ImageSharp/Processing/Transforms/Resamplers/WelchResampler.cs
@@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Processing
if (x < 3F)
{
- return MathF.SinC(x) * (1F - (x * x / 9F));
+ return ImageMaths.SinC(x) * (1F - (x * x / 9F));
}
return 0F;
diff --git a/src/ImageSharp/Processing/Transforms/Resize.cs b/src/ImageSharp/Processing/Transforms/Resize.cs
index 7897e8f30..3c7cbca31 100644
--- a/src/ImageSharp/Processing/Transforms/Resize.cs
+++ b/src/ImageSharp/Processing/Transforms/Resize.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
diff --git a/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs b/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs
index 8ab390f4e..44311e080 100644
--- a/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs
+++ b/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs
@@ -60,11 +60,6 @@ namespace SixLabors.ImageSharp.Quantizers
///
private const int TableLength = IndexCount * IndexCount * IndexCount * IndexAlphaCount;
- ///
- /// A buffer for storing pixels
- ///
- private readonly byte[] rgbaBuffer = new byte[4];
-
///
/// A lookup table for colors
///
@@ -199,19 +194,15 @@ namespace SixLabors.ImageSharp.Quantizers
{
// Add the color to a 3-D color histogram.
// Colors are expected in r->g->b->a format
- pixel.ToXyzwBytes(this.rgbaBuffer, 0);
-
- byte r = this.rgbaBuffer[0];
- byte g = this.rgbaBuffer[1];
- byte b = this.rgbaBuffer[2];
- byte a = this.rgbaBuffer[3];
+ var rgba = default(Rgba32);
+ pixel.ToRgba32(ref rgba);
- int inr = r >> (8 - IndexBits);
- int ing = g >> (8 - IndexBits);
- int inb = b >> (8 - IndexBits);
- int ina = a >> (8 - IndexAlphaBits);
+ int r = rgba.R >> 2; // 8 - IndexBits
+ int g = rgba.G >> 2;
+ int b = rgba.B >> 2;
+ int a = rgba.A >> 5; // 8 - IndexAlphaBits
- int ind = GetPaletteIndex(inr + 1, ing + 1, inb + 1, ina + 1);
+ int ind = GetPaletteIndex(r + 1, g + 1, b + 1, a + 1);
this.vwt[ind]++;
this.vmr[ind] += r;
@@ -840,12 +831,13 @@ namespace SixLabors.ImageSharp.Quantizers
}
// Expected order r->g->b->a
- pixel.ToXyzwBytes(this.rgbaBuffer, 0);
+ var rgba = default(Rgba32);
+ pixel.ToRgba32(ref rgba);
- int r = this.rgbaBuffer[0] >> (8 - IndexBits);
- int g = this.rgbaBuffer[1] >> (8 - IndexBits);
- int b = this.rgbaBuffer[2] >> (8 - IndexBits);
- int a = this.rgbaBuffer[3] >> (8 - IndexAlphaBits);
+ int r = rgba.R >> (8 - IndexBits);
+ int g = rgba.G >> (8 - IndexBits);
+ int b = rgba.B >> (8 - IndexBits);
+ int a = rgba.A >> (8 - IndexAlphaBits);
return this.tag[GetPaletteIndex(r + 1, g + 1, b + 1, a + 1)];
}
diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs
index e1f5e6106..2d624c19f 100644
--- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs
+++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs
@@ -35,11 +35,16 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
{
TPixel[] s = this.source.Array;
byte[] d = this.destination.Array;
+ var rgb = default(Rgb24);
for (int i = 0; i < this.Count; i++)
{
TPixel c = s[i];
- c.ToXyzBytes(d, i * 4);
+ int i3 = i * 3;
+ c.ToRgb24(ref rgb);
+ d[i3] = rgb.R;
+ d[i3 + 1] = rgb.G;
+ d[i3 + 2] = rgb.B;
}
}
diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs
index 603289763..150b55aed 100644
--- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs
+++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs
@@ -40,11 +40,17 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
{
TPixel[] s = this.source.Array;
byte[] d = this.destination.Array;
+ var rgba = default(Rgba32);
for (int i = 0; i < this.Count; i++)
{
TPixel c = s[i];
- c.ToXyzwBytes(d, i * 4);
+ int i4 = i * 4;
+ c.ToRgba32(ref rgba);
+ d[i4] = rgba.R;
+ d[i4 + 1] = rgba.G;
+ d[i4 + 2] = rgba.B;
+ d[i4 + 3] = rgba.A;
}
}
diff --git a/tests/ImageSharp.Benchmarks/General/Block8x8F_Round.cs b/tests/ImageSharp.Benchmarks/General/Block8x8F_Round.cs
index 2739877a6..d101bf050 100644
--- a/tests/ImageSharp.Benchmarks/General/Block8x8F_Round.cs
+++ b/tests/ImageSharp.Benchmarks/General/Block8x8F_Round.cs
@@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General
for (int i = 0; i < Block8x8F.Size; i++)
{
ref float v = ref Unsafe.Add(ref b, i);
- v = MathF.Round(v);
+ v = (float)Math.Round(v);
}
}
diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs
index 884ae3501..1f88c4fbf 100644
--- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs
+++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs
@@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.Benchmarks
int endX = sourceRectangle.Right;
TPixel glowColor = this.GlowColor;
Vector2 centre = Rectangle.Center(sourceRectangle);
- float maxDistance = this.Radius > 0 ? MathF.Min(this.Radius, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F;
+ float maxDistance = this.Radius > 0 ? Math.Min(this.Radius, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F;
// Align start/end positions.
int minX = Math.Max(0, startX);
@@ -136,13 +136,13 @@ namespace SixLabors.ImageSharp.Benchmarks
amount = amount.Clamp(0, 1);
// Santize on zero alpha
- if (MathF.Abs(backdrop.W) < Constants.Epsilon)
+ if (Math.Abs(backdrop.W) < Constants.Epsilon)
{
source.W *= amount;
return source;
}
- if (MathF.Abs(source.W) < Constants.Epsilon)
+ if (Math.Abs(source.W) < Constants.Epsilon)
{
return backdrop;
}
diff --git a/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs b/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs
index 15a794144..8014925e2 100644
--- a/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs
+++ b/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs
@@ -22,9 +22,9 @@ namespace SixLabors.ImageSharp.Tests.Common
this.Output = output;
}
- private static int R(float f) => (int)MathF.Round(f, MidpointRounding.AwayFromZero);
+ private static int R(float f) => (int)Math.Round(f, MidpointRounding.AwayFromZero);
- private static int Re(float f) => (int)MathF.Round(f, MidpointRounding.ToEven);
+ private static int Re(float f) => (int)Math.Round(f, MidpointRounding.ToEven);
// TODO: Move this to a proper test class!
[Theory]
@@ -168,7 +168,7 @@ namespace SixLabors.ImageSharp.Tests.Common
Assert.Equal(expected, dest);
}
- private static float Clamp255(float x) => MathF.Min(255f, MathF.Max(0f, x));
+ private static float Clamp255(float x) => Math.Min(255f, Math.Max(0f, x));
[Theory]
[InlineData(1, 0)]
diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs
index bf5507676..8c12b0050 100644
--- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs
@@ -335,7 +335,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
for (int i = 0; i < 64; i++)
{
- float expected = MathF.Round(s[i]);
+ float expected = (float)Math.Round(s[i]);
float actual = d[i];
Assert.Equal(expected, actual);
diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs
index 46f137f81..7e0dc915c 100644
--- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs
@@ -236,11 +236,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
float cr = values.Component2[i] - 128F;
float k = values.Component3[i] / 255F;
- v.X = (255F - MathF.Round(y + (1.402F * cr), MidpointRounding.AwayFromZero)) * k;
- v.Y = (255F - MathF.Round(
+ v.X = (255F - (float)Math.Round(y + (1.402F * cr), MidpointRounding.AwayFromZero)) * k;
+ v.Y = (255F - (float)Math.Round(
y - (0.344136F * cb) - (0.714136F * cr),
MidpointRounding.AwayFromZero)) * k;
- v.Z = (255F - MathF.Round(y + (1.772F * cb), MidpointRounding.AwayFromZero)) * k;
+ v.Z = (255F - (float)Math.Round(y + (1.772F * cb), MidpointRounding.AwayFromZero)) * k;
v.W = 1F;
v *= scale;
diff --git a/tests/ImageSharp.Tests/Helpers/MathFTests.cs b/tests/ImageSharp.Tests/Helpers/MathFTests.cs
deleted file mode 100644
index f865353c4..000000000
--- a/tests/ImageSharp.Tests/Helpers/MathFTests.cs
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using Xunit;
-
-namespace SixLabors.ImageSharp.Tests.Helpers
-{
- public class MathFTests
- {
- [Fact]
- public void MathF_PI_Is_Equal()
- {
- Assert.Equal(MathF.PI, (float)Math.PI);
- }
-
- [Fact]
- public void MathF_Ceililng_Is_Equal()
- {
- Assert.Equal(MathF.Ceiling(0.3333F), (float)Math.Ceiling(0.3333F));
- }
-
- [Fact]
- public void MathF_Cos_Is_Equal()
- {
- Assert.Equal(MathF.Cos(0.3333F), (float)Math.Cos(0.3333F));
- }
-
- [Fact]
- public void MathF_Abs_Is_Equal()
- {
- Assert.Equal(MathF.Abs(-0.3333F), (float)Math.Abs(-0.3333F));
- }
-
- [Fact]
- public void MathF_Atan2_Is_Equal()
- {
- Assert.Equal(MathF.Atan2(1.2345F, 1.2345F), (float)Math.Atan2(1.2345F, 1.2345F));
- }
-
- [Fact]
- public void MathF_Exp_Is_Equal()
- {
- Assert.Equal(MathF.Exp(1.2345F), (float)Math.Exp(1.2345F));
- }
-
- [Fact]
- public void MathF_Floor_Is_Equal()
- {
- Assert.Equal(MathF.Floor(1.2345F), (float)Math.Floor(1.2345F));
- }
-
- [Fact]
- public void MathF_Min_Is_Equal()
- {
- Assert.Equal(MathF.Min(1.2345F, 5.4321F), (float)Math.Min(1.2345F, 5.4321F));
- }
-
- [Fact]
- public void MathF_Max_Is_Equal()
- {
- Assert.Equal(MathF.Max(1.2345F, 5.4321F), (float)Math.Max(1.2345F, 5.4321F));
- }
-
- [Fact]
- public void MathF_Pow_Is_Equal()
- {
- Assert.Equal(MathF.Pow(1.2345F, 5.4321F), (float)Math.Pow(1.2345F, 5.4321F));
- }
-
- [Fact]
- public void MathF_Round_Is_Equal()
- {
- Assert.Equal(MathF.Round(1.2345F), (float)Math.Round(1.2345F));
- }
-
- [Fact]
- public void MathF_Round_With_Midpoint_Is_Equal()
- {
- Assert.Equal(MathF.Round(1.2345F, MidpointRounding.AwayFromZero), (float)Math.Round(1.2345F, MidpointRounding.AwayFromZero));
- }
-
- [Fact]
- public void MathF_Sin_Is_Equal()
- {
- Assert.Equal(MathF.Sin(1.2345F), (float)Math.Sin(1.2345F));
- }
-
- [Fact]
- public void MathF_SinC_Is_Equal()
- {
- float f = 1.2345F;
- float expected = 1F;
- if (Math.Abs(f) > Constants.Epsilon)
- {
- f *= (float)Math.PI;
- float sinC = (float)Math.Sin(f) / f;
-
- expected = Math.Abs(sinC) < Constants.Epsilon ? 0F : sinC;
- }
-
- Assert.Equal(MathF.SinC(1.2345F), expected);
- }
-
- [Fact]
- public void MathF_Sqrt_Is_Equal()
- {
- Assert.Equal(MathF.Sqrt(2F), (float)Math.Sqrt(2F));
- }
-
- [Fact]
- public void Convert_Degree_To_Radian()
- {
- Assert.Equal((float)(Math.PI / 2D), MathF.DegreeToRadian(90F), new FloatRoundingComparer(6));
- }
-
- [Fact]
- public void Convert_Radian_To_Degree()
- {
- Assert.Equal(60F, MathF.RadianToDegree((float)(Math.PI / 3D)), new FloatRoundingComparer(5));
- }
- }
-}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs b/tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs
index 303905baf..9b6d53fd9 100644
--- a/tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
-using System.Diagnostics;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
@@ -34,29 +33,29 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal(26, new Alpha8(0.1F).PackedValue);
// Test ordering
- Vector4 vector = new Alpha8(.5F).ToVector4();
+ var vector = new Alpha8(.5F).ToVector4();
Assert.Equal(0, vector.X);
Assert.Equal(0, vector.Y);
Assert.Equal(0, vector.Z);
Assert.Equal(.5F, vector.W, 2);
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new Alpha8(.5F).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 0, 0, 0 });
+ new Alpha8(.5F).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(0, 0, 0));
- new Alpha8(.5F).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 0, 0, 0, 128 });
+ new Alpha8(.5F).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(0, 0, 0, 128));
- new Alpha8(.5F).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 0, 0, 0 });
+ new Alpha8(.5F).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(0, 0, 0));
- new Alpha8(.5F).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 0, 0, 0, 128 });
+ new Alpha8(.5F).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(0, 0, 0, 128));
}
[Fact]
@@ -82,26 +81,26 @@ namespace SixLabors.ImageSharp.Tests.Colors
float y = -0.3f;
float z = +0.5f;
float w = -0.7f;
- Argb32 argb = new Argb32(x, y, z, w);
+ var argb = new Argb32(x, y, z, w);
Assert.Equal(0x001a0080u, argb.PackedValue);
// Test ordering
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- argb.ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 0x1a, 0, 0x80 });
+ argb.ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(0x1a, 0, 0x80));
- argb.ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 0x1a, 0, 0x80, 0 });
+ argb.ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(0x1a, 0, 0x80, 0));
- argb.ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 0x80, 0, 0x1a });
+ argb.ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(0x1a, 0, 0x80));
- argb.ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 0x80, 0, 0x1a, 0 });
+ argb.ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(0x1a, 0, 0x80, 0));
}
[Fact]
@@ -133,22 +132,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal(6160, new Bgr565(x, y, z).PackedValue);
// Test ordering
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new Bgr565(x, y, z).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 25, 0, 132 });
+ new Bgr565(x, y, z).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(25, 0, 132));
- new Bgr565(x, y, z).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 25, 0, 132, 255 });
+ new Bgr565(x, y, z).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(25, 0, 132, 255));
- new Bgr565(x, y, z).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 132, 0, 25 });
+ new Bgr565(x, y, z).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(25, 0, 132));
- new Bgr565(x, y, z).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 132, 0, 25, 255 });
+ new Bgr565(x, y, z).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(25, 0, 132, 255));
}
[Fact]
@@ -183,22 +182,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal(520, new Bgra4444(x, y, z, w).PackedValue);
// Test ordering
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new Bgra4444(x, y, z, w).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 34, 0, 136 });
+ new Bgra4444(x, y, z, w).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(34, 0, 136));
- new Bgra4444(x, y, z, w).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 34, 0, 136, 0 });
+ new Bgra4444(x, y, z, w).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(34, 0, 136, 0));
- new Bgra4444(x, y, z, w).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 136, 0, 34 });
+ new Bgra4444(x, y, z, w).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(34, 0, 136));
- new Bgra4444(x, y, z, w).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 136, 0, 34, 0 });
+ new Bgra4444(x, y, z, w).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(34, 0, 136, 0));
}
[Fact]
@@ -229,22 +228,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal(3088, new Bgra5551(x, y, z, w).PackedValue);
// Test ordering
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new Bgra5551(x, y, z, w).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 24, 0, 131 });
+ new Bgra5551(x, y, z, w).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(24, 0, 131));
- new Bgra5551(x, y, z, w).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 24, 0, 131, 0 });
+ new Bgra5551(x, y, z, w).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(24, 0, 131, 0));
- new Bgra5551(x, y, z, w).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 131, 0, 24 });
+ new Bgra5551(x, y, z, w).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(24, 0, 131));
- new Bgra5551(x, y, z, w).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 131, 0, 24, 0 });
+ new Bgra5551(x, y, z, w).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(24, 0, 131, 0));
}
[Fact]
@@ -280,27 +279,27 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal((uint)128, new Byte4(x, y, z, w).PackedValue);
// Test ordering
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new Byte4(x, y, z, w).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 128, 0, 0 });
+ new Byte4(x, y, z, w).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(128, 0, 0));
- new Byte4(x, y, z, w).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 128, 0, 0, 0 });
+ new Byte4(x, y, z, w).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(128, 0, 0, 0));
- new Byte4(x, y, z, w).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 0, 0, 128 });
+ new Byte4(x, y, z, w).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(128, 0, 0));
- new Byte4(x, y, z, w).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 0, 0, 128, 0 });
+ new Byte4(x, y, z, w).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(128, 0, 0, 0));
- Byte4 r = new Byte4();
+ var r = new Byte4();
r.PackFromRgba32(new Rgba32(20, 38, 0, 255));
- r.ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 20, 38, 0, 255 });
+ r.ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(20, 38, 0, 255));
}
[Fact]
@@ -319,22 +318,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
float x = .5F;
Assert.True(Equal(new Vector4(x, 0, 0, 1), new HalfSingle(x).ToVector4()));
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new HalfSingle(x).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 128, 0, 0 });
+ new HalfSingle(x).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(128, 0, 0));
- new HalfSingle(x).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 128, 0, 0, 255 });
+ new HalfSingle(x).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(128, 0, 0, 255));
- new HalfSingle(x).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 0, 0, 128 });
+ new HalfSingle(x).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(128, 0, 0));
- new HalfSingle(x).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 0, 0, 128, 255 });
+ new HalfSingle(x).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(128, 0, 0, 255));
}
[Fact]
@@ -356,22 +355,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
float y = .25F;
Assert.True(Equal(new Vector4(x, y, 0, 1), new HalfVector2(x, y).ToVector4()));
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new HalfVector2(x, y).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 128, 64, 0 });
+ new HalfVector2(x, y).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(128, 64, 0));
- new HalfVector2(x, y).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 128, 64, 0, 255 });
+ new HalfVector2(x, y).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(128, 64, 0, 255));
- new HalfVector2(x, y).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 0, 64, 128 });
+ new HalfVector2(x, y).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(128, 64, 0));
- new HalfVector2(x, y).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 0, 64, 128, 255 });
+ new HalfVector2(x, y).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(128, 64, 0, 255));
}
[Fact]
@@ -402,22 +401,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
float z = .75F;
float w = 1F;
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new HalfVector4(x, y, z, w).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 64, 128, 191 });
+ new HalfVector4(x, y, z, w).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(64, 128, 191));
- new HalfVector4(x, y, z, w).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 64, 128, 191, 255 });
+ new HalfVector4(x, y, z, w).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(64, 128, 191, 255));
- new HalfVector4(x, y, z, w).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 191, 128, 64 });
+ new HalfVector4(x, y, z, w).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(64, 128, 191));
- new HalfVector4(x, y, z, w).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 191, 128, 64, 255 });
+ new HalfVector4(x, y, z, w).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(64, 128, 191, 255));
}
[Fact]
@@ -443,26 +442,26 @@ namespace SixLabors.ImageSharp.Tests.Colors
float x = 0.1f;
float y = -0.3f;
Assert.Equal(0xda0d, new NormalizedByte2(x, y).PackedValue);
- NormalizedByte2 n = new NormalizedByte2();
+ var n = new NormalizedByte2();
n.PackFromRgba32(new Rgba32(141, 90, 0, 0));
Assert.Equal(0xda0d, n.PackedValue);
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new NormalizedByte2(x, y).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 141, 90, 0 });
+ new NormalizedByte2(x, y).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(141, 90, 0));
- new NormalizedByte2(x, y).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 141, 90, 0, 255 });
+ new NormalizedByte2(x, y).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(141, 90, 0, 255));
- new NormalizedByte2(x, y).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 0, 90, 141 });
+ new NormalizedByte2(x, y).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(141, 90, 0));
- new NormalizedByte2(x, y).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 0, 90, 141, 255 });
+ new NormalizedByte2(x, y).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(141, 90, 0, 255));
}
[Fact]
@@ -486,38 +485,38 @@ namespace SixLabors.ImageSharp.Tests.Colors
float z = 0.5f;
float w = -0.7f;
Assert.Equal(0xA740DA0D, new NormalizedByte4(x, y, z, w).PackedValue);
- NormalizedByte4 n = new NormalizedByte4();
+ var n = new NormalizedByte4();
n.PackFromRgba32(new Rgba32(141, 90, 192, 39));
Assert.Equal(0xA740DA0D, n.PackedValue);
Assert.Equal((uint)958796544, new NormalizedByte4(0.0008f, 0.15f, 0.30f, 0.45f).PackedValue);
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new NormalizedByte4(x, y, z, w).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 141, 90, 192 });
+ new NormalizedByte4(x, y, z, w).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(141, 90, 192));
- new NormalizedByte4(x, y, z, w).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 141, 90, 192, 39 });
+ new NormalizedByte4(x, y, z, w).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(141, 90, 192, 39));
- new NormalizedByte4(x, y, z, w).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 192, 90, 141 });
+ new NormalizedByte4(x, y, z, w).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(141, 90, 192));
- new NormalizedByte4(x, y, z, w).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 192, 90, 141, 39 });
+ new NormalizedByte4(x, y, z, w).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(141, 90, 192, 39));
// http://community.monogame.net/t/normalizedbyte4-texture2d-gives-different-results-from-xna/8012/8
- NormalizedByte4 r = new NormalizedByte4();
+ var r = new NormalizedByte4();
r.PackFromRgba32(new Rgba32(9, 115, 202, 127));
- r.ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 9, 115, 202, 127 });
+ r.ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(9, 115, 202, 127));
r.PackedValue = 0xff4af389;
- r.ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 9, 115, 202, 127 });
+ r.ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(9, 115, 202, 127));
}
[Fact]
@@ -544,30 +543,30 @@ namespace SixLabors.ImageSharp.Tests.Colors
y = -0.3f;
Assert.Equal(3650751693, new NormalizedShort2(x, y).PackedValue);
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- NormalizedShort2 n = new NormalizedShort2();
+ var n = new NormalizedShort2();
n.PackFromRgba32(new Rgba32(141, 90, 0, 0));
- n.ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 141, 90, 0 });
+ n.ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(141, 90, 0));
// TODO: I don't think this can ever pass since the bytes are already truncated.
// Assert.Equal(3650751693, n.PackedValue);
- new NormalizedShort2(x, y).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 141, 90, 0 });
+ new NormalizedShort2(x, y).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(141, 90, 0));
- new NormalizedShort2(x, y).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 141, 90, 0, 255 });
+ new NormalizedShort2(x, y).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(141, 90, 0, 255));
- new NormalizedShort2(x, y).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 0, 90, 141 });
+ new NormalizedShort2(x, y).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(141, 90, 0));
- new NormalizedShort2(x, y).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 0, 90, 141, 255 });
+ new NormalizedShort2(x, y).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(141, 90, 0, 255));
}
[Fact]
@@ -593,27 +592,27 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal(0xa6674000d99a0ccd, new NormalizedShort4(x, y, z, w).PackedValue);
Assert.Equal((ulong)4150390751449251866, new NormalizedShort4(0.0008f, 0.15f, 0.30f, 0.45f).PackedValue);
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new NormalizedShort4(x, y, z, w).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 141, 90, 192 });
+ new NormalizedShort4(x, y, z, w).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(141, 90, 192));
- new NormalizedShort4(x, y, z, w).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 141, 90, 192, 39 });
+ new NormalizedShort4(x, y, z, w).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(141, 90, 192, 39));
- new NormalizedShort4(x, y, z, w).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 192, 90, 141 });
+ new NormalizedShort4(x, y, z, w).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(141, 90, 192));
- new NormalizedShort4(x, y, z, w).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 192, 90, 141, 39 });
+ new NormalizedShort4(x, y, z, w).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(141, 90, 192, 39));
- NormalizedShort4 r = new NormalizedShort4();
+ var r = new NormalizedShort4();
r.PackFromRgba32(new Rgba32(9, 115, 202, 127));
- r.ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 9, 115, 202, 127 });
+ r.ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(9, 115, 202, 127));
}
[Fact]
@@ -640,22 +639,22 @@ namespace SixLabors.ImageSharp.Tests.Colors
Assert.Equal((uint)6554, new Rg32(x, y).PackedValue);
// Test ordering
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new Rg32(x, y).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 25, 0, 0 });
+ new Rg32(x, y).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(25, 0, 0));
- new Rg32(x, y).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 25, 0, 0, 255 });
+ new Rg32(x, y).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(25, 0, 0, 255));
- new Rg32(x, y).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 0, 0, 25 });
+ new Rg32(x, y).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(25, 0, 0));
- new Rg32(x, y).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 0, 0, 25, 255 });
+ new Rg32(x, y).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(25, 0, 0, 255));
}
[Fact]
@@ -685,28 +684,28 @@ namespace SixLabors.ImageSharp.Tests.Colors
w = -0.7f;
Assert.Equal((uint)536871014, new Rgba1010102(x, y, z, w).PackedValue);
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new Rgba1010102(x, y, z, w).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 25, 0, 128 });
+ new Rgba1010102(x, y, z, w).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(25, 0, 128));
- new Rgba1010102(x, y, z, w).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 25, 0, 128, 0 });
+ new Rgba1010102(x, y, z, w).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(25, 0, 128, 0));
- new Rgba1010102(x, y, z, w).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 128, 0, 25 });
+ new Rgba1010102(x, y, z, w).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(25, 0, 128));
- new Rgba1010102(x, y, z, w).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 128, 0, 25, 0 });
+ new Rgba1010102(x, y, z, w).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(25, 0, 128, 0));
// Alpha component accuracy will be awful.
- Rgba1010102 r = new Rgba1010102();
+ var r = new Rgba1010102();
r.PackFromRgba32(new Rgba32(25, 0, 128, 0));
- r.ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 25, 0, 128, 0 });
+ r.ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(25, 0, 128, 0));
}
[Fact]
@@ -732,26 +731,26 @@ namespace SixLabors.ImageSharp.Tests.Colors
float y = -0.3f;
float z = +0.5f;
float w = -0.7f;
- Rgba32 rgba32 = new Rgba32(x, y, z, w);
+ var rgba32 = new Rgba32(x, y, z, w);
Assert.Equal(0x80001Au, rgba32.PackedValue);
// Test ordering
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- rgba32.ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 0x1a, 0, 0x80 });
+ rgba32.ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(0x1a, 0, 0x80));
- rgba32.ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 0x1a, 0, 0x80, 0 });
+ rgba32.ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(0x1a, 0, 0x80, 0));
- rgba32.ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 0x80, 0, 0x1a });
+ rgba32.ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(0x1a, 0, 0x80));
- rgba32.ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 0x80, 0, 0x1a, 0 });
+ rgba32.ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(0x1a, 0, 0x80, 0));
}
[Fact]
@@ -779,27 +778,27 @@ namespace SixLabors.ImageSharp.Tests.Colors
float w = 0.45f;
Assert.Equal((ulong)0x73334CCC2666147B, new Rgba64(x, y, z, w).PackedValue);
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new Rgba64(x, y, z, w).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 20, 38, 76 });
+ new Rgba64(x, y, z, w).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(20, 38, 76));
- new Rgba64(x, y, z, w).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 20, 38, 76, 115 });
+ new Rgba64(x, y, z, w).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(20, 38, 76, 115));
- new Rgba64(x, y, z, w).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 76, 38, 20 });
+ new Rgba64(x, y, z, w).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(20, 38, 76));
- new Rgba64(x, y, z, w).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 76, 38, 20, 115 });
+ new Rgba64(x, y, z, w).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(20, 38, 76, 115));
- Rgba64 r = new Rgba64();
+ var r = new Rgba64();
r.PackFromRgba32(new Rgba32(20, 38, 76, 115));
- r.ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 20, 38, 76, 115 });
+ r.ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(20, 38, 76, 115));
}
[Fact]
@@ -834,27 +833,27 @@ namespace SixLabors.ImageSharp.Tests.Colors
y = -5.3f;
Assert.Equal(4294639744, new Short2(x, y).PackedValue);
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new Short2(x, y).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 128, 127, 0 });
+ new Short2(x, y).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(128, 127, 0));
- new Short2(x, y).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 128, 127, 0, 255 });
+ new Short2(x, y).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(128, 127, 0, 255));
- new Short2(x, y).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 0, 127, 128 });
+ new Short2(x, y).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(128, 127, 0));
- new Short2(x, y).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 0, 127, 128, 255 });
+ new Short2(x, y).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(128, 127, 0, 255));
- Short2 r = new Short2();
+ var r = new Short2();
r.PackFromRgba32(new Rgba32(20, 38, 0, 255));
- r.ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 20, 38, 0, 255 });
+ r.ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(20, 38, 0, 255));
}
[Fact]
@@ -891,27 +890,27 @@ namespace SixLabors.ImageSharp.Tests.Colors
w = 193;
Assert.Equal((ulong)0x00c173b7316d2d1b, new Short4(x, y, z, w).PackedValue);
- byte[] rgb = new byte[3];
- byte[] rgba = new byte[4];
- byte[] bgr = new byte[3];
- byte[] bgra = new byte[4];
+ var rgb = default(Rgb24);
+ var rgba = default(Rgba32);
+ var bgr = default(Bgr24);
+ var bgra = default(Bgra32);
- new Short4(x, y, z, w).ToXyzBytes(rgb, 0);
- Assert.Equal(rgb, new byte[] { 172, 177, 243 });
+ new Short4(x, y, z, w).ToRgb24(ref rgb);
+ Assert.Equal(rgb, new Rgb24(172, 177, 243));
- new Short4(x, y, z, w).ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 172, 177, 243, 128 });
+ new Short4(x, y, z, w).ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(172, 177, 243, 128));
- new Short4(x, y, z, w).ToZyxBytes(bgr, 0);
- Assert.Equal(bgr, new byte[] { 243, 177, 172 });
+ new Short4(x, y, z, w).ToBgr24(ref bgr);
+ Assert.Equal(bgr, new Bgr24(172, 177, 243));
- new Short4(x, y, z, w).ToZyxwBytes(bgra, 0);
- Assert.Equal(bgra, new byte[] { 243, 177, 172, 128 });
+ new Short4(x, y, z, w).ToBgra32(ref bgra);
+ Assert.Equal(bgra, new Bgra32(172, 177, 243, 128));
- Short4 r = new Short4();
+ var r = new Short4();
r.PackFromRgba32(new Rgba32(20, 38, 0, 255));
- r.ToXyzwBytes(rgba, 0);
- Assert.Equal(rgba, new byte[] { 20, 38, 0, 255 });
+ r.ToRgba32(ref rgba);
+ Assert.Equal(rgba, new Rgba32(20, 38, 0, 255));
}
// Comparison helpers with small tolerance to allow for floating point rounding during computations.
diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
index dbb9a6c24..0fde67d28 100644
--- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
@@ -173,11 +173,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{
TPixel[] source = CreatePixelTestData(count);
byte[] expected = new byte[count * 3];
+ var rgb = default(Rgb24);
for (int i = 0; i < count; i++)
{
int i3 = i * 3;
- source[i].ToXyzBytes(expected, i3);
+ source[i].ToRgb24(ref rgb);
+ expected[i3] = rgb.R;
+ expected[i3 + 1] = rgb.G;
+ expected[i3 + 2] = rgb.B;
}
TestOperation(
@@ -214,11 +218,16 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{
TPixel[] source = CreatePixelTestData(count);
byte[] expected = new byte[count * 4];
+ var rgba = default(Rgba32);
for (int i = 0; i < count; i++)
{
int i4 = i * 4;
- source[i].ToXyzwBytes(expected, i4);
+ source[i].ToRgba32(ref rgba);
+ expected[i4] = rgba.R;
+ expected[i4 + 1] = rgba.G;
+ expected[i4 + 2] = rgba.B;
+ expected[i4 + 3] = rgba.A;
}
TestOperation(
@@ -255,11 +264,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{
TPixel[] source = CreatePixelTestData(count);
byte[] expected = new byte[count * 3];
+ var bgr = default(Bgr24);
for (int i = 0; i < count; i++)
{
int i3 = i * 3;
- source[i].ToZyxBytes(expected, i3);
+ source[i].ToBgr24(ref bgr);
+ expected[i3] = bgr.B;
+ expected[i3 + 1] = bgr.G;
+ expected[i3 + 2] = bgr.R;
}
TestOperation(
@@ -296,11 +309,16 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{
TPixel[] source = CreatePixelTestData(count);
byte[] expected = new byte[count * 4];
+ var bgra = default(Bgra32);
for (int i = 0; i < count; i++)
{
int i4 = i * 4;
- source[i].ToZyxwBytes(expected, i4);
+ source[i].ToBgra32(ref bgra);
+ expected[i4] = bgra.B;
+ expected[i4 + 1] = bgra.G;
+ expected[i4 + 2] = bgra.R;
+ expected[i4 + 3] = bgra.A;
}
TestOperation(
diff --git a/tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs b/tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs
index b5d46ba76..1fca398fc 100644
--- a/tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs
@@ -12,8 +12,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact]
public void Color_Types_From_Bytes_Produce_Equal_Scaled_Component_OutPut()
{
- Rgba32 color = new Rgba32(24, 48, 96, 192);
- RgbaVector colorVector = new RgbaVector(24, 48, 96, 192);
+ var color = new Rgba32(24, 48, 96, 192);
+ var colorVector = new RgbaVector(24, 48, 96, 192);
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
@@ -24,8 +24,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact]
public void Color_Types_From_Floats_Produce_Equal_Scaled_Component_OutPut()
{
- Rgba32 color = new Rgba32(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
- RgbaVector colorVector = new RgbaVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
+ var color = new Rgba32(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
+ var colorVector = new RgbaVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
@@ -36,8 +36,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact]
public void Color_Types_From_Vector4_Produce_Equal_Scaled_Component_OutPut()
{
- Rgba32 color = new Rgba32(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F));
- RgbaVector colorVector = new RgbaVector(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F));
+ var color = new Rgba32(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F));
+ var colorVector = new RgbaVector(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F));
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
@@ -48,8 +48,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact]
public void Color_Types_From_Vector3_Produce_Equal_Scaled_Component_OutPut()
{
- Rgba32 color = new Rgba32(new Vector3(24 / 255F, 48 / 255F, 96 / 255F));
- RgbaVector colorVector = new RgbaVector(new Vector3(24 / 255F, 48 / 255F, 96 / 255F));
+ var color = new Rgba32(new Vector3(24 / 255F, 48 / 255F, 96 / 255F));
+ var colorVector = new RgbaVector(new Vector3(24 / 255F, 48 / 255F, 96 / 255F));
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
@@ -60,8 +60,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact]
public void Color_Types_From_Hex_Produce_Equal_Scaled_Component_OutPut()
{
- Rgba32 color = Rgba32.FromHex("183060C0");
- RgbaVector colorVector = RgbaVector.FromHex("183060C0");
+ var color = Rgba32.FromHex("183060C0");
+ var colorVector = RgbaVector.FromHex("183060C0");
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
@@ -72,8 +72,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact]
public void Color_Types_To_Vector4_Produce_Equal_OutPut()
{
- Rgba32 color = new Rgba32(24, 48, 96, 192);
- RgbaVector colorVector = new RgbaVector(24, 48, 96, 192);
+ var color = new Rgba32(24, 48, 96, 192);
+ var colorVector = new RgbaVector(24, 48, 96, 192);
Assert.Equal(color.ToVector4(), colorVector.ToVector4());
}
@@ -81,14 +81,14 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact]
public void Color_Types_To_RgbBytes_Produce_Equal_OutPut()
{
- Rgba32 color = new Rgba32(24, 48, 96, 192);
- RgbaVector colorVector = new RgbaVector(24, 48, 96, 192);
+ var color = new Rgba32(24, 48, 96, 192);
+ var colorVector = new RgbaVector(24, 48, 96, 192);
- byte[] rgb = new byte[3];
- byte[] rgbVector = new byte[3];
+ var rgb = default(Rgb24);
+ var rgbVector = default(Rgb24);
- color.ToXyzBytes(rgb, 0);
- colorVector.ToXyzBytes(rgbVector, 0);
+ color.ToRgb24(ref rgb);
+ colorVector.ToRgb24(ref rgbVector);
Assert.Equal(rgb, rgbVector);
}
@@ -96,14 +96,14 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact]
public void Color_Types_To_RgbaBytes_Produce_Equal_OutPut()
{
- Rgba32 color = new Rgba32(24, 48, 96, 192);
- RgbaVector colorVector = new RgbaVector(24, 48, 96, 192);
+ var color = new Rgba32(24, 48, 96, 192);
+ var colorVector = new RgbaVector(24, 48, 96, 192);
- byte[] rgba = new byte[4];
- byte[] rgbaVector = new byte[4];
+ var rgba = default(Rgba32);
+ var rgbaVector = default(Rgba32);
- color.ToXyzwBytes(rgba, 0);
- colorVector.ToXyzwBytes(rgbaVector, 0);
+ color.ToRgba32(ref rgba);
+ colorVector.ToRgba32(ref rgbaVector);
Assert.Equal(rgba, rgbaVector);
}
@@ -111,14 +111,14 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact]
public void Color_Types_To_BgrBytes_Produce_Equal_OutPut()
{
- Rgba32 color = new Rgba32(24, 48, 96, 192);
- RgbaVector colorVector = new RgbaVector(24, 48, 96, 192);
+ var color = new Rgba32(24, 48, 96, 192);
+ var colorVector = new RgbaVector(24, 48, 96, 192);
- byte[] bgr = new byte[3];
- byte[] bgrVector = new byte[3];
+ var bgr = default(Bgr24);
+ var bgrVector = default(Bgr24);
- color.ToZyxBytes(bgr, 0);
- colorVector.ToZyxBytes(bgrVector, 0);
+ color.ToBgr24(ref bgr);
+ colorVector.ToBgr24(ref bgrVector);
Assert.Equal(bgr, bgrVector);
}
@@ -126,14 +126,14 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact]
public void Color_Types_To_BgraBytes_Produce_Equal_OutPut()
{
- Rgba32 color = new Rgba32(24, 48, 96, 192);
- RgbaVector colorVector = new RgbaVector(24, 48, 96, 192);
+ var color = new Rgba32(24, 48, 96, 192);
+ var colorVector = new RgbaVector(24, 48, 96, 192);
- byte[] bgra = new byte[4];
- byte[] bgraVector = new byte[4];
+ var bgra = default(Bgra32);
+ var bgraVector = default(Bgra32);
- color.ToZyxwBytes(bgra, 0);
- colorVector.ToZyxwBytes(bgraVector, 0);
+ color.ToBgra32(ref bgra);
+ colorVector.ToBgra32(ref bgraVector);
Assert.Equal(bgra, bgraVector);
}
@@ -141,8 +141,8 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact]
public void Color_Types_To_Hex_Produce_Equal_OutPut()
{
- Rgba32 color = new Rgba32(24, 48, 96, 192);
- RgbaVector colorVector = new RgbaVector(24, 48, 96, 192);
+ var color = new Rgba32(24, 48, 96, 192);
+ var colorVector = new RgbaVector(24, 48, 96, 192);
// 183060C0
Assert.Equal(color.ToHex(), colorVector.ToHex());
diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs
index fe003da32..0fbc54b8f 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs
@@ -31,13 +31,13 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix
using (Image image = provider.GetImage())
{
image.Mutate(x => x.Grayscale(value));
- byte[] data = new byte[3];
+ var rgb = default(Rgb24);
System.Span span = image.Frames.RootFrame.GetPixelSpan();
for (int i = 0; i < span.Length; i++)
{
- span[i].ToXyzBytes(data, 0);
- Assert.Equal(data[0], data[1]);
- Assert.Equal(data[1], data[2]);
+ span[i].ToRgb24(ref rgb);
+ Assert.Equal(rgb.R, rgb.B);
+ Assert.Equal(rgb.B, rgb.G);
}
image.DebugSave(provider, value.ToString());
@@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix
where TPixel : struct, IPixel
{
using (Image source = provider.GetImage())
- using (var image = source.Clone())
+ using (Image image = source.Clone())
{
var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.Mutate(x => x.Grayscale(value, bounds));
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
index ed643c820..a5e21b8ef 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
@@ -1,6 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
+
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
@@ -245,7 +247,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{
var options = new ResizeOptions
{
- Size = new Size((int)MathF.Round(image.Width * .75F), (int)MathF.Round(image.Height * .95F)),
+ Size = new Size((int)Math.Round(image.Width * .75F), (int)Math.Round(image.Height * .95F)),
Mode = ResizeMode.Min
};
diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs
index 83997841a..a468c2116 100644
--- a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs
@@ -54,8 +54,8 @@ namespace SixLabors.ImageSharp.Tests
return false;
}
- byte[] bytesA = new byte[3];
- byte[] bytesB = new byte[3];
+ var rgb1 = default(Rgb24);
+ var rgb2 = default(Rgb24);
using (PixelAccessor pixA = a.Lock())
{
@@ -77,12 +77,12 @@ namespace SixLabors.ImageSharp.Tests
}
else
{
- ca.ToXyzBytes(bytesA, 0);
- cb.ToXyzBytes(bytesB, 0);
+ ca.ToRgb24(ref rgb1);
+ cb.ToRgb24(ref rgb2);
- if (bytesA[0] != bytesB[0] ||
- bytesA[1] != bytesB[1] ||
- bytesA[2] != bytesB[2])
+ if (rgb1.R != rgb2.R ||
+ rgb1.G != rgb2.G ||
+ rgb1.B != rgb2.B)
{
return false;
}
@@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Tests
///
public static PixelTypes GetPixelType(this Type colorStructClrType) => ClrTypes2PixelTypes[colorStructClrType];
-
+
public static IEnumerable> ExpandAllTypes(this PixelTypes pixelTypes)
{
diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
index 24becce2e..0c54f8a3c 100644
--- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
@@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Tests
{
Assert.Equal(expected, provider.PixelType);
}
-
+
[Theory]
[WithFile(TestImages.Bmp.Car, PixelTypes.All, 88)]
[WithFile(TestImages.Bmp.F, PixelTypes.All, 88)]
@@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.Tests
}
internal static int GetInvocationCount(string callerName) => invocationCounts[callerName];
-
+
private static readonly object Monitor = new object();
public static void DoTestThreadSafe(Action action)
@@ -166,7 +166,7 @@ namespace SixLabors.ImageSharp.Tests
}
internal static int GetInvocationCount(string callerName) => invocationCounts[callerName];
-
+
private static readonly object Monitor = new object();
public static void DoTestThreadSafe(Action action)
@@ -244,7 +244,7 @@ namespace SixLabors.ImageSharp.Tests
Image image = provider.GetImage();
provider.Utility.SaveTestOutputFile(image, "png");
}
-
+
[Theory]
[WithSolidFilledImages(10, 20, 255, 100, 50, 200, PixelTypes.Rgba32 | PixelTypes.Argb32)]
public void Use_WithSolidFilledImagesAttribute(TestImageProvider provider)
@@ -254,7 +254,7 @@ namespace SixLabors.ImageSharp.Tests
Assert.Equal(10, img.Width);
Assert.Equal(20, img.Height);
- byte[] colors = new byte[4];
+ var rgba = default(Rgba32);
using (PixelAccessor pixels = img.Lock())
{
@@ -262,12 +262,12 @@ namespace SixLabors.ImageSharp.Tests
{
for (int x = 0; x < pixels.Width; x++)
{
- pixels[x, y].ToXyzwBytes(colors, 0);
+ pixels[x, y].ToRgba32(ref rgba);
- Assert.Equal(255, colors[0]);
- Assert.Equal(100, colors[1]);
- Assert.Equal(50, colors[2]);
- Assert.Equal(200, colors[3]);
+ Assert.Equal(255, rgba.R);
+ Assert.Equal(100, rgba.G);
+ Assert.Equal(50, rgba.B);
+ Assert.Equal(200, rgba.A);
}
}
}