@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,703 @@
|
|
|
1
|
+
<!-- nodes/blend/add-masks.html -->
|
|
2
|
+
|
|
3
|
+
<script type="text/javascript">
|
|
4
|
+
RED.nodes.registerType('add-masks',{
|
|
5
|
+
category:'RP Image',
|
|
6
|
+
color:'#DDA0DD',
|
|
7
|
+
icon:'font-awesome/fa-masks',
|
|
8
|
+
defaults:{
|
|
9
|
+
name:{value:""},
|
|
10
|
+
imagePath:{value:"image"}, imagePathType:{value:"msg"},
|
|
11
|
+
masksPath:{value:"array"}, masksPathType:{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
|
+
globalMaskStrength:{value:50}, // 0-100%, default 50%
|
|
21
|
+
classColorMappings:{value:[]} // Array of {className, color} objects
|
|
22
|
+
},
|
|
23
|
+
inputs:1,outputs:1,
|
|
24
|
+
label:function(){return this.name||"add-masks";},
|
|
25
|
+
oneditprepare:function(){
|
|
26
|
+
const node = this;
|
|
27
|
+
let classMappingIndex = 0;
|
|
28
|
+
|
|
29
|
+
/* path typedInputs */
|
|
30
|
+
$("#node-input-imagePath").typedInput({
|
|
31
|
+
default:'msg',types:['msg','flow','global'],
|
|
32
|
+
typeField:"#node-input-imagePathType"});
|
|
33
|
+
$("#node-input-masksPath").typedInput({
|
|
34
|
+
default:'msg',types:['msg','flow','global'],
|
|
35
|
+
typeField:"#node-input-masksPathType"});
|
|
36
|
+
$("#node-input-outputPath").typedInput({
|
|
37
|
+
default:'msg',types:['msg','flow','global'],
|
|
38
|
+
typeField:"#node-input-outputPathType"});
|
|
39
|
+
|
|
40
|
+
/* mask strength slider functionality */
|
|
41
|
+
const $strengthSlider = $("#node-input-globalMaskStrength");
|
|
42
|
+
const $strengthValue = $("#strength-value");
|
|
43
|
+
const $strengthLabel = $("#strength-label");
|
|
44
|
+
|
|
45
|
+
function updateStrengthDisplay() {
|
|
46
|
+
const value = parseInt($strengthSlider.val());
|
|
47
|
+
$strengthValue.text(value + "%");
|
|
48
|
+
|
|
49
|
+
// Update label to show effect
|
|
50
|
+
if (value === 0) {
|
|
51
|
+
$strengthLabel.text("No mask effect - original image only");
|
|
52
|
+
} else if (value === 100) {
|
|
53
|
+
$strengthLabel.text("Full mask effect - maximum blending");
|
|
54
|
+
} else if (value === 50) {
|
|
55
|
+
$strengthLabel.text("Balanced mask application");
|
|
56
|
+
} else {
|
|
57
|
+
$strengthLabel.text(value + "% mask strength");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
$strengthSlider.on("input", updateStrengthDisplay);
|
|
62
|
+
updateStrengthDisplay(); // initial state
|
|
63
|
+
|
|
64
|
+
function updateQualityVisibility(){
|
|
65
|
+
const format = $("#node-input-outputFormat").val();
|
|
66
|
+
$("#quality-row").toggle(format === "jpg" || format === "webp");
|
|
67
|
+
$("#png-optimize-row").toggle(format === "png");
|
|
68
|
+
}
|
|
69
|
+
$("#node-input-outputFormat").on("change", updateQualityVisibility);
|
|
70
|
+
updateQualityVisibility(); // initial state
|
|
71
|
+
|
|
72
|
+
// === Debug Display Logic ===
|
|
73
|
+
const debugCheckbox = $('#node-input-debugEnabled');
|
|
74
|
+
const debugWidthRow = $('#debug-width-row');
|
|
75
|
+
|
|
76
|
+
// Initialize debug width TypedInput
|
|
77
|
+
$("#node-input-debugWidth").typedInput({
|
|
78
|
+
default: 'num',
|
|
79
|
+
types: ['num', 'msg', 'flow', 'global'],
|
|
80
|
+
typeField: "#node-input-debugWidthType"
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Function to toggle debug width visibility
|
|
84
|
+
function updateDebugWidthVisibility() {
|
|
85
|
+
if (debugCheckbox.is(':checked')) {
|
|
86
|
+
debugWidthRow.show();
|
|
87
|
+
} else {
|
|
88
|
+
debugWidthRow.hide();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Initialize debug state on node open
|
|
93
|
+
updateDebugWidthVisibility();
|
|
94
|
+
|
|
95
|
+
// Handle debug checkbox changes
|
|
96
|
+
debugCheckbox.on('change', function() {
|
|
97
|
+
const enabled = this.checked;
|
|
98
|
+
updateDebugWidthVisibility();
|
|
99
|
+
// Store debug state for runtime access
|
|
100
|
+
$('#node-input-debugEnabled').data('debug-enabled', enabled);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// === Dynamic Class Color Mapping Logic ===
|
|
104
|
+
|
|
105
|
+
// Initialize class mappings from saved config
|
|
106
|
+
function initializeClassMappings() {
|
|
107
|
+
const mappings = node.classColorMappings || [];
|
|
108
|
+
mappings.forEach(mapping => {
|
|
109
|
+
addClassMappingRow(mapping.className, mapping.color);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (mappings.length === 0) {
|
|
113
|
+
addClassMappingRow(); // Add one empty row by default
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Initialize drag-and-drop after all rows are created
|
|
117
|
+
setupDragAndDrop();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Add new class mapping row
|
|
121
|
+
function addClassMappingRow(className = '', color = '#ff0000') {
|
|
122
|
+
const container = $('#class-mappings-container');
|
|
123
|
+
const index = classMappingIndex++;
|
|
124
|
+
|
|
125
|
+
const rowHtml = `
|
|
126
|
+
<div class="class-mapping-row" data-index="${index}" style="margin-bottom: 10px; display: flex; align-items: center;">
|
|
127
|
+
<span class="drag-handle" style="cursor: grab; margin-right: 8px; color: #888; padding: 4px;">
|
|
128
|
+
<i class="fa fa-bars"></i>
|
|
129
|
+
</span>
|
|
130
|
+
<input type="text" placeholder="Class name (e.g., dog)"
|
|
131
|
+
class="class-name-input" value="${className}"
|
|
132
|
+
style="width: 180px; margin-right: 10px;">
|
|
133
|
+
<input type="color" class="class-color-input" value="${color}"
|
|
134
|
+
style="width: 60px; height: 30px; margin-right: 10px;">
|
|
135
|
+
<button type="button" class="remove-class-mapping editor-button"
|
|
136
|
+
style="margin-right: 10px;">
|
|
137
|
+
<i class="fa fa-trash"></i>
|
|
138
|
+
</button>
|
|
139
|
+
<span class="duplicate-warning" style="color: red; display: none; margin-right: 10px;">
|
|
140
|
+
⚠️ Duplicate
|
|
141
|
+
</span>
|
|
142
|
+
<span class="color-conflict-warning" style="color: orange; display: none;">
|
|
143
|
+
⚠️ Similar color
|
|
144
|
+
</span>
|
|
145
|
+
</div>
|
|
146
|
+
`;
|
|
147
|
+
|
|
148
|
+
container.append(rowHtml);
|
|
149
|
+
updateEventHandlers();
|
|
150
|
+
setupDragAndDrop();
|
|
151
|
+
validateClassNames();
|
|
152
|
+
validateColors();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Remove class mapping row
|
|
156
|
+
function removeClassMappingRow(index) {
|
|
157
|
+
$(`.class-mapping-row[data-index="${index}"]`).remove();
|
|
158
|
+
validateClassNames();
|
|
159
|
+
validateColors();
|
|
160
|
+
|
|
161
|
+
// Ensure at least one row exists
|
|
162
|
+
if ($('.class-mapping-row').length === 0) {
|
|
163
|
+
addClassMappingRow();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Update event handlers for dynamic elements
|
|
168
|
+
function updateEventHandlers() {
|
|
169
|
+
// Remove existing handlers to prevent duplicates
|
|
170
|
+
$('.remove-class-mapping').off('click');
|
|
171
|
+
$('.class-name-input').off('input');
|
|
172
|
+
$('.class-color-input').off('change');
|
|
173
|
+
|
|
174
|
+
// Add class mapping button
|
|
175
|
+
$('#add-class-mapping').off('click').on('click', function() {
|
|
176
|
+
addClassMappingRow();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Remove class mapping button
|
|
180
|
+
$('.remove-class-mapping').on('click', function() {
|
|
181
|
+
const index = $(this).closest('.class-mapping-row').data('index');
|
|
182
|
+
removeClassMappingRow(index);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Class name validation
|
|
186
|
+
$('.class-name-input').on('input', function() {
|
|
187
|
+
validateClassNames();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// Color change validation
|
|
191
|
+
$('.class-color-input').on('change', function() {
|
|
192
|
+
validateColors();
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Validate class names for duplicates
|
|
197
|
+
function validateClassNames() {
|
|
198
|
+
const classNames = [];
|
|
199
|
+
const inputs = $('.class-name-input');
|
|
200
|
+
|
|
201
|
+
inputs.each(function() {
|
|
202
|
+
const value = $(this).val().trim();
|
|
203
|
+
const row = $(this).closest('.class-mapping-row');
|
|
204
|
+
const warning = row.find('.duplicate-warning');
|
|
205
|
+
|
|
206
|
+
if (value && classNames.includes(value)) {
|
|
207
|
+
warning.show();
|
|
208
|
+
} else {
|
|
209
|
+
warning.hide();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (value) classNames.push(value);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Validate colors for conflicts (similar colors)
|
|
217
|
+
function validateColors() {
|
|
218
|
+
const colors = [];
|
|
219
|
+
const inputs = $('.class-color-input');
|
|
220
|
+
|
|
221
|
+
inputs.each(function() {
|
|
222
|
+
const color = $(this).val();
|
|
223
|
+
const row = $(this).closest('.class-mapping-row');
|
|
224
|
+
const warning = row.find('.color-conflict-warning');
|
|
225
|
+
|
|
226
|
+
// Check for similar colors (simplified RGB distance)
|
|
227
|
+
const hasSimilar = colors.some(existingColor => {
|
|
228
|
+
return calculateColorDistance(color, existingColor) < 50; // Threshold for "similar"
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
if (hasSimilar) {
|
|
232
|
+
warning.show();
|
|
233
|
+
} else {
|
|
234
|
+
warning.hide();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
colors.push(color);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Calculate simple RGB distance between two hex colors
|
|
242
|
+
function calculateColorDistance(color1, color2) {
|
|
243
|
+
const rgb1 = hexToRgb(color1);
|
|
244
|
+
const rgb2 = hexToRgb(color2);
|
|
245
|
+
|
|
246
|
+
if (!rgb1 || !rgb2) return 255; // Max distance for invalid colors
|
|
247
|
+
|
|
248
|
+
return Math.sqrt(
|
|
249
|
+
Math.pow(rgb1.r - rgb2.r, 2) +
|
|
250
|
+
Math.pow(rgb1.g - rgb2.g, 2) +
|
|
251
|
+
Math.pow(rgb1.b - rgb2.b, 2)
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function hexToRgb(hex) {
|
|
256
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
257
|
+
return result ? {
|
|
258
|
+
r: parseInt(result[1], 16),
|
|
259
|
+
g: parseInt(result[2], 16),
|
|
260
|
+
b: parseInt(result[3], 16)
|
|
261
|
+
} : null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Setup drag-and-drop for reordering class mappings (mouse-based for smooth sliding)
|
|
265
|
+
function setupDragAndDrop() {
|
|
266
|
+
const container = $('#class-mappings-container');
|
|
267
|
+
let dragState = null;
|
|
268
|
+
|
|
269
|
+
// Add CSS styles for drag states (only once)
|
|
270
|
+
if (!$('#drag-drop-styles').length) {
|
|
271
|
+
$('head').append(`
|
|
272
|
+
<style id="drag-drop-styles">
|
|
273
|
+
.class-mapping-row {
|
|
274
|
+
transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
|
|
275
|
+
position: relative;
|
|
276
|
+
z-index: 0;
|
|
277
|
+
user-select: none;
|
|
278
|
+
}
|
|
279
|
+
.class-mapping-row.dragging {
|
|
280
|
+
opacity: 0.95;
|
|
281
|
+
background: #f8f9fa;
|
|
282
|
+
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
|
283
|
+
z-index: 100;
|
|
284
|
+
}
|
|
285
|
+
.class-mapping-row.no-transition {
|
|
286
|
+
transition: none !important;
|
|
287
|
+
}
|
|
288
|
+
.drag-handle {
|
|
289
|
+
cursor: grab;
|
|
290
|
+
}
|
|
291
|
+
.drag-handle:active {
|
|
292
|
+
cursor: grabbing;
|
|
293
|
+
}
|
|
294
|
+
</style>
|
|
295
|
+
`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Remove existing handlers to prevent duplicates
|
|
299
|
+
container.off('.mapping');
|
|
300
|
+
|
|
301
|
+
// MOUSEDOWN on drag handle - Start drag
|
|
302
|
+
container.on('mousedown.mapping', '.drag-handle', function(e) {
|
|
303
|
+
e.preventDefault();
|
|
304
|
+
const row = $(this).closest('.class-mapping-row');
|
|
305
|
+
const rows = container.find('.class-mapping-row').toArray();
|
|
306
|
+
|
|
307
|
+
// Store drag state
|
|
308
|
+
dragState = {
|
|
309
|
+
element: row[0],
|
|
310
|
+
startY: e.clientY,
|
|
311
|
+
startIndex: rows.indexOf(row[0]),
|
|
312
|
+
rowHeight: row.outerHeight(true),
|
|
313
|
+
rows: rows,
|
|
314
|
+
currentIndex: rows.indexOf(row[0])
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
row.addClass('dragging');
|
|
318
|
+
|
|
319
|
+
// Add document listeners for mouse movement
|
|
320
|
+
$(document).on('mousemove.drag', onMouseMove);
|
|
321
|
+
$(document).on('mouseup.drag', onMouseUp);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
function onMouseMove(e) {
|
|
325
|
+
if (!dragState) return;
|
|
326
|
+
|
|
327
|
+
const deltaY = e.clientY - dragState.startY;
|
|
328
|
+
const moveCount = Math.round(deltaY / dragState.rowHeight);
|
|
329
|
+
const newIndex = Math.max(0, Math.min(
|
|
330
|
+
dragState.startIndex + moveCount,
|
|
331
|
+
dragState.rows.length - 1
|
|
332
|
+
));
|
|
333
|
+
|
|
334
|
+
// Apply transforms to create sliding effect
|
|
335
|
+
dragState.rows.forEach((row, i) => {
|
|
336
|
+
if (row === dragState.element) return;
|
|
337
|
+
|
|
338
|
+
const $row = $(row);
|
|
339
|
+
if (i > dragState.startIndex && i <= newIndex) {
|
|
340
|
+
// Items between original and new position (dragging down) - slide UP
|
|
341
|
+
$row.css('transform', `translateY(-${dragState.rowHeight}px)`);
|
|
342
|
+
} else if (i < dragState.startIndex && i >= newIndex) {
|
|
343
|
+
// Items between new and original position (dragging up) - slide DOWN
|
|
344
|
+
$row.css('transform', `translateY(${dragState.rowHeight}px)`);
|
|
345
|
+
} else {
|
|
346
|
+
$row.css('transform', '');
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
dragState.currentIndex = newIndex;
|
|
351
|
+
|
|
352
|
+
// Move the dragged item to follow cursor
|
|
353
|
+
$(dragState.element).css('transform', `translateY(${deltaY}px)`);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function onMouseUp() {
|
|
357
|
+
if (!dragState) return;
|
|
358
|
+
|
|
359
|
+
const $dragged = $(dragState.element);
|
|
360
|
+
const finalIndex = dragState.currentIndex;
|
|
361
|
+
|
|
362
|
+
// Remove transforms from all items
|
|
363
|
+
dragState.rows.forEach(row => $(row).css('transform', ''));
|
|
364
|
+
$dragged.removeClass('dragging');
|
|
365
|
+
|
|
366
|
+
// Reorder DOM if position changed
|
|
367
|
+
if (finalIndex !== dragState.startIndex) {
|
|
368
|
+
$dragged.addClass('no-transition');
|
|
369
|
+
const rows = container.find('.class-mapping-row');
|
|
370
|
+
|
|
371
|
+
if (finalIndex < dragState.startIndex) {
|
|
372
|
+
// Moving up - insert before the target
|
|
373
|
+
rows.eq(finalIndex).before($dragged);
|
|
374
|
+
} else {
|
|
375
|
+
// Moving down - insert after the target
|
|
376
|
+
rows.eq(finalIndex).after($dragged);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Re-enable transitions after DOM update
|
|
380
|
+
requestAnimationFrame(() => $dragged.removeClass('no-transition'));
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Cleanup
|
|
384
|
+
$(document).off('.drag');
|
|
385
|
+
dragState = null;
|
|
386
|
+
updateRowIndices();
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Update row indices after reordering
|
|
391
|
+
function updateRowIndices() {
|
|
392
|
+
$('.class-mapping-row').each(function(index) {
|
|
393
|
+
$(this).attr('data-index', index);
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Save configuration before closing
|
|
398
|
+
function saveClassMappings() {
|
|
399
|
+
const mappings = [];
|
|
400
|
+
$('.class-mapping-row').each(function() {
|
|
401
|
+
const className = $(this).find('.class-name-input').val().trim();
|
|
402
|
+
const color = $(this).find('.class-color-input').val();
|
|
403
|
+
|
|
404
|
+
if (className) { // Only save non-empty class names
|
|
405
|
+
mappings.push({ className, color });
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
node.classColorMappings = mappings;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
// Initialize UI
|
|
414
|
+
initializeClassMappings();
|
|
415
|
+
},
|
|
416
|
+
oneditsave: function() {
|
|
417
|
+
// Save class color mappings when dialog is closed
|
|
418
|
+
const mappings = [];
|
|
419
|
+
$('.class-mapping-row').each(function() {
|
|
420
|
+
const className = $(this).find('.class-name-input').val().trim();
|
|
421
|
+
const color = $(this).find('.class-color-input').val();
|
|
422
|
+
|
|
423
|
+
if (className) { // Only save non-empty class names
|
|
424
|
+
mappings.push({ className, color });
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
this.classColorMappings = mappings;
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
// Debug image display renderer - shared across all image processing nodes
|
|
433
|
+
if (!window.debugImageRendererInitialized) {
|
|
434
|
+
window.debugImageRendererInitialized = true;
|
|
435
|
+
|
|
436
|
+
(function() {
|
|
437
|
+
var isSubscribed = false;
|
|
438
|
+
|
|
439
|
+
function subscribeToDebugImages() {
|
|
440
|
+
if (isSubscribed || typeof RED === 'undefined' || !RED.comms) return;
|
|
441
|
+
isSubscribed = true;
|
|
442
|
+
|
|
443
|
+
RED.comms.subscribe('debug-image', function(event, data) {
|
|
444
|
+
if (!data || !data.id) return;
|
|
445
|
+
|
|
446
|
+
try {
|
|
447
|
+
renderDebugImage(data);
|
|
448
|
+
} catch (err) {
|
|
449
|
+
console.warn('Debug image render error:', err);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function renderDebugImage(data) {
|
|
455
|
+
const nodeId = data.id;
|
|
456
|
+
const base64Data = data.data;
|
|
457
|
+
const format = data.format || 'unknown';
|
|
458
|
+
const mimeType = data.mimeType || 'jpeg';
|
|
459
|
+
|
|
460
|
+
if (!base64Data) {
|
|
461
|
+
removeDebugImage(nodeId);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const nodeElement = document.getElementById(nodeId);
|
|
466
|
+
if (!nodeElement) return;
|
|
467
|
+
|
|
468
|
+
let debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
469
|
+
|
|
470
|
+
if (!debugContainer) {
|
|
471
|
+
// Create SVG foreignObject to embed HTML content in SVG
|
|
472
|
+
debugContainer = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
|
|
473
|
+
debugContainer.id = 'debug-img-container-' + nodeId;
|
|
474
|
+
debugContainer.setAttribute('x', '70');
|
|
475
|
+
debugContainer.setAttribute('y', '5');
|
|
476
|
+
debugContainer.setAttribute('width', '120');
|
|
477
|
+
debugContainer.setAttribute('height', '120');
|
|
478
|
+
debugContainer.style.overflow = 'visible';
|
|
479
|
+
|
|
480
|
+
// Create simple image directly inside foreignObject
|
|
481
|
+
const img = document.createElement('img');
|
|
482
|
+
img.id = 'debug-img-' + nodeId;
|
|
483
|
+
img.style.width = '100%';
|
|
484
|
+
img.style.height = 'auto';
|
|
485
|
+
img.style.display = 'block';
|
|
486
|
+
img.style.cursor = 'pointer';
|
|
487
|
+
img.style.maxHeight = '100px';
|
|
488
|
+
img.style.maxWidth = '100px';
|
|
489
|
+
|
|
490
|
+
img.onclick = function() {
|
|
491
|
+
removeDebugImage(nodeId);
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
debugContainer.appendChild(img);
|
|
495
|
+
nodeElement.appendChild(debugContainer);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const img = document.getElementById('debug-img-' + nodeId);
|
|
499
|
+
|
|
500
|
+
if (img) {
|
|
501
|
+
img.src = `data:image/${mimeType};base64,${base64Data}`;
|
|
502
|
+
img.title = 'Debug image (click to hide)';
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function removeDebugImage(nodeId) {
|
|
507
|
+
const debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
508
|
+
if (debugContainer) {
|
|
509
|
+
debugContainer.remove();
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function initializeWhenReady() {
|
|
514
|
+
if (typeof RED !== 'undefined' && RED.comms) {
|
|
515
|
+
subscribeToDebugImages();
|
|
516
|
+
|
|
517
|
+
// Clean up orphaned debug images periodically
|
|
518
|
+
setInterval(function() {
|
|
519
|
+
const debugContainers = document.querySelectorAll('[id^="debug-img-container-"]');
|
|
520
|
+
debugContainers.forEach(container => {
|
|
521
|
+
const nodeId = container.id.replace('debug-img-container-', '');
|
|
522
|
+
const nodeElement = document.getElementById(nodeId);
|
|
523
|
+
if (!nodeElement) {
|
|
524
|
+
container.remove();
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
}, 5000);
|
|
528
|
+
} else {
|
|
529
|
+
setTimeout(initializeWhenReady, 100);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if (document.readyState === 'loading') {
|
|
534
|
+
document.addEventListener('DOMContentLoaded', initializeWhenReady);
|
|
535
|
+
} else {
|
|
536
|
+
initializeWhenReady();
|
|
537
|
+
}
|
|
538
|
+
})();
|
|
539
|
+
}
|
|
540
|
+
</script>
|
|
541
|
+
|
|
542
|
+
<script type="text/x-red" data-template-name="add-masks">
|
|
543
|
+
<div class="form-row">
|
|
544
|
+
<label><i class="fa fa-picture-o"></i> Image</label>
|
|
545
|
+
<input type="text" id="node-input-imagePath" style="width:70%;">
|
|
546
|
+
<input type="hidden" id="node-input-imagePathType">
|
|
547
|
+
</div>
|
|
548
|
+
|
|
549
|
+
<div class="form-row">
|
|
550
|
+
<label><i class="fa fa-list"></i> Masks Array</label>
|
|
551
|
+
<input type="text" id="node-input-masksPath" style="width:70%;">
|
|
552
|
+
<input type="hidden" id="node-input-masksPathType">
|
|
553
|
+
</div>
|
|
554
|
+
|
|
555
|
+
<div class="form-row">
|
|
556
|
+
<label><i class="fa fa-sign-out"></i> Output</label>
|
|
557
|
+
<input type="text" id="node-input-outputPath" style="width:70%;">
|
|
558
|
+
<input type="hidden" id="node-input-outputPathType">
|
|
559
|
+
</div>
|
|
560
|
+
|
|
561
|
+
<div class="form-row">
|
|
562
|
+
<label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
|
|
563
|
+
<select id="node-input-outputFormat" style="width: 200px;">
|
|
564
|
+
<option value="raw">Raw (fastest)</option>
|
|
565
|
+
<option value="jpg">JPEG</option>
|
|
566
|
+
<option value="png">PNG</option>
|
|
567
|
+
<option value="webp">WebP</option>
|
|
568
|
+
</select>
|
|
569
|
+
</div>
|
|
570
|
+
|
|
571
|
+
<div class="form-row" id="quality-row">
|
|
572
|
+
<label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
|
|
573
|
+
<input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
|
|
574
|
+
<span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
|
|
575
|
+
</div>
|
|
576
|
+
|
|
577
|
+
<div class="form-row" id="png-optimize-row" style="display: none;">
|
|
578
|
+
<label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
|
|
579
|
+
<input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
580
|
+
<label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
|
|
581
|
+
</div>
|
|
582
|
+
|
|
583
|
+
<!-- Debug Configuration -->
|
|
584
|
+
<div class="form-row">
|
|
585
|
+
<label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
|
|
586
|
+
<input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
587
|
+
<label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
|
|
588
|
+
</div>
|
|
589
|
+
<div class="form-row" id="debug-width-row" style="display: none;">
|
|
590
|
+
<label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
|
|
591
|
+
<input type="text" id="node-input-debugWidth" style="width: 120px;">
|
|
592
|
+
<input type="hidden" id="node-input-debugWidthType">
|
|
593
|
+
<span style="margin-left: 10px; color: #666;">pixels</span>
|
|
594
|
+
</div>
|
|
595
|
+
|
|
596
|
+
<hr/>
|
|
597
|
+
|
|
598
|
+
<div class="form-row">
|
|
599
|
+
<label for="node-input-globalMaskStrength"><i class="fa fa-adjust"></i> Global Mask Strength</label>
|
|
600
|
+
<input type="range" id="node-input-globalMaskStrength" min="0" max="100" value="50" style="width: 200px;">
|
|
601
|
+
<span id="strength-value" style="margin-left: 10px; font-weight: bold;">50%</span>
|
|
602
|
+
<div style="margin-top: 5px; font-size: 11px; color: #666;" id="strength-label">
|
|
603
|
+
Balanced mask application
|
|
604
|
+
</div>
|
|
605
|
+
<div style="margin-top: 5px; font-size: 10px; color: #999;">
|
|
606
|
+
0% = No mask effect | 50% = Balanced | 100% = Full mask effect
|
|
607
|
+
</div>
|
|
608
|
+
</div>
|
|
609
|
+
|
|
610
|
+
<div class="form-row">
|
|
611
|
+
<label><i class="fa fa-palette"></i> Class Color Mappings</label>
|
|
612
|
+
<div id="class-mappings-container" style="margin-top: 10px;">
|
|
613
|
+
<!-- Dynamic class mapping rows will be inserted here -->
|
|
614
|
+
</div>
|
|
615
|
+
<div style="margin-top: 10px;">
|
|
616
|
+
<button type="button" id="add-class-mapping" class="editor-button">
|
|
617
|
+
<i class="fa fa-plus"></i> Add Class Mapping
|
|
618
|
+
</button>
|
|
619
|
+
</div>
|
|
620
|
+
<div style="margin-top: 5px; font-size: 11px; color: #666;">
|
|
621
|
+
<i class="fa fa-arrows-v"></i> Drag to reorder priority.
|
|
622
|
+
<strong>First = highest priority</strong> when masks overlap.
|
|
623
|
+
Undefined classes use auto-generated colors.
|
|
624
|
+
</div>
|
|
625
|
+
</div>
|
|
626
|
+
</script>
|
|
627
|
+
|
|
628
|
+
<script type="text/x-red" data-help-name="add-masks">
|
|
629
|
+
<p><b>rosepetal-add-masks</b> applies multiple polygon-based masks to a base image using weighted blending with configurable mask strength and class-based color mapping. This node processes arrays of mask objects with automatic color assignment for different classes.</p>
|
|
630
|
+
|
|
631
|
+
<h3>Details</h3>
|
|
632
|
+
<p>This node performs high-performance multi-polygon-based blending using OpenCV. Binary masks are generated from polygon coordinates using OpenCV's fillPoly function, then applied to the base image as blending weights. Each mask can have a different color based on its class name. The polygon coordinates are expected to be normalized (0-1 range) and are automatically scaled to match the image dimensions.</p>
|
|
633
|
+
|
|
634
|
+
<h3>Properties</h3>
|
|
635
|
+
<dl class="message-properties">
|
|
636
|
+
<dt>Image <span class="property-type">string</span></dt>
|
|
637
|
+
<dd>Message property path containing the base image to which the masks will be applied (default: <code>msg.image</code>). Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
|
|
638
|
+
|
|
639
|
+
<dt>Masks Array <span class="property-type">string</span></dt>
|
|
640
|
+
<dd>Message property path containing the masks array (default: <code>msg.array</code>). Expected structure: direct array of mask objects with <code>polygons</code> coordinates and <code>tag</code> property. Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
|
|
641
|
+
|
|
642
|
+
<dt>Output to <span class="property-type">string</span></dt>
|
|
643
|
+
<dd>Message property path where the masked image will be stored (default: <code>msg.payload</code>). Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
|
|
644
|
+
|
|
645
|
+
<dt>Output Format <span class="property-type">string</span></dt>
|
|
646
|
+
<dd>Format for the output image: <code>raw</code> (fastest), <code>jpg</code>, <code>png</code>, or <code>webp</code>.</dd>
|
|
647
|
+
|
|
648
|
+
<dt>Quality <span class="property-type">number</span></dt>
|
|
649
|
+
<dd>Compression quality (1-100) for JPEG and WebP formats. Only visible when JPG or WebP is selected.</dd>
|
|
650
|
+
|
|
651
|
+
<dt>Global Mask Strength <span class="property-type">number</span></dt>
|
|
652
|
+
<dd>Intensity of mask application from 0% to 100%. Controls how strongly all masks affect the final result.</dd>
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
<dt>Class Color Mappings <span class="property-type">array</span></dt>
|
|
656
|
+
<dd>Dynamic list of tag name to color mappings. Each mapping defines a specific color for masks with that tag. Supports adding and removing mappings.</dd>
|
|
657
|
+
</dl>
|
|
658
|
+
|
|
659
|
+
<h3>Input Structure</h3>
|
|
660
|
+
<p>The masks array should follow this exact structure (direct array of mask objects):</p>
|
|
661
|
+
<pre>[
|
|
662
|
+
{
|
|
663
|
+
"tag": "bottle",
|
|
664
|
+
"polygons": [[[0.107, 0.141], [0.211, 0.141], [0.211, 0.930], [0.107, 0.930]]],
|
|
665
|
+
"confidence": 0.9697,
|
|
666
|
+
"color": "rgb(144,133,227)", // Ignored - use class color mappings instead
|
|
667
|
+
"classId": 0, // Ignored
|
|
668
|
+
"raw_boxes": [...], // Ignored
|
|
669
|
+
"area": 0.072 // Ignored
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
"tag": "mountain",
|
|
673
|
+
"polygons": [[[0.283, 0.158], [0.391, 0.158], [0.391, 0.963], [0.283, 0.963]]],
|
|
674
|
+
"confidence": 0.9648
|
|
675
|
+
}
|
|
676
|
+
]</pre>
|
|
677
|
+
<p><b>Note:</b> Only <code>tag</code> and <code>polygons</code> fields are used. Other fields (color, classId, raw_boxes, area, confidence) are ignored.</p>
|
|
678
|
+
|
|
679
|
+
<h3>Key Features</h3>
|
|
680
|
+
<ul>
|
|
681
|
+
<li><b>Dynamic Color Management:</b> Add/remove tag color mappings with real-time validation</li>
|
|
682
|
+
<li><b>Auto-Color Generation:</b> Consistent random colors for undefined tags using maximally different color algorithm</li>
|
|
683
|
+
<li><b>Duplicate Detection:</b> Visual warnings for duplicate tags and similar colors</li>
|
|
684
|
+
<li><b>Multi-Layer Blending:</b> Proper compositing of multiple masks with weight normalization</li>
|
|
685
|
+
<li><b>Structure Validation:</b> Comprehensive validation of direct array structure</li>
|
|
686
|
+
</ul>
|
|
687
|
+
|
|
688
|
+
<h3>Color Management</h3>
|
|
689
|
+
<p>Colors are assigned using this priority order:</p>
|
|
690
|
+
<ol>
|
|
691
|
+
<li><b>User-defined mapping:</b> Colors explicitly set in the tag color mappings</li>
|
|
692
|
+
<li><b>Auto-generated:</b> Maximally different colors for undefined tags</li>
|
|
693
|
+
<li><b>Default fallback:</b> White color (#ffffff)</li>
|
|
694
|
+
</ol>
|
|
695
|
+
|
|
696
|
+
<h3>Performance</h3>
|
|
697
|
+
<ul>
|
|
698
|
+
<li><b>C++ Backend:</b> High-performance OpenCV implementation with SIMD optimizations</li>
|
|
699
|
+
<li><b>Batch Processing:</b> Efficient handling of multiple masks in single operation</li>
|
|
700
|
+
<li><b>Memory Efficient:</b> Optimized buffer handling and intermediate result reuse</li>
|
|
701
|
+
<li><b>Weight Normalization:</b> Prevents over-saturation when masks overlap</li>
|
|
702
|
+
</ul>
|
|
703
|
+
</script>
|