Skip to content

Commit e6f7876

Browse files
committed
Added check function
1 parent c7ea487 commit e6f7876

File tree

6 files changed

+46
-42
lines changed

6 files changed

+46
-42
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ All changes and a bit of context are part of the [release notes for 0.1.0](docs/
1515
Import the required function(s):
1616

1717
```javascript
18-
import { checkHDR, checkHDRCanvas, checkHDRVideo(), checkFloat16Array } from "hdr-canvas";
18+
import { checkHDR, checkHDRCanvas, checkHDRVideo, checkFloat16Array, checkHDRBitDepth } from "hdr-canvas";
1919
```
2020

2121
## Example `checkHDRCanvas()`
@@ -73,6 +73,16 @@ if (checkHDRVideo()) {
7373
}
7474
```
7575

76+
## Example `checkHDRBitDepth()`
77+
78+
This can be used to check if the current screen supports HDR.
79+
80+
```javascript
81+
setInterval(() => {
82+
console.log(checkHDRBitDepth());
83+
}, 500);
84+
```
85+
7686
# Canvas
7787

7888
**Note: Currently the Chrome flag `enable-experimental-web-platform-features` needs to be enabled to have HDR support for the `canvas` element. You need to tell your visitors about that.**
@@ -174,6 +184,10 @@ Use it as you'll do with a `WebGPURenderer`.
174184
renderer = new HDRWebGPURenderer({ canvas: canvas, antialias: true });
175185
```
176186

187+
## Three.js WebGPU
188+
189+
Starting with R180 the WebGPU supports the `toneMapping` which is the succesor of `colorMetadata`.
190+
177191
## Updating textures
178192

179193
Starting from Three.js version 167 you need to fix imported UHDR Textures, otherwise they will appear black:

src/Float16Image.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HDRImage } from "./HDRImage";
22

33
import Color from "colorjs.io";
4-
import type { Coords } from "colorjs.io";
4+
import type { Coords, ColorTypes } from "colorjs.io";
55
import { f16round } from "@petamoriken/float16";
66

