All files / engine/Source/Core srgbToLinear.js

100% Statements 4/4
100% Branches 2/2
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                                    145x     145x   74x   71x              
import Check from "./Check.js";
 
/**
 * Converts the value from sRGB color space to linear color space.
 *
 * @function
 *
 * @param {number} value The color value in sRGB color space.
 * @returns {number} Returns the color value in linear color space.
 *
 * @example
 * const srgbColor = [0.5, 0.5, 0.5];
 * const linearColor = srgbColor.map(function (c) {
 *     return Cesium.srgbToLinear(c);
 * });
 */
function srgbToLinear(value) {
  //>>includeStart('debug', pragmas.debug);
  Check.defined("value", value);
  //>>includeEnd('debug');
 
  if (value <= 0.04045) {
    // eslint-disable-next-line no-loss-of-precision
    return value * 0.07739938080495356037151702786378;
  }
  return Math.pow(
    // eslint-disable-next-line no-loss-of-precision
    (value + 0.055) * 0.94786729857819905213270142180095,
    2.4,
  );
}
export default srgbToLinear;