@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,410 @@
|
|
|
1
|
+
<!-- ───────── nodes/rosepetal-crop/crop.html (revised) ────────────── -->
|
|
2
|
+
|
|
3
|
+
<!-- 1 ▸ Runtime registration -->
|
|
4
|
+
<script type="text/javascript">
|
|
5
|
+
RED.nodes.registerType('crop',{
|
|
6
|
+
|
|
7
|
+
category:'RP Image',
|
|
8
|
+
color :'#DDA0DD',
|
|
9
|
+
icon :'font-awesome/fa-crop',
|
|
10
|
+
|
|
11
|
+
defaults:{
|
|
12
|
+
name:{value:""},
|
|
13
|
+
inputPath:{value:"payload"}, inputPathType:{value:"msg"},
|
|
14
|
+
outputPath:{value:"payload"}, outputPathType:{value:"msg"},
|
|
15
|
+
outputFormat:{value:"raw"},
|
|
16
|
+
outputQuality:{value:90},
|
|
17
|
+
pngOptimize:{value:false},
|
|
18
|
+
// Debug configuration
|
|
19
|
+
debugEnabled:{value:false},
|
|
20
|
+
debugWidth:{value:200},
|
|
21
|
+
debugWidthType:{value:"num"},
|
|
22
|
+
|
|
23
|
+
coordNorm:{value:true}, /* ⇄ pixels / 0–1 */
|
|
24
|
+
|
|
25
|
+
/* coords */
|
|
26
|
+
cropX:{value:"0"}, cropXType:{value:"num"},
|
|
27
|
+
cropY:{value:"0"}, cropYType:{value:"num"},
|
|
28
|
+
width:{value:"1"}, widthType:{value:"num"},
|
|
29
|
+
height:{value:"1"}, heightType:{value:"num"}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
inputs:1, outputs:1,
|
|
33
|
+
label:function(){ return this.name || "crop"; },
|
|
34
|
+
|
|
35
|
+
/* ---------------- oneditprepare ---------------- */
|
|
36
|
+
oneditprepare:function(){
|
|
37
|
+
|
|
38
|
+
/* I/O typedInputs */
|
|
39
|
+
$("#node-input-inputPath").typedInput({
|
|
40
|
+
default:'msg',types:['msg','flow','global'],
|
|
41
|
+
typeField:"#node-input-inputPathType"
|
|
42
|
+
});
|
|
43
|
+
$("#node-input-outputPath").typedInput({
|
|
44
|
+
default:'msg',types:['msg','flow','global'],
|
|
45
|
+
typeField:"#node-input-outputPathType"
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/* coordinate typedInputs */
|
|
49
|
+
["cropX","cropY","width","height"].forEach(id=>{
|
|
50
|
+
$("#node-input-"+id).typedInput({
|
|
51
|
+
default:'num',
|
|
52
|
+
types:['num','msg','flow','global'],
|
|
53
|
+
typeField:"#node-input-"+id+"Type"
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/* normalised toggle → show/hide help blocks */
|
|
58
|
+
function updateTips(){
|
|
59
|
+
const on = $("#node-input-coordNorm").prop("checked");
|
|
60
|
+
$("#norm-enabled").toggle( on );
|
|
61
|
+
$("#norm-disabled").toggle(!on );
|
|
62
|
+
}
|
|
63
|
+
$("#node-input-coordNorm").on("change",updateTips);
|
|
64
|
+
updateTips(); // initial state
|
|
65
|
+
|
|
66
|
+
/* output format → show/hide quality */
|
|
67
|
+
function updateQualityVisibility(){
|
|
68
|
+
const format = $("#node-input-outputFormat").val();
|
|
69
|
+
$("#quality-row").toggle(format === "jpg" || format === "webp");
|
|
70
|
+
$("#png-optimize-row").toggle(format === "png");
|
|
71
|
+
}
|
|
72
|
+
$("#node-input-outputFormat").on("change", updateQualityVisibility);
|
|
73
|
+
updateQualityVisibility(); // initial state
|
|
74
|
+
|
|
75
|
+
// === Debug Display Logic ===
|
|
76
|
+
const debugCheckbox = $('#node-input-debugEnabled');
|
|
77
|
+
const debugWidthRow = $('#debug-width-row');
|
|
78
|
+
|
|
79
|
+
// Initialize debug width TypedInput
|
|
80
|
+
$("#node-input-debugWidth").typedInput({
|
|
81
|
+
default: 'num',
|
|
82
|
+
types: ['num', 'msg', 'flow', 'global'],
|
|
83
|
+
typeField: "#node-input-debugWidthType"
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Function to toggle debug width visibility
|
|
87
|
+
function updateDebugWidthVisibility() {
|
|
88
|
+
if (debugCheckbox.is(':checked')) {
|
|
89
|
+
debugWidthRow.show();
|
|
90
|
+
} else {
|
|
91
|
+
debugWidthRow.hide();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Initialize debug state on node open
|
|
96
|
+
updateDebugWidthVisibility();
|
|
97
|
+
|
|
98
|
+
// Handle debug checkbox changes
|
|
99
|
+
debugCheckbox.on('change', function() {
|
|
100
|
+
const enabled = this.checked;
|
|
101
|
+
updateDebugWidthVisibility();
|
|
102
|
+
// Store debug state for runtime access
|
|
103
|
+
$('#node-input-debugEnabled').data('debug-enabled', enabled);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Debug image display renderer - shared across all image processing nodes
|
|
109
|
+
if (!window.debugImageRendererInitialized) {
|
|
110
|
+
window.debugImageRendererInitialized = true;
|
|
111
|
+
|
|
112
|
+
(function() {
|
|
113
|
+
var isSubscribed = false;
|
|
114
|
+
|
|
115
|
+
function subscribeToDebugImages() {
|
|
116
|
+
if (isSubscribed || typeof RED === 'undefined' || !RED.comms) return;
|
|
117
|
+
isSubscribed = true;
|
|
118
|
+
|
|
119
|
+
RED.comms.subscribe('debug-image', function(event, data) {
|
|
120
|
+
if (!data || !data.id) return;
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
renderDebugImage(data);
|
|
124
|
+
} catch (err) {
|
|
125
|
+
console.warn('Debug image render error:', err);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function renderDebugImage(data) {
|
|
131
|
+
const nodeId = data.id;
|
|
132
|
+
const base64Data = data.data;
|
|
133
|
+
const format = data.format || 'unknown';
|
|
134
|
+
const mimeType = data.mimeType || 'jpeg';
|
|
135
|
+
|
|
136
|
+
if (!base64Data) {
|
|
137
|
+
removeDebugImage(nodeId);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const nodeElement = document.getElementById(nodeId);
|
|
142
|
+
if (!nodeElement) return;
|
|
143
|
+
|
|
144
|
+
let debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
145
|
+
|
|
146
|
+
if (!debugContainer) {
|
|
147
|
+
// Create SVG foreignObject to embed HTML content in SVG
|
|
148
|
+
debugContainer = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
|
|
149
|
+
debugContainer.id = 'debug-img-container-' + nodeId;
|
|
150
|
+
debugContainer.setAttribute('x', '70');
|
|
151
|
+
debugContainer.setAttribute('y', '5');
|
|
152
|
+
debugContainer.setAttribute('width', '120');
|
|
153
|
+
debugContainer.setAttribute('height', '120');
|
|
154
|
+
debugContainer.style.overflow = 'visible';
|
|
155
|
+
|
|
156
|
+
// Create simple image directly inside foreignObject
|
|
157
|
+
const img = document.createElement('img');
|
|
158
|
+
img.id = 'debug-img-' + nodeId;
|
|
159
|
+
img.style.width = '100%';
|
|
160
|
+
img.style.height = 'auto';
|
|
161
|
+
img.style.display = 'block';
|
|
162
|
+
img.style.cursor = 'pointer';
|
|
163
|
+
img.style.maxHeight = '100px';
|
|
164
|
+
img.style.maxWidth = '100px';
|
|
165
|
+
|
|
166
|
+
img.onclick = function() {
|
|
167
|
+
removeDebugImage(nodeId);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
debugContainer.appendChild(img);
|
|
171
|
+
nodeElement.appendChild(debugContainer);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const img = document.getElementById('debug-img-' + nodeId);
|
|
175
|
+
|
|
176
|
+
if (img) {
|
|
177
|
+
img.src = `data:image/${mimeType};base64,${base64Data}`;
|
|
178
|
+
img.title = 'Debug image (click to hide)';
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function removeDebugImage(nodeId) {
|
|
183
|
+
const debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
184
|
+
if (debugContainer) {
|
|
185
|
+
debugContainer.remove();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function initializeWhenReady() {
|
|
190
|
+
if (typeof RED !== 'undefined' && RED.comms) {
|
|
191
|
+
subscribeToDebugImages();
|
|
192
|
+
|
|
193
|
+
// Clean up orphaned debug images periodically
|
|
194
|
+
setInterval(function() {
|
|
195
|
+
const debugContainers = document.querySelectorAll('[id^="debug-img-container-"]');
|
|
196
|
+
debugContainers.forEach(container => {
|
|
197
|
+
const nodeId = container.id.replace('debug-img-container-', '');
|
|
198
|
+
const nodeElement = document.getElementById(nodeId);
|
|
199
|
+
if (!nodeElement) {
|
|
200
|
+
container.remove();
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}, 5000);
|
|
204
|
+
} else {
|
|
205
|
+
setTimeout(initializeWhenReady, 100);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (document.readyState === 'loading') {
|
|
210
|
+
document.addEventListener('DOMContentLoaded', initializeWhenReady);
|
|
211
|
+
} else {
|
|
212
|
+
initializeWhenReady();
|
|
213
|
+
}
|
|
214
|
+
})();
|
|
215
|
+
}
|
|
216
|
+
</script>
|
|
217
|
+
|
|
218
|
+
<!-- 2 ▸ Edit‑dialog template -->
|
|
219
|
+
<script type="text/x-red" data-template-name="crop">
|
|
220
|
+
|
|
221
|
+
<!-- Name -->
|
|
222
|
+
<div class="form-row">
|
|
223
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
224
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
225
|
+
</div>
|
|
226
|
+
|
|
227
|
+
<hr>
|
|
228
|
+
|
|
229
|
+
<!-- STANDARD I/O SECTION (same as all other nodes) -->
|
|
230
|
+
<div class="form-row">
|
|
231
|
+
<label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input from</label>
|
|
232
|
+
<input type="text" id="node-input-inputPath" style="width: 70%;">
|
|
233
|
+
<input type="hidden" id="node-input-inputPathType">
|
|
234
|
+
</div>
|
|
235
|
+
<div class="form-row">
|
|
236
|
+
<label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output to</label>
|
|
237
|
+
<input type="text" id="node-input-outputPath" style="width: 70%;">
|
|
238
|
+
<input type="hidden" id="node-input-outputPathType">
|
|
239
|
+
</div>
|
|
240
|
+
<div class="form-row">
|
|
241
|
+
<label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
|
|
242
|
+
<select id="node-input-outputFormat" style="width: 200px;">
|
|
243
|
+
<option value="raw">Raw (fastest)</option>
|
|
244
|
+
<option value="jpg">JPEG</option>
|
|
245
|
+
<option value="png">PNG</option>
|
|
246
|
+
<option value="webp">WebP</option>
|
|
247
|
+
</select>
|
|
248
|
+
</div>
|
|
249
|
+
<div class="form-row" id="quality-row">
|
|
250
|
+
<label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
|
|
251
|
+
<input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
|
|
252
|
+
<span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
|
|
253
|
+
</div>
|
|
254
|
+
<div class="form-row" id="png-optimize-row" style="display: none;">
|
|
255
|
+
<label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
|
|
256
|
+
<input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
257
|
+
<label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
|
|
258
|
+
</div>
|
|
259
|
+
|
|
260
|
+
<!-- Debug Configuration -->
|
|
261
|
+
<div class="form-row">
|
|
262
|
+
<label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
|
|
263
|
+
<input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
264
|
+
<label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
|
|
265
|
+
</div>
|
|
266
|
+
<div class="form-row" id="debug-width-row" style="display: none;">
|
|
267
|
+
<label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
|
|
268
|
+
<input type="text" id="node-input-debugWidth" style="width: 120px;">
|
|
269
|
+
<input type="hidden" id="node-input-debugWidthType">
|
|
270
|
+
<span style="margin-left: 10px; color: #666;">pixels</span>
|
|
271
|
+
</div>
|
|
272
|
+
|
|
273
|
+
<hr>
|
|
274
|
+
|
|
275
|
+
<!-- CROP-SPECIFIC SECTION -->
|
|
276
|
+
<div class="form-row">
|
|
277
|
+
<label for="node-input-coordNorm"><i class="fa fa-percent"></i> Normalised</label>
|
|
278
|
+
<input type="checkbox" id="node-input-coordNorm" style="width: 20px; height: 20px;">
|
|
279
|
+
</div>
|
|
280
|
+
|
|
281
|
+
<!-- Tips that toggle -->
|
|
282
|
+
<div id="norm-enabled" class="form-tips" style="font-size: 0.85em; margin: 4px 0; color: #666;">
|
|
283
|
+
<b>Normalised ON:</b> values must be between <code>0.0</code> and <code>1.0</code> (fractions of image dimensions).
|
|
284
|
+
</div>
|
|
285
|
+
<div id="norm-disabled" class="form-tips" style="font-size: 0.85em; margin: 4px 0; color: #666;">
|
|
286
|
+
<b>Normalised OFF:</b> values are absolute pixels from top-left corner.
|
|
287
|
+
</div>
|
|
288
|
+
|
|
289
|
+
<div class="form-row">
|
|
290
|
+
<label for="node-input-cropX"><i class="fa fa-arrows-h"></i> X Position</label>
|
|
291
|
+
<input type="text" id="node-input-cropX" style="width: 70%;" placeholder="0">
|
|
292
|
+
<input type="hidden" id="node-input-cropXType">
|
|
293
|
+
</div>
|
|
294
|
+
<div class="form-row">
|
|
295
|
+
<label for="node-input-cropY"><i class="fa fa-arrows-v"></i> Y Position</label>
|
|
296
|
+
<input type="text" id="node-input-cropY" style="width: 70%;" placeholder="0">
|
|
297
|
+
<input type="hidden" id="node-input-cropYType">
|
|
298
|
+
</div>
|
|
299
|
+
<div class="form-row">
|
|
300
|
+
<label for="node-input-width"><i class="fa fa-arrows-h"></i> Width</label>
|
|
301
|
+
<input type="text" id="node-input-width" style="width: 70%;" placeholder="100">
|
|
302
|
+
<input type="hidden" id="node-input-widthType">
|
|
303
|
+
</div>
|
|
304
|
+
<div class="form-row">
|
|
305
|
+
<label for="node-input-height"><i class="fa fa-arrows-v"></i> Height</label>
|
|
306
|
+
<input type="text" id="node-input-height" style="width: 70%;" placeholder="100">
|
|
307
|
+
<input type="hidden" id="node-input-heightType">
|
|
308
|
+
</div>
|
|
309
|
+
|
|
310
|
+
<div class="form-tips">
|
|
311
|
+
<b>Tips:</b>
|
|
312
|
+
<ul>
|
|
313
|
+
<li><b>X, Y:</b> Position of the top-left corner of the crop area.</li>
|
|
314
|
+
<li><b>Width, Height:</b> Dimensions of the crop area.</li>
|
|
315
|
+
<li>All parameters support dynamic values from <code>msg</code>, <code>flow</code>, or <code>global</code> context.</li>
|
|
316
|
+
</ul>
|
|
317
|
+
</div>
|
|
318
|
+
</script>
|
|
319
|
+
|
|
320
|
+
<!-- 3 ▸ Help panel -->
|
|
321
|
+
<script type="text/x-red" data-help-name="crop">
|
|
322
|
+
<p>Extracts a rectangular region from images using flexible coordinate systems and dynamic value sources.</p>
|
|
323
|
+
|
|
324
|
+
<h3>Details</h3>
|
|
325
|
+
<p>This node crops images by extracting a rectangular region defined by X, Y position and width, height dimensions. It supports both normalized coordinates (0-1 relative to image dimensions) and absolute pixel coordinates. All coordinate values can be dynamically sourced from message properties, flow, or global context.</p>
|
|
326
|
+
|
|
327
|
+
<h3>Properties</h3>
|
|
328
|
+
<dl class="message-properties">
|
|
329
|
+
<dt>Input from <span class="property-type">string</span></dt>
|
|
330
|
+
<dd>The location to read image data from. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
|
|
331
|
+
<dt>Output to <span class="property-type">string</span></dt>
|
|
332
|
+
<dd>The location where the cropped image will be stored. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
|
|
333
|
+
<dt>Output Format <span class="property-type">string</span></dt>
|
|
334
|
+
<dd>Choose output format: <code>raw</code> (fastest, standard image object), <code>jpg</code>, <code>png</code>, or <code>webp</code> (encoded file buffers).</dd>
|
|
335
|
+
<dt>Quality <span class="property-type">number</span></dt>
|
|
336
|
+
<dd>Compression quality for JPEG and WebP formats (1-100). Only visible when jpg or webp format is selected. Default: 90.</dd>
|
|
337
|
+
<dt>Normalised <span class="property-type">boolean</span></dt>
|
|
338
|
+
<dd>When enabled, coordinates are normalized (0.0-1.0 as fractions of image dimensions). When disabled, coordinates are absolute pixels.</dd>
|
|
339
|
+
<dt>X Position <span class="property-type">number|string</span></dt>
|
|
340
|
+
<dd>X coordinate of the top-left corner of the crop area. Can be fixed number or dynamic value from msg property, flow, or global context.</dd>
|
|
341
|
+
<dt>Y Position <span class="property-type">number|string</span></dt>
|
|
342
|
+
<dd>Y coordinate of the top-left corner of the crop area. Can be fixed number or dynamic value from msg property, flow, or global context.</dd>
|
|
343
|
+
<dt>Width <span class="property-type">number|string</span></dt>
|
|
344
|
+
<dd>Width of the crop area. Can be fixed number or dynamic value from msg property, flow, or global context.</dd>
|
|
345
|
+
<dt>Height <span class="property-type">number|string</span></dt>
|
|
346
|
+
<dd>Height of the crop area. Can be fixed number or dynamic value from msg property, flow, or global context.</dd>
|
|
347
|
+
</dl>
|
|
348
|
+
|
|
349
|
+
<h3>Inputs</h3>
|
|
350
|
+
<dl class="message-properties">
|
|
351
|
+
<dt>payload <span class="property-type">object | array</span></dt>
|
|
352
|
+
<dd>Single image object or array of image objects in standard format: <code>{ data: Buffer, width: number, height: number, channels: number, colorSpace: string, dtype: string }</code></dd>
|
|
353
|
+
</dl>
|
|
354
|
+
|
|
355
|
+
<h3>Outputs</h3>
|
|
356
|
+
<dl class="message-properties">
|
|
357
|
+
<dt>payload <span class="property-type">object | array | Buffer</span></dt>
|
|
358
|
+
<dd>Cropped image(s). Format depends on Output Format setting: raw image object(s) or encoded file buffer(s).</dd>
|
|
359
|
+
</dl>
|
|
360
|
+
|
|
361
|
+
<h3>Coordinate Systems</h3>
|
|
362
|
+
<p><strong>Normalized Coordinates (0.0-1.0):</strong></p>
|
|
363
|
+
<ul>
|
|
364
|
+
<li><strong>Advantages:</strong> Resolution-independent, easy to work with percentages</li>
|
|
365
|
+
<li><strong>Example:</strong> X=0.25, Y=0.25, Width=0.5, Height=0.5 crops the center quarter of any image</li>
|
|
366
|
+
<li><strong>Range:</strong> All values must be between 0.0 and 1.0</li>
|
|
367
|
+
</ul>
|
|
368
|
+
<p><strong>Absolute Pixel Coordinates:</strong></p>
|
|
369
|
+
<ul>
|
|
370
|
+
<li><strong>Advantages:</strong> Precise pixel-level control</li>
|
|
371
|
+
<li><strong>Example:</strong> X=100, Y=50, Width=200, Height=150 crops a 200x150 region starting at pixel (100,50)</li>
|
|
372
|
+
<li><strong>Range:</strong> Values are in pixels from top-left corner</li>
|
|
373
|
+
</ul>
|
|
374
|
+
|
|
375
|
+
<h3>Examples</h3>
|
|
376
|
+
<ul>
|
|
377
|
+
<li><strong>Center Crop (Normalized):</strong> X=0.25, Y=0.25, Width=0.5, Height=0.5 → Center quarter of image</li>
|
|
378
|
+
<li><strong>Top-Left Corner (Pixels):</strong> X=0, Y=0, Width=100, Height=100 → 100x100 pixel square from top-left</li>
|
|
379
|
+
<li><strong>Dynamic Crop:</strong> X=msg.cropX, Y=msg.cropY → Use coordinates from message properties</li>
|
|
380
|
+
<li><strong>Face Detection Crop:</strong> Coordinates calculated by face detection → dynamic cropping based on detected faces</li>
|
|
381
|
+
</ul>
|
|
382
|
+
|
|
383
|
+
<h3>Node Interactions</h3>
|
|
384
|
+
<p><strong>Input Sources:</strong> Image-in, Array-out, other transform nodes</p>
|
|
385
|
+
<p><strong>Output Destinations:</strong> Other transform nodes, Mix nodes (concat, mosaic), Array-in for collections</p>
|
|
386
|
+
<p><strong>Common Workflows:</strong> Face detection → Crop, Image preprocessing → Crop → Resize, Batch cropping for thumbnails</p>
|
|
387
|
+
|
|
388
|
+
<h3>Output Formats</h3>
|
|
389
|
+
<ul>
|
|
390
|
+
<li><strong>Raw:</strong> Standard image object (fastest, for further processing)</li>
|
|
391
|
+
<li><strong>JPEG:</strong> Compressed file buffer with quality setting</li>
|
|
392
|
+
<li><strong>PNG:</strong> Lossless compressed file buffer</li>
|
|
393
|
+
<li><strong>WebP:</strong> Modern compressed format with quality setting</li>
|
|
394
|
+
</ul>
|
|
395
|
+
|
|
396
|
+
<h3>Boundary Handling</h3>
|
|
397
|
+
<p>The node automatically handles boundary conditions:</p>
|
|
398
|
+
<ul>
|
|
399
|
+
<li><strong>Out-of-bounds:</strong> Crop area is clipped to image boundaries</li>
|
|
400
|
+
<li><strong>Invalid coordinates:</strong> Negative positions are clamped to 0</li>
|
|
401
|
+
<li><strong>Oversized dimensions:</strong> Width/height automatically limited to available space</li>
|
|
402
|
+
</ul>
|
|
403
|
+
|
|
404
|
+
<h3>Error Handling</h3>
|
|
405
|
+
<p>The node validates input data and coordinates, displaying warnings for invalid inputs. Invalid coordinates are clamped to valid ranges. Processing errors are logged and the message is not propagated.</p>
|
|
406
|
+
|
|
407
|
+
<h3>Performance</h3>
|
|
408
|
+
<p>Uses optimized C++ backend with OpenCV for high-performance cropping. Node status displays processing time including conversion, processing, and encoding phases. Array inputs are processed in parallel for optimal performance.</p>
|
|
409
|
+
</script>
|
|
410
|
+
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-RED logic for *rosepetal-crop* (C++ backend)
|
|
3
|
+
* Tiempos: convertMs · taskMs · encodeMs → OK … (conv X | task Y ms)
|
|
4
|
+
*/
|
|
5
|
+
const { performance } = require('perf_hooks');
|
|
6
|
+
const CppProcessor = require('../../lib/cpp-bridge.js');
|
|
7
|
+
|
|
8
|
+
module.exports = function (RED) {
|
|
9
|
+
const NodeUtils = require('../../lib/node-utils.js')(RED);
|
|
10
|
+
|
|
11
|
+
function CropNode(config) {
|
|
12
|
+
RED.nodes.createNode(this, config);
|
|
13
|
+
const node = this;
|
|
14
|
+
|
|
15
|
+
node.on('input', async (msg, send, done) => {
|
|
16
|
+
/* rutas I/O */
|
|
17
|
+
const inputPath = config.inputPath || 'payload';
|
|
18
|
+
const outputPath = config.outputPath || 'payload';
|
|
19
|
+
|
|
20
|
+
/* Capture original payload for error passthrough */
|
|
21
|
+
const originalPayload = RED.util.getMessageProperty(msg, inputPath);
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const t0 = performance.now();
|
|
25
|
+
node.status({});
|
|
26
|
+
|
|
27
|
+
/* flags */
|
|
28
|
+
const normalized = !!config.coordNorm;
|
|
29
|
+
const outputFormat = config.outputFormat || 'raw';
|
|
30
|
+
const outputQuality = parseInt(config.outputQuality) || 90;
|
|
31
|
+
const pngOptimize = config.pngOptimize || false;
|
|
32
|
+
|
|
33
|
+
/* imagen o lista de imágenes */
|
|
34
|
+
const imgs = Array.isArray(originalPayload) ? originalPayload : [originalPayload];
|
|
35
|
+
|
|
36
|
+
// Validate input images
|
|
37
|
+
if (Array.isArray(originalPayload)) {
|
|
38
|
+
if (!NodeUtils.validateListImage(originalPayload, node)) {
|
|
39
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
40
|
+
node, 'Invalid image list structure', msg, send, done,
|
|
41
|
+
{ originalPayload, outputPath, outputType: 'preserve' }
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
if (!NodeUtils.validateSingleImage(originalPayload, node)) {
|
|
46
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
47
|
+
node, 'Invalid image structure', msg, send, done,
|
|
48
|
+
{ originalPayload, outputPath, outputType: 'preserve' }
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* lanzar recortes en paralelo */
|
|
54
|
+
const jobs = imgs.map(img => {
|
|
55
|
+
const x = Number(NodeUtils.resolveDimension(node, config.cropXType, config.cropX, msg));
|
|
56
|
+
const y = Number(NodeUtils.resolveDimension(node, config.cropYType, config.cropY, msg));
|
|
57
|
+
const width = Number(NodeUtils.resolveDimension(node, config.widthType, config.width, msg));
|
|
58
|
+
const height = Number(NodeUtils.resolveDimension(node, config.heightType, config.height, msg));
|
|
59
|
+
|
|
60
|
+
return CppProcessor.crop(img, x, y, width, height, normalized, outputFormat, outputQuality, pngOptimize);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const results = await Promise.all(jobs);
|
|
64
|
+
|
|
65
|
+
/* acumular métricas */
|
|
66
|
+
const { totalConvertMs, totalTaskMs, totalEncodeMs, images } =
|
|
67
|
+
results.reduce((acc, { image, timing }) => {
|
|
68
|
+
acc.totalConvertMs += timing?.convertMs ?? 0;
|
|
69
|
+
acc.totalTaskMs += timing?.taskMs ?? 0;
|
|
70
|
+
acc.totalEncodeMs += timing?.encodeMs ?? 0;
|
|
71
|
+
acc.images.push(image);
|
|
72
|
+
return acc;
|
|
73
|
+
}, { totalConvertMs: 0, totalTaskMs: 0, totalEncodeMs: 0, images: [] });
|
|
74
|
+
|
|
75
|
+
/* salida */
|
|
76
|
+
const out = Array.isArray(originalPayload) ? images : images[0];
|
|
77
|
+
RED.util.setMessageProperty(msg, outputPath, out);
|
|
78
|
+
|
|
79
|
+
/* status con mismo formato que resize/rotate */
|
|
80
|
+
const dur = performance.now() - t0;
|
|
81
|
+
|
|
82
|
+
// Debug image display
|
|
83
|
+
let debugFormat = null;
|
|
84
|
+
if (config.debugEnabled) {
|
|
85
|
+
try {
|
|
86
|
+
// Resolve and validate debug width
|
|
87
|
+
let debugWidth = NodeUtils.resolveDimension(
|
|
88
|
+
node,
|
|
89
|
+
config.debugWidthType,
|
|
90
|
+
config.debugWidth,
|
|
91
|
+
msg
|
|
92
|
+
);
|
|
93
|
+
debugWidth = Math.max(1, parseInt(debugWidth) || 200); // Ensure positive, default 200
|
|
94
|
+
|
|
95
|
+
// For arrays, show the first image as representative
|
|
96
|
+
const debugImage = Array.isArray(originalPayload) ? images[0] : images[0];
|
|
97
|
+
const debugResult = await NodeUtils.debugImageDisplay(
|
|
98
|
+
debugImage,
|
|
99
|
+
outputFormat,
|
|
100
|
+
outputQuality,
|
|
101
|
+
node,
|
|
102
|
+
true,
|
|
103
|
+
debugWidth
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
if (debugResult) {
|
|
107
|
+
debugFormat = debugResult.formatMessage;
|
|
108
|
+
// Update node status with debug info
|
|
109
|
+
NodeUtils.setSuccessStatusWithDebug(node, imgs.length, dur, {
|
|
110
|
+
convertMs: totalConvertMs,
|
|
111
|
+
taskMs: totalTaskMs,
|
|
112
|
+
encodeMs: totalEncodeMs
|
|
113
|
+
}, debugFormat + (Array.isArray(originalPayload) ? ' (first)' : ''));
|
|
114
|
+
}
|
|
115
|
+
} catch (debugError) {
|
|
116
|
+
node.warn(`Debug display error: ${debugError.message}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Set regular status if debug not enabled or failed
|
|
121
|
+
if (!debugFormat) {
|
|
122
|
+
node.status({
|
|
123
|
+
fill : 'green',
|
|
124
|
+
shape : 'dot',
|
|
125
|
+
text : `OK: ${imgs.length} img in ${dur.toFixed(2)} ms `
|
|
126
|
+
+ `(conv ${(totalConvertMs + totalEncodeMs).toFixed(2)} ms | `
|
|
127
|
+
+ `task ${totalTaskMs.toFixed(2)} ms)`
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
NodeUtils.recordPerformanceMetrics(node, msg, {
|
|
132
|
+
convertMs: totalConvertMs,
|
|
133
|
+
encodeMs: totalEncodeMs,
|
|
134
|
+
taskMs: totalTaskMs
|
|
135
|
+
}, dur);
|
|
136
|
+
|
|
137
|
+
send(msg);
|
|
138
|
+
done && done();
|
|
139
|
+
} catch (err) {
|
|
140
|
+
NodeUtils.handleNodeErrorWithPassthrough(
|
|
141
|
+
node, err, msg, send, done, 'crop processing',
|
|
142
|
+
{ originalPayload, outputPath, outputType: 'preserve' }
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
RED.nodes.registerType('crop', CropNode);
|
|
149
|
+
};
|