hdr-canvas 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -5
- package/dist/@types/hdr-canvas.d.ts +57 -0
- package/dist/hdr-canvas.cjs +25 -20
- package/dist/hdr-canvas.cjs.map +1 -1
- package/dist/hdr-canvas.d.ts +4 -35
- package/dist/hdr-canvas.js +25 -20
- 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/dist/index.d.ts +57 -0
- package/package.json +23 -11
- package/src/Uint16Image.ts +17 -34
- package/src/hdr-canvas.ts +8 -7
- package/src/hdr-check.ts +13 -15
- package/src/index.ts +1 -5
- package/src/{@types → types}/HDRCanvas.d.ts +4 -5
package/dist/hdr-canvas.d.ts
CHANGED
@@ -1,35 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
declare
|
5
|
-
height: number;
|
6
|
-
width: number;
|
7
|
-
data: Uint16Array;
|
8
|
-
static DEFAULT_COLORSPACE: HDRPredefinedColorSpace;
|
9
|
-
static SDR_MULTIPLIER: number;
|
10
|
-
static COLORSPACES: Record<HDRPredefinedColorSpace, ColorTypes>;
|
11
|
-
colorSpace: HDRPredefinedColorSpace;
|
12
|
-
constructor(width: number, height: number, colorspace?: string);
|
13
|
-
fill(color: number[]): Uint16Image | undefined;
|
14
|
-
getPixel(w: number, h: number): Uint16Array;
|
15
|
-
setPixel(w: number, h: number, px: number[]): void;
|
16
|
-
static scaleUint8ToUint16(val: number): number;
|
17
|
-
getImageData(): ImageData | null;
|
18
|
-
static convertPixelToRec2100_hlg(pixel: Uint8ClampedArray): Uint16Array;
|
19
|
-
static convertArrayToRec2100_hlg(data: Uint8ClampedArray): Uint16Array;
|
20
|
-
pixelCallback(fn: Uint16ImagePixelCallback): void;
|
21
|
-
static loadSDRImageData(url: URL): Promise<HDRImageData | undefined>;
|
22
|
-
static fromImageData(imageData: HDRImageData): Uint16Image;
|
23
|
-
static fromURL(url: URL): Promise<Uint16Image | undefined>;
|
24
|
-
setImageData(imageData: HDRImageData): void;
|
25
|
-
clone(): Uint16Image;
|
26
|
-
}
|
27
|
-
|
28
|
-
declare function checkHDR(): boolean;
|
29
|
-
declare function checkHDRCanvas(): boolean;
|
30
|
-
|
31
|
-
declare function initHDRCanvas(canvas: HDRHTMLCanvasElement): RenderingContext | null;
|
32
|
-
declare function defaultGetContextHDR(): void;
|
33
|
-
declare function resetGetContext(): void;
|
34
|
-
|
35
|
-
export { Uint16Image, checkHDR, checkHDRCanvas, defaultGetContextHDR, initHDRCanvas, resetGetContext };
|
1
|
+
import type { HDRHTMLCanvasElement } from "./types/HDRCanvas.d.ts";
|
2
|
+
export declare function initHDRCanvas(canvas: HDRHTMLCanvasElement): RenderingContext | null;
|
3
|
+
export declare function defaultGetContextHDR(): void;
|
4
|
+
export declare function resetGetContext(): void;
|
package/dist/hdr-canvas.js
CHANGED
@@ -5750,6 +5750,18 @@ Color.extend(interpolation);
|
|
5750
5750
|
Color.extend(contrastMethods);
|
5751
5751
|
|
5752
5752
|
class Uint16Image {
|
5753
|
+
height;
|
5754
|
+
width;
|
5755
|
+
data;
|
5756
|
+
static DEFAULT_COLORSPACE = "rec2100-hlg";
|
5757
|
+
static SDR_MULTIPLIER = 2 ** 16 - 1;
|
5758
|
+
static COLORSPACES = {
|
5759
|
+
"rec2100-hlg": "rec2100hlg",
|
5760
|
+
"display-p3": "p3",
|
5761
|
+
srgb: "sRGB",
|
5762
|
+
"rec2100-pq": "rec2100pq"
|
5763
|
+
};
|
5764
|
+
colorSpace;
|
5753
5765
|
constructor(width, height, colorspace) {
|
5754
5766
|
if (colorspace === undefined || colorspace === null) {
|
5755
5767
|
this.colorSpace = Uint16Image.DEFAULT_COLORSPACE;
|
@@ -5791,10 +5803,12 @@ class Uint16Image {
|
|
5791
5803
|
if (this.data === undefined || this.data === null) {
|
5792
5804
|
return null;
|
5793
5805
|
}
|
5794
|
-
return new ImageData(this.data, this.width, this.height, {
|
5806
|
+
return new ImageData(this.data, this.width, this.height, {
|
5807
|
+
colorSpace: this.colorSpace
|
5808
|
+
});
|
5795
5809
|
}
|
5796
5810
|
static convertPixelToRec2100_hlg(pixel) {
|
5797
|
-
const colorJScolorSpace =
|
5811
|
+
const colorJScolorSpace = Uint16Image.COLORSPACES["rec2100-hlg"];
|
5798
5812
|
const srgbColor = new Color("srgb", Array.from(pixel.slice(0, 3)).map((band) => {
|
5799
5813
|
return band / 255;
|
5800
5814
|
}), pixel[3] / 255);
|
@@ -5829,11 +5843,11 @@ class Uint16Image {
|
|
5829
5843
|
const { width, height } = bitmap;
|
5830
5844
|
const offscreen = new OffscreenCanvas(width, height);
|
5831
5845
|
const ctx = offscreen.getContext("2d");
|
5832
|
-
ctx
|
5846
|
+
ctx?.drawImage(bitmap, 0, 0);
|
5833
5847
|
return ctx;
|
5834
5848
|
})
|
5835
5849
|
.then((ctx) => {
|
5836
|
-
return ctx
|
5850
|
+
return ctx?.getImageData(0, 0, ctx?.canvas.width, ctx?.canvas.height);
|
5837
5851
|
});
|
5838
5852
|
}
|
5839
5853
|
static fromImageData(imageData) {
|
@@ -5876,22 +5890,13 @@ class Uint16Image {
|
|
5876
5890
|
return i;
|
5877
5891
|
}
|
5878
5892
|
}
|
5879
|
-
Uint16Image.DEFAULT_COLORSPACE = "rec2100-hlg";
|
5880
|
-
Uint16Image.SDR_MULTIPLIER = 2 ** 16 - 1;
|
5881
|
-
Uint16Image.COLORSPACES = {
|
5882
|
-
"rec2100-hlg": "rec2100hlg",
|
5883
|
-
"display-p3": "p3",
|
5884
|
-
srgb: "sRGB",
|
5885
|
-
"rec2100-pq": "rec2100pq",
|
5886
|
-
};
|
5887
5893
|
|
5888
5894
|
function checkHDR() {
|
5889
5895
|
try {
|
5890
5896
|
const bitsPerChannel = screen.colorDepth / 3;
|
5891
5897
|
const hdrSupported = bitsPerChannel > 8;
|
5892
5898
|
const dynamicRangeHighMQ = window.matchMedia("(dynamic-range: high)").matches;
|
5893
|
-
const colorGamutMQ = window.matchMedia("(color-gamut: rec2020)").matches ||
|
5894
|
-
window.matchMedia("(color-gamut: p3)").matches;
|
5899
|
+
const colorGamutMQ = window.matchMedia("(color-gamut: rec2020)").matches || window.matchMedia("(color-gamut: p3)").matches;
|
5895
5900
|
if (colorGamutMQ && dynamicRangeHighMQ) {
|
5896
5901
|
if (bitsPerChannel !== Math.round(bitsPerChannel)) {
|
5897
5902
|
return false;
|
@@ -5917,24 +5922,24 @@ function checkHDRCanvas() {
|
|
5917
5922
|
if (!canvas.getContext) {
|
5918
5923
|
return false;
|
5919
5924
|
}
|
5920
|
-
const ctx =
|
5925
|
+
const ctx = canvas.getContext("2d", {
|
5921
5926
|
colorSpace: colorSpace,
|
5922
|
-
pixelFormat: "float16"
|
5923
|
-
})
|
5927
|
+
pixelFormat: "float16"
|
5928
|
+
});
|
5924
5929
|
if (ctx === null) {
|
5925
5930
|
return false;
|
5926
5931
|
}
|
5927
5932
|
return true;
|
5928
5933
|
}
|
5929
5934
|
catch (e) {
|
5930
|
-
console.error("Bad canvas ColorSpace test"
|
5935
|
+
console.error("Bad canvas ColorSpace test - make sure that the Chromium browser flag 'enable-experimental-web-platform-features' has been enabled");
|
5931
5936
|
return false;
|
5932
5937
|
}
|
5933
5938
|
}
|
5934
5939
|
|
5935
|
-
const hdr_options = { colorSpace: Uint16Image.DEFAULT_COLORSPACE, pixelFormat:
|
5940
|
+
const hdr_options = { colorSpace: Uint16Image.DEFAULT_COLORSPACE, pixelFormat: "float16" };
|
5936
5941
|
function initHDRCanvas(canvas) {
|
5937
|
-
canvas.configureHighDynamicRange({ mode:
|
5942
|
+
canvas.configureHighDynamicRange({ mode: "extended" });
|
5938
5943
|
const ctx = canvas.getContext("2d", hdr_options);
|
5939
5944
|
return ctx;
|
5940
5945
|
}
|