@blazediff/cli 4.0.4 → 5.0.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,208 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/commands/interpret.ts
22
+ var interpret_exports = {};
23
+ __export(interpret_exports, {
24
+ default: () => main
25
+ });
26
+ module.exports = __toCommonJS(interpret_exports);
27
+ var import_interpret_native = require("@blazediff/interpret-native");
28
+ var SOURCES = [
29
+ "pixel",
30
+ "ssim",
31
+ "ms-ssim",
32
+ "hitchhikers-ssim"
33
+ ];
34
+ function printUsage() {
35
+ console.log(`
36
+ Usage: blazediff-cli interpret <image1> <image2> [output] [options]
37
+
38
+ Describes *what* changed between two images \u2014 region by region, with a change
39
+ type, position and shape \u2014 rather than only which pixels differ.
40
+
41
+ Arguments:
42
+ image1 Path to the first image
43
+ image2 Path to the second image
44
+ output Path for the diff visualization (optional; the pixel source
45
+ writes it, the metric sources and --regions do not)
46
+
47
+ Options:
48
+ --source <name> How to locate regions: pixel (default), ssim,
49
+ ms-ssim, hitchhikers-ssim
50
+ -t, --threshold <num> Color difference threshold (0 to 1, default: 0.1).
51
+ pixel source only
52
+ -a, --antialiasing Exclude anti-aliased pixels. pixel source only
53
+ -c, --compression <num> PNG compression level (0-9, default: 0)
54
+ --window-size <num> Local window size for the metric sources (default: 11)
55
+ --region-floor <num> Window score at or below which it counts as changed
56
+ (0 to 1, default: 0.99). Metric sources only
57
+ --regions <json> Skip the search and classify these boxes instead.
58
+ A JSON array of { x, y, width, height }
59
+ --json Print the full result as JSON
60
+ -h, --help Show this help message
61
+
62
+ The metric sources locate regions by thresholding a similarity map, so their
63
+ boxes are as coarse as that map's grid. The numbers are not: every box is
64
+ refined against the source pixels first, so pixel counts stay per-pixel.
65
+
66
+ Examples:
67
+ blazediff-cli interpret image1.png image2.png
68
+ blazediff-cli interpret image1.png image2.png diff.png -t 0.05 -a
69
+ blazediff-cli interpret image1.png image2.png --source ms-ssim
70
+ blazediff-cli interpret image1.png image2.png --json
71
+ blazediff-cli interpret image1.png image2.png --regions '[{"x":0,"y":0,"width":64,"height":64}]'
72
+ `);
73
+ }
74
+ function parseNumber(value, flag, min, max) {
75
+ const parsed = Number.parseFloat(value ?? "");
76
+ if (Number.isNaN(parsed) || parsed < min || parsed > max) {
77
+ throw new Error(
78
+ `Invalid ${flag}: ${value}. Must be between ${min} and ${max}`
79
+ );
80
+ }
81
+ return parsed;
82
+ }
83
+ function printSummary(result) {
84
+ console.log(result.summary);
85
+ for (const region of result.regions) {
86
+ const { x, y, width, height } = region.bbox;
87
+ console.log(
88
+ ` ${region.changeType} ${region.shape} at ${region.position} \u2014 ${width}x${height} at (${x}, ${y}), ${region.pixelCount}px (${region.percentage.toFixed(2)}%)`
89
+ );
90
+ }
91
+ }
92
+ async function main() {
93
+ try {
94
+ const args = process.argv.slice(2);
95
+ if (args.length === 0 || args.includes("-h") || args.includes("--help")) {
96
+ printUsage();
97
+ process.exit(0);
98
+ }
99
+ if (args.length < 2) {
100
+ console.error("Error: Two image paths are required");
101
+ printUsage();
102
+ process.exit(1);
103
+ }
104
+ const image1 = args[0];
105
+ const image2 = args[1];
106
+ const options = {};
107
+ let output;
108
+ let regions;
109
+ let json = false;
110
+ let optStart = 2;
111
+ if (args.length > 2 && !args[2].startsWith("-")) {
112
+ output = args[2];
113
+ optStart = 3;
114
+ }
115
+ for (let i = optStart; i < args.length; i++) {
116
+ const arg = args[i];
117
+ const nextArg = args[i + 1];
118
+ switch (arg) {
119
+ case "--source":
120
+ if (!nextArg || !SOURCES.includes(nextArg)) {
121
+ throw new Error(
122
+ `Invalid source: ${nextArg}. Must be one of: ${SOURCES.join(", ")}`
123
+ );
124
+ }
125
+ options.source = nextArg;
126
+ i++;
127
+ break;
128
+ case "-t":
129
+ case "--threshold":
130
+ options.threshold = parseNumber(nextArg, "threshold", 0, 1);
131
+ i++;
132
+ break;
133
+ case "-a":
134
+ case "--antialiasing":
135
+ options.antialiasing = true;
136
+ break;
137
+ case "-c":
138
+ case "--compression":
139
+ options.compression = parseNumber(nextArg, "compression", 0, 9);
140
+ i++;
141
+ break;
142
+ case "--window-size":
143
+ options.windowSize = parseNumber(nextArg, "window-size", 1, 1024);
144
+ i++;
145
+ break;
146
+ case "--region-floor":
147
+ options.regionFloor = parseNumber(nextArg, "region-floor", 0, 1);
148
+ i++;
149
+ break;
150
+ case "--regions":
151
+ if (!nextArg) {
152
+ throw new Error("--regions requires a JSON array");
153
+ }
154
+ regions = nextArg;
155
+ i++;
156
+ break;
157
+ case "--json":
158
+ json = true;
159
+ break;
160
+ default:
161
+ console.error(`Unknown option: ${arg}`);
162
+ printUsage();
163
+ process.exit(1);
164
+ }
165
+ }
166
+ const startTime = performance.now();
167
+ let result;
168
+ if (regions !== void 0) {
169
+ if (output !== void 0) {
170
+ throw new Error(
171
+ "--regions does not write a diff visualization; drop the output path"
172
+ );
173
+ }
174
+ let parsed;
175
+ try {
176
+ parsed = JSON.parse(regions);
177
+ } catch {
178
+ throw new Error("--regions must be valid JSON");
179
+ }
180
+ if (!Array.isArray(parsed)) {
181
+ throw new Error("--regions must be a JSON array of boxes");
182
+ }
183
+ result = await (0, import_interpret_native.interpretRegions)(image1, image2, parsed);
184
+ } else {
185
+ result = await (0, import_interpret_native.interpret)(image1, image2, output, options);
186
+ }
187
+ const duration = performance.now() - startTime;
188
+ console.log(`completed in: ${duration.toFixed(2)}ms`);
189
+ if (json) {
190
+ console.log(JSON.stringify(result, null, 2));
191
+ } else {
192
+ printSummary(result);
193
+ if (output && result.diffCount > 0) {
194
+ console.log(`diff output: ${output}`);
195
+ }
196
+ }
197
+ process.exit(result.totalRegions === 0 ? 0 : 1);
198
+ } catch (error) {
199
+ console.error(
200
+ "Error:",
201
+ error instanceof Error ? error.message : String(error)
202
+ );
203
+ process.exit(2);
204
+ }
205
+ }
206
+ if (typeof require !== "undefined" && require.main === module) {
207
+ main();
208
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazediff/cli",
3
- "version": "4.0.4",
3
+ "version": "5.0.0",
4
4
  "description": "Command-line interface for the blazediff image comparison library",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -37,9 +37,10 @@
37
37
  "homepage": "https://blazediff.dev",
38
38
  "license": "MIT",
39
39
  "dependencies": {
40
- "@blazediff/core-native": "5.3.0",
41
- "@blazediff/core": "1.9.3",
42
- "@blazediff/core-wasm": "5.3.0",
40
+ "@blazediff/core-native": "6.0.0",
41
+ "@blazediff/core": "1.10.0",
42
+ "@blazediff/core-wasm": "6.0.0",
43
+ "@blazediff/interpret-native": "6.0.0",
43
44
  "@blazediff/gmsd": "1.7.1",
44
45
  "@blazediff/codec-pngjs": "4.0.0",
45
46
  "@blazediff/codec-sharp": "4.0.0",