File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -216,28 +216,37 @@ function XYZ_to_lin_a98rgb(XYZ) {
216216function 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
232236function 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 ;
You can’t perform that action at this time.
0 commit comments