diff --git a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs index 31f3f32ae7..fac33da140 100644 --- a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs +++ b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs @@ -5,7 +5,6 @@ namespace ImageSharp { - using System; using System.Numerics; using System.Runtime.CompilerServices; using ImageSharp.PixelFormats; @@ -13,7 +12,7 @@ namespace ImageSharp /// /// Extension methods for the struct. /// - public static class Vector4Extensions + internal static class Vector4Extensions { /// /// Compresses a linear color signal to its sRGB equivalent. @@ -22,6 +21,7 @@ namespace ImageSharp /// /// The whose signal to compress. /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector4 Compress(this Vector4 linear) { // TODO: Is there a faster way to do this? @@ -35,6 +35,7 @@ namespace ImageSharp /// /// The whose signal to expand. /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector4 Expand(this Vector4 gamma) { // TODO: Is there a faster way to do this? diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs index 2b8c15ab3c..56466d7a0f 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs @@ -235,7 +235,7 @@ namespace ImageSharp.Formats.Jpg /// /// Vector to multiply by [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void MultiplyAllInplace(Vector4 scaleVec) + public void MultiplyAllInplace(float scaleVec) { this.V0L *= scaleVec; this.V0R *= scaleVec; diff --git a/src/ImageSharp/Formats/Jpeg/Components/DCT.cs b/src/ImageSharp/Formats/Jpeg/Components/DCT.cs index 186a23862f..5729fe46d6 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/DCT.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/DCT.cs @@ -15,31 +15,31 @@ namespace ImageSharp.Formats.Jpg internal static class DCT { #pragma warning disable SA1310 // FieldNamesMustNotContainUnderscore - private static readonly Vector4 C_1_175876 = new Vector4(1.175876f); + private static readonly float C_1_175876 = 1.175876f; - private static readonly Vector4 C_1_961571 = new Vector4(-1.961571f); + private static readonly float C_1_961571 = -1.961571f; - private static readonly Vector4 C_0_390181 = new Vector4(-0.390181f); + private static readonly float C_0_390181 = -0.390181f; - private static readonly Vector4 C_0_899976 = new Vector4(-0.899976f); + private static readonly float C_0_899976 = -0.899976f; - private static readonly Vector4 C_2_562915 = new Vector4(-2.562915f); + private static readonly float C_2_562915 = -2.562915f; - private static readonly Vector4 C_0_298631 = new Vector4(0.298631f); + private static readonly float C_0_298631 = 0.298631f; - private static readonly Vector4 C_2_053120 = new Vector4(2.053120f); + private static readonly float C_2_053120 = 2.053120f; - private static readonly Vector4 C_3_072711 = new Vector4(3.072711f); + private static readonly float C_3_072711 = 3.072711f; - private static readonly Vector4 C_1_501321 = new Vector4(1.501321f); + private static readonly float C_1_501321 = 1.501321f; - private static readonly Vector4 C_0_541196 = new Vector4(0.541196f); + private static readonly float C_0_541196 = 0.541196f; - private static readonly Vector4 C_1_847759 = new Vector4(-1.847759f); + private static readonly float C_1_847759 = -1.847759f; - private static readonly Vector4 C_0_765367 = new Vector4(0.765367f); + private static readonly float C_0_765367 = 0.765367f; - private static readonly Vector4 C_0_125 = new Vector4(0.1250f); + private static readonly float C_0_125 = 0.1250f; #pragma warning restore SA1310 // FieldNamesMustNotContainUnderscore private static readonly Vector4 InvSqrt2 = new Vector4(0.707107f); @@ -216,26 +216,26 @@ namespace ImageSharp.Formats.Jpg d.V0L = c0 + c1; d.V4L = c0 - c1; - Vector4 w0 = new Vector4(0.541196f); - Vector4 w1 = new Vector4(1.306563f); + float w0 = 0.541196f; + float w1 = 1.306563f; d.V2L = (w0 * c2) + (w1 * c3); d.V6L = (w0 * c3) - (w1 * c2); - w0 = new Vector4(1.175876f); - w1 = new Vector4(0.785695f); + w0 = 1.175876f; + w1 = 0.785695f; c3 = (w0 * t4) + (w1 * t7); c0 = (w0 * t7) - (w1 * t4); - w0 = new Vector4(1.387040f); - w1 = new Vector4(0.275899f); + w0 = 1.387040f; + w1 = 0.275899f; c2 = (w0 * t5) + (w1 * t6); c1 = (w0 * t6) - (w1 * t5); d.V3L = c0 - c2; d.V5L = c3 - c1; - Vector4 invsqrt2 = new Vector4(0.707107f); + float invsqrt2 = 0.707107f; c0 = (c0 + c2) * invsqrt2; c3 = (c3 + c1) * invsqrt2; @@ -281,19 +281,19 @@ namespace ImageSharp.Formats.Jpg d.V0R = c0 + c1; d.V4R = c0 - c1; - Vector4 w0 = new Vector4(0.541196f); - Vector4 w1 = new Vector4(1.306563f); + float w0 = 0.541196f; + float w1 = 1.306563f; d.V2R = (w0 * c2) + (w1 * c3); d.V6R = (w0 * c3) - (w1 * c2); - w0 = new Vector4(1.175876f); - w1 = new Vector4(0.785695f); + w0 = 1.175876f; + w1 = 0.785695f; c3 = (w0 * t4) + (w1 * t7); c0 = (w0 * t7) - (w1 * t4); - w0 = new Vector4(1.387040f); - w1 = new Vector4(0.275899f); + w0 = 1.387040f; + w1 = 0.275899f; c2 = (w0 * t5) + (w1 * t6); c1 = (w0 * t6) - (w1 * t5); diff --git a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs index 638a56bf31..932c229bd4 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs @@ -14,6 +14,7 @@ namespace ImageSharp.Benchmarks using CoreSize = ImageSharp.Size; using CoreImage = ImageSharp.Image; + using CoreImageVector = ImageSharp.Image; public class Resize : BenchmarkBase { @@ -50,7 +51,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Vector Resize")] public CoreSize ResizeCoreVector() { - using (CoreImage image = new CoreImage(2000, 2000)) + using (CoreImageVector image = new CoreImageVector(2000, 2000)) { image.Resize(400, 400); return new CoreSize(image.Width, image.Height); @@ -70,7 +71,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Vector Compand Resize")] public CoreSize ResizeCoreVectorCompand() { - using (CoreImage image = new CoreImage(2000, 2000)) + using (CoreImageVector image = new CoreImageVector(2000, 2000)) { image.Resize(400, 400, true); return new CoreSize(image.Width, image.Height); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs index 63ddbc884c..01501a33d4 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs @@ -309,7 +309,7 @@ namespace ImageSharp.Tests float[] data = Create8x8FloatData(); Block8x8F block = new Block8x8F(); block.LoadFrom(data); - block.MultiplyAllInplace(new Vector4(5, 5, 5, 5)); + block.MultiplyAllInplace(5); int stride = 256; int height = 42;