@blazediff/cli 1.8.0 → 2.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.
- package/README.md +49 -23
- package/dist/cli.js +9406 -140
- package/dist/commands/bin.js +145 -0
- package/dist/commands/core.js +8984 -0
- package/dist/commands/gmsd.js +8727 -17
- package/dist/commands/hitchhikers-ssim.js +8704 -17
- package/dist/commands/msssim.js +8739 -15
- package/dist/commands/ssim.js +8770 -15
- package/package.json +3 -2
- package/dist/commands/diff.js +0 -255
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blazediff/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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/bin": "2.1.0",
|
|
40
41
|
"@blazediff/core": "1.8.0",
|
|
41
42
|
"@blazediff/gmsd": "1.7.0",
|
|
42
|
-
"@blazediff/pngjs-transformer": "2.0.0",
|
|
43
43
|
"@blazediff/sharp-transformer": "2.0.0",
|
|
44
|
+
"@blazediff/pngjs-transformer": "2.0.0",
|
|
44
45
|
"@blazediff/ssim": "1.7.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
package/dist/commands/diff.js
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
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/diff.ts
|
|
32
|
-
var diff_exports = {};
|
|
33
|
-
__export(diff_exports, {
|
|
34
|
-
default: () => main
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(diff_exports);
|
|
37
|
-
var import_core = __toESM(require("@blazediff/core"));
|
|
38
|
-
function parseRGB(colorStr) {
|
|
39
|
-
const parts = colorStr.split(",").map((s) => parseInt(s.trim(), 10));
|
|
40
|
-
if (parts.length !== 3 || parts.some((p) => Number.isNaN(p) || p < 0 || p > 255)) {
|
|
41
|
-
throw new Error(
|
|
42
|
-
`Invalid RGB color format: ${colorStr}. Expected format: r,g,b (e.g., 255,0,0)`
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
return [parts[0], parts[1], parts[2]];
|
|
46
|
-
}
|
|
47
|
-
function printUsage() {
|
|
48
|
-
console.log(`
|
|
49
|
-
Usage: blazediff diff <image1> <image2> [options]
|
|
50
|
-
|
|
51
|
-
Arguments:
|
|
52
|
-
image1 Path to the first image
|
|
53
|
-
image2 Path to the second image
|
|
54
|
-
|
|
55
|
-
Options:
|
|
56
|
-
-o, --output <path> Output path for the diff image
|
|
57
|
-
-t, --threshold <num> Matching threshold (0 to 1, default: 0.1)
|
|
58
|
-
-a, --alpha <num> Opacity of original image in diff (default: 0.1)
|
|
59
|
-
--aa-color <r,g,b> Color for anti-aliased pixels (default: 255,255,0)
|
|
60
|
-
--diff-color <r,g,b> Color for different pixels (default: 255,0,0)
|
|
61
|
-
--diff-color-alt <r,g,b> Alternative color for dark differences (default: same as diff-color)
|
|
62
|
-
--include-aa Include anti-aliasing detection
|
|
63
|
-
--diff-mask Draw diff over transparent background
|
|
64
|
-
--color-space <name> Specify color space to use (e.g. yiq, ycbcr)
|
|
65
|
-
--transformer <name> Specify transformer to use (e.g. pngjs, sharp)
|
|
66
|
-
-h, --help Show this help message
|
|
67
|
-
|
|
68
|
-
Examples:
|
|
69
|
-
blazediff diff image1.png image2.png
|
|
70
|
-
blazediff diff image1.png image2.png -o diff.png -t 0.05
|
|
71
|
-
blazediff diff image1.png image2.png --threshold 0.2 --alpha 0.3
|
|
72
|
-
`);
|
|
73
|
-
}
|
|
74
|
-
var getTransformer = async (transformer) => {
|
|
75
|
-
if (!transformer || transformer === "pngjs") {
|
|
76
|
-
const { default: transformer2 } = await import("@blazediff/pngjs-transformer");
|
|
77
|
-
return transformer2;
|
|
78
|
-
}
|
|
79
|
-
if (transformer === "sharp") {
|
|
80
|
-
const { default: transformer2 } = await import("@blazediff/sharp-transformer");
|
|
81
|
-
return transformer2;
|
|
82
|
-
}
|
|
83
|
-
throw new Error(`Unknown transformer: ${transformer}`);
|
|
84
|
-
};
|
|
85
|
-
async function main() {
|
|
86
|
-
try {
|
|
87
|
-
const args = process.argv.slice(2);
|
|
88
|
-
if (args.length === 0 || args.includes("-h") || args.includes("--help")) {
|
|
89
|
-
printUsage();
|
|
90
|
-
process.exit(0);
|
|
91
|
-
}
|
|
92
|
-
if (args.length < 2) {
|
|
93
|
-
console.error("Error: Two image paths are required");
|
|
94
|
-
printUsage();
|
|
95
|
-
process.exit(1);
|
|
96
|
-
}
|
|
97
|
-
const image1 = args[0];
|
|
98
|
-
const image2 = args[1];
|
|
99
|
-
const options = {};
|
|
100
|
-
for (let i = 2; i < args.length; i++) {
|
|
101
|
-
const arg = args[i];
|
|
102
|
-
const nextArg = args[i + 1];
|
|
103
|
-
switch (arg) {
|
|
104
|
-
case "-o":
|
|
105
|
-
case "--output":
|
|
106
|
-
if (nextArg) {
|
|
107
|
-
options.outputPath = nextArg;
|
|
108
|
-
i++;
|
|
109
|
-
}
|
|
110
|
-
break;
|
|
111
|
-
case "-t":
|
|
112
|
-
case "--threshold":
|
|
113
|
-
if (nextArg) {
|
|
114
|
-
const threshold = parseFloat(nextArg);
|
|
115
|
-
if (Number.isNaN(threshold) || threshold < 0 || threshold > 1) {
|
|
116
|
-
throw new Error(
|
|
117
|
-
`Invalid threshold: ${nextArg}. Must be between 0 and 1`
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
options.threshold = threshold;
|
|
121
|
-
i++;
|
|
122
|
-
}
|
|
123
|
-
break;
|
|
124
|
-
case "-a":
|
|
125
|
-
case "--alpha":
|
|
126
|
-
if (nextArg) {
|
|
127
|
-
const alpha = parseFloat(nextArg);
|
|
128
|
-
if (Number.isNaN(alpha) || alpha < 0 || alpha > 1) {
|
|
129
|
-
throw new Error(
|
|
130
|
-
`Invalid alpha: ${nextArg}. Must be between 0 and 1`
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
options.alpha = alpha;
|
|
134
|
-
i++;
|
|
135
|
-
}
|
|
136
|
-
break;
|
|
137
|
-
case "--aa-color":
|
|
138
|
-
if (nextArg) {
|
|
139
|
-
options.aaColor = parseRGB(nextArg);
|
|
140
|
-
i++;
|
|
141
|
-
}
|
|
142
|
-
break;
|
|
143
|
-
case "--diff-color":
|
|
144
|
-
if (nextArg) {
|
|
145
|
-
options.diffColor = parseRGB(nextArg);
|
|
146
|
-
i++;
|
|
147
|
-
}
|
|
148
|
-
break;
|
|
149
|
-
case "--diff-color-alt":
|
|
150
|
-
if (nextArg) {
|
|
151
|
-
options.diffColorAlt = parseRGB(nextArg);
|
|
152
|
-
i++;
|
|
153
|
-
}
|
|
154
|
-
break;
|
|
155
|
-
case "--include-aa":
|
|
156
|
-
options.includeAA = true;
|
|
157
|
-
break;
|
|
158
|
-
case "--diff-mask":
|
|
159
|
-
options.diffMask = true;
|
|
160
|
-
break;
|
|
161
|
-
case "--transformer":
|
|
162
|
-
if (nextArg) {
|
|
163
|
-
options.transformer = nextArg;
|
|
164
|
-
i++;
|
|
165
|
-
}
|
|
166
|
-
break;
|
|
167
|
-
case "--color-space":
|
|
168
|
-
if (nextArg) {
|
|
169
|
-
options.colorSpace = nextArg;
|
|
170
|
-
i++;
|
|
171
|
-
}
|
|
172
|
-
break;
|
|
173
|
-
default:
|
|
174
|
-
console.error(`Unknown option: ${arg}`);
|
|
175
|
-
printUsage();
|
|
176
|
-
process.exit(1);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
const transformer = await getTransformer(
|
|
180
|
-
options.transformer
|
|
181
|
-
);
|
|
182
|
-
const [img1, img2] = await Promise.all([
|
|
183
|
-
transformer.read(image1),
|
|
184
|
-
transformer.read(image2)
|
|
185
|
-
]);
|
|
186
|
-
if (img1.width !== img2.width || img1.height !== img2.height) {
|
|
187
|
-
throw new Error(
|
|
188
|
-
`Image dimensions do not match: ${img1.width}x${img1.height} vs ${img2.width}x${img2.height}`
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
let outputData;
|
|
192
|
-
if (options.outputPath) {
|
|
193
|
-
outputData = new Uint8Array(img1.data.length);
|
|
194
|
-
}
|
|
195
|
-
const coreOptions = {
|
|
196
|
-
threshold: options.threshold,
|
|
197
|
-
alpha: options.alpha,
|
|
198
|
-
aaColor: options.aaColor,
|
|
199
|
-
diffColor: options.diffColor,
|
|
200
|
-
diffColorAlt: options.diffColorAlt,
|
|
201
|
-
includeAA: options.includeAA,
|
|
202
|
-
diffMask: options.diffMask
|
|
203
|
-
};
|
|
204
|
-
const startTime = performance.now();
|
|
205
|
-
const diffCount = (0, import_core.default)(
|
|
206
|
-
img1.data,
|
|
207
|
-
img2.data,
|
|
208
|
-
outputData,
|
|
209
|
-
img1.width,
|
|
210
|
-
img1.height,
|
|
211
|
-
coreOptions
|
|
212
|
-
);
|
|
213
|
-
const duration = performance.now() - startTime;
|
|
214
|
-
if (diffCount > 0 && options.outputPath && outputData) {
|
|
215
|
-
await transformer.write(
|
|
216
|
-
{
|
|
217
|
-
data: outputData,
|
|
218
|
-
width: img1.width,
|
|
219
|
-
height: img1.height
|
|
220
|
-
},
|
|
221
|
-
options.outputPath
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
const result = {
|
|
225
|
-
diffCount,
|
|
226
|
-
width: img1.width,
|
|
227
|
-
height: img1.height,
|
|
228
|
-
duration
|
|
229
|
-
};
|
|
230
|
-
console.log(`completed in: ${result.duration.toFixed(2)}ms`);
|
|
231
|
-
console.log(`dimensions: ${result.width}x${result.height}`);
|
|
232
|
-
console.log(`different pixels: ${result.diffCount}`);
|
|
233
|
-
console.log(
|
|
234
|
-
`error: ${(result.diffCount / (result.width * result.height) * 100).toFixed(2)}%`
|
|
235
|
-
);
|
|
236
|
-
if (result.diffCount > 0 && outputData && options.outputPath) {
|
|
237
|
-
console.log(`diff image: ${options.outputPath}`);
|
|
238
|
-
}
|
|
239
|
-
if (result.diffCount > 0) {
|
|
240
|
-
process.exit(1);
|
|
241
|
-
} else {
|
|
242
|
-
console.log(`Images are identical!`);
|
|
243
|
-
process.exit(0);
|
|
244
|
-
}
|
|
245
|
-
} catch (error) {
|
|
246
|
-
console.error(
|
|
247
|
-
"Error:",
|
|
248
|
-
error instanceof Error ? error.message : String(error)
|
|
249
|
-
);
|
|
250
|
-
process.exit(1);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
if (typeof require !== "undefined" && require.main === module) {
|
|
254
|
-
main();
|
|
255
|
-
}
|