Skip to content

Commit 53b4479

Browse files
committed
Adjustments to itp color space:
* Add references in Color Spaces docs * Avoid creating intermediary objects in conversion functions * Handle missing (`none`) components in the conversion functions * Clean up HDR constants
1 parent 28646c6 commit 53b4479

File tree

5 files changed

+61
-41
lines changed

5 files changed

+61
-41
lines changed

docs/color-spaces.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,15 +442,17 @@ It has the default _Chroma from Luma_ adjustment applied (effectively Y is subtr
442442

443443
Does not have gamut limits.
444444

445-
#### `itp`
445+
### <abbr>IC<sub>t</sub>C<sub>p</sub></abbr>
446+
447+
<abbr>IC<sub>t</sub>C<sub>p</sub></abbr> (or <abbr>ITP</abbr>) color space developed by [Dolby Laboratories](https://professional.dolby.com/siteassets/pdfs/ictcp_dolbywhitepaper_v071.pdf), as defined in [<abbr>ITU-R</abbr> Recommendation BT.2100](https://www.itu.int/rec/R-REC-BT.2100). It is included in the <abbr>CSS</abbr> [<abbr>HDR</abbr> Color Module Level 1](https://drafts.csswg.org/css-color-hdr/#ICtCp) specification.
446448

447-
IC<sub>t</sub>C<sub>p</sub> (or ITP) color space, as defined in ITU-R Recommendation BT.2100.
449+
#### `itp`
448450

449451
| Channel | Range | Description |
450452
|---------|-------------------|-----------------------|
451453
| `i` | `[0, 0.581]`| Intensity |
452-
| `t` | `[-0.282, 0.278]`| Blue-yellow component |
453-
| `p` | `[-0.162, 0.279]`| Green–red component |
454+
| `t` | `[-0.282, 0.278]`| Blue-yellow component (“tritanopia”) |
455+
| `p` | `[-0.162, 0.279]`| Green–red component (“protanopia”) |
454456

455457
Serialized as `color(--ictcp i t p)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
456458

src/hdr/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
Relative XYZ has Y=1 for media white,
3+
BT.2048 says media white Y=203 (at PQ 58).
4+
See: https://www.itu.int/dms_pub/itu-r/opb/rep/R-REP-BT.2408-3-2019-PDF-E.pdf
5+
*/
6+
export const YW = 203;

src/itp/constants.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/itp/convertItpToXyz65.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,42 @@
1-
import { YW } from './constants.js';
1+
import { YW } from '../hdr/constants.js';
22
import { transferPqDecode } from '../hdr/transfer.js';
33

4+
const toRel = c => Math.max(c / YW, 0);
5+
46
const convertItpToXyz65 = ({ i, t, p, alpha }) => {
5-
const [l, m, s] = [
6-
i + 0.008609037037932761 * t + 0.11102962500302593 * p,
7-
i - 0.00860903703793275 * t - 0.11102962500302599 * p,
7+
if (i === undefined) i = 0;
8+
if (t === undefined) t = 0;
9+
if (p === undefined) p = 0;
10+
11+
const l = transferPqDecode(
12+
i + 0.008609037037932761 * t + 0.11102962500302593 * p
13+
);
14+
const m = transferPqDecode(
15+
i - 0.00860903703793275 * t - 0.11102962500302599 * p
16+
);
17+
const s = transferPqDecode(
818
i + 0.5600313357106791 * t - 0.32062717498731885 * p
9-
].map(transferPqDecode);
19+
);
1020

11-
const [x, y, z] = [
12-
2.0701522183894219 * l -
13-
1.3263473389671556 * m +
14-
0.2066510476294051 * s,
15-
0.3647385209748074 * l + 0.680566024947227 * m - 0.0453045459220346 * s,
16-
-0.049747207535812 * l - 0.0492609666966138 * m + 1.1880659249923042 * s
17-
].map(c => Math.max(c / YW, 0));
21+
const res = {
22+
mode: 'xyz65',
23+
x: toRel(
24+
2.0701522183894219 * l -
25+
1.3263473389671556 * m +
26+
0.2066510476294051 * s
27+
),
28+
y: toRel(
29+
0.3647385209748074 * l +
30+
0.680566024947227 * m -
31+
0.0453045459220346 * s
32+
),
33+
z: toRel(
34+
-0.049747207535812 * l -
35+
0.0492609666966138 * m +
36+
1.1880659249923042 * s
37+
)
38+
};
1839

19-
const res = { mode: 'xyz65', x, y, z };
2040
if (alpha !== undefined) {
2141
res.alpha = alpha;
2242
}

src/itp/convertXyz65ToItp.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1-
import { YW } from './constants.js';
1+
import { YW } from '../hdr/constants.js';
22
import { transferPqEncode } from '../hdr/transfer.js';
33

4+
const toAbs = (c = 0) => Math.max(c * YW, 0);
5+
46
const convertXyz65ToItp = ({ x, y, z, alpha }) => {
5-
const [absX, absY, absZ] = [x, y, z].map(c => Math.max(c * YW, 0));
6-
const [l, m, s] = [
7+
const absX = toAbs(x);
8+
const absY = toAbs(y);
9+
const absZ = toAbs(z);
10+
const l = transferPqEncode(
711
0.3592832590121217 * absX +
812
0.6976051147779502 * absY -
9-
0.0358915932320289 * absZ,
13+
0.0358915932320289 * absZ
14+
);
15+
const m = transferPqEncode(
1016
-0.1920808463704995 * absX +
1117
1.1004767970374323 * absY +
12-
0.0753748658519118 * absZ,
18+
0.0753748658519118 * absZ
19+
);
20+
const s = transferPqEncode(
1321
0.0070797844607477 * absX +
1422
0.0748396662186366 * absY +
1523
0.8433265453898765 * absZ
16-
].map(transferPqEncode);
24+
);
1725

1826
const i = 0.5 * l + 0.5 * m;
19-
const t = 1.61376953125 * l + -3.323486328125 * m + 1.709716796875 * s;
20-
const p = 4.378173828125 * l + -4.24560546875 * m + -0.132568359375 * s;
27+
const t = 1.61376953125 * l - 3.323486328125 * m + 1.709716796875 * s;
28+
const p = 4.378173828125 * l - 4.24560546875 * m - 0.132568359375 * s;
2129

2230
const res = { mode: 'itp', i, t, p };
2331
if (alpha !== undefined) {

0 commit comments

Comments
 (0)