@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,162 @@
1
+ /**
2
+ * @file Node-RED logic for the resize node (C++-driven dimensions).
3
+ * Works with single images or arrays transparently.
4
+ * @author Rosepetal
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 ResizeNode(config) {
13
+ RED.nodes.createNode(this, config);
14
+ const node = this;
15
+
16
+ node.on('input', async (msg, send, done) => {
17
+ try {
18
+ const startTime = performance.now();
19
+ node.status({});
20
+ const inputPath = config.inputPath || 'payload';
21
+ const outputPath = config.outputPath || 'payload';
22
+ const outputFormat = config.outputFormat || 'raw';
23
+ const outputQuality = parseInt(config.outputQuality) || 90;
24
+ const pngOptimize = config.pngOptimize || false;
25
+
26
+ const originalPayload = RED.util.getMessageProperty(msg, inputPath);
27
+ const inputList = Array.isArray(originalPayload)
28
+ ? originalPayload
29
+ : [originalPayload];
30
+
31
+ // Validate input images
32
+ if (Array.isArray(originalPayload)) {
33
+ if (!NodeUtils.validateListImage(originalPayload, node)) {
34
+ return NodeUtils.handleValidationErrorWithPassthrough(
35
+ node, 'Invalid image list structure', msg, send, done,
36
+ { originalPayload, outputPath, outputType: 'preserve' }
37
+ );
38
+ }
39
+ } else {
40
+ if (!NodeUtils.validateSingleImage(originalPayload, node)) {
41
+ return NodeUtils.handleValidationErrorWithPassthrough(
42
+ node, 'Invalid image structure', msg, send, done,
43
+ { originalPayload, outputPath, outputType: 'preserve' }
44
+ );
45
+ }
46
+ }
47
+
48
+ const promises = inputList.map((inputImage) => {
49
+ // Resolve dimension values (can come from msg/flow/global)
50
+ let wVal = NodeUtils.resolveDimension(
51
+ node,
52
+ config.widthType,
53
+ config.widthValue,
54
+ msg
55
+ );
56
+ let hVal = NodeUtils.resolveDimension(
57
+ node,
58
+ config.heightType,
59
+ config.heightValue,
60
+ msg
61
+ );
62
+
63
+ // Convert to Number or NaN (C++ interprets NaN as "Auto")
64
+ wVal = wVal === null || wVal === '' ? NaN : Number(wVal);
65
+ hVal = hVal === null || hVal === '' ? NaN : Number(hVal);
66
+
67
+ // Direct call to addon: (image, wMode, wVal, hMode, hVal, outputFormat, quality, pngOptimize)
68
+ return CppProcessor.resize(
69
+ inputImage,
70
+ config.widthMode, wVal,
71
+ config.heightMode, hVal,
72
+ outputFormat,
73
+ outputQuality,
74
+ pngOptimize
75
+ );
76
+ });
77
+ const results = await Promise.all(promises);
78
+
79
+ // Aggregate timings and prepare output
80
+ const { totalConvertMs, totalTaskMs, encodeMs, images } =
81
+ results.reduce(
82
+ (acc, { image, timing }) => {
83
+ acc.totalConvertMs += timing?.convertMs ?? 0;
84
+ acc.totalTaskMs += timing?.taskMs ?? 0;
85
+ acc.encodeMs += timing?.encodeMs ?? 0;
86
+ acc.images.push(image);
87
+ return acc;
88
+ },
89
+ { totalConvertMs: 0, totalTaskMs: 0, encodeMs: 0, images: [] }
90
+ );
91
+
92
+ const out = Array.isArray(originalPayload) ? images : images[0];
93
+ const elapsedTime = performance.now() - startTime;
94
+
95
+ // Debug image display
96
+ let debugFormat = null;
97
+ if (config.debugEnabled) {
98
+ try {
99
+ // Resolve and validate debug width
100
+ let debugWidth = NodeUtils.resolveDimension(
101
+ node,
102
+ config.debugWidthType,
103
+ config.debugWidth,
104
+ msg
105
+ );
106
+ debugWidth = Math.max(1, parseInt(debugWidth) || 200); // Ensure positive, default 200
107
+
108
+ // For arrays, show the first image as representative
109
+ const debugImage = Array.isArray(originalPayload) ? images[0] : images[0];
110
+ const debugResult = await NodeUtils.debugImageDisplay(
111
+ debugImage,
112
+ outputFormat,
113
+ outputQuality,
114
+ node,
115
+ true,
116
+ debugWidth
117
+ );
118
+
119
+ if (debugResult) {
120
+ debugFormat = debugResult.formatMessage;
121
+ // Update node status with debug info
122
+ NodeUtils.setSuccessStatusWithDebug(node, results.length, elapsedTime, {
123
+ convertMs: totalConvertMs,
124
+ taskMs: totalTaskMs,
125
+ encodeMs: encodeMs
126
+ }, debugFormat + (Array.isArray(originalPayload) ? ' (first)' : ''));
127
+ }
128
+ } catch (debugError) {
129
+ node.warn(`Debug display error: ${debugError.message}`);
130
+ }
131
+ }
132
+
133
+ // Set regular status if debug not enabled or failed
134
+ if (!debugFormat) {
135
+ NodeUtils.setSuccessStatus(node, results.length, elapsedTime, {
136
+ convertMs: totalConvertMs,
137
+ taskMs: totalTaskMs,
138
+ encodeMs: encodeMs
139
+ });
140
+ }
141
+
142
+ NodeUtils.recordPerformanceMetrics(node, msg, {
143
+ convertMs: totalConvertMs,
144
+ encodeMs: encodeMs,
145
+ taskMs: totalTaskMs
146
+ }, elapsedTime);
147
+
148
+ RED.util.setMessageProperty(msg, outputPath, out);
149
+
150
+ send(msg);
151
+ done && done();
152
+ } catch (err) {
153
+ NodeUtils.handleNodeErrorWithPassthrough(
154
+ node, err, msg, send, done, 'resize processing',
155
+ { originalPayload, outputPath, outputType: 'preserve' }
156
+ );
157
+ }
158
+ });
159
+ }
160
+
161
+ RED.nodes.registerType('resize', ResizeNode);
162
+ };
@@ -0,0 +1,299 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('rotate', {
3
+ category : 'RP Image',
4
+ color : '#DDA0DD',
5
+ defaults : {
6
+ name : { value:"" },
7
+ inputPath : { value:"payload" },
8
+ inputPathType : { value:"msg" },
9
+ outputPath : { value:"payload" },
10
+ outputPathType : { value:"msg" },
11
+ outputFormat : { value:"raw" },
12
+ outputQuality : { value:90 },
13
+ pngOptimize : { value:false },
14
+ // Debug configuration
15
+ debugEnabled : { value:false },
16
+ debugWidth : { value:200 },
17
+ debugWidthType : { value:"num" },
18
+ angleValue : { value:"90" },
19
+ angleType : { value:"num" },
20
+ padColor : { value:"#000000" } // siempre visible
21
+ },
22
+ inputs :1, outputs:1,
23
+ icon:"font-awesome/fa-rotate-right",
24
+ label:function(){ return this.name || "rotate"; },
25
+
26
+ oneditprepare:function(){
27
+ $("#node-input-inputPath").typedInput({default:'msg',types:['msg','flow','global'],typeField:"#node-input-inputPathType"});
28
+ $("#node-input-outputPath").typedInput({default:'msg',types:['msg','flow','global'],typeField:"#node-input-outputPathType"});
29
+ $("#node-input-angleValue").typedInput({default:'num',types:['num','msg','flow','global'],typeField:"#node-input-angleType"});
30
+
31
+ function updateQualityVisibility(){
32
+ const format = $("#node-input-outputFormat").val();
33
+ $("#quality-row").toggle(format === "jpg" || format === "webp");
34
+ $("#png-optimize-row").toggle(format === "png");
35
+ }
36
+ $("#node-input-outputFormat").on("change", updateQualityVisibility);
37
+ updateQualityVisibility(); // initial state
38
+
39
+ // === Debug Display Logic ===
40
+ const debugCheckbox = $('#node-input-debugEnabled');
41
+ const debugWidthRow = $('#debug-width-row');
42
+
43
+ // Initialize debug width TypedInput
44
+ $("#node-input-debugWidth").typedInput({
45
+ default: 'num',
46
+ types: ['num', 'msg', 'flow', 'global'],
47
+ typeField: "#node-input-debugWidthType"
48
+ });
49
+
50
+ // Function to toggle debug width visibility
51
+ function updateDebugWidthVisibility() {
52
+ if (debugCheckbox.is(':checked')) {
53
+ debugWidthRow.show();
54
+ } else {
55
+ debugWidthRow.hide();
56
+ }
57
+ }
58
+
59
+ // Initialize debug state on node open
60
+ updateDebugWidthVisibility();
61
+
62
+ // Handle debug checkbox changes
63
+ debugCheckbox.on('change', function() {
64
+ const enabled = this.checked;
65
+ updateDebugWidthVisibility();
66
+ // Store debug state for runtime access
67
+ $('#node-input-debugEnabled').data('debug-enabled', enabled);
68
+ });
69
+ }
70
+ });
71
+
72
+ // Debug image display renderer - shared across all image processing nodes
73
+ if (!window.debugImageRendererInitialized) {
74
+ window.debugImageRendererInitialized = true;
75
+
76
+ (function() {
77
+ var isSubscribed = false;
78
+
79
+ function subscribeToDebugImages() {
80
+ if (isSubscribed || typeof RED === 'undefined' || !RED.comms) return;
81
+ isSubscribed = true;
82
+
83
+ RED.comms.subscribe('debug-image', function(event, data) {
84
+ if (!data || !data.id) return;
85
+
86
+ try {
87
+ renderDebugImage(data);
88
+ } catch (err) {
89
+ console.warn('Debug image render error:', err);
90
+ }
91
+ });
92
+ }
93
+
94
+ function renderDebugImage(data) {
95
+ const nodeId = data.id;
96
+ const base64Data = data.data;
97
+ const format = data.format || 'unknown';
98
+ const mimeType = data.mimeType || 'jpeg';
99
+
100
+ if (!base64Data) {
101
+ removeDebugImage(nodeId);
102
+ return;
103
+ }
104
+
105
+ const nodeElement = document.getElementById(nodeId);
106
+ if (!nodeElement) return;
107
+
108
+ let debugContainer = document.getElementById('debug-img-container-' + nodeId);
109
+
110
+ if (!debugContainer) {
111
+ // Create SVG foreignObject to embed HTML content in SVG
112
+ debugContainer = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
113
+ debugContainer.id = 'debug-img-container-' + nodeId;
114
+ debugContainer.setAttribute('x', '70');
115
+ debugContainer.setAttribute('y', '5');
116
+ debugContainer.setAttribute('width', '120');
117
+ debugContainer.setAttribute('height', '120');
118
+ debugContainer.style.overflow = 'visible';
119
+
120
+ // Create simple image directly inside foreignObject
121
+ const img = document.createElement('img');
122
+ img.id = 'debug-img-' + nodeId;
123
+ img.style.width = '100%';
124
+ img.style.height = 'auto';
125
+ img.style.display = 'block';
126
+ img.style.cursor = 'pointer';
127
+ img.style.maxHeight = '100px';
128
+ img.style.maxWidth = '100px';
129
+
130
+ img.onclick = function() {
131
+ removeDebugImage(nodeId);
132
+ };
133
+
134
+ debugContainer.appendChild(img);
135
+ nodeElement.appendChild(debugContainer);
136
+ }
137
+
138
+ const img = document.getElementById('debug-img-' + nodeId);
139
+
140
+ if (img) {
141
+ img.src = `data:image/${mimeType};base64,${base64Data}`;
142
+ img.title = 'Debug image (click to hide)';
143
+ }
144
+ }
145
+
146
+ function removeDebugImage(nodeId) {
147
+ const debugContainer = document.getElementById('debug-img-container-' + nodeId);
148
+ if (debugContainer) {
149
+ debugContainer.remove();
150
+ }
151
+ }
152
+
153
+ function initializeWhenReady() {
154
+ if (typeof RED !== 'undefined' && RED.comms) {
155
+ subscribeToDebugImages();
156
+
157
+ // Clean up orphaned debug images periodically
158
+ setInterval(function() {
159
+ const debugContainers = document.querySelectorAll('[id^="debug-img-container-"]');
160
+ debugContainers.forEach(container => {
161
+ const nodeId = container.id.replace('debug-img-container-', '');
162
+ const nodeElement = document.getElementById(nodeId);
163
+ if (!nodeElement) {
164
+ container.remove();
165
+ }
166
+ });
167
+ }, 5000);
168
+ } else {
169
+ setTimeout(initializeWhenReady, 100);
170
+ }
171
+ }
172
+
173
+ if (document.readyState === 'loading') {
174
+ document.addEventListener('DOMContentLoaded', initializeWhenReady);
175
+ } else {
176
+ initializeWhenReady();
177
+ }
178
+ })();
179
+ }
180
+ </script>
181
+
182
+ <script type="text/x-red" data-template-name="rotate">
183
+ <div class="form-row"><label for="node-input-name"><i class="fa fa-tag"></i> Name</label><input type="text" id="node-input-name"></div>
184
+ <hr>
185
+ <div class="form-row"><label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input</label><input type="text" id="node-input-inputPath" style="width:70%;"><input type="hidden" id="node-input-inputPathType"></div>
186
+ <div class="form-row"><label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output</label><input type="text" id="node-input-outputPath" style="width:70%;"><input type="hidden" id="node-input-outputPathType"></div>
187
+ <div class="form-row">
188
+ <label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
189
+ <select id="node-input-outputFormat" style="width: 200px;">
190
+ <option value="raw">Raw (fastest)</option>
191
+ <option value="jpg">JPEG</option>
192
+ <option value="png">PNG</option>
193
+ <option value="webp">WebP</option>
194
+ </select>
195
+ </div>
196
+ <div class="form-row" id="quality-row">
197
+ <label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
198
+ <input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
199
+ <span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
200
+ </div>
201
+ <div class="form-row" id="png-optimize-row" style="display: none;">
202
+ <label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
203
+ <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
204
+ <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
205
+ </div>
206
+
207
+ <!-- Debug Configuration -->
208
+ <div class="form-row">
209
+ <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
210
+ <input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
211
+ <label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
212
+ </div>
213
+ <div class="form-row" id="debug-width-row" style="display: none;">
214
+ <label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
215
+ <input type="text" id="node-input-debugWidth" style="width: 120px;">
216
+ <input type="hidden" id="node-input-debugWidthType">
217
+ <span style="margin-left: 10px; color: #666;">pixels</span>
218
+ </div>
219
+
220
+ <hr>
221
+ <div class="form-row"><label for="node-input-angleValue"><i class="fa fa-refresh"></i> Angle (°)</label><input type="text" id="node-input-angleValue" style="width:70%;"><input type="hidden" id="node-input-angleType"></div>
222
+ <div class="form-row"><label for="node-input-padColor"><i class="fa fa-tint"></i> Pad colour</label><input type="color" id="node-input-padColor" style="width:80px;"></div>
223
+ </script>
224
+
225
+ <script type="text/x-red" data-help-name="rotate">
226
+ <p>Rotates images by a specified angle with customizable padding color using high-performance C++ processing.</p>
227
+
228
+ <h3>Details</h3>
229
+ <p>This node rotates images clockwise by a specified angle in degrees. When rotation creates areas outside the original image bounds, these areas are filled with the specified padding color. The rotation operation supports both single images and arrays, with dynamic angle values from various sources.</p>
230
+
231
+ <h3>Properties</h3>
232
+ <dl class="message-properties">
233
+ <dt>Input from <span class="property-type">string</span></dt>
234
+ <dd>The location to read image data from. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
235
+ <dt>Output to <span class="property-type">string</span></dt>
236
+ <dd>The location where the rotated image will be stored. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
237
+ <dt>Output Format <span class="property-type">string</span></dt>
238
+ <dd>Choose output format: <code>raw</code> (fastest, standard image object), <code>jpg</code>, <code>png</code>, or <code>webp</code> (encoded file buffers).</dd>
239
+ <dt>Quality <span class="property-type">number</span></dt>
240
+ <dd>Compression quality for JPEG and WebP formats (1-100). Only visible when jpg or webp format is selected. Default: 90.</dd>
241
+ <dt>Angle <span class="property-type">number|string</span></dt>
242
+ <dd>Rotation angle in degrees (clockwise). Can be a fixed number or dynamic value from msg property, flow, or global context. Supports decimal values.</dd>
243
+ <dt>Pad Color <span class="property-type">string</span></dt>
244
+ <dd>Color to fill areas created by rotation, specified as hexadecimal color (#RRGGBB). Default: #000000 (black).</dd>
245
+ </dl>
246
+
247
+ <h3>Inputs</h3>
248
+ <dl class="message-properties">
249
+ <dt>payload <span class="property-type">object | array</span></dt>
250
+ <dd>Single image object or array of image objects in standard format: <code>{ data: Buffer, width: number, height: number, channels: number, colorSpace: string, dtype: string }</code></dd>
251
+ </dl>
252
+
253
+ <h3>Outputs</h3>
254
+ <dl class="message-properties">
255
+ <dt>payload <span class="property-type">object | array | Buffer</span></dt>
256
+ <dd>Rotated image(s). Format depends on Output Format setting: raw image object(s) or encoded file buffer(s).</dd>
257
+ </dl>
258
+
259
+ <h3>Rotation Behavior</h3>
260
+ <ul>
261
+ <li><strong>Direction:</strong> Clockwise rotation (positive angles)</li>
262
+ <li><strong>Angle Range:</strong> Any angle supported (0-360° and beyond)</li>
263
+ <li><strong>Padding:</strong> Areas outside original bounds filled with specified color</li>
264
+ <li><strong>Precision:</strong> Decimal angles supported (e.g., 45.5°, 30.25°)</li>
265
+ <li><strong>Canvas Size:</strong> Output canvas automatically sized to contain rotated image</li>
266
+ </ul>
267
+
268
+ <h3>Examples</h3>
269
+ <ul>
270
+ <li><strong>90° Rotation:</strong> Angle: 90 → Image rotated 90° clockwise</li>
271
+ <li><strong>Custom Angle:</strong> Angle: 45.5 → Image rotated 45.5° clockwise</li>
272
+ <li><strong>Dynamic Angle:</strong> Angle: msg.rotationAngle → Use angle from message property</li>
273
+ <li><strong>White Padding:</strong> Pad Color: #FFFFFF → White background for rotated areas</li>
274
+ <li><strong>Transparent Padding:</strong> For RGBA images, use appropriate color with alpha channel</li>
275
+ </ul>
276
+
277
+ <h3>Node Interactions</h3>
278
+ <p><strong>Input Sources:</strong> Image-in, Array-out, other transform nodes</p>
279
+ <p><strong>Output Destinations:</strong> Other transform nodes, Mix nodes (concat, mosaic), Array-in for collections</p>
280
+ <p><strong>Common Workflows:</strong> Image correction, artistic effects, batch rotation for image alignment</p>
281
+
282
+ <h3>Output Formats</h3>
283
+ <ul>
284
+ <li><strong>Raw:</strong> Standard image object (fastest, for further processing)</li>
285
+ <li><strong>JPEG:</strong> Compressed file buffer with quality setting</li>
286
+ <li><strong>PNG:</strong> Lossless compressed file buffer</li>
287
+ <li><strong>WebP:</strong> Modern compressed format with quality setting</li>
288
+ </ul>
289
+
290
+ <h3>Color Format</h3>
291
+ <p>Pad color is specified as hexadecimal (#RRGGBB) and passed directly to the C++ engine. The color picker provides an easy way to select colors visually.</p>
292
+
293
+ <h3>Error Handling</h3>
294
+ <p>The node validates input data and angle values, displaying warnings for invalid inputs. Invalid angles default to 0°. Processing errors are logged and the message is not propagated.</p>
295
+
296
+ <h3>Performance</h3>
297
+ <p>Uses optimized C++ backend with OpenCV for high-performance rotation processing. Node status displays processing time. Array inputs are processed in parallel for optimal performance.</p>
298
+ </script>
299
+
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Node-RED logic for *rosepetal-rotate* — always padding, timing formatted.
3
+ */
4
+ const { performance } = require('perf_hooks');
5
+ const CppProcessor = require('../../lib/cpp-bridge.js');
6
+
7
+ module.exports = function (RED) {
8
+ const NodeUtils = require('../../lib/node-utils.js')(RED);
9
+
10
+ function RotateNode(config) {
11
+ RED.nodes.createNode(this, config);
12
+ const node = this;
13
+
14
+ node.on('input', async (msg, send, done) => {
15
+ try {
16
+ const t0 = performance.now();
17
+ node.status({}); // clear
18
+
19
+ const inputPath = config.inputPath || 'payload';
20
+ const outputPath = config.outputPath || 'payload';
21
+ const outputFormat = config.outputFormat || 'raw';
22
+ const outputQuality = parseInt(config.outputQuality) || 90;
23
+ const pngOptimize = config.pngOptimize || false;
24
+ const padColorHex = config.padColor || '#000000';
25
+
26
+ const originalPayload = RED.util.getMessageProperty(msg, inputPath);
27
+
28
+ // Validate input images with error passthrough
29
+ if (Array.isArray(originalPayload)) {
30
+ if (!NodeUtils.validateListImage(originalPayload, node)) {
31
+ return NodeUtils.handleValidationErrorWithPassthrough(
32
+ node, 'Invalid image list structure', msg, send, done,
33
+ { originalPayload, outputPath, outputType: 'preserve' }
34
+ );
35
+ }
36
+ } else {
37
+ if (!NodeUtils.validateSingleImage(originalPayload, node)) {
38
+ return NodeUtils.handleValidationErrorWithPassthrough(
39
+ node, 'Invalid image structure', msg, send, done,
40
+ { originalPayload, outputPath, outputType: 'preserve' }
41
+ );
42
+ }
43
+ }
44
+
45
+ const imgs = Array.isArray(originalPayload) ? originalPayload : [originalPayload];
46
+
47
+ /* ——— lanzar rotaciones en paralelo ——— */
48
+ const promises = imgs.map(img => {
49
+ let angle = NodeUtils.resolveDimension(
50
+ node, config.angleType, config.angleValue, msg);
51
+ angle = angle === null || angle === '' ? 0 : Number(angle);
52
+
53
+ return CppProcessor.rotate(img, angle, padColorHex, outputFormat, outputQuality, pngOptimize);
54
+ });
55
+
56
+ const results = await Promise.all(promises);
57
+
58
+ /* ——— acumular métricas ——— */
59
+ const { totalConvertMs, totalTaskMs, encodeMs, images } =
60
+ results.reduce((acc, { image, timing }) => {
61
+ acc.totalConvertMs += timing?.convertMs ?? 0;
62
+ acc.totalTaskMs += timing?.taskMs ?? 0;
63
+ acc.encodeMs += timing?.encodeMs ?? 0;
64
+ acc.images.push(image);
65
+ return acc;
66
+ }, { totalConvertMs: 0, totalTaskMs: 0, encodeMs: 0, images: [] });
67
+
68
+ const out = Array.isArray(originalPayload) ? images : images[0];
69
+ const durMs = performance.now() - t0;
70
+
71
+ RED.util.setMessageProperty(msg, outputPath, out);
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
+ // For arrays, show the first image as representative
87
+ const debugImage = Array.isArray(originalPayload) ? images[0] : images[0];
88
+ const debugResult = await NodeUtils.debugImageDisplay(
89
+ debugImage,
90
+ outputFormat,
91
+ outputQuality,
92
+ node,
93
+ true,
94
+ debugWidth
95
+ );
96
+
97
+ if (debugResult) {
98
+ debugFormat = debugResult.formatMessage;
99
+ // Update node status with debug info
100
+ NodeUtils.setSuccessStatusWithDebug(node, imgs.length, durMs, {
101
+ convertMs: totalConvertMs,
102
+ taskMs: totalTaskMs,
103
+ encodeMs: encodeMs
104
+ }, debugFormat + (Array.isArray(originalPayload) ? ' (first)' : ''));
105
+ }
106
+ } catch (debugError) {
107
+ node.warn(`Debug display error: ${debugError.message}`);
108
+ }
109
+ }
110
+
111
+ // Set regular status if debug not enabled or failed
112
+ if (!debugFormat) {
113
+ /* ——— mismo formato que en resize ——— */
114
+ node.status({
115
+ fill : 'green',
116
+ shape : 'dot',
117
+ text : `OK: ${imgs.length} img in ${durMs.toFixed(2)} ms `
118
+ + `(conv ${(totalConvertMs + encodeMs).toFixed(2)} ms `
119
+ + `| task ${totalTaskMs.toFixed(2)} ms)`
120
+ });
121
+ }
122
+
123
+ NodeUtils.recordPerformanceMetrics(node, msg, {
124
+ convertMs: totalConvertMs,
125
+ encodeMs: encodeMs,
126
+ taskMs: totalTaskMs
127
+ }, durMs);
128
+
129
+ send(msg);
130
+ done && done();
131
+ } catch (err) {
132
+ NodeUtils.handleNodeErrorWithPassthrough(
133
+ node, err, msg, send, done, 'rotate processing',
134
+ { originalPayload, outputPath, outputType: 'preserve' }
135
+ );
136
+ }
137
+ });
138
+ }
139
+
140
+ RED.nodes.registerType('rotate', RotateNode);
141
+ };