Skip to content

Commit

Permalink
Correct rec2100-hlg, #190
Browse files Browse the repository at this point in the history
  • Loading branch information
svgeesus authored and LeaVerou committed Jan 16, 2023
1 parent b235490 commit f3791da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/spaces/rec2020-linear.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ export default new RGBColorSpace({
name: "Linear REC.2020",
white: "D65",
toXYZ_M,
fromXYZ_M
fromXYZ_M,
formats: {
color: {},
}
});
25 changes: 18 additions & 7 deletions src/spaces/rec2100-hlg.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const a = 0.17883277;
const b = 0.28466892; // 1 - (4 * a)
const c = 0.55991073; // 0.5 - a * Math.log(4 *a)

const scale = 3.7743; // Place 18% grey at HLG 0.38, so media white at 0.75

export default new RGBColorSpace({
id: "rec2100hlg",
cssid: "rec2100-hlg",
Expand All @@ -18,21 +20,30 @@ export default new RGBColorSpace({
// given HLG encoded component in range [0, 1]
// return media-white relative linear-light
return RGB.map(function (val) {
if (val <= 1/12) {
return Math.sqrt( 3 * val);
// first the HLG EOTF
// ITU-R BT.2390-10 p.30 section
// 6.3 The hybrid log-gamma electro-optical transfer function (EOTF)
// Then scale by 3 so media white is 1.0
if (val <= 0.5) {
return (val ** 2) / 3 * scale;
}
return a * Math.log(12 * val - b) + c;
return Math.exp(((val - c) / a) + b) / 12 * scale;
});
},
fromBase (RGB) {
// given media-white relative linear-light
// where diffuse white is 1.0,
// return HLG encoded component in range [0, 1]
// per ITU Rec BT.2390
return RGB.map(function (val) {
if (val <= 0.5) {
return (val ** 2) / 3;
// first scale to put linear-light media white at 1/3
val /= scale;
// now the HLG OETF
// ITU-R BT.2390-10 p.23
// 6.1 The hybrid log-gamma opto-electronic transfer function (OETF)
if (val <= 1/12) {
return Math.sqrt( 3 * val);
}
return Math.exp(((val - c) / a) + b) / 12;
return a * Math.log(12 * val - b) + c;
});
},
formats: {
Expand Down

0 comments on commit f3791da

Please sign in to comment.