Skip to content

Commit c9a6f04

Browse files
committed
[css-color-4] correct rec2020 transfer function
1 parent 337369a commit c9a6f04

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

css-color-4/conversions.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -216,28 +216,37 @@ function XYZ_to_lin_a98rgb(XYZ) {
216216
function lin_2020(RGB) {
217217
// convert an array of rec2020 RGB values in the range 0.0 - 1.0
218218
// to linear light (un-companded) form.
219+
// ITU-R BT.2020-2 p.4
220+
219221
const α = 1.09929682680944 ;
220222
const β = 0.018053968510807;
221223

224+
let sign = val < 0? -1 : 1;
225+
let abs = Math.abs(val);
226+
222227
return RGB.map(function (val) {
223-
if (val < β * 4.5 ) {
228+
if (abs < β * 4.5 ) {
224229
return val / 4.5;
225230
}
226231

227-
return Math.pow((val + α -1 ) / α, 2.4);
232+
return sign * Math.pow((val + α -1 ) / α, 1/0.45);
228233
});
229234
}
230-
//check with standard this really is 2.4 and 1/2.4, not 0.45 was wikipedia claims
231235

232236
function gam_2020(RGB) {
233237
// convert an array of linear-light rec2020 RGB in the range 0.0-1.0
234238
// to gamma corrected form
239+
// ITU-R BT.2020-2 p.4
240+
235241
const α = 1.09929682680944 ;
236242
const β = 0.018053968510807;
237243

244+
let sign = val < 0? -1 : 1;
245+
let abs = Math.abs(val);
246+
238247
return RGB.map(function (val) {
239-
if (val > β ) {
240-
return α * Math.pow(val, 1/2.4) - (α - 1);
248+
if (abs > β ) {
249+
return sign * α * Math.pow(val, 0.45) - (α - 1);
241250
}
242251

243252
return 4.5 * val;

0 commit comments

Comments
 (0)