@rosepetal/node-red-contrib-image-tools 1.1.3
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/.gitattributes +6 -0
- package/.github/workflows/build-prebuild.yml +326 -0
- package/LICENSE +13 -0
- package/README.md +161 -0
- package/artifacts/darwin-arm64/package.json +25 -0
- package/artifacts/linux-arm64/package.json +26 -0
- package/artifacts/linux-x64/package.json +26 -0
- package/artifacts/linuxmusl-x64/package.json +26 -0
- package/assets/flow_time_example.gif +0 -0
- package/assets/nodes/io/array-in-demo.gif +0 -0
- package/assets/nodes/io/array-out-demo.gif +0 -0
- package/assets/nodes/io/array-select-demo.gif +0 -0
- package/assets/nodes/io/image-in-demo.gif +0 -0
- package/assets/nodes/mix/concat-demo.gif +0 -0
- package/assets/nodes/mix/mosaic-demo.gif +0 -0
- package/assets/nodes/transform/crop-demo.gif +0 -0
- package/assets/nodes/transform/filter-demo.gif +0 -0
- package/assets/nodes/transform/padding-demo.gif +0 -0
- package/assets/nodes/transform/resize-demo.gif +0 -0
- package/assets/nodes/transform/rotate-demo.gif +0 -0
- package/docs/nodes/blend/add-mask.md +275 -0
- package/docs/nodes/blend/add-masks.md +284 -0
- package/docs/nodes/blend/blend.md +248 -0
- package/docs/nodes/io/array-in.md +119 -0
- package/docs/nodes/io/array-out.md +150 -0
- package/docs/nodes/io/array-select.md +157 -0
- package/docs/nodes/io/image-in.md +131 -0
- package/docs/nodes/io/image-out.md +179 -0
- package/docs/nodes/io/queue.md +57 -0
- package/docs/nodes/io/save-file.md +30 -0
- package/docs/nodes/mix/advanced-mosaic.md +108 -0
- package/docs/nodes/mix/concat.md +127 -0
- package/docs/nodes/mix/mosaic.md +146 -0
- package/docs/nodes/specialized/cropBB.md +271 -0
- package/docs/nodes/specialized/image-align.md +426 -0
- package/docs/nodes/transform/crop.md +132 -0
- package/docs/nodes/transform/draw.md +77 -0
- package/docs/nodes/transform/filter.md +84 -0
- package/docs/nodes/transform/padding.md +133 -0
- package/docs/nodes/transform/resize.md +158 -0
- package/docs/nodes/transform/rotate.md +121 -0
- package/docs/nodes/util/block-detect.md +46 -0
- package/install.sh +144 -0
- package/node-red-contrib-image-tools/lib/cpp-bridge.js +224 -0
- package/node-red-contrib-image-tools/lib/node-utils.js +529 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +590 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +241 -0
- package/node-red-contrib-image-tools/nodes/blend/add-mask.html +449 -0
- package/node-red-contrib-image-tools/nodes/blend/add-mask.js +170 -0
- package/node-red-contrib-image-tools/nodes/blend/add-masks.html +703 -0
- package/node-red-contrib-image-tools/nodes/blend/add-masks.js +321 -0
- package/node-red-contrib-image-tools/nodes/blend/blend.html +552 -0
- package/node-red-contrib-image-tools/nodes/blend/blend.js +124 -0
- package/node-red-contrib-image-tools/nodes/io/array-in.html +110 -0
- package/node-red-contrib-image-tools/nodes/io/array-in.js +113 -0
- package/node-red-contrib-image-tools/nodes/io/array-out.html +125 -0
- package/node-red-contrib-image-tools/nodes/io/array-out.js +213 -0
- package/node-red-contrib-image-tools/nodes/io/array-select.html +156 -0
- package/node-red-contrib-image-tools/nodes/io/array-select.js +187 -0
- package/node-red-contrib-image-tools/nodes/io/folder-in.html +248 -0
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +335 -0
- package/node-red-contrib-image-tools/nodes/io/image-in.html +146 -0
- package/node-red-contrib-image-tools/nodes/io/image-in.js +143 -0
- package/node-red-contrib-image-tools/nodes/io/image-out.html +506 -0
- package/node-red-contrib-image-tools/nodes/io/image-out.js +545 -0
- package/node-red-contrib-image-tools/nodes/io/queue.html +119 -0
- package/node-red-contrib-image-tools/nodes/io/queue.js +191 -0
- package/node-red-contrib-image-tools/nodes/io/save-file.html +243 -0
- package/node-red-contrib-image-tools/nodes/io/save-file.js +440 -0
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +2149 -0
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +195 -0
- package/node-red-contrib-image-tools/nodes/mix/concat.html +390 -0
- package/node-red-contrib-image-tools/nodes/mix/concat.js +112 -0
- package/node-red-contrib-image-tools/nodes/mix/mosaic.html +550 -0
- package/node-red-contrib-image-tools/nodes/mix/mosaic.js +151 -0
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +268 -0
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +277 -0
- package/node-red-contrib-image-tools/nodes/specialized/image-align.html +528 -0
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +306 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.html +410 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.js +149 -0
- package/node-red-contrib-image-tools/nodes/transform/draw.html +719 -0
- package/node-red-contrib-image-tools/nodes/transform/draw.js +509 -0
- package/node-red-contrib-image-tools/nodes/transform/filter.html +578 -0
- package/node-red-contrib-image-tools/nodes/transform/filter.js +177 -0
- package/node-red-contrib-image-tools/nodes/transform/padding.html +475 -0
- package/node-red-contrib-image-tools/nodes/transform/padding.js +142 -0
- package/node-red-contrib-image-tools/nodes/transform/resize.html +429 -0
- package/node-red-contrib-image-tools/nodes/transform/resize.js +162 -0
- package/node-red-contrib-image-tools/nodes/transform/rotate.html +299 -0
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +141 -0
- package/node-red-contrib-image-tools/nodes/util/block-detect.html +85 -0
- package/node-red-contrib-image-tools/nodes/util/block-detect.js +136 -0
- package/node-red-contrib-image-tools/nodes/util/clean-debug.html +201 -0
- package/node-red-contrib-image-tools/nodes/util/clean-debug.js +393 -0
- package/node-red-contrib-image-tools/package.json +64 -0
- package/npm/darwin-arm64/lib/.gitkeep +1 -0
- package/npm/darwin-arm64/package.json +25 -0
- package/npm/darwin-x64/lib/.gitkeep +1 -0
- package/npm/darwin-x64/package.json +25 -0
- package/npm/linux-arm64/lib/.gitkeep +1 -0
- package/npm/linux-arm64/package.json +26 -0
- package/npm/linux-x64/lib/.gitkeep +1 -0
- package/npm/linux-x64/package.json +26 -0
- package/npm/linuxmusl-x64/lib/.gitkeep +1 -0
- package/npm/linuxmusl-x64/package.json +26 -0
- package/npm/win32-x64/lib/.gitkeep +1 -0
- package/npm/win32-x64/package.json +25 -0
- package/package.json +74 -0
- package/rosepetal-image-engine/binding.gyp +153 -0
- package/rosepetal-image-engine/package.json +19 -0
- package/rosepetal-image-engine/src/add-bbs.cpp +433 -0
- package/rosepetal-image-engine/src/add-mask.cpp +240 -0
- package/rosepetal-image-engine/src/add-masks.cpp +638 -0
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +740 -0
- package/rosepetal-image-engine/src/blend.cpp +200 -0
- package/rosepetal-image-engine/src/concat.cpp +329 -0
- package/rosepetal-image-engine/src/crop.cpp +139 -0
- package/rosepetal-image-engine/src/draw.cpp +414 -0
- package/rosepetal-image-engine/src/filter.cpp +230 -0
- package/rosepetal-image-engine/src/filters/kernels.h +171 -0
- package/rosepetal-image-engine/src/image-align.cpp +551 -0
- package/rosepetal-image-engine/src/main.cpp +36 -0
- package/rosepetal-image-engine/src/mosaic.cpp +373 -0
- package/rosepetal-image-engine/src/padding.cpp +124 -0
- package/rosepetal-image-engine/src/resize.cpp +210 -0
- package/rosepetal-image-engine/src/rotate.cpp +177 -0
- package/rosepetal-image-engine/src/utils.h +563 -0
- package/rosepetal-image-engine/test-formats.js +119 -0
- package/scripts/build-opencv-static.ps1 +166 -0
- package/scripts/build-opencv-static.sh +147 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
<!-- nodes/blend/add-mask.html -->
|
|
2
|
+
|
|
3
|
+
<script type="text/javascript">
|
|
4
|
+
RED.nodes.registerType('add-mask',{
|
|
5
|
+
category:'RP Image',
|
|
6
|
+
color:'#DDA0DD',
|
|
7
|
+
icon:'font-awesome/fa-mask',
|
|
8
|
+
defaults:{
|
|
9
|
+
name:{value:""},
|
|
10
|
+
imagePath:{value:"payload.image"}, imagePathType:{value:"msg"},
|
|
11
|
+
polygonPath:{value:"payload.default.masks[0].mask[0]"}, polygonPathType:{value:"msg"},
|
|
12
|
+
outputPath:{value:"payload"},outputPathType:{value:"msg"},
|
|
13
|
+
outputFormat:{value:"raw"},
|
|
14
|
+
outputQuality:{value:90},
|
|
15
|
+
pngOptimize:{value:false},
|
|
16
|
+
// Debug configuration
|
|
17
|
+
debugEnabled:{value:false},
|
|
18
|
+
debugWidth:{value:200},
|
|
19
|
+
debugWidthType:{value:"num"},
|
|
20
|
+
maskStrength:{value:50}, // 0-100%, default 50%
|
|
21
|
+
fillColor:{value:"#ffffff"} // Default white for polygon fill
|
|
22
|
+
},
|
|
23
|
+
inputs:1,outputs:1,
|
|
24
|
+
label:function(){return this.name||"add-mask";},
|
|
25
|
+
oneditprepare:function(){
|
|
26
|
+
/* path typedInputs */
|
|
27
|
+
$("#node-input-imagePath").typedInput({
|
|
28
|
+
default:'msg',types:['msg','flow','global'],
|
|
29
|
+
typeField:"#node-input-imagePathType"});
|
|
30
|
+
$("#node-input-polygonPath").typedInput({
|
|
31
|
+
default:'msg',types:['msg','flow','global'],
|
|
32
|
+
typeField:"#node-input-polygonPathType"});
|
|
33
|
+
$("#node-input-outputPath").typedInput({
|
|
34
|
+
default:'msg',types:['msg','flow','global'],
|
|
35
|
+
typeField:"#node-input-outputPathType"});
|
|
36
|
+
|
|
37
|
+
/* mask strength slider functionality */
|
|
38
|
+
const $strengthSlider = $("#node-input-maskStrength");
|
|
39
|
+
const $strengthValue = $("#strength-value");
|
|
40
|
+
const $strengthLabel = $("#strength-label");
|
|
41
|
+
|
|
42
|
+
function updateStrengthDisplay() {
|
|
43
|
+
const value = parseInt($strengthSlider.val());
|
|
44
|
+
$strengthValue.text(value + "%");
|
|
45
|
+
|
|
46
|
+
// Update label to show effect
|
|
47
|
+
if (value === 0) {
|
|
48
|
+
$strengthLabel.text("No mask effect - original image only");
|
|
49
|
+
} else if (value === 100) {
|
|
50
|
+
$strengthLabel.text("Full mask effect - maximum blending");
|
|
51
|
+
} else if (value === 50) {
|
|
52
|
+
$strengthLabel.text("Balanced mask application");
|
|
53
|
+
} else {
|
|
54
|
+
$strengthLabel.text(value + "% mask strength");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
$strengthSlider.on("input", updateStrengthDisplay);
|
|
59
|
+
updateStrengthDisplay(); // initial state
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
function updateQualityVisibility(){
|
|
63
|
+
const format = $("#node-input-outputFormat").val();
|
|
64
|
+
$("#quality-row").toggle(format === "jpg" || format === "webp");
|
|
65
|
+
$("#png-optimize-row").toggle(format === "png");
|
|
66
|
+
}
|
|
67
|
+
$("#node-input-outputFormat").on("change", updateQualityVisibility);
|
|
68
|
+
updateQualityVisibility(); // initial state
|
|
69
|
+
|
|
70
|
+
// === Debug Display Logic ===
|
|
71
|
+
const debugCheckbox = $('#node-input-debugEnabled');
|
|
72
|
+
const debugWidthRow = $('#debug-width-row');
|
|
73
|
+
|
|
74
|
+
// Initialize debug width TypedInput
|
|
75
|
+
$("#node-input-debugWidth").typedInput({
|
|
76
|
+
default: 'num',
|
|
77
|
+
types: ['num', 'msg', 'flow', 'global'],
|
|
78
|
+
typeField: "#node-input-debugWidthType"
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Function to toggle debug width visibility
|
|
82
|
+
function updateDebugWidthVisibility() {
|
|
83
|
+
if (debugCheckbox.is(':checked')) {
|
|
84
|
+
debugWidthRow.show();
|
|
85
|
+
} else {
|
|
86
|
+
debugWidthRow.hide();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Initialize debug state on node open
|
|
91
|
+
updateDebugWidthVisibility();
|
|
92
|
+
|
|
93
|
+
// Handle debug checkbox changes
|
|
94
|
+
debugCheckbox.on('change', function() {
|
|
95
|
+
const enabled = this.checked;
|
|
96
|
+
updateDebugWidthVisibility();
|
|
97
|
+
// Store debug state for runtime access
|
|
98
|
+
$('#node-input-debugEnabled').data('debug-enabled', enabled);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Debug image display renderer - shared across all image processing nodes
|
|
104
|
+
if (!window.debugImageRendererInitialized) {
|
|
105
|
+
window.debugImageRendererInitialized = true;
|
|
106
|
+
|
|
107
|
+
(function() {
|
|
108
|
+
var isSubscribed = false;
|
|
109
|
+
|
|
110
|
+
function subscribeToDebugImages() {
|
|
111
|
+
if (isSubscribed || typeof RED === 'undefined' || !RED.comms) return;
|
|
112
|
+
isSubscribed = true;
|
|
113
|
+
|
|
114
|
+
RED.comms.subscribe('debug-image', function(event, data) {
|
|
115
|
+
if (!data || !data.id) return;
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
renderDebugImage(data);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
console.warn('Debug image render error:', err);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function renderDebugImage(data) {
|
|
126
|
+
const nodeId = data.id;
|
|
127
|
+
const base64Data = data.data;
|
|
128
|
+
const format = data.format || 'unknown';
|
|
129
|
+
const mimeType = data.mimeType || 'jpeg';
|
|
130
|
+
|
|
131
|
+
if (!base64Data) {
|
|
132
|
+
removeDebugImage(nodeId);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const nodeElement = document.getElementById(nodeId);
|
|
137
|
+
if (!nodeElement) return;
|
|
138
|
+
|
|
139
|
+
let debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
140
|
+
|
|
141
|
+
if (!debugContainer) {
|
|
142
|
+
// Create SVG foreignObject to embed HTML content in SVG
|
|
143
|
+
debugContainer = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
|
|
144
|
+
debugContainer.id = 'debug-img-container-' + nodeId;
|
|
145
|
+
debugContainer.setAttribute('x', '70');
|
|
146
|
+
debugContainer.setAttribute('y', '5');
|
|
147
|
+
debugContainer.setAttribute('width', '120');
|
|
148
|
+
debugContainer.setAttribute('height', '120');
|
|
149
|
+
debugContainer.style.overflow = 'visible';
|
|
150
|
+
|
|
151
|
+
// Create simple image directly inside foreignObject
|
|
152
|
+
const img = document.createElement('img');
|
|
153
|
+
img.id = 'debug-img-' + nodeId;
|
|
154
|
+
img.style.width = '100%';
|
|
155
|
+
img.style.height = 'auto';
|
|
156
|
+
img.style.display = 'block';
|
|
157
|
+
img.style.cursor = 'pointer';
|
|
158
|
+
img.style.maxHeight = '100px';
|
|
159
|
+
img.style.maxWidth = '100px';
|
|
160
|
+
|
|
161
|
+
img.onclick = function() {
|
|
162
|
+
removeDebugImage(nodeId);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
debugContainer.appendChild(img);
|
|
166
|
+
nodeElement.appendChild(debugContainer);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const img = document.getElementById('debug-img-' + nodeId);
|
|
170
|
+
|
|
171
|
+
if (img) {
|
|
172
|
+
img.src = `data:image/${mimeType};base64,${base64Data}`;
|
|
173
|
+
img.title = 'Debug image (click to hide)';
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function removeDebugImage(nodeId) {
|
|
178
|
+
const debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
179
|
+
if (debugContainer) {
|
|
180
|
+
debugContainer.remove();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function initializeWhenReady() {
|
|
185
|
+
if (typeof RED !== 'undefined' && RED.comms) {
|
|
186
|
+
subscribeToDebugImages();
|
|
187
|
+
|
|
188
|
+
// Clean up orphaned debug images periodically
|
|
189
|
+
setInterval(function() {
|
|
190
|
+
const debugContainers = document.querySelectorAll('[id^="debug-img-container-"]');
|
|
191
|
+
debugContainers.forEach(container => {
|
|
192
|
+
const nodeId = container.id.replace('debug-img-container-', '');
|
|
193
|
+
const nodeElement = document.getElementById(nodeId);
|
|
194
|
+
if (!nodeElement) {
|
|
195
|
+
container.remove();
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}, 5000);
|
|
199
|
+
} else {
|
|
200
|
+
setTimeout(initializeWhenReady, 100);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (document.readyState === 'loading') {
|
|
205
|
+
document.addEventListener('DOMContentLoaded', initializeWhenReady);
|
|
206
|
+
} else {
|
|
207
|
+
initializeWhenReady();
|
|
208
|
+
}
|
|
209
|
+
})();
|
|
210
|
+
}
|
|
211
|
+
</script>
|
|
212
|
+
|
|
213
|
+
<script type="text/x-red" data-template-name="add-mask">
|
|
214
|
+
<div class="form-row">
|
|
215
|
+
<label><i class="fa fa-picture-o"></i> Image</label>
|
|
216
|
+
<input type="text" id="node-input-imagePath" style="width:70%;">
|
|
217
|
+
<input type="hidden" id="node-input-imagePathType">
|
|
218
|
+
</div>
|
|
219
|
+
|
|
220
|
+
<div class="form-row">
|
|
221
|
+
<label><i class="fa fa-draw-polygon"></i> Polygon Path</label>
|
|
222
|
+
<input type="text" id="node-input-polygonPath" style="width:70%;">
|
|
223
|
+
<input type="hidden" id="node-input-polygonPathType">
|
|
224
|
+
</div>
|
|
225
|
+
|
|
226
|
+
<div class="form-row">
|
|
227
|
+
<label><i class="fa fa-sign-out"></i> Output</label>
|
|
228
|
+
<input type="text" id="node-input-outputPath" style="width:70%;">
|
|
229
|
+
<input type="hidden" id="node-input-outputPathType">
|
|
230
|
+
</div>
|
|
231
|
+
|
|
232
|
+
<div class="form-row">
|
|
233
|
+
<label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
|
|
234
|
+
<select id="node-input-outputFormat" style="width: 200px;">
|
|
235
|
+
<option value="raw">Raw (fastest)</option>
|
|
236
|
+
<option value="jpg">JPEG</option>
|
|
237
|
+
<option value="png">PNG</option>
|
|
238
|
+
<option value="webp">WebP</option>
|
|
239
|
+
</select>
|
|
240
|
+
</div>
|
|
241
|
+
|
|
242
|
+
<div class="form-row" id="quality-row">
|
|
243
|
+
<label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
|
|
244
|
+
<input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
|
|
245
|
+
<span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
|
|
246
|
+
</div>
|
|
247
|
+
|
|
248
|
+
<div class="form-row" id="png-optimize-row" style="display: none;">
|
|
249
|
+
<label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
|
|
250
|
+
<input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
251
|
+
<label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
|
|
252
|
+
</div>
|
|
253
|
+
|
|
254
|
+
<!-- Debug Configuration -->
|
|
255
|
+
<div class="form-row">
|
|
256
|
+
<label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
|
|
257
|
+
<input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
258
|
+
<label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
|
|
259
|
+
</div>
|
|
260
|
+
<div class="form-row" id="debug-width-row" style="display: none;">
|
|
261
|
+
<label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
|
|
262
|
+
<input type="text" id="node-input-debugWidth" style="width: 120px;">
|
|
263
|
+
<input type="hidden" id="node-input-debugWidthType">
|
|
264
|
+
<span style="margin-left: 10px; color: #666;">pixels</span>
|
|
265
|
+
</div>
|
|
266
|
+
|
|
267
|
+
<hr/>
|
|
268
|
+
|
|
269
|
+
<div class="form-row">
|
|
270
|
+
<label for="node-input-maskStrength"><i class="fa fa-adjust"></i> Mask Strength</label>
|
|
271
|
+
<input type="range" id="node-input-maskStrength" min="0" max="100" value="50" style="width: 200px;">
|
|
272
|
+
<span id="strength-value" style="margin-left: 10px; font-weight: bold;">50%</span>
|
|
273
|
+
<div style="margin-top: 5px; font-size: 11px; color: #666;" id="strength-label">
|
|
274
|
+
Balanced mask application
|
|
275
|
+
</div>
|
|
276
|
+
<div style="margin-top: 5px; font-size: 10px; color: #999;">
|
|
277
|
+
0% = No mask effect | 50% = Balanced | 100% = Full mask effect
|
|
278
|
+
</div>
|
|
279
|
+
</div>
|
|
280
|
+
|
|
281
|
+
<div class="form-row">
|
|
282
|
+
<label for="node-input-fillColor"><i class="fa fa-eyedropper"></i> Fill Color</label>
|
|
283
|
+
<input type="color" id="node-input-fillColor" value="#ffffff" style="width: 60px; height: 30px;">
|
|
284
|
+
<span style="margin-left: 10px; color: #666;">Color to fill polygon mask</span>
|
|
285
|
+
</div>
|
|
286
|
+
</script>
|
|
287
|
+
|
|
288
|
+
<script type="text/x-red" data-help-name="add-mask">
|
|
289
|
+
<p><b>rosepetal-add-mask</b> applies a polygon-based mask to a base image using weighted blending with configurable mask strength and fill color. This node generates masks from polygon coordinates (from object detection results) and blends them with the original image.</p>
|
|
290
|
+
|
|
291
|
+
<h3>Details</h3>
|
|
292
|
+
<p>This node performs high-performance polygon-based blending using OpenCV. A binary mask is generated from polygon coordinates using OpenCV's fillPoly function, then applied to the base image as blending weights. The polygon coordinates are expected to be normalized (0-1 range) and are automatically scaled to match the image dimensions.</p>
|
|
293
|
+
|
|
294
|
+
<h3>Properties</h3>
|
|
295
|
+
<dl class="message-properties">
|
|
296
|
+
<dt>Image <span class="property-type">string</span></dt>
|
|
297
|
+
<dd>Message property path containing the base image to which the mask will be applied. Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
|
|
298
|
+
|
|
299
|
+
<dt>Polygon Path <span class="property-type">string</span></dt>
|
|
300
|
+
<dd>Message property path containing the polygon coordinates array. Expected format: array of [x, y] coordinate pairs with normalized values (0.0-1.0 range). Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
|
|
301
|
+
|
|
302
|
+
<dt>Output to <span class="property-type">string</span></dt>
|
|
303
|
+
<dd>Message property path where the masked image will be stored. Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
|
|
304
|
+
|
|
305
|
+
<dt>Output Format <span class="property-type">string</span></dt>
|
|
306
|
+
<dd>Format for the output image: <code>raw</code> (fastest), <code>jpg</code>, <code>png</code>, or <code>webp</code>.</dd>
|
|
307
|
+
|
|
308
|
+
<dt>Quality <span class="property-type">number</span></dt>
|
|
309
|
+
<dd>Compression quality (1-100) for JPEG and WebP formats. Only visible when JPG or WebP is selected.</dd>
|
|
310
|
+
|
|
311
|
+
<dt>Mask Strength <span class="property-type">number</span></dt>
|
|
312
|
+
<dd>Intensity of mask application from 0% to 100%. Controls how strongly the mask affects the final result.</dd>
|
|
313
|
+
|
|
314
|
+
<dt>Fill Color <span class="property-type">color</span></dt>
|
|
315
|
+
<dd>Color to fill the polygon mask (default: white #ffffff). This becomes the mask color for blending with the original image.</dd>
|
|
316
|
+
</dl>
|
|
317
|
+
|
|
318
|
+
<h3>Inputs</h3>
|
|
319
|
+
<p>Requires a base image and polygon coordinates from the specified message property paths:</p>
|
|
320
|
+
<ul>
|
|
321
|
+
<li><b>Base Image:</b> From the path specified in "Image" field (default: <code>msg.payload.image</code>)</li>
|
|
322
|
+
<li><b>Polygon Coordinates:</b> From the path specified in "Polygon Path" field (default: <code>msg.payload.default.masks[0].mask[0]</code>)</li>
|
|
323
|
+
</ul>
|
|
324
|
+
|
|
325
|
+
<p>The base image should follow the standard format:</p>
|
|
326
|
+
<pre>{
|
|
327
|
+
data: Buffer, // Raw pixel data or encoded file buffer
|
|
328
|
+
width: number, // Image width in pixels
|
|
329
|
+
height: number, // Image height in pixels
|
|
330
|
+
channels: number, // Channel count (1=grayscale, 3=RGB, 4=RGBA)
|
|
331
|
+
colorSpace: string, // "GRAY", "RGB", "RGBA", "BGR", "BGRA"
|
|
332
|
+
dtype: string // "uint8", "uint16", "float32"
|
|
333
|
+
}</pre>
|
|
334
|
+
<p>File buffers (JPEG, PNG, WebP, BMP) are automatically detected and decoded.</p>
|
|
335
|
+
|
|
336
|
+
<p>The polygon coordinates should be an array of [x, y] coordinate pairs:</p>
|
|
337
|
+
<pre>[
|
|
338
|
+
[0.30859375, 0.5797164440155029],
|
|
339
|
+
[0.314453125, 0.5797164440155029],
|
|
340
|
+
[0.31640625, 0.5818142294883728],
|
|
341
|
+
// ... more coordinate pairs
|
|
342
|
+
]</pre>
|
|
343
|
+
<p>All coordinates must be normalized to 0.0-1.0 range (percentage of image dimensions).</p>
|
|
344
|
+
|
|
345
|
+
<h3>Outputs</h3>
|
|
346
|
+
<p>Produces a single masked image in the specified format:</p>
|
|
347
|
+
<ul>
|
|
348
|
+
<li><b>Raw format:</b> Complete image object with pixel data and metadata</li>
|
|
349
|
+
<li><b>Encoded formats (JPG/PNG/WebP):</b> File buffer ready for storage or transmission</li>
|
|
350
|
+
</ul>
|
|
351
|
+
<p>Output dimensions match the input image dimensions. The generated mask is automatically sized to match the base image.</p>
|
|
352
|
+
|
|
353
|
+
<h3>Masking Behavior</h3>
|
|
354
|
+
<h4>Polygon-to-Mask Conversion Process</h4>
|
|
355
|
+
<ol>
|
|
356
|
+
<li><b>Coordinate Scaling:</b> Converts normalized coordinates (0-1) to pixel coordinates</li>
|
|
357
|
+
<li><b>Mask Generation:</b> Uses OpenCV fillPoly to create binary mask from polygon</li>
|
|
358
|
+
<li><b>Color Application:</b> Fills polygon area with the specified fill color</li>
|
|
359
|
+
<li><b>Blending:</b> Applies the mask as blending weights scaled by mask strength</li>
|
|
360
|
+
</ol>
|
|
361
|
+
|
|
362
|
+
<h4>Mathematical Formula</h4>
|
|
363
|
+
<p>The masking operation uses weighted blending:</p>
|
|
364
|
+
<pre>pixel_coords = polygon_coords × [image_width, image_height]
|
|
365
|
+
binary_mask = fillPoly(pixel_coords, fill_color)
|
|
366
|
+
blend_weights = mask_strength × normalized_mask
|
|
367
|
+
result = image × (1 - blend_weights) + mask_color × blend_weights</pre>
|
|
368
|
+
|
|
369
|
+
<h3>Automatic Image Processing</h3>
|
|
370
|
+
<h4>Dimension Handling</h4>
|
|
371
|
+
<ul>
|
|
372
|
+
<li><b>Same Size:</b> Direct processing with no resizing</li>
|
|
373
|
+
<li><b>Different Sizes:</b> Both images resized to max(width1, width2) × max(height1, height2)</li>
|
|
374
|
+
<li><b>Aspect Ratio:</b> Preserved during resize operations to prevent distortion</li>
|
|
375
|
+
</ul>
|
|
376
|
+
|
|
377
|
+
<h4>Color Space Conversion</h4>
|
|
378
|
+
<ul>
|
|
379
|
+
<li><b>Automatic Detection:</b> Color spaces detected from image metadata or inferred from channel count</li>
|
|
380
|
+
<li><b>Smart Conversion:</b> Images converted to compatible format for processing</li>
|
|
381
|
+
<li><b>Quality Preservation:</b> Lossless conversions maintain image quality throughout processing</li>
|
|
382
|
+
</ul>
|
|
383
|
+
|
|
384
|
+
<h3>Examples</h3>
|
|
385
|
+
<h4>Logo Watermarking</h4>
|
|
386
|
+
<p>Apply a logo with transparent background:</p>
|
|
387
|
+
<ul>
|
|
388
|
+
<li>Image: Main content</li>
|
|
389
|
+
<li>Mask: Logo with black background</li>
|
|
390
|
+
<li>Background Color: Black (#000000)</li>
|
|
391
|
+
<li>Mask Strength: 80-90% for strong branding</li>
|
|
392
|
+
<li>Tolerance: 5-15% for clean edges</li>
|
|
393
|
+
</ul>
|
|
394
|
+
|
|
395
|
+
<h4>Artistic Overlays</h4>
|
|
396
|
+
<p>Create artistic effects with texture masks:</p>
|
|
397
|
+
<ul>
|
|
398
|
+
<li>Image: Photo or artwork</li>
|
|
399
|
+
<li>Mask: Texture or pattern with background</li>
|
|
400
|
+
<li>Background Color: Dominant background color</li>
|
|
401
|
+
<li>Mask Strength: 30-60% for subtle effects</li>
|
|
402
|
+
<li>Tolerance: 20-40% for smooth blending</li>
|
|
403
|
+
</ul>
|
|
404
|
+
|
|
405
|
+
<h4>Selective Enhancement</h4>
|
|
406
|
+
<p>Apply effects to specific image regions:</p>
|
|
407
|
+
<ul>
|
|
408
|
+
<li>Image: Original photo</li>
|
|
409
|
+
<li>Mask: Region selector (white areas to enhance)</li>
|
|
410
|
+
<li>Background Color: Black (#000000)</li>
|
|
411
|
+
<li>Mask Strength: 70-100% for strong effects</li>
|
|
412
|
+
<li>Tolerance: 5-10% for precise control</li>
|
|
413
|
+
</ul>
|
|
414
|
+
|
|
415
|
+
<h3>Node Interactions</h3>
|
|
416
|
+
<ul>
|
|
417
|
+
<li><b>Upstream:</b> Works with <code>image-in</code>, <code>array-in</code>, or any nodes producing image/mask pairs</li>
|
|
418
|
+
<li><b>Downstream:</b> Connect to image writers, further processing nodes, or display components</li>
|
|
419
|
+
<li><b>Chaining:</b> Can be chained for complex multi-layer masking effects</li>
|
|
420
|
+
<li><b>Flow Integration:</b> Supports flow and global context for cross-node data sharing</li>
|
|
421
|
+
</ul>
|
|
422
|
+
|
|
423
|
+
<h3>Error Handling</h3>
|
|
424
|
+
<ul>
|
|
425
|
+
<li><b>Missing Images:</b> Clear warnings when either input image is missing or invalid</li>
|
|
426
|
+
<li><b>Dimension Mismatch:</b> Automatic resizing with performance-optimized interpolation</li>
|
|
427
|
+
<li><b>Color Space Issues:</b> Intelligent conversion with format preservation</li>
|
|
428
|
+
<li><b>Memory Management:</b> Efficient processing of large images with automatic cleanup</li>
|
|
429
|
+
<li><b>Parameter Validation:</b> Range checking for all numeric parameters</li>
|
|
430
|
+
</ul>
|
|
431
|
+
|
|
432
|
+
<h3>Performance</h3>
|
|
433
|
+
<ul>
|
|
434
|
+
<li><b>C++ Backend:</b> High-performance OpenCV implementation with SIMD optimizations</li>
|
|
435
|
+
<li><b>Memory Efficient:</b> Minimal memory allocation with intelligent buffer reuse</li>
|
|
436
|
+
<li><b>Parallel Processing:</b> Multi-threaded operations for large images</li>
|
|
437
|
+
<li><b>Status Timing:</b> Real-time metrics showing conversion, processing, and encoding times</li>
|
|
438
|
+
<li><b>Optimized Builds:</b> Compiled with <code>-O3</code>, <code>-march=native</code> for maximum performance</li>
|
|
439
|
+
</ul>
|
|
440
|
+
|
|
441
|
+
<h3>Advanced Features</h3>
|
|
442
|
+
<ul>
|
|
443
|
+
<li><b>Live Preview:</b> Debug mode shows masked result in real-time</li>
|
|
444
|
+
<li><b>Color Precision:</b> Advanced color matching with configurable tolerance</li>
|
|
445
|
+
<li><b>Batch Processing:</b> Efficient handling of multiple image/mask pairs</li>
|
|
446
|
+
<li><b>Context Integration:</b> Full support for flow and global context storage</li>
|
|
447
|
+
<li><b>Format Flexibility:</b> Seamless conversion between raw and encoded formats</li>
|
|
448
|
+
</ul>
|
|
449
|
+
</script>
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node‑RED logic for *rosepetal‑add‑mask* (C++ backend).
|
|
3
|
+
* Applies a polygon-based mask to a base image using weighted blending with
|
|
4
|
+
* configurable mask strength and colors.
|
|
5
|
+
*
|
|
6
|
+
* Timing fields returned by C++:
|
|
7
|
+
* timing.convertMs · timing.taskMs · timing.encodeMs
|
|
8
|
+
* …and the node status shows: OK … (conv X | task Y ms)
|
|
9
|
+
*/
|
|
10
|
+
const { performance } = require('perf_hooks');
|
|
11
|
+
const Cpp = require('../../lib/cpp-bridge.js');
|
|
12
|
+
|
|
13
|
+
module.exports = function (RED) {
|
|
14
|
+
const NodeUtils = require('../../lib/node-utils.js')(RED);
|
|
15
|
+
|
|
16
|
+
function AddMaskNode (config) {
|
|
17
|
+
RED.nodes.createNode(this, config);
|
|
18
|
+
const node = this;
|
|
19
|
+
|
|
20
|
+
node.on('input', async (msg, send, done) => {
|
|
21
|
+
// Capture original payload for error passthrough
|
|
22
|
+
const outputPath = config.outputPath || 'payload';
|
|
23
|
+
const originalPayload = RED.util.getMessageProperty(msg, outputPath);
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const t0 = performance.now();
|
|
27
|
+
node.status({}); // clear status
|
|
28
|
+
|
|
29
|
+
/* ▸ Read image and polygon from message -------------------------- */
|
|
30
|
+
// Get base image and polygon coordinates from specified paths
|
|
31
|
+
const image = RED.util.getMessageProperty(msg, config.imagePath || 'payload.image');
|
|
32
|
+
const polygon = RED.util.getMessageProperty(msg, config.polygonPath || 'payload.default.masks[0].mask[0]');
|
|
33
|
+
|
|
34
|
+
// Validate base image
|
|
35
|
+
const baseImg = NodeUtils.validateImageStructure(image, node);
|
|
36
|
+
if (!baseImg) {
|
|
37
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
38
|
+
node, 'Base image is invalid or missing', msg, send, done,
|
|
39
|
+
{ originalPayload, outputPath, outputType: 'single' }
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Validate polygon coordinates
|
|
44
|
+
if (!Array.isArray(polygon)) {
|
|
45
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
46
|
+
node, 'Polygon coordinates must be an array', msg, send, done,
|
|
47
|
+
{ originalPayload, outputPath, outputType: 'single' }
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (polygon.length === 0) {
|
|
52
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
53
|
+
node, 'Polygon coordinates array is empty', msg, send, done,
|
|
54
|
+
{ originalPayload, outputPath, outputType: 'single' }
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Validate polygon coordinate format
|
|
59
|
+
for (let i = 0; i < polygon.length; i++) {
|
|
60
|
+
const point = polygon[i];
|
|
61
|
+
if (!Array.isArray(point) || point.length !== 2) {
|
|
62
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
63
|
+
node, `Invalid polygon coordinate at index ${i}: expected [x, y] pair`, msg, send, done,
|
|
64
|
+
{ originalPayload, outputPath, outputType: 'single' }
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const [x, y] = point;
|
|
69
|
+
if (typeof x !== 'number' || typeof y !== 'number') {
|
|
70
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
71
|
+
node, `Invalid polygon coordinate at index ${i}: coordinates must be numbers`, msg, send, done,
|
|
72
|
+
{ originalPayload, outputPath, outputType: 'single' }
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (x < 0 || x > 1 || y < 0 || y > 1) {
|
|
77
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
78
|
+
node, `Invalid polygon coordinate at index ${i}: coordinates must be in range [0, 1]`, msg, send, done,
|
|
79
|
+
{ originalPayload, outputPath, outputType: 'single' }
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* ▸ Options from the editor -------------------------------------- */
|
|
85
|
+
const maskStrength = Math.max(0, Math.min(100, parseInt(config.maskStrength) || 50)) / 100.0;
|
|
86
|
+
const outputFormat = config.outputFormat || 'raw';
|
|
87
|
+
const outputQuality = parseInt(config.outputQuality) || 90;
|
|
88
|
+
const pngOptimize = config.pngOptimize || false;
|
|
89
|
+
|
|
90
|
+
// Color processing
|
|
91
|
+
const fillColor = config.fillColor || '#ffffff';
|
|
92
|
+
|
|
93
|
+
// Convert hex color to RGB values
|
|
94
|
+
let fillR = 255, fillG = 255, fillB = 255; // Default white
|
|
95
|
+
if (fillColor.startsWith('#') && fillColor.length === 7) {
|
|
96
|
+
fillR = parseInt(fillColor.substr(1, 2), 16);
|
|
97
|
+
fillG = parseInt(fillColor.substr(3, 2), 16);
|
|
98
|
+
fillB = parseInt(fillColor.substr(5, 2), 16);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* ▸ Single call to the C++ addon --------------------------------- */
|
|
102
|
+
const { image: result, timing = {} } =
|
|
103
|
+
await Cpp.addMask(
|
|
104
|
+
baseImg,
|
|
105
|
+
polygon,
|
|
106
|
+
maskStrength,
|
|
107
|
+
fillR, fillG, fillB,
|
|
108
|
+
outputFormat,
|
|
109
|
+
outputQuality,
|
|
110
|
+
pngOptimize
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
/* ▸ Write the result back to msg ---------------------------------- */
|
|
114
|
+
RED.util.setMessageProperty(msg, config.outputPath || 'payload', result);
|
|
115
|
+
|
|
116
|
+
/* ▸ Status: standardized success formatting ----------------------- */
|
|
117
|
+
const total = performance.now() - t0;
|
|
118
|
+
|
|
119
|
+
// Debug image display
|
|
120
|
+
let debugFormat = null;
|
|
121
|
+
if (config.debugEnabled) {
|
|
122
|
+
try {
|
|
123
|
+
// Resolve and validate debug width
|
|
124
|
+
let debugWidth = NodeUtils.resolveDimension(
|
|
125
|
+
node,
|
|
126
|
+
config.debugWidthType,
|
|
127
|
+
config.debugWidth,
|
|
128
|
+
msg
|
|
129
|
+
);
|
|
130
|
+
debugWidth = Math.max(1, parseInt(debugWidth) || 200); // Ensure positive, default 200
|
|
131
|
+
|
|
132
|
+
const debugResult = await NodeUtils.debugImageDisplay(
|
|
133
|
+
result,
|
|
134
|
+
outputFormat,
|
|
135
|
+
outputQuality,
|
|
136
|
+
node,
|
|
137
|
+
true,
|
|
138
|
+
debugWidth
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
if (debugResult) {
|
|
142
|
+
debugFormat = debugResult.formatMessage;
|
|
143
|
+
// Update node status with debug info
|
|
144
|
+
NodeUtils.setSuccessStatusWithDebug(node, 1, total, timing, debugFormat);
|
|
145
|
+
}
|
|
146
|
+
} catch (debugError) {
|
|
147
|
+
node.warn(`Debug display error: ${debugError.message}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Set regular status if debug not enabled or failed
|
|
152
|
+
if (!debugFormat) {
|
|
153
|
+
NodeUtils.setSuccessStatus(node, 1, total, timing);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
NodeUtils.recordPerformanceMetrics(node, msg, timing || {}, total);
|
|
157
|
+
|
|
158
|
+
send(msg);
|
|
159
|
+
done && done();
|
|
160
|
+
} catch (err) {
|
|
161
|
+
NodeUtils.handleNodeErrorWithPassthrough(
|
|
162
|
+
node, err, msg, send, done, 'add-mask processing',
|
|
163
|
+
{ originalPayload, outputPath, outputType: 'single' }
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
RED.nodes.registerType('add-mask', AddMaskNode);
|
|
170
|
+
};
|