@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.
Files changed (131) hide show
  1. package/.gitattributes +6 -0
  2. package/.github/workflows/build-prebuild.yml +326 -0
  3. package/LICENSE +13 -0
  4. package/README.md +161 -0
  5. package/artifacts/darwin-arm64/package.json +25 -0
  6. package/artifacts/linux-arm64/package.json +26 -0
  7. package/artifacts/linux-x64/package.json +26 -0
  8. package/artifacts/linuxmusl-x64/package.json +26 -0
  9. package/assets/flow_time_example.gif +0 -0
  10. package/assets/nodes/io/array-in-demo.gif +0 -0
  11. package/assets/nodes/io/array-out-demo.gif +0 -0
  12. package/assets/nodes/io/array-select-demo.gif +0 -0
  13. package/assets/nodes/io/image-in-demo.gif +0 -0
  14. package/assets/nodes/mix/concat-demo.gif +0 -0
  15. package/assets/nodes/mix/mosaic-demo.gif +0 -0
  16. package/assets/nodes/transform/crop-demo.gif +0 -0
  17. package/assets/nodes/transform/filter-demo.gif +0 -0
  18. package/assets/nodes/transform/padding-demo.gif +0 -0
  19. package/assets/nodes/transform/resize-demo.gif +0 -0
  20. package/assets/nodes/transform/rotate-demo.gif +0 -0
  21. package/docs/nodes/blend/add-mask.md +275 -0
  22. package/docs/nodes/blend/add-masks.md +284 -0
  23. package/docs/nodes/blend/blend.md +248 -0
  24. package/docs/nodes/io/array-in.md +119 -0
  25. package/docs/nodes/io/array-out.md +150 -0
  26. package/docs/nodes/io/array-select.md +157 -0
  27. package/docs/nodes/io/image-in.md +131 -0
  28. package/docs/nodes/io/image-out.md +179 -0
  29. package/docs/nodes/io/queue.md +57 -0
  30. package/docs/nodes/io/save-file.md +30 -0
  31. package/docs/nodes/mix/advanced-mosaic.md +108 -0
  32. package/docs/nodes/mix/concat.md +127 -0
  33. package/docs/nodes/mix/mosaic.md +146 -0
  34. package/docs/nodes/specialized/cropBB.md +271 -0
  35. package/docs/nodes/specialized/image-align.md +426 -0
  36. package/docs/nodes/transform/crop.md +132 -0
  37. package/docs/nodes/transform/draw.md +77 -0
  38. package/docs/nodes/transform/filter.md +84 -0
  39. package/docs/nodes/transform/padding.md +133 -0
  40. package/docs/nodes/transform/resize.md +158 -0
  41. package/docs/nodes/transform/rotate.md +121 -0
  42. package/docs/nodes/util/block-detect.md +46 -0
  43. package/install.sh +144 -0
  44. package/node-red-contrib-image-tools/lib/cpp-bridge.js +224 -0
  45. package/node-red-contrib-image-tools/lib/node-utils.js +529 -0
  46. package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +590 -0
  47. package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +241 -0
  48. package/node-red-contrib-image-tools/nodes/blend/add-mask.html +449 -0
  49. package/node-red-contrib-image-tools/nodes/blend/add-mask.js +170 -0
  50. package/node-red-contrib-image-tools/nodes/blend/add-masks.html +703 -0
  51. package/node-red-contrib-image-tools/nodes/blend/add-masks.js +321 -0
  52. package/node-red-contrib-image-tools/nodes/blend/blend.html +552 -0
  53. package/node-red-contrib-image-tools/nodes/blend/blend.js +124 -0
  54. package/node-red-contrib-image-tools/nodes/io/array-in.html +110 -0
  55. package/node-red-contrib-image-tools/nodes/io/array-in.js +113 -0
  56. package/node-red-contrib-image-tools/nodes/io/array-out.html +125 -0
  57. package/node-red-contrib-image-tools/nodes/io/array-out.js +213 -0
  58. package/node-red-contrib-image-tools/nodes/io/array-select.html +156 -0
  59. package/node-red-contrib-image-tools/nodes/io/array-select.js +187 -0
  60. package/node-red-contrib-image-tools/nodes/io/folder-in.html +248 -0
  61. package/node-red-contrib-image-tools/nodes/io/folder-in.js +335 -0
  62. package/node-red-contrib-image-tools/nodes/io/image-in.html +146 -0
  63. package/node-red-contrib-image-tools/nodes/io/image-in.js +143 -0
  64. package/node-red-contrib-image-tools/nodes/io/image-out.html +506 -0
  65. package/node-red-contrib-image-tools/nodes/io/image-out.js +545 -0
  66. package/node-red-contrib-image-tools/nodes/io/queue.html +119 -0
  67. package/node-red-contrib-image-tools/nodes/io/queue.js +191 -0
  68. package/node-red-contrib-image-tools/nodes/io/save-file.html +243 -0
  69. package/node-red-contrib-image-tools/nodes/io/save-file.js +440 -0
  70. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +2149 -0
  71. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +195 -0
  72. package/node-red-contrib-image-tools/nodes/mix/concat.html +390 -0
  73. package/node-red-contrib-image-tools/nodes/mix/concat.js +112 -0
  74. package/node-red-contrib-image-tools/nodes/mix/mosaic.html +550 -0
  75. package/node-red-contrib-image-tools/nodes/mix/mosaic.js +151 -0
  76. package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +268 -0
  77. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +277 -0
  78. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +528 -0
  79. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +306 -0
  80. package/node-red-contrib-image-tools/nodes/transform/crop.html +410 -0
  81. package/node-red-contrib-image-tools/nodes/transform/crop.js +149 -0
  82. package/node-red-contrib-image-tools/nodes/transform/draw.html +719 -0
  83. package/node-red-contrib-image-tools/nodes/transform/draw.js +509 -0
  84. package/node-red-contrib-image-tools/nodes/transform/filter.html +578 -0
  85. package/node-red-contrib-image-tools/nodes/transform/filter.js +177 -0
  86. package/node-red-contrib-image-tools/nodes/transform/padding.html +475 -0
  87. package/node-red-contrib-image-tools/nodes/transform/padding.js +142 -0
  88. package/node-red-contrib-image-tools/nodes/transform/resize.html +429 -0
  89. package/node-red-contrib-image-tools/nodes/transform/resize.js +162 -0
  90. package/node-red-contrib-image-tools/nodes/transform/rotate.html +299 -0
  91. package/node-red-contrib-image-tools/nodes/transform/rotate.js +141 -0
  92. package/node-red-contrib-image-tools/nodes/util/block-detect.html +85 -0
  93. package/node-red-contrib-image-tools/nodes/util/block-detect.js +136 -0
  94. package/node-red-contrib-image-tools/nodes/util/clean-debug.html +201 -0
  95. package/node-red-contrib-image-tools/nodes/util/clean-debug.js +393 -0
  96. package/node-red-contrib-image-tools/package.json +64 -0
  97. package/npm/darwin-arm64/lib/.gitkeep +1 -0
  98. package/npm/darwin-arm64/package.json +25 -0
  99. package/npm/darwin-x64/lib/.gitkeep +1 -0
  100. package/npm/darwin-x64/package.json +25 -0
  101. package/npm/linux-arm64/lib/.gitkeep +1 -0
  102. package/npm/linux-arm64/package.json +26 -0
  103. package/npm/linux-x64/lib/.gitkeep +1 -0
  104. package/npm/linux-x64/package.json +26 -0
  105. package/npm/linuxmusl-x64/lib/.gitkeep +1 -0
  106. package/npm/linuxmusl-x64/package.json +26 -0
  107. package/npm/win32-x64/lib/.gitkeep +1 -0
  108. package/npm/win32-x64/package.json +25 -0
  109. package/package.json +74 -0
  110. package/rosepetal-image-engine/binding.gyp +153 -0
  111. package/rosepetal-image-engine/package.json +19 -0
  112. package/rosepetal-image-engine/src/add-bbs.cpp +433 -0
  113. package/rosepetal-image-engine/src/add-mask.cpp +240 -0
  114. package/rosepetal-image-engine/src/add-masks.cpp +638 -0
  115. package/rosepetal-image-engine/src/advanced-mosaic.cpp +740 -0
  116. package/rosepetal-image-engine/src/blend.cpp +200 -0
  117. package/rosepetal-image-engine/src/concat.cpp +329 -0
  118. package/rosepetal-image-engine/src/crop.cpp +139 -0
  119. package/rosepetal-image-engine/src/draw.cpp +414 -0
  120. package/rosepetal-image-engine/src/filter.cpp +230 -0
  121. package/rosepetal-image-engine/src/filters/kernels.h +171 -0
  122. package/rosepetal-image-engine/src/image-align.cpp +551 -0
  123. package/rosepetal-image-engine/src/main.cpp +36 -0
  124. package/rosepetal-image-engine/src/mosaic.cpp +373 -0
  125. package/rosepetal-image-engine/src/padding.cpp +124 -0
  126. package/rosepetal-image-engine/src/resize.cpp +210 -0
  127. package/rosepetal-image-engine/src/rotate.cpp +177 -0
  128. package/rosepetal-image-engine/src/utils.h +563 -0
  129. package/rosepetal-image-engine/test-formats.js +119 -0
  130. package/scripts/build-opencv-static.ps1 +166 -0
  131. package/scripts/build-opencv-static.sh +147 -0
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Node-RED logic for *rosepetal-advanced-mosaic* (Ultra-optimized C++ backend).
3
+ * Creates composite images with per-image transformations (resize, rotate) and positioning.
4
+ * Super fast with zero-copy operations and parallel processing.
5
+ */
6
+ const { performance } = require('perf_hooks');
7
+ const CppProcessor = require('../../lib/cpp-bridge.js');
8
+
9
+ module.exports = function (RED) {
10
+ const NodeUtils = require('../../lib/node-utils.js')(RED);
11
+
12
+ function AdvancedMosaicNode(config) {
13
+ RED.nodes.createNode(this, config);
14
+ const node = this;
15
+
16
+ node.on('input', async (msg, send, done) => {
17
+ /* I/O paths - needed early for error passthrough */
18
+ const inputPath = config.inputPath || 'payload';
19
+ const outputPath = config.outputPath || 'payload';
20
+
21
+ /* Get input and capture first image for error passthrough */
22
+ const inputImages = RED.util.getMessageProperty(msg, inputPath);
23
+ const firstImage = Array.isArray(inputImages) ? inputImages[0] : inputImages;
24
+
25
+ try {
26
+ const t0 = performance.now();
27
+ node.status({});
28
+ const outputFormat = config.outputFormat || 'raw';
29
+ const outputQuality = parseInt(config.outputQuality) || 90;
30
+ const pngOptimize = config.pngOptimize || false;
31
+ const propagateMasks = !!config.propagateMasks;
32
+ const masksPath = config.masksPath || 'masks';
33
+ const masksPathType = config.masksPathType || 'msg';
34
+ const masksOutputPath = config.masksOutputPath || 'masks';
35
+ const masksOutputPathType = config.masksOutputPathType || 'msg';
36
+
37
+ /* Canvas configuration */
38
+ const canvasWidth = Number(NodeUtils.resolveDimension(node, config.canvasWidthType, config.canvasWidth, msg));
39
+ const canvasHeight = Number(NodeUtils.resolveDimension(node, config.canvasHeightType, config.canvasHeight, msg));
40
+ const backgroundColor = config.backgroundColor || '#000000';
41
+ const normalized = !!config.coordNorm;
42
+
43
+ /* Image configurations */
44
+ const imageConfigs = config.imageConfigs || [];
45
+
46
+ /* Input images array (inputImages already captured above for error passthrough) */
47
+ const imageArray = Array.isArray(inputImages) ? inputImages : [inputImages];
48
+
49
+ // Validate input images - advanced mosaic expects array input
50
+ if (!NodeUtils.validateListImage(imageArray, node)) {
51
+ return NodeUtils.handleValidationErrorWithPassthrough(
52
+ node, 'Invalid image list', msg, send, done,
53
+ { originalPayload: firstImage, outputPath, outputType: 'single' }
54
+ );
55
+ }
56
+
57
+ /* Validate image configurations */
58
+ const validImageConfigs = imageConfigs.filter(config => {
59
+ const arrayIndex = parseInt(config.arrayIndex);
60
+ return arrayIndex >= 0 && arrayIndex < imageArray.length;
61
+ });
62
+
63
+ // Note: Allow empty validImageConfigs - this will create canvas with just background color
64
+
65
+ /* Validate canvas dimensions */
66
+ if (canvasWidth <= 0 || canvasHeight <= 0) {
67
+ throw new Error('Canvas dimensions must be positive numbers');
68
+ }
69
+
70
+ /* Optional mask propagation */
71
+ let masksArray = null;
72
+ if (propagateMasks) {
73
+ try {
74
+ if (masksPathType === 'msg') {
75
+ masksArray = RED.util.getMessageProperty(msg, masksPath);
76
+ } else if (masksPathType === 'flow') {
77
+ masksArray = node.context().flow.get(masksPath);
78
+ } else if (masksPathType === 'global') {
79
+ masksArray = node.context().global.get(masksPath);
80
+ }
81
+ } catch (e) {
82
+ node.warn(`Failed to read masks from ${masksPathType}.${masksPath}: ${e.message}`);
83
+ }
84
+
85
+ if (!Array.isArray(masksArray)) {
86
+ node.warn('Mask propagation enabled but masks input is not an array; skipping mask propagation.');
87
+ masksArray = null;
88
+ }
89
+ }
90
+
91
+ /* Single ultra-fast C++ call */
92
+ const options = {
93
+ outputFormat,
94
+ quality: outputQuality,
95
+ pngOptimize
96
+ };
97
+ if (masksArray) {
98
+ options.masks = masksArray;
99
+ }
100
+
101
+ const { image, masks: transformedMasks, timing = {} } = await CppProcessor.advancedMosaic(
102
+ imageArray,
103
+ canvasWidth,
104
+ canvasHeight,
105
+ backgroundColor,
106
+ validImageConfigs,
107
+ normalized,
108
+ options
109
+ );
110
+
111
+ const maskCount = Array.isArray(transformedMasks) ? transformedMasks.length : (propagateMasks && masksArray ? masksArray.length : 0);
112
+
113
+ /* Set output */
114
+ RED.util.setMessageProperty(msg, outputPath, image);
115
+ if (propagateMasks && transformedMasks) {
116
+ if (masksOutputPathType === 'msg') {
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
+ }
123
+ }
124
+
125
+ /* Performance status - same format as other nodes */
126
+ const { convertMs = 0, taskMs = 0, encodeMs = 0 } = timing;
127
+ const totalTime = performance.now() - t0;
128
+
129
+ // Debug image display
130
+ let debugFormat = null;
131
+ if (config.debugEnabled) {
132
+ try {
133
+ // Resolve and validate debug width
134
+ let debugWidth = NodeUtils.resolveDimension(
135
+ node,
136
+ config.debugWidthType,
137
+ config.debugWidth,
138
+ msg
139
+ );
140
+ debugWidth = Math.max(1, parseInt(debugWidth) || 200); // Ensure positive, default 200
141
+
142
+ const debugResult = await NodeUtils.debugImageDisplay(
143
+ image,
144
+ outputFormat,
145
+ outputQuality,
146
+ node,
147
+ true,
148
+ debugWidth
149
+ );
150
+
151
+ if (debugResult) {
152
+ debugFormat = debugResult.formatMessage;
153
+ // Update node status with debug info
154
+ const configsText = validImageConfigs.length === 0 ? 'empty canvas' : `${validImageConfigs.length} img`;
155
+ NodeUtils.setSuccessStatusWithDebug(node, 1, totalTime, {
156
+ convertMs: convertMs,
157
+ taskMs: taskMs,
158
+ encodeMs: encodeMs
159
+ }, `${debugFormat} (${configsText})`);
160
+ }
161
+ } catch (debugError) {
162
+ node.warn(`Debug display error: ${debugError.message}`);
163
+ }
164
+ }
165
+
166
+ // Set regular status if debug not enabled or failed
167
+ if (!debugFormat) {
168
+ const statusText = validImageConfigs.length === 0
169
+ ? `OK: empty canvas in ${totalTime.toFixed(2)} ms`
170
+ : `OK: ${validImageConfigs.length} img${maskCount ? `/${maskCount} mask` : ''} in ${totalTime.toFixed(2)} ms ` +
171
+ `(conv ${(convertMs + encodeMs).toFixed(2)} ms | ` +
172
+ `task ${taskMs.toFixed(2)} ms)`;
173
+
174
+ node.status({
175
+ fill: 'green',
176
+ shape: 'dot',
177
+ text: statusText
178
+ });
179
+ }
180
+
181
+ NodeUtils.recordPerformanceMetrics(node, msg, timing, totalTime);
182
+
183
+ send(msg);
184
+ done && done();
185
+ } catch (err) {
186
+ NodeUtils.handleNodeErrorWithPassthrough(
187
+ node, err, msg, send, done, 'advanced-mosaic processing',
188
+ { originalPayload: firstImage, outputPath, outputType: 'single' }
189
+ );
190
+ }
191
+ });
192
+ }
193
+
194
+ RED.nodes.registerType('advanced-mosaic', AdvancedMosaicNode);
195
+ };
@@ -0,0 +1,390 @@
1
+ <!-- nodes/rosepetal-concat/concat.html -->
2
+
3
+ <script type="text/javascript">
4
+ RED.nodes.registerType('concat',{
5
+ category:'RP Image',
6
+ color:'#DDA0DD',
7
+ icon:'font-awesome/fa-th-large',
8
+ defaults:{
9
+ name:{value:""},
10
+ inputPath:{value:"payload"}, inputPathType:{value:"msg"},
11
+ outputPath:{value:"payload"},outputPathType:{value:"msg"},
12
+ outputFormat:{value:"raw"},
13
+ outputQuality:{value:90},
14
+ pngOptimize:{value:false},
15
+ // Debug configuration
16
+ debugEnabled:{value:false},
17
+ debugWidth:{value:200},
18
+ debugWidthType:{value:"num"},
19
+ direction:{value:"right"}, // right|left|down|up
20
+ strategy :{value:"pad-start"}, // pad-start|pad-end|pad-both|resize
21
+ padColor :{value:"#000000"}
22
+ },
23
+ inputs:1,outputs:1,
24
+ label:function(){return this.name||"concat";},
25
+ oneditprepare:function(){
26
+ /* path typedInputs */
27
+ $("#node-input-inputPath").typedInput({
28
+ default:'msg',types:['msg','flow','global'],
29
+ typeField:"#node-input-inputPathType"});
30
+ $("#node-input-outputPath").typedInput({
31
+ default:'msg',types:['msg','flow','global'],
32
+ typeField:"#node-input-outputPathType"});
33
+
34
+ /* colour‑row toggle (only change added) */
35
+ const $strategy=$("#node-input-strategy");
36
+ const $padRow =$("#pad-colour-row");
37
+ function toggleColour(){ $padRow.toggle($strategy.val()!=="resize"); }
38
+ $strategy.on("change",toggleColour);
39
+ toggleColour(); /* initial state */
40
+
41
+ function updateQualityVisibility(){
42
+ const format = $("#node-input-outputFormat").val();
43
+ $("#quality-row").toggle(format === "jpg" || format === "webp");
44
+ $("#png-optimize-row").toggle(format === "png");
45
+ }
46
+ $("#node-input-outputFormat").on("change", updateQualityVisibility);
47
+ updateQualityVisibility(); // initial state
48
+
49
+ // === Debug Display Logic ===
50
+ const debugCheckbox = $('#node-input-debugEnabled');
51
+ const debugWidthRow = $('#debug-width-row');
52
+
53
+ // Initialize debug width TypedInput
54
+ $("#node-input-debugWidth").typedInput({
55
+ default: 'num',
56
+ types: ['num', 'msg', 'flow', 'global'],
57
+ typeField: "#node-input-debugWidthType"
58
+ });
59
+
60
+ // Function to toggle debug width visibility
61
+ function updateDebugWidthVisibility() {
62
+ if (debugCheckbox.is(':checked')) {
63
+ debugWidthRow.show();
64
+ } else {
65
+ debugWidthRow.hide();
66
+ }
67
+ }
68
+
69
+ // Initialize debug state on node open
70
+ updateDebugWidthVisibility();
71
+
72
+ // Handle debug checkbox changes
73
+ debugCheckbox.on('change', function() {
74
+ const enabled = this.checked;
75
+ updateDebugWidthVisibility();
76
+ // Store debug state for runtime access
77
+ $('#node-input-debugEnabled').data('debug-enabled', enabled);
78
+ });
79
+ }
80
+ });
81
+
82
+ // Debug image display renderer - shared across all image processing nodes
83
+ if (!window.debugImageRendererInitialized) {
84
+ window.debugImageRendererInitialized = true;
85
+
86
+ (function() {
87
+ var isSubscribed = false;
88
+
89
+ function subscribeToDebugImages() {
90
+ if (isSubscribed || typeof RED === 'undefined' || !RED.comms) return;
91
+ isSubscribed = true;
92
+
93
+ RED.comms.subscribe('debug-image', function(event, data) {
94
+ if (!data || !data.id) return;
95
+
96
+ try {
97
+ renderDebugImage(data);
98
+ } catch (err) {
99
+ console.warn('Debug image render error:', err);
100
+ }
101
+ });
102
+ }
103
+
104
+ function renderDebugImage(data) {
105
+ const nodeId = data.id;
106
+ const base64Data = data.data;
107
+ const format = data.format || 'unknown';
108
+ const mimeType = data.mimeType || 'jpeg';
109
+
110
+ if (!base64Data) {
111
+ removeDebugImage(nodeId);
112
+ return;
113
+ }
114
+
115
+ const nodeElement = document.getElementById(nodeId);
116
+ if (!nodeElement) return;
117
+
118
+ let debugContainer = document.getElementById('debug-img-container-' + nodeId);
119
+
120
+ if (!debugContainer) {
121
+ // Create SVG foreignObject to embed HTML content in SVG
122
+ debugContainer = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
123
+ debugContainer.id = 'debug-img-container-' + nodeId;
124
+ debugContainer.setAttribute('x', '70');
125
+ debugContainer.setAttribute('y', '5');
126
+ debugContainer.setAttribute('width', '120');
127
+ debugContainer.setAttribute('height', '120');
128
+ debugContainer.style.overflow = 'visible';
129
+
130
+ // Create simple image directly inside foreignObject
131
+ const img = document.createElement('img');
132
+ img.id = 'debug-img-' + nodeId;
133
+ img.style.width = '100%';
134
+ img.style.height = 'auto';
135
+ img.style.display = 'block';
136
+ img.style.cursor = 'pointer';
137
+ img.style.maxHeight = '100px';
138
+ img.style.maxWidth = '100px';
139
+
140
+ img.onclick = function() {
141
+ removeDebugImage(nodeId);
142
+ };
143
+
144
+ debugContainer.appendChild(img);
145
+ nodeElement.appendChild(debugContainer);
146
+ }
147
+
148
+ const img = document.getElementById('debug-img-' + nodeId);
149
+
150
+ if (img) {
151
+ img.src = `data:image/${mimeType};base64,${base64Data}`;
152
+ img.title = 'Debug image (click to hide)';
153
+ }
154
+ }
155
+
156
+ function removeDebugImage(nodeId) {
157
+ const debugContainer = document.getElementById('debug-img-container-' + nodeId);
158
+ if (debugContainer) {
159
+ debugContainer.remove();
160
+ }
161
+ }
162
+
163
+ function initializeWhenReady() {
164
+ if (typeof RED !== 'undefined' && RED.comms) {
165
+ subscribeToDebugImages();
166
+
167
+ // Clean up orphaned debug images periodically
168
+ setInterval(function() {
169
+ const debugContainers = document.querySelectorAll('[id^="debug-img-container-"]');
170
+ debugContainers.forEach(container => {
171
+ const nodeId = container.id.replace('debug-img-container-', '');
172
+ const nodeElement = document.getElementById(nodeId);
173
+ if (!nodeElement) {
174
+ container.remove();
175
+ }
176
+ });
177
+ }, 5000);
178
+ } else {
179
+ setTimeout(initializeWhenReady, 100);
180
+ }
181
+ }
182
+
183
+ if (document.readyState === 'loading') {
184
+ document.addEventListener('DOMContentLoaded', initializeWhenReady);
185
+ } else {
186
+ initializeWhenReady();
187
+ }
188
+ })();
189
+ }
190
+ </script>
191
+
192
+ <script type="text/x-red" data-template-name="concat">
193
+ <div class="form-row">
194
+ <label><i class="fa fa-sign-in"></i> Input</label>
195
+ <input type="text" id="node-input-inputPath" style="width:70%;">
196
+ <input type="hidden" id="node-input-inputPathType">
197
+ </div>
198
+ <div class="form-row">
199
+ <label><i class="fa fa-sign-out"></i> Output</label>
200
+ <input type="text" id="node-input-outputPath" style="width:70%;">
201
+ <input type="hidden" id="node-input-outputPathType">
202
+ </div>
203
+ <div class="form-row">
204
+ <label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
205
+ <select id="node-input-outputFormat" style="width: 200px;">
206
+ <option value="raw">Raw (fastest)</option>
207
+ <option value="jpg">JPEG</option>
208
+ <option value="png">PNG</option>
209
+ <option value="webp">WebP</option>
210
+ </select>
211
+ </div>
212
+ <div class="form-row" id="quality-row">
213
+ <label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
214
+ <input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
215
+ <span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
216
+ </div>
217
+ <div class="form-row" id="png-optimize-row" style="display: none;">
218
+ <label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
219
+ <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
220
+ <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
221
+ </div>
222
+
223
+ <!-- Debug Configuration -->
224
+ <div class="form-row">
225
+ <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
226
+ <input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
227
+ <label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
228
+ </div>
229
+ <div class="form-row" id="debug-width-row" style="display: none;">
230
+ <label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
231
+ <input type="text" id="node-input-debugWidth" style="width: 120px;">
232
+ <input type="hidden" id="node-input-debugWidthType">
233
+ <span style="margin-left: 10px; color: #666;">pixels</span>
234
+ </div>
235
+
236
+ <hr/>
237
+ <div class="form-row">
238
+ <label><i class="fa fa-arrows-h"></i> Direction</label>
239
+ <select id="node-input-direction">
240
+ <option value="right">→ Right</option>
241
+ <option value="left">← Left</option>
242
+ <option value="down">↓ Down</option>
243
+ <option value="up">↑ Up</option>
244
+ </select>
245
+ </div>
246
+ <div class="form-row">
247
+ <label><i class="fa fa-th"></i> Strategy</label>
248
+ <select id="node-input-strategy">
249
+ <option value="pad-start">Pad at start</option>
250
+ <option value="pad-end">Pad at end</option>
251
+ <option value="pad-both">Pad both sides</option>
252
+ <option value="resize">Resize to max</option>
253
+ </select>
254
+ </div>
255
+ <!-- único cambio: id para poder toggle‑ar -->
256
+ <div class="form-row" id="pad-colour-row">
257
+ <label for="node-input-padColor"><i class="fa fa-tint"></i> Pad colour</label>
258
+ <input type="color" id="node-input-padColor" style="width:80px;">
259
+ </div>
260
+ </script>
261
+
262
+ <script type="text/x-red" data-help-name="concat">
263
+ <p><b>rosepetal-concat</b> combines multiple images into a single composite image through concatenation. Images can be joined horizontally or vertically with intelligent handling of size differences using padding or scaling strategies.</p>
264
+
265
+ <h3>Details</h3>
266
+ <p>This node processes arrays of images and combines them into a seamless composite using high-performance C++ operations. It supports flexible concatenation directions, intelligent sizing strategies, and maintains image quality throughout the process. The node handles both raw pixel data and encoded image files transparently.</p>
267
+
268
+ <h3>Properties</h3>
269
+ <dl class="message-properties">
270
+ <dt>Input from <span class="property-type">string</span></dt>
271
+ <dd>Message property path containing the input image array. Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
272
+
273
+ <dt>Output to <span class="property-type">string</span></dt>
274
+ <dd>Message property path where the concatenated image will be stored. Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
275
+
276
+ <dt>Output Format <span class="property-type">string</span></dt>
277
+ <dd>Format for the output image: <code>raw</code> (fastest), <code>jpg</code>, <code>png</code>, or <code>webp</code>.</dd>
278
+
279
+ <dt>Quality <span class="property-type">number</span></dt>
280
+ <dd>Compression quality (1-100) for JPEG and WebP formats. Only visible when JPG or WebP is selected.</dd>
281
+
282
+ <dt>Direction <span class="property-type">string</span></dt>
283
+ <dd>Concatenation direction: <code>right</code> (→), <code>left</code> (←), <code>down</code> (↓), or <code>up</code> (↑).</dd>
284
+
285
+ <dt>Strategy <span class="property-type">string</span></dt>
286
+ <dd>Size handling strategy: <code>pad-start</code>, <code>pad-end</code>, <code>pad-both</code>, or <code>resize</code>.</dd>
287
+
288
+ <dt>Pad Colour <span class="property-type">color</span></dt>
289
+ <dd>Background color for padding areas when using pad strategies. Hidden when resize strategy is selected.</dd>
290
+ </dl>
291
+
292
+ <h3>Inputs</h3>
293
+ <p>The input should be an array of image objects in the standard format:</p>
294
+ <pre>{
295
+ data: Buffer, // Raw pixel data or encoded file buffer
296
+ width: number, // Image width in pixels
297
+ height: number, // Image height in pixels
298
+ channels: number, // Channel count (1=grayscale, 3=RGB, 4=RGBA)
299
+ colorSpace: string, // "GRAY", "RGB", "RGBA", "BGR", "BGRA"
300
+ dtype: string // "uint8", "uint16", "float32"
301
+ }</pre>
302
+ <p>File buffers (JPEG, PNG, WebP, BMP) are automatically detected and decoded.</p>
303
+
304
+ <h3>Outputs</h3>
305
+ <p>Produces a single concatenated image in the specified format:</p>
306
+ <ul>
307
+ <li><b>Raw format:</b> Complete image object with pixel data and metadata</li>
308
+ <li><b>Encoded formats (JPG/PNG/WebP):</b> File buffer ready for storage or transmission</li>
309
+ </ul>
310
+ <p>Output dimensions depend on input images and concatenation direction. Width/height are calculated automatically based on the combined images.</p>
311
+
312
+ <h3>Concatenation Strategies</h3>
313
+ <h4>Padding Strategies</h4>
314
+ <ul>
315
+ <li><b>Pad Start:</b> Adds padding before smaller images (top for horizontal, left for vertical)</li>
316
+ <li><b>Pad End:</b> Adds padding after smaller images (bottom for horizontal, right for vertical)</li>
317
+ <li><b>Pad Both:</b> Centers smaller images with equal padding on both sides</li>
318
+ </ul>
319
+ <h4>Resize Strategy</h4>
320
+ <ul>
321
+ <li><b>Resize:</b> Scales all images to match the largest dimension, eliminating gaps entirely</li>
322
+ </ul>
323
+
324
+ <h3>Direction Behavior</h3>
325
+ <ul>
326
+ <li><b>Right (→):</b> Images placed left-to-right, heights normalized</li>
327
+ <li><b>Left (←):</b> Images placed right-to-left, heights normalized</li>
328
+ <li><b>Down (↓):</b> Images stacked top-to-bottom, widths normalized</li>
329
+ <li><b>Up (↑):</b> Images stacked bottom-to-top, widths normalized</li>
330
+ </ul>
331
+
332
+ <h3>Examples</h3>
333
+ <h4>Horizontal Photo Strip</h4>
334
+ <p>Create a horizontal photo strip from portrait images:</p>
335
+ <ul>
336
+ <li>Direction: Right (→)</li>
337
+ <li>Strategy: Pad Both</li>
338
+ <li>Pad Color: White (#FFFFFF)</li>
339
+ </ul>
340
+
341
+ <h4>Vertical Timeline</h4>
342
+ <p>Stack images vertically for a timeline view:</p>
343
+ <ul>
344
+ <li>Direction: Down (↓)</li>
345
+ <li>Strategy: Resize</li>
346
+ <li>Output: PNG for high quality</li>
347
+ </ul>
348
+
349
+ <h4>Dynamic Context Usage</h4>
350
+ <p>Use flow context for batch processing multiple image sets:</p>
351
+ <ul>
352
+ <li>Input from: flow.imageArray</li>
353
+ <li>Output to: flow.concatenated</li>
354
+ </ul>
355
+
356
+ <h3>Node Interactions</h3>
357
+ <ul>
358
+ <li><b>Upstream:</b> Works with <code>array-in</code>, <code>image-in</code>, or any nodes producing image arrays</li>
359
+ <li><b>Downstream:</b> Connect to <code>array-out</code>, file writers, or further processing nodes</li>
360
+ <li><b>Chaining:</b> Can be chained with other mix nodes for complex compositions</li>
361
+ <li><b>Flow Integration:</b> Supports flow and global context for cross-node data sharing</li>
362
+ </ul>
363
+
364
+ <h3>Output Formats</h3>
365
+ <ul>
366
+ <li><b>Raw (fastest):</b> Uncompressed pixel data, ideal for further processing</li>
367
+ <li><b>JPEG:</b> Lossy compression, smaller files, quality parameter controls compression level</li>
368
+ <li><b>PNG:</b> Lossless compression, preserves transparency, larger files</li>
369
+ <li><b>WebP:</b> Modern format with superior compression, quality parameter available</li>
370
+ </ul>
371
+
372
+ <h3>Error Handling</h3>
373
+ <ul>
374
+ <li><b>Input Validation:</b> Comprehensive validation of image structure and array format</li>
375
+ <li><b>Size Compatibility:</b> Automatic handling of different image dimensions</li>
376
+ <li><b>Memory Management:</b> Efficient memory usage with automatic cleanup</li>
377
+ <li><b>Format Support:</b> Graceful handling of mixed input formats</li>
378
+ <li><b>Warning System:</b> Uses <code>node.warn()</code> for non-fatal issues without stopping flow</li>
379
+ </ul>
380
+
381
+ <h3>Performance</h3>
382
+ <ul>
383
+ <li><b>C++ Backend:</b> High-performance OpenCV-based processing with optimized build flags</li>
384
+ <li><b>Zero-Copy Operations:</b> Minimal memory allocation and copying for maximum efficiency</li>
385
+ <li><b>Parallel Processing:</b> Array operations processed in parallel using Promise.all()</li>
386
+ <li><b>Status Timing:</b> Real-time performance metrics displayed as <code>conv | task | enc</code> (conversion, processing, encoding)</li>
387
+ <li><b>Memory Optimization:</b> Automatic memory management and garbage collection</li>
388
+ <li><b>Build Optimization:</b> Compiled with <code>-O3</code>, <code>-march=native</code>, <code>-ffast-math</code> flags</li>
389
+ </ul>
390
+ </script>