Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct rec2100-hlg, #190 #271

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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