@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,552 @@
1
+ <!-- nodes/blend/blend.html -->
2
+
3
+ <script type="text/javascript">
4
+ RED.nodes.registerType('blend',{
5
+ category:'RP Image',
6
+ color:'#DDA0DD',
7
+ icon:'font-awesome/fa-adjust',
8
+ defaults:{
9
+ name:{value:""},
10
+ image1Path:{value:"payload.image1"}, image1PathType:{value:"msg"},
11
+ image2Path:{value:"payload.image2"}, image2PathType:{value:"msg"},
12
+ outputPath:{value:"payload"},outputPathType:{value:"msg"},
13
+ outputFormat:{value:"raw"},
14
+ outputQuality:{value:90},
15
+ pngOptimize:{value:false},
16
+ // Debug configuration
17
+ debugEnabled:{value:false},
18
+ debugWidth:{value:200},
19
+ debugWidthType:{value:"num"},
20
+ opacity:{value:50}, // 0-100%, default 50% (equal blend)
21
+ // Alpha compositing configuration
22
+ alphaCompositing:{value:false}, // Enable alpha compositing mode
23
+ removeBackground:{value:false}, // Enable background removal
24
+ backgroundColor:{value:"#ffffff"}, // Background color to remove
25
+ colorTolerance:{value:10} // Color tolerance 0-100%
26
+ },
27
+ inputs:1,outputs:1,
28
+ label:function(){return this.name||"blend";},
29
+ oneditprepare:function(){
30
+ /* path typedInputs */
31
+ $("#node-input-image1Path").typedInput({
32
+ default:'msg',types:['msg','flow','global'],
33
+ typeField:"#node-input-image1PathType"});
34
+ $("#node-input-image2Path").typedInput({
35
+ default:'msg',types:['msg','flow','global'],
36
+ typeField:"#node-input-image2PathType"});
37
+ $("#node-input-outputPath").typedInput({
38
+ default:'msg',types:['msg','flow','global'],
39
+ typeField:"#node-input-outputPathType"});
40
+
41
+ /* opacity slider functionality */
42
+ const $opacitySlider = $("#node-input-opacity");
43
+ const $opacityValue = $("#opacity-value");
44
+ const $opacityLabel = $("#opacity-label");
45
+
46
+ function updateOpacityDisplay() {
47
+ const value = parseInt($opacitySlider.val());
48
+ const isAlphaMode = $("#node-input-alphaCompositing").is(':checked');
49
+ $opacityValue.text(value + "%");
50
+
51
+ // Update label based on compositing mode
52
+ if (isAlphaMode) {
53
+ // Alpha compositing mode: Image 1 is base, Image 2 is overlay with opacity
54
+ if (value === 0) {
55
+ $opacityLabel.text("Base image only (overlay fully transparent)");
56
+ } else if (value === 100) {
57
+ $opacityLabel.text("Full overlay opacity on base");
58
+ } else {
59
+ $opacityLabel.text("Base + " + value + "% overlay opacity");
60
+ }
61
+ } else {
62
+ // Traditional blending mode
63
+ const img1Percent = value;
64
+ const img2Percent = 100 - value;
65
+
66
+ if (value === 0) {
67
+ $opacityLabel.text("0% Image 1, 100% Image 2");
68
+ } else if (value === 100) {
69
+ $opacityLabel.text("100% Image 1, 0% Image 2");
70
+ } else if (value === 50) {
71
+ $opacityLabel.text("50% each image");
72
+ } else {
73
+ $opacityLabel.text(img1Percent + "% Image 1, " + img2Percent + "% Image 2");
74
+ }
75
+ }
76
+ }
77
+
78
+ $opacitySlider.on("input", updateOpacityDisplay);
79
+ updateOpacityDisplay(); // initial state
80
+
81
+ // Alpha compositing mode toggle
82
+ const $alphaCheckbox = $("#node-input-alphaCompositing");
83
+ const $backgroundRemovalRow = $("#background-removal-row");
84
+ const $backgroundColorRow = $("#background-color-row");
85
+ const $toleranceRow = $("#tolerance-row");
86
+
87
+ function updateAlphaModeVisibility() {
88
+ const alphaEnabled = $alphaCheckbox.is(':checked');
89
+ $backgroundRemovalRow.toggle(alphaEnabled);
90
+
91
+ const bgRemovalEnabled = alphaEnabled && $("#node-input-removeBackground").is(':checked');
92
+ $backgroundColorRow.toggle(bgRemovalEnabled);
93
+ $toleranceRow.toggle(bgRemovalEnabled);
94
+
95
+ // Update opacity display when mode changes
96
+ updateOpacityDisplay();
97
+ }
98
+
99
+ $alphaCheckbox.on("change", updateAlphaModeVisibility);
100
+ $("#node-input-removeBackground").on("change", updateAlphaModeVisibility);
101
+ updateAlphaModeVisibility(); // initial state
102
+
103
+ // Color tolerance slider functionality
104
+ const $toleranceSlider = $("#node-input-colorTolerance");
105
+ const $toleranceValue = $("#tolerance-value");
106
+
107
+ function updateToleranceDisplay() {
108
+ const value = parseInt($toleranceSlider.val());
109
+ $toleranceValue.text(value + "%");
110
+ }
111
+
112
+ $toleranceSlider.on("input", updateToleranceDisplay);
113
+ updateToleranceDisplay(); // initial state
114
+
115
+ function updateQualityVisibility(){
116
+ const format = $("#node-input-outputFormat").val();
117
+ $("#quality-row").toggle(format === "jpg" || format === "webp");
118
+ $("#png-optimize-row").toggle(format === "png");
119
+ }
120
+ $("#node-input-outputFormat").on("change", updateQualityVisibility);
121
+ updateQualityVisibility(); // initial state
122
+
123
+ // === Debug Display Logic ===
124
+ const debugCheckbox = $('#node-input-debugEnabled');
125
+ const debugWidthRow = $('#debug-width-row');
126
+
127
+ // Initialize debug width TypedInput
128
+ $("#node-input-debugWidth").typedInput({
129
+ default: 'num',
130
+ types: ['num', 'msg', 'flow', 'global'],
131
+ typeField: "#node-input-debugWidthType"
132
+ });
133
+
134
+ // Function to toggle debug width visibility
135
+ function updateDebugWidthVisibility() {
136
+ if (debugCheckbox.is(':checked')) {
137
+ debugWidthRow.show();
138
+ } else {
139
+ debugWidthRow.hide();
140
+ }
141
+ }
142
+
143
+ // Initialize debug state on node open
144
+ updateDebugWidthVisibility();
145
+
146
+ // Handle debug checkbox changes
147
+ debugCheckbox.on('change', function() {
148
+ const enabled = this.checked;
149
+ updateDebugWidthVisibility();
150
+ // Store debug state for runtime access
151
+ $('#node-input-debugEnabled').data('debug-enabled', enabled);
152
+ });
153
+ }
154
+ });
155
+
156
+ // Debug image display renderer - shared across all image processing nodes
157
+ if (!window.debugImageRendererInitialized) {
158
+ window.debugImageRendererInitialized = true;
159
+
160
+ (function() {
161
+ var isSubscribed = false;
162
+
163
+ function subscribeToDebugImages() {
164
+ if (isSubscribed || typeof RED === 'undefined' || !RED.comms) return;
165
+ isSubscribed = true;
166
+
167
+ RED.comms.subscribe('debug-image', function(event, data) {
168
+ if (!data || !data.id) return;
169
+
170
+ try {
171
+ renderDebugImage(data);
172
+ } catch (err) {
173
+ console.warn('Debug image render error:', err);
174
+ }
175
+ });
176
+ }
177
+
178
+ function renderDebugImage(data) {
179
+ const nodeId = data.id;
180
+ const base64Data = data.data;
181
+ const format = data.format || 'unknown';
182
+ const mimeType = data.mimeType || 'jpeg';
183
+
184
+ if (!base64Data) {
185
+ removeDebugImage(nodeId);
186
+ return;
187
+ }
188
+
189
+ const nodeElement = document.getElementById(nodeId);
190
+ if (!nodeElement) return;
191
+
192
+ let debugContainer = document.getElementById('debug-img-container-' + nodeId);
193
+
194
+ if (!debugContainer) {
195
+ // Create SVG foreignObject to embed HTML content in SVG
196
+ debugContainer = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
197
+ debugContainer.id = 'debug-img-container-' + nodeId;
198
+ debugContainer.setAttribute('x', '70');
199
+ debugContainer.setAttribute('y', '5');
200
+ debugContainer.setAttribute('width', '120');
201
+ debugContainer.setAttribute('height', '120');
202
+ debugContainer.style.overflow = 'visible';
203
+
204
+ // Create simple image directly inside foreignObject
205
+ const img = document.createElement('img');
206
+ img.id = 'debug-img-' + nodeId;
207
+ img.style.width = '100%';
208
+ img.style.height = 'auto';
209
+ img.style.display = 'block';
210
+ img.style.cursor = 'pointer';
211
+ img.style.maxHeight = '100px';
212
+ img.style.maxWidth = '100px';
213
+
214
+ img.onclick = function() {
215
+ removeDebugImage(nodeId);
216
+ };
217
+
218
+ debugContainer.appendChild(img);
219
+ nodeElement.appendChild(debugContainer);
220
+ }
221
+
222
+ const img = document.getElementById('debug-img-' + nodeId);
223
+
224
+ if (img) {
225
+ img.src = `data:image/${mimeType};base64,${base64Data}`;
226
+ img.title = 'Debug image (click to hide)';
227
+ }
228
+ }
229
+
230
+ function removeDebugImage(nodeId) {
231
+ const debugContainer = document.getElementById('debug-img-container-' + nodeId);
232
+ if (debugContainer) {
233
+ debugContainer.remove();
234
+ }
235
+ }
236
+
237
+ function initializeWhenReady() {
238
+ if (typeof RED !== 'undefined' && RED.comms) {
239
+ subscribeToDebugImages();
240
+
241
+ // Clean up orphaned debug images periodically
242
+ setInterval(function() {
243
+ const debugContainers = document.querySelectorAll('[id^="debug-img-container-"]');
244
+ debugContainers.forEach(container => {
245
+ const nodeId = container.id.replace('debug-img-container-', '');
246
+ const nodeElement = document.getElementById(nodeId);
247
+ if (!nodeElement) {
248
+ container.remove();
249
+ }
250
+ });
251
+ }, 5000);
252
+ } else {
253
+ setTimeout(initializeWhenReady, 100);
254
+ }
255
+ }
256
+
257
+ if (document.readyState === 'loading') {
258
+ document.addEventListener('DOMContentLoaded', initializeWhenReady);
259
+ } else {
260
+ initializeWhenReady();
261
+ }
262
+ })();
263
+ }
264
+ </script>
265
+
266
+ <script type="text/x-red" data-template-name="blend">
267
+ <div class="form-row">
268
+ <label><i class="fa fa-picture-o"></i> Image 1</label>
269
+ <input type="text" id="node-input-image1Path" style="width:70%;">
270
+ <input type="hidden" id="node-input-image1PathType">
271
+ </div>
272
+
273
+ <div class="form-row">
274
+ <label><i class="fa fa-picture-o"></i> Image 2</label>
275
+ <input type="text" id="node-input-image2Path" style="width:70%;">
276
+ <input type="hidden" id="node-input-image2PathType">
277
+ </div>
278
+
279
+ <div class="form-row">
280
+ <label><i class="fa fa-sign-out"></i> Output</label>
281
+ <input type="text" id="node-input-outputPath" style="width:70%;">
282
+ <input type="hidden" id="node-input-outputPathType">
283
+ </div>
284
+
285
+ <div class="form-row">
286
+ <label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
287
+ <select id="node-input-outputFormat" style="width: 200px;">
288
+ <option value="raw">Raw (fastest)</option>
289
+ <option value="jpg">JPEG</option>
290
+ <option value="png">PNG</option>
291
+ <option value="webp">WebP</option>
292
+ </select>
293
+ </div>
294
+
295
+ <div class="form-row" id="quality-row">
296
+ <label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
297
+ <input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
298
+ <span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
299
+ </div>
300
+
301
+ <div class="form-row" id="png-optimize-row" style="display: none;">
302
+ <label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
303
+ <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
304
+ <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
305
+ </div>
306
+
307
+ <!-- Debug Configuration -->
308
+ <div class="form-row">
309
+ <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
310
+ <input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
311
+ <label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
312
+ </div>
313
+ <div class="form-row" id="debug-width-row" style="display: none;">
314
+ <label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
315
+ <input type="text" id="node-input-debugWidth" style="width: 120px;">
316
+ <input type="hidden" id="node-input-debugWidthType">
317
+ <span style="margin-left: 10px; color: #666;">pixels</span>
318
+ </div>
319
+
320
+ <hr/>
321
+
322
+ <!-- Alpha Compositing Mode -->
323
+ <div class="form-row">
324
+ <label for="node-input-alphaCompositing"><i class="fa fa-layers"></i> Alpha Compositing</label>
325
+ <input type="checkbox" id="node-input-alphaCompositing" style="display:inline-block; width:auto; vertical-align:baseline;">
326
+ <label for="node-input-alphaCompositing" style="width:auto; margin-left:5px;">Use Image 1 as base layer</label>
327
+ <div style="margin-top: 5px; font-size: 10px; color: #999;">
328
+ When enabled: Image 1 = base, Image 2 = overlay with proper transparency support
329
+ </div>
330
+ </div>
331
+
332
+ <!-- Background Removal (only visible when alpha compositing enabled) -->
333
+ <div class="form-row" id="background-removal-row" style="display: none;">
334
+ <label for="node-input-removeBackground"><i class="fa fa-eraser"></i> Background Removal</label>
335
+ <input type="checkbox" id="node-input-removeBackground" style="display:inline-block; width:auto; vertical-align:baseline;">
336
+ <label for="node-input-removeBackground" style="width:auto; margin-left:5px;">Remove background from overlay image</label>
337
+ </div>
338
+
339
+ <div class="form-row" id="background-color-row" style="display: none;">
340
+ <label for="node-input-backgroundColor"><i class="fa fa-eyedropper"></i> Background Color</label>
341
+ <input type="color" id="node-input-backgroundColor" value="#ffffff" style="width: 60px; height: 30px;">
342
+ <span style="margin-left: 10px; color: #666;">Color to remove from overlay image</span>
343
+ </div>
344
+
345
+ <div class="form-row" id="tolerance-row" style="display: none;">
346
+ <label for="node-input-colorTolerance"><i class="fa fa-crosshairs"></i> Color Tolerance</label>
347
+ <input type="range" id="node-input-colorTolerance" min="0" max="100" value="10" style="width: 200px;">
348
+ <span id="tolerance-value" style="margin-left: 10px; font-weight: bold;">10%</span>
349
+ <div style="margin-top: 5px; font-size: 10px; color: #999;">
350
+ 0% = Exact match | 50% = Moderate tolerance | 100% = Maximum tolerance
351
+ </div>
352
+ </div>
353
+
354
+ <div class="form-row">
355
+ <label for="node-input-opacity"><i class="fa fa-adjust"></i> Opacity</label>
356
+ <input type="range" id="node-input-opacity" min="0" max="100" value="50" style="width: 200px;">
357
+ <span id="opacity-value" style="margin-left: 10px; font-weight: bold;">50%</span>
358
+ <div style="margin-top: 5px; font-size: 11px; color: #666;" id="opacity-label">
359
+ 50% each image
360
+ </div>
361
+ <div style="margin-top: 5px; font-size: 10px; color: #999;" id="opacity-help">
362
+ Traditional: 0% = Image 2 only | 50% = Equal blend | 100% = Image 1 only<br/>
363
+ Alpha Compositing: 0% = Base only | 100% = Full overlay on base
364
+ </div>
365
+ </div>
366
+ </script>
367
+
368
+ <script type="text/x-red" data-help-name="blend">
369
+ <p><b>rosepetal-blend</b> combines two images using traditional blending or advanced alpha compositing with adjustable opacity. This node supports both mathematical blending and true layered compositing with transparency support and optional background removal.</p>
370
+
371
+ <h3>Details</h3>
372
+ <p>This node offers two distinct blending modes:</p>
373
+ <ul>
374
+ <li><b>Traditional Blending:</b> Mathematical mixing using OpenCV's <code>addWeighted</code> function</li>
375
+ <li><b>Alpha Compositing:</b> True layered compositing with transparency support, background removal, and proper alpha channel handling</li>
376
+ </ul>
377
+ <p>The opacity slider controls the contribution of each image to the final result. Images with different dimensions are automatically resized to match, and color space conversions are handled transparently. Alpha compositing mode enables proper PNG transparency handling and color-based background removal.</p>
378
+
379
+ <h3>Properties</h3>
380
+ <dl class="message-properties">
381
+ <dt>Image 1 <span class="property-type">string</span></dt>
382
+ <dd>Message property path containing the first input image. This image's contribution increases as opacity approaches 100%. Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
383
+
384
+ <dt>Image 2 <span class="property-type">string</span></dt>
385
+ <dd>Message property path containing the second input image. This image's contribution increases as opacity approaches 0%. Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
386
+
387
+ <dt>Output to <span class="property-type">string</span></dt>
388
+ <dd>Message property path where the blended image will be stored. Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
389
+
390
+ <dt>Output Format <span class="property-type">string</span></dt>
391
+ <dd>Format for the output image: <code>raw</code> (fastest), <code>jpg</code>, <code>png</code>, or <code>webp</code>.</dd>
392
+
393
+ <dt>Quality <span class="property-type">number</span></dt>
394
+ <dd>Compression quality (1-100) for JPEG and WebP formats. Only visible when JPG or WebP is selected.</dd>
395
+
396
+ <dt>Opacity <span class="property-type">number</span></dt>
397
+ <dd>Blend ratio from 0% to 100%. In traditional mode: controls mix ratio. In alpha compositing mode: controls overlay opacity on base image.</dd>
398
+
399
+ <dt>Alpha Compositing <span class="property-type">boolean</span></dt>
400
+ <dd>Enable alpha compositing mode where Image 1 becomes the base layer and Image 2 becomes the overlay with proper transparency support.</dd>
401
+
402
+ <dt>Background Removal <span class="property-type">boolean</span></dt>
403
+ <dd>Remove specified background color from the overlay image (Image 2) before compositing. Only available in alpha compositing mode.</dd>
404
+
405
+ <dt>Background Color <span class="property-type">color</span></dt>
406
+ <dd>Color to remove from the overlay image. Uses HSV color space matching with configurable tolerance.</dd>
407
+
408
+ <dt>Color Tolerance <span class="property-type">number</span></dt>
409
+ <dd>Tolerance for background color matching (0-100%). Higher values remove more similar colors.</dd>
410
+ </dl>
411
+
412
+ <h3>Inputs</h3>
413
+ <p>Requires two input images from the specified message property paths:</p>
414
+ <ul>
415
+ <li><b>Image 1:</b> From the path specified in "Image 1" field (default: <code>msg.payload.image1</code>)</li>
416
+ <li><b>Image 2:</b> From the path specified in "Image 2" field (default: <code>msg.payload.image2</code>)</li>
417
+ </ul>
418
+
419
+ <p>Each image should follow the standard format:</p>
420
+ <pre>{
421
+ data: Buffer, // Raw pixel data or encoded file buffer
422
+ width: number, // Image width in pixels
423
+ height: number, // Image height in pixels
424
+ channels: number, // Channel count (1=grayscale, 3=RGB, 4=RGBA)
425
+ colorSpace: string, // "GRAY", "RGB", "RGBA", "BGR", "BGRA"
426
+ dtype: string // "uint8", "uint16", "float32"
427
+ }</pre>
428
+ <p>File buffers (JPEG, PNG, WebP, BMP) are automatically detected and decoded.</p>
429
+
430
+ <h3>Outputs</h3>
431
+ <p>Produces a single blended image in the specified format:</p>
432
+ <ul>
433
+ <li><b>Raw format:</b> Complete image object with pixel data and metadata</li>
434
+ <li><b>Encoded formats (JPG/PNG/WebP):</b> File buffer ready for storage or transmission</li>
435
+ </ul>
436
+ <p>Output dimensions match the larger of the two input images. Smaller images are automatically resized to prevent dimension mismatches.</p>
437
+
438
+ <h3>Blending Behavior</h3>
439
+
440
+ <h4>Traditional Blending Mode</h4>
441
+ <p>Mathematical mixing using OpenCV's <code>addWeighted</code> function:</p>
442
+ <ul>
443
+ <li><b>0%:</b> 100% Image 2, 0% Image 1</li>
444
+ <li><b>50%:</b> Equal contribution from both images</li>
445
+ <li><b>100%:</b> 100% Image 1, 0% Image 2</li>
446
+ </ul>
447
+ <pre>result = image1 × (opacity/100) + image2 × (1 - opacity/100)</pre>
448
+
449
+ <h4>Alpha Compositing Mode</h4>
450
+ <p>True layered compositing with transparency support:</p>
451
+ <ul>
452
+ <li><b>0%:</b> Base image only (overlay fully transparent)</li>
453
+ <li><b>50%:</b> Base image with 50% opacity overlay</li>
454
+ <li><b>100%:</b> Base image with full opacity overlay</li>
455
+ </ul>
456
+ <pre>result = overlay × (overlay_alpha × opacity) + base × (1 - overlay_alpha × opacity)</pre>
457
+
458
+ <h4>Background Removal Process</h4>
459
+ <p>When background removal is enabled in alpha compositing mode:</p>
460
+ <ol>
461
+ <li>Convert overlay image to HSV color space</li>
462
+ <li>Calculate color distance from target background color</li>
463
+ <li>Create alpha mask where matching pixels become transparent</li>
464
+ <li>Apply Gaussian blur for smooth edges</li>
465
+ <li>Perform alpha compositing with transparency</li>
466
+ </ol>
467
+
468
+ <h3>Automatic Image Processing</h3>
469
+ <h4>Dimension Handling</h4>
470
+ <ul>
471
+ <li><b>Same Size:</b> Direct blending with no resizing</li>
472
+ <li><b>Different Sizes:</b> Smaller image is resized to match the larger one using high-quality interpolation</li>
473
+ <li><b>Aspect Ratio:</b> Preserved during resize operations to prevent distortion</li>
474
+ </ul>
475
+
476
+ <h4>Color Space Conversion</h4>
477
+ <ul>
478
+ <li><b>Automatic Detection:</b> Color spaces are detected from image metadata or inferred from channel count</li>
479
+ <li><b>Smart Conversion:</b> Images are converted to a common format for blending (RGBA > BGRA > RGB > BGR > GRAY priority)</li>
480
+ <li><b>Quality Preservation:</b> Lossless conversions maintain image quality throughout the process</li>
481
+ </ul>
482
+
483
+ <h3>Examples</h3>
484
+ <h4>Photo Double Exposure</h4>
485
+ <p>Create artistic double exposure effects:</p>
486
+ <ul>
487
+ <li>Input: Portrait + landscape images</li>
488
+ <li>Opacity: 60-80% for subtle overlay</li>
489
+ <li>Output: PNG for transparency support</li>
490
+ </ul>
491
+
492
+ <h4>Background Replacement</h4>
493
+ <p>Blend foreground object with new background:</p>
494
+ <ul>
495
+ <li>Image 1: Foreground with transparency</li>
496
+ <li>Image 2: New background</li>
497
+ <li>Opacity: 90-100% to preserve foreground</li>
498
+ </ul>
499
+
500
+ <h4>Watermark Application</h4>
501
+ <p>Add semi-transparent watermarks:</p>
502
+ <ul>
503
+ <li>Image 1: Main content</li>
504
+ <li>Image 2: Watermark/logo</li>
505
+ <li>Opacity: 80-95% for subtle branding</li>
506
+ </ul>
507
+
508
+ <h4>Transition Effects</h4>
509
+ <p>Create smooth transitions between images:</p>
510
+ <ul>
511
+ <li>Use with flow control to animate opacity</li>
512
+ <li>Multiple blend nodes for complex transitions</li>
513
+ <li>Real-time adjustment via message properties</li>
514
+ </ul>
515
+
516
+ <h3>Node Interactions</h3>
517
+ <ul>
518
+ <li><b>Upstream:</b> Works with <code>image-in</code>, <code>array-in</code>, or any nodes producing image pairs</li>
519
+ <li><b>Downstream:</b> Connect to image writers, further processing nodes, or display components</li>
520
+ <li><b>Chaining:</b> Can be chained for complex multi-layer compositions</li>
521
+ <li><b>Flow Integration:</b> Supports flow and global context for cross-node data sharing</li>
522
+ </ul>
523
+
524
+
525
+ <h3>Error Handling</h3>
526
+ <ul>
527
+ <li><b>Missing Images:</b> Clear warnings when either input image is missing or invalid</li>
528
+ <li><b>Dimension Mismatch:</b> Automatic resizing with performance-optimized interpolation</li>
529
+ <li><b>Color Space Issues:</b> Intelligent conversion with format preservation</li>
530
+ <li><b>Memory Management:</b> Efficient processing of large images with automatic cleanup</li>
531
+ <li><b>Format Compatibility:</b> Graceful handling of different input formats and encodings</li>
532
+ </ul>
533
+
534
+ <h3>Performance</h3>
535
+ <ul>
536
+ <li><b>C++ Backend:</b> High-performance OpenCV implementation with SIMD optimizations</li>
537
+ <li><b>Memory Efficient:</b> Minimal memory allocation with intelligent buffer reuse</li>
538
+ <li><b>Parallel Processing:</b> Multi-threaded operations for large images</li>
539
+ <li><b>Status Timing:</b> Real-time metrics showing conversion, processing, and encoding times</li>
540
+ <li><b>Zero-Copy Operations:</b> Efficient data transfer between JavaScript and C++ layers</li>
541
+ <li><b>Optimized Builds:</b> Compiled with <code>-O3</code>, <code>-march=native</code> for maximum performance</li>
542
+ </ul>
543
+
544
+ <h3>Advanced Features</h3>
545
+ <ul>
546
+ <li><b>Live Preview:</b> Debug mode shows blended result in real-time</li>
547
+ <li><b>Opacity Animation:</b> Programmatic control for animated blending effects</li>
548
+ <li><b>Batch Processing:</b> Efficient handling of multiple image pairs</li>
549
+ <li><b>Context Integration:</b> Full support for flow and global context storage</li>
550
+ <li><b>Format Flexibility:</b> Seamless conversion between raw and encoded formats</li>
551
+ </ul>
552
+ </script>