image-js 1.1.0 → 1.2.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.
Files changed (74) hide show
  1. package/dist/image-js.esm.js +176 -48
  2. package/dist/image-js.esm.js.map +1 -1
  3. package/dist/image-js.esm.min.js +2 -2
  4. package/dist/image-js.esm.min.js.map +1 -1
  5. package/dist/image-js.umd.js +144 -14
  6. package/dist/image-js.umd.js.map +1 -1
  7. package/dist/image-js.umd.min.js +2 -2
  8. package/dist/image-js.umd.min.js.map +1 -1
  9. package/dist-types/image-js.d.ts +2 -2
  10. package/lib/draw/drawLineOnImage.d.ts.map +1 -1
  11. package/lib/draw/drawLineOnImage.js.map +1 -1
  12. package/lib/extra/draw/draw_text.d.ts +47 -0
  13. package/lib/extra/draw/draw_text.d.ts.map +1 -0
  14. package/lib/extra/draw/draw_text.js +108 -0
  15. package/lib/extra/draw/draw_text.js.map +1 -0
  16. package/lib/extra/draw/index.d.ts +3 -0
  17. package/lib/extra/draw/index.d.ts.map +1 -0
  18. package/lib/extra/draw/index.js +3 -0
  19. package/lib/extra/draw/index.js.map +1 -0
  20. package/lib/{ssim → extra/ssim}/compute_dssim.d.ts +2 -2
  21. package/lib/extra/ssim/compute_dssim.d.ts.map +1 -0
  22. package/lib/{ssim → extra/ssim}/compute_dssim.js +1 -1
  23. package/lib/extra/ssim/compute_dssim.js.map +1 -0
  24. package/lib/{ssim → extra/ssim}/compute_ssim.d.ts +1 -1
  25. package/lib/extra/ssim/compute_ssim.d.ts.map +1 -0
  26. package/lib/{ssim → extra/ssim}/compute_ssim.js +2 -2
  27. package/lib/extra/ssim/compute_ssim.js.map +1 -0
  28. package/lib/extra/ssim/index.d.ts +3 -0
  29. package/lib/extra/ssim/index.d.ts.map +1 -0
  30. package/lib/extra/ssim/index.js +3 -0
  31. package/lib/extra/ssim/index.js.map +1 -0
  32. package/lib/index_browser.d.ts +3 -0
  33. package/lib/index_browser.d.ts.map +1 -0
  34. package/lib/index_browser.js +5 -0
  35. package/lib/index_browser.js.map +1 -0
  36. package/lib/index_full.d.ts +4 -0
  37. package/lib/index_full.d.ts.map +1 -0
  38. package/lib/index_full.js +5 -0
  39. package/lib/index_full.js.map +1 -0
  40. package/lib/load/read.d.ts +1 -1
  41. package/lib/load/read.js +1 -1
  42. package/lib/save/write.d.ts +1 -1
  43. package/lib/save/write.js +1 -1
  44. package/lib/utils/cross_platform.d.ts +8 -0
  45. package/lib/utils/cross_platform.d.ts.map +1 -1
  46. package/lib/utils/cross_platform.js +34 -2
  47. package/lib/utils/cross_platform.js.map +1 -1
  48. package/lib/utils/setBlendedPixel.d.ts +1 -1
  49. package/lib/utils/setBlendedPixel.js +1 -1
  50. package/lib/utils/setBlendedVisiblePixel.d.ts +1 -1
  51. package/lib/utils/setBlendedVisiblePixel.js +1 -1
  52. package/package.json +17 -3
  53. package/src/draw/drawLineOnImage.ts +0 -1
  54. package/src/extra/draw/draw_text.ts +194 -0
  55. package/src/extra/draw/index.ts +2 -0
  56. package/src/{ssim → extra/ssim}/compute_dssim.ts +3 -3
  57. package/src/{ssim → extra/ssim}/compute_ssim.ts +3 -3
  58. package/src/extra/ssim/index.ts +2 -0
  59. package/src/index_browser.ts +4 -0
  60. package/src/index_full.ts +4 -0
  61. package/src/load/read.ts +1 -1
  62. package/src/save/write.ts +1 -1
  63. package/src/utils/cross_platform.ts +47 -4
  64. package/src/utils/setBlendedPixel.ts +1 -1
  65. package/src/utils/setBlendedVisiblePixel.ts +1 -1
  66. package/lib/ssim/compute_dssim.d.ts.map +0 -1
  67. package/lib/ssim/compute_dssim.js.map +0 -1
  68. package/lib/ssim/compute_ssim.d.ts.map +0 -1
  69. package/lib/ssim/compute_ssim.js.map +0 -1
  70. package/lib/ssim/index.d.ts +0 -3
  71. package/lib/ssim/index.d.ts.map +0 -1
  72. package/lib/ssim/index.js +0 -3
  73. package/lib/ssim/index.js.map +0 -1
  74. package/src/ssim/index.ts +0 -2
