hdr-canvas 0.0.1 → 0.0.3

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.1",
3
+ "version": "0.0.3",
4
4
  "description": "HDR capable HTML canvas",
5
5
  "main": "dist/hdr-canvas.js",
6
6
  "files": [
@@ -125,6 +125,24 @@ export class Uint16Image {
125
125
  }
126
126
  }
127
127
 
128
+ static async loadSDRImageData(url: URL): Promise<HDRImageData | undefined> {
129
+ return fetch(url)
130
+ .then((response) => response.blob())
131
+ .then((blob: Blob) => {
132
+ return createImageBitmap(blob);
133
+ })
134
+ .then((bitmap: ImageBitmap) => {
135
+ const { width, height } = bitmap;
136
+ const offscreen = new OffscreenCanvas(width, height);
137
+ const ctx = offscreen.getContext("2d");
138
+ ctx?.drawImage(bitmap, 0, 0);
139
+ return ctx;
140
+ })
141
+ .then((ctx: OffscreenCanvasRenderingContext2D | null) => {
142
+ return ctx?.getImageData(0, 0, ctx?.canvas.width, ctx?.canvas.height);
143
+ });
144
+ }
145
+
128
146
  static fromImageData(imageData: HDRImageData): Uint16Image {
129
147
  const i = new Uint16Image(imageData.width, imageData.height);
130
148
  if (imageData.colorSpace == "srgb") {
@@ -139,6 +157,16 @@ export class Uint16Image {
139
157
  return i;
140
158
  }
141
159
 
160
+ static async fromURL(url: URL): Promise<Uint16Image | undefined> {
161
+ return Uint16Image.loadSDRImageData(url).then(
162
+ (data: HDRImageData | undefined) => {
163
+ if (data !== undefined) {
164
+ return Uint16Image.fromImageData(data);
165
+ }
166
+ },
167
+ );
168
+ }
169
+
142
170
  setImageData(imageData: HDRImageData): void {
143
171
  this.width = imageData.width;
144
172
  this.height = imageData.height;
@@ -1,5 +1,5 @@
1
1
  import WebGPUBackend from 'three/addons/renderers/webgpu/WebGPUBackend.js';
2
- import { GPUFeatureName, GPUTextureFormat, GPUTextureUsage } from 'three/addons/renderers/webgpu/utils/WebGPUConstants.js';
2
+ import { GPUFeatureName, GPUTextureFormat } from 'three/addons/renderers/webgpu/utils/WebGPUConstants.js';
3
3
 
4
4
  class HDRWebGPUBackend extends WebGPUBackend {
5
5