hdr-canvas 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,8 +18,11 @@ 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;
25
+ clone(): Uint16Image;
23
26
  }
24
27
 
25
28
  declare function checkHDR(): boolean;
@@ -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;
@@ -5846,6 +5870,11 @@ class Uint16Image {
5846
5870
  }
5847
5871
  this.colorSpace = Uint16Image.DEFAULT_COLORSPACE;
5848
5872
  }
5873
+ clone() {
5874
+ const i = new Uint16Image(this.width, this.height, this.colorSpace);
5875
+ i.data = this.data.slice();
5876
+ return i;
5877
+ }
5849
5878
  }
5850
5879
  Uint16Image.DEFAULT_COLORSPACE = "rec2100-hlg";
5851
5880
  Uint16Image.SDR_MULTIPLIER = 2 ** 16 - 1;