hdr-canvas 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -10
- package/dist/@types/hdr-canvas.d.ts +4 -20
- package/dist/hdr-canvas.js +346 -5921
- package/dist/hdr-canvas.js.map +1 -1
- package/dist/hdr-canvas.min.js +1 -1
- package/dist/hdr-canvas.min.js.map +1 -1
- package/dist/index.d.ts +4 -20
- package/docs/release-notes-0.1.2.md +16 -0
- package/docs/release-notes-0.2.0.md +26 -0
- package/package.json +26 -29
- package/rollup.config.mjs +6 -10
- package/scripts/check-import.sh +11 -0
- package/scripts/check.sh +1 -0
- package/src/Float16Image.ts +34 -39
- package/src/HDRImage.ts +0 -10
- package/src/hdr-canvas.ts +7 -13
- package/src/hdr-check.ts +35 -18
- package/src/index.ts +1 -2
- package/src/types/HDRCanvas.d.ts +5 -0
- package/three/HDRWebGPUBackend.js +12 -2
- package/three/HDRWebGPURenderer.js +1 -0
- package/tsconfig.json +4 -3
- package/dist/hdr-canvas.umd.js +0 -6130
- package/dist/hdr-canvas.umd.js.map +0 -1
- package/src/Uint16Image.ts +0 -191
- package/src/browser-util.ts +0 -9
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ All changes and a bit of context are part of the [release notes for 0.1.0](docs/
|
|
|
15
15
|
Import the required function(s):
|
|
16
16
|
|
|
17
17
|
```javascript
|
|
18
|
-
import { checkHDR, checkHDRCanvas } from "hdr-canvas";
|
|
18
|
+
import { checkHDR, checkHDRCanvas, checkHDRVideo, checkFloat16Array, checkHDRBitDepth } from "hdr-canvas";
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Example `checkHDRCanvas()`
|
|
@@ -37,7 +37,7 @@ This can be useful to add a warning (using the [`fillText()`](https://developer.
|
|
|
37
37
|
## Example `checkHDRCanvas()`
|
|
38
38
|
|
|
39
39
|
```javascript
|
|
40
|
-
const hdrCanvasStatus = document.getElementById("hdr-check
|
|
40
|
+
const hdrCanvasStatus = document.getElementById("hdr-canvas-check")! as HTMLDivElement;
|
|
41
41
|
if (checkHDRCanvas()) {
|
|
42
42
|
hdrCanvasStatus.innerText = "HDR Canvas are supported";
|
|
43
43
|
hdrCanvasStatus.style.color = "green";
|
|
@@ -50,7 +50,7 @@ if (checkHDRCanvas()) {
|
|
|
50
50
|
## Example `checkHDRVideo()`
|
|
51
51
|
|
|
52
52
|
```javascript
|
|
53
|
-
const hdrCanvasStatus = document.getElementById("hdr-check
|
|
53
|
+
const hdrCanvasStatus = document.getElementById("hdr-video-check")! as HTMLDivElement;
|
|
54
54
|
if (checkHDRVideo()) {
|
|
55
55
|
hdrCanvasStatus.innerText = "HDR Video is supported";
|
|
56
56
|
hdrCanvasStatus.style.color = "green";
|
|
@@ -60,6 +60,29 @@ if (checkHDRVideo()) {
|
|
|
60
60
|
}
|
|
61
61
|
```
|
|
62
62
|
|
|
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
|
+
|
|
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
|
+
|
|
63
86
|
# Canvas
|
|
64
87
|
|
|
65
88
|
**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.**
|
|
@@ -161,6 +184,10 @@ Use it as you'll do with a `WebGPURenderer`.
|
|
|
161
184
|
renderer = new HDRWebGPURenderer({ canvas: canvas, antialias: true });
|
|
162
185
|
```
|
|
163
186
|
|
|
187
|
+
## Three.js WebGPU
|
|
188
|
+
|
|
189
|
+
Starting with R180 the WebGPU supports the `toneMapping` which is the succesor of `colorMetadata`. But currently this is still limited in colorspaces.
|
|
190
|
+
|
|
164
191
|
## Updating textures
|
|
165
192
|
|
|
166
193
|
Starting from Three.js version 167 you need to fix imported UHDR Textures, otherwise they will appear black:
|
|
@@ -223,17 +250,12 @@ All examples requires a Chromium based browser (like Chrome, Edge, Opera and Bra
|
|
|
223
250
|
|
|
224
251
|
The following things might be improved:
|
|
225
252
|
|
|
226
|
-
- [x]
|
|
227
|
-
- [ ] Try to detect change of screen for HDR detection - [#107](https://github.com/cmahnke/hdr-canvas/issues/107)
|
|
228
|
-
- [ ] Remove `Uint16Image`
|
|
253
|
+
- [x] Try to detect change of screen for HDR detection - [#107](https://github.com/cmahnke/hdr-canvas/issues/107) - implemented but not documented
|
|
229
254
|
- [ ] Improve speed
|
|
230
255
|
- [ ] Provide WebWorker
|
|
231
256
|
- [ ] Documentation
|
|
232
257
|
- [ ] Link to browser HDR support
|
|
233
|
-
- [
|
|
234
|
-
- [ ] Tests and examples
|
|
235
|
-
- [x] Provide examples from blog
|
|
236
|
-
- [x] Provide simple sanity tests
|
|
258
|
+
- [ ] Give a overview on current status
|
|
237
259
|
|
|
238
260
|
# References
|
|
239
261
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ColorTypes } from 'colorjs.io';
|
|
2
|
-
|
|
3
1
|
// See https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.generated.d.ts
|
|
4
2
|
/// <reference lib="dom" />
|
|
5
3
|
|
|
@@ -44,7 +42,6 @@ interface CanvasRenderingContext2DHDR extends CanvasRenderingContext2D {}
|
|
|
44
42
|
declare abstract class HDRImage {
|
|
45
43
|
static DEFAULT_COLORSPACE: HDRPredefinedColorSpace;
|
|
46
44
|
static SDR_MULTIPLIER: number;
|
|
47
|
-
static COLORSPACES: Record<HDRPredefinedColorSpace, ColorTypes>;
|
|
48
45
|
data: HDRImageDataArray;
|
|
49
46
|
height: number;
|
|
50
47
|
width: number;
|
|
@@ -61,21 +58,6 @@ declare abstract class HDRImage {
|
|
|
61
58
|
clone(): this;
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
declare class Uint16Image extends HDRImage {
|
|
65
|
-
data: Uint16Array;
|
|
66
|
-
colorSpace: HDRPredefinedColorSpace;
|
|
67
|
-
constructor(width: number, height: number, colorspace?: string);
|
|
68
|
-
fill(color: number[]): this | undefined;
|
|
69
|
-
static scaleUint8ToUint16(val: number): number;
|
|
70
|
-
getImageData(): ImageData | null;
|
|
71
|
-
static convertPixelToRec2100_hlg(pixel: Uint8ClampedArray): Uint16Array;
|
|
72
|
-
static convertArrayToRec2100_hlg(data: Uint8ClampedArray): Uint16Array;
|
|
73
|
-
pixelCallback(fn: HDRImagePixelCallback): void;
|
|
74
|
-
static fromImageData(imageData: HDRImageData): Uint16Image;
|
|
75
|
-
static fromURL(url: URL): Promise<Uint16Image | undefined>;
|
|
76
|
-
setImageData(imageData: HDRImageData): void;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
61
|
declare class Float16Image extends HDRImage {
|
|
80
62
|
data: Float16Array;
|
|
81
63
|
static DEFAULT_PIXELFORMAT: ImageDataPixelFormat;
|
|
@@ -85,7 +67,6 @@ declare class Float16Image extends HDRImage {
|
|
|
85
67
|
fill(color: number[]): this | undefined;
|
|
86
68
|
static scaleUint8ToFloat16(val: number): number;
|
|
87
69
|
getImageData(): ImageData | null;
|
|
88
|
-
static convertPixelToRec2100_hlg(pixel: Uint8ClampedArray): Float16Array;
|
|
89
70
|
static convertArrayToRec2100_hlg(data: Uint8ClampedArray): Float16Array;
|
|
90
71
|
pixelCallback(fn: HDRImagePixelCallback): void;
|
|
91
72
|
static fromImageData(imageData: HDRImageData): Float16Image;
|
|
@@ -95,11 +76,14 @@ declare class Float16Image extends HDRImage {
|
|
|
95
76
|
clone(): this;
|
|
96
77
|
}
|
|
97
78
|
|
|
79
|
+
declare function checkHDRVideo(): boolean;
|
|
98
80
|
declare function checkHDR(): boolean;
|
|
99
81
|
declare function checkHDRCanvas(): boolean;
|
|
82
|
+
declare function checkFloat16Array(): boolean;
|
|
83
|
+
declare function checkHDRBitDepth(): boolean;
|
|
100
84
|
|
|
101
85
|
declare function initHDRCanvas(canvas: HDRHTMLCanvasElement): CanvasRenderingContext2DHDR | null;
|
|
102
86
|
declare function defaultGetContextHDR(): void;
|
|
103
87
|
declare function resetGetContext(): void;
|
|
104
88
|
|
|
105
|
-
export { Float16Image, HDRImage,
|
|
89
|
+
export { Float16Image, HDRImage, checkFloat16Array, checkHDR, checkHDRBitDepth, checkHDRCanvas, checkHDRVideo, defaultGetContextHDR, initHDRCanvas, resetGetContext };
|