From 3cbd8e393d570ba53184b7386667ede3685248ba Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 18 Dec 2020 15:58:31 +0000 Subject: [PATCH] Use explicit threadsafety declaration. --- .../ColorSpaces/Companding/SRgbCompanding.cs | 72 ++++++++++--------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs b/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs index 4bc790493c..dc6c960aa5 100644 --- a/src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs +++ b/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 Scale = (1 << 16) - 1; - private static readonly Lazy LazyCompressTable = new Lazy(() => - { - var result = new float[Length]; - - for (int i = 0; i < result.Length; i++) + private static readonly Lazy LazyCompressTable = new Lazy( + () => { - double d = (double)i / Scale; - if (d <= (0.04045 / 12.92)) - { - d *= 12.92; - } - else + var result = new float[Length]; + + for (int i = 0; i < result.Length; i++) { - 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; - }); + return result; + }, + true); - private static readonly Lazy LazyExpandTable = new Lazy(() => - { - var result = new float[Length]; - - for (int i = 0; i < result.Length; i++) + private static readonly Lazy LazyExpandTable = new Lazy( + () => { - double d = (double)i / Scale; - if (d <= 0.04045) - { - d /= 12.92; - } - else + var result = new float[Length]; + + for (int i = 0; i < result.Length; i++) { - 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; - }); + return result; + }, + true); private static float[] ExpandTable => LazyExpandTable.Value;