@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,241 @@
1
+ /**
2
+ * Node-RED logic for *rosepetal-add-bbs* (C++ backend).
3
+ * Draws bounding boxes with optional labels on images for object detection visualization.
4
+ * Supports class name and confidence display with customizable colors and styles.
5
+ *
6
+ * Timing fields returned by C++:
7
+ * timing.convertMs · timing.taskMs · timing.encodeMs
8
+ * …and the node status shows: OK … (conv X | task Y ms)
9
+ */
10
+ const { performance } = require('perf_hooks');
11
+ const Cpp = require('../../lib/cpp-bridge.js');
12
+
13
+ module.exports = function (RED) {
14
+ const NodeUtils = require('../../lib/node-utils.js')(RED);
15
+
16
+ function AddBBsNode(config) {
17
+ RED.nodes.createNode(this, config);
18
+ const node = this;
19
+
20
+ node.on('input', async (msg, send, done) => {
21
+ // Capture original payload for error passthrough
22
+ const outputPath = config.outputPath || 'payload';
23
+ const originalPayload = RED.util.getMessageProperty(msg, config.imagePath || 'payload.image');
24
+
25
+ try {
26
+ const t0 = performance.now();
27
+ node.status({}); // clear status
28
+
29
+ /* ▸ Read image and boxes from message -------------------------- */
30
+ // Get base image and boxes array from specified paths
31
+ const image = RED.util.getMessageProperty(msg, config.imagePath || 'payload.image');
32
+ const boxesArray = RED.util.getMessageProperty(msg, config.boxesPath || 'payload');
33
+
34
+ // Validate base image
35
+ const baseImg = NodeUtils.validateImageStructure(image, node);
36
+ if (!baseImg) {
37
+ return NodeUtils.handleValidationErrorWithPassthrough(
38
+ node, 'Base image is invalid or missing', msg, send, done,
39
+ { originalPayload, outputPath, outputType: 'single' }
40
+ );
41
+ }
42
+
43
+ // Validate boxes input - expect direct array format
44
+ if (!Array.isArray(boxesArray)) {
45
+ return NodeUtils.handleValidationErrorWithPassthrough(
46
+ node, 'Boxes input must be an array', msg, send, done,
47
+ { originalPayload, outputPath, outputType: 'single' }
48
+ );
49
+ }
50
+
51
+ if (boxesArray.length === 0) {
52
+ const total = performance.now() - t0;
53
+ RED.util.setMessageProperty(msg, config.outputPath || 'payload', baseImg);
54
+ NodeUtils.setSuccessStatus(node, 0, total, { convertMs: 0, taskMs: 0, encodeMs: 0 });
55
+ NodeUtils.recordPerformanceMetrics(node, msg, {
56
+ convertMs: 0,
57
+ encodeMs: 0,
58
+ taskMs: 0
59
+ }, total);
60
+ send(msg);
61
+ done && done();
62
+ return;
63
+ }
64
+
65
+ // Validate boxes array structure in detail
66
+ let totalBoxCount = 0;
67
+ for (let boxIndex = 0; boxIndex < boxesArray.length; boxIndex++) {
68
+ const boxObj = boxesArray[boxIndex];
69
+
70
+ if (!boxObj || typeof boxObj !== 'object') {
71
+ return NodeUtils.handleValidationErrorWithPassthrough(
72
+ node, `Invalid box object at index ${boxIndex}: expected object`, msg, send, done,
73
+ { originalPayload, outputPath, outputType: 'single' }
74
+ );
75
+ }
76
+
77
+ if (!boxObj.hasOwnProperty('raw_boxes') || !Array.isArray(boxObj.raw_boxes)) {
78
+ return NodeUtils.handleValidationErrorWithPassthrough(
79
+ node, `Invalid box object at index ${boxIndex}: 'raw_boxes' property must be an array`, msg, send, done,
80
+ { originalPayload, outputPath, outputType: 'single' }
81
+ );
82
+ }
83
+
84
+ if (boxObj.raw_boxes.length !== 4) {
85
+ return NodeUtils.handleValidationErrorWithPassthrough(
86
+ node, `Invalid box format at index ${boxIndex}: expected 4 corner points`, msg, send, done,
87
+ { originalPayload, outputPath, outputType: 'single' }
88
+ );
89
+ }
90
+
91
+ // Validate 4-corner format
92
+ const [[x1, y1], [x2, y1_check], [x2_check, y2], [x1_check, y2_check]] = boxObj.raw_boxes;
93
+
94
+ if (x2 !== x2_check || x1 !== x1_check || y1 !== y1_check || y2 !== y2_check) {
95
+ return NodeUtils.handleValidationErrorWithPassthrough(
96
+ node, `Inconsistent corner points at index ${boxIndex}`, msg, send, done,
97
+ { originalPayload, outputPath, outputType: 'single' }
98
+ );
99
+ }
100
+
101
+ // Check normalized range
102
+ if (x1 < 0 || x1 > 1 || x2 < 0 || x2 > 1 || y1 < 0 || y1 > 1 || y2 < 0 || y2 > 1) {
103
+ return NodeUtils.handleValidationErrorWithPassthrough(
104
+ node, `Box coordinates out of range [0,1] at index ${boxIndex}`, msg, send, done,
105
+ { originalPayload, outputPath, outputType: 'single' }
106
+ );
107
+ }
108
+
109
+ if (!boxObj.hasOwnProperty('tag') || typeof boxObj.tag !== 'string') {
110
+ return NodeUtils.handleValidationErrorWithPassthrough(
111
+ node, `Invalid tag at index ${boxIndex}: must be a non-empty string`, msg, send, done,
112
+ { originalPayload, outputPath, outputType: 'single' }
113
+ );
114
+ }
115
+
116
+ if (boxObj.tag.trim() === '') {
117
+ return NodeUtils.handleValidationErrorWithPassthrough(
118
+ node, `Empty tag at index ${boxIndex}: tag cannot be empty`, msg, send, done,
119
+ { originalPayload, outputPath, outputType: 'single' }
120
+ );
121
+ }
122
+
123
+ totalBoxCount++;
124
+ }
125
+
126
+ if (totalBoxCount === 0) {
127
+ const total = performance.now() - t0;
128
+ RED.util.setMessageProperty(msg, config.outputPath || 'payload', baseImg);
129
+ NodeUtils.setSuccessStatus(node, 0, total, { convertMs: 0, taskMs: 0, encodeMs: 0 });
130
+ NodeUtils.recordPerformanceMetrics(node, msg, {
131
+ convertMs: 0,
132
+ encodeMs: 0,
133
+ taskMs: 0
134
+ }, total);
135
+ send(msg);
136
+ done && done();
137
+ return;
138
+ }
139
+
140
+ /* ▸ Options from the editor -------------------------------------- */
141
+ // Display options (showClassName and showConfidence default to true)
142
+ const showClassName = config.showClassName !== false;
143
+ const showConfidence = config.showConfidence !== false;
144
+ const onlyMapped = config.onlyMapped === true;
145
+
146
+ // Visual settings
147
+ const boxThickness = Math.max(1, Math.min(10, parseInt(config.boxThickness) || 2));
148
+ const fontSize = Math.max(0.3, Math.min(2.0, parseFloat(config.fontSize) || 0.5));
149
+ const labelBackground = true; // Always enable background for readability
150
+
151
+ // Output settings
152
+ const outputFormat = config.outputFormat || 'raw';
153
+ const outputQuality = parseInt(config.outputQuality) || 90;
154
+ const pngOptimize = config.pngOptimize || false;
155
+
156
+ // Build class color map from configuration
157
+ const classColorMap = {};
158
+ const classColorMappings = config.classColorMappings || [];
159
+
160
+ for (const mapping of classColorMappings) {
161
+ if (mapping.className && mapping.className.trim() !== '' && mapping.color) {
162
+ classColorMap[mapping.className.trim()] = mapping.color;
163
+ }
164
+ }
165
+
166
+ /* ▸ Single call to the C++ addon --------------------------------- */
167
+ const { image: result, timing = {}, boxCount } =
168
+ await Cpp.addBBs(
169
+ baseImg,
170
+ boxesArray, // Pass direct array to C++
171
+ classColorMap,
172
+ showClassName,
173
+ showConfidence,
174
+ onlyMapped,
175
+ boxThickness,
176
+ fontSize,
177
+ 'above', // Always position labels above the box
178
+ labelBackground,
179
+ outputFormat,
180
+ outputQuality,
181
+ pngOptimize
182
+ );
183
+
184
+ /* ▸ Write the result back to msg ---------------------------------- */
185
+ RED.util.setMessageProperty(msg, config.outputPath || 'payload', result);
186
+
187
+ /* ▸ Status: standardized success formatting ----------------------- */
188
+ const total = performance.now() - t0;
189
+
190
+ // Debug image display
191
+ let debugFormat = null;
192
+ if (config.debugEnabled) {
193
+ try {
194
+ // Resolve and validate debug width
195
+ let debugWidth = NodeUtils.resolveDimension(
196
+ node,
197
+ config.debugWidthType,
198
+ config.debugWidth,
199
+ msg
200
+ );
201
+ debugWidth = Math.max(1, parseInt(debugWidth) || 200); // Ensure positive, default 200
202
+
203
+ const debugResult = await NodeUtils.debugImageDisplay(
204
+ result,
205
+ outputFormat,
206
+ outputQuality,
207
+ node,
208
+ true,
209
+ debugWidth
210
+ );
211
+
212
+ if (debugResult) {
213
+ debugFormat = debugResult.formatMessage;
214
+ // Update node status with debug info and box count
215
+ NodeUtils.setSuccessStatusWithDebug(node, boxCount, total, timing, debugFormat);
216
+ }
217
+ } catch (debugError) {
218
+ node.warn(`Debug display error: ${debugError.message}`);
219
+ }
220
+ }
221
+
222
+ // Set regular status if debug not enabled or failed
223
+ if (!debugFormat) {
224
+ NodeUtils.setSuccessStatus(node, boxCount, total, timing);
225
+ }
226
+
227
+ NodeUtils.recordPerformanceMetrics(node, msg, timing || {}, total);
228
+
229
+ send(msg);
230
+ done && done();
231
+ } catch (err) {
232
+ NodeUtils.handleNodeErrorWithPassthrough(
233
+ node, err, msg, send, done, 'add-bbs processing',
234
+ { originalPayload, outputPath, outputType: 'single' }
235
+ );
236
+ }
237
+ });
238
+ }
239
+
240
+ RED.nodes.registerType('add-bbs', AddBBsNode);
241
+ };