Skip to content

Commit 08d0981

Browse files
authored
Add interface to query the display color volume and linear display light encoding
Closes #110 Closes #109 Closes #103 Closes #102 Closes #100 Closes #99 Closes #92 Closes #50 Closes #42 Closes #39 Closes #36
1 parent 955eead commit 08d0981

File tree

3 files changed

+163
-47
lines changed

3 files changed

+163
-47
lines changed

hdr_html_canvas_element.md

Lines changed: 163 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Adding support High Dynamic Range (HDR) imagery to HTML Canvas: a baseline proposal
1+
# Adding support High Dynamic Range (HDR) imagery to HTML Canvas: a baseline proposal (version 2)
22

33
## Introduction
44

@@ -24,31 +24,40 @@ BT.2100 HLG. All movies and TV shows are distributed using either of these two
2424
color spaces. Products with HDMI and/or DisplayPort interfaces also use these
2525
color spaces for HDR support.
2626

27-
* To render HDR imagery, it is useful to have information on the luminance range
28-
and color gamut that were used when authoring the image.
27+
* To reproduce an HDR image on a display, it is useful to have information on
28+
both the color volume of that display and the color volume of the image since
29+
one can be significantly smaller than the other.
2930

3031
Accordingly, the following API modifications are needed to manipulate HDR images
3132
in HTML Canvas:
3233

33-
1. add BT.2100 PQ and BT.2100 HLG color spaces to `PredefinedColorSpace`
34+
1. add BT.2100 color spaces to `PredefinedColorSpace`
3435
2. add higher bit depth capabilities to `CanvasRenderingContext2DSettings`
3536
3. add higher bit depth capabilities to `ImageDataSettings`
36-
4. add luminance and color gamut information to `ImageDataSettings` and
37+
4. add image color volume information to `ImageDataSettings` and
3738
`CanvasRenderingContext2DSettings`
39+
5. add display color volume information to the `Screen` interface of the CSS
40+
Object Model, to determine the characteristics of the display on which the
41+
image is being reproduced
3842

3943
## Target use cases
4044

41-
The primary use case is the drawing of HDR images into an HTML Canvas element
42-
such that the images are displayed as they would have been if they had been
43-
introduced in an `img` or `video` element. Example applications include:
45+
As illustrated below, the primary use case is the drawing of HDR images into an
46+
HTML Canvas element such that the images are displayed as they would have been
47+
if they had been introduced in an `img` or `video` element.
48+
49+
![Primary Use Case](./primary-use-case.png)
50+
51+
Example applications include:
4452

4553
* drawing images retrieved from a file whose format is not supported by the
4654
`img` or `video` elements
4755
* collage of images, both HDR and SDR
4856
* adding graphics to an HDR image
4957
* drawing of visual elements that are related to an HDR presentation in a
5058
`video` element, with the expectation that the former match the look of the
51-
latter.
59+
latter
60+
* authoring HDR images
5261

5362
## Scope
5463

@@ -58,8 +67,6 @@ BT.2100 PQ and BT.2100 HLG color spaces.
5867

5968
This proposal:
6069

61-
* does not target applications that require high-performance custom image
62-
tone-mapping or compositing methods.
6370
* does not preclude adding other HDR capabilities to HTML Canvas, such as
6471
support for additional color spaces like a linear high-dynamic range color
6572
space.
@@ -71,7 +78,7 @@ This proposal:
7178
### General
7279

