From 6fbd5ae36f7bfc83b6e41cd650db98b078f9fa45 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 10 Aug 2016 14:10:10 +1000 Subject: [PATCH] Speed up companding conversions Former-commit-id: 2f3cbe8f979ef1fae811f5138426e72fcfdd9265 Former-commit-id: 7a29098ba4de5bdd1ea9c19918a4741c3e508a69 Former-commit-id: 248447ae4b53a20f75cf07eb37d867c0898a2ccd --- .../Common/Extensions/Vector4Extensions.cs | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/ImageProcessorCore/Common/Extensions/Vector4Extensions.cs b/src/ImageProcessorCore/Common/Extensions/Vector4Extensions.cs index 97d2b66d7..a420122e8 100644 --- a/src/ImageProcessorCore/Common/Extensions/Vector4Extensions.cs +++ b/src/ImageProcessorCore/Common/Extensions/Vector4Extensions.cs @@ -24,11 +24,7 @@ namespace ImageProcessorCore public static Vector4 Compress(this Vector4 linear) { // TODO: Is there a faster way to do this? - float r = Compress(linear.X); - float g = Compress(linear.Y); - float b = Compress(linear.Z); - - return new Vector4(r, g, b, linear.W); + return new Vector4(Compress(linear.X), Compress(linear.Y), Compress(linear.Z), linear.W); } /// @@ -41,11 +37,7 @@ namespace ImageProcessorCore public static Vector4 Expand(this Vector4 gamma) { // TODO: Is there a faster way to do this? - float r = Expand(gamma.X); - float g = Expand(gamma.Y); - float b = Expand(gamma.Z); - - return new Vector4(r, g, b, gamma.W); + return new Vector4(Expand(gamma.X), Expand(gamma.Y), Expand(gamma.Z), gamma.W); } /// @@ -60,12 +52,12 @@ namespace ImageProcessorCore [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float Compress(float signal) { - if (signal <= 0.0031308f) + if (signal <= 0.0031308F) { - return signal * 12.92f; + return signal * 12.92F; } - return (1.055f * (float)Math.Pow(signal, 0.41666666f)) - 0.055f; + return (1.055F * (float)Math.Pow(signal, 0.41666666F)) - 0.055F; } /// @@ -80,12 +72,12 @@ namespace ImageProcessorCore [MethodImpl(MethodImplOptions.AggressiveInlining)] private static float Expand(float signal) { - if (signal <= 0.04045f) + if (signal <= 0.04045F) { - return signal / 12.92f; + return signal / 12.92F; } - return (float)Math.Pow((signal + 0.055f) / 1.055f, 2.4f); + return (float)Math.Pow((signal + 0.055F) / 1.055F, 2.4F); } } }