@rosepetal/node-red-contrib-image-tools 1.1.3 → 1.2.0
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/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.js +40 -20
- package/node-red-contrib-image-tools/package.json +1 -8
- package/package.json +1 -1
- package/rosepetal-image-engine/binding.gyp +5 -23
- 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 +3 -4
- package/rosepetal-image-engine/src/blend.cpp +2 -2
- package/rosepetal-image-engine/src/concat.cpp +2 -2
- package/rosepetal-image-engine/src/crop.cpp +3 -3
- package/rosepetal-image-engine/src/draw.cpp +1 -1
- package/rosepetal-image-engine/src/filter.cpp +3 -3
- package/rosepetal-image-engine/src/mosaic.cpp +4 -5
- package/rosepetal-image-engine/src/padding.cpp +4 -3
- package/rosepetal-image-engine/src/resize.cpp +101 -23
- package/rosepetal-image-engine/src/rotate.cpp +3 -6
- package/rosepetal-image-engine/src/utils.h +46 -8
- 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
|
@@ -20,7 +20,26 @@ module.exports = function (RED) {
|
|
|
20
20
|
node.on('input', async (msg, send, done) => {
|
|
21
21
|
// Capture original payload for error passthrough
|
|
22
22
|
const outputPath = config.outputPath || 'payload';
|
|
23
|
-
const
|
|
23
|
+
const imagePath = config.imagePath || 'payload.image';
|
|
24
|
+
const masksPath = config.masksPath || 'payload';
|
|
25
|
+
|
|
26
|
+
const { value: image, error: imageErr } =
|
|
27
|
+
NodeUtils.safeGetMessageProperty(msg, imagePath);
|
|
28
|
+
if (imageErr) {
|
|
29
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
30
|
+
node,
|
|
31
|
+
{
|
|
32
|
+
message: `Invalid imagePath "${imagePath}": ${imageErr.message}`,
|
|
33
|
+
hint: `Ensure "${imagePath}" exists on msg and contains an image.`,
|
|
34
|
+
details: { imagePath, masksPath, outputPath }
|
|
35
|
+
},
|
|
36
|
+
msg,
|
|
37
|
+
send,
|
|
38
|
+
done,
|
|
39
|
+
{ originalPayload: undefined, outputPath: null, outputType: 'preserve' }
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
24
43
|
const originalPayload = image;
|
|
25
44
|
|
|
26
45
|
try {
|
|
@@ -29,13 +48,36 @@ module.exports = function (RED) {
|
|
|
29
48
|
|
|
30
49
|
/* ▸ Read image and masks array from message ------------------------ */
|
|
31
50
|
// Get base image and masks array from specified paths
|
|
32
|
-
const
|
|
51
|
+
const { value: masksArray, error: masksErr } =
|
|
52
|
+
NodeUtils.safeGetMessageProperty(msg, masksPath);
|
|
53
|
+
if (masksErr) {
|
|
54
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
55
|
+
node,
|
|
56
|
+
{
|
|
57
|
+
message: `Invalid masksPath "${masksPath}": ${masksErr.message}`,
|
|
58
|
+
hint: `Ensure "${masksPath}" exists on msg and contains an array of masks.`,
|
|
59
|
+
details: { imagePath, masksPath, outputPath }
|
|
60
|
+
},
|
|
61
|
+
msg,
|
|
62
|
+
send,
|
|
63
|
+
done,
|
|
64
|
+
{ originalPayload, outputPath, outputType: 'single' }
|
|
65
|
+
);
|
|
66
|
+
}
|
|
33
67
|
|
|
34
68
|
// Validate base image
|
|
35
69
|
const baseImg = NodeUtils.validateImageStructure(image, node);
|
|
36
70
|
if (!baseImg) {
|
|
37
71
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
38
|
-
node,
|
|
72
|
+
node,
|
|
73
|
+
{
|
|
74
|
+
message: 'Base image is invalid or missing',
|
|
75
|
+
hint: `Check that "${imagePath}" contains a valid image (Buffer or raw image object).`,
|
|
76
|
+
details: { imagePath, masksPath, outputPath }
|
|
77
|
+
},
|
|
78
|
+
msg,
|
|
79
|
+
send,
|
|
80
|
+
done,
|
|
39
81
|
{ originalPayload, outputPath, outputType: 'single' }
|
|
40
82
|
);
|
|
41
83
|
}
|
|
@@ -43,7 +85,15 @@ module.exports = function (RED) {
|
|
|
43
85
|
// Validate masks array - expect direct array format
|
|
44
86
|
if (!Array.isArray(masksArray)) {
|
|
45
87
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
46
|
-
node,
|
|
88
|
+
node,
|
|
89
|
+
{
|
|
90
|
+
message: 'Masks input must be an array',
|
|
91
|
+
hint: `Set "${masksPath}" to an array of masks. Each entry should include either "polygons" or "mask" plus a class/tag.`,
|
|
92
|
+
details: { masksPath, outputPath }
|
|
93
|
+
},
|
|
94
|
+
msg,
|
|
95
|
+
send,
|
|
96
|
+
done,
|
|
47
97
|
{ originalPayload, outputPath, outputType: 'single' }
|
|
48
98
|
);
|
|
49
99
|
}
|
|
@@ -269,12 +319,13 @@ module.exports = function (RED) {
|
|
|
269
319
|
|
|
270
320
|
// Debug image display
|
|
271
321
|
let debugFormat = null;
|
|
272
|
-
|
|
322
|
+
const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
|
|
323
|
+
if (debugEnabled) {
|
|
273
324
|
try {
|
|
274
325
|
// Resolve and validate debug width
|
|
275
326
|
let debugWidth = NodeUtils.resolveDimension(
|
|
276
327
|
node,
|
|
277
|
-
config.debugWidthType,
|
|
328
|
+
config.debugWidthType || 'num',
|
|
278
329
|
config.debugWidth,
|
|
279
330
|
msg
|
|
280
331
|
);
|
|
@@ -285,7 +336,7 @@ module.exports = function (RED) {
|
|
|
285
336
|
outputFormat,
|
|
286
337
|
outputQuality,
|
|
287
338
|
node,
|
|
288
|
-
|
|
339
|
+
debugEnabled,
|
|
289
340
|
debugWidth
|
|
290
341
|
);
|
|
291
342
|
|
|
@@ -311,7 +362,12 @@ module.exports = function (RED) {
|
|
|
311
362
|
} catch (err) {
|
|
312
363
|
NodeUtils.handleNodeErrorWithPassthrough(
|
|
313
364
|
node, err, msg, send, done, 'add-masks processing',
|
|
314
|
-
{
|
|
365
|
+
{
|
|
366
|
+
originalPayload,
|
|
367
|
+
outputPath,
|
|
368
|
+
outputType: 'single',
|
|
369
|
+
context: { imagePath, masksPath, outputPath }
|
|
370
|
+
}
|
|
315
371
|
);
|
|
316
372
|
}
|
|
317
373
|
});
|
|
@@ -19,9 +19,27 @@ module.exports = function (RED) {
|
|
|
19
19
|
node.on('input', async (msg, send, done) => {
|
|
20
20
|
// Capture output path for error passthrough
|
|
21
21
|
const outputPath = config.outputPath || 'payload';
|
|
22
|
+
const image1Path = config.image1Path || 'payload.image1';
|
|
23
|
+
const image2Path = config.image2Path || 'payload.image2';
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
const { value: image1, error: image1Err } =
|
|
26
|
+
NodeUtils.safeGetMessageProperty(msg, image1Path);
|
|
27
|
+
if (image1Err) {
|
|
28
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
29
|
+
node,
|
|
30
|
+
{
|
|
31
|
+
message: `Invalid image1Path "${image1Path}": ${image1Err.message}`,
|
|
32
|
+
hint: `Ensure "${image1Path}" exists on msg before this node.`,
|
|
33
|
+
details: { image1Path, image2Path, outputPath }
|
|
34
|
+
},
|
|
35
|
+
msg,
|
|
36
|
+
send,
|
|
37
|
+
done,
|
|
38
|
+
{ originalPayload: undefined, outputPath: null, outputType: 'preserve' }
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Base image passthrough (use first/base image)
|
|
25
43
|
const baseImageForPassthrough = image1;
|
|
26
44
|
|
|
27
45
|
try {
|
|
@@ -29,14 +47,36 @@ module.exports = function (RED) {
|
|
|
29
47
|
node.status({}); // clear status
|
|
30
48
|
|
|
31
49
|
/* ▸ Read images from message ------------------------------------ */
|
|
32
|
-
|
|
33
|
-
|
|
50
|
+
const { value: image2, error: image2Err } =
|
|
51
|
+
NodeUtils.safeGetMessageProperty(msg, image2Path);
|
|
52
|
+
if (image2Err) {
|
|
53
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
54
|
+
node,
|
|
55
|
+
{
|
|
56
|
+
message: `Invalid image2Path "${image2Path}": ${image2Err.message}`,
|
|
57
|
+
hint: `Ensure "${image2Path}" exists on msg before this node.`,
|
|
58
|
+
details: { image1Path, image2Path, outputPath }
|
|
59
|
+
},
|
|
60
|
+
msg,
|
|
61
|
+
send,
|
|
62
|
+
done,
|
|
63
|
+
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'single' }
|
|
64
|
+
);
|
|
65
|
+
}
|
|
34
66
|
|
|
35
67
|
// Validate input images
|
|
36
68
|
const img1 = NodeUtils.validateImageStructure(image1, node);
|
|
37
69
|
if (!img1) {
|
|
38
70
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
39
|
-
node,
|
|
71
|
+
node,
|
|
72
|
+
{
|
|
73
|
+
message: 'First image is invalid or missing',
|
|
74
|
+
hint: `Check that "${image1Path}" contains a valid image (Buffer or raw image object).`,
|
|
75
|
+
details: { image1Path, image2Path, outputPath }
|
|
76
|
+
},
|
|
77
|
+
msg,
|
|
78
|
+
send,
|
|
79
|
+
done,
|
|
40
80
|
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'single' }
|
|
41
81
|
);
|
|
42
82
|
}
|
|
@@ -44,7 +84,15 @@ module.exports = function (RED) {
|
|
|
44
84
|
const img2 = NodeUtils.validateImageStructure(image2, node);
|
|
45
85
|
if (!img2) {
|
|
46
86
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
47
|
-
node,
|
|
87
|
+
node,
|
|
88
|
+
{
|
|
89
|
+
message: 'Second image is invalid or missing',
|
|
90
|
+
hint: `Check that "${image2Path}" contains a valid image (Buffer or raw image object).`,
|
|
91
|
+
details: { image1Path, image2Path, outputPath }
|
|
92
|
+
},
|
|
93
|
+
msg,
|
|
94
|
+
send,
|
|
95
|
+
done,
|
|
48
96
|
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'single' }
|
|
49
97
|
);
|
|
50
98
|
}
|
|
@@ -72,12 +120,13 @@ module.exports = function (RED) {
|
|
|
72
120
|
|
|
73
121
|
// Debug image display
|
|
74
122
|
let debugFormat = null;
|
|
75
|
-
|
|
123
|
+
const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
|
|
124
|
+
if (debugEnabled) {
|
|
76
125
|
try {
|
|
77
126
|
// Resolve and validate debug width
|
|
78
127
|
let debugWidth = NodeUtils.resolveDimension(
|
|
79
128
|
node,
|
|
80
|
-
config.debugWidthType,
|
|
129
|
+
config.debugWidthType || 'num',
|
|
81
130
|
config.debugWidth,
|
|
82
131
|
msg
|
|
83
132
|
);
|
|
@@ -88,7 +137,7 @@ module.exports = function (RED) {
|
|
|
88
137
|
outputFormat,
|
|
89
138
|
outputQuality,
|
|
90
139
|
node,
|
|
91
|
-
|
|
140
|
+
debugEnabled,
|
|
92
141
|
debugWidth
|
|
93
142
|
);
|
|
94
143
|
|
|
@@ -114,7 +163,12 @@ module.exports = function (RED) {
|
|
|
114
163
|
} catch (err) {
|
|
115
164
|
NodeUtils.handleNodeErrorWithPassthrough(
|
|
116
165
|
node, err, msg, send, done, 'blend processing',
|
|
117
|
-
{
|
|
166
|
+
{
|
|
167
|
+
originalPayload: baseImageForPassthrough,
|
|
168
|
+
outputPath,
|
|
169
|
+
outputType: 'single',
|
|
170
|
+
context: { image1Path, image2Path, outputPath }
|
|
171
|
+
}
|
|
118
172
|
);
|
|
119
173
|
}
|
|
120
174
|
});
|
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const { performance } = require('perf_hooks');
|
|
9
|
-
|
|
9
|
+
let sharp;
|
|
10
|
+
try {
|
|
11
|
+
sharp = require('sharp');
|
|
12
|
+
} catch (err) {
|
|
13
|
+
sharp = null;
|
|
14
|
+
}
|
|
10
15
|
const fs = require('fs').promises;
|
|
11
16
|
const path = require('path');
|
|
12
17
|
|
|
@@ -80,6 +85,12 @@ module.exports = function(RED) {
|
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
try {
|
|
88
|
+
if (!sharp) {
|
|
89
|
+
node.error('Folder-In requires "sharp" but it is not available. Install "sharp" and restart Node-RED.');
|
|
90
|
+
stopEmission();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
83
94
|
const startTime = performance.now();
|
|
84
95
|
const filePath = imageFiles[currentIndex];
|
|
85
96
|
const fileName = path.basename(filePath);
|
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
* @author Rosepetal
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
let sharp;
|
|
8
|
+
try {
|
|
9
|
+
sharp = require('sharp');
|
|
10
|
+
} catch (err) {
|
|
11
|
+
sharp = null;
|
|
12
|
+
}
|
|
8
13
|
const fs = require('fs').promises;
|
|
9
14
|
|
|
10
15
|
module.exports = function(RED) {
|
|
@@ -16,6 +21,9 @@ module.exports = function(RED) {
|
|
|
16
21
|
|
|
17
22
|
node.on('input', async function(msg, send, done) {
|
|
18
23
|
try {
|
|
24
|
+
if (!sharp) {
|
|
25
|
+
throw new Error('Sharp is not available. Install "sharp" in your Node-RED userDir and restart Node-RED.');
|
|
26
|
+
}
|
|
19
27
|
let filePath;
|
|
20
28
|
if (config.filePathType === 'msg' || config.filePathType === 'flow' || config.filePathType === 'global') {
|
|
21
29
|
filePath = RED.util.evaluateNodeProperty(config.filePath, config.filePathType, node, msg);
|
|
@@ -140,4 +148,4 @@ module.exports = function(RED) {
|
|
|
140
148
|
});
|
|
141
149
|
}
|
|
142
150
|
RED.nodes.registerType("image-in", ImageInNode);
|
|
143
|
-
};
|
|
151
|
+
};
|
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
* @author Rosepetal
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
let sharp;
|
|
8
|
+
try {
|
|
9
|
+
sharp = require('sharp');
|
|
10
|
+
} catch (err) {
|
|
11
|
+
sharp = null;
|
|
12
|
+
}
|
|
8
13
|
const fs = require('fs').promises;
|
|
9
14
|
const path = require('path');
|
|
10
15
|
|
|
@@ -110,7 +115,11 @@ module.exports = function(RED) {
|
|
|
110
115
|
|
|
111
116
|
let image;
|
|
112
117
|
if (inputPathType === 'msg') {
|
|
113
|
-
|
|
118
|
+
const { value, error } = NodeUtils.safeGetMessageProperty(msg, inputPath);
|
|
119
|
+
if (error) {
|
|
120
|
+
throw new Error(`Invalid inputPath "${inputPath}": ${error.message}`);
|
|
121
|
+
}
|
|
122
|
+
image = value;
|
|
114
123
|
} else if (inputPathType === 'flow') {
|
|
115
124
|
image = node.context().flow.get(inputPath);
|
|
116
125
|
} else if (inputPathType === 'global') {
|
|
@@ -121,6 +130,10 @@ module.exports = function(RED) {
|
|
|
121
130
|
throw new Error('No image data found at specified input path');
|
|
122
131
|
}
|
|
123
132
|
|
|
133
|
+
if (!sharp) {
|
|
134
|
+
throw new Error('Sharp is not available. Install "sharp" in your Node-RED userDir and restart Node-RED.');
|
|
135
|
+
}
|
|
136
|
+
|
|
124
137
|
node.status({ fill: 'blue', shape: 'dot', text: 'saving...' });
|
|
125
138
|
|
|
126
139
|
// Resolve optional full filename override
|
|
@@ -402,7 +415,16 @@ module.exports = function(RED) {
|
|
|
402
415
|
|
|
403
416
|
} catch (err) {
|
|
404
417
|
node.status({ fill: "red", shape: "ring", text: "Error" });
|
|
405
|
-
|
|
418
|
+
const { message, hint } = NodeUtils.explainError(err, 'image-out', {
|
|
419
|
+
inputPath: config.inputPath || 'payload',
|
|
420
|
+
inputPathType: config.inputPathType || 'msg',
|
|
421
|
+
folderPath: config.folderPath,
|
|
422
|
+
outputFormat: config.outputFormat || 'jpg'
|
|
423
|
+
});
|
|
424
|
+
node.error(`Error saving image: ${message}`, msg);
|
|
425
|
+
if (hint) {
|
|
426
|
+
node.warn(`Hint: ${hint}`);
|
|
427
|
+
}
|
|
406
428
|
if (done) done(err);
|
|
407
429
|
}
|
|
408
430
|
});
|
|
@@ -16,11 +16,32 @@ module.exports = function (RED) {
|
|
|
16
16
|
node.on('input', async (msg, send, done) => {
|
|
17
17
|
/* I/O paths - needed early for error passthrough */
|
|
18
18
|
const inputPath = config.inputPath || 'payload';
|
|
19
|
+
const inputPathType = config.inputPathType || 'msg';
|
|
19
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
|
+
}
|
|
20
42
|
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const firstImage = Array.isArray(inputImages) ? inputImages[0] : inputImages;
|
|
43
|
+
const imageArray = Array.isArray(inputImages) ? inputImages : [inputImages];
|
|
44
|
+
const firstImage = imageArray[0];
|
|
24
45
|
|
|
25
46
|
try {
|
|
26
47
|
const t0 = performance.now();
|
|
@@ -43,14 +64,19 @@ module.exports = function (RED) {
|
|
|
43
64
|
/* Image configurations */
|
|
44
65
|
const imageConfigs = config.imageConfigs || [];
|
|
45
66
|
|
|
46
|
-
/* Input images array (inputImages already captured above for error passthrough) */
|
|
47
|
-
const imageArray = Array.isArray(inputImages) ? inputImages : [inputImages];
|
|
48
|
-
|
|
49
67
|
// Validate input images - advanced mosaic expects array input
|
|
50
68
|
if (!NodeUtils.validateListImage(imageArray, node)) {
|
|
51
69
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
52
|
-
node,
|
|
53
|
-
{
|
|
70
|
+
node,
|
|
71
|
+
{
|
|
72
|
+
message: 'Invalid image list',
|
|
73
|
+
hint: `Ensure "${inputPath}" is an array of valid images. Use the "image-in" node or pass Buffers/Raw image objects.`,
|
|
74
|
+
details: { inputPath, inputPathType, outputPath, outputPathType }
|
|
75
|
+
},
|
|
76
|
+
msg,
|
|
77
|
+
send,
|
|
78
|
+
done,
|
|
79
|
+
{ originalPayload: firstImage, outputPath, outputPathType, outputType: 'single' }
|
|
54
80
|
);
|
|
55
81
|
}
|
|
56
82
|
|
|
@@ -71,12 +97,11 @@ module.exports = function (RED) {
|
|
|
71
97
|
let masksArray = null;
|
|
72
98
|
if (propagateMasks) {
|
|
73
99
|
try {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
masksArray = node.context().global.get(masksPath);
|
|
100
|
+
const { value, error } = NodeUtils.getInputValue(node, msg, masksPath, masksPathType);
|
|
101
|
+
if (error) {
|
|
102
|
+
node.warn(`Failed to read masks from ${masksPathType}.${masksPath}: ${error.message}`);
|
|
103
|
+
} else {
|
|
104
|
+
masksArray = value;
|
|
80
105
|
}
|
|
81
106
|
} catch (e) {
|
|
82
107
|
node.warn(`Failed to read masks from ${masksPathType}.${masksPath}: ${e.message}`);
|
|
@@ -111,15 +136,9 @@ module.exports = function (RED) {
|
|
|
111
136
|
const maskCount = Array.isArray(transformedMasks) ? transformedMasks.length : (propagateMasks && masksArray ? masksArray.length : 0);
|
|
112
137
|
|
|
113
138
|
/* Set output */
|
|
114
|
-
|
|
139
|
+
NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, image);
|
|
115
140
|
if (propagateMasks && transformedMasks) {
|
|
116
|
-
|
|
117
|
-
RED.util.setMessageProperty(msg, masksOutputPath, transformedMasks);
|
|
118
|
-
} else if (masksOutputPathType === 'flow') {
|
|
119
|
-
node.context().flow.set(masksOutputPath, transformedMasks);
|
|
120
|
-
} else if (masksOutputPathType === 'global') {
|
|
121
|
-
node.context().global.set(masksOutputPath, transformedMasks);
|
|
122
|
-
}
|
|
141
|
+
NodeUtils.setOutputValue(node, msg, masksOutputPath, masksOutputPathType, transformedMasks);
|
|
123
142
|
}
|
|
124
143
|
|
|
125
144
|
/* Performance status - same format as other nodes */
|
|
@@ -128,12 +147,13 @@ module.exports = function (RED) {
|
|
|
128
147
|
|
|
129
148
|
// Debug image display
|
|
130
149
|
let debugFormat = null;
|
|
131
|
-
|
|
150
|
+
const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
|
|
151
|
+
if (debugEnabled) {
|
|
132
152
|
try {
|
|
133
153
|
// Resolve and validate debug width
|
|
134
154
|
let debugWidth = NodeUtils.resolveDimension(
|
|
135
155
|
node,
|
|
136
|
-
config.debugWidthType,
|
|
156
|
+
config.debugWidthType || 'num',
|
|
137
157
|
config.debugWidth,
|
|
138
158
|
msg
|
|
139
159
|
);
|
|
@@ -144,7 +164,7 @@ module.exports = function (RED) {
|
|
|
144
164
|
outputFormat,
|
|
145
165
|
outputQuality,
|
|
146
166
|
node,
|
|
147
|
-
|
|
167
|
+
debugEnabled,
|
|
148
168
|
debugWidth
|
|
149
169
|
);
|
|
150
170
|
|
|
@@ -185,7 +205,13 @@ module.exports = function (RED) {
|
|
|
185
205
|
} catch (err) {
|
|
186
206
|
NodeUtils.handleNodeErrorWithPassthrough(
|
|
187
207
|
node, err, msg, send, done, 'advanced-mosaic processing',
|
|
188
|
-
{
|
|
208
|
+
{
|
|
209
|
+
originalPayload: firstImage,
|
|
210
|
+
outputPath,
|
|
211
|
+
outputPathType,
|
|
212
|
+
outputType: 'single',
|
|
213
|
+
context: { inputPath, inputPathType, outputPath, outputPathType, masksPath, masksPathType }
|
|
214
|
+
}
|
|
189
215
|
);
|
|
190
216
|
}
|
|
191
217
|
});
|
|
@@ -18,7 +18,10 @@ module.exports = function (RED) {
|
|
|
18
18
|
const node = this;
|
|
19
19
|
|
|
20
20
|
node.on('input', async (msg, send, done) => {
|
|
21
|
+
const inputPath = config.inputPath || 'payload';
|
|
22
|
+
const inputPathType = config.inputPathType || 'msg';
|
|
21
23
|
const outputPath = config.outputPath || 'payload';
|
|
24
|
+
const outputPathType = config.outputPathType || 'msg';
|
|
22
25
|
let firstImage = null;
|
|
23
26
|
|
|
24
27
|
try {
|
|
@@ -26,8 +29,27 @@ module.exports = function (RED) {
|
|
|
26
29
|
node.status({}); // clear status
|
|
27
30
|
|
|
28
31
|
/* ▸ Read images --------------------------------------------------- */
|
|
29
|
-
const
|
|
30
|
-
|
|
32
|
+
const { value: list, error: inputErr } =
|
|
33
|
+
NodeUtils.getInputValue(node, msg, inputPath, inputPathType);
|
|
34
|
+
if (inputErr) {
|
|
35
|
+
const hint = inputPathType === 'msg'
|
|
36
|
+
? `Set inputPath to an existing msg property (e.g. "payload"), or ensure "${inputPath}" exists before this node.`
|
|
37
|
+
: `Set inputPath to an existing ${inputPathType} context key, or ensure "${inputPath}" exists before this node.`;
|
|
38
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
39
|
+
node,
|
|
40
|
+
{
|
|
41
|
+
message: `Invalid inputPath "${inputPath}" (${inputPathType}): ${inputErr.message}`,
|
|
42
|
+
hint,
|
|
43
|
+
details: { inputPath, inputPathType, outputPath, outputPathType }
|
|
44
|
+
},
|
|
45
|
+
msg,
|
|
46
|
+
send,
|
|
47
|
+
done,
|
|
48
|
+
{ originalPayload: undefined, outputPath: null, outputPathType, outputType: 'preserve' }
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const imgs = Array.isArray(list) ? list : [list]; // always an array
|
|
31
53
|
|
|
32
54
|
// Capture first image for error passthrough
|
|
33
55
|
firstImage = imgs[0] || null;
|
|
@@ -35,8 +57,16 @@ module.exports = function (RED) {
|
|
|
35
57
|
// Validate input images - concat expects array input
|
|
36
58
|
if (!NodeUtils.validateListImage(imgs, node)) {
|
|
37
59
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
38
|
-
node,
|
|
39
|
-
{
|
|
60
|
+
node,
|
|
61
|
+
{
|
|
62
|
+
message: 'Invalid image list',
|
|
63
|
+
hint: `Ensure "${inputPath}" is an array of valid images. Use the "image-in" node or pass Buffers/Raw image objects.`,
|
|
64
|
+
details: { inputPath, inputPathType, outputPath, outputPathType }
|
|
65
|
+
},
|
|
66
|
+
msg,
|
|
67
|
+
send,
|
|
68
|
+
done,
|
|
69
|
+
{ originalPayload: firstImage, outputPath, outputPathType, outputType: 'single' }
|
|
40
70
|
);
|
|
41
71
|
}
|
|
42
72
|
|
|
@@ -53,19 +83,20 @@ module.exports = function (RED) {
|
|
|
53
83
|
await Cpp.concat(imgs, direction, strategy, padColorHex, outputFormat, outputQuality, pngOptimize);
|
|
54
84
|
|
|
55
85
|
/* ▸ Write the single result back to msg -------------------------- */
|
|
56
|
-
|
|
86
|
+
NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, image);
|
|
57
87
|
|
|
58
88
|
/* ▸ Status: standardized success formatting ----------------------- */
|
|
59
89
|
const total = performance.now() - t0;
|
|
60
90
|
|
|
61
91
|
// Debug image display
|
|
62
92
|
let debugFormat = null;
|
|
63
|
-
|
|
93
|
+
const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
|
|
94
|
+
if (debugEnabled) {
|
|
64
95
|
try {
|
|
65
96
|
// Resolve and validate debug width
|
|
66
97
|
let debugWidth = NodeUtils.resolveDimension(
|
|
67
98
|
node,
|
|
68
|
-
config.debugWidthType,
|
|
99
|
+
config.debugWidthType || 'num',
|
|
69
100
|
config.debugWidth,
|
|
70
101
|
msg
|
|
71
102
|
);
|
|
@@ -76,7 +107,7 @@ module.exports = function (RED) {
|
|
|
76
107
|
outputFormat,
|
|
77
108
|
outputQuality,
|
|
78
109
|
node,
|
|
79
|
-
|
|
110
|
+
debugEnabled,
|
|
80
111
|
debugWidth
|
|
81
112
|
);
|
|
82
113
|
|
|
@@ -102,7 +133,13 @@ module.exports = function (RED) {
|
|
|
102
133
|
} catch (err) {
|
|
103
134
|
NodeUtils.handleNodeErrorWithPassthrough(
|
|
104
135
|
node, err, msg, send, done, 'concat processing',
|
|
105
|
-
{
|
|
136
|
+
{
|
|
137
|
+
originalPayload: firstImage,
|
|
138
|
+
outputPath,
|
|
139
|
+
outputPathType,
|
|
140
|
+
outputType: 'single',
|
|
141
|
+
context: { inputPath, inputPathType, outputPath, outputPathType }
|
|
142
|
+
}
|
|
106
143
|
);
|
|
107
144
|
}
|
|
108
145
|
});
|