| 1 |
import RGBColorSpace from "../RGBColorSpace.js"; |
| 2 |
import REC_2100_Linear from "./rec2100-linear.js"; |
| 3 |
|
| 4 |
const Yw = 203; // absolute luminance of media white, cd/m² |
| 5 |
const n = 2610 / 2 ** 14; |
| 6 |
const ninv = 2 ** 14 / 2610; |
| 7 |
const m = 2523 / 2 ** 5; |
| 8 |
const minv = 2 ** 5 / 2523; |
| 9 |
const c1 = 3424 / 2 ** 12; |
| 10 |
const c2 = 2413 / 2 ** 7; |
| 11 |
const c3 = 2392 / 2 ** 7; |
| 12 |
|
| 13 |
export default new RGBColorSpace({ |
| 14 |
id: "rec2100pq", |
| 15 |
cssId: "rec2100-pq", |
| 16 |
name: "REC.2100-PQ", |
| 17 |
base: REC_2100_Linear, |
| 18 |
linearGamut: REC_2100_Linear, |
| 19 |
toBase (RGB) { |
| 20 |
// given PQ encoded component in range [0, 1] |
| 21 |
// return media-white relative linear-light |
| 22 |
return RGB.map(function (val) { |
| 23 |
let x = (Math.max(val ** minv - c1, 0) / (c2 - c3 * val ** minv)) ** ninv; |
| 24 |
return (x * 10000) / Yw; // luminance relative to diffuse white, [0, 70 or so]. |
| 25 |
}); |
| 26 |
}, |
| 27 |
fromBase (RGB) { |
| 28 |
// given media-white relative linear-light |
| 29 |
// returnPQ encoded component in range [0, 1] |
| 30 |
return RGB.map(function (val) { |
| 31 |
let x = Math.max((val * Yw) / 10000, 0); // absolute luminance of peak white is 10,000 cd/m². |
| 32 |
let num = c1 + c2 * x ** n; |
| 33 |
let denom = 1 + c3 * x ** n; |
| 34 |
|
| 35 |
return (num / denom) ** m; |
| 36 |
}); |
| 37 |
}, |
| 38 |
}); |