@rosepetal/node-red-contrib-image-tools 1.5.0 → 1.5.2
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/.claude/CLAUDE.md +33 -0
- package/.claude/agents/doc-env-validator.md +136 -0
- package/.claude/agents/doc-reviewer.md +78 -0
- package/.claude/agents/doc-writer.md +67 -0
- package/.claude/agents/gif-recorder.md +143 -0
- package/.claude/rules/claude-code-conventions.md +58 -0
- package/.claude/rules/documentation-conventions.md +136 -0
- package/.claude/rules/node-implementation-template.md +125 -0
- package/.claude/scripts/announce-orphans.sh +70 -0
- package/.claude/skills/doctor/SKILL.md +37 -0
- package/.claude/skills/document-all-nodes/SKILL.md +48 -0
- package/.claude/skills/document-node/SKILL.md +131 -0
- package/.claude/skills/document-node/prompts/synthesize-help.md +33 -0
- package/.claude/skills/document-node/prompts/synthesize-md.md +48 -0
- package/.claude/skills/document-node/templates/help-block.html.tmpl +34 -0
- package/.claude/skills/document-node/templates/node-doc.md.tmpl +43 -0
- package/artifacts/darwin-arm64/package.json +1 -1
- package/artifacts/linux-arm64/package.json +1 -1
- package/artifacts/linux-x64/package.json +1 -1
- package/artifacts/linuxmusl-x64/package.json +1 -1
- package/node-red-contrib-image-tools/nodes/io/image-out.html +22 -3
- package/node-red-contrib-image-tools/nodes/io/image-out.js +8 -4
- package/node-red-contrib-image-tools/nodes/specialized/heat-diff.html +218 -0
- package/node-red-contrib-image-tools/nodes/specialized/heat-diff.js +177 -0
- package/node-red-contrib-image-tools/nodes/transform/filter.html +106 -3
- package/node-red-contrib-image-tools/nodes/transform/filter.js +31 -4
- package/npm/darwin-arm64/package.json +1 -1
- package/npm/darwin-x64/package.json +1 -1
- package/npm/linux-arm64/package.json +1 -1
- package/npm/linux-x64/package.json +1 -1
- package/npm/linuxmusl-x64/package.json +1 -1
- package/npm/win32-x64/package.json +1 -1
- package/package.json +8 -7
- package/rosepetal-image-engine/binding.gyp +2 -1
- package/rosepetal-image-engine/src/filter.cpp +144 -0
- package/rosepetal-image-engine/src/heat-diff.cpp +146 -0
- package/rosepetal-image-engine/src/main.cpp +2 -0
|
@@ -66,10 +66,37 @@ module.exports = function (RED) {
|
|
|
66
66
|
msg
|
|
67
67
|
));
|
|
68
68
|
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
// Override parameters for filter types with their own config
|
|
70
|
+
if (filterType === 'otsu') {
|
|
71
|
+
const preBlurResolved = NodeUtils.resolveDimension(
|
|
72
|
+
node,
|
|
73
|
+
config.otsuPreBlurType || 'num',
|
|
74
|
+
config.otsuPreBlur,
|
|
75
|
+
msg
|
|
76
|
+
);
|
|
77
|
+
let preBlur = parseInt(preBlurResolved);
|
|
78
|
+
if (!Number.isFinite(preBlur)) preBlur = 0;
|
|
79
|
+
kernelSize = Math.max(0, Math.min(preBlur, 15));
|
|
80
|
+
if (kernelSize > 0 && kernelSize < 3) kernelSize = 3;
|
|
81
|
+
if (kernelSize > 0 && kernelSize % 2 === 0) kernelSize++;
|
|
82
|
+
intensity = config.otsuInvert ? 1.0 : 0.0;
|
|
83
|
+
} else if (filterType === 'histogram_eq') {
|
|
84
|
+
kernelSize = 3; // unused but must be valid
|
|
85
|
+
const strengthResolved = NodeUtils.resolveDimension(
|
|
86
|
+
node,
|
|
87
|
+
config.histEqStrengthType || 'num',
|
|
88
|
+
config.histEqStrength,
|
|
89
|
+
msg
|
|
90
|
+
);
|
|
91
|
+
let strength = parseInt(strengthResolved);
|
|
92
|
+
if (!Number.isFinite(strength)) strength = 100;
|
|
93
|
+
intensity = Math.max(0.0, Math.min(strength / 100.0, 1.0));
|
|
94
|
+
} else {
|
|
95
|
+
// Standard filters: validate parameters
|
|
96
|
+
kernelSize = Math.max(3, Math.min(kernelSize, 15));
|
|
97
|
+
if (kernelSize % 2 === 0) kernelSize++; // Ensure odd size
|
|
98
|
+
intensity = Math.max(0.0, Math.min(intensity, 2.0));
|
|
99
|
+
}
|
|
73
100
|
|
|
74
101
|
// Validate input images
|
|
75
102
|
if (Array.isArray(originalPayload)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rosepetal/node-red-contrib-image-tools",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Node-RED Image Processing Toolkit",
|
|
5
5
|
"main": "install.sh",
|
|
6
6
|
"directories": {
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"sharp": "^0.34.2"
|
|
36
36
|
},
|
|
37
37
|
"optionalDependencies": {
|
|
38
|
-
"@rosepetal/node-red-contrib-image-tools-linux-x64": "1.5.
|
|
39
|
-
"@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.5.
|
|
40
|
-
"@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.5.
|
|
41
|
-
"@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.5.
|
|
42
|
-
"@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.5.
|
|
38
|
+
"@rosepetal/node-red-contrib-image-tools-linux-x64": "1.5.2",
|
|
39
|
+
"@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.5.2",
|
|
40
|
+
"@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.5.2",
|
|
41
|
+
"@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.5.2",
|
|
42
|
+
"@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.5.2"
|
|
43
43
|
},
|
|
44
44
|
"node-red": {
|
|
45
45
|
"version": ">=1.0.0",
|
|
@@ -62,7 +62,8 @@
|
|
|
62
62
|
"rp-blend": "node-red-contrib-image-tools/nodes/blend/blend.js",
|
|
63
63
|
"rp-add-mask": "node-red-contrib-image-tools/nodes/blend/add-mask.js",
|
|
64
64
|
"rp-add-masks": "node-red-contrib-image-tools/nodes/blend/add-masks.js",
|
|
65
|
-
"rp-add-bbs": "node-red-contrib-image-tools/nodes/blend/add-bbs.js"
|
|
65
|
+
"rp-add-bbs": "node-red-contrib-image-tools/nodes/blend/add-bbs.js",
|
|
66
|
+
"rp-heat-diff": "node-red-contrib-image-tools/nodes/specialized/heat-diff.js"
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
}
|
|
@@ -68,6 +68,12 @@ protected:
|
|
|
68
68
|
ApplyEmbossFilter();
|
|
69
69
|
} else if (filterType_ == "gaussian") {
|
|
70
70
|
ApplyGaussianFilter();
|
|
71
|
+
} else if (filterType_ == "otsu") {
|
|
72
|
+
ApplyOtsuFilter();
|
|
73
|
+
} else if (filterType_ == "histogram_eq") {
|
|
74
|
+
ApplyHistogramEqualization();
|
|
75
|
+
} else if (filterType_ == "clahe") {
|
|
76
|
+
ApplyCLAHE();
|
|
71
77
|
} else {
|
|
72
78
|
throw std::runtime_error("Unknown filter type: " + filterType_);
|
|
73
79
|
}
|
|
@@ -181,6 +187,144 @@ private:
|
|
|
181
187
|
double sigma = kernelSize_ / 6.0 * intensity_; // Scale sigma with intensity
|
|
182
188
|
cv::GaussianBlur(input_, result_, ksize, sigma);
|
|
183
189
|
}
|
|
190
|
+
|
|
191
|
+
void ApplyOtsuFilter() {
|
|
192
|
+
// kernelSize_ = pre-blur kernel (0 = none, 3+ = Gaussian blur)
|
|
193
|
+
// intensity_ = invert flag (0 = normal THRESH_BINARY, >0 = THRESH_BINARY_INV)
|
|
194
|
+
|
|
195
|
+
// Convert to grayscale if needed
|
|
196
|
+
cv::Mat gray;
|
|
197
|
+
bool wasColor = (input_.channels() > 1);
|
|
198
|
+
|
|
199
|
+
if (wasColor) {
|
|
200
|
+
if (channel_ == "BGR" || channel_ == "BGRA")
|
|
201
|
+
cv::cvtColor(input_, gray, input_.channels() == 4 ? cv::COLOR_BGRA2GRAY : cv::COLOR_BGR2GRAY);
|
|
202
|
+
else
|
|
203
|
+
cv::cvtColor(input_, gray, input_.channels() == 4 ? cv::COLOR_RGBA2GRAY : cv::COLOR_RGB2GRAY);
|
|
204
|
+
} else {
|
|
205
|
+
gray = input_;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Optional pre-blur to reduce noise before thresholding
|
|
209
|
+
if (kernelSize_ >= 3) {
|
|
210
|
+
int k = kernelSize_ | 1; // ensure odd
|
|
211
|
+
cv::GaussianBlur(gray, gray, cv::Size(k, k), 0);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
int threshType = (intensity_ > 0.5) ? cv::THRESH_BINARY_INV : cv::THRESH_BINARY;
|
|
215
|
+
cv::Mat binary;
|
|
216
|
+
cv::threshold(gray, binary, 0, 255, threshType | cv::THRESH_OTSU);
|
|
217
|
+
|
|
218
|
+
// Convert back to original channel count
|
|
219
|
+
if (wasColor) {
|
|
220
|
+
if (channel_ == "BGR" || channel_ == "BGRA") {
|
|
221
|
+
cv::cvtColor(binary, result_, cv::COLOR_GRAY2BGR);
|
|
222
|
+
if (input_.channels() == 4) cv::cvtColor(result_, result_, cv::COLOR_BGR2BGRA);
|
|
223
|
+
} else {
|
|
224
|
+
cv::cvtColor(binary, result_, cv::COLOR_GRAY2RGB);
|
|
225
|
+
if (input_.channels() == 4) cv::cvtColor(result_, result_, cv::COLOR_RGB2RGBA);
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
result_ = binary;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
void ApplyHistogramEqualization() {
|
|
233
|
+
// intensity_ = strength blend factor (0.0 = original, 1.0 = fully equalized)
|
|
234
|
+
cv::Mat equalized;
|
|
235
|
+
|
|
236
|
+
if (input_.channels() == 1) {
|
|
237
|
+
cv::equalizeHist(input_, equalized);
|
|
238
|
+
} else {
|
|
239
|
+
// For color images, convert to YCrCb, equalize Y channel, convert back
|
|
240
|
+
cv::Mat ycrcb;
|
|
241
|
+
if (channel_ == "BGR" || channel_ == "BGRA") {
|
|
242
|
+
cv::Mat bgr = input_;
|
|
243
|
+
if (input_.channels() == 4) cv::cvtColor(input_, bgr, cv::COLOR_BGRA2BGR);
|
|
244
|
+
cv::cvtColor(bgr, ycrcb, cv::COLOR_BGR2YCrCb);
|
|
245
|
+
} else {
|
|
246
|
+
cv::Mat bgr;
|
|
247
|
+
if (input_.channels() == 4) cv::cvtColor(input_, bgr, cv::COLOR_RGBA2BGR);
|
|
248
|
+
else cv::cvtColor(input_, bgr, cv::COLOR_RGB2BGR);
|
|
249
|
+
cv::cvtColor(bgr, ycrcb, cv::COLOR_BGR2YCrCb);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
std::vector<cv::Mat> channels;
|
|
253
|
+
cv::split(ycrcb, channels);
|
|
254
|
+
cv::equalizeHist(channels[0], channels[0]);
|
|
255
|
+
cv::merge(channels, ycrcb);
|
|
256
|
+
|
|
257
|
+
cv::Mat bgr_out;
|
|
258
|
+
cv::cvtColor(ycrcb, bgr_out, cv::COLOR_YCrCb2BGR);
|
|
259
|
+
|
|
260
|
+
if (channel_ == "BGR") {
|
|
261
|
+
equalized = bgr_out;
|
|
262
|
+
} else if (channel_ == "BGRA") {
|
|
263
|
+
cv::cvtColor(bgr_out, equalized, cv::COLOR_BGR2BGRA);
|
|
264
|
+
} else if (channel_ == "RGB") {
|
|
265
|
+
cv::cvtColor(bgr_out, equalized, cv::COLOR_BGR2RGB);
|
|
266
|
+
} else if (channel_ == "RGBA") {
|
|
267
|
+
cv::cvtColor(bgr_out, equalized, cv::COLOR_BGR2RGBA);
|
|
268
|
+
} else {
|
|
269
|
+
equalized = bgr_out;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Blend between original and equalized based on strength
|
|
274
|
+
double strength = std::max(0.0, std::min(intensity_, 1.0));
|
|
275
|
+
if (strength >= 0.999) {
|
|
276
|
+
result_ = equalized;
|
|
277
|
+
} else if (strength <= 0.001) {
|
|
278
|
+
result_ = input_.clone();
|
|
279
|
+
} else {
|
|
280
|
+
cv::addWeighted(equalized, strength, input_, 1.0 - strength, 0, result_);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
void ApplyCLAHE() {
|
|
285
|
+
// Contrast Limited Adaptive Histogram Equalization
|
|
286
|
+
// intensity_ controls clip limit (default 2.0), kernelSize_ controls tile grid
|
|
287
|
+
double clipLimit = std::max(1.0, intensity_ * 4.0); // scale intensity 0-2 -> clipLimit 0-8
|
|
288
|
+
int tileSize = std::max(2, kernelSize_); // use kernel size as tile grid size
|
|
289
|
+
|
|
290
|
+
auto clahe = cv::createCLAHE(clipLimit, cv::Size(tileSize, tileSize));
|
|
291
|
+
|
|
292
|
+
if (input_.channels() == 1) {
|
|
293
|
+
clahe->apply(input_, result_);
|
|
294
|
+
} else {
|
|
295
|
+
cv::Mat ycrcb;
|
|
296
|
+
if (channel_ == "BGR" || channel_ == "BGRA") {
|
|
297
|
+
cv::Mat bgr = input_;
|
|
298
|
+
if (input_.channels() == 4) cv::cvtColor(input_, bgr, cv::COLOR_BGRA2BGR);
|
|
299
|
+
cv::cvtColor(bgr, ycrcb, cv::COLOR_BGR2YCrCb);
|
|
300
|
+
} else {
|
|
301
|
+
cv::Mat bgr;
|
|
302
|
+
if (input_.channels() == 4) cv::cvtColor(input_, bgr, cv::COLOR_RGBA2BGR);
|
|
303
|
+
else cv::cvtColor(input_, bgr, cv::COLOR_RGB2BGR);
|
|
304
|
+
cv::cvtColor(bgr, ycrcb, cv::COLOR_BGR2YCrCb);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
std::vector<cv::Mat> channels;
|
|
308
|
+
cv::split(ycrcb, channels);
|
|
309
|
+
clahe->apply(channels[0], channels[0]);
|
|
310
|
+
cv::merge(channels, ycrcb);
|
|
311
|
+
|
|
312
|
+
cv::Mat bgr_out;
|
|
313
|
+
cv::cvtColor(ycrcb, bgr_out, cv::COLOR_YCrCb2BGR);
|
|
314
|
+
|
|
315
|
+
if (channel_ == "BGR") {
|
|
316
|
+
result_ = bgr_out;
|
|
317
|
+
} else if (channel_ == "BGRA") {
|
|
318
|
+
cv::cvtColor(bgr_out, result_, cv::COLOR_BGR2BGRA);
|
|
319
|
+
} else if (channel_ == "RGB") {
|
|
320
|
+
cv::cvtColor(bgr_out, result_, cv::COLOR_BGR2RGB);
|
|
321
|
+
} else if (channel_ == "RGBA") {
|
|
322
|
+
cv::cvtColor(bgr_out, result_, cv::COLOR_BGR2RGBA);
|
|
323
|
+
} else {
|
|
324
|
+
result_ = bgr_out;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
184
328
|
};
|
|
185
329
|
|
|
186
330
|
/*──────── binding: filter(image, filterType, kernelSize, intensity, [outputFormat], [quality], [pngOptimize], callback) ─*/
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#include <napi.h>
|
|
2
|
+
#include <opencv2/opencv.hpp>
|
|
3
|
+
#include "utils.h"
|
|
4
|
+
|
|
5
|
+
class HeatDiffWorker final : public Napi::AsyncWorker {
|
|
6
|
+
public:
|
|
7
|
+
HeatDiffWorker(Napi::Function cb,
|
|
8
|
+
const Napi::Value& jsImg1,
|
|
9
|
+
const Napi::Value& jsImg2,
|
|
10
|
+
int colormapType,
|
|
11
|
+
int blurSize,
|
|
12
|
+
int threshold,
|
|
13
|
+
std::string outputFormat,
|
|
14
|
+
int quality = 90,
|
|
15
|
+
bool pngOptimize = false)
|
|
16
|
+
: Napi::AsyncWorker(cb),
|
|
17
|
+
colormapType(colormapType),
|
|
18
|
+
blurSize(blurSize),
|
|
19
|
+
threshold(threshold),
|
|
20
|
+
outputFormat(std::move(outputFormat)),
|
|
21
|
+
quality(quality),
|
|
22
|
+
pngOptimize(pngOptimize)
|
|
23
|
+
{
|
|
24
|
+
const int64 t0 = cv::getTickCount();
|
|
25
|
+
mat1 = ConvertToMat(jsImg1);
|
|
26
|
+
mat2 = ConvertToMat(jsImg2);
|
|
27
|
+
format1 = DetectChannelFormatShared(jsImg1, mat1);
|
|
28
|
+
format2 = DetectChannelFormatShared(jsImg2, mat2);
|
|
29
|
+
convertMs = (cv::getTickCount() - t0) / cv::getTickFrequency() * 1e3;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
protected:
|
|
33
|
+
void Execute() override {
|
|
34
|
+
const int64 t0 = cv::getTickCount();
|
|
35
|
+
|
|
36
|
+
// Convert both to grayscale for diff computation
|
|
37
|
+
cv::Mat gray1, gray2;
|
|
38
|
+
|
|
39
|
+
if (mat1.channels() == 1) {
|
|
40
|
+
gray1 = mat1;
|
|
41
|
+
} else if (format1 == "BGR" || format1 == "BGRA") {
|
|
42
|
+
cv::cvtColor(mat1, gray1, mat1.channels() == 4 ? cv::COLOR_BGRA2GRAY : cv::COLOR_BGR2GRAY);
|
|
43
|
+
} else {
|
|
44
|
+
cv::cvtColor(mat1, gray1, mat1.channels() == 4 ? cv::COLOR_RGBA2GRAY : cv::COLOR_RGB2GRAY);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (mat2.channels() == 1) {
|
|
48
|
+
gray2 = mat2;
|
|
49
|
+
} else if (format2 == "BGR" || format2 == "BGRA") {
|
|
50
|
+
cv::cvtColor(mat2, gray2, mat2.channels() == 4 ? cv::COLOR_BGRA2GRAY : cv::COLOR_BGR2GRAY);
|
|
51
|
+
} else {
|
|
52
|
+
cv::cvtColor(mat2, gray2, mat2.channels() == 4 ? cv::COLOR_RGBA2GRAY : cv::COLOR_RGB2GRAY);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Resize if dimensions differ
|
|
56
|
+
if (gray1.size() != gray2.size()) {
|
|
57
|
+
cv::Size targetSize(std::max(gray1.cols, gray2.cols),
|
|
58
|
+
std::max(gray1.rows, gray2.rows));
|
|
59
|
+
if (gray1.size() != targetSize) cv::resize(gray1, gray1, targetSize);
|
|
60
|
+
if (gray2.size() != targetSize) cv::resize(gray2, gray2, targetSize);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Absolute difference
|
|
64
|
+
cv::Mat diff;
|
|
65
|
+
cv::absdiff(gray1, gray2, diff);
|
|
66
|
+
|
|
67
|
+
// Optional Gaussian blur to smooth noise
|
|
68
|
+
if (blurSize > 0) {
|
|
69
|
+
int ksize = blurSize | 1; // ensure odd
|
|
70
|
+
cv::GaussianBlur(diff, diff, cv::Size(ksize, ksize), 0);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Optional threshold to suppress small differences
|
|
74
|
+
if (threshold > 0) {
|
|
75
|
+
cv::threshold(diff, diff, threshold, 0, cv::THRESH_TOZERO);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Apply colormap
|
|
79
|
+
cv::applyColorMap(diff, result, colormapType);
|
|
80
|
+
// applyColorMap outputs BGR
|
|
81
|
+
outputChannel = "BGR";
|
|
82
|
+
|
|
83
|
+
taskMs = (cv::getTickCount() - t0) / cv::getTickFrequency() * 1e3;
|
|
84
|
+
|
|
85
|
+
if (outputFormat != "raw") {
|
|
86
|
+
cv::Mat tmp = PrepareForEncoding(result, outputChannel, outputFormat);
|
|
87
|
+
encodeMs = EncodeToFormat(tmp, encodedBuf, outputFormat, quality, pngOptimize);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
void OnOK() override {
|
|
92
|
+
Napi::Env env = Env();
|
|
93
|
+
Napi::Value jsImg = (outputFormat != "raw")
|
|
94
|
+
? VectorToBuffer(env, std::move(encodedBuf))
|
|
95
|
+
: MatToRawJS(env, result, outputChannel);
|
|
96
|
+
|
|
97
|
+
Napi::Object out = Napi::Object::New(env);
|
|
98
|
+
out.Set("image", jsImg);
|
|
99
|
+
out.Set("timing", MakeTimingJS(env, convertMs, taskMs, encodeMs));
|
|
100
|
+
Callback().Call({env.Null(), out});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private:
|
|
104
|
+
cv::Mat mat1, mat2, result;
|
|
105
|
+
std::string format1, format2, outputChannel;
|
|
106
|
+
int colormapType;
|
|
107
|
+
int blurSize;
|
|
108
|
+
int threshold;
|
|
109
|
+
std::string outputFormat;
|
|
110
|
+
int quality;
|
|
111
|
+
bool pngOptimize;
|
|
112
|
+
double convertMs = 0, taskMs = 0, encodeMs = 0;
|
|
113
|
+
std::vector<uchar> encodedBuf;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
Napi::Value HeatDiff(const Napi::CallbackInfo& info) {
|
|
117
|
+
Napi::Env env = info.Env();
|
|
118
|
+
|
|
119
|
+
if (info.Length() < 3 || !info[info.Length() - 1].IsFunction()) {
|
|
120
|
+
Napi::TypeError::New(env,
|
|
121
|
+
"heatDiff(image1, image2, colormapType, [blurSize], [threshold], [outputFormat], [quality], [pngOptimize], callback)")
|
|
122
|
+
.ThrowAsJavaScriptException();
|
|
123
|
+
return env.Null();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
Napi::Value jsImg1 = info[0];
|
|
127
|
+
Napi::Value jsImg2 = info[1];
|
|
128
|
+
int colormapType = info[2].As<Napi::Number>().Int32Value();
|
|
129
|
+
|
|
130
|
+
int blurSize = 0;
|
|
131
|
+
int threshold = 0;
|
|
132
|
+
std::string outputFormat = "raw";
|
|
133
|
+
int quality = 90;
|
|
134
|
+
bool pngOptimize = false;
|
|
135
|
+
size_t cbIdx = 3;
|
|
136
|
+
|
|
137
|
+
if (info.Length() >= 5) { blurSize = info[3].As<Napi::Number>().Int32Value(); cbIdx = 4; }
|
|
138
|
+
if (info.Length() >= 6) { threshold = info[4].As<Napi::Number>().Int32Value(); cbIdx = 5; }
|
|
139
|
+
if (info.Length() >= 7) { outputFormat = info[5].As<Napi::String>().Utf8Value(); cbIdx = 6; }
|
|
140
|
+
if (info.Length() >= 8) { quality = info[6].As<Napi::Number>().Int32Value(); cbIdx = 7; }
|
|
141
|
+
if (info.Length() >= 9) { pngOptimize = info[7].As<Napi::Boolean>().Value(); cbIdx = 8; }
|
|
142
|
+
|
|
143
|
+
(new HeatDiffWorker(info[cbIdx].As<Napi::Function>(),
|
|
144
|
+
jsImg1, jsImg2, colormapType, blurSize, threshold, outputFormat, quality, pngOptimize))->Queue();
|
|
145
|
+
return env.Undefined();
|
|
146
|
+
}
|
|
@@ -15,6 +15,7 @@ Napi::Value AddBBs(const Napi::CallbackInfo& info);
|
|
|
15
15
|
Napi::Value ImageAlign(const Napi::CallbackInfo& info);
|
|
16
16
|
Napi::Value Draw(const Napi::CallbackInfo& info);
|
|
17
17
|
Napi::Value ColorConvert(const Napi::CallbackInfo& info);
|
|
18
|
+
Napi::Value HeatDiff(const Napi::CallbackInfo& info);
|
|
18
19
|
|
|
19
20
|
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
20
21
|
exports.Set(Napi::String::New(env, "resize"), Napi::Function::New(env, Resize));
|
|
@@ -32,6 +33,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
|
32
33
|
exports.Set(Napi::String::New(env, "imageAlign"), Napi::Function::New(env, ImageAlign));
|
|
33
34
|
exports.Set(Napi::String::New(env, "draw"), Napi::Function::New(env, Draw));
|
|
34
35
|
exports.Set(Napi::String::New(env, "colorConvert"), Napi::Function::New(env, ColorConvert));
|
|
36
|
+
exports.Set(Napi::String::New(env, "heatDiff"), Napi::Function::New(env, HeatDiff));
|
|
35
37
|
return exports;
|
|
36
38
|
}
|
|
37
39
|
|