hdr-canvas 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +12 -3
- package/dist/hdr-canvas.cjs +2 -1
- package/dist/hdr-canvas.cjs.map +1 -1
- package/dist/hdr-canvas.js +2 -1
- 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 +3 -3
- package/src/@types/HDRCanvas.d.ts +1 -0
- package/src/hdr-canvas.ts +24 -1
- package/three/HDRWebGPURenderer.js +1 -1
- package/three/WebGPU.js +60 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hdr-canvas",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.6",
|
4
4
|
"description": "HDR capable HTML canvas",
|
5
5
|
"main": "dist/hdr-canvas.js",
|
6
6
|
"files": [
|
@@ -47,9 +47,9 @@
|
|
47
47
|
"eslint": "^9.6.0",
|
48
48
|
"prettier": "^3.3.2",
|
49
49
|
"rimraf": "^6.0.0",
|
50
|
-
"rollup": "^4.18.
|
50
|
+
"rollup": "^4.18.1",
|
51
51
|
"rollup-plugin-dts": "^6.1.1",
|
52
|
-
"three": "^0.
|
52
|
+
"three": "^0.167.0",
|
53
53
|
"tslib": "^2.6.3",
|
54
54
|
"typescript": "^5.5.3",
|
55
55
|
"typescript-eslint": "^8.0.0-alpha.10"
|
@@ -5,6 +5,7 @@ type HDRHTMLCanvasOptions = { [key in HDRHTMLCanvasOptionsType]?: string };
|
|
5
5
|
|
6
6
|
interface HDRHTMLCanvasElement extends HTMLCanvasElement {
|
7
7
|
configureHighDynamicRange(options: HDRHTMLCanvasOptions): void;
|
8
|
+
_getContext(contextId: string, options?: object): RenderingContext | null;
|
8
9
|
}
|
9
10
|
|
10
11
|
interface HDRImageData {
|
package/src/hdr-canvas.ts
CHANGED
@@ -1,7 +1,30 @@
|
|
1
1
|
import {Uint16Image} from './Uint16Image'
|
2
2
|
|
3
|
+
const hdr_options = {colorSpace: Uint16Image.DEFAULT_COLORSPACE, pixelFormat: 'float16'}
|
4
|
+
|
3
5
|
export function initHDRCanvas(canvas : HDRHTMLCanvasElement) : RenderingContext | null {
|
4
6
|
canvas.configureHighDynamicRange({mode: 'extended'});
|
5
|
-
const ctx = canvas.getContext("2d",
|
7
|
+
const ctx = canvas.getContext("2d", hdr_options);
|
6
8
|
return ctx;
|
7
9
|
}
|
10
|
+
|
11
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
12
|
+
export function defaultGetContextHDR() {
|
13
|
+
(HTMLCanvasElement.prototype as HDRHTMLCanvasElement)._getContext = HTMLCanvasElement.prototype.getContext;
|
14
|
+
(HTMLCanvasElement.prototype as any).getContext = function(type: string, options: object) {
|
15
|
+
|
16
|
+
if (options !== undefined) {
|
17
|
+
options = Object.assign({}, options, hdr_options);
|
18
|
+
} else {
|
19
|
+
options = hdr_options;
|
20
|
+
}
|
21
|
+
return (this as HDRHTMLCanvasElement)._getContext(type, options);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
26
|
+
export function resetGetContext() {
|
27
|
+
if (typeof (HTMLCanvasElement.prototype as HDRHTMLCanvasElement)._getContext === "function") {
|
28
|
+
HTMLCanvasElement.prototype.getContext = (HTMLCanvasElement.prototype as any)._getContext;
|
29
|
+
}
|
30
|
+
}
|
package/three/WebGPU.js
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
if ( self.GPUShaderStage === undefined ) {
|
2
|
+
|
3
|
+
self.GPUShaderStage = { VERTEX: 1, FRAGMENT: 2, COMPUTE: 4 };
|
4
|
+
|
5
|
+
}
|
6
|
+
|
7
|
+
// statics
|
8
|
+
|
9
|
+
let isAvailable = navigator.gpu !== undefined;
|
10
|
+
|
11
|
+
|
12
|
+
if ( typeof window !== 'undefined' && isAvailable ) {
|
13
|
+
|
14
|
+
//isAvailable = await navigator.gpu.requestAdapter();
|
15
|
+
isAvailable = navigator.gpu.requestAdapter().then((isAvailable) => {
|
16
|
+
return isAvailable;
|
17
|
+
});
|
18
|
+
|
19
|
+
}
|
20
|
+
|
21
|
+
class WebGPU {
|
22
|
+
|
23
|
+
static isAvailable() {
|
24
|
+
|
25
|
+
return Boolean( isAvailable );
|
26
|
+
|
27
|
+
}
|
28
|
+
|
29
|
+
static getStaticAdapter() {
|
30
|
+
|
31
|
+
return isAvailable;
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
static getErrorMessage() {
|
36
|
+
|
37
|
+
const message = 'Your browser does not support <a href="https://gpuweb.github.io/gpuweb/" style="color:blue">WebGPU</a> yet';
|
38
|
+
|
39
|
+
const element = document.createElement( 'div' );
|
40
|
+
element.id = 'webgpumessage';
|
41
|
+
element.style.fontFamily = 'monospace';
|
42
|
+
element.style.fontSize = '13px';
|
43
|
+
element.style.fontWeight = 'normal';
|
44
|
+
element.style.textAlign = 'center';
|
45
|
+
element.style.background = '#fff';
|
46
|
+
element.style.color = '#000';
|
47
|
+
element.style.padding = '1.5em';
|
48
|
+
element.style.maxWidth = '400px';
|
49
|
+
element.style.margin = '5em auto 0';
|
50
|
+
|
51
|
+
element.innerHTML = message;
|
52
|
+
|
53
|
+
return element;
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
export default WebGPU;
|