@rosepetal/node-red-contrib-image-tools 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +6 -0
- package/.github/workflows/build-prebuild.yml +326 -0
- package/LICENSE +13 -0
- package/README.md +161 -0
- package/artifacts/darwin-arm64/package.json +25 -0
- package/artifacts/linux-arm64/package.json +26 -0
- package/artifacts/linux-x64/package.json +26 -0
- package/artifacts/linuxmusl-x64/package.json +26 -0
- package/assets/flow_time_example.gif +0 -0
- package/assets/nodes/io/array-in-demo.gif +0 -0
- package/assets/nodes/io/array-out-demo.gif +0 -0
- package/assets/nodes/io/array-select-demo.gif +0 -0
- package/assets/nodes/io/image-in-demo.gif +0 -0
- package/assets/nodes/mix/concat-demo.gif +0 -0
- package/assets/nodes/mix/mosaic-demo.gif +0 -0
- package/assets/nodes/transform/crop-demo.gif +0 -0
- package/assets/nodes/transform/filter-demo.gif +0 -0
- package/assets/nodes/transform/padding-demo.gif +0 -0
- package/assets/nodes/transform/resize-demo.gif +0 -0
- package/assets/nodes/transform/rotate-demo.gif +0 -0
- package/docs/nodes/blend/add-mask.md +275 -0
- package/docs/nodes/blend/add-masks.md +284 -0
- package/docs/nodes/blend/blend.md +248 -0
- package/docs/nodes/io/array-in.md +119 -0
- package/docs/nodes/io/array-out.md +150 -0
- package/docs/nodes/io/array-select.md +157 -0
- package/docs/nodes/io/image-in.md +131 -0
- package/docs/nodes/io/image-out.md +179 -0
- package/docs/nodes/io/queue.md +57 -0
- package/docs/nodes/io/save-file.md +30 -0
- package/docs/nodes/mix/advanced-mosaic.md +108 -0
- package/docs/nodes/mix/concat.md +127 -0
- package/docs/nodes/mix/mosaic.md +146 -0
- package/docs/nodes/specialized/cropBB.md +271 -0
- package/docs/nodes/specialized/image-align.md +426 -0
- package/docs/nodes/transform/crop.md +132 -0
- package/docs/nodes/transform/draw.md +77 -0
- package/docs/nodes/transform/filter.md +84 -0
- package/docs/nodes/transform/padding.md +133 -0
- package/docs/nodes/transform/resize.md +158 -0
- package/docs/nodes/transform/rotate.md +121 -0
- package/docs/nodes/util/block-detect.md +46 -0
- package/install.sh +144 -0
- package/node-red-contrib-image-tools/lib/cpp-bridge.js +224 -0
- package/node-red-contrib-image-tools/lib/node-utils.js +529 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +590 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +241 -0
- package/node-red-contrib-image-tools/nodes/blend/add-mask.html +449 -0
- package/node-red-contrib-image-tools/nodes/blend/add-mask.js +170 -0
- package/node-red-contrib-image-tools/nodes/blend/add-masks.html +703 -0
- package/node-red-contrib-image-tools/nodes/blend/add-masks.js +321 -0
- package/node-red-contrib-image-tools/nodes/blend/blend.html +552 -0
- package/node-red-contrib-image-tools/nodes/blend/blend.js +124 -0
- package/node-red-contrib-image-tools/nodes/io/array-in.html +110 -0
- package/node-red-contrib-image-tools/nodes/io/array-in.js +113 -0
- package/node-red-contrib-image-tools/nodes/io/array-out.html +125 -0
- package/node-red-contrib-image-tools/nodes/io/array-out.js +213 -0
- package/node-red-contrib-image-tools/nodes/io/array-select.html +156 -0
- package/node-red-contrib-image-tools/nodes/io/array-select.js +187 -0
- package/node-red-contrib-image-tools/nodes/io/folder-in.html +248 -0
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +335 -0
- package/node-red-contrib-image-tools/nodes/io/image-in.html +146 -0
- package/node-red-contrib-image-tools/nodes/io/image-in.js +143 -0
- package/node-red-contrib-image-tools/nodes/io/image-out.html +506 -0
- package/node-red-contrib-image-tools/nodes/io/image-out.js +545 -0
- package/node-red-contrib-image-tools/nodes/io/queue.html +119 -0
- package/node-red-contrib-image-tools/nodes/io/queue.js +191 -0
- package/node-red-contrib-image-tools/nodes/io/save-file.html +243 -0
- package/node-red-contrib-image-tools/nodes/io/save-file.js +440 -0
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +2149 -0
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +195 -0
- package/node-red-contrib-image-tools/nodes/mix/concat.html +390 -0
- package/node-red-contrib-image-tools/nodes/mix/concat.js +112 -0
- package/node-red-contrib-image-tools/nodes/mix/mosaic.html +550 -0
- package/node-red-contrib-image-tools/nodes/mix/mosaic.js +151 -0
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +268 -0
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +277 -0
- package/node-red-contrib-image-tools/nodes/specialized/image-align.html +528 -0
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +306 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.html +410 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.js +149 -0
- package/node-red-contrib-image-tools/nodes/transform/draw.html +719 -0
- package/node-red-contrib-image-tools/nodes/transform/draw.js +509 -0
- package/node-red-contrib-image-tools/nodes/transform/filter.html +578 -0
- package/node-red-contrib-image-tools/nodes/transform/filter.js +177 -0
- package/node-red-contrib-image-tools/nodes/transform/padding.html +475 -0
- package/node-red-contrib-image-tools/nodes/transform/padding.js +142 -0
- package/node-red-contrib-image-tools/nodes/transform/resize.html +429 -0
- package/node-red-contrib-image-tools/nodes/transform/resize.js +162 -0
- package/node-red-contrib-image-tools/nodes/transform/rotate.html +299 -0
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +141 -0
- package/node-red-contrib-image-tools/nodes/util/block-detect.html +85 -0
- package/node-red-contrib-image-tools/nodes/util/block-detect.js +136 -0
- package/node-red-contrib-image-tools/nodes/util/clean-debug.html +201 -0
- package/node-red-contrib-image-tools/nodes/util/clean-debug.js +393 -0
- package/node-red-contrib-image-tools/package.json +64 -0
- package/npm/darwin-arm64/lib/.gitkeep +1 -0
- package/npm/darwin-arm64/package.json +25 -0
- package/npm/darwin-x64/lib/.gitkeep +1 -0
- package/npm/darwin-x64/package.json +25 -0
- package/npm/linux-arm64/lib/.gitkeep +1 -0
- package/npm/linux-arm64/package.json +26 -0
- package/npm/linux-x64/lib/.gitkeep +1 -0
- package/npm/linux-x64/package.json +26 -0
- package/npm/linuxmusl-x64/lib/.gitkeep +1 -0
- package/npm/linuxmusl-x64/package.json +26 -0
- package/npm/win32-x64/lib/.gitkeep +1 -0
- package/npm/win32-x64/package.json +25 -0
- package/package.json +74 -0
- package/rosepetal-image-engine/binding.gyp +153 -0
- package/rosepetal-image-engine/package.json +19 -0
- package/rosepetal-image-engine/src/add-bbs.cpp +433 -0
- package/rosepetal-image-engine/src/add-mask.cpp +240 -0
- package/rosepetal-image-engine/src/add-masks.cpp +638 -0
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +740 -0
- package/rosepetal-image-engine/src/blend.cpp +200 -0
- package/rosepetal-image-engine/src/concat.cpp +329 -0
- package/rosepetal-image-engine/src/crop.cpp +139 -0
- package/rosepetal-image-engine/src/draw.cpp +414 -0
- package/rosepetal-image-engine/src/filter.cpp +230 -0
- package/rosepetal-image-engine/src/filters/kernels.h +171 -0
- package/rosepetal-image-engine/src/image-align.cpp +551 -0
- package/rosepetal-image-engine/src/main.cpp +36 -0
- package/rosepetal-image-engine/src/mosaic.cpp +373 -0
- package/rosepetal-image-engine/src/padding.cpp +124 -0
- package/rosepetal-image-engine/src/resize.cpp +210 -0
- package/rosepetal-image-engine/src/rotate.cpp +177 -0
- package/rosepetal-image-engine/src/utils.h +563 -0
- package/rosepetal-image-engine/test-formats.js +119 -0
- package/scripts/build-opencv-static.ps1 +166 -0
- package/scripts/build-opencv-static.sh +147 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node‑RED logic for *rosepetal‑blend* (C++ backend).
|
|
3
|
+
* Blends two images with adjustable opacity using alpha blending.
|
|
4
|
+
*
|
|
5
|
+
* Timing fields returned by C++:
|
|
6
|
+
* timing.convertMs · timing.taskMs · timing.encodeMs
|
|
7
|
+
* …and the node status shows: OK … (conv X | task Y ms)
|
|
8
|
+
*/
|
|
9
|
+
const { performance } = require('perf_hooks');
|
|
10
|
+
const Cpp = require('../../lib/cpp-bridge.js');
|
|
11
|
+
|
|
12
|
+
module.exports = function (RED) {
|
|
13
|
+
const NodeUtils = require('../../lib/node-utils.js')(RED);
|
|
14
|
+
|
|
15
|
+
function BlendNode (config) {
|
|
16
|
+
RED.nodes.createNode(this, config);
|
|
17
|
+
const node = this;
|
|
18
|
+
|
|
19
|
+
node.on('input', async (msg, send, done) => {
|
|
20
|
+
// Capture output path for error passthrough
|
|
21
|
+
const outputPath = config.outputPath || 'payload';
|
|
22
|
+
|
|
23
|
+
// Capture base image early for error passthrough (use first/base image)
|
|
24
|
+
const image1 = RED.util.getMessageProperty(msg, config.image1Path || 'payload.image1');
|
|
25
|
+
const baseImageForPassthrough = image1;
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const t0 = performance.now();
|
|
29
|
+
node.status({}); // clear status
|
|
30
|
+
|
|
31
|
+
/* ▸ Read images from message ------------------------------------ */
|
|
32
|
+
// Get images directly from specified paths
|
|
33
|
+
const image2 = RED.util.getMessageProperty(msg, config.image2Path || 'payload.image2');
|
|
34
|
+
|
|
35
|
+
// Validate input images
|
|
36
|
+
const img1 = NodeUtils.validateImageStructure(image1, node);
|
|
37
|
+
if (!img1) {
|
|
38
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
39
|
+
node, 'First image is invalid or missing', msg, send, done,
|
|
40
|
+
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'single' }
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const img2 = NodeUtils.validateImageStructure(image2, node);
|
|
45
|
+
if (!img2) {
|
|
46
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
47
|
+
node, 'Second image is invalid or missing', msg, send, done,
|
|
48
|
+
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'single' }
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* ▸ Options from the editor -------------------------------------- */
|
|
53
|
+
const opacity = Math.max(0, Math.min(100, parseInt(config.opacity) || 50)) / 100.0;
|
|
54
|
+
const outputFormat = config.outputFormat || 'raw';
|
|
55
|
+
const outputQuality = parseInt(config.outputQuality) || 90;
|
|
56
|
+
const pngOptimize = config.pngOptimize || false;
|
|
57
|
+
const alphaCompositing = config.alphaCompositing || false;
|
|
58
|
+
const removeBackground = config.removeBackground || false;
|
|
59
|
+
const backgroundColor = config.backgroundColor || '#ffffff';
|
|
60
|
+
const colorTolerance = Math.max(0, Math.min(100, parseInt(config.colorTolerance) || 10)) / 100.0;
|
|
61
|
+
|
|
62
|
+
/* ▸ Single call to the C++ addon --------------------------------- */
|
|
63
|
+
const { image, timing = {} } =
|
|
64
|
+
await Cpp.blend(img1, img2, opacity, outputFormat, outputQuality, pngOptimize,
|
|
65
|
+
alphaCompositing, removeBackground, backgroundColor, colorTolerance);
|
|
66
|
+
|
|
67
|
+
/* ▸ Write the result back to msg ---------------------------------- */
|
|
68
|
+
RED.util.setMessageProperty(msg, config.outputPath || 'payload', image);
|
|
69
|
+
|
|
70
|
+
/* ▸ Status: standardized success formatting ----------------------- */
|
|
71
|
+
const total = performance.now() - t0;
|
|
72
|
+
|
|
73
|
+
// Debug image display
|
|
74
|
+
let debugFormat = null;
|
|
75
|
+
if (config.debugEnabled) {
|
|
76
|
+
try {
|
|
77
|
+
// Resolve and validate debug width
|
|
78
|
+
let debugWidth = NodeUtils.resolveDimension(
|
|
79
|
+
node,
|
|
80
|
+
config.debugWidthType,
|
|
81
|
+
config.debugWidth,
|
|
82
|
+
msg
|
|
83
|
+
);
|
|
84
|
+
debugWidth = Math.max(1, parseInt(debugWidth) || 200); // Ensure positive, default 200
|
|
85
|
+
|
|
86
|
+
const debugResult = await NodeUtils.debugImageDisplay(
|
|
87
|
+
image,
|
|
88
|
+
outputFormat,
|
|
89
|
+
outputQuality,
|
|
90
|
+
node,
|
|
91
|
+
true,
|
|
92
|
+
debugWidth
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
if (debugResult) {
|
|
96
|
+
debugFormat = debugResult.formatMessage;
|
|
97
|
+
// Update node status with debug info
|
|
98
|
+
NodeUtils.setSuccessStatusWithDebug(node, 1, total, timing, debugFormat);
|
|
99
|
+
}
|
|
100
|
+
} catch (debugError) {
|
|
101
|
+
node.warn(`Debug display error: ${debugError.message}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Set regular status if debug not enabled or failed
|
|
106
|
+
if (!debugFormat) {
|
|
107
|
+
NodeUtils.setSuccessStatus(node, 1, total, timing);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
NodeUtils.recordPerformanceMetrics(node, msg, timing || {}, total);
|
|
111
|
+
|
|
112
|
+
send(msg);
|
|
113
|
+
done && done();
|
|
114
|
+
} catch (err) {
|
|
115
|
+
NodeUtils.handleNodeErrorWithPassthrough(
|
|
116
|
+
node, err, msg, send, done, 'blend processing',
|
|
117
|
+
{ originalPayload: baseImageForPassthrough, outputPath, outputType: 'single' }
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
RED.nodes.registerType('blend', BlendNode);
|
|
124
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('array-in', {
|
|
3
|
+
category: 'RP Image',
|
|
4
|
+
color: '#87CEEB',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: "" },
|
|
7
|
+
inputPath: { value: "payload" },
|
|
8
|
+
inputPathType: { value: "msg" },
|
|
9
|
+
arrayPositionType: { value: "num" },
|
|
10
|
+
arrayPositionValue: { value: 0 }
|
|
11
|
+
},
|
|
12
|
+
inputs: 1,
|
|
13
|
+
outputs: 1,
|
|
14
|
+
icon: "font-awesome/fa-sign-in",
|
|
15
|
+
label: function() {
|
|
16
|
+
if (this.name) return this.name;
|
|
17
|
+
|
|
18
|
+
const posDisplay = this.arrayPositionType === 'num'
|
|
19
|
+
? this.arrayPositionValue
|
|
20
|
+
: `${this.arrayPositionType}.${this.arrayPositionValue}`;
|
|
21
|
+
return `Array In [${posDisplay}]`;
|
|
22
|
+
},
|
|
23
|
+
oneditprepare: function() {
|
|
24
|
+
// Set up TypedInput for input path
|
|
25
|
+
$("#node-input-inputPath").typedInput({
|
|
26
|
+
default: 'msg',
|
|
27
|
+
types: ['msg', 'flow', 'global'],
|
|
28
|
+
typeField: "#node-input-inputPathType"
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Set up TypedInput for array position
|
|
32
|
+
$("#node-input-arrayPositionValue").typedInput({
|
|
33
|
+
default: 'num',
|
|
34
|
+
types: ['num', 'msg', 'flow', 'global'],
|
|
35
|
+
typeField: "#node-input-arrayPositionType"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<script type="text/x-red" data-template-name="array-in">
|
|
42
|
+
<div class="form-row">
|
|
43
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
44
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<hr>
|
|
48
|
+
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input from</label>
|
|
51
|
+
<input type="text" id="node-input-inputPath" style="width: 70%;">
|
|
52
|
+
<input type="hidden" id="node-input-inputPathType">
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
<div class="form-row">
|
|
56
|
+
<label for="node-input-arrayPositionValue"><i class="fa fa-sort-numeric-asc"></i> Array Position</label>
|
|
57
|
+
<input type="text" id="node-input-arrayPositionValue" style="width: 70%;" placeholder="0">
|
|
58
|
+
<input type="hidden" id="node-input-arrayPositionType">
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<div class="form-tips">
|
|
62
|
+
<b>Tip:</b> Array position can be a fixed number (starting from 0) or dynamically resolved from msg, flow, or global context. This determines where this data will be placed in the output array.
|
|
63
|
+
</div>
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<script type="text/x-red" data-help-name="array-in">
|
|
67
|
+
<p>Collects data from a specified input path and tags it for ordered array assembly with a position index.</p>
|
|
68
|
+
|
|
69
|
+
<h3>Details</h3>
|
|
70
|
+
<p>This node is designed to work with the array-out node to create ordered arrays from multiple data sources. It extracts data from the specified input path and tags it with a position index, allowing multiple array-in nodes to feed into a single array-out node for ordered collection.</p>
|
|
71
|
+
|
|
72
|
+
<h3>Properties</h3>
|
|
73
|
+
<dl class="message-properties">
|
|
74
|
+
<dt>Input from <span class="property-type">string</span></dt>
|
|
75
|
+
<dd>The location to read data from. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
|
|
76
|
+
<dt>Array Position <span class="property-type">number | msg | flow | global</span></dt>
|
|
77
|
+
<dd>The index position (0, 1, 2...) where this data should be placed in the final array. Can be a fixed number or dynamically resolved from message properties, flow context, or global context. Must resolve to a non-negative integer.</dd>
|
|
78
|
+
</dl>
|
|
79
|
+
|
|
80
|
+
<h3>Inputs</h3>
|
|
81
|
+
<dl class="message-properties">
|
|
82
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
83
|
+
<dd>Input message containing the data to be extracted. The actual data location is determined by the "Input from" property. The payload is only replaced when the input is set to <code>msg.payload</code>; otherwise it is left untouched.</dd>
|
|
84
|
+
</dl>
|
|
85
|
+
|
|
86
|
+
<h3>Outputs</h3>
|
|
87
|
+
<p>The node passes through the original message with added metadata for array assembly. When the input path is <code>msg.payload</code> the payload is mirrored; for all other inputs the existing payload is preserved and only the metadata is updated.</p>
|
|
88
|
+
<dl class="message-properties">
|
|
89
|
+
<dt>meta.arrayPosition <span class="property-type">number</span></dt>
|
|
90
|
+
<dd>The configured array position index.</dd>
|
|
91
|
+
<dt>meta.arrayData <span class="property-type">any</span></dt>
|
|
92
|
+
<dd>The data extracted from the specified input path.</dd>
|
|
93
|
+
</dl>
|
|
94
|
+
|
|
95
|
+
<h3>Examples</h3>
|
|
96
|
+
<ul>
|
|
97
|
+
<li><strong>Basic Array Assembly:</strong> Three array-in nodes with positions 0, 1, 2 feeding into an array-out will create: <code>[data0, data1, data2]</code></li>
|
|
98
|
+
<li><strong>Dynamic Positioning:</strong> Set array position from <code>msg.index</code> to dynamically determine where data should be placed based on message content</li>
|
|
99
|
+
<li><strong>Image Collection:</strong> Multiple image-in nodes → array-in nodes (positions 0, 1, 2...) → array-out → transform nodes that support arrays</li>
|
|
100
|
+
<li><strong>Mixed Data Sources:</strong> Combine data from different context levels (msg, flow, global) into a single ordered array</li>
|
|
101
|
+
<li><strong>Conditional Assembly:</strong> Use flow variables to set positions based on processing conditions or user preferences</li>
|
|
102
|
+
</ul>
|
|
103
|
+
|
|
104
|
+
<h3>Node Interactions</h3>
|
|
105
|
+
<p><strong>Works with:</strong> Must be used with array-out node for array assembly. Can receive data from any node that outputs to the specified input path.</p>
|
|
106
|
+
<p><strong>Best Practice:</strong> Use sequential positions starting from 0, ensure each array-in node connected to the same array-out has a unique position.</p>
|
|
107
|
+
|
|
108
|
+
<h3>Error Handling</h3>
|
|
109
|
+
<p>If the input path contains no data or is invalid, the node will set <code>meta.arrayData</code> to <code>null</code> and display a warning.</p>
|
|
110
|
+
</script>
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Node.js logic for the Array-In node with input path and array position.
|
|
3
|
+
* @author Rosepetal
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
module.exports = function(RED) {
|
|
7
|
+
const NodeUtils = require('../../lib/node-utils.js')(RED);
|
|
8
|
+
|
|
9
|
+
function ArrayInNode(config) {
|
|
10
|
+
RED.nodes.createNode(this, config);
|
|
11
|
+
const node = this;
|
|
12
|
+
|
|
13
|
+
// Store configuration with validation
|
|
14
|
+
node.inputPath = config.inputPath || 'payload';
|
|
15
|
+
node.inputPathType = config.inputPathType || 'msg';
|
|
16
|
+
|
|
17
|
+
// Dynamic position configuration
|
|
18
|
+
node.arrayPositionType = config.arrayPositionType || 'num';
|
|
19
|
+
node.arrayPositionValue = config.arrayPositionValue !== undefined ? config.arrayPositionValue : 0;
|
|
20
|
+
|
|
21
|
+
// Set initial status
|
|
22
|
+
const statusText = node.arrayPositionType === 'num'
|
|
23
|
+
? `Position: ${node.arrayPositionValue}`
|
|
24
|
+
: `Position: ${node.arrayPositionType}.${node.arrayPositionValue}`;
|
|
25
|
+
node.status({
|
|
26
|
+
fill: "blue",
|
|
27
|
+
shape: "dot",
|
|
28
|
+
text: statusText
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Handle incoming messages
|
|
32
|
+
node.on('input', function(msg, send, done) {
|
|
33
|
+
try {
|
|
34
|
+
// Resolve array position dynamically
|
|
35
|
+
let resolvedPosition;
|
|
36
|
+
try {
|
|
37
|
+
resolvedPosition = NodeUtils.resolveArrayPosition(
|
|
38
|
+
node,
|
|
39
|
+
node.arrayPositionType,
|
|
40
|
+
node.arrayPositionValue,
|
|
41
|
+
msg
|
|
42
|
+
);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
node.warn(`Failed to resolve array position: ${err.message}`);
|
|
45
|
+
node.status({ fill: "red", shape: "ring", text: "Invalid position" });
|
|
46
|
+
return done ? done() : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Get data from configured input path
|
|
50
|
+
let arrayData;
|
|
51
|
+
if (node.inputPathType === 'msg') {
|
|
52
|
+
arrayData = RED.util.getMessageProperty(msg, node.inputPath);
|
|
53
|
+
} else if (node.inputPathType === 'flow') {
|
|
54
|
+
arrayData = node.context().flow.get(node.inputPath);
|
|
55
|
+
} else if (node.inputPathType === 'global') {
|
|
56
|
+
arrayData = node.context().global.get(node.inputPath);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Handle undefined data gracefully
|
|
60
|
+
if (arrayData === undefined) {
|
|
61
|
+
node.warn(`No data found at ${node.inputPathType}.${node.inputPath}`);
|
|
62
|
+
arrayData = null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Initialize msg.meta if it doesn't exist
|
|
66
|
+
if (!msg.meta) {
|
|
67
|
+
msg.meta = {};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Add array metadata and optionally mirror into payload
|
|
71
|
+
msg.meta.arrayPosition = resolvedPosition;
|
|
72
|
+
msg.meta.arrayData = arrayData;
|
|
73
|
+
|
|
74
|
+
const normalizedPath = typeof node.inputPath === 'string'
|
|
75
|
+
? node.inputPath.trim()
|
|
76
|
+
: node.inputPath;
|
|
77
|
+
const shouldMirrorPayload =
|
|
78
|
+
node.inputPathType === 'msg' &&
|
|
79
|
+
normalizedPath === 'payload';
|
|
80
|
+
|
|
81
|
+
if (shouldMirrorPayload) {
|
|
82
|
+
msg.payload = arrayData;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Update status
|
|
86
|
+
node.status({
|
|
87
|
+
fill: "green",
|
|
88
|
+
shape: "dot",
|
|
89
|
+
text: `Position: ${resolvedPosition}`
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Send the message with array metadata
|
|
93
|
+
send(msg);
|
|
94
|
+
if (done) { done(); }
|
|
95
|
+
|
|
96
|
+
} catch (err) {
|
|
97
|
+
node.status({ fill: "red", shape: "ring", text: "Error" });
|
|
98
|
+
if (done) {
|
|
99
|
+
done(err);
|
|
100
|
+
} else {
|
|
101
|
+
node.error(err, msg);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Clean up on node removal
|
|
107
|
+
node.on('close', function() {
|
|
108
|
+
node.status({});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
RED.nodes.registerType("array-in", ArrayInNode);
|
|
113
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('array-out', {
|
|
3
|
+
category: 'RP Image',
|
|
4
|
+
color: '#87CEEB',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: "" },
|
|
7
|
+
timeout: { value: 5000 },
|
|
8
|
+
expectedCount: { value: 2, required: true, validate: RED.validators.number() },
|
|
9
|
+
outputPath: { value: "payload" },
|
|
10
|
+
outputPathType: { value: "msg" }
|
|
11
|
+
},
|
|
12
|
+
inputs: 1,
|
|
13
|
+
outputs: 2,
|
|
14
|
+
icon: "font-awesome/fa-sign-out",
|
|
15
|
+
label: function() {
|
|
16
|
+
return this.name || `Array Out (${this.expectedCount} items)`;
|
|
17
|
+
},
|
|
18
|
+
oneditprepare: function() {
|
|
19
|
+
// Set up TypedInput for output path
|
|
20
|
+
$("#node-input-outputPath").typedInput({
|
|
21
|
+
default: 'msg',
|
|
22
|
+
types: ['msg', 'flow', 'global'],
|
|
23
|
+
typeField: "#node-input-outputPathType"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<script type="text/x-red" data-template-name="array-out">
|
|
30
|
+
<div class="form-row">
|
|
31
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
32
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<hr>
|
|
36
|
+
|
|
37
|
+
<div class="form-row">
|
|
38
|
+
<label for="node-input-timeout"><i class="fa fa-clock-o"></i> Timeout (ms)</label>
|
|
39
|
+
<input type="number" id="node-input-timeout" min="100" step="100" style="width: 70%;" placeholder="5000">
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div class="form-row">
|
|
43
|
+
<label for="node-input-expectedCount"><i class="fa fa-hashtag"></i> Expected Count</label>
|
|
44
|
+
<input type="number" id="node-input-expectedCount" min="1" step="1" style="width: 70%;" placeholder="2" required>
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<div class="form-row">
|
|
48
|
+
<label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output to</label>
|
|
49
|
+
<input type="text" id="node-input-outputPath" style="width: 70%;">
|
|
50
|
+
<input type="hidden" id="node-input-outputPathType">
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<div class="form-tips">
|
|
54
|
+
<b>Timeout:</b> Maximum time to wait for all array elements after the first message arrives. If timeout occurs, collected data and missing position info are sent to output 2.<br>
|
|
55
|
+
<b>Expected Count:</b> Number of array elements required before outputting the assembled array.
|
|
56
|
+
</div>
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<script type="text/x-red" data-help-name="array-out">
|
|
60
|
+
<p>Collects messages from multiple array-in nodes and assembles them into an ordered array based on position indices.</p>
|
|
61
|
+
|
|
62
|
+
<h3>Details</h3>
|
|
63
|
+
<p>This node works as the collection point for multiple array-in nodes. It waits for messages containing array metadata, collects them based on their position indices, and outputs a complete array when all expected elements are received. The node includes timeout protection and performance monitoring.</p>
|
|
64
|
+
|
|
65
|
+
<h3>Properties</h3>
|
|
66
|
+
<dl class="message-properties">
|
|
67
|
+
<dt>Timeout <span class="property-type">number</span></dt>
|
|
68
|
+
<dd>Maximum time in milliseconds to wait for all array elements after the first message arrives. Default: 5000ms. If timeout occurs, collected data and missing position info are sent to output 2.</dd>
|
|
69
|
+
<dt>Expected Count <span class="property-type">number</span></dt>
|
|
70
|
+
<dd>Number of array elements required before outputting the assembled array. Must match the number of array-in nodes connected. Required field, minimum value: 1.</dd>
|
|
71
|
+
<dt>Output to <span class="property-type">string</span></dt>
|
|
72
|
+
<dd>The location where the assembled array 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>
|
|
73
|
+
</dl>
|
|
74
|
+
|
|
75
|
+
<h3>Inputs</h3>
|
|
76
|
+
<dl class="message-properties">
|
|
77
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
78
|
+
<dd>Messages from array-in nodes containing array metadata.</dd>
|
|
79
|
+
<dt>meta.arrayPosition <span class="property-type">number</span></dt>
|
|
80
|
+
<dd>The array position index (0, 1, 2...) provided by array-in nodes.</dd>
|
|
81
|
+
<dt>meta.arrayData <span class="property-type">any</span></dt>
|
|
82
|
+
<dd>The actual data to be placed in the array at the specified position.</dd>
|
|
83
|
+
</dl>
|
|
84
|
+
|
|
85
|
+
<h3>Outputs</h3>
|
|
86
|
+
<dl class="message-properties">
|
|
87
|
+
<dt>Output 1 - Complete Array <span class="property-type">array</span></dt>
|
|
88
|
+
<dd>The complete assembled array when all expected elements are received: [data0, data1, data2...]</dd>
|
|
89
|
+
<dt>Output 2 - Timeout Data <span class="property-type">object</span></dt>
|
|
90
|
+
<dd>On timeout: collected data array (with nulls for missing) plus metadata about missing positions</dd>
|
|
91
|
+
</dl>
|
|
92
|
+
|
|
93
|
+
<h3>Operation Flow</h3>
|
|
94
|
+
<ol>
|
|
95
|
+
<li><strong>First Message:</strong> Starts timeout timer and begins collection</li>
|
|
96
|
+
<li><strong>Collection:</strong> Gathers messages from array-in nodes, validates positions</li>
|
|
97
|
+
<li><strong>Assembly:</strong> Places data at specified array positions based on meta.arrayPosition</li>
|
|
98
|
+
<li><strong>Success:</strong> Outputs assembled array when all expected elements received</li>
|
|
99
|
+
<li><strong>Timeout:</strong> Sends collected data + missing info to output 2</li>
|
|
100
|
+
<li><strong>Reset:</strong> Ready for next collection cycle</li>
|
|
101
|
+
</ol>
|
|
102
|
+
|
|
103
|
+
<h3>Examples</h3>
|
|
104
|
+
<ul>
|
|
105
|
+
<li><strong>Basic Array Assembly:</strong> With Expected Count = 3, array-in nodes at positions 0, 1, 2 will produce: <code>["data0", "data1", "data2"]</code></li>
|
|
106
|
+
<li><strong>Image Array:</strong> Three image-in → array-in (positions 0,1,2) → array-out → creates array of image objects for batch processing</li>
|
|
107
|
+
<li><strong>Mixed Data:</strong> Combine different data types from various sources into a single ordered array</li>
|
|
108
|
+
</ul>
|
|
109
|
+
|
|
110
|
+
<h3>Node Interactions</h3>
|
|
111
|
+
<p><strong>Requires:</strong> Multiple array-in nodes, each with unique position indices (0, 1, 2...)</p>
|
|
112
|
+
<p><strong>Works with:</strong> Transform nodes that support array inputs (resize, rotate, etc.), array-select for element extraction</p>
|
|
113
|
+
<p><strong>Best Practice:</strong> Set Expected Count to match the number of array-in nodes. Use reasonable timeout values based on your processing requirements.</p>
|
|
114
|
+
|
|
115
|
+
<h3>Error Handling</h3>
|
|
116
|
+
<p>The node handles various error conditions:</p>
|
|
117
|
+
<ul>
|
|
118
|
+
<li><strong>Missing metadata:</strong> Messages without proper array metadata are ignored</li>
|
|
119
|
+
<li><strong>Duplicate positions:</strong> Later messages overwrite earlier ones at the same position</li>
|
|
120
|
+
<li><strong>Timeout:</strong> Collection resets, node status shows timeout, no output sent</li>
|
|
121
|
+
</ul>
|
|
122
|
+
|
|
123
|
+
<h3>Performance</h3>
|
|
124
|
+
<p>Node status displays collection timing when successful. The timeout mechanism prevents indefinite waiting for missing array elements.</p>
|
|
125
|
+
</script>
|