public static byte PerformLookup(byte value) { if (_lookupTable is null) { CalculateLookups(); } // Can safely cast to byte, cause of the constrain of 255 return((byte)ScalingUtils.ConstrainNonnegative(_lookupTable[value], 255)); }
private static void CalculateLookups() { var lut = new short[OutputRange + 1]; const double coefficientA = -CoefficientB; var coefficientC = Math.Log((OutputRange - coefficientA) / CoefficientB) / OutputRange; for (var i = 0; i < OutputRange + 1; i++) { lut[i] = (short)Math.Ceiling(coefficientA + CoefficientB * Math.Exp(coefficientC * i)); lut[i] = ScalingUtils.ConstrainNonnegative(lut[i], OutputRange); } _lookupTable = lut; }