image-js 1.1.0 → 1.3.0
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/dist/image-js.esm.js +268 -54
- package/dist/image-js.esm.js.map +1 -1
- package/dist/image-js.esm.min.js +2 -2
- package/dist/image-js.esm.min.js.map +1 -1
- package/dist/image-js.umd.js +236 -20
- package/dist/image-js.umd.js.map +1 -1
- package/dist/image-js.umd.min.js +2 -2
- package/dist/image-js.umd.min.js.map +1 -1
- package/dist-types/image-js.d.ts +26 -2
- package/lib/Image.d.ts +17 -1
- package/lib/Image.d.ts.map +1 -1
- package/lib/Image.js +38 -1
- package/lib/Image.js.map +1 -1
- package/lib/draw/drawLineOnImage.d.ts.map +1 -1
- package/lib/draw/drawLineOnImage.js.map +1 -1
- package/lib/extra/draw/draw_text.d.ts +47 -0
- package/lib/extra/draw/draw_text.d.ts.map +1 -0
- package/lib/extra/draw/draw_text.js +108 -0
- package/lib/extra/draw/draw_text.js.map +1 -0
- package/lib/extra/draw/index.d.ts +3 -0
- package/lib/extra/draw/index.d.ts.map +1 -0
- package/lib/extra/draw/index.js +3 -0
- package/lib/extra/draw/index.js.map +1 -0
- package/lib/{ssim → extra/ssim}/compute_dssim.d.ts +2 -2
- package/lib/extra/ssim/compute_dssim.d.ts.map +1 -0
- package/lib/{ssim → extra/ssim}/compute_dssim.js +1 -1
- package/lib/extra/ssim/compute_dssim.js.map +1 -0
- package/lib/{ssim → extra/ssim}/compute_ssim.d.ts +1 -1
- package/lib/extra/ssim/compute_ssim.d.ts.map +1 -0
- package/lib/{ssim → extra/ssim}/compute_ssim.js +2 -2
- package/lib/extra/ssim/compute_ssim.js.map +1 -0
- package/lib/extra/ssim/index.d.ts +3 -0
- package/lib/extra/ssim/index.d.ts.map +1 -0
- package/lib/extra/ssim/index.js +3 -0
- package/lib/extra/ssim/index.js.map +1 -0
- package/lib/index_browser.d.ts +3 -0
- package/lib/index_browser.d.ts.map +1 -0
- package/lib/index_browser.js +5 -0
- package/lib/index_browser.js.map +1 -0
- package/lib/index_full.d.ts +4 -0
- package/lib/index_full.d.ts.map +1 -0
- package/lib/index_full.js +5 -0
- package/lib/index_full.js.map +1 -0
- package/lib/load/decodePng.d.ts.map +1 -1
- package/lib/load/decodePng.js +16 -0
- package/lib/load/decodePng.js.map +1 -1
- package/lib/load/decodeTiff.d.ts.map +1 -1
- package/lib/load/decodeTiff.js +35 -0
- package/lib/load/decodeTiff.js.map +1 -1
- package/lib/load/load.types.d.ts +6 -0
- package/lib/load/load.types.d.ts.map +1 -1
- package/lib/load/read.d.ts +1 -1
- package/lib/load/read.js +1 -1
- package/lib/save/write.d.ts +1 -1
- package/lib/save/write.js +1 -1
- package/lib/utils/cross_platform.d.ts +8 -0
- package/lib/utils/cross_platform.d.ts.map +1 -1
- package/lib/utils/cross_platform.js +34 -2
- package/lib/utils/cross_platform.js.map +1 -1
- package/lib/utils/setBlendedPixel.d.ts +1 -1
- package/lib/utils/setBlendedPixel.js +1 -1
- package/lib/utils/setBlendedVisiblePixel.d.ts +1 -1
- package/lib/utils/setBlendedVisiblePixel.js +1 -1
- package/package.json +17 -3
- package/src/Image.ts +44 -4
- package/src/draw/drawLineOnImage.ts +0 -1
- package/src/extra/draw/draw_text.ts +194 -0
- package/src/extra/draw/index.ts +2 -0
- package/src/{ssim → extra/ssim}/compute_dssim.ts +3 -3
- package/src/{ssim → extra/ssim}/compute_ssim.ts +3 -3
- package/src/extra/ssim/index.ts +2 -0
- package/src/index_browser.ts +4 -0
- package/src/index_full.ts +4 -0
- package/src/load/decodePng.ts +18 -0
- package/src/load/decodeTiff.ts +38 -1
- package/src/load/load.types.ts +8 -0
- package/src/load/read.ts +1 -1
- package/src/save/write.ts +1 -1
- package/src/utils/cross_platform.ts +47 -4
- package/src/utils/setBlendedPixel.ts +1 -1
- package/src/utils/setBlendedVisiblePixel.ts +1 -1
- package/lib/ssim/compute_dssim.d.ts.map +0 -1
- package/lib/ssim/compute_dssim.js.map +0 -1
- package/lib/ssim/compute_ssim.d.ts.map +0 -1
- package/lib/ssim/compute_ssim.js.map +0 -1
- package/lib/ssim/index.d.ts +0 -3
- package/lib/ssim/index.d.ts.map +0 -1
- package/lib/ssim/index.js +0 -3
- package/lib/ssim/index.js.map +0 -1
- package/src/ssim/index.ts +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decodePng.d.ts","sourceRoot":"","sources":["../../src/load/decodePng.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"decodePng.d.ts","sourceRoot":"","sources":["../../src/load/decodePng.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAMpC;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,KAAK,CAoDnD"}
|
package/lib/load/decodePng.js
CHANGED
|
@@ -35,10 +35,26 @@ export function decodePng(buffer) {
|
|
|
35
35
|
default:
|
|
36
36
|
throw new RangeError(`invalid number of channels: ${png.channels}`);
|
|
37
37
|
}
|
|
38
|
+
let resolution;
|
|
39
|
+
if (png.resolution) {
|
|
40
|
+
resolution =
|
|
41
|
+
png.resolution.unit === 1
|
|
42
|
+
? /*If the resolution unit is meters*/ {
|
|
43
|
+
x: png.resolution.x,
|
|
44
|
+
y: png.resolution.y,
|
|
45
|
+
unit: 'meter',
|
|
46
|
+
}
|
|
47
|
+
: /*If resolution unit is unknown */ {
|
|
48
|
+
x: png.resolution.x,
|
|
49
|
+
y: png.resolution.y,
|
|
50
|
+
unit: 'unknown',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
38
53
|
return new Image(png.width, png.height, {
|
|
39
54
|
colorModel,
|
|
40
55
|
bitDepth,
|
|
41
56
|
data: png.data,
|
|
57
|
+
resolution,
|
|
42
58
|
});
|
|
43
59
|
}
|
|
44
60
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decodePng.js","sourceRoot":"","sources":["../../src/load/decodePng.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"decodePng.js","sourceRoot":"","sources":["../../src/load/decodePng.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAIvD;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,MAAkB;IAC1C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAE3B,IAAI,UAA2B,CAAC;IAChC,MAAM,QAAQ,GAAa,GAAG,CAAC,KAAiB,CAAC;IACjD,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;QAChB,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IACD,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE;YACtC,IAAI,EAAE,YAAY,CAAC,GAAG,CAAC;YACvB,UAAU,EAAE,MAAM;SACnB,CAAC,CAAC;IACL,CAAC;IACD,QAAQ,GAAG,CAAC,QAAQ,EAAE,CAAC;QACrB,KAAK,CAAC;YACJ,UAAU,GAAG,MAAM,CAAC;YACpB,MAAM;QACR,KAAK,CAAC;YACJ,UAAU,GAAG,OAAO,CAAC;YACrB,MAAM;QACR,KAAK,CAAC;YACJ,UAAU,GAAG,KAAK,CAAC;YACnB,MAAM;QACR,KAAK,CAAC;YACJ,UAAU,GAAG,MAAM,CAAC;YACpB,MAAM;QACR;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AAO,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC;IAC9B,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC9C,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,KACE,IAAI,SAAS,GAAG,CAAC,EACjB,SAAS,GAAG,OAAO,CAAC,MAAM,IAAI,UAAU,GAAG,WAAW,EACtD,SAAS,EAAE,EACX,CAAC;QACD,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,SAAS,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/D,KACE,IAAI,QAAQ,GAAG,CAAC,EAChB,QAAQ,IAAI,KAAK,IAAI,UAAU,GAAG,WAAW,EAC7C,QAAQ,EAAE,EACV,CAAC;YACD,MAAM,GAAG,GAAG,CAAC,IAAI,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC;YACnC,MAAM,CAAC,UAAU,EAAE,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC;QACnC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decodeTiff.d.ts","sourceRoot":"","sources":["../../src/load/decodeTiff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAG9B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"decodeTiff.d.ts","sourceRoot":"","sources":["../../src/load/decodeTiff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAG9B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAKpC,KAAK,OAAO,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,KAAK,CAGpD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CAyEnD"}
|
package/lib/load/decodeTiff.js
CHANGED
|
@@ -19,6 +19,7 @@ export function getImageFromIFD(ifd) {
|
|
|
19
19
|
if (ifd.data instanceof Float32Array || ifd.data instanceof Float64Array) {
|
|
20
20
|
throw new Error('Float TIFF data is not supported.');
|
|
21
21
|
}
|
|
22
|
+
const resolution = getTiffResolution(ifd);
|
|
22
23
|
if (ifd.type === 3) {
|
|
23
24
|
const hasAlpha = ifd.samplesPerPixel === 2;
|
|
24
25
|
const pixelLength = hasAlpha ? 4 : 3;
|
|
@@ -48,6 +49,7 @@ export function getImageFromIFD(ifd) {
|
|
|
48
49
|
colorModel: hasAlpha ? 'RGBA' : 'RGB',
|
|
49
50
|
bitDepth: 16,
|
|
50
51
|
meta: getMetadata(ifd),
|
|
52
|
+
resolution,
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
55
|
else if (ifd.type === 1 || ifd.type === 0) {
|
|
@@ -57,6 +59,7 @@ export function getImageFromIFD(ifd) {
|
|
|
57
59
|
bitDepth: ifd.bitsPerSample,
|
|
58
60
|
colorModel: ifd.alpha ? 'GREYA' : 'GREY',
|
|
59
61
|
meta: getMetadata(ifd),
|
|
62
|
+
resolution,
|
|
60
63
|
});
|
|
61
64
|
}
|
|
62
65
|
else {
|
|
@@ -65,6 +68,7 @@ export function getImageFromIFD(ifd) {
|
|
|
65
68
|
bitDepth: 8,
|
|
66
69
|
colorModel: 'GREY',
|
|
67
70
|
meta: getMetadata(ifd),
|
|
71
|
+
resolution,
|
|
68
72
|
});
|
|
69
73
|
}
|
|
70
74
|
}
|
|
@@ -74,7 +78,38 @@ export function getImageFromIFD(ifd) {
|
|
|
74
78
|
bitDepth: ifd.bitsPerSample,
|
|
75
79
|
colorModel: ifd.alpha ? 'RGBA' : 'RGB',
|
|
76
80
|
meta: getMetadata(ifd),
|
|
81
|
+
resolution,
|
|
77
82
|
});
|
|
78
83
|
}
|
|
79
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Gets image resolution from its metadata and converts it into Pixels per meter, when it's possible. Also keeps original resolution values and units.
|
|
87
|
+
* @param ifd - Tiff metadata.
|
|
88
|
+
* @returns Resolution object.
|
|
89
|
+
*/
|
|
90
|
+
function getTiffResolution(ifd) {
|
|
91
|
+
if (!ifd.xResolution || !ifd.yResolution) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
switch (ifd.resolutionUnit) {
|
|
95
|
+
case 1:
|
|
96
|
+
return {
|
|
97
|
+
x: ifd.xResolution,
|
|
98
|
+
y: ifd.yResolution,
|
|
99
|
+
unit: 'unknown',
|
|
100
|
+
};
|
|
101
|
+
case 3:
|
|
102
|
+
return {
|
|
103
|
+
x: ifd.xResolution,
|
|
104
|
+
y: ifd.yResolution,
|
|
105
|
+
unit: 'centimeter',
|
|
106
|
+
};
|
|
107
|
+
default:
|
|
108
|
+
return {
|
|
109
|
+
x: ifd.xResolution,
|
|
110
|
+
y: ifd.yResolution,
|
|
111
|
+
unit: 'inch',
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
80
115
|
//# sourceMappingURL=decodeTiff.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decodeTiff.js","sourceRoot":"","sources":["../../src/load/decodeTiff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAG9B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"decodeTiff.js","sourceRoot":"","sources":["../../src/load/decodeTiff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MA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GAAG,CAAC,WAAW,EAAE,CAAC;QACzC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,QAAQ,GAAG,CAAC,cAAc,EAAE,CAAC;QAC3B,KAAK,CAAC;YACJ,OAAO;gBACL,CAAC,EAAE,GAAG,CAAC,WAAW;gBAClB,CAAC,EAAE,GAAG,CAAC,WAAW;gBAClB,IAAI,EAAE,SAAS;aAChB,CAAC;QACJ,KAAK,CAAC;YACJ,OAAO;gBACL,CAAC,EAAE,GAAG,CAAC,WAAW;gBAClB,CAAC,EAAE,GAAG,CAAC,WAAW;gBAClB,IAAI,EAAE,YAAY;aACnB,CAAC;QACJ;YACE,OAAO;gBACL,CAAC,EAAE,GAAG,CAAC,WAAW;gBAClB,CAAC,EAAE,GAAG,CAAC,WAAW;gBAClB,IAAI,EAAE,MAAM;aACb,CAAC;IACN,CAAC;AACH,CAAC"}
|
package/lib/load/load.types.d.ts
CHANGED
|
@@ -5,4 +5,10 @@ export interface ImageMetadata {
|
|
|
5
5
|
};
|
|
6
6
|
exif: Record<string, unknown>;
|
|
7
7
|
}
|
|
8
|
+
export interface Resolution {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
unit: ResolutionUnit;
|
|
12
|
+
}
|
|
13
|
+
export type ResolutionUnit = 'inch' | 'centimeter' | 'meter' | 'unknown';
|
|
8
14
|
//# sourceMappingURL=load.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.types.d.ts","sourceRoot":"","sources":["../../src/load/load.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE;QACJ,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B,CAAC;IACF,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B"}
|
|
1
|
+
{"version":3,"file":"load.types.d.ts","sourceRoot":"","sources":["../../src/load/load.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE;QACJ,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B,CAAC;IACF,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,UAAU;IACzB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,YAAY,GAAG,OAAO,GAAG,SAAS,CAAC"}
|
package/lib/load/read.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { Image } from '../Image.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function read(path: string | URL): Promise<Image>;
|
|
10
10
|
/**
|
|
11
|
-
* Synchronous version of
|
|
11
|
+
* Synchronous version of {@link read}.
|
|
12
12
|
* This method is only implemented for Node.js.
|
|
13
13
|
* @param path - The path to the image.
|
|
14
14
|
* @returns Image instance.
|
package/lib/load/read.js
CHANGED
|
@@ -13,7 +13,7 @@ export async function read(path) {
|
|
|
13
13
|
return decode(data);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Synchronous version of
|
|
16
|
+
* Synchronous version of {@link read}.
|
|
17
17
|
* This method is only implemented for Node.js.
|
|
18
18
|
* @param path - The path to the image.
|
|
19
19
|
* @returns Image instance.
|
package/lib/save/write.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export declare function write(path: string | URL, image: Image | Mask, options:
|
|
|
52
52
|
*/
|
|
53
53
|
export declare function write(path: string | URL, image: Mask, options?: WriteOptionsBmp): Promise<void>;
|
|
54
54
|
/**
|
|
55
|
-
* Synchronous version of
|
|
55
|
+
* Synchronous version of {@link write}.
|
|
56
56
|
* This method is only implemented for Node.js.
|
|
57
57
|
* @param path - Path where the image should be written.
|
|
58
58
|
* @param image - Image to save.
|
package/lib/save/write.js
CHANGED
|
@@ -24,7 +24,7 @@ export async function write(path, image, options) {
|
|
|
24
24
|
await nodeApi.fs.promises.writeFile(path, toWrite);
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* Synchronous version of
|
|
27
|
+
* Synchronous version of {@link write}.
|
|
28
28
|
* This method is only implemented for Node.js.
|
|
29
29
|
* @param path - Path where the image should be written.
|
|
30
30
|
* @param image - Image to save.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CanvasRenderingContext2D as SkiaCanvasRenderingContext2D } from 'skia-canvas';
|
|
1
2
|
/**
|
|
2
3
|
* Returns builtin Node.js modules or throws an error saying that the method is only implemented in Node.js.
|
|
3
4
|
* @param methodName - Name of the method that calls this function
|
|
@@ -8,4 +9,11 @@ export declare function getNodeApiOrThrow(methodName: string): {
|
|
|
8
9
|
path: import("path").PlatformPath;
|
|
9
10
|
url: typeof import("node:url");
|
|
10
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Returns a 2D canvas context for rendering on the browser or Node.js.
|
|
14
|
+
* @param width - Width of the canvas.
|
|
15
|
+
* @param height - Height of the canvas.
|
|
16
|
+
* @returns The initialised canvas context.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getCanvasContext(width: number, height: number): OffscreenCanvasRenderingContext2D | SkiaCanvasRenderingContext2D;
|
|
11
19
|
//# sourceMappingURL=cross_platform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cross_platform.d.ts","sourceRoot":"","sources":["../../src/utils/cross_platform.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM;;;;
|
|
1
|
+
{"version":3,"file":"cross_platform.d.ts","sourceRoot":"","sources":["../../src/utils/cross_platform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,wBAAwB,IAAI,4BAA4B,EACzD,MAAM,aAAa,CAAC;AAErB;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM;;;;EASnD;AAKD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,iCAAiC,GAAG,4BAA4B,CAYlE"}
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* @returns - The `fs`, `path` and `url` Node.js modules.
|
|
5
5
|
*/
|
|
6
6
|
export function getNodeApiOrThrow(methodName) {
|
|
7
|
-
if (
|
|
8
|
-
typeof process.getBuiltinModule !== 'function') {
|
|
7
|
+
if (!isNode()) {
|
|
9
8
|
throw new Error(`${methodName} is only implemented for Node.js`);
|
|
10
9
|
}
|
|
11
10
|
return {
|
|
@@ -14,4 +13,37 @@ export function getNodeApiOrThrow(methodName) {
|
|
|
14
13
|
url: process.getBuiltinModule('node:url'),
|
|
15
14
|
};
|
|
16
15
|
}
|
|
16
|
+
let CanvasCtorBrowser;
|
|
17
|
+
let CanvasCtorNode;
|
|
18
|
+
/**
|
|
19
|
+
* Returns a 2D canvas context for rendering on the browser or Node.js.
|
|
20
|
+
* @param width - Width of the canvas.
|
|
21
|
+
* @param height - Height of the canvas.
|
|
22
|
+
* @returns The initialised canvas context.
|
|
23
|
+
*/
|
|
24
|
+
export function getCanvasContext(width, height) {
|
|
25
|
+
if (isNode()) {
|
|
26
|
+
CanvasCtorNode ??= getRequireFn()('skia-canvas').Canvas;
|
|
27
|
+
return new CanvasCtorNode(width, height).getContext('2d');
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
CanvasCtorBrowser ??= globalThis.OffscreenCanvas;
|
|
31
|
+
const context = new CanvasCtorBrowser(width, height).getContext('2d');
|
|
32
|
+
if (!context) {
|
|
33
|
+
throw new Error('Failed to create canvas context');
|
|
34
|
+
}
|
|
35
|
+
return context;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function isNode() {
|
|
39
|
+
return (typeof process !== 'undefined' &&
|
|
40
|
+
typeof process.getBuiltinModule === 'function');
|
|
41
|
+
}
|
|
42
|
+
let requireFn;
|
|
43
|
+
function getRequireFn() {
|
|
44
|
+
requireFn ??= process
|
|
45
|
+
.getBuiltinModule('node:module')
|
|
46
|
+
.createRequire(import.meta.url);
|
|
47
|
+
return requireFn;
|
|
48
|
+
}
|
|
17
49
|
//# sourceMappingURL=cross_platform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cross_platform.js","sourceRoot":"","sources":["../../src/utils/cross_platform.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cross_platform.js","sourceRoot":"","sources":["../../src/utils/cross_platform.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,kCAAkC,CAAC,CAAC;IACnE,CAAC;IACD,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC;QACvC,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC;QAC3C,GAAG,EAAE,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC;KAC1C,CAAC;AACJ,CAAC;AAED,IAAI,iBAAyC,CAAC;AAC9C,IAAI,cAAiC,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAa,EACb,MAAc;IAEd,IAAI,MAAM,EAAE,EAAE,CAAC;QACb,cAAc,KAAK,YAAY,EAAE,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC;QACxD,OAAO,IAAI,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC;SAAM,CAAC;QACN,iBAAiB,KAAK,UAAU,CAAC,eAAe,CAAC;QACjD,MAAM,OAAO,GAAG,IAAI,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACtE,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAED,SAAS,MAAM;IACb,OAAO,CACL,OAAO,OAAO,KAAK,WAAW;QAC9B,OAAO,OAAO,CAAC,gBAAgB,KAAK,UAAU,CAC/C,CAAC;AACJ,CAAC;AAED,IAAI,SAAyB,CAAC;AAC9B,SAAS,YAAY;IACnB,SAAS,KAAK,OAAO;SAClB,gBAAgB,CAAC,aAAa,CAAC;SAC/B,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -5,7 +5,7 @@ import type { Mask } from '../Mask.js';
|
|
|
5
5
|
* @param image - The image with which to blend.
|
|
6
6
|
* @param column - Column of the target pixel.
|
|
7
7
|
* @param row - Row of the target pixel.
|
|
8
|
-
* @param color - Color with which to blend the image pixel.
|
|
8
|
+
* @param color - Color with which to blend the image pixel. Default: `Opaque black`.
|
|
9
9
|
*/
|
|
10
10
|
export declare function setBlendedPixel(image: Image | Mask, column: number, row: number, color?: number[]): void;
|
|
11
11
|
//# sourceMappingURL=setBlendedPixel.d.ts.map
|
|
@@ -6,7 +6,7 @@ import { assert } from './validators/assert.js';
|
|
|
6
6
|
* @param image - The image with which to blend.
|
|
7
7
|
* @param column - Column of the target pixel.
|
|
8
8
|
* @param row - Row of the target pixel.
|
|
9
|
-
* @param color - Color with which to blend the image pixel.
|
|
9
|
+
* @param color - Color with which to blend the image pixel. Default: `Opaque black`.
|
|
10
10
|
*/
|
|
11
11
|
export function setBlendedPixel(image, column, row, color) {
|
|
12
12
|
color = color ?? getDefaultColor(image);
|
|
@@ -5,7 +5,7 @@ import type { Mask } from '../Mask.js';
|
|
|
5
5
|
* @param image - The image with which to blend.
|
|
6
6
|
* @param column - Column of the target pixel.
|
|
7
7
|
* @param row - Row of the target pixel.
|
|
8
|
-
* @param color - Color with which to blend the image pixel.
|
|
8
|
+
* @param color - Color with which to blend the image pixel. Default: `Opaque black`.
|
|
9
9
|
*/
|
|
10
10
|
export declare function setBlendedVisiblePixel(image: Image | Mask, column: number, row: number, color?: number[]): void;
|
|
11
11
|
//# sourceMappingURL=setBlendedVisiblePixel.d.ts.map
|
|
@@ -4,7 +4,7 @@ import { setBlendedPixel } from './setBlendedPixel.js';
|
|
|
4
4
|
* @param image - The image with which to blend.
|
|
5
5
|
* @param column - Column of the target pixel.
|
|
6
6
|
* @param row - Row of the target pixel.
|
|
7
|
-
* @param color - Color with which to blend the image pixel.
|
|
7
|
+
* @param color - Color with which to blend the image pixel. Default: `Opaque black`.
|
|
8
8
|
*/
|
|
9
9
|
export function setBlendedVisiblePixel(image, column, row, color) {
|
|
10
10
|
if (column >= 0 && column < image.width && row >= 0 && row < image.height) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "image-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Image processing and manipulation in JavaScript",
|
|
6
6
|
"author": "Michaël Zasso",
|
|
@@ -12,15 +12,18 @@
|
|
|
12
12
|
"lib",
|
|
13
13
|
"src"
|
|
14
14
|
],
|
|
15
|
+
"types": "./lib/index.d.ts",
|
|
15
16
|
"exports": {
|
|
16
17
|
".": "./lib/index.js",
|
|
17
|
-
"./
|
|
18
|
+
"./full": "./lib/index_full.js",
|
|
19
|
+
"./draw": "./lib/extra/draw/index.js",
|
|
20
|
+
"./ssim": "./lib/extra/ssim/index.js"
|
|
18
21
|
},
|
|
19
22
|
"scripts": {
|
|
20
23
|
"api-extractor": "rimraf dist-types && api-extractor run --local",
|
|
21
24
|
"build": "npm run tsc && npm run cheminfo-build",
|
|
22
25
|
"check-types": "tsc --noEmit",
|
|
23
|
-
"cheminfo-build": "cheminfo-build --entry lib/
|
|
26
|
+
"cheminfo-build": "cheminfo-build --entry lib/index_browser.js --root IJS",
|
|
24
27
|
"clean": "rimraf coverage dist dist-types lib",
|
|
25
28
|
"demo": "vite --open",
|
|
26
29
|
"eslint": "eslint . --cache",
|
|
@@ -51,12 +54,22 @@
|
|
|
51
54
|
"ml-regression-polynomial-2d": "^1.0.0",
|
|
52
55
|
"ml-spectra-processing": "^14.18.0",
|
|
53
56
|
"robust-point-in-polygon": "^1.0.3",
|
|
57
|
+
"skia-canvas": "^3.0.8",
|
|
54
58
|
"ssim.js": "^3.5.0",
|
|
55
59
|
"tiff": "^7.1.2",
|
|
56
60
|
"ts-pattern": "^5.9.0",
|
|
57
61
|
"uint8-base64": "^1.0.0"
|
|
58
62
|
},
|
|
63
|
+
"lavamoat": {
|
|
64
|
+
"allowScripts": {
|
|
65
|
+
"@lavamoat/preinstall-always-fail": false,
|
|
66
|
+
"skia-canvas": true,
|
|
67
|
+
"vite>esbuild": false
|
|
68
|
+
}
|
|
69
|
+
},
|
|
59
70
|
"devDependencies": {
|
|
71
|
+
"@lavamoat/allow-scripts": "^3.4.0",
|
|
72
|
+
"@lavamoat/preinstall-always-fail": "^2.1.1",
|
|
60
73
|
"@microsoft/api-extractor": "^7.53.3",
|
|
61
74
|
"@tailwindcss/forms": "^0.5.10",
|
|
62
75
|
"@tailwindcss/vite": "^4.1.16",
|
|
@@ -66,6 +79,7 @@
|
|
|
66
79
|
"@types/react": "^19.2.2",
|
|
67
80
|
"@types/react-dom": "^19.2.2",
|
|
68
81
|
"@types/robust-point-in-polygon": "^1.0.4",
|
|
82
|
+
"@types/skia-canvas": "^0.9.2",
|
|
69
83
|
"@vitejs/plugin-react": "^5.1.0",
|
|
70
84
|
"@vitest/coverage-v8": "^4.0.6",
|
|
71
85
|
"@vitest/expect": "^4.0.6",
|
package/src/Image.ts
CHANGED
|
@@ -78,7 +78,7 @@ import {
|
|
|
78
78
|
transform,
|
|
79
79
|
transformRotate,
|
|
80
80
|
} from './geometry/index.js';
|
|
81
|
-
import type { ImageMetadata } from './load/load.types.js';
|
|
81
|
+
import type { ImageMetadata, Resolution } from './load/load.types.js';
|
|
82
82
|
import type {
|
|
83
83
|
BottomHatOptions,
|
|
84
84
|
CannyEdgeOptions,
|
|
@@ -173,6 +173,10 @@ export interface ImageOptions {
|
|
|
173
173
|
* @default `{row: 0, column: 0}`
|
|
174
174
|
*/
|
|
175
175
|
origin?: Point;
|
|
176
|
+
/**
|
|
177
|
+
* Original resolution decoded from the image.
|
|
178
|
+
*/
|
|
179
|
+
resolution?: Resolution;
|
|
176
180
|
|
|
177
181
|
meta?: ImageMetadata;
|
|
178
182
|
}
|
|
@@ -235,8 +239,12 @@ export class Image {
|
|
|
235
239
|
*/
|
|
236
240
|
public readonly origin: Point;
|
|
237
241
|
|
|
238
|
-
|
|
242
|
+
/**
|
|
243
|
+
* Original image resolution.
|
|
244
|
+
*/
|
|
245
|
+
public readonly originalResolution: Resolution | undefined;
|
|
239
246
|
|
|
247
|
+
public readonly meta?: ImageMetadata;
|
|
240
248
|
/**
|
|
241
249
|
* Typed array holding the image data.
|
|
242
250
|
*/
|
|
@@ -259,6 +267,7 @@ export class Image {
|
|
|
259
267
|
colorModel = 'RGB',
|
|
260
268
|
origin = { row: 0, column: 0 },
|
|
261
269
|
meta,
|
|
270
|
+
resolution,
|
|
262
271
|
} = options;
|
|
263
272
|
|
|
264
273
|
if (width < 1 || !Number.isInteger(width)) {
|
|
@@ -280,7 +289,7 @@ export class Image {
|
|
|
280
289
|
this.colorModel = colorModel;
|
|
281
290
|
this.origin = origin;
|
|
282
291
|
this.meta = meta;
|
|
283
|
-
|
|
292
|
+
this.originalResolution = resolution;
|
|
284
293
|
const colorModelDef = colorModels[colorModel];
|
|
285
294
|
this.components = colorModelDef.components;
|
|
286
295
|
this.alpha = colorModelDef.alpha;
|
|
@@ -311,7 +320,38 @@ export class Image {
|
|
|
311
320
|
this.data = data;
|
|
312
321
|
}
|
|
313
322
|
}
|
|
314
|
-
|
|
323
|
+
/**
|
|
324
|
+
* Returns normalized resolution in pixels per centimeter. If resolution unit is unknown, return null.
|
|
325
|
+
* @returns Object with x and y resolutions in pixel/cm.
|
|
326
|
+
*/
|
|
327
|
+
get normalizedResolution() {
|
|
328
|
+
if (!this.originalResolution) {
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|
|
331
|
+
const centimetersPerInch = 2.54;
|
|
332
|
+
const centimetersPerMeter = 100;
|
|
333
|
+
switch (this.originalResolution.unit) {
|
|
334
|
+
case 'inch':
|
|
335
|
+
return {
|
|
336
|
+
x: this.originalResolution.x / centimetersPerInch,
|
|
337
|
+
y: this.originalResolution.y / centimetersPerInch,
|
|
338
|
+
};
|
|
339
|
+
case 'centimeter':
|
|
340
|
+
return {
|
|
341
|
+
x: this.originalResolution.x,
|
|
342
|
+
y: this.originalResolution.y,
|
|
343
|
+
};
|
|
344
|
+
case 'meter':
|
|
345
|
+
return {
|
|
346
|
+
x: this.originalResolution.x / centimetersPerMeter,
|
|
347
|
+
y: this.originalResolution.y / centimetersPerMeter,
|
|
348
|
+
};
|
|
349
|
+
case 'unknown':
|
|
350
|
+
return null;
|
|
351
|
+
default:
|
|
352
|
+
throw new Error('Unknown resolution unit.');
|
|
353
|
+
}
|
|
354
|
+
}
|
|
315
355
|
/**
|
|
316
356
|
* Create a new Image based on the properties of an existing one.
|
|
317
357
|
* @param other - Reference image.
|