hdr-canvas 0.1.2 → 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 +93 -5949
- 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.2.0.md +26 -0
- package/package.json +26 -30
- package/rollup.config.mjs +6 -10
- package/scripts/check-import.sh +11 -0
- package/src/Float16Image.ts +16 -34
- package/src/HDRImage.ts +0 -10
- package/src/hdr-canvas.ts +8 -17
- package/src/hdr-check.ts +35 -18
- package/src/index.ts +1 -2
- package/three/HDRWebGPUBackend.js +11 -2
- package/tsconfig.json +4 -3
- package/dist/hdr-canvas.umd.js +0 -6411
- package/dist/hdr-canvas.umd.js.map +0 -1
- package/src/Uint16Image.ts +0 -192
- package/src/browser-util.ts +0 -9
package/dist/index.d.ts
CHANGED
|
@@ -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 };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# `hdr-canvas` 0.2.0
|
|
2
|
+
|
|
3
|
+
# Introduction
|
|
4
|
+
|
|
5
|
+
The following things have been removed:
|
|
6
|
+
|
|
7
|
+
- the support for Chrom(e|ium) < 140
|
|
8
|
+
- `Uint16Image`
|
|
9
|
+
- Utils for browser version check.
|
|
10
|
+
- bundled UMD and IIFE builds.
|
|
11
|
+
- `colorjs.io` isn't a direct dependency anymore
|
|
12
|
+
|
|
13
|
+
Support for Safari started (current target is Safari Technology Preview R232 and later): This requires the feature flag "Canvas Color Types and ImageData Pixel Formats". But this currently doesn't support the `rec2100-hlg` color space.
|
|
14
|
+
|
|
15
|
+
# Key Changes & New Features
|
|
16
|
+
|
|
17
|
+
- Check function for Float16Array
|
|
18
|
+
- `Float16Array` support is no handled by [`@petamoriken/float16`](https://www.npmjs.com/package/@petamoriken/float16)
|
|
19
|
+
|
|
20
|
+
# Removal of [`colorjs.io`](https://colorjs.io/)
|
|
21
|
+
|
|
22
|
+
Even though `colorjs.io` is quite helpful for color space conversions, it's increases the size of a package considerably. And since there are other packages to handle the `Float16`, the package has been removed. If you need your own conversions, add it to your project:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
npm install colorjs.io
|
|
26
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hdr-canvas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "HDR capable HTML canvas",
|
|
5
5
|
"main": "dist/hdr-canvas.cjs",
|
|
6
6
|
"module": "dist/hdr-canvas.js",
|
|
@@ -19,8 +19,6 @@
|
|
|
19
19
|
"dist/hdr-canvas.js.map",
|
|
20
20
|
"dist/hdr-canvas.min.js",
|
|
21
21
|
"dist/hdr-canvas.min.js.map",
|
|
22
|
-
"dist/hdr-canvas.umd.js",
|
|
23
|
-
"dist/hdr-canvas.umd.js.map",
|
|
24
22
|
"dist/index.d.ts",
|
|
25
23
|
"dist/@types",
|
|
26
24
|
"three",
|
|
@@ -70,44 +68,42 @@
|
|
|
70
68
|
},
|
|
71
69
|
"homepage": "https://github.com/cmahnke/hdr-canvas#readme",
|
|
72
70
|
"devDependencies": {
|
|
73
|
-
"@eslint/js": "^
|
|
74
|
-
"@eslint/markdown": "^
|
|
71
|
+
"@eslint/js": "^10.0.1",
|
|
72
|
+
"@eslint/markdown": "^8.0.1",
|
|
75
73
|
"@fontsource-utils/scss": "^0.2.2",
|
|
76
74
|
"@fontsource-variable/league-spartan": "^5.2.8",
|
|
77
|
-
"@napi-rs/canvas": "^0.1.
|
|
75
|
+
"@napi-rs/canvas": "^0.1.97",
|
|
78
76
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
79
|
-
"@rollup/plugin-terser": "^0.
|
|
77
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
80
78
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
81
|
-
"@types/jsdom": "^
|
|
79
|
+
"@types/jsdom": "^28.0.1",
|
|
82
80
|
"@types/semver": "^7.7.1",
|
|
83
|
-
"@types/three": "^0.
|
|
84
|
-
"@typescript-eslint/parser": "^8.
|
|
85
|
-
"@typescript/lib-dom": "npm:@types/web@^0.0.294",
|
|
81
|
+
"@types/three": "^0.183.1",
|
|
82
|
+
"@typescript-eslint/parser": "^8.58.0",
|
|
86
83
|
"better-docs": "^2.7.3",
|
|
87
|
-
"eslint": "^
|
|
84
|
+
"eslint": "^10.2.0",
|
|
88
85
|
"file-url": "^4.0.0",
|
|
89
|
-
"globals": "^
|
|
86
|
+
"globals": "^17.4.0",
|
|
90
87
|
"jsdoc": "^4.0.5",
|
|
91
|
-
"jsdom": "^
|
|
92
|
-
"knip": "^
|
|
88
|
+
"jsdom": "^29.0.1",
|
|
89
|
+
"knip": "^6.3.0",
|
|
93
90
|
"pkg-types": "^2.3.0",
|
|
94
|
-
"prettier": "^3.
|
|
95
|
-
"rimraf": "^6.1.
|
|
96
|
-
"rollup": "^4.
|
|
97
|
-
"rollup-plugin-dts": "^6.
|
|
98
|
-
"sass": "^1.
|
|
99
|
-
"semver": "^7.7.
|
|
100
|
-
"stylelint": "^
|
|
101
|
-
"stylelint-config-standard-scss": "^
|
|
102
|
-
"three": "^0.
|
|
91
|
+
"prettier": "^3.8.1",
|
|
92
|
+
"rimraf": "^6.1.3",
|
|
93
|
+
"rollup": "^4.60.1",
|
|
94
|
+
"rollup-plugin-dts": "^6.4.1",
|
|
95
|
+
"sass": "^1.99.0",
|
|
96
|
+
"semver": "^7.7.4",
|
|
97
|
+
"stylelint": "^17.6.0",
|
|
98
|
+
"stylelint-config-standard-scss": "^17.0.0",
|
|
99
|
+
"three": "^0.183.2",
|
|
103
100
|
"tslib": "^2.8.1",
|
|
104
|
-
"typescript": "^
|
|
105
|
-
"typescript-eslint": "^8.
|
|
106
|
-
"vite": "^
|
|
107
|
-
"vitest": "^4.
|
|
101
|
+
"typescript": "^6.0.2",
|
|
102
|
+
"typescript-eslint": "^8.58.0",
|
|
103
|
+
"vite": "^8.0.3",
|
|
104
|
+
"vitest": "^4.1.2"
|
|
108
105
|
},
|
|
109
106
|
"dependencies": {
|
|
110
|
-
"@petamoriken/float16": "^3.9.3"
|
|
111
|
-
"colorjs.io": "^0.5.2"
|
|
107
|
+
"@petamoriken/float16": "^3.9.3"
|
|
112
108
|
}
|
|
113
109
|
}
|
package/rollup.config.mjs
CHANGED
|
@@ -6,6 +6,9 @@ import terser from "@rollup/plugin-terser";
|
|
|
6
6
|
// External configs
|
|
7
7
|
import typescriptOptions from "./tsconfig.json" with { type: "json" };
|
|
8
8
|
|
|
9
|
+
//const tsOptions = Object.assign(typescriptOptions, { rootDir: "src" });
|
|
10
|
+
const tsOptions = typescriptOptions;
|
|
11
|
+
|
|
9
12
|
const config = [
|
|
10
13
|
{
|
|
11
14
|
input: "src/index.ts",
|
|
@@ -14,27 +17,20 @@ const config = [
|
|
|
14
17
|
file: "dist/hdr-canvas.js",
|
|
15
18
|
format: "es",
|
|
16
19
|
sourcemap: true
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
file: "dist/hdr-canvas.umd.js",
|
|
20
|
-
format: "umd",
|
|
21
|
-
name: "HDRCanvas",
|
|
22
|
-
sourcemap: true
|
|
23
20
|
}
|
|
24
21
|
],
|
|
25
22
|
external: ["three" /*, "colorjs.io" */],
|
|
26
|
-
plugins: [typescript(
|
|
23
|
+
plugins: [typescript(tsOptions), nodeResolve()]
|
|
27
24
|
},
|
|
28
25
|
{
|
|
29
26
|
input: "src/index.ts",
|
|
30
27
|
output: {
|
|
31
28
|
file: "dist/hdr-canvas.min.js",
|
|
32
|
-
format: "
|
|
33
|
-
name: "HDRCanvas",
|
|
29
|
+
format: "es",
|
|
34
30
|
sourcemap: true
|
|
35
31
|
},
|
|
36
32
|
external: ["three"],
|
|
37
|
-
plugins: [typescript(
|
|
33
|
+
plugins: [typescript(tsOptions), nodeResolve(), terser()]
|
|
38
34
|
},
|
|
39
35
|
{
|
|
40
36
|
input: "src/index.ts",
|
package/src/Float16Image.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { HDRImage } from "./HDRImage";
|
|
2
2
|
|
|
3
|
-
import Color from "colorjs.io";
|
|
4
|
-
import type { Coords } from "colorjs.io";
|
|
5
3
|
import { f16round } from "@petamoriken/float16";
|
|
6
4
|
|
|
7
5
|
import type { HDRPredefinedColorSpace, HDRImageData, HDRImagePixelCallback } from "./types/HDRCanvas.d.ts";
|
|
@@ -86,38 +84,22 @@ export class Float16Image extends HDRImage {
|
|
|
86
84
|
return null;
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Converts a single 8-bit pixel (from sRGB color space) to a 16-bit pixel
|
|
97
|
-
* in the `rec2100-hlg` color space.
|
|
98
|
-
*
|
|
99
|
-
* @param {Uint8ClampedArray} pixel - An array of four 8-bit numbers (R, G, B, A).
|
|
100
|
-
* @returns {Float16Array} The converted 16-bit pixel in the `rec2100-hlg` color space.
|
|
101
|
-
* @deprecated
|
|
102
|
-
*/
|
|
103
|
-
static convertPixelToRec2100_hlg(pixel: Uint8ClampedArray): Float16Array {
|
|
104
|
-
const colorJScolorSpace = <string>Float16Image.COLORSPACES["rec2100-hlg" as HDRPredefinedColorSpace];
|
|
105
|
-
|
|
106
|
-
const srgbColor = new Color(
|
|
107
|
-
"srgb",
|
|
108
|
-
Array.from(pixel.slice(0, 3)).map((band: number) => {
|
|
109
|
-
return band / 255;
|
|
110
|
-
}) as Coords,
|
|
111
|
-
pixel[3] / 255
|
|
112
|
-
);
|
|
113
|
-
const rec2100hlgColor = srgbColor.to(colorJScolorSpace);
|
|
114
|
-
const hlg: Array<number> = rec2100hlgColor.coords.map((band: number) => {
|
|
115
|
-
return Math.round(band * Float16Image.SDR_MULTIPLIER);
|
|
116
|
-
});
|
|
117
|
-
// Readd alpha
|
|
118
|
-
hlg.push(rec2100hlgColor.alpha * Float16Image.SDR_MULTIPLIER);
|
|
87
|
+
try {
|
|
88
|
+
const imageDataSettings = {
|
|
89
|
+
colorSpace: this.colorSpace as PredefinedColorSpace,
|
|
90
|
+
pixelFormat: this.pixelFormat as ImageDataPixelFormat
|
|
91
|
+
};
|
|
119
92
|
|
|
120
|
-
|
|
93
|
+
if (Array.isArray(navigator.userAgent.match(/Version\/[\d.]+.*Safari/))) {
|
|
94
|
+
imageDataSettings["colorSpace"] = "display-p3";
|
|
95
|
+
}
|
|
96
|
+
return new ImageData(this.data as unknown as ImageDataArray, this.width, this.height, {
|
|
97
|
+
...imageDataSettings
|
|
98
|
+
} as ImageDataSettings) as ImageData;
|
|
99
|
+
} catch (e) {
|
|
100
|
+
console.error("Can't create Float16Array Image data, not supported by the browser", e);
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
121
103
|
}
|
|
122
104
|
|
|
123
105
|
/**
|
|
@@ -147,7 +129,7 @@ export class Float16Image extends HDRImage {
|
|
|
147
129
|
for (let i = 0; i < this.data.length; i += 4) {
|
|
148
130
|
const pixel = fn(this.data[i], this.data[i + 1], this.data[i + 2], this.data[i + 3]);
|
|
149
131
|
|
|
150
|
-
//TODO: Check if we should implicitly
|
|
132
|
+
//TODO: Check if we should implicitly operate on int pixel values
|
|
151
133
|
/*
|
|
152
134
|
for (let i = 0; i < pixel.length; i++) {
|
|
153
135
|
const normalizedFloat = pixel[i] / 255.0;
|
package/src/HDRImage.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
//import type { ImageData } from "./types/ImageData.d.ts";
|
|
2
2
|
import type { HDRPredefinedColorSpace, HDRImageData, HDRImageDataArray, HDRImagePixelCallback } from "./types/HDRCanvas.d.ts";
|
|
3
3
|
|
|
4
|
-
import type { ColorTypes } from "colorjs.io";
|
|
5
|
-
|
|
6
4
|
export abstract class HDRImage {
|
|
7
5
|
/** The default color space for new images, set to "rec2100-hlg". */
|
|
8
6
|
static DEFAULT_COLORSPACE: HDRPredefinedColorSpace = "rec2100-hlg";
|
|
@@ -10,14 +8,6 @@ export abstract class HDRImage {
|
|
|
10
8
|
/** A multiplier used for scaling 8-bit SDR values to 16-bit. */
|
|
11
9
|
static SDR_MULTIPLIER = 2 ** 16 - 1; //(2**16 - 1)
|
|
12
10
|
|
|
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
|
-
|
|
21
11
|
/** The raw pixel data stored as a `Float16Array`. */
|
|
22
12
|
data: HDRImageDataArray;
|
|
23
13
|
/** The height of the image in pixels. */
|
package/src/hdr-canvas.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { HDRImage } from "./HDRImage";
|
|
2
|
-
import { getBrowserVersion } from "./browser-util";
|
|
3
2
|
|
|
4
3
|
import type { HDRHTMLCanvasElement, CanvasRenderingContext2DHDRSettings, CanvasRenderingContext2DHDR } from "./types/HDRCanvas.d.ts";
|
|
5
4
|
|
|
@@ -10,19 +9,15 @@ import type { HDRHTMLCanvasElement, CanvasRenderingContext2DHDRSettings, CanvasR
|
|
|
10
9
|
* @returns {CanvasRenderingContext2DHDRSettings} An options object for creating an HDR canvas context.
|
|
11
10
|
*/
|
|
12
11
|
export function getHdrOptions(): CanvasRenderingContext2DHDRSettings {
|
|
13
|
-
const hdrOptions: CanvasRenderingContext2DHDRSettings = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (browserMajorVersion < 134) {
|
|
21
|
-
console.warn("Older Chrome / chromium based browser detected, using older `pixelFormat`");
|
|
22
|
-
} else {
|
|
23
|
-
hdrOptions["pixelFormat"] = "float16";
|
|
24
|
-
}
|
|
12
|
+
const hdrOptions: CanvasRenderingContext2DHDRSettings = {
|
|
13
|
+
colorSpace: HDRImage.DEFAULT_COLORSPACE,
|
|
14
|
+
colorType: "float16",
|
|
15
|
+
toneMapping: { mode: "extended" }
|
|
16
|
+
};
|
|
17
|
+
if (Array.isArray(navigator.userAgent.match(/Version\/[\d.]+.*Safari/))) {
|
|
18
|
+
hdrOptions["colorSpace"] = "display-p3";
|
|
25
19
|
}
|
|
20
|
+
|
|
26
21
|
return hdrOptions;
|
|
27
22
|
}
|
|
28
23
|
|
|
@@ -34,10 +29,6 @@ export function getHdrOptions(): CanvasRenderingContext2DHDRSettings {
|
|
|
34
29
|
* @returns {CanvasRenderingContext2DHDR | null} The 2D rendering context, or `null` if the context cannot be created. Can be cast down to `CanvasRenderingContext2D` or `RenderingContext`
|
|
35
30
|
*/
|
|
36
31
|
export function initHDRCanvas(canvas: HDRHTMLCanvasElement): CanvasRenderingContext2DHDR | null {
|
|
37
|
-
const browserMajorVersion = getBrowserVersion();
|
|
38
|
-
if (browserMajorVersion !== null && browserMajorVersion < 134) {
|
|
39
|
-
canvas.configureHighDynamicRange({ mode: "extended" });
|
|
40
|
-
}
|
|
41
32
|
const ctx = canvas.getContext("2d", getHdrOptions());
|
|
42
33
|
return ctx as CanvasRenderingContext2DHDR;
|
|
43
34
|
}
|
package/src/hdr-check.ts
CHANGED
|
@@ -7,8 +7,11 @@ import { getHdrOptions } from "./hdr-canvas";
|
|
|
7
7
|
*/
|
|
8
8
|
export function checkHDRVideo(): boolean {
|
|
9
9
|
try {
|
|
10
|
-
const
|
|
11
|
-
|
|
10
|
+
const dynamicRangeVideoFirefoxMQ: boolean =
|
|
11
|
+
navigator.userAgent.toLowerCase().includes("firefox") && window.matchMedia("(video-dynamic-range: high)").matches;
|
|
12
|
+
// For Safari
|
|
13
|
+
const dynamicRangeHighMQ: boolean = window.matchMedia("(dynamic-range: high) and (color-gamut: p3)").matches;
|
|
14
|
+
if (dynamicRangeVideoFirefoxMQ || dynamicRangeHighMQ) {
|
|
12
15
|
return true;
|
|
13
16
|
}
|
|
14
17
|
return false;
|
|
@@ -23,21 +26,10 @@ export function checkHDRVideo(): boolean {
|
|
|
23
26
|
*/
|
|
24
27
|
export function checkHDR(): boolean {
|
|
25
28
|
try {
|
|
26
|
-
const bitsPerChannel: number = screen.colorDepth / 3;
|
|
27
|
-
const hdrSupported: boolean = bitsPerChannel > 8;
|
|
28
|
-
|
|
29
|
-
//TODO: Test if this works as expected
|
|
30
29
|
const dynamicRangeHighMQ: boolean = window.matchMedia("(dynamic-range: high)").matches;
|
|
31
30
|
const colorGamutMQ: boolean = window.matchMedia("(color-gamut: rec2020)").matches || window.matchMedia("(color-gamut: p3)").matches;
|
|
32
31
|
if (colorGamutMQ && dynamicRangeHighMQ) {
|
|
33
|
-
|
|
34
|
-
// iOS bug
|
|
35
|
-
return false;
|
|
36
|
-
} else if (hdrSupported) {
|
|
37
|
-
return true;
|
|
38
|
-
} else {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
32
|
+
return true;
|
|
41
33
|
}
|
|
42
34
|
return false;
|
|
43
35
|
} catch (e) {
|
|
@@ -50,6 +42,9 @@ export function checkHDR(): boolean {
|
|
|
50
42
|
* @returns {boolean}
|
|
51
43
|
*/
|
|
52
44
|
export function checkHDRCanvas(): boolean {
|
|
45
|
+
if (!checkHDR() || !checkFloat16Array()) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
53
48
|
try {
|
|
54
49
|
const canvas: HTMLCanvasElement = document.createElement("canvas");
|
|
55
50
|
if (!canvas.getContext) {
|
|
@@ -58,17 +53,39 @@ export function checkHDRCanvas(): boolean {
|
|
|
58
53
|
|
|
59
54
|
const options = getHdrOptions();
|
|
60
55
|
const ctx: CanvasRenderingContext2D | null = <CanvasRenderingContext2D>canvas.getContext("2d", options);
|
|
61
|
-
//canvas.drawingBufferColorSpace = colorSpace;
|
|
62
|
-
//canvas.unpackColorSpace = colorSpace;
|
|
63
56
|
if (ctx === null) {
|
|
64
57
|
return false;
|
|
65
58
|
}
|
|
66
59
|
return true;
|
|
67
|
-
} catch {
|
|
60
|
+
} catch (e) {
|
|
68
61
|
console.error(
|
|
69
|
-
"Bad canvas ColorSpace test - make sure that the Chromium browser flag 'enable-experimental-web-platform-features' has been enabled"
|
|
62
|
+
"Bad canvas ColorSpace test - make sure that the Chromium browser flag 'enable-experimental-web-platform-features' has been enabled",
|
|
63
|
+
e
|
|
70
64
|
);
|
|
71
65
|
|
|
72
66
|
return false;
|
|
73
67
|
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Check if Float16Array is supported, to be used in {ImageData}
|
|
72
|
+
* @returns {boolean}
|
|
73
|
+
*/
|
|
74
|
+
export function checkFloat16Array(): boolean {
|
|
75
|
+
try {
|
|
76
|
+
new ImageData(new Float16Array(4) as any, 1, 1, { pixelFormat: "rgba-float16" } as any);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.error("Browser doesn't support Float16Array", e);
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
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;
|
|
74
91
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export { Uint16Image } from "./Uint16Image";
|
|
2
1
|
export { Float16Image } from "./Float16Image";
|
|
3
2
|
export { HDRImage } from "./HDRImage";
|
|
4
|
-
export { checkHDR, checkHDRCanvas } from "./hdr-check";
|
|
3
|
+
export { checkHDR, checkHDRVideo, checkHDRCanvas, checkFloat16Array, checkHDRBitDepth } from "./hdr-check";
|
|
5
4
|
export { initHDRCanvas, defaultGetContextHDR, resetGetContext } from "./hdr-canvas";
|
|
@@ -50,13 +50,22 @@ class HDRWebGPUBackend extends WebGPUBackend {
|
|
|
50
50
|
* @see {@link https://github.com/ccameron-chromium/webgpu-hdr/blob/main/EXPLAINER.md#example-use | WebGPU HDR Explainer}
|
|
51
51
|
*/
|
|
52
52
|
|
|
53
|
+
const hdrSettings = {};
|
|
54
|
+
const dynamicRangeHighMQ = window.matchMedia("(dynamic-range: high)").matches;
|
|
55
|
+
if (dynamicRangeHighMQ) {
|
|
56
|
+
hdrSettings["colorSpace"] = "rec2100-hlg";
|
|
57
|
+
hdrSettings["toneMapping"] = { mode: "extended" };
|
|
58
|
+
}
|
|
59
|
+
if (Array.isArray(navigator.userAgent.match(/Version\/[\d.]+.*Safari/))) {
|
|
60
|
+
delete hdrSettings["colorSpace"];
|
|
61
|
+
}
|
|
62
|
+
|
|
53
63
|
context.configure( {
|
|
54
64
|
device: this.device,
|
|
55
65
|
format: this.utils.getPreferredCanvasFormat(),
|
|
56
66
|
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
|
|
57
67
|
alphaMode: alphaMode,
|
|
58
|
-
|
|
59
|
-
toneMapping: { mode: "extended" }
|
|
68
|
+
...hdrSettings
|
|
60
69
|
} );
|
|
61
70
|
|
|
62
71
|
canvasData.context = context;
|
package/tsconfig.json
CHANGED
|
@@ -15,17 +15,18 @@
|
|
|
15
15
|
"declaration": true,
|
|
16
16
|
"allowJs": true,
|
|
17
17
|
"skipLibCheck": true,
|
|
18
|
-
"target": "
|
|
18
|
+
"target": "es2025",
|
|
19
|
+
"rootDir": ".",
|
|
19
20
|
"outDir": "dist",
|
|
20
21
|
"declarationDir": "dist",
|
|
21
22
|
"typeRoots": ["./node_modules/@types"],
|
|
22
|
-
"lib": ["
|
|
23
|
+
"lib": ["es2025"],
|
|
23
24
|
"paths": {
|
|
24
25
|
"~/hdr-canvas/three/*": ["./three/*"],
|
|
25
26
|
"~/hdr-canvas/*": ["./src/*"],
|
|
26
27
|
"three": ["./node_modules/@types/three"]
|
|
27
28
|
}
|
|
28
29
|
},
|
|
29
|
-
"include": ["src/**/*", "tests/site/**/*", "tests/*"],
|
|
30
|
+
"include": ["./src/**/*", "./tests/site/**/*", "./tests/*"],
|
|
30
31
|
"exclude": ["node_modules", "**/*.spec.ts", "three/**/*"]
|
|
31
32
|
}
|