-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
248 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// PQ Constants | ||
// https://en.wikipedia.org/wiki/High-dynamic-range_video#Perceptual_quantizer | ||
export const M1 = 2610 / 16384; | ||
export const M2 = 2523 / 32; | ||
export const IM1 = 16384 / 2610; | ||
export const IM2 = 32 / 2523; | ||
export const C1 = 3424 / 4096; | ||
export const C2 = 2413 / 128; | ||
export const C3 = 2392 / 128; | ||
|
||
// Maximum luminance in PQ is 10,000 cd/m^2 | ||
// Relative XYZ has Y=1 for media white | ||
// BT.2048 says media white Y=203 at PQ 58 | ||
// | ||
// This is confirmed here: https://www.itu.int/dms_pub/itu-r/opb/rep/R-REP-BT.2408-3-2019-PDF-E.pdf | ||
export const YW = 203; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { YW } from './constants.js'; | ||
import { pq_st2084_eotf } from './utils.js'; | ||
|
||
const convertItpToXyz65 = ({ i, t, p, alpha }) => { | ||
const [l, m, s] = [ | ||
i + 0.008609037037932761 * t + 0.11102962500302593 * p, | ||
i - 0.00860903703793275 * t - 0.11102962500302599 * p, | ||
i + 0.5600313357106791 * t - 0.32062717498731885 * p | ||
].map(pq_st2084_eotf); | ||
const [x, y, z] = [ | ||
2.0701522183894223 * l - | ||
1.3263473389671556 * m + | ||
0.20665104762940512 * s, | ||
0.36473852097480713 * l + | ||
0.6805660249472276 * m - | ||
0.04530454592203474 * s, | ||
-0.04974720753581203 * l - | ||
0.04926096669661379 * m + | ||
1.1880659249923042 * s | ||
].map(c => Math.max(c / YW, 0)); | ||
|
||
const res = { mode: 'xyz65', x, y, z }; | ||
if (alpha !== undefined) { | ||
res.alpha = alpha; | ||
} | ||
|
||
return res; | ||
}; | ||
|
||
export default convertItpToXyz65; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { YW } from './constants.js'; | ||
import { pq_st2084_oetf } from './utils.js'; | ||
|
||
const convertXyz65ToItp = ({ x, y, z, alpha }) => { | ||
const [absX, absY, absZ] = [x, y, z].map(c => Math.max(c * YW, 0)); | ||
const [l, m, s] = [ | ||
0.3592832590121218 * absX + | ||
0.6976051147779497 * absY - | ||
0.0358915932320289 * absZ, | ||
-0.1920808463704992 * absX + | ||
1.1004767970374318 * absY + | ||
0.07537486585191187 * absZ, | ||
0.007079784460747716 * absX + | ||
0.07483966621863658 * absY + | ||
0.8433265453898765 * absZ | ||
].map(pq_st2084_oetf); | ||
|
||
const i = 0.5 * l + 0.5 * m; | ||
const t = 1.61376953125 * l + -3.323486328125 * m + 1.709716796875 * s; | ||
const p = 4.378173828125 * l + -4.24560546875 * m + -0.132568359375 * s; | ||
|
||
const res = { mode: 'itp', i, t, p }; | ||
if (alpha !== undefined) { | ||
res.alpha = alpha; | ||
} | ||
|
||
return res; | ||
}; | ||
|
||
export default convertXyz65ToItp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { interpolatorLinear } from '../interpolate/linear.js'; | ||
import { fixupAlpha } from '../fixup/alpha.js'; | ||
import convertItpToXyz65 from './convertItpToXyz65.js'; | ||
import convertXyz65ToItp from './convertXyz65ToItp.js'; | ||
import { convertRgbToXyz65, convertXyz65ToRgb } from '../index.js'; | ||
|
||
/* | ||
ICtCp (or ITP) color space, as defined in ITU-R Recommendation BT.2100. | ||
ICtCp is drafted to be supported in CSS within | ||
[CSS Color HDR Module Level 1](https://drafts.csswg.org/css-color-hdr/#ICtCp) spec. | ||
*/ | ||
|
||
const definition = { | ||
mode: 'itp', | ||
channels: ['i', 't', 'p', 'alpha'], | ||
parse: ['--ictcp'], | ||
serialize: '--ictcp', | ||
|
||
toMode: { | ||
xyz65: convertItpToXyz65, | ||
rgb: color => convertXyz65ToRgb(convertItpToXyz65(color)) | ||
}, | ||
|
||
fromMode: { | ||
xyz65: convertXyz65ToItp, | ||
rgb: color => convertXyz65ToItp(convertRgbToXyz65(color)) | ||
}, | ||
|
||
ranges: { | ||
i: [0, 0.581], | ||
t: [-0.369, 0.272], | ||
p: [-0.164, 0.331] | ||
}, | ||
|
||
interpolate: { | ||
i: interpolatorLinear, | ||
t: interpolatorLinear, | ||
p: interpolatorLinear, | ||
alpha: { use: interpolatorLinear, fixup: fixupAlpha } | ||
} | ||
}; | ||
|
||
export default definition; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { C1, C2, C3, IM1, IM2, M1, M2 } from './constants.js'; | ||
|
||
function npow(base, exp) { | ||
return Math.sign(base) * Math.pow(Math.abs(base), exp); | ||
} | ||
|
||
export function pq_st2084_oetf(c) { | ||
const powC = npow(c / 10000, M1); | ||
const r = (C1 + C2 * powC) / (1 + C3 * powC); | ||
return npow(r, M2); | ||
} | ||
|
||
export function pq_st2084_eotf(c) { | ||
const powC = npow(c, IM2); | ||
const r = (powC - C1) / (C2 - C3 * powC); | ||
return 10000 * npow(r, IM1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.