Browse Source

Use explicit threadsafety declaration.

js/color-alpha-handling^2
James Jackson-South 5 years ago
parent
commit
3cbd8e393d
  1. 72
      src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs

72
src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs

@ -25,49 +25,53 @@ namespace SixLabors.ImageSharp.ColorSpaces.Companding
private const int Length = Scale + 2; // 256kb @ 16bit precision. private const int Length = Scale + 2; // 256kb @ 16bit precision.
private const int Scale = (1 << 16) - 1; private const int Scale = (1 << 16) - 1;
private static readonly Lazy<float[]> LazyCompressTable = new Lazy<float[]>(() => private static readonly Lazy<float[]> LazyCompressTable = new Lazy<float[]>(
{ () =>
var result = new float[Length];
for (int i = 0; i < result.Length; i++)
{ {
double d = (double)i / Scale; var result = new float[Length];
if (d <= (0.04045 / 12.92))
{ for (int i = 0; i < result.Length; i++)
d *= 12.92;
}
else
{ {
d = (1.055 * Math.Pow(d, 1.0 / 2.4)) - 0.055; double d = (double)i / Scale;
if (d <= (0.04045 / 12.92))
{
d *= 12.92;
}
else
{
d = (1.055 * Math.Pow(d, 1.0 / 2.4)) - 0.055;
}
result[i] = (float)d;
} }
result[i] = (float)d; return result;
} },
true);
return result;
});
private static readonly Lazy<float[]> LazyExpandTable = new Lazy<float[]>(() => private static readonly Lazy<float[]> LazyExpandTable = new Lazy<float[]>(
{ () =>
var result = new float[Length];
for (int i = 0; i < result.Length; i++)
{ {
double d = (double)i / Scale; var result = new float[Length];
if (d <= 0.04045)
{ for (int i = 0; i < result.Length; i++)
d /= 12.92;
}
else
{ {
d = Math.Pow((d + 0.055) / 1.055, 2.4); double d = (double)i / Scale;
if (d <= 0.04045)
{
d /= 12.92;
}
else
{
d = Math.Pow((d + 0.055) / 1.055, 2.4);
}
result[i] = (float)d;
} }
result[i] = (float)d; return result;
} },
true);
return result;
});
private static float[] ExpandTable => LazyExpandTable.Value; private static float[] ExpandTable => LazyExpandTable.Value;

Loading…
Cancel
Save