hdr-canvas 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,7 +18,9 @@ declare class Uint16Image {
18
18
  static convertPixelToRec2100_hlg(pixel: Uint8ClampedArray): Uint16Array;
19
19
  static convertArrayToRec2100_hlg(data: Uint8ClampedArray): Uint16Array;
20
20
  pixelCallback(fn: Uint16ImagePixelCallback): void;
21
+ static loadSDRImageData(url: URL): Promise<HDRImageData | undefined>;
21
22
  static fromImageData(imageData: HDRImageData): Uint16Image;
23
+ static fromURL(url: URL): Promise<Uint16Image | undefined>;
22
24
  setImageData(imageData: HDRImageData): void;
23
25
  }
24
26
 
@@ -5819,6 +5819,23 @@ class Uint16Image {
5819
5819
  this.data.set(fn(this.data[i], this.data[i + 1], this.data[i + 2], this.data[i + 3]), i);
5820
5820
  }
5821
5821
  }
5822
+ static async loadSDRImageData(url) {
5823
+ return fetch(url)
5824
+ .then((response) => response.blob())
5825
+ .then((blob) => {
5826
+ return createImageBitmap(blob);
5827
+ })
5828
+ .then((bitmap) => {
5829
+ const { width, height } = bitmap;
5830
+ const offscreen = new OffscreenCanvas(width, height);
5831
+ const ctx = offscreen.getContext("2d");
5832
+ ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(bitmap, 0, 0);
5833
+ return ctx;
5834
+ })
5835
+ .then((ctx) => {
5836
+ return ctx === null || ctx === void 0 ? void 0 : ctx.getImageData(0, 0, ctx === null || ctx === void 0 ? void 0 : ctx.canvas.width, ctx === null || ctx === void 0 ? void 0 : ctx.canvas.height);
5837
+ });
5838
+ }
5822
5839
  static fromImageData(imageData) {
5823
5840
  const i = new Uint16Image(imageData.width, imageData.height);
5824
5841
  if (imageData.colorSpace == "srgb") {
@@ -5832,6 +5849,13 @@ class Uint16Image {
5832
5849
  }
5833
5850
  return i;
5834
5851
  }
5852
+ static async fromURL(url) {
5853
+ return Uint16Image.loadSDRImageData(url).then((data) => {
5854
+ if (data !== undefined) {
5855
+ return Uint16Image.fromImageData(data);
5856
+ }
5857
+ });
5858
+ }
5835
5859
  setImageData(imageData) {
5836
5860
  this.width = imageData.width;
5837
5861
  this.height = imageData.height;