@rosepetal/node-red-contrib-image-tools 1.2.0 → 1.2.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/node-red-contrib-image-tools/lib/node-utils.js +64 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +23 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +8 -2
- package/node-red-contrib-image-tools/nodes/blend/add-mask.html +24 -1
- package/node-red-contrib-image-tools/nodes/blend/add-mask.js +13 -7
- package/node-red-contrib-image-tools/nodes/blend/add-masks.html +23 -0
- package/node-red-contrib-image-tools/nodes/blend/add-masks.js +8 -2
- package/node-red-contrib-image-tools/nodes/blend/blend.html +24 -1
- package/node-red-contrib-image-tools/nodes/blend/blend.js +8 -2
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +23 -0
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +9 -3
- package/node-red-contrib-image-tools/nodes/mix/concat.html +24 -1
- package/node-red-contrib-image-tools/nodes/mix/concat.js +8 -2
- package/node-red-contrib-image-tools/nodes/mix/mosaic.html +23 -0
- package/node-red-contrib-image-tools/nodes/mix/mosaic.js +8 -2
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +24 -1
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +9 -1
- package/node-red-contrib-image-tools/nodes/specialized/image-align.html +25 -2
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +7 -1
- package/node-red-contrib-image-tools/nodes/transform/color-convert.html +213 -0
- package/node-red-contrib-image-tools/nodes/transform/color-convert.js +161 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.html +25 -1
- package/node-red-contrib-image-tools/nodes/transform/crop.js +9 -1
- package/node-red-contrib-image-tools/nodes/transform/draw.html +24 -0
- package/node-red-contrib-image-tools/nodes/transform/draw.js +8 -2
- package/node-red-contrib-image-tools/nodes/transform/filter.html +25 -1
- package/node-red-contrib-image-tools/nodes/transform/filter.js +9 -1
- package/node-red-contrib-image-tools/nodes/transform/padding.html +25 -1
- package/node-red-contrib-image-tools/nodes/transform/padding.js +9 -1
- package/node-red-contrib-image-tools/nodes/transform/resize.html +26 -2
- package/node-red-contrib-image-tools/nodes/transform/resize.js +9 -1
- package/node-red-contrib-image-tools/nodes/transform/rotate.html +30 -6
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +9 -1
- package/node-red-contrib-image-tools/package.json +1 -0
- package/package.json +2 -1
- package/rosepetal-image-engine/binding.gyp +2 -1
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +4 -4
- package/rosepetal-image-engine/src/color-convert.cpp +184 -0
- package/rosepetal-image-engine/src/concat.cpp +2 -2
- package/rosepetal-image-engine/src/crop.cpp +4 -4
- package/rosepetal-image-engine/src/filter.cpp +4 -4
- package/rosepetal-image-engine/src/image-align.cpp +1 -1
- package/rosepetal-image-engine/src/main.cpp +2 -0
- package/rosepetal-image-engine/src/mosaic.cpp +4 -4
- package/rosepetal-image-engine/src/padding.cpp +4 -4
- package/rosepetal-image-engine/src/resize.cpp +4 -4
- package/rosepetal-image-engine/src/rotate.cpp +6 -6
- package/rosepetal-image-engine/src/utils.h +2 -2
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
outputFormat:{value:"raw"},
|
|
17
17
|
outputQuality:{value:90},
|
|
18
18
|
pngOptimize:{value:false},
|
|
19
|
-
|
|
19
|
+
webpLossless:{value:false},
|
|
20
|
+
webpSmartSubsample:{value:false},
|
|
21
|
+
webpEffort:{value:""},
|
|
22
|
+
|
|
20
23
|
// Filtering options
|
|
21
24
|
minConfidence:{value:0.5},
|
|
22
25
|
minConfidenceType:{value:"num"},
|
|
@@ -72,6 +75,11 @@
|
|
|
72
75
|
$('#quality-row').hide();
|
|
73
76
|
}
|
|
74
77
|
$('#png-optimize-row').toggle(format === 'png');
|
|
78
|
+
// Show WebP advanced options only when WebP is selected
|
|
79
|
+
const isWebp = format === 'webp';
|
|
80
|
+
$('#webp-lossless-row').toggle(isWebp);
|
|
81
|
+
$('#webp-smartsubsample-row').toggle(isWebp);
|
|
82
|
+
$('#webp-effort-row').toggle(isWebp);
|
|
75
83
|
}
|
|
76
84
|
|
|
77
85
|
$('#node-input-outputFormat').on('change', updateQualityVisibility);
|
|
@@ -137,6 +145,21 @@
|
|
|
137
145
|
<input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
138
146
|
<label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
|
|
139
147
|
</div>
|
|
148
|
+
<div class="form-row" id="webp-lossless-row" style="display: none;">
|
|
149
|
+
<label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
|
|
150
|
+
<input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
151
|
+
<label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
|
|
152
|
+
</div>
|
|
153
|
+
<div class="form-row" id="webp-smartsubsample-row" style="display: none;">
|
|
154
|
+
<label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
|
|
155
|
+
<input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
156
|
+
<label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
|
|
157
|
+
</div>
|
|
158
|
+
<div class="form-row" id="webp-effort-row" style="display: none;">
|
|
159
|
+
<label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
|
|
160
|
+
<input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
|
|
161
|
+
<span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
|
|
162
|
+
</div>
|
|
140
163
|
|
|
141
164
|
<!-- Debug Configuration -->
|
|
142
165
|
<div class="form-row">
|
|
@@ -29,6 +29,8 @@ module.exports = function (RED) {
|
|
|
29
29
|
const outputFormat = config.outputFormat || 'raw';
|
|
30
30
|
const outputQuality = parseInt(config.outputQuality) || 90;
|
|
31
31
|
const pngOptimize = config.pngOptimize || false;
|
|
32
|
+
const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
|
|
33
|
+
const cppFormat = useSharpWebp ? 'raw' : outputFormat;
|
|
32
34
|
const minConfidence = NodeUtils.resolveDimension(node, config.minConfidenceType, config.minConfidence, msg) || 0.5;
|
|
33
35
|
|
|
34
36
|
/* Get input data */
|
|
@@ -162,7 +164,7 @@ module.exports = function (RED) {
|
|
|
162
164
|
// Convert bbox coordinates to crop parameters
|
|
163
165
|
const { x, y, width, height, label, confidence, originalBbox } = bbox;
|
|
164
166
|
|
|
165
|
-
return CppProcessor.crop(image, x, y, width, height, false,
|
|
167
|
+
return CppProcessor.crop(image, x, y, width, height, false, cppFormat, outputQuality, pngOptimize)
|
|
166
168
|
.then(result => ({
|
|
167
169
|
...result.image, // Spread image properties (data, width, height, channels, colorSpace, dtype)
|
|
168
170
|
tag: label, // Add tag metadata directly
|
|
@@ -187,6 +189,12 @@ module.exports = function (RED) {
|
|
|
187
189
|
allCrops.push(cropWithMetadata);
|
|
188
190
|
});
|
|
189
191
|
|
|
192
|
+
if (useSharpWebp) {
|
|
193
|
+
for (let i = 0; i < allCrops.length; i++) {
|
|
194
|
+
allCrops[i] = await NodeUtils.encodeWebpAdvanced(allCrops[i], config);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
190
198
|
/* Set output */
|
|
191
199
|
RED.util.setMessageProperty(msg, outputPath, allCrops);
|
|
192
200
|
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
outputFormat: { value: "raw" },
|
|
15
15
|
outputQuality: { value: 90 },
|
|
16
16
|
pngOptimize: { value: false },
|
|
17
|
+
webpLossless: { value: false },
|
|
18
|
+
webpSmartSubsample: { value: false },
|
|
19
|
+
webpEffort: { value: "" },
|
|
17
20
|
// Debug configuration
|
|
18
21
|
debugEnabled: { value: false },
|
|
19
22
|
debugWidth: { value: 200 },
|
|
@@ -94,12 +97,17 @@
|
|
|
94
97
|
} else {
|
|
95
98
|
$('#quality-row').hide();
|
|
96
99
|
}
|
|
97
|
-
|
|
100
|
+
|
|
98
101
|
if (format === 'png') {
|
|
99
102
|
$('#png-optimize-row').show();
|
|
100
103
|
} else {
|
|
101
104
|
$('#png-optimize-row').hide();
|
|
102
105
|
}
|
|
106
|
+
// Show WebP advanced options only when WebP is selected
|
|
107
|
+
const isWebp = format === 'webp';
|
|
108
|
+
$('#webp-lossless-row').toggle(isWebp);
|
|
109
|
+
$('#webp-smartsubsample-row').toggle(isWebp);
|
|
110
|
+
$('#webp-effort-row').toggle(isWebp);
|
|
103
111
|
}
|
|
104
112
|
|
|
105
113
|
$('#node-input-outputFormat').on('change', updateQualityVisibility);
|
|
@@ -329,7 +337,22 @@
|
|
|
329
337
|
<input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
330
338
|
<label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
|
|
331
339
|
</div>
|
|
332
|
-
|
|
340
|
+
<div class="form-row" id="webp-lossless-row" style="display: none;">
|
|
341
|
+
<label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
|
|
342
|
+
<input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
343
|
+
<label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
|
|
344
|
+
</div>
|
|
345
|
+
<div class="form-row" id="webp-smartsubsample-row" style="display: none;">
|
|
346
|
+
<label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
|
|
347
|
+
<input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
348
|
+
<label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
|
|
349
|
+
</div>
|
|
350
|
+
<div class="form-row" id="webp-effort-row" style="display: none;">
|
|
351
|
+
<label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
|
|
352
|
+
<input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
|
|
353
|
+
<span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
|
|
354
|
+
</div>
|
|
355
|
+
|
|
333
356
|
<!-- Return Matrix Option -->
|
|
334
357
|
<div class="form-row">
|
|
335
358
|
<label for="node-input-returnMatrix"><i class="fa fa-calculator"></i> Transform Matrix</label>
|
|
@@ -63,6 +63,8 @@ module.exports = function (RED) {
|
|
|
63
63
|
const outputFormat = config.outputFormat || 'raw';
|
|
64
64
|
const outputQuality = parseInt(config.outputQuality) || 90;
|
|
65
65
|
const pngOptimize = config.pngOptimize || false;
|
|
66
|
+
const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
|
|
67
|
+
const cppFormat = useSharpWebp ? 'raw' : outputFormat;
|
|
66
68
|
const preset = config.preset || 'ultra-fast';
|
|
67
69
|
const returnMatrix = config.returnMatrix || false;
|
|
68
70
|
const transformPolygon = config.transformPolygon || false;
|
|
@@ -250,13 +252,17 @@ module.exports = function (RED) {
|
|
|
250
252
|
scale,
|
|
251
253
|
maxIterations,
|
|
252
254
|
terminationEps,
|
|
253
|
-
|
|
255
|
+
cppFormat,
|
|
254
256
|
outputQuality,
|
|
255
257
|
pngOptimize,
|
|
256
258
|
returnMatrix,
|
|
257
259
|
polygon
|
|
258
260
|
);
|
|
259
261
|
|
|
262
|
+
if (useSharpWebp) {
|
|
263
|
+
result.image = await NodeUtils.encodeWebpAdvanced(result.image, config);
|
|
264
|
+
}
|
|
265
|
+
|
|
260
266
|
/* ▸ Status: standardized success formatting ----------------------- */
|
|
261
267
|
const total = performance.now() - startTime;
|
|
262
268
|
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('color-convert', {
|
|
3
|
+
category : 'RP Image',
|
|
4
|
+
color : '#DDA0DD',
|
|
5
|
+
defaults : {
|
|
6
|
+
name : { value:"" },
|
|
7
|
+
inputPath : { value:"payload" },
|
|
8
|
+
inputPathType : { value:"msg" },
|
|
9
|
+
outputPath : { value:"payload" },
|
|
10
|
+
outputPathType : { value:"msg" },
|
|
11
|
+
outputFormat : { value:"raw" },
|
|
12
|
+
outputQuality : { value:90 },
|
|
13
|
+
pngOptimize : { value:false },
|
|
14
|
+
webpLossless : { value:false },
|
|
15
|
+
webpSmartSubsample : { value:false },
|
|
16
|
+
webpEffort : { value:"" },
|
|
17
|
+
// Debug configuration
|
|
18
|
+
debugEnabled : { value:false },
|
|
19
|
+
debugWidth : { value:200 },
|
|
20
|
+
debugWidthType : { value:"num" },
|
|
21
|
+
targetColorSpace: { value:"RGB" }
|
|
22
|
+
},
|
|
23
|
+
inputs :1, outputs:1,
|
|
24
|
+
icon:"font-awesome/fa-eyedropper",
|
|
25
|
+
label:function(){ return this.name || "color-convert"; },
|
|
26
|
+
|
|
27
|
+
oneditprepare:function(){
|
|
28
|
+
$("#node-input-inputPath").typedInput({default:'msg',types:['msg','flow','global'],typeField:"#node-input-inputPathType"});
|
|
29
|
+
$("#node-input-outputPath").typedInput({default:'msg',types:['msg','flow','global'],typeField:"#node-input-outputPathType"});
|
|
30
|
+
|
|
31
|
+
function updateQualityVisibility(){
|
|
32
|
+
const format = $("#node-input-outputFormat").val();
|
|
33
|
+
$("#quality-row").toggle(format === "jpg" || format === "webp");
|
|
34
|
+
$("#png-optimize-row").toggle(format === "png");
|
|
35
|
+
|
|
36
|
+
// Show WebP advanced options only when WebP is selected
|
|
37
|
+
const isWebp = format === "webp";
|
|
38
|
+
$("#webp-lossless-row").toggle(isWebp);
|
|
39
|
+
$("#webp-smartsubsample-row").toggle(isWebp);
|
|
40
|
+
$("#webp-effort-row").toggle(isWebp);
|
|
41
|
+
}
|
|
42
|
+
$("#node-input-outputFormat").on("change", updateQualityVisibility);
|
|
43
|
+
updateQualityVisibility(); // initial state
|
|
44
|
+
|
|
45
|
+
// === Debug Display Logic ===
|
|
46
|
+
const debugCheckbox = $('#node-input-debugEnabled');
|
|
47
|
+
const debugWidthRow = $('#debug-width-row');
|
|
48
|
+
|
|
49
|
+
// Initialize debug width TypedInput
|
|
50
|
+
$("#node-input-debugWidth").typedInput({
|
|
51
|
+
default: 'num',
|
|
52
|
+
types: ['num', 'msg', 'flow', 'global'],
|
|
53
|
+
typeField: "#node-input-debugWidthType"
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Function to toggle debug width visibility
|
|
57
|
+
function updateDebugWidthVisibility() {
|
|
58
|
+
if (debugCheckbox.is(':checked')) {
|
|
59
|
+
debugWidthRow.show();
|
|
60
|
+
} else {
|
|
61
|
+
debugWidthRow.hide();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Initialize debug state on node open
|
|
66
|
+
updateDebugWidthVisibility();
|
|
67
|
+
|
|
68
|
+
// Handle debug checkbox changes
|
|
69
|
+
debugCheckbox.on('change', function() {
|
|
70
|
+
const enabled = this.checked;
|
|
71
|
+
updateDebugWidthVisibility();
|
|
72
|
+
$('#node-input-debugEnabled').data('debug-enabled', enabled);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<script type="text/x-red" data-template-name="color-convert">
|
|
79
|
+
<div class="form-row"><label for="node-input-name"><i class="fa fa-tag"></i> Name</label><input type="text" id="node-input-name"></div>
|
|
80
|
+
<hr>
|
|
81
|
+
<div class="form-row"><label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input</label><input type="text" id="node-input-inputPath" style="width:70%;"><input type="hidden" id="node-input-inputPathType"></div>
|
|
82
|
+
<div class="form-row"><label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output</label><input type="text" id="node-input-outputPath" style="width:70%;"><input type="hidden" id="node-input-outputPathType"></div>
|
|
83
|
+
<div class="form-row">
|
|
84
|
+
<label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
|
|
85
|
+
<select id="node-input-outputFormat" style="width: 200px;">
|
|
86
|
+
<option value="raw">Raw (fastest)</option>
|
|
87
|
+
<option value="jpg">JPEG</option>
|
|
88
|
+
<option value="png">PNG</option>
|
|
89
|
+
<option value="webp">WebP</option>
|
|
90
|
+
</select>
|
|
91
|
+
</div>
|
|
92
|
+
<div class="form-row" id="quality-row">
|
|
93
|
+
<label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
|
|
94
|
+
<input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
|
|
95
|
+
<span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
|
|
96
|
+
</div>
|
|
97
|
+
<div class="form-row" id="png-optimize-row" style="display: none;">
|
|
98
|
+
<label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
|
|
99
|
+
<input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
100
|
+
<label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
|
|
101
|
+
</div>
|
|
102
|
+
<div class="form-row" id="webp-lossless-row" style="display: none;">
|
|
103
|
+
<label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
|
|
104
|
+
<input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
105
|
+
<label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
|
|
106
|
+
</div>
|
|
107
|
+
<div class="form-row" id="webp-smartsubsample-row" style="display: none;">
|
|
108
|
+
<label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
|
|
109
|
+
<input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
110
|
+
<label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
|
|
111
|
+
</div>
|
|
112
|
+
<div class="form-row" id="webp-effort-row" style="display: none;">
|
|
113
|
+
<label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
|
|
114
|
+
<input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
|
|
115
|
+
<span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<!-- Debug Configuration -->
|
|
119
|
+
<div class="form-row">
|
|
120
|
+
<label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
|
|
121
|
+
<input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
122
|
+
<label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
|
|
123
|
+
</div>
|
|
124
|
+
<div class="form-row" id="debug-width-row" style="display: none;">
|
|
125
|
+
<label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
|
|
126
|
+
<input type="text" id="node-input-debugWidth" style="width: 120px;">
|
|
127
|
+
<input type="hidden" id="node-input-debugWidthType">
|
|
128
|
+
<span style="margin-left: 10px; color: #666;">pixels</span>
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
<hr>
|
|
132
|
+
<div class="form-row">
|
|
133
|
+
<label for="node-input-targetColorSpace"><i class="fa fa-paint-brush"></i> Target Color Space</label>
|
|
134
|
+
<select id="node-input-targetColorSpace" style="width: 200px;">
|
|
135
|
+
<option value="GRAY">Grayscale (GRAY)</option>
|
|
136
|
+
<option value="RGB">RGB</option>
|
|
137
|
+
<option value="RGBA">RGBA</option>
|
|
138
|
+
<option value="BGR">BGR</option>
|
|
139
|
+
<option value="BGRA">BGRA</option>
|
|
140
|
+
</select>
|
|
141
|
+
</div>
|
|
142
|
+
</script>
|
|
143
|
+
|
|
144
|
+
<script type="text/x-red" data-help-name="color-convert">
|
|
145
|
+
<p>Converts images between color spaces (GRAY, RGB, RGBA, BGR, BGRA) using high-performance C++ processing.</p>
|
|
146
|
+
|
|
147
|
+
<h3>Details</h3>
|
|
148
|
+
<p>This node converts images from one color space to another. The source color space is automatically detected from the input image metadata (or inferred from channel count). The target color space is selected in the node configuration. Supports both single images and arrays, processed in parallel.</p>
|
|
149
|
+
|
|
150
|
+
<h3>Properties</h3>
|
|
151
|
+
<dl class="message-properties">
|
|
152
|
+
<dt>Input from <span class="property-type">string</span></dt>
|
|
153
|
+
<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>
|
|
154
|
+
<dt>Output to <span class="property-type">string</span></dt>
|
|
155
|
+
<dd>The location where the converted 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>
|
|
156
|
+
<dt>Output Format <span class="property-type">string</span></dt>
|
|
157
|
+
<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>
|
|
158
|
+
<dt>Quality <span class="property-type">number</span></dt>
|
|
159
|
+
<dd>Compression quality for JPEG and WebP formats (1-100). Only visible when jpg or webp format is selected. Default: 90.</dd>
|
|
160
|
+
<dt>Target Color Space <span class="property-type">string</span></dt>
|
|
161
|
+
<dd>The target color space to convert images to. Options: <code>GRAY</code>, <code>RGB</code>, <code>RGBA</code>, <code>BGR</code>, <code>BGRA</code>. Default: RGB.</dd>
|
|
162
|
+
</dl>
|
|
163
|
+
|
|
164
|
+
<h3>Inputs</h3>
|
|
165
|
+
<dl class="message-properties">
|
|
166
|
+
<dt>payload <span class="property-type">object | array</span></dt>
|
|
167
|
+
<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>
|
|
168
|
+
</dl>
|
|
169
|
+
|
|
170
|
+
<h3>Outputs</h3>
|
|
171
|
+
<dl class="message-properties">
|
|
172
|
+
<dt>payload <span class="property-type">object | array | Buffer</span></dt>
|
|
173
|
+
<dd>Converted image(s). Format depends on Output Format setting: raw image object(s) or encoded file buffer(s).</dd>
|
|
174
|
+
</dl>
|
|
175
|
+
|
|
176
|
+
<h3>Supported Conversions</h3>
|
|
177
|
+
<p>All 20 conversion paths between the 5 color spaces are supported:</p>
|
|
178
|
+
<ul>
|
|
179
|
+
<li><strong>GRAY →</strong> BGR, RGB, BGRA, RGBA</li>
|
|
180
|
+
<li><strong>BGR →</strong> GRAY, RGB, BGRA, RGBA</li>
|
|
181
|
+
<li><strong>RGB →</strong> GRAY, BGR, BGRA, RGBA</li>
|
|
182
|
+
<li><strong>BGRA →</strong> GRAY, BGR, RGB, RGBA</li>
|
|
183
|
+
<li><strong>RGBA →</strong> GRAY, BGR, RGB, BGRA</li>
|
|
184
|
+
</ul>
|
|
185
|
+
<p>If the source and target color space are the same, a fast passthrough is used (no conversion overhead).</p>
|
|
186
|
+
|
|
187
|
+
<h3>Examples</h3>
|
|
188
|
+
<ul>
|
|
189
|
+
<li><strong>RGB → GRAY:</strong> Convert a color image to grayscale (3 channels → 1 channel)</li>
|
|
190
|
+
<li><strong>GRAY → RGBA:</strong> Expand grayscale to RGBA with full alpha (1 channel → 4 channels)</li>
|
|
191
|
+
<li><strong>BGR → RGB:</strong> Swap blue and red channels for display compatibility</li>
|
|
192
|
+
<li><strong>RGB → BGRA:</strong> Add alpha channel and convert to OpenCV-native order</li>
|
|
193
|
+
</ul>
|
|
194
|
+
|
|
195
|
+
<h3>Node Interactions</h3>
|
|
196
|
+
<p><strong>Input Sources:</strong> Image-in, Array-out, other transform nodes</p>
|
|
197
|
+
<p><strong>Output Destinations:</strong> Other transform nodes, Mix nodes (concat, mosaic), Array-in for collections</p>
|
|
198
|
+
<p><strong>Common Workflows:</strong> Preparing images for specific processing pipelines, ensuring consistent color spaces before blending or concatenation</p>
|
|
199
|
+
|
|
200
|
+
<h3>Output Formats</h3>
|
|
201
|
+
<ul>
|
|
202
|
+
<li><strong>Raw:</strong> Standard image object (fastest, for further processing)</li>
|
|
203
|
+
<li><strong>JPEG:</strong> Compressed file buffer with quality setting</li>
|
|
204
|
+
<li><strong>PNG:</strong> Lossless compressed file buffer</li>
|
|
205
|
+
<li><strong>WebP:</strong> Modern compressed format with quality setting</li>
|
|
206
|
+
</ul>
|
|
207
|
+
|
|
208
|
+
<h3>Error Handling</h3>
|
|
209
|
+
<p>The node validates input data and displays warnings for invalid inputs. Unsupported conversion paths produce descriptive error messages. Processing errors are logged and the original message is passed through with error details.</p>
|
|
210
|
+
|
|
211
|
+
<h3>Performance</h3>
|
|
212
|
+
<p>Uses optimized C++ backend with OpenCV for high-performance color space conversion. Identity conversions (same source/target) use a zero-cost passthrough. Node status displays processing time. Array inputs are processed in parallel for optimal performance.</p>
|
|
213
|
+
</script>
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-RED logic for *rosepetal-color-convert* — color space conversion, timing formatted.
|
|
3
|
+
*/
|
|
4
|
+
const { performance } = require('perf_hooks');
|
|
5
|
+
const CppProcessor = require('../../lib/cpp-bridge.js');
|
|
6
|
+
|
|
7
|
+
module.exports = function (RED) {
|
|
8
|
+
const NodeUtils = require('../../lib/node-utils.js')(RED);
|
|
9
|
+
|
|
10
|
+
function ColorConvertNode(config) {
|
|
11
|
+
RED.nodes.createNode(this, config);
|
|
12
|
+
const node = this;
|
|
13
|
+
|
|
14
|
+
node.on('input', async (msg, send, done) => {
|
|
15
|
+
const inputPath = config.inputPath || 'payload';
|
|
16
|
+
const inputPathType = config.inputPathType || 'msg';
|
|
17
|
+
const outputPath = config.outputPath || 'payload';
|
|
18
|
+
const outputPathType = config.outputPathType || 'msg';
|
|
19
|
+
const { value: originalPayload, error: inputErr } =
|
|
20
|
+
NodeUtils.getInputValue(node, msg, inputPath, inputPathType);
|
|
21
|
+
if (inputErr) {
|
|
22
|
+
const hint = inputPathType === 'msg'
|
|
23
|
+
? `Set inputPath to an existing msg property (e.g. "payload"), or ensure "${inputPath}" exists before this node.`
|
|
24
|
+
: `Set inputPath to an existing ${inputPathType} context key, or ensure "${inputPath}" exists before this node.`;
|
|
25
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
26
|
+
node,
|
|
27
|
+
{
|
|
28
|
+
message: `Invalid inputPath "${inputPath}" (${inputPathType}): ${inputErr.message}`,
|
|
29
|
+
hint,
|
|
30
|
+
details: { inputPath, inputPathType, outputPath, outputPathType }
|
|
31
|
+
},
|
|
32
|
+
msg,
|
|
33
|
+
send,
|
|
34
|
+
done,
|
|
35
|
+
{ originalPayload: undefined, outputPath: null, outputPathType, outputType: 'preserve' }
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const t0 = performance.now();
|
|
41
|
+
node.status({});
|
|
42
|
+
const outputFormat = config.outputFormat || 'raw';
|
|
43
|
+
const outputQuality = parseInt(config.outputQuality) || 90;
|
|
44
|
+
const pngOptimize = config.pngOptimize || false;
|
|
45
|
+
const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
|
|
46
|
+
const cppFormat = useSharpWebp ? 'raw' : outputFormat;
|
|
47
|
+
const targetColorSpace = config.targetColorSpace || 'RGB';
|
|
48
|
+
|
|
49
|
+
// Validate input images with error passthrough
|
|
50
|
+
if (Array.isArray(originalPayload)) {
|
|
51
|
+
if (!NodeUtils.validateListImage(originalPayload, node)) {
|
|
52
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
53
|
+
node, 'Invalid image list structure', msg, send, done,
|
|
54
|
+
{ originalPayload, outputPath, outputPathType, outputType: 'preserve' }
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
if (!NodeUtils.validateSingleImage(originalPayload, node)) {
|
|
59
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
60
|
+
node, 'Invalid image structure', msg, send, done,
|
|
61
|
+
{ originalPayload, outputPath, outputPathType, outputType: 'preserve' }
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const imgs = Array.isArray(originalPayload) ? originalPayload : [originalPayload];
|
|
67
|
+
|
|
68
|
+
/* ——— launch conversions in parallel ——— */
|
|
69
|
+
const promises = imgs.map(img =>
|
|
70
|
+
CppProcessor.colorConvert(img, targetColorSpace, cppFormat, outputQuality, pngOptimize)
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const results = await Promise.all(promises);
|
|
74
|
+
|
|
75
|
+
/* ——— accumulate metrics ——— */
|
|
76
|
+
const { totalConvertMs, totalTaskMs, encodeMs, images } =
|
|
77
|
+
results.reduce((acc, { image, timing }) => {
|
|
78
|
+
acc.totalConvertMs += timing?.convertMs ?? 0;
|
|
79
|
+
acc.totalTaskMs += timing?.taskMs ?? 0;
|
|
80
|
+
acc.encodeMs += timing?.encodeMs ?? 0;
|
|
81
|
+
acc.images.push(image);
|
|
82
|
+
return acc;
|
|
83
|
+
}, { totalConvertMs: 0, totalTaskMs: 0, encodeMs: 0, images: [] });
|
|
84
|
+
|
|
85
|
+
if (useSharpWebp) {
|
|
86
|
+
for (let i = 0; i < images.length; i++) {
|
|
87
|
+
images[i] = await NodeUtils.encodeWebpAdvanced(images[i], config);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const out = Array.isArray(originalPayload) ? images : images[0];
|
|
92
|
+
const durMs = performance.now() - t0;
|
|
93
|
+
|
|
94
|
+
NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, out);
|
|
95
|
+
|
|
96
|
+
// Debug image display
|
|
97
|
+
let debugFormat = null;
|
|
98
|
+
const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
|
|
99
|
+
if (debugEnabled) {
|
|
100
|
+
try {
|
|
101
|
+
let debugWidth = NodeUtils.resolveDimension(
|
|
102
|
+
node,
|
|
103
|
+
config.debugWidthType || 'num',
|
|
104
|
+
config.debugWidth,
|
|
105
|
+
msg
|
|
106
|
+
);
|
|
107
|
+
debugWidth = Math.max(1, parseInt(debugWidth) || 200);
|
|
108
|
+
|
|
109
|
+
const debugImage = images[0];
|
|
110
|
+
const debugResult = await NodeUtils.debugImageDisplay(
|
|
111
|
+
debugImage,
|
|
112
|
+
outputFormat,
|
|
113
|
+
outputQuality,
|
|
114
|
+
node,
|
|
115
|
+
debugEnabled,
|
|
116
|
+
debugWidth
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
if (debugResult) {
|
|
120
|
+
debugFormat = debugResult.formatMessage;
|
|
121
|
+
NodeUtils.setSuccessStatusWithDebug(node, imgs.length, durMs, {
|
|
122
|
+
convertMs: totalConvertMs,
|
|
123
|
+
taskMs: totalTaskMs,
|
|
124
|
+
encodeMs: encodeMs
|
|
125
|
+
}, debugFormat + (Array.isArray(originalPayload) ? ' (first)' : ''));
|
|
126
|
+
}
|
|
127
|
+
} catch (debugError) {
|
|
128
|
+
node.warn(`Debug display error: ${debugError.message}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Set regular status if debug not enabled or failed
|
|
133
|
+
if (!debugFormat) {
|
|
134
|
+
node.status({
|
|
135
|
+
fill : 'green',
|
|
136
|
+
shape : 'dot',
|
|
137
|
+
text : `OK: ${imgs.length} img in ${durMs.toFixed(2)} ms `
|
|
138
|
+
+ `(conv ${(totalConvertMs + encodeMs).toFixed(2)} ms `
|
|
139
|
+
+ `| task ${totalTaskMs.toFixed(2)} ms)`
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
NodeUtils.recordPerformanceMetrics(node, msg, {
|
|
144
|
+
convertMs: totalConvertMs,
|
|
145
|
+
encodeMs: encodeMs,
|
|
146
|
+
taskMs: totalTaskMs
|
|
147
|
+
}, durMs);
|
|
148
|
+
|
|
149
|
+
send(msg);
|
|
150
|
+
done && done();
|
|
151
|
+
} catch (err) {
|
|
152
|
+
NodeUtils.handleNodeErrorWithPassthrough(
|
|
153
|
+
node, err, msg, send, done, 'color-convert processing',
|
|
154
|
+
{ originalPayload, outputPath, outputPathType, outputType: 'preserve' }
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
RED.nodes.registerType('color-convert', ColorConvertNode);
|
|
161
|
+
};
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
outputFormat:{value:"raw"},
|
|
16
16
|
outputQuality:{value:90},
|
|
17
17
|
pngOptimize:{value:false},
|
|
18
|
+
webpLossless:{value:false},
|
|
19
|
+
webpSmartSubsample:{value:false},
|
|
20
|
+
webpEffort:{value:""},
|
|
18
21
|
// Debug configuration
|
|
19
22
|
debugEnabled:{value:false},
|
|
20
23
|
debugWidth:{value:200},
|
|
@@ -68,6 +71,12 @@
|
|
|
68
71
|
const format = $("#node-input-outputFormat").val();
|
|
69
72
|
$("#quality-row").toggle(format === "jpg" || format === "webp");
|
|
70
73
|
$("#png-optimize-row").toggle(format === "png");
|
|
74
|
+
|
|
75
|
+
// Show WebP advanced options only when WebP is selected
|
|
76
|
+
const isWebp = format === "webp";
|
|
77
|
+
$("#webp-lossless-row").toggle(isWebp);
|
|
78
|
+
$("#webp-smartsubsample-row").toggle(isWebp);
|
|
79
|
+
$("#webp-effort-row").toggle(isWebp);
|
|
71
80
|
}
|
|
72
81
|
$("#node-input-outputFormat").on("change", updateQualityVisibility);
|
|
73
82
|
updateQualityVisibility(); // initial state
|
|
@@ -256,7 +265,22 @@
|
|
|
256
265
|
<input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
257
266
|
<label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
|
|
258
267
|
</div>
|
|
259
|
-
|
|
268
|
+
<div class="form-row" id="webp-lossless-row" style="display: none;">
|
|
269
|
+
<label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
|
|
270
|
+
<input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
271
|
+
<label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
|
|
272
|
+
</div>
|
|
273
|
+
<div class="form-row" id="webp-smartsubsample-row" style="display: none;">
|
|
274
|
+
<label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
|
|
275
|
+
<input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
276
|
+
<label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
|
|
277
|
+
</div>
|
|
278
|
+
<div class="form-row" id="webp-effort-row" style="display: none;">
|
|
279
|
+
<label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
|
|
280
|
+
<input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
|
|
281
|
+
<span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
|
|
282
|
+
</div>
|
|
283
|
+
|
|
260
284
|
<!-- Debug Configuration -->
|
|
261
285
|
<div class="form-row">
|
|
262
286
|
<label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
|
|
@@ -49,6 +49,8 @@ module.exports = function (RED) {
|
|
|
49
49
|
const outputFormat = config.outputFormat || 'raw';
|
|
50
50
|
const outputQuality = parseInt(config.outputQuality) || 90;
|
|
51
51
|
const pngOptimize = config.pngOptimize || false;
|
|
52
|
+
const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
|
|
53
|
+
const cppFormat = useSharpWebp ? 'raw' : outputFormat;
|
|
52
54
|
|
|
53
55
|
/* imagen o lista de imágenes */
|
|
54
56
|
const imgs = Array.isArray(originalPayload) ? originalPayload : [originalPayload];
|
|
@@ -77,7 +79,7 @@ module.exports = function (RED) {
|
|
|
77
79
|
|
|
78
80
|
/* lanzar recortes en paralelo */
|
|
79
81
|
const jobs = imgs.map(img =>
|
|
80
|
-
CppProcessor.crop(img, x, y, width, height, normalized,
|
|
82
|
+
CppProcessor.crop(img, x, y, width, height, normalized, cppFormat, outputQuality, pngOptimize)
|
|
81
83
|
);
|
|
82
84
|
|
|
83
85
|
const results = await Promise.all(jobs);
|
|
@@ -92,6 +94,12 @@ module.exports = function (RED) {
|
|
|
92
94
|
return acc;
|
|
93
95
|
}, { totalConvertMs: 0, totalTaskMs: 0, totalEncodeMs: 0, images: [] });
|
|
94
96
|
|
|
97
|
+
if (useSharpWebp) {
|
|
98
|
+
for (let i = 0; i < images.length; i++) {
|
|
99
|
+
images[i] = await NodeUtils.encodeWebpAdvanced(images[i], config);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
95
103
|
/* salida */
|
|
96
104
|
const out = Array.isArray(originalPayload) ? images : images[0];
|
|
97
105
|
NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, out);
|