@rosepetal/node-red-contrib-image-tools 1.1.3 → 1.2.2
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/README.md +1 -13
- package/node-red-contrib-image-tools/lib/node-utils.js +218 -17
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +64 -9
- package/node-red-contrib-image-tools/nodes/blend/add-mask.js +81 -9
- package/node-red-contrib-image-tools/nodes/blend/add-masks.js +64 -8
- package/node-red-contrib-image-tools/nodes/blend/blend.js +64 -10
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +12 -1
- package/node-red-contrib-image-tools/nodes/io/image-in.js +10 -2
- package/node-red-contrib-image-tools/nodes/io/image-out.js +25 -3
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +52 -26
- package/node-red-contrib-image-tools/nodes/mix/concat.js +46 -9
- package/node-red-contrib-image-tools/nodes/mix/mosaic.js +52 -15
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +53 -5
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +54 -7
- package/node-red-contrib-image-tools/nodes/transform/color-convert.html +189 -0
- package/node-red-contrib-image-tools/nodes/transform/color-convert.js +153 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.js +38 -17
- package/node-red-contrib-image-tools/nodes/transform/draw.js +28 -7
- package/node-red-contrib-image-tools/nodes/transform/filter.js +34 -15
- package/node-red-contrib-image-tools/nodes/transform/padding.js +30 -9
- package/node-red-contrib-image-tools/nodes/transform/resize.js +58 -33
- package/node-red-contrib-image-tools/nodes/transform/rotate.html +5 -5
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +40 -20
- package/node-red-contrib-image-tools/package.json +2 -8
- package/package.json +2 -1
- package/rosepetal-image-engine/binding.gyp +7 -24
- package/rosepetal-image-engine/src/add-mask.cpp +2 -2
- package/rosepetal-image-engine/src/add-masks.cpp +2 -2
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +7 -8
- package/rosepetal-image-engine/src/blend.cpp +2 -2
- package/rosepetal-image-engine/src/color-convert.cpp +184 -0
- package/rosepetal-image-engine/src/concat.cpp +4 -4
- package/rosepetal-image-engine/src/crop.cpp +7 -7
- package/rosepetal-image-engine/src/draw.cpp +1 -1
- package/rosepetal-image-engine/src/filter.cpp +7 -7
- 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 +8 -9
- package/rosepetal-image-engine/src/padding.cpp +8 -7
- package/rosepetal-image-engine/src/resize.cpp +105 -27
- package/rosepetal-image-engine/src/rotate.cpp +9 -12
- package/rosepetal-image-engine/src/utils.h +48 -10
- package/docs/nodes/io/array-in.md +0 -119
- package/docs/nodes/io/array-out.md +0 -150
- package/docs/nodes/io/array-select.md +0 -157
- package/docs/nodes/io/queue.md +0 -57
- package/docs/nodes/io/save-file.md +0 -30
- package/docs/nodes/util/block-detect.md +0 -46
- package/node-red-contrib-image-tools/nodes/io/array-in.html +0 -110
- package/node-red-contrib-image-tools/nodes/io/array-in.js +0 -113
- package/node-red-contrib-image-tools/nodes/io/array-out.html +0 -125
- package/node-red-contrib-image-tools/nodes/io/array-out.js +0 -213
- package/node-red-contrib-image-tools/nodes/io/array-select.html +0 -156
- package/node-red-contrib-image-tools/nodes/io/array-select.js +0 -187
- package/node-red-contrib-image-tools/nodes/io/queue.html +0 -119
- package/node-red-contrib-image-tools/nodes/io/queue.js +0 -191
- package/node-red-contrib-image-tools/nodes/io/save-file.html +0 -243
- package/node-red-contrib-image-tools/nodes/io/save-file.js +0 -440
- package/node-red-contrib-image-tools/nodes/util/block-detect.html +0 -85
- package/node-red-contrib-image-tools/nodes/util/block-detect.js +0 -136
- package/node-red-contrib-image-tools/nodes/util/clean-debug.html +0 -201
- package/node-red-contrib-image-tools/nodes/util/clean-debug.js +0 -393
|
@@ -14,13 +14,39 @@ module.exports = function (RED) {
|
|
|
14
14
|
const node = this;
|
|
15
15
|
|
|
16
16
|
node.on('input', async (msg, send, done) => {
|
|
17
|
+
/* I/O paths */
|
|
18
|
+
const inputPath = config.inputPath || 'payload';
|
|
19
|
+
const inputPathType = config.inputPathType || 'msg';
|
|
20
|
+
const outputPath = config.outputPath || 'payload';
|
|
21
|
+
const outputPathType = config.outputPathType || 'msg';
|
|
22
|
+
|
|
23
|
+
const { value: inputImages, error: inputErr } =
|
|
24
|
+
NodeUtils.getInputValue(node, msg, inputPath, inputPathType);
|
|
25
|
+
if (inputErr) {
|
|
26
|
+
const hint = inputPathType === 'msg'
|
|
27
|
+
? `Set inputPath to an existing msg property (e.g. "payload"), or ensure "${inputPath}" exists before this node.`
|
|
28
|
+
: `Set inputPath to an existing ${inputPathType} context key, or ensure "${inputPath}" exists before this node.`;
|
|
29
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
30
|
+
node,
|
|
31
|
+
{
|
|
32
|
+
message: `Invalid inputPath "${inputPath}" (${inputPathType}): ${inputErr.message}`,
|
|
33
|
+
hint,
|
|
34
|
+
details: { inputPath, inputPathType, outputPath, outputPathType }
|
|
35
|
+
},
|
|
36
|
+
msg,
|
|
37
|
+
send,
|
|
38
|
+
done,
|
|
39
|
+
{ originalPayload: undefined, outputPath: null, outputPathType, outputType: 'preserve' }
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const imageArrayForPassthrough = Array.isArray(inputImages) ? inputImages : [inputImages];
|
|
44
|
+
const passthroughImage = imageArrayForPassthrough[0];
|
|
45
|
+
|
|
17
46
|
try {
|
|
18
47
|
const t0 = performance.now();
|
|
19
48
|
node.status({});
|
|
20
49
|
|
|
21
|
-
/* I/O paths */
|
|
22
|
-
const inputPath = config.inputPath || 'payload';
|
|
23
|
-
const outputPath = config.outputPath || 'payload';
|
|
24
50
|
const outputFormat = config.outputFormat || 'raw';
|
|
25
51
|
const outputQuality = parseInt(config.outputQuality) || 90;
|
|
26
52
|
const pngOptimize = config.pngOptimize || false;
|
|
@@ -35,17 +61,21 @@ module.exports = function (RED) {
|
|
|
35
61
|
const positions = config.positions || [];
|
|
36
62
|
|
|
37
63
|
/* Input images array */
|
|
38
|
-
const
|
|
39
|
-
const imageArray = Array.isArray(inputImages) ? inputImages : [inputImages];
|
|
40
|
-
|
|
41
|
-
// Capture first image for error passthrough
|
|
42
|
-
const firstImage = imageArray[0];
|
|
64
|
+
const imageArray = imageArrayForPassthrough;
|
|
43
65
|
|
|
44
66
|
// Validate input images - mosaic expects array input
|
|
45
67
|
if (!NodeUtils.validateListImage(imageArray, node)) {
|
|
46
68
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
47
|
-
node,
|
|
48
|
-
{
|
|
69
|
+
node,
|
|
70
|
+
{
|
|
71
|
+
message: 'Invalid image list',
|
|
72
|
+
hint: `Ensure "${inputPath}" is an array of valid images. Use the "image-in" node or pass Buffers/Raw image objects.`,
|
|
73
|
+
details: { inputPath, inputPathType, outputPath, outputPathType }
|
|
74
|
+
},
|
|
75
|
+
msg,
|
|
76
|
+
send,
|
|
77
|
+
done,
|
|
78
|
+
{ originalPayload: passthroughImage, outputPath, outputPathType, outputType: 'single' }
|
|
49
79
|
);
|
|
50
80
|
}
|
|
51
81
|
|
|
@@ -76,7 +106,7 @@ module.exports = function (RED) {
|
|
|
76
106
|
);
|
|
77
107
|
|
|
78
108
|
/* Set output */
|
|
79
|
-
|
|
109
|
+
NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, image);
|
|
80
110
|
|
|
81
111
|
/* Performance status - same format as other nodes */
|
|
82
112
|
const { convertMs = 0, taskMs = 0, encodeMs = 0 } = timing;
|
|
@@ -84,12 +114,13 @@ module.exports = function (RED) {
|
|
|
84
114
|
|
|
85
115
|
// Debug image display
|
|
86
116
|
let debugFormat = null;
|
|
87
|
-
|
|
117
|
+
const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
|
|
118
|
+
if (debugEnabled) {
|
|
88
119
|
try {
|
|
89
120
|
// Resolve and validate debug width
|
|
90
121
|
let debugWidth = NodeUtils.resolveDimension(
|
|
91
122
|
node,
|
|
92
|
-
config.debugWidthType,
|
|
123
|
+
config.debugWidthType || 'num',
|
|
93
124
|
config.debugWidth,
|
|
94
125
|
msg
|
|
95
126
|
);
|
|
@@ -100,7 +131,7 @@ module.exports = function (RED) {
|
|
|
100
131
|
outputFormat,
|
|
101
132
|
outputQuality,
|
|
102
133
|
node,
|
|
103
|
-
|
|
134
|
+
debugEnabled,
|
|
104
135
|
debugWidth
|
|
105
136
|
);
|
|
106
137
|
|
|
@@ -141,7 +172,13 @@ module.exports = function (RED) {
|
|
|
141
172
|
} catch (err) {
|
|
142
173
|
NodeUtils.handleNodeErrorWithPassthrough(
|
|
143
174
|
node, err, msg, send, done, 'mosaic processing',
|
|
144
|
-
{
|
|
175
|
+
{
|
|
176
|
+
originalPayload: passthroughImage,
|
|
177
|
+
outputPath,
|
|
178
|
+
outputPathType,
|
|
179
|
+
outputType: 'single',
|
|
180
|
+
context: { inputPath, inputPathType, outputPath, outputPathType }
|
|
181
|
+
}
|
|
145
182
|
);
|
|
146
183
|
}
|
|
147
184
|
});
|
|
@@ -32,8 +32,39 @@ module.exports = function (RED) {
|
|
|
32
32
|
const minConfidence = NodeUtils.resolveDimension(node, config.minConfidenceType, config.minConfidence, msg) || 0.5;
|
|
33
33
|
|
|
34
34
|
/* Get input data */
|
|
35
|
-
const
|
|
36
|
-
|
|
35
|
+
const { value: imageData, error: imageErr } =
|
|
36
|
+
NodeUtils.safeGetMessageProperty(msg, imageInputPath);
|
|
37
|
+
if (imageErr) {
|
|
38
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
39
|
+
node,
|
|
40
|
+
{
|
|
41
|
+
message: `Invalid imageInputPath "${imageInputPath}": ${imageErr.message}`,
|
|
42
|
+
hint: `Ensure "${imageInputPath}" exists on msg and contains an image (or array of images).`,
|
|
43
|
+
details: { imageInputPath, bboxInputPath, outputPath }
|
|
44
|
+
},
|
|
45
|
+
msg,
|
|
46
|
+
send,
|
|
47
|
+
done,
|
|
48
|
+
{ originalPayload: [], outputPath, outputType: 'empty-array' }
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const { value: bboxData, error: bboxErr } =
|
|
53
|
+
NodeUtils.safeGetMessageProperty(msg, bboxInputPath);
|
|
54
|
+
if (bboxErr) {
|
|
55
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
56
|
+
node,
|
|
57
|
+
{
|
|
58
|
+
message: `Invalid bboxInputPath "${bboxInputPath}": ${bboxErr.message}`,
|
|
59
|
+
hint: `Ensure "${bboxInputPath}" exists on msg and contains a detection array (raw_boxes/confidence/tag).`,
|
|
60
|
+
details: { imageInputPath, bboxInputPath, outputPath }
|
|
61
|
+
},
|
|
62
|
+
msg,
|
|
63
|
+
send,
|
|
64
|
+
done,
|
|
65
|
+
{ originalPayload: [], outputPath, outputType: 'empty-array' }
|
|
66
|
+
);
|
|
67
|
+
}
|
|
37
68
|
|
|
38
69
|
if (!imageData) {
|
|
39
70
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
@@ -86,6 +117,22 @@ module.exports = function (RED) {
|
|
|
86
117
|
// For now, assume single image with all detections
|
|
87
118
|
// In the future, could handle multiple images with detection arrays
|
|
88
119
|
const image = images[0]; // Use first image
|
|
120
|
+
|
|
121
|
+
// cropBB needs image dimensions to convert normalized boxes -> pixels.
|
|
122
|
+
if (!image || typeof image.width !== 'number' || typeof image.height !== 'number') {
|
|
123
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
124
|
+
node,
|
|
125
|
+
{
|
|
126
|
+
message: 'cropBB requires raw images with width/height metadata',
|
|
127
|
+
hint: `Use the "image-in" node (raw output) before cropBB, or pass raw image objects instead of encoded Buffers.`,
|
|
128
|
+
details: { imageInputPath, bboxInputPath, outputPath }
|
|
129
|
+
},
|
|
130
|
+
msg,
|
|
131
|
+
send,
|
|
132
|
+
done,
|
|
133
|
+
{ originalPayload: [], outputPath, outputType: 'empty-array' }
|
|
134
|
+
);
|
|
135
|
+
}
|
|
89
136
|
|
|
90
137
|
/* Filter detections by confidence and extract bounding boxes */
|
|
91
138
|
const validBboxes = [];
|
|
@@ -148,9 +195,10 @@ module.exports = function (RED) {
|
|
|
148
195
|
|
|
149
196
|
// Debug image display for first crop if enabled
|
|
150
197
|
let debugFormat = null;
|
|
151
|
-
|
|
198
|
+
const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
|
|
199
|
+
if (debugEnabled && allCrops.length > 0) {
|
|
152
200
|
try {
|
|
153
|
-
let debugWidth = NodeUtils.resolveDimension(node, config.debugWidthType, config.debugWidth, msg) || 200;
|
|
201
|
+
let debugWidth = NodeUtils.resolveDimension(node, config.debugWidthType || 'num', config.debugWidth, msg) || 200;
|
|
154
202
|
debugWidth = Math.max(1, parseInt(debugWidth));
|
|
155
203
|
|
|
156
204
|
const debugResult = await NodeUtils.debugImageDisplay(
|
|
@@ -158,7 +206,7 @@ module.exports = function (RED) {
|
|
|
158
206
|
outputFormat,
|
|
159
207
|
outputQuality,
|
|
160
208
|
node,
|
|
161
|
-
|
|
209
|
+
debugEnabled,
|
|
162
210
|
debugWidth
|
|
163
211
|
);
|
|
164
212
|
|
|
@@ -16,8 +16,42 @@ module.exports = function (RED) {
|
|
|
16
16
|
node.on('input', async (msg, send, done) => {
|
|
17
17
|
// Capture images early for error passthrough
|
|
18
18
|
const outputPath = config.outputPath || 'payload';
|
|
19
|
-
const
|
|
20
|
-
const
|
|
19
|
+
const referenceImagePath = config.referenceImagePath || 'payload.reference';
|
|
20
|
+
const targetImagePath = config.targetImagePath || 'payload.target';
|
|
21
|
+
|
|
22
|
+
const { value: referenceImage, error: refErr } =
|
|
23
|
+
NodeUtils.safeGetMessageProperty(msg, referenceImagePath);
|
|
24
|
+
if (refErr) {
|
|
25
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
26
|
+
node,
|
|
27
|
+
{
|
|
28
|
+
message: `Invalid referenceImagePath "${referenceImagePath}": ${refErr.message}`,
|
|
29
|
+
hint: `Ensure "${referenceImagePath}" exists on msg and contains an image.`,
|
|
30
|
+
details: { referenceImagePath, targetImagePath, outputPath }
|
|
31
|
+
},
|
|
32
|
+
msg,
|
|
33
|
+
send,
|
|
34
|
+
done,
|
|
35
|
+
{ originalPayload: undefined, outputPath: null, outputType: 'preserve' }
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const { value: targetImage, error: targetErr } =
|
|
40
|
+
NodeUtils.safeGetMessageProperty(msg, targetImagePath);
|
|
41
|
+
if (targetErr) {
|
|
42
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
43
|
+
node,
|
|
44
|
+
{
|
|
45
|
+
message: `Invalid targetImagePath "${targetImagePath}": ${targetErr.message}`,
|
|
46
|
+
hint: `Ensure "${targetImagePath}" exists on msg and contains an image.`,
|
|
47
|
+
details: { referenceImagePath, targetImagePath, outputPath }
|
|
48
|
+
},
|
|
49
|
+
msg,
|
|
50
|
+
send,
|
|
51
|
+
done,
|
|
52
|
+
{ originalPayload: referenceImage, outputPath, outputType: 'single' }
|
|
53
|
+
);
|
|
54
|
+
}
|
|
21
55
|
|
|
22
56
|
// For error passthrough: prefer target, fallback to reference, else undefined
|
|
23
57
|
const passthroughImage = targetImage || referenceImage || undefined;
|
|
@@ -55,7 +89,14 @@ module.exports = function (RED) {
|
|
|
55
89
|
let polygon = null;
|
|
56
90
|
let isPolygonArray = false;
|
|
57
91
|
if (transformPolygon) {
|
|
58
|
-
|
|
92
|
+
const polygonPath = config.polygonPath || 'payload.polygon';
|
|
93
|
+
const { value, error } = NodeUtils.safeGetMessageProperty(msg, polygonPath);
|
|
94
|
+
if (error) {
|
|
95
|
+
node.warn(`Invalid polygonPath "${polygonPath}": ${error.message} (polygon transform skipped)`);
|
|
96
|
+
polygon = null;
|
|
97
|
+
} else {
|
|
98
|
+
polygon = value;
|
|
99
|
+
}
|
|
59
100
|
|
|
60
101
|
// Validate polygon coordinates
|
|
61
102
|
if (polygon) {
|
|
@@ -221,12 +262,13 @@ module.exports = function (RED) {
|
|
|
221
262
|
|
|
222
263
|
// Debug image display
|
|
223
264
|
let debugFormat = null;
|
|
224
|
-
|
|
265
|
+
const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
|
|
266
|
+
if (debugEnabled) {
|
|
225
267
|
try {
|
|
226
268
|
// Resolve and validate debug width
|
|
227
269
|
let debugWidth = NodeUtils.resolveDimension(
|
|
228
270
|
node,
|
|
229
|
-
config.debugWidthType,
|
|
271
|
+
config.debugWidthType || 'num',
|
|
230
272
|
config.debugWidth,
|
|
231
273
|
msg
|
|
232
274
|
);
|
|
@@ -237,7 +279,7 @@ module.exports = function (RED) {
|
|
|
237
279
|
outputFormat,
|
|
238
280
|
outputQuality,
|
|
239
281
|
node,
|
|
240
|
-
|
|
282
|
+
debugEnabled,
|
|
241
283
|
debugWidth
|
|
242
284
|
);
|
|
243
285
|
|
|
@@ -296,7 +338,12 @@ module.exports = function (RED) {
|
|
|
296
338
|
} catch (err) {
|
|
297
339
|
NodeUtils.handleNodeErrorWithPassthrough(
|
|
298
340
|
node, err, msg, send, done, 'image-align processing',
|
|
299
|
-
{
|
|
341
|
+
{
|
|
342
|
+
originalPayload: passthroughImage,
|
|
343
|
+
outputPath,
|
|
344
|
+
outputType: 'single',
|
|
345
|
+
context: { referenceImagePath, targetImagePath, outputPath }
|
|
346
|
+
}
|
|
300
347
|
);
|
|
301
348
|
}
|
|
302
349
|
});
|
|
@@ -0,0 +1,189 @@
|
|
|
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
|
+
// Debug configuration
|
|
15
|
+
debugEnabled : { value:false },
|
|
16
|
+
debugWidth : { value:200 },
|
|
17
|
+
debugWidthType : { value:"num" },
|
|
18
|
+
targetColorSpace: { value:"RGB" }
|
|
19
|
+
},
|
|
20
|
+
inputs :1, outputs:1,
|
|
21
|
+
icon:"font-awesome/fa-paint-brush",
|
|
22
|
+
label:function(){ return this.name || "color-convert"; },
|
|
23
|
+
|
|
24
|
+
oneditprepare:function(){
|
|
25
|
+
$("#node-input-inputPath").typedInput({default:'msg',types:['msg','flow','global'],typeField:"#node-input-inputPathType"});
|
|
26
|
+
$("#node-input-outputPath").typedInput({default:'msg',types:['msg','flow','global'],typeField:"#node-input-outputPathType"});
|
|
27
|
+
|
|
28
|
+
function updateQualityVisibility(){
|
|
29
|
+
const format = $("#node-input-outputFormat").val();
|
|
30
|
+
$("#quality-row").toggle(format === "jpg" || format === "webp");
|
|
31
|
+
$("#png-optimize-row").toggle(format === "png");
|
|
32
|
+
}
|
|
33
|
+
$("#node-input-outputFormat").on("change", updateQualityVisibility);
|
|
34
|
+
updateQualityVisibility(); // initial state
|
|
35
|
+
|
|
36
|
+
// === Debug Display Logic ===
|
|
37
|
+
const debugCheckbox = $('#node-input-debugEnabled');
|
|
38
|
+
const debugWidthRow = $('#debug-width-row');
|
|
39
|
+
|
|
40
|
+
// Initialize debug width TypedInput
|
|
41
|
+
$("#node-input-debugWidth").typedInput({
|
|
42
|
+
default: 'num',
|
|
43
|
+
types: ['num', 'msg', 'flow', 'global'],
|
|
44
|
+
typeField: "#node-input-debugWidthType"
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Function to toggle debug width visibility
|
|
48
|
+
function updateDebugWidthVisibility() {
|
|
49
|
+
if (debugCheckbox.is(':checked')) {
|
|
50
|
+
debugWidthRow.show();
|
|
51
|
+
} else {
|
|
52
|
+
debugWidthRow.hide();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Initialize debug state on node open
|
|
57
|
+
updateDebugWidthVisibility();
|
|
58
|
+
|
|
59
|
+
// Handle debug checkbox changes
|
|
60
|
+
debugCheckbox.on('change', function() {
|
|
61
|
+
const enabled = this.checked;
|
|
62
|
+
updateDebugWidthVisibility();
|
|
63
|
+
$('#node-input-debugEnabled').data('debug-enabled', enabled);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<script type="text/x-red" data-template-name="color-convert">
|
|
70
|
+
<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>
|
|
71
|
+
<hr>
|
|
72
|
+
<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>
|
|
73
|
+
<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>
|
|
74
|
+
<div class="form-row">
|
|
75
|
+
<label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
|
|
76
|
+
<select id="node-input-outputFormat" style="width: 200px;">
|
|
77
|
+
<option value="raw">Raw (fastest)</option>
|
|
78
|
+
<option value="jpg">JPEG</option>
|
|
79
|
+
<option value="png">PNG</option>
|
|
80
|
+
<option value="webp">WebP</option>
|
|
81
|
+
</select>
|
|
82
|
+
</div>
|
|
83
|
+
<div class="form-row" id="quality-row">
|
|
84
|
+
<label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
|
|
85
|
+
<input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
|
|
86
|
+
<span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
|
|
87
|
+
</div>
|
|
88
|
+
<div class="form-row" id="png-optimize-row" style="display: none;">
|
|
89
|
+
<label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
|
|
90
|
+
<input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
91
|
+
<label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
|
|
92
|
+
</div>
|
|
93
|
+
|
|
94
|
+
<!-- Debug Configuration -->
|
|
95
|
+
<div class="form-row">
|
|
96
|
+
<label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
|
|
97
|
+
<input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
98
|
+
<label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
|
|
99
|
+
</div>
|
|
100
|
+
<div class="form-row" id="debug-width-row" style="display: none;">
|
|
101
|
+
<label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
|
|
102
|
+
<input type="text" id="node-input-debugWidth" style="width: 120px;">
|
|
103
|
+
<input type="hidden" id="node-input-debugWidthType">
|
|
104
|
+
<span style="margin-left: 10px; color: #666;">pixels</span>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<hr>
|
|
108
|
+
<div class="form-row">
|
|
109
|
+
<label for="node-input-targetColorSpace"><i class="fa fa-paint-brush"></i> Target Color Space</label>
|
|
110
|
+
<select id="node-input-targetColorSpace" style="width: 200px;">
|
|
111
|
+
<option value="GRAY">Grayscale (GRAY)</option>
|
|
112
|
+
<option value="RGB">RGB</option>
|
|
113
|
+
<option value="RGBA">RGBA</option>
|
|
114
|
+
<option value="BGR">BGR</option>
|
|
115
|
+
<option value="BGRA">BGRA</option>
|
|
116
|
+
</select>
|
|
117
|
+
</div>
|
|
118
|
+
</script>
|
|
119
|
+
|
|
120
|
+
<script type="text/x-red" data-help-name="color-convert">
|
|
121
|
+
<p>Converts images between color spaces (GRAY, RGB, RGBA, BGR, BGRA) using high-performance C++ processing.</p>
|
|
122
|
+
|
|
123
|
+
<h3>Details</h3>
|
|
124
|
+
<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>
|
|
125
|
+
|
|
126
|
+
<h3>Properties</h3>
|
|
127
|
+
<dl class="message-properties">
|
|
128
|
+
<dt>Input from <span class="property-type">string</span></dt>
|
|
129
|
+
<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>
|
|
130
|
+
<dt>Output to <span class="property-type">string</span></dt>
|
|
131
|
+
<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>
|
|
132
|
+
<dt>Output Format <span class="property-type">string</span></dt>
|
|
133
|
+
<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>
|
|
134
|
+
<dt>Quality <span class="property-type">number</span></dt>
|
|
135
|
+
<dd>Compression quality for JPEG and WebP formats (1-100). Only visible when jpg or webp format is selected. Default: 90.</dd>
|
|
136
|
+
<dt>Target Color Space <span class="property-type">string</span></dt>
|
|
137
|
+
<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>
|
|
138
|
+
</dl>
|
|
139
|
+
|
|
140
|
+
<h3>Inputs</h3>
|
|
141
|
+
<dl class="message-properties">
|
|
142
|
+
<dt>payload <span class="property-type">object | array</span></dt>
|
|
143
|
+
<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>
|
|
144
|
+
</dl>
|
|
145
|
+
|
|
146
|
+
<h3>Outputs</h3>
|
|
147
|
+
<dl class="message-properties">
|
|
148
|
+
<dt>payload <span class="property-type">object | array | Buffer</span></dt>
|
|
149
|
+
<dd>Converted image(s). Format depends on Output Format setting: raw image object(s) or encoded file buffer(s).</dd>
|
|
150
|
+
</dl>
|
|
151
|
+
|
|
152
|
+
<h3>Supported Conversions</h3>
|
|
153
|
+
<p>All 20 conversion paths between the 5 color spaces are supported:</p>
|
|
154
|
+
<ul>
|
|
155
|
+
<li><strong>GRAY →</strong> BGR, RGB, BGRA, RGBA</li>
|
|
156
|
+
<li><strong>BGR →</strong> GRAY, RGB, BGRA, RGBA</li>
|
|
157
|
+
<li><strong>RGB →</strong> GRAY, BGR, BGRA, RGBA</li>
|
|
158
|
+
<li><strong>BGRA →</strong> GRAY, BGR, RGB, RGBA</li>
|
|
159
|
+
<li><strong>RGBA →</strong> GRAY, BGR, RGB, BGRA</li>
|
|
160
|
+
</ul>
|
|
161
|
+
<p>If the source and target color space are the same, a fast passthrough is used (no conversion overhead).</p>
|
|
162
|
+
|
|
163
|
+
<h3>Examples</h3>
|
|
164
|
+
<ul>
|
|
165
|
+
<li><strong>RGB → GRAY:</strong> Convert a color image to grayscale (3 channels → 1 channel)</li>
|
|
166
|
+
<li><strong>GRAY → RGBA:</strong> Expand grayscale to RGBA with full alpha (1 channel → 4 channels)</li>
|
|
167
|
+
<li><strong>BGR → RGB:</strong> Swap blue and red channels for display compatibility</li>
|
|
168
|
+
<li><strong>RGB → BGRA:</strong> Add alpha channel and convert to OpenCV-native order</li>
|
|
169
|
+
</ul>
|
|
170
|
+
|
|
171
|
+
<h3>Node Interactions</h3>
|
|
172
|
+
<p><strong>Input Sources:</strong> Image-in, Array-out, other transform nodes</p>
|
|
173
|
+
<p><strong>Output Destinations:</strong> Other transform nodes, Mix nodes (concat, mosaic), Array-in for collections</p>
|
|
174
|
+
<p><strong>Common Workflows:</strong> Preparing images for specific processing pipelines, ensuring consistent color spaces before blending or concatenation</p>
|
|
175
|
+
|
|
176
|
+
<h3>Output Formats</h3>
|
|
177
|
+
<ul>
|
|
178
|
+
<li><strong>Raw:</strong> Standard image object (fastest, for further processing)</li>
|
|
179
|
+
<li><strong>JPEG:</strong> Compressed file buffer with quality setting</li>
|
|
180
|
+
<li><strong>PNG:</strong> Lossless compressed file buffer</li>
|
|
181
|
+
<li><strong>WebP:</strong> Modern compressed format with quality setting</li>
|
|
182
|
+
</ul>
|
|
183
|
+
|
|
184
|
+
<h3>Error Handling</h3>
|
|
185
|
+
<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>
|
|
186
|
+
|
|
187
|
+
<h3>Performance</h3>
|
|
188
|
+
<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>
|
|
189
|
+
</script>
|
|
@@ -0,0 +1,153 @@
|
|
|
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 targetColorSpace = config.targetColorSpace || 'RGB';
|
|
46
|
+
|
|
47
|
+
// Validate input images with error passthrough
|
|
48
|
+
if (Array.isArray(originalPayload)) {
|
|
49
|
+
if (!NodeUtils.validateListImage(originalPayload, node)) {
|
|
50
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
51
|
+
node, 'Invalid image list structure', msg, send, done,
|
|
52
|
+
{ originalPayload, outputPath, outputPathType, outputType: 'preserve' }
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
if (!NodeUtils.validateSingleImage(originalPayload, node)) {
|
|
57
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
58
|
+
node, 'Invalid image structure', msg, send, done,
|
|
59
|
+
{ originalPayload, outputPath, outputPathType, outputType: 'preserve' }
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const imgs = Array.isArray(originalPayload) ? originalPayload : [originalPayload];
|
|
65
|
+
|
|
66
|
+
/* ——— launch conversions in parallel ——— */
|
|
67
|
+
const promises = imgs.map(img =>
|
|
68
|
+
CppProcessor.colorConvert(img, targetColorSpace, outputFormat, outputQuality, pngOptimize)
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const results = await Promise.all(promises);
|
|
72
|
+
|
|
73
|
+
/* ——— accumulate metrics ——— */
|
|
74
|
+
const { totalConvertMs, totalTaskMs, encodeMs, images } =
|
|
75
|
+
results.reduce((acc, { image, timing }) => {
|
|
76
|
+
acc.totalConvertMs += timing?.convertMs ?? 0;
|
|
77
|
+
acc.totalTaskMs += timing?.taskMs ?? 0;
|
|
78
|
+
acc.encodeMs += timing?.encodeMs ?? 0;
|
|
79
|
+
acc.images.push(image);
|
|
80
|
+
return acc;
|
|
81
|
+
}, { totalConvertMs: 0, totalTaskMs: 0, encodeMs: 0, images: [] });
|
|
82
|
+
|
|
83
|
+
const out = Array.isArray(originalPayload) ? images : images[0];
|
|
84
|
+
const durMs = performance.now() - t0;
|
|
85
|
+
|
|
86
|
+
NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, out);
|
|
87
|
+
|
|
88
|
+
// Debug image display
|
|
89
|
+
let debugFormat = null;
|
|
90
|
+
const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
|
|
91
|
+
if (debugEnabled) {
|
|
92
|
+
try {
|
|
93
|
+
let debugWidth = NodeUtils.resolveDimension(
|
|
94
|
+
node,
|
|
95
|
+
config.debugWidthType || 'num',
|
|
96
|
+
config.debugWidth,
|
|
97
|
+
msg
|
|
98
|
+
);
|
|
99
|
+
debugWidth = Math.max(1, parseInt(debugWidth) || 200);
|
|
100
|
+
|
|
101
|
+
const debugImage = images[0];
|
|
102
|
+
const debugResult = await NodeUtils.debugImageDisplay(
|
|
103
|
+
debugImage,
|
|
104
|
+
outputFormat,
|
|
105
|
+
outputQuality,
|
|
106
|
+
node,
|
|
107
|
+
debugEnabled,
|
|
108
|
+
debugWidth
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (debugResult) {
|
|
112
|
+
debugFormat = debugResult.formatMessage;
|
|
113
|
+
NodeUtils.setSuccessStatusWithDebug(node, imgs.length, durMs, {
|
|
114
|
+
convertMs: totalConvertMs,
|
|
115
|
+
taskMs: totalTaskMs,
|
|
116
|
+
encodeMs: encodeMs
|
|
117
|
+
}, debugFormat + (Array.isArray(originalPayload) ? ' (first)' : ''));
|
|
118
|
+
}
|
|
119
|
+
} catch (debugError) {
|
|
120
|
+
node.warn(`Debug display error: ${debugError.message}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Set regular status if debug not enabled or failed
|
|
125
|
+
if (!debugFormat) {
|
|
126
|
+
node.status({
|
|
127
|
+
fill : 'green',
|
|
128
|
+
shape : 'dot',
|
|
129
|
+
text : `OK: ${imgs.length} img in ${durMs.toFixed(2)} ms `
|
|
130
|
+
+ `(conv ${(totalConvertMs + encodeMs).toFixed(2)} ms `
|
|
131
|
+
+ `| task ${totalTaskMs.toFixed(2)} ms)`
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
NodeUtils.recordPerformanceMetrics(node, msg, {
|
|
136
|
+
convertMs: totalConvertMs,
|
|
137
|
+
encodeMs: encodeMs,
|
|
138
|
+
taskMs: totalTaskMs
|
|
139
|
+
}, durMs);
|
|
140
|
+
|
|
141
|
+
send(msg);
|
|
142
|
+
done && done();
|
|
143
|
+
} catch (err) {
|
|
144
|
+
NodeUtils.handleNodeErrorWithPassthrough(
|
|
145
|
+
node, err, msg, send, done, 'color-convert processing',
|
|
146
|
+
{ originalPayload, outputPath, outputPathType, outputType: 'preserve' }
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
RED.nodes.registerType('color-convert', ColorConvertNode);
|
|
153
|
+
};
|