hdr-canvas 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdr-canvas",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "HDR capable HTML canvas",
5
5
  "main": "dist/hdr-canvas.js",
6
6
  "files": [
@@ -49,7 +49,7 @@
49
49
  "rimraf": "^6.0.0",
50
50
  "rollup": "^4.18.1",
51
51
  "rollup-plugin-dts": "^6.1.1",
52
- "three": "^0.166.1",
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", {colorSpace: Uint16Image.DEFAULT_COLORSPACE, pixelFormat: 'float16'});
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/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { Uint16Image } from "./Uint16Image";
2
2
  export { checkHDR, checkHDRCanvas } from "./hdr-check";
3
- export { initHDRCanvas } from "./hdr-canvas";
3
+ export { initHDRCanvas, defaultGetContextHDR, resetGetContext } from "./hdr-canvas";