Skip to content

Commit 5659148

Browse files
Use explicit threadsafety declaration.
1 parent 41d98d6 commit 5659148

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,49 +25,53 @@ public static class SRgbCompanding
2525
private const int Length = Scale + 2; // 256kb @ 16bit precision.
2626
private const int Scale = (1 << 16) - 1;
2727

28-
private static readonly Lazy<float[]> LazyCompressTable = new Lazy<float[]>(() =>
29-
{
30-
var result = new float[Length];
31-
32-
for (int i = 0; i < result.Length; i++)
28+
private static readonly Lazy<float[]> LazyCompressTable = new Lazy<float[]>(
29+
() =>
3330
{
34-
double d = (double)i / Scale;
35-
if (d <= (0.04045 / 12.92))
36-
{
37-
d *= 12.92;
38-
}
39-
else
31+
var result = new float[Length];
32+
33+
for (int i = 0; i < result.Length; i++)
4034
{
41-
d = (1.055 * Math.Pow(d, 1.0 / 2.4)) - 0.055;
35+
double d = (double)i / Scale;
36+
if (d <= (0.04045 / 12.92))
37+
{
38+
d *= 12.92;
39+
}
40+
else
41+
{
42+
d = (1.055 * Math.Pow(d, 1.0 / 2.4)) - 0.055;
43+
}
44+
45+
result[i] = (float)d;
4246
}
4347

44-
result[i] = (float)d;
45-
}
46-
47-
return result;
48-
});
48+
return result;
49+
},
50+
true);
4951

50-
private static readonly Lazy<float[]> LazyExpandTable = new Lazy<float[]>(() =>
51-
{
52-
var result = new float[Length];
53-
54-
for (int i = 0; i < result.Length; i++)
52+
private static readonly Lazy<float[]> LazyExpandTable = new Lazy<float[]>(
53+
() =>
5554
{
56-
double d = (double)i / Scale;
57-
if (d <= 0.04045)
58-
{
59-
d /= 12.92;
60-
}
61-
else
55+
var result = new float[Length];
56+
57+
for (int i = 0; i < result.Length; i++)
6258
{
63-
d = Math.Pow((d + 0.055) / 1.055, 2.4);
59+
double d = (double)i / Scale;
60+
if (d <= 0.04045)
61+
{
62+
d /= 12.92;
63+
}
64+
else
65+
{
66+
d = Math.Pow((d + 0.055) / 1.055, 2.4);
67+
}
68+
69+
result[i] = (float)d;
6470
}
6571

66-
result[i] = (float)d;
67-
}
68-
69-
return result;
70-
});
72+
return result;
73+
},
74+
true);
7175

7276
private static float[] ExpandTable => LazyExpandTable.Value;
7377

0 commit comments

Comments
 (0)