hdr-canvas 0.0.8 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +79 -5
- package/dist/hdr-canvas.cjs +23 -18
- package/dist/hdr-canvas.cjs.map +1 -1
- package/dist/hdr-canvas.d.ts +22 -0
- package/dist/hdr-canvas.js +23 -18
- 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/package.json +8 -8
- package/src/Uint16Image.ts +17 -34
- package/src/hdr-canvas.ts +2 -0
- package/src/hdr-check.ts +13 -15
- package/src/index.ts +1 -5
- package/src/{@types → types}/HDRCanvas.d.ts +4 -5
- package/three/HDRWebGPUBackend.js +2 -2
- package/three/HDRWebGPURenderer.js +2 -2
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hdr-canvas",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.10",
|
4
4
|
"description": "HDR capable HTML canvas",
|
5
5
|
"main": "dist/hdr-canvas.js",
|
6
6
|
"files": [
|
@@ -40,19 +40,19 @@
|
|
40
40
|
"homepage": "https://github.com/cmahnke/hdr-canvas#readme",
|
41
41
|
"devDependencies": {
|
42
42
|
"@eslint/js": "^9.6.0",
|
43
|
-
"@rollup/plugin-node-resolve": "^15.
|
43
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
44
44
|
"@rollup/plugin-terser": "^0.4.4",
|
45
45
|
"@rollup/plugin-typescript": "^11.1.6",
|
46
46
|
"@types/eslint__js": "^8.42.3",
|
47
|
-
"eslint": "^9.
|
47
|
+
"eslint": "^9.13.0",
|
48
48
|
"prettier": "^3.3.3",
|
49
49
|
"rimraf": "^6.0.1",
|
50
|
-
"rollup": "^4.
|
50
|
+
"rollup": "^4.24.0",
|
51
51
|
"rollup-plugin-dts": "^6.1.1",
|
52
|
-
"three": "^0.
|
53
|
-
"tslib": "^2.
|
54
|
-
"typescript": "^5.
|
55
|
-
"typescript-eslint": "^8.
|
52
|
+
"three": "^0.169.0",
|
53
|
+
"tslib": "^2.8.0",
|
54
|
+
"typescript": "^5.6.3",
|
55
|
+
"typescript-eslint": "^8.10.0"
|
56
56
|
},
|
57
57
|
"dependencies": {
|
58
58
|
"colorjs.io": "^0.5.2"
|
package/src/Uint16Image.ts
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
import Color from "colorjs.io";
|
2
2
|
import type { Coords, ColorTypes } from "colorjs.io";
|
3
3
|
|
4
|
-
type
|
5
|
-
|
6
|
-
|
7
|
-
blue: number,
|
8
|
-
alpha: number,
|
9
|
-
) => Uint16Array;
|
4
|
+
import type { HDRPredefinedColorSpace, HDRImageData } from "./types/HDRCanvas.d.ts";
|
5
|
+
|
6
|
+
type Uint16ImagePixelCallback = (red: number, green: number, blue: number, alpha: number) => Uint16Array;
|
10
7
|
|
11
8
|
/*
|
12
9
|
interface ColorSpaceMapping {
|
@@ -24,7 +21,7 @@ export class Uint16Image {
|
|
24
21
|
"rec2100-hlg": "rec2100hlg",
|
25
22
|
"display-p3": "p3",
|
26
23
|
srgb: "sRGB",
|
27
|
-
"rec2100-pq": "rec2100pq"
|
24
|
+
"rec2100-pq": "rec2100pq"
|
28
25
|
};
|
29
26
|
colorSpace: HDRPredefinedColorSpace;
|
30
27
|
|
@@ -76,25 +73,20 @@ export class Uint16Image {
|
|
76
73
|
if (this.data === undefined || this.data === null) {
|
77
74
|
return null;
|
78
75
|
}
|
79
|
-
return new ImageData(
|
80
|
-
this.
|
81
|
-
|
82
|
-
this.height,
|
83
|
-
{ colorSpace: this.colorSpace as PredefinedColorSpace },
|
84
|
-
);
|
76
|
+
return new ImageData(this.data as unknown as Uint8ClampedArray, this.width, this.height, {
|
77
|
+
colorSpace: this.colorSpace as PredefinedColorSpace
|
78
|
+
});
|
85
79
|
}
|
86
80
|
|
87
81
|
static convertPixelToRec2100_hlg(pixel: Uint8ClampedArray): Uint16Array {
|
88
|
-
const colorJScolorSpace = <string>
|
89
|
-
Uint16Image.COLORSPACES["rec2100-hlg" as HDRPredefinedColorSpace]
|
90
|
-
);
|
82
|
+
const colorJScolorSpace = <string>Uint16Image.COLORSPACES["rec2100-hlg" as HDRPredefinedColorSpace];
|
91
83
|
|
92
84
|
const srgbColor = new Color(
|
93
85
|
"srgb",
|
94
86
|
Array.from(pixel.slice(0, 3)).map((band: number) => {
|
95
87
|
return band / 255;
|
96
88
|
}) as Coords,
|
97
|
-
pixel[3] / 255
|
89
|
+
pixel[3] / 255
|
98
90
|
);
|
99
91
|
const rec2100hlgColor = srgbColor.to(colorJScolorSpace);
|
100
92
|
const hlg: Array<number> = rec2100hlgColor.coords.map((band: number) => {
|
@@ -118,10 +110,7 @@ export class Uint16Image {
|
|
118
110
|
|
119
111
|
pixelCallback(fn: Uint16ImagePixelCallback) {
|
120
112
|
for (let i = 0; i < this.data.length; i += 4) {
|
121
|
-
this.data.set(
|
122
|
-
fn(this.data[i], this.data[i + 1], this.data[i + 2], this.data[i + 3]),
|
123
|
-
i,
|
124
|
-
);
|
113
|
+
this.data.set(fn(this.data[i], this.data[i + 1], this.data[i + 2], this.data[i + 3]), i);
|
125
114
|
}
|
126
115
|
}
|
127
116
|
|
@@ -146,9 +135,7 @@ export class Uint16Image {
|
|
146
135
|
static fromImageData(imageData: HDRImageData): Uint16Image {
|
147
136
|
const i = new Uint16Image(imageData.width, imageData.height);
|
148
137
|
if (imageData.colorSpace == "srgb") {
|
149
|
-
i.data = Uint16Image.convertArrayToRec2100_hlg(
|
150
|
-
<Uint8ClampedArray>imageData.data,
|
151
|
-
);
|
138
|
+
i.data = Uint16Image.convertArrayToRec2100_hlg(<Uint8ClampedArray>imageData.data);
|
152
139
|
} else if (imageData.colorSpace == Uint16Image.DEFAULT_COLORSPACE) {
|
153
140
|
i.data = <Uint16Array>imageData.data;
|
154
141
|
} else {
|
@@ -158,22 +145,18 @@ export class Uint16Image {
|
|
158
145
|
}
|
159
146
|
|
160
147
|
static async fromURL(url: URL): Promise<Uint16Image | undefined> {
|
161
|
-
return Uint16Image.loadSDRImageData(url).then(
|
162
|
-
(data
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
},
|
167
|
-
);
|
148
|
+
return Uint16Image.loadSDRImageData(url).then((data: HDRImageData | undefined) => {
|
149
|
+
if (data !== undefined) {
|
150
|
+
return Uint16Image.fromImageData(data);
|
151
|
+
}
|
152
|
+
});
|
168
153
|
}
|
169
154
|
|
170
155
|
setImageData(imageData: HDRImageData): void {
|
171
156
|
this.width = imageData.width;
|
172
157
|
this.height = imageData.height;
|
173
158
|
if (imageData.colorSpace == "srgb") {
|
174
|
-
this.data = Uint16Image.convertArrayToRec2100_hlg(
|
175
|
-
<Uint8ClampedArray>imageData.data,
|
176
|
-
);
|
159
|
+
this.data = Uint16Image.convertArrayToRec2100_hlg(<Uint8ClampedArray>imageData.data);
|
177
160
|
} else if (imageData.colorSpace == Uint16Image.DEFAULT_COLORSPACE) {
|
178
161
|
this.data = <Uint16Array>imageData.data;
|
179
162
|
} else {
|
package/src/hdr-canvas.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import {Uint16Image} from './Uint16Image'
|
2
2
|
|
3
|
+
import type {HDRHTMLCanvasElement} from './types/HDRCanvas.d.ts'
|
4
|
+
|
3
5
|
const hdr_options = {colorSpace: Uint16Image.DEFAULT_COLORSPACE, pixelFormat: 'float16'}
|
4
6
|
|
5
7
|
export function initHDRCanvas(canvas : HDRHTMLCanvasElement) : RenderingContext | null {
|
package/src/hdr-check.ts
CHANGED
@@ -4,12 +4,8 @@ export function checkHDR(): boolean {
|
|
4
4
|
const hdrSupported: boolean = bitsPerChannel > 8;
|
5
5
|
|
6
6
|
//TODO: Test if this works as expected
|
7
|
-
const dynamicRangeHighMQ: boolean = window.matchMedia(
|
8
|
-
|
9
|
-
).matches;
|
10
|
-
const colorGamutMQ: boolean =
|
11
|
-
window.matchMedia("(color-gamut: rec2020)").matches ||
|
12
|
-
window.matchMedia("(color-gamut: p3)").matches;
|
7
|
+
const dynamicRangeHighMQ: boolean = window.matchMedia("(dynamic-range: high)").matches;
|
8
|
+
const colorGamutMQ: boolean = window.matchMedia("(color-gamut: rec2020)").matches || window.matchMedia("(color-gamut: p3)").matches;
|
13
9
|
if (colorGamutMQ && dynamicRangeHighMQ) {
|
14
10
|
if (bitsPerChannel !== Math.round(bitsPerChannel)) {
|
15
11
|
// iOS bug
|
@@ -37,22 +33,24 @@ export function checkHDRCanvas(): boolean {
|
|
37
33
|
if (!canvas.getContext) {
|
38
34
|
return false;
|
39
35
|
}
|
40
|
-
const ctx: CanvasRenderingContext2D | null = <CanvasRenderingContext2D>(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
})
|
45
|
-
);
|
36
|
+
const ctx: CanvasRenderingContext2D | null = <CanvasRenderingContext2D>canvas.getContext("2d", {
|
37
|
+
colorSpace: colorSpace,
|
38
|
+
pixelFormat: "float16"
|
39
|
+
});
|
46
40
|
//canvas.drawingBufferColorSpace = colorSpace;
|
47
41
|
//canvas.unpackColorSpace = colorSpace;
|
48
42
|
if (ctx === null) {
|
49
43
|
return false;
|
50
44
|
}
|
51
45
|
return true;
|
46
|
+
/* eslint-disable no-console, @typescript-eslint/no-unused-vars */
|
52
47
|
} catch (e) {
|
53
|
-
|
54
|
-
console.error(
|
55
|
-
|
48
|
+
//console.error("Bad canvas ColorSpace test", e);
|
49
|
+
console.error(
|
50
|
+
"Bad canvas ColorSpace test - make sure that the Chromium browser flag 'enable-experimental-web-platform-features' has been enabled"
|
51
|
+
);
|
52
|
+
|
56
53
|
return false;
|
57
54
|
}
|
55
|
+
/* eslint-enable */
|
58
56
|
}
|
package/src/index.ts
CHANGED
@@ -1,7 +1,3 @@
|
|
1
1
|
export { Uint16Image } from "./Uint16Image";
|
2
2
|
export { checkHDR, checkHDRCanvas } from "./hdr-check";
|
3
|
-
export {
|
4
|
-
initHDRCanvas,
|
5
|
-
defaultGetContextHDR,
|
6
|
-
resetGetContext,
|
7
|
-
} from "./hdr-canvas";
|
3
|
+
export { initHDRCanvas, defaultGetContextHDR, resetGetContext } from "./hdr-canvas";
|
@@ -1,4 +1,5 @@
|
|
1
1
|
// See https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.generated.d.ts
|
2
|
+
/// <reference lib="dom" />
|
2
3
|
|
3
4
|
type HDRHTMLCanvasOptionsType = "mode";
|
4
5
|
type HDRHTMLCanvasOptions = { [key in HDRHTMLCanvasOptionsType]?: string };
|
@@ -17,10 +18,8 @@ interface HDRImageData {
|
|
17
18
|
|
18
19
|
// See https://github.com/w3c/ColorWeb-CG/blob/main/hdr_html_canvas_element.md
|
19
20
|
// "rec2100-display-linear" is left out beacause of mapping issues
|
20
|
-
type HDRPredefinedColorSpace =
|
21
|
-
| "display-p3"
|
22
|
-
| "srgb"
|
23
|
-
| "rec2100-hlg"
|
24
|
-
| "rec2100-pq";
|
21
|
+
type HDRPredefinedColorSpace = "display-p3" | "srgb" | "rec2100-hlg" | "rec2100-pq";
|
25
22
|
|
26
23
|
//enum HDRPredefinedColorSpace {"display-p3", "srgb", "rec2100-hlg", "rec2100-pq", "rec2100-display-linear"};
|
24
|
+
|
25
|
+
export { HDRHTMLCanvasElement, HDRPredefinedColorSpace, HDRImageData };
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import WebGPUBackend from 'three/renderers/webgpu/WebGPUBackend.js';
|
2
|
-
import { GPUFeatureName, GPUTextureFormat } from 'three/renderers/webgpu/utils/WebGPUConstants.js';
|
1
|
+
import WebGPUBackend from 'three/src/renderers/webgpu/WebGPUBackend.js';
|
2
|
+
import { GPUFeatureName, GPUTextureFormat } from 'three/src/renderers/webgpu/utils/WebGPUConstants.js';
|
3
3
|
|
4
4
|
class HDRWebGPUBackend extends WebGPUBackend {
|
5
5
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import WebGPU from './WebGPU.js';
|
2
2
|
|
3
|
-
import Renderer from 'three/renderers/common/Renderer.js';
|
4
|
-
import WebGLBackend from 'three/renderers/webgl/WebGLBackend.js';
|
3
|
+
import Renderer from 'three/src/renderers/common/Renderer.js';
|
4
|
+
import WebGLBackend from 'three/src/renderers/webgl-fallback/WebGLBackend.js';
|
5
5
|
import HDRWebGPUBackend from './HDRWebGPUBackend.js';
|
6
6
|
|
7
7
|
class HDRWebGPURenderer extends Renderer {
|