@@ -3392,7 +3392,7 @@ export declare function readCanvas(canvas: HTMLCanvasElement): Image_2;
3392
3392
  export declare function readImg(img: Extract<CanvasImageSource, Record<'width' | 'height', number>>): Image_2;
3393
3393
 
3394
3394
  /**
3395
- * Synchronous version of @see {@link read}.
3395
+ * Synchronous version of {@link read}.
3396
3396
  * This method is only implemented for Node.js.
3397
3397
  * @param path - The path to the image.
3398
3398
  * @returns Image instance.
@@ -4248,7 +4248,7 @@ export declare type WriteOptionsJpeg = WriteOptions & EncodeOptionsJpeg;
4248
4248
  export declare type WriteOptionsPng = WriteOptions & EncodeOptionsPng;
4249
4249
 
4250
4250
  /**
4251
- * Synchronous version of @see {@link write}.
4251
+ * Synchronous version of {@link write}.
4252
4252
  * This method is only implemented for Node.js.
4253
4253
  * @param path - Path where the image should be written.
4254
4254
  * @param image - Image to save.
@@ -1 +1 @@
1
- {"version":3,"file":"drawLineOnImage.d.ts","sourceRoot":"","sources":["../../src/draw/drawLineOnImage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAOzD,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB;;;OAGG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC;IACf;;OAEG;IACH,GAAG,CAAC,EAAE,KAAK,CAAC;CACb;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,KAAK,EACX,EAAE,EAAE,KAAK,EACT,OAAO,GAAE,sBAA2B,GACnC,KAAK,CAuBP"}
1
+ {"version":3,"file":"drawLineOnImage.d.ts","sourceRoot":"","sources":["../../src/draw/drawLineOnImage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE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GAAG,EAAE,CAAC,EAAE,GAC/B,GAAG,OAAO,CAAC;IAEZ,aAAa,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAErC,gBAAgB,CAAC,QAAQ,EAAE;QACzB,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;KAClB,CAAC,CAAC;IACH,IAAI,CACF,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,EACvC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,EACjC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC,EACrC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAC/B,CAAC,MAAc,EAAE,GAAW,EAAE,EAAE;QAC9B,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;IAC7D,CAAC,CACF,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { Image } from '../../Image.ts';
2
+ import type { Point } from '../../geometry/index.ts';
3
+ export interface DrawTextLabel {
4
+ /**
5
+ * Text of the label.
6
+ */
7
+ content: number | string;
8
+ /**
9
+ * Position to draw the label at.
10
+ */
11
+ position: Point;
12
+ /**
13
+ * Size and type of font.
14
+ * If specified, this overrides the general font from DrawTextOptions.
15
+ */
16
+ font?: string;
17
+ /**
18
+ * Font color. Should be in rgba8 format.
19
+ * If specified, this overrides the general fontColor from DrawTextOptions.
20
+ */
21
+ fontColor?: number[];
22
+ }
23
+ export interface DrawTextOptions {
24
+ /**
25
+ * General size and type of font.
26
+ * Used as the default when font is not specified in individual text labels.
27
+ */
28
+ font?: string;
29
+ /**
30
+ * General font color.
31
+ * Used as the default when fontColor is not specified in individual text labels.
32
+ */
33
+ fontColor?: number[];
34
+ /**
35
+ * Image to which the resulting image has to be put.
36
+ */
37
+ out?: Image;
38
+ }
39
+ /**
40
+ * Draws text on an image.
41
+ * @param image - Image to write text on.
42
+ * @param text - Text to write on the image.
43
+ * @param options - Out Options
44
+ * @returns Image with drawn text.
45
+ */
46
+ export declare function drawText(image: Image, text: DrawTextLabel | DrawTextLabel[], options?: DrawTextOptions): Image;
47
+ //# sourceMappingURL=draw_text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draw_text.d.ts","sourceRoot":"","sources":["../../../src/extra/draw/draw_text.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAkB,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAKrD,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC;IAChB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;OAEG;IACH,GAAG,CAAC,EAAE,KAAK,CAAC;CACb;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,aAAa,GAAG,aAAa,EAAE,EACrC,OAAO,CAAC,EAAE,eAAe,SA2B1B"}
@@ -0,0 +1,108 @@
1
+ import { getCanvasContext } from "../../utils/cross_platform.js";
2
+ import { getOutputImage } from "../../utils/getOutputImage.js";
3
+ import { validateValues } from "../../utils/validators/validators.js";
4
+ /**
5
+ * Draws text on an image.
6
+ * @param image - Image to write text on.
7
+ * @param text - Text to write on the image.
8
+ * @param options - Out Options
9
+ * @returns Image with drawn text.
10
+ */
11
+ export function drawText(image, text, options) {
12
+ if (Array.isArray(text) && text.length === 0) {
13
+ throw new Error('At least one text element must be provided');
14
+ }
15
+ const newImage = getOutputImage(image, options, { clone: true });
16
+ const defaultFont = options?.font ?? '12px Helvetica';
17
+ const defaultColor = options?.fontColor ?? [255, 255, 255, 255];
18
+ const ctx = getCanvasContext(image.width, image.height);
19
+ if (!Array.isArray(text)) {
20
+ drawTextElement(image, ctx, text, defaultFont, defaultColor);
21
+ }
22
+ else {
23
+ for (const label of text) {
24
+ drawTextElement(image, ctx, label, defaultFont, defaultColor);
25
+ }
26
+ }
27
+ layerCanvas(newImage.getRawImage().data, ctx.getImageData(0, 0, image.width, image.height).data, image.channels, image.bitDepth);
28
+ return newImage;
29
+ }
30
+ function drawTextElement(image, ctx, text, defaultFont, defaultColor) {
31
+ ctx.font = text.font ?? defaultFont;
32
+ const fontColor = text.fontColor ?? defaultColor;
33
+ validateValues(fontColor, image);
34
+ const alpha = fontColor[3] ? fontColor[3] / 255 : 1;
35
+ const normalizedColor = [
36
+ fontColor[0] ?? 0,
37
+ fontColor[1] ?? 0,
38
+ fontColor[2] ?? 0,
39
+ alpha,
40
+ ];
41
+ ctx.fillStyle = `rgba(${normalizedColor.join(',')})`;
42
+ ctx.fillText(String(text.content), text.position.column, text.position.row);
43
+ }
44
+ /**
45
+ * Draws labels on the image data from canvas.
46
+ * @param imageData - Image data to draw text on.
47
+ * @param canvasData - Canvas data to draw on the image.
48
+ * @param numberOfChannels - Number of channels of the initial image.
49
+ * @param bitDepth - Bit depth of the initial image.
50
+ */
51
+ function layerCanvas(imageData, canvasData, numberOfChannels, bitDepth) {
52
+ const config = CHANNEL_CONFIGS[numberOfChannels] || CHANNEL_CONFIGS[1];
53
+ const pixelCount = canvasData.length >>> 2;
54
+ const bitShift = bitDepth - 8;
55
+ let imageIndex = 0;
56
+ let canvasIndex = 0;
57
+ for (let pixel = 0; pixel < pixelCount; pixel++) {
58
+ const canvasAlpha = canvasData[canvasIndex + 3] / 255;
59
+ // Skip transparent canvas pixels completely
60
+ if (canvasAlpha === 0) {
61
+ imageIndex += numberOfChannels;
62
+ canvasIndex += 4;
63
+ continue;
64
+ }
65
+ const invAlpha = 1 - canvasAlpha;
66
+ for (const channel of config.channelOffsets) {
67
+ const targetIndex = imageIndex + channel;
68
+ imageData[targetIndex] =
69
+ Math.round(canvasData[canvasIndex + channel] * canvasAlpha +
70
+ imageData[targetIndex] * invAlpha) << bitShift;
71
+ }
72
+ if (config.hasAlpha) {
73
+ const alphaIndex = imageIndex + config.alphaOffset;
74
+ const imageAlpha = (imageData[alphaIndex] >>> bitShift) / 255;
75
+ const newAlpha = canvasAlpha + imageAlpha * (1 - canvasAlpha);
76
+ imageData[alphaIndex] = Math.round(newAlpha * 255) << bitShift;
77
+ }
78
+ imageIndex += numberOfChannels;
79
+ canvasIndex += 4;
80
+ }
81
+ }
82
+ const CHANNEL_CONFIGS = {
83
+ // GREY
84
+ 1: {
85
+ channelOffsets: [0],
86
+ hasAlpha: false,
87
+ alphaOffset: undefined,
88
+ },
89
+ // GREYA
90
+ 2: {
91
+ channelOffsets: [0],
92
+ hasAlpha: true,
93
+ alphaOffset: 1,
94
+ },
95
+ 3: {
96
+ // RGB
97
+ channelOffsets: [0, 1, 2],
98
+ hasAlpha: false,
99
+ alphaOffset: undefined,
100
+ },
101
+ 4: {
102
+ // RGBA
103
+ channelOffsets: [0, 1, 2],
104
+ hasAlpha: true,
105
+ alphaOffset: 3,
106
+ },
107
+ };
108
+ //# sourceMappingURL=draw_text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draw_text.js","sourceRoot":"","sources":["../../../src/extra/draw/draw_text.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAA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ACD,QAAQ;IACR,CAAC,EAAE;QACD,cAAc,EAAE,CAAC,CAAC,CAAC;QACnB,QAAQ,EAAE,IAAI;QACd,WAAW,EAAE,CAAC;KACf;IACD,CAAC,EAAE;QACD,MAAM;QACN,cAAc,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACzB,QAAQ,EAAE,KAAK;QACf,WAAW,EAAE,SAAS;KACvB;IACD,CAAC,EAAE;QACD,OAAO;QACP,cAAc,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACzB,QAAQ,EAAE,IAAI;QACd,WAAW,EAAE,CAAC;KACf;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './draw_text.ts';
2
+ export * from '../../draw/index.ts';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extra/draw/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./draw_text.js";
2
+ export * from "../../draw/index.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extra/draw/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC"}
@@ -1,5 +1,5 @@
1
- import type { Image } from '../Image.js';
2
- import type { SsimOptions } from './compute_ssim.js';
1
+ import type { Image } from '../../Image.ts';
2
+ import type { SsimOptions } from './compute_ssim.ts';
3
3
  /**
4
4
  * Compute the Structural Dissimilarity (DSSIM) of two GREY images.
5
5
  * @see {@link https://en.wikipedia.org/wiki/Structural_similarity}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute_dssim.d.ts","sourceRoot":"","sources":["../../../src/extra/ssim/compute_dssim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,KAAK,EACjB,OAAO,GAAE,WAAgB,GACxB,MAAM,CAGR"}
@@ -1,4 +1,4 @@
1
- import { computeSsim } from './compute_ssim.js';
1
+ import { computeSsim } from "./compute_ssim.js";
2
2
  /**
3
3
  * Compute the Structural Dissimilarity (DSSIM) of two GREY images.
4
4
  * @see {@link https://en.wikipedia.org/wiki/Structural_similarity}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute_dssim.js","sourceRoot":"","sources":["../../../src/extra/ssim/compute_dssim.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAY,EACZ,UAAiB,EACjB,UAAuB,EAAE;IAEzB,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC;IAC3D,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { Image } from '../Image.js';
1
+ import type { Image } from '../../Image.ts';
2
2
  export interface SsimOptions {
3
3
  /**
4
4
  * Window size for SSIM map.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute_ssim.d.ts","sourceRoot":"","sources":["../../../src/extra/ssim/compute_ssim.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAI5C,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC;CACzD;AAED,MAAM,WAAW,IAAI;IACnB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,KAAK,EACjB,OAAO,GAAE,WAAgB,GACxB,IAAI,CA8CN"}
@@ -1,6 +1,6 @@
1
1
  import { ssim as bufferSsim } from 'ssim.js';
2
- import checkProcessable from '../utils/validators/checkProcessable.js';
3
- import { validateForComparison } from '../utils/validators/validators.js';
2
+ import checkProcessable from "../../utils/validators/checkProcessable.js";
3
+ import { validateForComparison } from "../../utils/validators/validators.js";
4
4
  /**
5
5
  * Compute the Structural Similarity (SSIM) of two RGBA or two GREY images.
6
6
  * "The resultant SSIM index is a decimal value between -1 and 1,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute_ssim.js","sourceRoot":"","sources":["../../../src/extra/ssim/compute_ssim.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAG7C,OAAO,gBAAgB,MAAM,4CAA4C,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AA4B7E;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CACzB,KAAY,EACZ,UAAiB,EACjB,UAAuB,EAAE;IAEzB,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,EAAE,SAAS,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;IAE3C,IAAI,UAAU,EAAE,CAAC;QACf,IAAI,UAAU,GAAG,KAAK,CAAC,KAAK,IAAI,UAAU,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;YA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Q;KACvB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './compute_dssim.ts';
2
+ export * from './compute_ssim.ts';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extra/ssim/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./compute_dssim.js";
2
+ export * from "./compute_ssim.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extra/ssim/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './index.ts';
2
+ export * from './extra/draw/index.ts';
3
+ //# sourceMappingURL=index_browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index_browser.d.ts","sourceRoot":"","sources":["../src/index_browser.ts"],"names":[],"mappings":"AAEA,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,5 @@
1
+ // API for the browser build.
2
+ // TODO: figure out how to bundle the SSIM library. Then we can just use `index_full.ts` instead.
3
+ export * from "./index.js";
4
+ export * from "./extra/draw/index.js";
5
+ //# sourceMappingURL=index_browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index_browser.js","sourceRoot":"","sources":["../src/index_browser.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,iGAAiG;AACjG,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './index.ts';
2
+ export * from './extra/draw/index.ts';
3
+ export * from './extra/ssim/index.ts';
4
+ //# sourceMappingURL=index_full.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index_full.d.ts","sourceRoot":"","sources":["../src/index_full.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,5 @@
1
+ // Full API.
2
+ export * from "./index.js";
3
+ export * from "./extra/draw/index.js";
4
+ export * from "./extra/ssim/index.js";
5
+ //# sourceMappingURL=index_full.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index_full.js","sourceRoot":"","sources":["../src/index_full.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
@@ -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 @see {@link read}.
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 @see {@link read}.
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.
@@ -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 @see {@link write}.
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 @see {@link write}.
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;;;;EAYnD"}
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 (typeof process === 'undefined' ||
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":"AAAA;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,IACE,OAAO,OAAO,KAAK,WAAW;QAC9B,OAAO,OAAO,CAAC,gBAAgB,KAAK,UAAU,EAC9C,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,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U,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. @default `'Opaque black'`.
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. @default `'Opaque black'`.
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. @default `'Opaque black'`.
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. @default `'Opaque black'`.
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.1.0",
3
+ "version": "1.2.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
- "./ssim": "./lib/ssim/index.js"
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/index.js --root IJS",
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",
@@ -50,7 +50,6 @@ export function drawLineOnImage(
50
50
  checkProcessable(newImage, {
51
51
  bitDepth: [8, 16],
52
52
  });
53
-
54
53
  line(
55
54
  Math.round(origin.column + from.column),
56
55
  Math.round(origin.row + from.row),