| 1 |
import RGBColorSpace from "../RGBColorSpace.js"; |
| 2 |
import "../CATs.js"; // because of the funky whitepoint |
| 3 |
import ACEScg from "./acescg.js"; |
| 4 |
|
| 5 |
const ε = 2 ** -16; |
| 6 |
|
| 7 |
// the smallest value which, in the 32bit IEEE 754 float encoding, |
| 8 |
// decodes as a non-negative value |
| 9 |
const ACES_min_nonzero = -0.35828683; |
| 10 |
|
| 11 |
// brightest encoded value, decodes to 65504 |
| 12 |
const ACES_cc_max = (Math.log2(65504) + 9.72) / 17.52; // 1.468 |
| 13 |
|
| 14 |
export default new RGBColorSpace({ |
| 15 |
id: "acescc", |
| 16 |
cssId: "--acescc", |
| 17 |
name: "ACEScc", |
| 18 |
// see S-2014-003 ACEScc – A Logarithmic Encoding of ACES Data |
| 19 |
// https://docs.acescentral.com/specifications/acescc/ |
| 20 |
// uses the AP1 primaries, see section 4.3.1 Color primaries |
| 21 |
|
| 22 |
// Appendix A: "Very small ACES scene referred values below 7 1/4 stops |
| 23 |
// below 18% middle gray are encoded as negative ACEScc values. |
| 24 |
// These values should be preserved per the encoding in Section 4.4 |
| 25 |
// so that all positive ACES values are maintained." |
| 26 |
coords: { |
| 27 |
r: { |
| 28 |
range: [ACES_min_nonzero, ACES_cc_max], |
| 29 |
name: "Red", |
| 30 |
}, |
| 31 |
g: { |
| 32 |
range: [ACES_min_nonzero, ACES_cc_max], |
| 33 |
name: "Green", |
| 34 |
}, |
| 35 |
b: { |
| 36 |
range: [ACES_min_nonzero, ACES_cc_max], |
| 37 |
name: "Blue", |
| 38 |
}, |
| 39 |
}, |
| 40 |
referred: "scene", |
| 41 |
|
| 42 |
base: ACEScg, |
| 43 |
linearGamut: ACEScg, |
| 44 |
// from section 4.4.2 Decoding Function |
| 45 |
toBase (RGB) { |
| 46 |
const low = (9.72 - 15) / 17.52; // -0.3014 |
| 47 |
|
| 48 |
return RGB.map(function (val) { |
| 49 |
if (val <= low) { |
| 50 |
return (2 ** (val * 17.52 - 9.72) - ε) * 2; // very low values, below -0.3014 |
| 51 |
} |
| 52 |
else if (val < ACES_cc_max) { |
| 53 |
return 2 ** (val * 17.52 - 9.72); |
| 54 |
} |
| 55 |
else { |
| 56 |
// val >= ACES_cc_max |
| 57 |
return 65504; |
| 58 |
} |
| 59 |
}); |
| 60 |
}, |
| 61 |
|
| 62 |
// Non-linear encoding function from S-2014-003, section 4.4.1 Encoding Function |
| 63 |
fromBase (RGB) { |
| 64 |
return RGB.map(function (val) { |
| 65 |
if (val <= 0) { |
| 66 |
return (Math.log2(ε) + 9.72) / 17.52; // -0.3584 |
| 67 |
} |
| 68 |
else if (val < ε) { |
| 69 |
return (Math.log2(ε + val * 0.5) + 9.72) / 17.52; |
| 70 |
} |
| 71 |
else { |
| 72 |
// val >= ε |
| 73 |
return (Math.log2(val) + 9.72) / 17.52; |
| 74 |
} |
| 75 |
}); |
| 76 |
}, |
| 77 |
// encoded media white (rgb 1,1,1) => linear [ 222.861, 222.861, 222.861 ] |
| 78 |
// encoded media black (rgb 0,0,0) => linear [ 0.0011857, 0.0011857, 0.0011857] |
| 79 |
}); |