File tree 1 file changed +14
-5
lines changed
1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -216,28 +216,37 @@ function XYZ_to_lin_a98rgb(XYZ) {
216
216
function lin_2020 ( RGB ) {
217
217
// convert an array of rec2020 RGB values in the range 0.0 - 1.0
218
218
// to linear light (un-companded) form.
219
+ // ITU-R BT.2020-2 p.4
220
+
219
221
const α = 1.09929682680944 ;
220
222
const β = 0.018053968510807 ;
221
223
224
+ let sign = val < 0 ? - 1 : 1 ;
225
+ let abs = Math . abs ( val ) ;
226
+
222
227
return RGB . map ( function ( val ) {
223
- if ( val < β * 4.5 ) {
228
+ if ( abs < β * 4.5 ) {
224
229
return val / 4.5 ;
225
230
}
226
231
227
- return Math . pow ( ( val + α - 1 ) / α , 2.4 ) ;
232
+ return sign * Math . pow ( ( val + α - 1 ) / α , 1 / 0.45 ) ;
228
233
} ) ;
229
234
}
230
- //check with standard this really is 2.4 and 1/2.4, not 0.45 was wikipedia claims
231
235
232
236
function gam_2020 ( RGB ) {
233
237
// convert an array of linear-light rec2020 RGB in the range 0.0-1.0
234
238
// to gamma corrected form
239
+ // ITU-R BT.2020-2 p.4
240
+
235
241
const α = 1.09929682680944 ;
236
242
const β = 0.018053968510807 ;
237
243
244
+ let sign = val < 0 ? - 1 : 1 ;
245
+ let abs = Math . abs ( val ) ;
246
+
238
247
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 ) ;
241
250
}
242
251
243
252
return 4.5 * val ;
You can’t perform that action at this time.
0 commit comments