@rosepetal/node-red-contrib-image-tools 1.4.3 → 1.5.1
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/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 +19 -0
- 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/specialized/image-align.html +243 -16
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +71 -2
- package/node-red-contrib-image-tools/nodes/transform/filter.html +111 -2
- package/node-red-contrib-image-tools/nodes/transform/filter.js +15 -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 +29 -3
- package/rosepetal-image-engine/src/filter.cpp +144 -0
- package/rosepetal-image-engine/src/heat-diff.cpp +146 -0
- package/rosepetal-image-engine/src/image-align.cpp +708 -116
- package/rosepetal-image-engine/src/main.cpp +2 -0
- package/scripts/build-opencv-static.ps1 +7 -2
- package/scripts/build-opencv-static.sh +13 -2
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
overwriteProtection: { value: true },
|
|
30
30
|
maxImages: { value: "" },
|
|
31
31
|
maxImagesType: { value: "num" },
|
|
32
|
+
diskThreshold: { value: 90 },
|
|
32
33
|
active: { value: true },
|
|
33
34
|
debugEnabled: { value: false },
|
|
34
35
|
debugWidth: { value: 200 },
|
|
@@ -501,6 +502,12 @@
|
|
|
501
502
|
<span style="margin-left: 10px; color: #666;">0 or blank keeps all files.</span>
|
|
502
503
|
</div>
|
|
503
504
|
|
|
505
|
+
<div class="form-row">
|
|
506
|
+
<label for="node-input-diskThreshold"><i class="fa fa-hdd-o"></i> Disk Limit</label>
|
|
507
|
+
<input type="number" id="node-input-diskThreshold" min="0" max="100" step="1" style="width: 70px;">
|
|
508
|
+
<span style="margin-left: 10px; color: #666;">% full — skip saving above this. 0 disables check.</span>
|
|
509
|
+
</div>
|
|
510
|
+
|
|
504
511
|
<!-- Debug Configuration -->
|
|
505
512
|
<div class="form-row">
|
|
506
513
|
<label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
|
|
@@ -658,6 +665,12 @@
|
|
|
658
665
|
<span style="margin-left: 10px; color: #666;">0 or blank keeps all files.</span>
|
|
659
666
|
</div>
|
|
660
667
|
|
|
668
|
+
<div class="form-row">
|
|
669
|
+
<label for="node-input-diskThreshold"><i class="fa fa-hdd-o"></i> Disk Limit</label>
|
|
670
|
+
<input type="number" id="node-input-diskThreshold" min="0" max="100" step="1" style="width: 70px;">
|
|
671
|
+
<span style="margin-left: 10px; color: #666;">% full — skip saving above this. 0 disables check.</span>
|
|
672
|
+
</div>
|
|
673
|
+
|
|
661
674
|
<!-- Debug Configuration -->
|
|
662
675
|
<div class="form-row">
|
|
663
676
|
<label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
|
|
@@ -736,6 +749,9 @@
|
|
|
736
749
|
<dt>Max Images <span class="property-type">number | msg | flow | global</span></dt>
|
|
737
750
|
<dd>FIFO retention: deletes oldest files to keep at most this many.</dd>
|
|
738
751
|
|
|
752
|
+
<dt>Disk Limit <span class="property-type">number</span></dt>
|
|
753
|
+
<dd>Percentage of disk usage above which saving is skipped (default 90). Set to 0 to disable the check.</dd>
|
|
754
|
+
|
|
739
755
|
<dt>Active Button <span class="property-type">button</span></dt>
|
|
740
756
|
<dd>Enable/disable saving without modifying the flow.</dd>
|
|
741
757
|
</dl>
|
|
@@ -819,6 +835,9 @@
|
|
|
819
835
|
<dt>Max Images <span class="property-type">number | msg | flow | global</span></dt>
|
|
820
836
|
<dd>FIFO retention: deletes oldest files to keep at most this many.</dd>
|
|
821
837
|
|
|
838
|
+
<dt>Disk Limit <span class="property-type">number</span></dt>
|
|
839
|
+
<dd>Percentage of disk usage above which saving is skipped (default 90). Set to 0 to disable the check.</dd>
|
|
840
|
+
|
|
822
841
|
<dt>Active Button <span class="property-type">button</span></dt>
|
|
823
842
|
<dd>Enable/disable saving without modifying the flow.</dd>
|
|
824
843
|
</dl>
|
|
@@ -44,6 +44,10 @@ module.exports = function(RED) {
|
|
|
44
44
|
|
|
45
45
|
// Initialize node state
|
|
46
46
|
node.active = config.active !== false;
|
|
47
|
+
const diskThresholdPct = parseInt(config.diskThreshold, 10);
|
|
48
|
+
const diskThreshold = (Number.isInteger(diskThresholdPct) && diskThresholdPct > 0 && diskThresholdPct <= 100)
|
|
49
|
+
? diskThresholdPct / 100
|
|
50
|
+
: 0;
|
|
47
51
|
let diskCheckErrorLogged = false;
|
|
48
52
|
|
|
49
53
|
updateNodeStatus();
|
|
@@ -268,8 +272,8 @@ module.exports = function(RED) {
|
|
|
268
272
|
await fs.mkdir(folderPath, { recursive: true });
|
|
269
273
|
|
|
270
274
|
// Disk check
|
|
271
|
-
const diskInfo = await getDiskUsageInfo(folderPath);
|
|
272
|
-
if (diskInfo && diskInfo.usedRatio >=
|
|
275
|
+
const diskInfo = diskThreshold > 0 ? await getDiskUsageInfo(folderPath) : null;
|
|
276
|
+
if (diskInfo && diskInfo.usedRatio >= diskThreshold) {
|
|
273
277
|
const pct = (diskInfo.usedRatio * 100).toFixed(1);
|
|
274
278
|
node.warn(`Storage ${pct}% full, skipping remaining items.`);
|
|
275
279
|
node.status({ fill: 'yellow', shape: 'ring', text: `disk ${pct}% full` });
|
|
@@ -486,8 +490,8 @@ module.exports = function(RED) {
|
|
|
486
490
|
}
|
|
487
491
|
}
|
|
488
492
|
|
|
489
|
-
const diskInfo = await getDiskUsageInfo(folderPath);
|
|
490
|
-
if (diskInfo && diskInfo.usedRatio >=
|
|
493
|
+
const diskInfo = diskThreshold > 0 ? await getDiskUsageInfo(folderPath) : null;
|
|
494
|
+
if (diskInfo && diskInfo.usedRatio >= diskThreshold) {
|
|
491
495
|
const usedPercent = (diskInfo.usedRatio * 100).toFixed(1);
|
|
492
496
|
node.warn(`Storage at "${folderPath}" is ${usedPercent}% full. Skipping image save to avoid exhausting disk space.`);
|
|
493
497
|
node.status({ fill: "yellow", shape: "ring", text: `disk ${usedPercent}% full` });
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
<!-- nodes/specialized/heat-diff.html -->
|
|
2
|
+
|
|
3
|
+
<script type="text/javascript">
|
|
4
|
+
RED.nodes.registerType('rp-heat-diff',{
|
|
5
|
+
category:'RP Image',
|
|
6
|
+
color:'#FF6B6B',
|
|
7
|
+
icon:'font-awesome/fa-fire',
|
|
8
|
+
defaults:{
|
|
9
|
+
name:{value:""},
|
|
10
|
+
image1Path:{value:"payload"}, image1PathType:{value:"msg"},
|
|
11
|
+
image2Path:{value:"goldenImage"}, image2PathType:{value:"msg"},
|
|
12
|
+
outputPath:{value:"payload"},outputPathType:{value:"msg"},
|
|
13
|
+
outputFormat:{value:"raw"},
|
|
14
|
+
outputQuality:{value:90},
|
|
15
|
+
pngOptimize:{value:false},
|
|
16
|
+
webpLossless:{value:false},
|
|
17
|
+
webpSmartSubsample:{value:false},
|
|
18
|
+
webpEffort:{value:""},
|
|
19
|
+
debugEnabled:{value:false},
|
|
20
|
+
debugWidth:{value:200},
|
|
21
|
+
debugWidthType:{value:"num"},
|
|
22
|
+
colormap:{value:"JET"},
|
|
23
|
+
blurSize:{value:0},
|
|
24
|
+
threshold:{value:0}
|
|
25
|
+
},
|
|
26
|
+
inputs:1,outputs:1,
|
|
27
|
+
label:function(){return this.name||"rp-heat-diff";},
|
|
28
|
+
oneditprepare:function(){
|
|
29
|
+
$("#node-input-image1Path").typedInput({
|
|
30
|
+
default:'msg',types:['msg','flow','global'],
|
|
31
|
+
typeField:"#node-input-image1PathType"});
|
|
32
|
+
$("#node-input-image2Path").typedInput({
|
|
33
|
+
default:'msg',types:['msg','flow','global'],
|
|
34
|
+
typeField:"#node-input-image2PathType"});
|
|
35
|
+
$("#node-input-outputPath").typedInput({
|
|
36
|
+
default:'msg',types:['msg','flow','global'],
|
|
37
|
+
typeField:"#node-input-outputPathType"});
|
|
38
|
+
|
|
39
|
+
// Threshold slider
|
|
40
|
+
var $thresholdSlider = $("#node-input-threshold");
|
|
41
|
+
var $thresholdValue = $("#threshold-value");
|
|
42
|
+
function updateThresholdDisplay() {
|
|
43
|
+
$thresholdValue.text($thresholdSlider.val());
|
|
44
|
+
}
|
|
45
|
+
$thresholdSlider.on("input", updateThresholdDisplay);
|
|
46
|
+
updateThresholdDisplay();
|
|
47
|
+
|
|
48
|
+
// Output format visibility
|
|
49
|
+
function updateQualityVisibility(){
|
|
50
|
+
var format = $("#node-input-outputFormat").val();
|
|
51
|
+
$("#quality-row").toggle(format === "jpg" || format === "webp");
|
|
52
|
+
$("#png-optimize-row").toggle(format === "png");
|
|
53
|
+
var isWebp = format === 'webp';
|
|
54
|
+
$("#webp-lossless-row").toggle(isWebp);
|
|
55
|
+
$("#webp-smartsubsample-row").toggle(isWebp);
|
|
56
|
+
$("#webp-effort-row").toggle(isWebp);
|
|
57
|
+
}
|
|
58
|
+
$("#node-input-outputFormat").on("change", updateQualityVisibility);
|
|
59
|
+
updateQualityVisibility();
|
|
60
|
+
|
|
61
|
+
// Debug display
|
|
62
|
+
var debugCheckbox = $('#node-input-debugEnabled');
|
|
63
|
+
var debugWidthRow = $('#debug-width-row');
|
|
64
|
+
$("#node-input-debugWidth").typedInput({
|
|
65
|
+
default: 'num',
|
|
66
|
+
types: ['num', 'msg', 'flow', 'global'],
|
|
67
|
+
typeField: "#node-input-debugWidthType"
|
|
68
|
+
});
|
|
69
|
+
function updateDebugWidthVisibility() {
|
|
70
|
+
debugWidthRow.toggle(debugCheckbox.is(':checked'));
|
|
71
|
+
}
|
|
72
|
+
updateDebugWidthVisibility();
|
|
73
|
+
debugCheckbox.on('change', updateDebugWidthVisibility);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<script type="text/x-red" data-template-name="rp-heat-diff">
|
|
79
|
+
<div class="form-row">
|
|
80
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
81
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
<div class="form-row">
|
|
85
|
+
<label><i class="fa fa-picture-o"></i> Image 1</label>
|
|
86
|
+
<input type="text" id="node-input-image1Path" style="width:70%;">
|
|
87
|
+
<input type="hidden" id="node-input-image1PathType">
|
|
88
|
+
</div>
|
|
89
|
+
|
|
90
|
+
<div class="form-row">
|
|
91
|
+
<label><i class="fa fa-picture-o"></i> Image 2</label>
|
|
92
|
+
<input type="text" id="node-input-image2Path" style="width:70%;">
|
|
93
|
+
<input type="hidden" id="node-input-image2PathType">
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
<div class="form-row">
|
|
97
|
+
<label><i class="fa fa-sign-out"></i> Output</label>
|
|
98
|
+
<input type="text" id="node-input-outputPath" style="width:70%;">
|
|
99
|
+
<input type="hidden" id="node-input-outputPathType">
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<div class="form-row">
|
|
103
|
+
<label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
|
|
104
|
+
<select id="node-input-outputFormat" style="width: 200px;">
|
|
105
|
+
<option value="raw">Raw (fastest)</option>
|
|
106
|
+
<option value="jpg">JPEG</option>
|
|
107
|
+
<option value="png">PNG</option>
|
|
108
|
+
<option value="webp">WebP</option>
|
|
109
|
+
</select>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<div class="form-row" id="quality-row">
|
|
113
|
+
<label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
|
|
114
|
+
<input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
|
|
115
|
+
<span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<div class="form-row" id="png-optimize-row" style="display: none;">
|
|
119
|
+
<label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
|
|
120
|
+
<input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
121
|
+
<label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
|
|
122
|
+
</div>
|
|
123
|
+
<div class="form-row" id="webp-lossless-row" style="display: none;">
|
|
124
|
+
<label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
|
|
125
|
+
<input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
126
|
+
<label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
|
|
127
|
+
</div>
|
|
128
|
+
<div class="form-row" id="webp-smartsubsample-row" style="display: none;">
|
|
129
|
+
<label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
|
|
130
|
+
<input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
131
|
+
<label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
|
|
132
|
+
</div>
|
|
133
|
+
<div class="form-row" id="webp-effort-row" style="display: none;">
|
|
134
|
+
<label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
|
|
135
|
+
<input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
|
|
136
|
+
<span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
|
|
137
|
+
</div>
|
|
138
|
+
|
|
139
|
+
<!-- Debug Configuration -->
|
|
140
|
+
<div class="form-row">
|
|
141
|
+
<label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
|
|
142
|
+
<input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
143
|
+
<label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
|
|
144
|
+
</div>
|
|
145
|
+
<div class="form-row" id="debug-width-row" style="display: none;">
|
|
146
|
+
<label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
|
|
147
|
+
<input type="text" id="node-input-debugWidth" style="width: 120px;">
|
|
148
|
+
<input type="hidden" id="node-input-debugWidthType">
|
|
149
|
+
<span style="margin-left: 10px; color: #666;">pixels</span>
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
<hr/>
|
|
153
|
+
|
|
154
|
+
<div class="form-row">
|
|
155
|
+
<label for="node-input-colormap"><i class="fa fa-fire"></i> Colormap</label>
|
|
156
|
+
<select id="node-input-colormap" style="width: 200px;">
|
|
157
|
+
<option value="JET">Jet (blue-cyan-green-yellow-red)</option>
|
|
158
|
+
<option value="HOT">Hot (black-red-yellow-white)</option>
|
|
159
|
+
<option value="INFERNO">Inferno (black-purple-red-yellow)</option>
|
|
160
|
+
<option value="TURBO">Turbo (improved rainbow)</option>
|
|
161
|
+
<option value="BONE">Bone (blue-tinted grayscale)</option>
|
|
162
|
+
<option value="COOL">Cool (cyan-magenta)</option>
|
|
163
|
+
<option value="RAINBOW">Rainbow</option>
|
|
164
|
+
<option value="OCEAN">Ocean (blue shades)</option>
|
|
165
|
+
<option value="PINK">Pink</option>
|
|
166
|
+
<option value="HSV">HSV</option>
|
|
167
|
+
</select>
|
|
168
|
+
</div>
|
|
169
|
+
|
|
170
|
+
<div class="form-row">
|
|
171
|
+
<label for="node-input-blurSize"><i class="fa fa-circle-o"></i> Blur</label>
|
|
172
|
+
<input type="number" id="node-input-blurSize" min="0" max="99" value="0" style="width: 70px;">
|
|
173
|
+
<span style="margin-left: 10px; color: #666;">Gaussian blur kernel size (0 = off, odd values)</span>
|
|
174
|
+
</div>
|
|
175
|
+
|
|
176
|
+
<div class="form-row">
|
|
177
|
+
<label for="node-input-threshold"><i class="fa fa-filter"></i> Threshold</label>
|
|
178
|
+
<input type="range" id="node-input-threshold" min="0" max="255" value="0" style="width: 200px;">
|
|
179
|
+
<span id="threshold-value" style="margin-left: 10px; font-weight: bold;">0</span>
|
|
180
|
+
<div style="margin-top: 5px; font-size: 10px; color: #999;">
|
|
181
|
+
Pixel differences below this value are suppressed (0 = show all)
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
</script>
|
|
185
|
+
|
|
186
|
+
<script type="text/x-red" data-help-name="rp-heat-diff">
|
|
187
|
+
<p><b>rosepetal-heat-diff</b> computes the absolute pixel difference between two images and visualizes the result as a color-mapped heat image. Useful for comparing a scanned image against a golden reference after alignment.</p>
|
|
188
|
+
|
|
189
|
+
<h3>Details</h3>
|
|
190
|
+
<p>Both input images are converted to grayscale, then the per-pixel absolute difference is computed. The difference map is passed through a configurable colormap to produce a heat visualization where brighter/warmer colors indicate larger differences.</p>
|
|
191
|
+
|
|
192
|
+
<h3>Properties</h3>
|
|
193
|
+
<dl class="message-properties">
|
|
194
|
+
<dt>Image 1 <span class="property-type">string</span></dt>
|
|
195
|
+
<dd>Path to the first image (e.g. the scanned/test image).</dd>
|
|
196
|
+
|
|
197
|
+
<dt>Image 2 <span class="property-type">string</span></dt>
|
|
198
|
+
<dd>Path to the second image (e.g. the golden/reference image).</dd>
|
|
199
|
+
|
|
200
|
+
<dt>Output to <span class="property-type">string</span></dt>
|
|
201
|
+
<dd>Message property where the heat map image will be stored.</dd>
|
|
202
|
+
|
|
203
|
+
<dt>Colormap <span class="property-type">string</span></dt>
|
|
204
|
+
<dd>Color mapping applied to the difference: JET, HOT, INFERNO, TURBO, BONE, COOL, RAINBOW, OCEAN, PINK, HSV.</dd>
|
|
205
|
+
|
|
206
|
+
<dt>Blur <span class="property-type">number</span></dt>
|
|
207
|
+
<dd>Gaussian blur kernel size applied to the difference before colormapping. Smooths noise. 0 to disable.</dd>
|
|
208
|
+
|
|
209
|
+
<dt>Threshold <span class="property-type">number</span></dt>
|
|
210
|
+
<dd>Pixel differences below this value (0-255) are set to zero before colormapping. Suppresses minor noise.</dd>
|
|
211
|
+
</dl>
|
|
212
|
+
|
|
213
|
+
<h3>Inputs</h3>
|
|
214
|
+
<p>Two images in the standard format (raw image object or encoded buffer). Images of different sizes are resized to match the larger one.</p>
|
|
215
|
+
|
|
216
|
+
<h3>Outputs</h3>
|
|
217
|
+
<p>A 3-channel BGR heat map image in the selected output format.</p>
|
|
218
|
+
</script>
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-RED logic for *rosepetal-heat-diff* (C++ backend).
|
|
3
|
+
* Computes absolute difference between two images and applies a colormap
|
|
4
|
+
* to produce a heat map visualization of the differences.
|
|
5
|
+
*
|
|
6
|
+
* Timing fields returned by C++:
|
|
7
|
+
* timing.convertMs . timing.taskMs . timing.encodeMs
|
|
8
|
+
*/
|
|
9
|
+
const { performance } = require('perf_hooks');
|
|
10
|
+
const Cpp = require('../../lib/cpp-bridge.js');
|
|
11
|
+
|
|
12
|
+
// OpenCV COLORMAP constants
|
|
13
|
+
const COLORMAP = {
|
|
14
|
+
'JET': 2,
|
|
15
|
+
'HOT': 11,
|
|
16
|
+
'INFERNO': 14,
|
|
17
|
+
'TURBO': 20,
|
|
18
|
+
'BONE': 1,
|
|
19
|
+
'COOL': 8,
|
|
20
|
+
'RAINBOW': 4,
|
|
21
|
+
'OCEAN': 5,
|
|
22
|
+
'PINK': 10,
|
|
23
|
+
'HSV': 9
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
module.exports = function (RED) {
|
|
27
|
+
const NodeUtils = require('../../lib/node-utils.js')(RED);
|
|
28
|
+
|
|
29
|
+
function HeatDiffNode (config) {
|
|
30
|
+
RED.nodes.createNode(this, config);
|
|
31
|
+
const node = this;
|
|
32
|
+
|
|
33
|
+
node.on('input', async (msg, send, done) => {
|
|
34
|
+
const outputPath = config.outputPath || 'payload';
|
|
35
|
+
const image1Path = config.image1Path || 'payload';
|
|
36
|
+
const image2Path = config.image2Path || 'payload.image2';
|
|
37
|
+
|
|
38
|
+
const { value: image1, error: image1Err } =
|
|
39
|
+
NodeUtils.safeGetMessageProperty(msg, image1Path);
|
|
40
|
+
if (image1Err) {
|
|
41
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
42
|
+
node,
|
|
43
|
+
{
|
|
44
|
+
message: `Invalid image1Path "${image1Path}": ${image1Err.message}`,
|
|
45
|
+
hint: `Ensure "${image1Path}" exists on msg before this node.`,
|
|
46
|
+
details: { image1Path, image2Path, outputPath }
|
|
47
|
+
},
|
|
48
|
+
msg, send, done,
|
|
49
|
+
{ originalPayload: undefined, outputPath: null, outputType: 'preserve' }
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const baseImageForPassthrough = image1;
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const t0 = performance.now();
|
|
57
|
+
node.status({});
|
|
58
|
+
|
|
59
|
+
const { value: image2, error: image2Err } =
|
|
60
|
+
NodeUtils.safeGetMessageProperty(msg, image2Path);
|
|
61
|
+
if (image2Err) {
|
|
62
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
63
|
+
node,
|
|
64
|
+
{
|
|
65
|
+
message: `Invalid image2Path "${image2Path}": ${image2Err.message}`,
|
|
66
|
+
hint: `Ensure "${image2Path}" exists on msg before this node.`,
|
|
67
|
+
details: { image1Path, image2Path, outputPath }
|
|
68
|
+
},
|
|
69
|
+
msg, send, done,
|
|
70
|
+
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'single' }
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const img1 = NodeUtils.validateImageStructure(image1, node);
|
|
75
|
+
if (!img1) {
|
|
76
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
77
|
+
node,
|
|
78
|
+
{
|
|
79
|
+
message: 'First image is invalid or missing',
|
|
80
|
+
hint: `Check that "${image1Path}" contains a valid image.`,
|
|
81
|
+
details: { image1Path, image2Path, outputPath }
|
|
82
|
+
},
|
|
83
|
+
msg, send, done,
|
|
84
|
+
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'single' }
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const img2 = NodeUtils.validateImageStructure(image2, node);
|
|
89
|
+
if (!img2) {
|
|
90
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
91
|
+
node,
|
|
92
|
+
{
|
|
93
|
+
message: 'Second image is invalid or missing',
|
|
94
|
+
hint: `Check that "${image2Path}" contains a valid image.`,
|
|
95
|
+
details: { image1Path, image2Path, outputPath }
|
|
96
|
+
},
|
|
97
|
+
msg, send, done,
|
|
98
|
+
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'single' }
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* Options from the editor */
|
|
103
|
+
const colormapName = config.colormap || 'JET';
|
|
104
|
+
const colormapType = COLORMAP[colormapName] !== undefined ? COLORMAP[colormapName] : 2;
|
|
105
|
+
const blurSize = Math.max(0, parseInt(config.blurSize) || 0);
|
|
106
|
+
const threshold = Math.max(0, Math.min(255, parseInt(config.threshold) || 0));
|
|
107
|
+
const outputFormat = config.outputFormat || 'raw';
|
|
108
|
+
const outputQuality = parseInt(config.outputQuality) || 90;
|
|
109
|
+
const pngOptimize = config.pngOptimize || false;
|
|
110
|
+
const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
|
|
111
|
+
const cppFormat = useSharpWebp ? 'raw' : outputFormat;
|
|
112
|
+
|
|
113
|
+
/* Single call to the C++ addon */
|
|
114
|
+
let { image, timing = {} } =
|
|
115
|
+
await Cpp.heatDiff(img1, img2, colormapType, blurSize, threshold,
|
|
116
|
+
cppFormat, outputQuality, pngOptimize);
|
|
117
|
+
|
|
118
|
+
if (useSharpWebp) {
|
|
119
|
+
image = await NodeUtils.encodeWebpAdvanced(image, config);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* Write result */
|
|
123
|
+
RED.util.setMessageProperty(msg, outputPath, image);
|
|
124
|
+
|
|
125
|
+
/* Status */
|
|
126
|
+
const total = performance.now() - t0;
|
|
127
|
+
|
|
128
|
+
let debugFormat = null;
|
|
129
|
+
const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
|
|
130
|
+
if (debugEnabled) {
|
|
131
|
+
try {
|
|
132
|
+
let debugWidth = NodeUtils.resolveDimension(
|
|
133
|
+
node,
|
|
134
|
+
config.debugWidthType || 'num',
|
|
135
|
+
config.debugWidth,
|
|
136
|
+
msg
|
|
137
|
+
);
|
|
138
|
+
debugWidth = Math.max(1, parseInt(debugWidth) || 200);
|
|
139
|
+
|
|
140
|
+
const debugResult = await NodeUtils.debugImageDisplay(
|
|
141
|
+
image, outputFormat, outputQuality,
|
|
142
|
+
node, debugEnabled, debugWidth
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
if (debugResult) {
|
|
146
|
+
debugFormat = debugResult.formatMessage;
|
|
147
|
+
NodeUtils.setSuccessStatusWithDebug(node, 1, total, timing, debugFormat);
|
|
148
|
+
}
|
|
149
|
+
} catch (debugError) {
|
|
150
|
+
node.warn(`Debug display error: ${debugError.message}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!debugFormat) {
|
|
155
|
+
NodeUtils.setSuccessStatus(node, 1, total, timing);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
NodeUtils.recordPerformanceMetrics(node, msg, timing || {}, total);
|
|
159
|
+
|
|
160
|
+
send(msg);
|
|
161
|
+
done && done();
|
|
162
|
+
} catch (err) {
|
|
163
|
+
NodeUtils.handleNodeErrorWithPassthrough(
|
|
164
|
+
node, err, msg, send, done, 'heat-diff processing',
|
|
165
|
+
{
|
|
166
|
+
originalPayload: baseImageForPassthrough,
|
|
167
|
+
outputPath,
|
|
168
|
+
outputType: 'single',
|
|
169
|
+
context: { image1Path, image2Path, outputPath }
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
RED.nodes.registerType('rp-heat-diff', HeatDiffNode);
|
|
177
|
+
};
|