hdr-canvas 0.0.1
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/LICENSE +21 -0
- package/README.md +103 -0
- package/dist/hdr-canvas.cjs +5918 -0
- package/dist/hdr-canvas.cjs.map +1 -0
- package/dist/hdr-canvas.d.ts +30 -0
- package/dist/hdr-canvas.js +5913 -0
- package/dist/hdr-canvas.js.map +1 -0
- package/dist/hdr-canvas.min.js +2 -0
- package/dist/hdr-canvas.min.js.map +1 -0
- package/package.json +60 -0
- package/src/@types/HDRCanvas.d.ts +25 -0
- package/src/Uint16Image.ts +156 -0
- package/src/hdr-canvas.ts +7 -0
- package/src/hdr-check.ts +58 -0
- package/src/index.ts +3 -0
- package/three/HDRWebGPUBackend.js +87 -0
- package/three/HDRWebGPURenderer.js +40 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright © 2010-2024 three.js authors
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# `hdr-canvas`
|
2
|
+
|
3
|
+
This Module contains a collection of functions and classes to work with the HDR support for HTML `canvas` elements i chrome based browsers. This should only be considered as proof of concept or alpha code, don't use it in production environments.
|
4
|
+
|
5
|
+
# Feature detection
|
6
|
+
|
7
|
+
Import the required function(s):
|
8
|
+
|
9
|
+
```javascript
|
10
|
+
import { checkHDR, checkHDRCanvas } from "hdr-canvas";
|
11
|
+
```
|
12
|
+
|
13
|
+
## Examples `checkHDRCanvas()`
|
14
|
+
|
15
|
+
The functions return `true` if HDR is supported, example:
|
16
|
+
|
17
|
+
```javascript
|
18
|
+
const canvas = document.getElementById("canvas");
|
19
|
+
if (checkHDRCanvas()) {
|
20
|
+
canvas.configureHighDynamicRange({ mode: "extended" });
|
21
|
+
} else {
|
22
|
+
console.debug("hdr not supported");
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
```
|
26
|
+
|
27
|
+
## Example `checkHDRCanvas()`
|
28
|
+
|
29
|
+
```javascript
|
30
|
+
if (checkHDRCanvas()) {
|
31
|
+
hdrCanvas.innerText = "HDR Canvas are supported";
|
32
|
+
hdrCanvas.style.color = "green";
|
33
|
+
} else {
|
34
|
+
hdrCanvas.innerText = "HDR Canvas are not supported";
|
35
|
+
hdrCanvas.style.color = "red";
|
36
|
+
}
|
37
|
+
```
|
38
|
+
|
39
|
+
# Canvas
|
40
|
+
|
41
|
+
The HDR `canvas` support is activated by initializing a canvas context using the following snippet:
|
42
|
+
|
43
|
+
```javascript
|
44
|
+
const colorSpace = "rec2100-hlg";
|
45
|
+
canvas.configureHighDynamicRange({ mode: "extended" });
|
46
|
+
const ctx = canvas.getContext("2d", {
|
47
|
+
colorSpace: colorSpace,
|
48
|
+
pixelFormat: "float16",
|
49
|
+
});
|
50
|
+
```
|
51
|
+
|
52
|
+
## Canvas setup
|
53
|
+
|
54
|
+
The snippet above is also available as function:
|
55
|
+
|
56
|
+
```javascript
|
57
|
+
import { initHDRCanvas } from "hdr-canvas";
|
58
|
+
```
|
59
|
+
|
60
|
+
## Importing `Uint16Image`
|
61
|
+
|
62
|
+
Afterwards one can use [ImageData](https://developer.mozilla.org/en-US/docs/Web/API/ImageData) with a `float16` array, first the `Uint16Image` needs to be imported:
|
63
|
+
|
64
|
+
```javascript
|
65
|
+
import { Uint16Image } from "hdr-canvas";
|
66
|
+
```
|
67
|
+
|
68
|
+
## Example: Loading an image
|
69
|
+
|
70
|
+
Thisexample assumes `image` to be a [HTMLImageElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement) including an existing image.
|
71
|
+
|
72
|
+
```javascript
|
73
|
+
const offscreen = new OffscreenCanvas(image.width, image.height);
|
74
|
+
const loadCtx = offscreen.getContext("2d");
|
75
|
+
loadCtx.drawImage(image, 0, 0);
|
76
|
+
const imData = loadCtx.getImageData(0, 0, image.width, image.height);
|
77
|
+
console.log(imData);
|
78
|
+
|
79
|
+
var hdrCanvas = document.createElement("canvas");
|
80
|
+
hdrCanvas.width = image.width;
|
81
|
+
hdrCanvas.height = image.height;
|
82
|
+
|
83
|
+
const rec210hglImage = Uint16Image.fromImageData(imData);
|
84
|
+
|
85
|
+
const ctx = initHDRCanvas(hdrCanvas);
|
86
|
+
ctx.putImageData(rec210hglImage.getImageData(), 0, 0);
|
87
|
+
```
|
88
|
+
|
89
|
+
# Three.js WebGPU
|
90
|
+
|
91
|
+
**Note**: Make sure to have Three.js added as a dependency.
|
92
|
+
|
93
|
+
This is just a drop in replacement for the regular `WebGPURenderer` of Three.js.
|
94
|
+
|
95
|
+
```javascript
|
96
|
+
import HDRWebGPURenderer from "hdr-canvas/three/HDRWebGPURenderer.js";
|
97
|
+
```
|
98
|
+
|
99
|
+
Use it as you'll do with a `WebGPURenderer`.
|
100
|
+
|
101
|
+
```javascript
|
102
|
+
renderer = new HDRWebGPURenderer({ canvas: canvas, antialias: true });
|
103
|
+
```
|