77
import type { HDRPredefinedColorSpace, HDRImageData, HDRImagePixelCallback } from "./types/HDRCanvas.d.ts";
@@ -17,6 +17,14 @@ export class Float16Image extends HDRImage {
1717
/** The default pixel format for new images, set to "rgba-float16". */
1818
static DEFAULT_PIXELFORMAT: ImageDataPixelFormat = "rgba-float16";
1919

20+
/** A mapping of predefined HDR color space names to their corresponding `colorjs.io` string representations. */
21+
static COLORSPACES: Record<HDRPredefinedColorSpace, ColorTypes> = {
22+
"rec2100-hlg": "rec2100hlg",
23+
"display-p3": "p3",
24+
srgb: "sRGB",
25+
"rec2100-pq": "rec2100pq"
26+
};
27+
2028
/** The color space of the image. */
2129
colorSpace: HDRPredefinedColorSpace;
2230
/** The pixel format of the image - usualy 'rgba-float16'. */

src/HDRImage.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
//import type { ImageData } from "./types/ImageData.d.ts";
22
import type { HDRPredefinedColorSpace, HDRImageData, HDRImageDataArray, HDRImagePixelCallback } from "./types/HDRCanvas.d.ts";
33

4-
import type { ColorTypes } from "colorjs.io";
5-
64
export abstract class HDRImage {
75
/** The default color space for new images, set to "rec2100-hlg". */
86
static DEFAULT_COLORSPACE: HDRPredefinedColorSpace = "rec2100-hlg";
97

108
/** A multiplier used for scaling 8-bit SDR values to 16-bit. */
119
static SDR_MULTIPLIER = 2 ** 16 - 1; //(2**16 - 1)
1210

13-
/** A mapping of predefined HDR color space names to their corresponding `colorjs.io` string representations. */
14-
static COLORSPACES: Record<HDRPredefinedColorSpace, ColorTypes> = {
15-
"rec2100-hlg": "rec2100hlg",
16-
"display-p3": "p3",
17-
srgb: "sRGB",
18-
"rec2100-pq": "rec2100pq"
19-
};
20-
2111
/** The raw pixel data stored as a `Float16Array`. */
2212
data: HDRImageDataArray;
2313
/** The height of the image in pixels. */

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { Float16Image } from "./Float16Image";
22
export { HDRImage } from "./HDRImage";
3-
export { checkHDR, checkHDRVideo, checkHDRCanvas, checkFloat16Array } from "./hdr-check";
3+
export { checkHDR, checkHDRVideo, checkHDRCanvas, checkFloat16Array, checkHDRBitDepth } from "./hdr-check";
44
export { initHDRCanvas, defaultGetContextHDR, resetGetContext } from "./hdr-canvas";

tests/site/assets/ts/main.ts

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,29 @@ import { checkHDR, checkHDRVideo, checkHDRCanvas, checkFloat16Array, checkHDRBit
22
import { initModel } from "./hdr-three.js";
33
import { initCanvas } from "./image-slider.js";
44

5+
function setStatus(element: HTMLDivElement, status: boolean) {
6+
if (status) {
7+
element.classList.add("success");
8+
element.classList.remove("fail");
9+
} else {
10+
element.classList.add("fail");
11+
element.classList.remove("success");
12+
}
13+
}
14+
515
document.addEventListener("DOMContentLoaded", function () {
616
const hdrCheck = document.getElementById("hdr-check")! as HTMLDivElement;
717
const hdrVideoCheck = document.getElementById("hdr-video-check")! as HTMLDivElement;
818
const hdrCanvasCheck = document.getElementById("hdr-canvas-check")! as HTMLDivElement;
919
const float16arrayCheck = document.getElementById("float16array-check")! as HTMLDivElement;
1020
const screenCheck = document.getElementById("screen-check")! as HTMLDivElement;
1121

12-
if (checkHDR()) {
13-
hdrCheck.classList.add("success");
14-
} else {
15-
hdrCheck.classList.add("fail");
16-
}
17-
18-
if (checkHDRVideo()) {
19-
hdrVideoCheck.classList.add("success");
20-
} else {
21-
hdrVideoCheck.classList.add("fail");
22-
}
23-
24-
if (checkHDRCanvas()) {
25-
hdrCanvasCheck.classList.add("success");
26-
} else {
27-
hdrCanvasCheck.classList.add("fail");
28-
}
29-
30-
if (checkFloat16Array()) {
31-
float16arrayCheck.classList.add("success");
32-
} else {
33-
float16arrayCheck.classList.add("fail");
34-
}
35-
3622
setInterval(() => {
37-
if (checkHDRBitDepth()) {
38-
screenCheck.classList.add("success");
39-
} else {
40-
screenCheck.classList.add("fail");
41-
}
23+
setStatus(hdrCheck, checkHDR());
24+
setStatus(hdrVideoCheck, checkHDRVideo());
25+
setStatus(hdrCanvasCheck, checkHDRCanvas());
26+
setStatus(float16arrayCheck, checkFloat16Array());
27+
setStatus(screenCheck, checkHDRBitDepth());
4228
}, 500);
4329

4430
try {

tests/site/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ <h2>Feature detection</h2>
2323
<li><div class="hdr-check-result" id="float16array-check">Check for Float16Array Image constructor Support</div></li>
2424
<li><div class="hdr-check-result" id="screen-check">Check for screen hardware HDR Support</div></li>
2525
</ul>
26+
<div>
27+
Note that this might be a bit off:
28+
<ul>
29+
<li>On Chrome on Mac this might report HDR support if Display P§ is enabled, even when HDR itself is disabled.</li>
30+
</ul>
31+
</div>
2632
</div>
2733
<div class="model">
2834
<h2>Three.js HDR</h2>

0 commit comments

Comments
 (0)