| 1 |
import RGBColorSpace from "../RGBColorSpace.js"; |
| 2 |
import REC_2100_Linear from "./rec2100-linear.js"; |
| 3 |
import { spow } from "../util.js"; |
| 4 |
|
| 5 |
const a = 0.17883277; |
| 6 |
const b = 0.28466892; // 1 - (4 * a) |
| 7 |
const c = 0.55991073; // 0.5 - a * Math.log(4 *a) |
| 8 |
|
| 9 |
const scale = 3.7743; // Place 18% grey at HLG 0.38, so media white at 0.75 |
| 10 |
|
| 11 |
export default new RGBColorSpace({ |
| 12 |
id: "rec2100hlg", |
| 13 |
cssId: "rec2100-hlg", |
| 14 |
name: "REC.2100-HLG", |
| 15 |
referred: "scene", |
| 16 |
|
| 17 |
base: REC_2100_Linear, |
| 18 |
linearGamut: REC_2100_Linear, |
| 19 |
toBase (RGB) { |
| 20 |
// given HLG encoded component in range [0, 1] |
| 21 |
// return media-white relative linear-light |
| 22 |
return RGB.map(function (val) { |
| 23 |
// first the HLG EOTF |
| 24 |
// ITU-R BT.2390-10 p.30 section |
| 25 |
// 6.3 The hybrid log-gamma electro-optical transfer function (EOTF) |
| 26 |
// Then scale by 3 so media white is 1.0 |
| 27 |
if (val <= 0.5) { |
| 28 |
return (val ** 2 / 3) * scale; |
| 29 |
} |
| 30 |
return ((Math.exp((val - c) / a) + b) / 12) * scale; |
| 31 |
}); |
| 32 |
}, |
| 33 |
fromBase (RGB) { |
| 34 |
// given media-white relative linear-light |
| 35 |
// where diffuse white is 1.0, |
| 36 |
// return HLG encoded component in range [0, 1] |
| 37 |
return RGB.map(function (val) { |
| 38 |
// first scale to put linear-light media white at 1/3 |
| 39 |
val /= scale; |
| 40 |
// now the HLG OETF |
| 41 |
// ITU-R BT.2390-10 p.23 |
| 42 |
// 6.1 The hybrid log-gamma opto-electronic transfer function (OETF) |
| 43 |
if (val <= 1 / 12) { |
| 44 |
return spow(3 * val, 0.5); |
| 45 |
} |
| 46 |
return a * Math.log(12 * val - b) + c; |
| 47 |
}); |
| 48 |
}, |
| 49 |
}); |