Skip to content

Commit c7ea487

Browse files
committed
More updates
1 parent 70a7fea commit c7ea487

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

README.md

Lines changed: 18 additions & 10 deletions
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 } from "hdr-canvas";
18+
import { checkHDR, checkHDRCanvas, checkHDRVideo(), checkFloat16Array } from "hdr-canvas";
1919
```
2020

2121
## Example `checkHDRCanvas()`
@@ -37,7 +37,7 @@ This can be useful to add a warning (using the [`fillText()`](https://developer.
3737
## Example `checkHDRCanvas()`
3838

3939
```javascript
40-
const hdrCanvasStatus = document.getElementById("hdr-check-status")! as HTMLDivElement;
40+
const hdrCanvasStatus = document.getElementById("hdr-canvas-check")! as HTMLDivElement;
4141
if (checkHDRCanvas()) {
4242
hdrCanvasStatus.innerText = "HDR Canvas are supported";
4343
hdrCanvasStatus.style.color = "green";
@@ -50,7 +50,7 @@ if (checkHDRCanvas()) {
5050
## Example `checkHDRVideo()`
5151

5252
```javascript
53-
const hdrCanvasStatus = document.getElementById("hdr-check-status")! as HTMLDivElement;
53+
const hdrCanvasStatus = document.getElementById("hdr-video-check")! as HTMLDivElement;
5454
if (checkHDRVideo()) {
5555
hdrCanvasStatus.innerText = "HDR Video is supported";
5656
hdrCanvasStatus.style.color = "green";
@@ -60,6 +60,19 @@ if (checkHDRVideo()) {
6060
}
6161
```
6262

63+
## Example `checkFloat16Array()`
64+
65+
```javascript
66+
const float16ArrayStatus = document.getElementById("float16array-check")! as HTMLDivElement;
67+
if (checkHDRVideo()) {
68+
hdrCanvasStatus.innerText = "Float16Array in Image constructor is supported";
69+
hdrCanvasStatus.style.color = "green";
70+
} else {
71+
hdrCanvasStatus.innerText = "Float16Array in Image constructor is not supported";
72+
hdrCanvasStatus.style.color = "red";
73+
}
74+
```
75+
6376
# Canvas
6477

6578
**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.**
@@ -223,17 +236,12 @@ All examples requires a Chromium based browser (like Chrome, Edge, Opera and Bra
223236
224237
The following things might be improved:
225238
226-
- [x] Change `pixelFormat` in `HTMLCanvasElement.getContext("2d")` to `colorType` (["unorm8", "float16"]) while keeping some downward compatibility - [#151](https://github.com/cmahnke/hdr-canvas/issues/151)
227-
- [ ] Try to detect change of screen for HDR detection - [#107](https://github.com/cmahnke/hdr-canvas/issues/107)
228-
- [ ] Remove `Uint16Image`
239+
- [x] Try to detect change of screen for HDR detection - [#107](https://github.com/cmahnke/hdr-canvas/issues/107) - implemented but not documented
229240
- [ ] Improve speed
230241
- [ ] Provide WebWorker
231242
- [ ] Documentation
232243
- [ ] Link to browser HDR support
233-
- [x] Document `Uint16Image`
234-
- [ ] Tests and examples
235-
- [x] Provide examples from blog
236-
- [x] Provide simple sanity tests
244+
- [ ] Give a overview on current status
237245
238246
# References
239247

src/hdr-check.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function checkHDRCanvas(): boolean {
6868
return false;
6969
}
7070

71-
/** Check if Float16Array is supported, to e used in {ImageData}
71+
/** Check if Float16Array is supported, to be used in {ImageData}
7272
* @returns {boolean}
7373
*/
7474
export function checkFloat16Array(): boolean {
@@ -80,3 +80,12 @@ export function checkFloat16Array(): boolean {
8080
}
8181
return true;
8282
}
83+
84+
/** Check if the supported bit depth is larger then 8
85+
* @returns {boolean}
86+
*/
87+
export function checkHDRBitDepth(): boolean {
88+
const bitsPerChannel: number = screen.colorDepth / 3;
89+
const hdrSupported: boolean = bitsPerChannel > 8;
90+
return hdrSupported;
91+
}

tests/site/assets/ts/main.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { checkHDR, checkHDRVideo, checkHDRCanvas } from "~/hdr-canvas/hdr-check";
1+
import { checkHDR, checkHDRVideo, checkHDRCanvas, checkFloat16Array, checkHDRBitDepth } from "~/hdr-canvas/hdr-check";
22
import { initModel } from "./hdr-three.js";
33
import { initCanvas } from "./image-slider.js";
44

55
document.addEventListener("DOMContentLoaded", function () {
66
const hdrCheck = document.getElementById("hdr-check")! as HTMLDivElement;
77
const hdrVideoCheck = document.getElementById("hdr-video-check")! as HTMLDivElement;
88
const hdrCanvasCheck = document.getElementById("hdr-canvas-check")! as HTMLDivElement;
9+
const float16arrayCheck = document.getElementById("float16array-check")! as HTMLDivElement;
10+
const screenCheck = document.getElementById("screen-check")! as HTMLDivElement;
911

1012
if (checkHDR()) {
1113
hdrCheck.classList.add("success");
@@ -25,6 +27,20 @@ document.addEventListener("DOMContentLoaded", function () {
2527
hdrCanvasCheck.classList.add("fail");
2628
}
2729

30+
if (checkFloat16Array()) {
31+
float16arrayCheck.classList.add("success");
32+
} else {
33+
float16arrayCheck.classList.add("fail");
34+
}
35+
36+
setInterval(() => {
37+
if (checkHDRBitDepth()) {
38+
screenCheck.classList.add("success");
39+
} else {
40+
screenCheck.classList.add("fail");
41+
}
42+
}, 500);
43+
2844
try {
2945
const modelUrl = "glb/uranium.glb";
3046
const canvas = document.getElementById("canvas-renderer")! as HTMLCanvasElement;

tests/site/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ <h2>Feature detection</h2>
2020
<li><div class="hdr-check-result" id="hdr-check">Check for HDR Support</div></li>
2121
<li><div class="hdr-check-result" id="hdr-video-check">Check for HDR Video Support</div></li>
2222
<li><div class="hdr-check-result" id="hdr-canvas-check">Check for Canvas with HDR Support</div></li>
23+
<li><div class="hdr-check-result" id="float16array-check">Check for Float16Array Image constructor Support</div></li>
24+
<li><div class="hdr-check-result" id="screen-check">Check for screen hardware HDR Support</div></li>
2325
</ul>
2426
</div>
2527
<div class="model">

0 commit comments

Comments
 (0)