Browse Source

Speed up companding conversions

Former-commit-id: 2f3cbe8f979ef1fae811f5138426e72fcfdd9265
Former-commit-id: 7a29098ba4de5bdd1ea9c19918a4741c3e508a69
Former-commit-id: 248447ae4b53a20f75cf07eb37d867c0898a2ccd
pull/1/head
James Jackson-South 10 years ago
parent
commit
6fbd5ae36f
  1. 24
      src/ImageProcessorCore/Common/Extensions/Vector4Extensions.cs

24
src/ImageProcessorCore/Common/Extensions/Vector4Extensions.cs

@ -24,11 +24,7 @@ namespace ImageProcessorCore
public static Vector4 Compress(this Vector4 linear) public static Vector4 Compress(this Vector4 linear)
{ {
// TODO: Is there a faster way to do this? // TODO: Is there a faster way to do this?
float r = Compress(linear.X); return new Vector4(Compress(linear.X), Compress(linear.Y), Compress(linear.Z), linear.W);
float g = Compress(linear.Y);
float b = Compress(linear.Z);
return new Vector4(r, g, b, linear.W);
} }
/// <summary> /// <summary>
@ -41,11 +37,7 @@ namespace ImageProcessorCore
public static Vector4 Expand(this Vector4 gamma) public static Vector4 Expand(this Vector4 gamma)
{ {
// TODO: Is there a faster way to do this? // TODO: Is there a faster way to do this?
float r = Expand(gamma.X); return new Vector4(Expand(gamma.X), Expand(gamma.Y), Expand(gamma.Z), gamma.W);
float g = Expand(gamma.Y);
float b = Expand(gamma.Z);
return new Vector4(r, g, b, gamma.W);
} }
/// <summary> /// <summary>
@ -60,12 +52,12 @@ namespace ImageProcessorCore
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static float Compress(float signal) 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;
} }
/// <summary> /// <summary>
@ -80,12 +72,12 @@ namespace ImageProcessorCore
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static float Expand(float signal) 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);
} }
} }
} }

Loading…
Cancel
Save