@blazediff/bin 1.4.1 → 1.6.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.
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/commands/msssim.ts
32
+ var msssim_exports = {};
33
+ __export(msssim_exports, {
34
+ default: () => main
35
+ });
36
+ module.exports = __toCommonJS(msssim_exports);
37
+ var import_msssim = __toESM(require("@blazediff/ssim/msssim"));
38
+ function printUsage() {
39
+ console.log(`
40
+ Usage: blazediff msssim <image1> <image2> [options]
41
+
42
+ Arguments:
43
+ image1 Path to the first image
44
+ image2 Path to the second image
45
+
46
+ Options:
47
+ -o, --output <path> Output path for MS-SSIM map visualization
48
+ --transformer <name> Specify transformer to use (e.g. pngjs, sharp)
49
+ -h, --help Show this help message
50
+
51
+ Examples:
52
+ blazediff msssim image1.png image2.png
53
+ blazediff msssim image1.png image2.png -o msssim-map.png
54
+ `);
55
+ }
56
+ var getTransformer = async (transformer) => {
57
+ if (!transformer || transformer === "pngjs") {
58
+ const { default: transformer2 } = await import("@blazediff/pngjs-transformer");
59
+ return transformer2;
60
+ }
61
+ if (transformer === "sharp") {
62
+ const { default: transformer2 } = await import("@blazediff/sharp-transformer");
63
+ return transformer2;
64
+ }
65
+ throw new Error(`Unknown transformer: ${transformer}`);
66
+ };
67
+ async function main() {
68
+ try {
69
+ const args = process.argv.slice(2);
70
+ if (args.length === 0 || args.includes("-h") || args.includes("--help")) {
71
+ printUsage();
72
+ process.exit(0);
73
+ }
74
+ if (args.length < 2) {
75
+ console.error("Error: Two image paths are required");
76
+ printUsage();
77
+ process.exit(1);
78
+ }
79
+ const image1 = args[0];
80
+ const image2 = args[1];
81
+ const options = {};
82
+ for (let i = 2; i < args.length; i++) {
83
+ const arg = args[i];
84
+ const nextArg = args[i + 1];
85
+ switch (arg) {
86
+ case "-o":
87
+ case "--output":
88
+ if (nextArg) {
89
+ options.outputPath = nextArg;
90
+ i++;
91
+ }
92
+ break;
93
+ case "--transformer":
94
+ if (nextArg) {
95
+ options.transformer = nextArg;
96
+ i++;
97
+ }
98
+ break;
99
+ default:
100
+ console.error(`Unknown option: ${arg}`);
101
+ printUsage();
102
+ process.exit(1);
103
+ }
104
+ }
105
+ const transformer = await getTransformer(options.transformer);
106
+ const [img1, img2] = await Promise.all([
107
+ transformer.transform(image1),
108
+ transformer.transform(image2)
109
+ ]);
110
+ if (img1.width !== img2.width || img1.height !== img2.height) {
111
+ throw new Error(
112
+ `Image dimensions do not match: ${img1.width}x${img1.height} vs ${img2.width}x${img2.height}`
113
+ );
114
+ }
115
+ let outputData;
116
+ if (options.outputPath) {
117
+ outputData = new Uint8Array(img1.data.length);
118
+ }
119
+ const startTime = performance.now();
120
+ const score = (0, import_msssim.default)(img1.data, img2.data, outputData, img1.width, img1.height, {});
121
+ const duration = performance.now() - startTime;
122
+ if (options.outputPath && outputData) {
123
+ await transformer.write(
124
+ {
125
+ data: outputData,
126
+ width: img1.width,
127
+ height: img1.height
128
+ },
129
+ options.outputPath
130
+ );
131
+ }
132
+ const result = {
133
+ score,
134
+ width: img1.width,
135
+ height: img1.height,
136
+ duration
137
+ };
138
+ console.log(`completed in: ${result.duration.toFixed(2)}ms`);
139
+ console.log(`dimensions: ${result.width}x${result.height}`);
140
+ console.log(
141
+ `MS-SSIM score: ${result.score.toFixed(6)} (0=different, 1=identical)`
142
+ );
143
+ console.log(`similarity: ${(result.score * 100).toFixed(2)}%`);
144
+ if (options.outputPath && outputData) {
145
+ console.log(`MS-SSIM map saved to: ${options.outputPath}`);
146
+ }
147
+ if (result.score < 0.95) {
148
+ process.exit(1);
149
+ } else {
150
+ console.log(`Images are highly similar!`);
151
+ process.exit(0);
152
+ }
153
+ } catch (error) {
154
+ console.error(
155
+ "Error:",
156
+ error instanceof Error ? error.message : String(error)
157
+ );
158
+ process.exit(1);
159
+ }
160
+ }
161
+ if (typeof require !== "undefined" && require.main === module) {
162
+ main();
163
+ }
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/commands/ssim.ts
32
+ var ssim_exports = {};
33
+ __export(ssim_exports, {
34
+ default: () => main
35
+ });
36
+ module.exports = __toCommonJS(ssim_exports);
37
+ var import_ssim = __toESM(require("@blazediff/ssim/ssim"));
38
+ function printUsage() {
39
+ console.log(`
40
+ Usage: blazediff ssim <image1> <image2> [options]
41
+
42
+ Arguments:
43
+ image1 Path to the first image
44
+ image2 Path to the second image
45
+
46
+ Options:
47
+ -o, --output <path> Output path for SSIM map visualization
48
+ --transformer <name> Specify transformer to use (e.g. pngjs, sharp)
49
+ -h, --help Show this help message
50
+
51
+ Examples:
52
+ blazediff ssim image1.png image2.png
53
+ blazediff ssim image1.png image2.png -o ssim-map.png
54
+ `);
55
+ }
56
+ var getTransformer = async (transformer) => {
57
+ if (!transformer || transformer === "pngjs") {
58
+ const { default: transformer2 } = await import("@blazediff/pngjs-transformer");
59
+ return transformer2;
60
+ }
61
+ if (transformer === "sharp") {
62
+ const { default: transformer2 } = await import("@blazediff/sharp-transformer");
63
+ return transformer2;
64
+ }
65
+ throw new Error(`Unknown transformer: ${transformer}`);
66
+ };
67
+ async function main() {
68
+ try {
69
+ const args = process.argv.slice(2);
70
+ if (args.length === 0 || args.includes("-h") || args.includes("--help")) {
71
+ printUsage();
72
+ process.exit(0);
73
+ }
74
+ if (args.length < 2) {
75
+ console.error("Error: Two image paths are required");
76
+ printUsage();
77
+ process.exit(1);
78
+ }
79
+ const image1 = args[0];
80
+ const image2 = args[1];
81
+ const options = {};
82
+ for (let i = 2; i < args.length; i++) {
83
+ const arg = args[i];
84
+ const nextArg = args[i + 1];
85
+ switch (arg) {
86
+ case "-o":
87
+ case "--output":
88
+ if (nextArg) {
89
+ options.outputPath = nextArg;
90
+ i++;
91
+ }
92
+ break;
93
+ case "--transformer":
94
+ if (nextArg) {
95
+ options.transformer = nextArg;
96
+ i++;
97
+ }
98
+ break;
99
+ default:
100
+ console.error(`Unknown option: ${arg}`);
101
+ printUsage();
102
+ process.exit(1);
103
+ }
104
+ }
105
+ const transformer = await getTransformer(options.transformer);
106
+ const [img1, img2] = await Promise.all([
107
+ transformer.transform(image1),
108
+ transformer.transform(image2)
109
+ ]);
110
+ if (img1.width !== img2.width || img1.height !== img2.height) {
111
+ throw new Error(
112
+ `Image dimensions do not match: ${img1.width}x${img1.height} vs ${img2.width}x${img2.height}`
113
+ );
114
+ }
115
+ let outputData;
116
+ if (options.outputPath) {
117
+ outputData = new Uint8Array(img1.data.length);
118
+ }
119
+ const startTime = performance.now();
120
+ const score = (0, import_ssim.default)(img1.data, img2.data, outputData, img1.width, img1.height, {});
121
+ const duration = performance.now() - startTime;
122
+ if (options.outputPath && outputData) {
123
+ await transformer.write(
124
+ {
125
+ data: outputData,
126
+ width: img1.width,
127
+ height: img1.height
128
+ },
129
+ options.outputPath
130
+ );
131
+ }
132
+ const result = {
133
+ score,
134
+ width: img1.width,
135
+ height: img1.height,
136
+ duration
137
+ };
138
+ console.log(`completed in: ${result.duration.toFixed(2)}ms`);
139
+ console.log(`dimensions: ${result.width}x${result.height}`);
140
+ console.log(
141
+ `SSIM score: ${result.score.toFixed(6)} (0=different, 1=identical)`
142
+ );
143
+ console.log(`similarity: ${(result.score * 100).toFixed(2)}%`);
144
+ if (options.outputPath && outputData) {
145
+ console.log(`SSIM map saved to: ${options.outputPath}`);
146
+ }
147
+ if (result.score < 0.95) {
148
+ process.exit(1);
149
+ } else {
150
+ console.log(`Images are highly similar!`);
151
+ process.exit(0);
152
+ }
153
+ } catch (error) {
154
+ console.error(
155
+ "Error:",
156
+ error instanceof Error ? error.message : String(error)
157
+ );
158
+ process.exit(1);
159
+ }
160
+ }
161
+ if (typeof require !== "undefined" && require.main === module) {
162
+ main();
163
+ }
package/dist/index.d.mts CHANGED
@@ -1,17 +1,69 @@
1
- import { BlazeDiffTransformer, BlazeDiffOptions } from '@blazediff/types';
2
-
3
- interface BlazeDiffBinOptions {
1
+ interface Image {
2
+ data: Buffer | Uint8Array | Uint8ClampedArray;
3
+ width: number;
4
+ height: number;
5
+ }
6
+ interface Transformer {
7
+ transform: (input: string | Buffer) => Promise<Image>;
8
+ write: (image: Image, output: string | Buffer) => Promise<void>;
9
+ }
10
+ type ComparisonMode = "diff" | "gmsd" | "ssim" | "msssim";
11
+ interface DiffModeOptions {
12
+ outputPath?: string;
13
+ transformer: Transformer;
14
+ mode?: "diff";
15
+ options?: Record<string, unknown>;
16
+ }
17
+ interface GmsdModeOptions {
4
18
  outputPath?: string;
5
- transformer: BlazeDiffTransformer;
6
- coreOptions?: BlazeDiffOptions;
19
+ transformer: Transformer;
20
+ mode: "gmsd";
21
+ options?: Record<string, unknown>;
7
22
  }
8
- interface BlazeDiffBinResult {
23
+ interface SsimModeOptions {
24
+ outputPath?: string;
25
+ transformer: Transformer;
26
+ mode: "ssim";
27
+ options?: Record<string, unknown>;
28
+ }
29
+ interface MsssimModeOptions {
30
+ outputPath?: string;
31
+ transformer: Transformer;
32
+ mode: "msssim";
33
+ options?: Record<string, unknown>;
34
+ }
35
+ interface DiffModeResult {
36
+ mode: "diff";
9
37
  diffCount: number;
10
38
  width: number;
11
39
  height: number;
12
40
  outputData?: Uint8Array;
13
41
  duration: number;
14
42
  }
15
- declare function blazeDiffBin(image1Path: string, image2Path: string, options: BlazeDiffBinOptions): Promise<BlazeDiffBinResult>;
43
+ interface GmsdModeResult {
44
+ mode: "gmsd";
45
+ score: number;
46
+ width: number;
47
+ height: number;
48
+ outputData?: Uint8Array;
49
+ duration: number;
50
+ }
51
+ interface SsimModeResult {
52
+ mode: "ssim";
53
+ score: number;
54
+ width: number;
55
+ height: number;
56
+ outputData?: Uint8Array;
57
+ duration: number;
58
+ }
59
+ interface MsssimModeResult {
60
+ mode: "msssim";
61
+ score: number;
62
+ width: number;
63
+ height: number;
64
+ outputData?: Uint8Array;
65
+ duration: number;
66
+ }
67
+ type BlazeDiffBinResult = DiffModeResult | GmsdModeResult | SsimModeResult | MsssimModeResult;
16
68
 
17
- export { type BlazeDiffBinOptions, type BlazeDiffBinResult, blazeDiffBin as default };
69
+ export type { BlazeDiffBinResult, ComparisonMode, DiffModeOptions, DiffModeResult, GmsdModeOptions, GmsdModeResult, Image, MsssimModeOptions, MsssimModeResult, SsimModeOptions, SsimModeResult, Transformer };
package/dist/index.d.ts CHANGED
@@ -1,17 +1,69 @@
1
- import { BlazeDiffTransformer, BlazeDiffOptions } from '@blazediff/types';
2
-
3
- interface BlazeDiffBinOptions {
1
+ interface Image {
2
+ data: Buffer | Uint8Array | Uint8ClampedArray;
3
+ width: number;
4
+ height: number;
5
+ }
6
+ interface Transformer {
7
+ transform: (input: string | Buffer) => Promise<Image>;
8
+ write: (image: Image, output: string | Buffer) => Promise<void>;
9
+ }
10
+ type ComparisonMode = "diff" | "gmsd" | "ssim" | "msssim";
11
+ interface DiffModeOptions {
12
+ outputPath?: string;
13
+ transformer: Transformer;
14
+ mode?: "diff";
15
+ options?: Record<string, unknown>;
16
+ }
17
+ interface GmsdModeOptions {
4
18
  outputPath?: string;
5
- transformer: BlazeDiffTransformer;
6
- coreOptions?: BlazeDiffOptions;
19
+ transformer: Transformer;
20
+ mode: "gmsd";
21
+ options?: Record<string, unknown>;
7
22
  }
8
- interface BlazeDiffBinResult {
23
+ interface SsimModeOptions {
24
+ outputPath?: string;
25
+ transformer: Transformer;
26
+ mode: "ssim";
27
+ options?: Record<string, unknown>;
28
+ }
29
+ interface MsssimModeOptions {
30
+ outputPath?: string;
31
+ transformer: Transformer;
32
+ mode: "msssim";
33
+ options?: Record<string, unknown>;
34
+ }
35
+ interface DiffModeResult {
36
+ mode: "diff";
9
37
  diffCount: number;
10
38
  width: number;
11
39
  height: number;
12
40
  outputData?: Uint8Array;
13
41
  duration: number;
14
42
  }
15
- declare function blazeDiffBin(image1Path: string, image2Path: string, options: BlazeDiffBinOptions): Promise<BlazeDiffBinResult>;
43
+ interface GmsdModeResult {
44
+ mode: "gmsd";
45
+ score: number;
46
+ width: number;
47
+ height: number;
48
+ outputData?: Uint8Array;
49
+ duration: number;
50
+ }
51
+ interface SsimModeResult {
52
+ mode: "ssim";
53
+ score: number;
54
+ width: number;
55
+ height: number;
56
+ outputData?: Uint8Array;
57
+ duration: number;
58
+ }
59
+ interface MsssimModeResult {
60
+ mode: "msssim";
61
+ score: number;
62
+ width: number;
63
+ height: number;
64
+ outputData?: Uint8Array;
65
+ duration: number;
66
+ }
67
+ type BlazeDiffBinResult = DiffModeResult | GmsdModeResult | SsimModeResult | MsssimModeResult;
16
68
 
17
- export { type BlazeDiffBinOptions, type BlazeDiffBinResult, blazeDiffBin as default };
69
+ export type { BlazeDiffBinResult, ComparisonMode, DiffModeOptions, DiffModeResult, GmsdModeOptions, GmsdModeResult, Image, MsssimModeOptions, MsssimModeResult, SsimModeOptions, SsimModeResult, Transformer };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var m=require('@blazediff/core');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var m__default=/*#__PURE__*/_interopDefault(m);async function u(n,f,i){let[t,e]=await Promise.all([i.transformer.transform(n),i.transformer.transform(f)]);if(t.width!==e.width||t.height!==e.height)throw new Error(`Image dimensions do not match: ${t.width}x${t.height} vs ${e.width}x${e.height}`);let r;i.outputPath&&(r=new Uint8Array(t.data.length));let h=performance.now(),a=m__default.default(t.data,e.data,r,t.width,t.height,i.coreOptions),o=performance.now()-h;return a>0&&i.outputPath&&r&&await i.transformer.write({data:r,width:t.width,height:t.height},i.outputPath),{diffCount:a,width:t.width,height:t.height,outputData:r,duration:o}}module.exports=u;
1
+ 'use strict';
package/dist/index.mjs CHANGED
@@ -1 +0,0 @@
1
- import m from'@blazediff/core';async function u(n,f,i){let[t,e]=await Promise.all([i.transformer.transform(n),i.transformer.transform(f)]);if(t.width!==e.width||t.height!==e.height)throw new Error(`Image dimensions do not match: ${t.width}x${t.height} vs ${e.width}x${e.height}`);let r;i.outputPath&&(r=new Uint8Array(t.data.length));let h=performance.now(),a=m(t.data,e.data,r,t.width,t.height,i.coreOptions),o=performance.now()-h;return a>0&&i.outputPath&&r&&await i.transformer.write({data:r,width:t.width,height:t.height},i.outputPath),{diffCount:a,width:t.width,height:t.height,outputData:r,duration:o}}export{u as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazediff/bin",
3
- "version": "1.4.1",
3
+ "version": "1.6.0",
4
4
  "description": "Command-line interface for the blazediff image comparison library",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -37,10 +37,11 @@
37
37
  "homepage": "https://blazediff.dev",
38
38
  "license": "MIT",
39
39
  "dependencies": {
40
- "@blazediff/core": "1.4.1",
41
- "@blazediff/pngjs-transformer": "1.4.1",
42
- "@blazediff/sharp-transformer": "1.4.1",
43
- "@blazediff/types": "1.4.1"
40
+ "@blazediff/core": "1.6.0",
41
+ "@blazediff/gmsd": "1.6.0",
42
+ "@blazediff/pngjs-transformer": "1.6.0",
43
+ "@blazediff/sharp-transformer": "1.6.0",
44
+ "@blazediff/ssim": "1.6.0"
44
45
  },
45
46
  "devDependencies": {
46
47
  "@types/node": "^24.3.0",