7380
Extend [`PredefinedColorSpace`](https://html.spec.whatwg.org/multipage/canvas.html#predefinedcolorspace) to
74-
include the following color spaces.
81+
include the following HDR color spaces.
7582

7683
```idl
7784
partial enum PredefinedColorSpace {
@@ -81,28 +88,19 @@ include the following color spaces.
8188
8289
"rec2100-hlg",
8390
"rec2100-pq",
91+
"rec2100-display-linear",
8492
}
8593
```
8694

8795
Extending `PredefinedColorSpace` automatically extends
8896
`CanvasRenderingContext2DSettings` and `ImageDataSettings`.
8997

90-
A Canvas that is initialized with `rec2100-pq` and `rec2100-hlg` is an HDR
91-
Canvas; otherwise it is an SDR Canvas.
92-
93-
As illustrated below, the tone mapping of `rec2100-pq` and `rec2100-hlg` images,
94-
i.e. the rendering of an image with a given dynamic range onto a display with
95-
different dynamic range, is performed by the platform. This is akin to the
96-
scenario where the `src` of an `img` element is a PQ or HLG image.
97-
98-
![Tone mapping scenarios](./tone-mapping-scenarios.png)
98+
A Canvas that is initialized with an HDR color space is an HDR Canvas; otherwise
99+
it is an SDR Canvas.
99100

100-
SDR images that are drawn to an HDR Canvas are first converted to an HDR
101-
representation. Conversely, HDR images that are drawn into SDR Canvas are first
102-
converted to an SDR representation.
103-
104-
Conversions to and from `rec2100-pq` and `rec2100-hlg` are detailed in Annex A
105-
below.
101+
When drawing an image into a Canvas, the image will be transformed unless the
102+
color spaces of the image and the Canvas match. Annex A specifies transformation
103+
to and from `rec2100-pq` and `rec2100-hlg`.
106104

107105
### rec2100-hlg
108106

@@ -119,6 +117,12 @@ specified in Rec. ITU-R BT.2100.
119117
_NOTE: {R', G', B'} are in the range [0, 1], i.e. they are not expressed in
120118
cd/m<sup>2</sup>_
121119

120+
### rec2100-display-linear
121+
122+
The linear display-referred component signals {R, G, B} are mapped to red, green
123+
and blue tristimulus values such that R = G = B = 1.0 represents HDR reference
124+
white with a nominal luminance of 203 cd/m².
125+
122126
## Extend `CanvasRenderingContext2DSettings` to support higher bit depths
123127

124128
Add to `CanvasRenderingContext2DSettings` a `CanvasDataType` member that
@@ -200,7 +204,7 @@ Add a new CanvasColorMetadata dictionary:
200204

201205
```idl
202206
dictionary CanvasColorMetadata {
203-
CanvasColorVolumeMetadata colorVolumeMetadata;
207+
optional ColorVolumeInfo contentColorVolume;
204208
}
205209
```
206210

@@ -220,7 +224,7 @@ dictionary CanvasColorMetadata {
220224
```
221225

222226
```idl
223-
dictionary CanvasColorVolumeMetadata {
227+
dictionary ColorVolumeInfo {
224228
optional Chromaticities chromaticity;
225229
optional double minimumLuminance;
226230
optional double maximumLuminance;
@@ -236,7 +240,7 @@ Add a mechanism for specifying this on `CanvasRenderingContext2D` and
236240
}
237241
```
238242

239-
`colorVolumeMetadata` specifies the nominal color volume occupied by
243+
`contentColorVolume` specifies the nominal color volume occupied by
240244
the image content in the CIE 1931 XYZ color space. The boundaries of the color
241245
volume are defined by:
242246

@@ -257,21 +261,21 @@ If omitted, `maximumLuminance` is equal to 1,000 cd/m².
257261
The color volume is nominal because it MAY be smaller or larger than the actual
258262
color volume of image content, but SHOULD not be smaller.
259263

260-
If present, `colorVolumeMetadata` SHOULD completely define the tone mapping
264+
If present, `contentColorVolume` SHOULD completely define the color volume mapping
261265
algorithm used when rendering the image to a display. For example, the
262266
_rec2100-pq to srgb_ mapping specified in Annex A uses the `minimumLuminance`
263267
and `maximumLuminance` parameters.
264268

265-
If `colorVolumeMetadata` is not present, the tone mapping algorithm is left
269+
If `contentColorVolume` is not present, the color volume mapping algorithm is left
266270
entirely to the implementation.
267271

268-
`colorVolumeMetadata` SHOULD be set if known, e.g. if obtained from metadata
272+
`contentColorVolume` SHOULD be set if known, e.g. if obtained from metadata
269273
contained in a source image, and omitted otherwise. This is particularly
270-
important when drawing a temporal sequence of images. If `colorVolumeMetadata`
271-
is not set, the tone mapping algorithm can vary over the sequence, resulting in
274+
important when drawing a temporal sequence of images. If `contentColorVolume`
275+
is not set, the color volume mapping algorithm can vary over the sequence, resulting in
272276
temporal artifacts.
273277

274-
For example, `colorVolumeMetadata` can be set according to the Mastering Display
278+
For example, `contentColorVolume` can be set according to the Mastering Display
275279
Color Volume and Content Light Level Information chunks found in a PNG image:
276280
the color volume of the image content is typically smaller than, or coincides
277281
with, that of the mastering display. For the color primaries and white point of
@@ -283,6 +287,97 @@ the Content Light Level Information chunk can provide more accurate information
283287
than the maximum luminance parameter of the Mastering Display Color Volume
284288
chunk.
285289

290+
As specified below, the platform does not generally apply color volume mapping
291+
if the color volume of the image is smaller than that of the display.
292+
293+
## Add display color volume information to `Screen` interface of the CSS Object Model
294+
295+
Add a new `screenColorInfo` attribute to the `Screen` interface:
296+
297+
```idl
298+
partial interface Screen {
299+
optional ScreenColorInfo screenColorInfo;
300+
}
301+
```
302+
303+
```idl
304+
dictionary ScreenColorInfo {
305+
optional ColorVolumeInfo colorVolume;
306+
optional double referenceWhiteLuminance;
307+
}
308+
```
309+
310+
If present,
311+
312+
* `colorVolume` specifies, as defined above, the set of colors that the screen
313+
of the output device can reproduce without significant color volume mapping; and
314+
* `referenceWhiteLuminance` specifies the luminance of reference white as
315+
reproduced by the screen of the output device, and reflects viewing environment
316+
and user settings.
317+
318+
When omitted, the value of a parameter is unspecified. It is preferable to omit
319+
parameters than to provide default or nominal values that are not known to be
320+
valid or accurate.
321+
322+
`referenceWhiteLuminance` must be larger than or equal to `minimumLuminance`,
323+
and smaller than or equal to `maximumLuminance`. The ratio of `maximumLuminance`
324+
to `referenceWhiteLuminance` effectively specifies the headroom available for
325+
HDR imagery.
326+
327+
_Reference white_ is also commonly referred to as diffuse white and graphics
328+
white.
329+
330+
_EXAMPLE_: [Report ITU-R BT.2408](https://www.itu.int/pub/R-REP-BT.2408)
331+
specifies that the luminance of reference white for a PQ reference display, or a
332+
1 000 cd/m² HLG display, is 203 cd/m².
333+
334+
_EXAMPLE_: A PC monitor in a bright environment might report a
335+
`maximumLuminance` of 600 cd/m² and a `referenceWhiteLuminance` of 400 cd/m².
336+
337+
`screenColorInfo` can, for example, be used in the following scenarios:
338+
339+
* an authoring application can use the information to (i) avoid image colors
340+
exceeding the color volume of the output device and (ii) correspondingly set
341+
`contentColorVolume` in `CanvasColorMetadata` (see above).
342+
* a player application can use the information to map the colors of the image to
343+
the color volume of the output device if some of the former are outside the
344+
latter -- this allows the application to use its own mapping algorithm,
345+
substituting those provided by the underlying platform.
346+
347+
In absence of some or all the parameters of `screenColorInfo`:
348+
349+
* the [`dynamic-range`](https://drafts.csswg.org/mediaqueries-5/#dynamic-range)
350+
media query can be used to determine whether the output device supports
351+
high-dynamic range imagery; and
352+
* the
353+
[`color-gamut`](https://drafts.csswg.org/mediaqueries-5/#descdef-media-color-gamut)
354+
media query feature can be used to determine whether the output device supports
355+
wide color gamut imagery.
356+
357+
## Color Volume Mapping
358+
359+
As illustrated by (b) below, when the the color volume of the image is not a
360+
subset of the color volume of the display, the platform performs color volume
361+
mapping, i.e. modifies the colors of the image to make them fit within the
362+
capabilities of the display.
363+
364+
Conversely and as illustrated by (a) below, the platform does not perform color
365+
volume mapping if the color volume of the image is a subset of the color volume
366+
of the display.
367+
368+
It is possible for an application to avoid color volume mapping by the platform
369+
by ensuring that the color volume of the image, as specified
370+
by`contentColorVolume`, is within `screenColorInfo`. This can be achieved,
371+
for example, by:
372+
373+
* preventing in the first place an author from creating colors exceeding the
374+
display color volume.
375+
* the application performing its own color volume mapping such that the
376+
resulting image color volume is within the display color volume, as
377+
illustrated by (c) below.
378+
379+
![Color Volume Mapping Scenarios](./tone-mapping-scenarios.png)
380+
286381
## Annex A: Color space conversions
287382

288383
### Background
@@ -312,7 +407,13 @@ The following illustrates the conversions that are explicitly specified:
312407
These conversions fall into two broad categories:
313408

314409
* conversion between HDR color spaces
315-
* conversion between an HDR and an SDR color space (tone mapping)
410+
* conversion between between images with different luminance dynamic ranges
411+
(tone mapping)
412+
413+
### Rendering to an HDR display with a lower dynamic range
414+
415+
[Rep. ITU-R BT.2408, Annex 5](https://www.itu.int/pub/R-REP-BT.2408) specifies a
416+
method to render an HDR image to an HDR display with a lower dynamic range.
316417

317418
### Between HDR color spaces
318419

@@ -323,26 +424,41 @@ ITU-R BT.2408-5, Clause 6](https://www.itu.int/pub/R-REP-BT.2408)
323424

324425
#### `rec2100-pq` to `srgb`
325426

326-
Tone mapping from `rec2100-pq` to `srgb` is performed using the following steps:
427+
Color volume mapping from `rec2100-pq` to `srgb` is performed using the
428+
following steps:
327429

328430
* apply the EETF specified at [Rep. ITU-R BT.2408, Annex
329431
5](https://www.itu.int/pub/R-REP-BT.2408) using the following parameter values:
330-
* L<sub>B</sub> = `CanvasColorVolumeMetadata::minimumLuminance` || 0;
331-
* L<sub>W</sub> = `CanvasColorVolumeMetadata::maximumLuminance` || 1000;
432+
* L<sub>B</sub> = `ColorVolumeInfo::minimumLuminance` || 0;
433+
* L<sub>W</sub> = `ColorVolumeInfo::maximumLuminance` || 1000;
332434
* L<sub>min</sub> = 0
333435
* L<sub>max</sub> = 203
334436
* convert to sRGB using `rec2100PQtoSRGB()` below
335437

336438
```javascript
439+
function simpleInverseTransform(value, gamma) {
440+
if (value < 0) {
441+
return -1.0 * Math.pow(-1.0 * value, 1.0 / gamma);
442+
} else {
443+
return Math.pow(value, 1.0 / gamma);
444+
}
445+
}
446+
337447
function rec2100PQtoSRGB(r, g, b) {
338448
let rt = 10000 * pqEOTF(r) / 203;
339449
let gt = 10000 * pqEOTF(g) / 203;
340-
let bt = 10000 * pqEOTF(b) / 203;
341-
[rt, gt, bt] = matrixXYZtoRec709(matrixBT2020toXYZ(rt, gt, bt));
342-
const rp = Math.pow(rt, 1/2.4);
343-
const gp = Math.pow(gt, 1/2.4);
344-
const bp = Math.pow(bt, 1/2.4);
345-
return [rp, gp, bp];
450+
let bt = 10000 * pqEOTF(b) / 203;
451+
452+
[rt, gt, bt] = matrixXYZtoSRGB(matrixBT2020toXYZ(rt, gt, bt));
453+
454+
const srgbGamma = 2.2;
455+
const r2 = simpleInverseTransform(rt, srgbGamma);
456+
const g2 = simpleInverseTransform(gt, srgbGamma);
457+
const b2 = simpleInverseTransform(bt, srgbGamma);
458+
459+
const [r3, g3, b3] = limitToSRGBGamut(r2, g2, b2);
460+
461+
return [r3, g3, b3];
346462
}
347463
```
348464

@@ -400,7 +516,7 @@ function tonemapREC2100HLGtoSRGBdisplay(r, g, b) {
400516
const g3 = simpleInverseTransform(g2, srgbGamma);
401517
const b3 = simpleInverseTransform(b2, srgbGamma);
402518

403-
const [r4, g4, b4] = limitTosRGBGamut(r3, g3, b3);
519+
const [r4, g4, b4] = limitToSRGBGamut(r3, g3, b3);
404520

405521
return [r4, g4, b4];
406522
}

primary-use-case.png

7.16 KB
Loading

tone-mapping-scenarios.png

4.8 KB
Loading

0 commit comments

Comments
 (0)