@rosepetal/node-red-contrib-image-tools 1.2.2 → 1.3.0

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 (43) hide show
  1. package/.github/workflows/build-prebuild.yml +3 -0
  2. package/install.sh +8 -0
  3. package/node-red-contrib-image-tools/lib/node-utils.js +64 -0
  4. package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +242 -3
  5. package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +10 -3
  6. package/node-red-contrib-image-tools/nodes/blend/add-mask.html +282 -4
  7. package/node-red-contrib-image-tools/nodes/blend/add-mask.js +15 -8
  8. package/node-red-contrib-image-tools/nodes/blend/add-masks.html +206 -3
  9. package/node-red-contrib-image-tools/nodes/blend/add-masks.js +10 -3
  10. package/node-red-contrib-image-tools/nodes/blend/blend.html +332 -4
  11. package/node-red-contrib-image-tools/nodes/blend/blend.js +10 -3
  12. package/node-red-contrib-image-tools/nodes/io/folder-in.html +147 -3
  13. package/node-red-contrib-image-tools/nodes/io/folder-in.js +2 -1
  14. package/node-red-contrib-image-tools/nodes/io/image-in.html +81 -2
  15. package/node-red-contrib-image-tools/nodes/io/image-in.js +2 -1
  16. package/node-red-contrib-image-tools/nodes/io/image-out.html +197 -3
  17. package/node-red-contrib-image-tools/nodes/io/image-out.js +2 -1
  18. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +398 -3
  19. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +11 -4
  20. package/node-red-contrib-image-tools/nodes/mix/concat.html +245 -5
  21. package/node-red-contrib-image-tools/nodes/mix/concat.js +10 -3
  22. package/node-red-contrib-image-tools/nodes/mix/mosaic.html +307 -3
  23. package/node-red-contrib-image-tools/nodes/mix/mosaic.js +10 -3
  24. package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +217 -4
  25. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +11 -2
  26. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +285 -4
  27. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +9 -2
  28. package/node-red-contrib-image-tools/nodes/transform/color-convert.html +169 -6
  29. package/node-red-contrib-image-tools/nodes/transform/color-convert.js +11 -2
  30. package/node-red-contrib-image-tools/nodes/transform/crop.html +237 -5
  31. package/node-red-contrib-image-tools/nodes/transform/crop.js +11 -2
  32. package/node-red-contrib-image-tools/nodes/transform/draw.html +152 -3
  33. package/node-red-contrib-image-tools/nodes/transform/draw.js +10 -3
  34. package/node-red-contrib-image-tools/nodes/transform/filter.html +369 -4
  35. package/node-red-contrib-image-tools/nodes/transform/filter.js +11 -2
  36. package/node-red-contrib-image-tools/nodes/transform/padding.html +316 -5
  37. package/node-red-contrib-image-tools/nodes/transform/padding.js +11 -2
  38. package/node-red-contrib-image-tools/nodes/transform/resize.html +203 -5
  39. package/node-red-contrib-image-tools/nodes/transform/resize.js +11 -2
  40. package/node-red-contrib-image-tools/nodes/transform/rotate.html +164 -5
  41. package/node-red-contrib-image-tools/nodes/transform/rotate.js +11 -2
  42. package/package.json +71 -71
  43. package/scripts/dual-register.js +267 -0
@@ -283,6 +283,8 @@ module.exports = function (RED) {
283
283
  const outputFormat = config.outputFormat || 'raw';
284
284
  const outputQuality = parseInt(config.outputQuality) || 90;
285
285
  const pngOptimize = config.pngOptimize || false;
286
+ const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
287
+ const cppFormat = useSharpWebp ? 'raw' : outputFormat;
286
288
 
287
289
  // Build class color map and priority order from configuration
288
290
  const classColorMap = {};
@@ -298,7 +300,7 @@ module.exports = function (RED) {
298
300
  }
299
301
 
300
302
  /* ▸ Single call to the C++ addon --------------------------------- */
301
- const { image: result, timing = {} } =
303
+ let { image: result, timing = {} } =
302
304
  await Cpp.addMasks(
303
305
  baseImg,
304
306
  masksArray,
@@ -306,11 +308,15 @@ module.exports = function (RED) {
306
308
  classPriorityOrder, // Priority order for overlap resolution
307
309
  maskStrength,
308
310
  true, // Always auto-generate colors for undefined classes
309
- outputFormat,
311
+ cppFormat,
310
312
  outputQuality,
311
313
  pngOptimize
312
314
  );
313
315
 
316
+ if (useSharpWebp) {
317
+ result = await NodeUtils.encodeWebpAdvanced(result, config);
318
+ }
319
+
314
320
  /* ▸ Write the result back to msg ---------------------------------- */
315
321
  RED.util.setMessageProperty(msg, config.outputPath || 'payload', result);
316
322
 
@@ -373,5 +379,6 @@ module.exports = function (RED) {
373
379
  });
374
380
  }
375
381
 
376
- RED.nodes.registerType('add-masks', AddMasksNode);
382
+ RED.nodes.registerType('rp-add-masks', AddMasksNode);
383
+ RED.nodes.registerType('add-masks', AddMasksNode); // legacy compat
377
384
  };
@@ -1,7 +1,7 @@
1
1
  <!-- nodes/blend/blend.html -->
2
2
 
3
3
  <script type="text/javascript">
4
- RED.nodes.registerType('blend',{
4
+ var _rpNodeCfg = {
5
5
  category:'RP Image',
6
6
  color:'#DDA0DD',
7
7
  icon:'font-awesome/fa-adjust',
@@ -13,6 +13,9 @@
13
13
  outputFormat:{value:"raw"},
14
14
  outputQuality:{value:90},
15
15
  pngOptimize:{value:false},
16
+ webpLossless:{value:false},
17
+ webpSmartSubsample:{value:false},
18
+ webpEffort:{value:""},
16
19
  // Debug configuration
17
20
  debugEnabled:{value:false},
18
21
  debugWidth:{value:200},
@@ -25,7 +28,7 @@
25
28
  colorTolerance:{value:10} // Color tolerance 0-100%
26
29
  },
27
30
  inputs:1,outputs:1,
28
- label:function(){return this.name||"blend";},
31
+ label:function(){return this.name||"rp-blend";},
29
32
  oneditprepare:function(){
30
33
  /* path typedInputs */
31
34
  $("#node-input-image1Path").typedInput({
@@ -116,6 +119,11 @@
116
119
  const format = $("#node-input-outputFormat").val();
117
120
  $("#quality-row").toggle(format === "jpg" || format === "webp");
118
121
  $("#png-optimize-row").toggle(format === "png");
122
+ // Show WebP advanced options only when WebP is selected
123
+ const isWebp = format === 'webp';
124
+ $("#webp-lossless-row").toggle(isWebp);
125
+ $("#webp-smartsubsample-row").toggle(isWebp);
126
+ $("#webp-effort-row").toggle(isWebp);
119
127
  }
120
128
  $("#node-input-outputFormat").on("change", updateQualityVisibility);
121
129
  updateQualityVisibility(); // initial state
@@ -151,7 +159,9 @@
151
159
  $('#node-input-debugEnabled').data('debug-enabled', enabled);
152
160
  });
153
161
  }
154
- });
162
+ };
163
+ RED.nodes.registerType('rp-blend', _rpNodeCfg);
164
+ RED.nodes.registerType('blend', Object.assign({}, _rpNodeCfg, { category: 'deprecated' }));
155
165
 
156
166
  // Debug image display renderer - shared across all image processing nodes
157
167
  if (!window.debugImageRendererInitialized) {
@@ -263,7 +273,7 @@
263
273
  }
264
274
  </script>
265
275
 
266
- <script type="text/x-red" data-template-name="blend">
276
+ <script type="text/x-red" data-template-name="rp-blend">
267
277
  <div class="form-row">
268
278
  <label><i class="fa fa-picture-o"></i> Image 1</label>
269
279
  <input type="text" id="node-input-image1Path" style="width:70%;">
@@ -303,7 +313,139 @@
303
313
  <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
304
314
  <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
305
315
  </div>
316
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
317
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
318
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
319
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
320
+ </div>
321
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
322
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
323
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
324
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
325
+ </div>
326
+ <div class="form-row" id="webp-effort-row" style="display: none;">
327
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
328
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
329
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
330
+ </div>
331
+
332
+ <!-- Debug Configuration -->
333
+ <div class="form-row">
334
+ <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
335
+ <input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
336
+ <label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
337
+ </div>
338
+ <div class="form-row" id="debug-width-row" style="display: none;">
339
+ <label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
340
+ <input type="text" id="node-input-debugWidth" style="width: 120px;">
341
+ <input type="hidden" id="node-input-debugWidthType">
342
+ <span style="margin-left: 10px; color: #666;">pixels</span>
343
+ </div>
344
+
345
+ <hr/>
346
+
347
+ <!-- Alpha Compositing Mode -->
348
+ <div class="form-row">
349
+ <label for="node-input-alphaCompositing"><i class="fa fa-layers"></i> Alpha Compositing</label>
350
+ <input type="checkbox" id="node-input-alphaCompositing" style="display:inline-block; width:auto; vertical-align:baseline;">
351
+ <label for="node-input-alphaCompositing" style="width:auto; margin-left:5px;">Use Image 1 as base layer</label>
352
+ <div style="margin-top: 5px; font-size: 10px; color: #999;">
353
+ When enabled: Image 1 = base, Image 2 = overlay with proper transparency support
354
+ </div>
355
+ </div>
356
+
357
+ <!-- Background Removal (only visible when alpha compositing enabled) -->
358
+ <div class="form-row" id="background-removal-row" style="display: none;">
359
+ <label for="node-input-removeBackground"><i class="fa fa-eraser"></i> Background Removal</label>
360
+ <input type="checkbox" id="node-input-removeBackground" style="display:inline-block; width:auto; vertical-align:baseline;">
361
+ <label for="node-input-removeBackground" style="width:auto; margin-left:5px;">Remove background from overlay image</label>
362
+ </div>
363
+
364
+ <div class="form-row" id="background-color-row" style="display: none;">
365
+ <label for="node-input-backgroundColor"><i class="fa fa-eyedropper"></i> Background Color</label>
366
+ <input type="color" id="node-input-backgroundColor" value="#ffffff" style="width: 60px; height: 30px;">
367
+ <span style="margin-left: 10px; color: #666;">Color to remove from overlay image</span>
368
+ </div>
369
+
370
+ <div class="form-row" id="tolerance-row" style="display: none;">
371
+ <label for="node-input-colorTolerance"><i class="fa fa-crosshairs"></i> Color Tolerance</label>
372
+ <input type="range" id="node-input-colorTolerance" min="0" max="100" value="10" style="width: 200px;">
373
+ <span id="tolerance-value" style="margin-left: 10px; font-weight: bold;">10%</span>
374
+ <div style="margin-top: 5px; font-size: 10px; color: #999;">
375
+ 0% = Exact match | 50% = Moderate tolerance | 100% = Maximum tolerance
376
+ </div>
377
+ </div>
378
+
379
+ <div class="form-row">
380
+ <label for="node-input-opacity"><i class="fa fa-adjust"></i> Opacity</label>
381
+ <input type="range" id="node-input-opacity" min="0" max="100" value="50" style="width: 200px;">
382
+ <span id="opacity-value" style="margin-left: 10px; font-weight: bold;">50%</span>
383
+ <div style="margin-top: 5px; font-size: 11px; color: #666;" id="opacity-label">
384
+ 50% each image
385
+ </div>
386
+ <div style="margin-top: 5px; font-size: 10px; color: #999;" id="opacity-help">
387
+ Traditional: 0% = Image 2 only | 50% = Equal blend | 100% = Image 1 only<br/>
388
+ Alpha Compositing: 0% = Base only | 100% = Full overlay on base
389
+ </div>
390
+ </div>
391
+ </script>
392
+
393
+ <script type="text/x-red" data-template-name="blend">
394
+ <div class="form-row">
395
+ <label><i class="fa fa-picture-o"></i> Image 1</label>
396
+ <input type="text" id="node-input-image1Path" style="width:70%;">
397
+ <input type="hidden" id="node-input-image1PathType">
398
+ </div>
306
399
 
400
+ <div class="form-row">
401
+ <label><i class="fa fa-picture-o"></i> Image 2</label>
402
+ <input type="text" id="node-input-image2Path" style="width:70%;">
403
+ <input type="hidden" id="node-input-image2PathType">
404
+ </div>
405
+
406
+ <div class="form-row">
407
+ <label><i class="fa fa-sign-out"></i> Output</label>
408
+ <input type="text" id="node-input-outputPath" style="width:70%;">
409
+ <input type="hidden" id="node-input-outputPathType">
410
+ </div>
411
+
412
+ <div class="form-row">
413
+ <label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
414
+ <select id="node-input-outputFormat" style="width: 200px;">
415
+ <option value="raw">Raw (fastest)</option>
416
+ <option value="jpg">JPEG</option>
417
+ <option value="png">PNG</option>
418
+ <option value="webp">WebP</option>
419
+ </select>
420
+ </div>
421
+
422
+ <div class="form-row" id="quality-row">
423
+ <label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
424
+ <input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
425
+ <span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
426
+ </div>
427
+
428
+ <div class="form-row" id="png-optimize-row" style="display: none;">
429
+ <label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
430
+ <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
431
+ <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
432
+ </div>
433
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
434
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
435
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
436
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
437
+ </div>
438
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
439
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
440
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
441
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
442
+ </div>
443
+ <div class="form-row" id="webp-effort-row" style="display: none;">
444
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
445
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
446
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
447
+ </div>
448
+
307
449
  <!-- Debug Configuration -->
308
450
  <div class="form-row">
309
451
  <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
@@ -365,6 +507,192 @@
365
507
  </div>
366
508
  </script>
367
509
 
510
+ <script type="text/x-red" data-help-name="rp-blend">
511
+ <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>
512
+
513
+ <h3>Details</h3>
514
+ <p>This node offers two distinct blending modes:</p>
515
+ <ul>
516
+ <li><b>Traditional Blending:</b> Mathematical mixing using OpenCV's <code>addWeighted</code> function</li>
517
+ <li><b>Alpha Compositing:</b> True layered compositing with transparency support, background removal, and proper alpha channel handling</li>
518
+ </ul>
519
+ <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>
520
+
521
+ <h3>Properties</h3>
522
+ <dl class="message-properties">
523
+ <dt>Image 1 <span class="property-type">string</span></dt>
524
+ <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>
525
+
526
+ <dt>Image 2 <span class="property-type">string</span></dt>
527
+ <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>
528
+
529
+ <dt>Output to <span class="property-type">string</span></dt>
530
+ <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>
531
+
532
+ <dt>Output Format <span class="property-type">string</span></dt>
533
+ <dd>Format for the output image: <code>raw</code> (fastest), <code>jpg</code>, <code>png</code>, or <code>webp</code>.</dd>
534
+
535
+ <dt>Quality <span class="property-type">number</span></dt>
536
+ <dd>Compression quality (1-100) for JPEG and WebP formats. Only visible when JPG or WebP is selected.</dd>
537
+
538
+ <dt>Opacity <span class="property-type">number</span></dt>
539
+ <dd>Blend ratio from 0% to 100%. In traditional mode: controls mix ratio. In alpha compositing mode: controls overlay opacity on base image.</dd>
540
+
541
+ <dt>Alpha Compositing <span class="property-type">boolean</span></dt>
542
+ <dd>Enable alpha compositing mode where Image 1 becomes the base layer and Image 2 becomes the overlay with proper transparency support.</dd>
543
+
544
+ <dt>Background Removal <span class="property-type">boolean</span></dt>
545
+ <dd>Remove specified background color from the overlay image (Image 2) before compositing. Only available in alpha compositing mode.</dd>
546
+
547
+ <dt>Background Color <span class="property-type">color</span></dt>
548
+ <dd>Color to remove from the overlay image. Uses HSV color space matching with configurable tolerance.</dd>
549
+
550
+ <dt>Color Tolerance <span class="property-type">number</span></dt>
551
+ <dd>Tolerance for background color matching (0-100%). Higher values remove more similar colors.</dd>
552
+ </dl>
553
+
554
+ <h3>Inputs</h3>
555
+ <p>Requires two input images from the specified message property paths:</p>
556
+ <ul>
557
+ <li><b>Image 1:</b> From the path specified in "Image 1" field (default: <code>msg.payload.image1</code>)</li>
558
+ <li><b>Image 2:</b> From the path specified in "Image 2" field (default: <code>msg.payload.image2</code>)</li>
559
+ </ul>
560
+
561
+ <p>Each image should follow the standard format:</p>
562
+ <pre>{
563
+ data: Buffer, // Raw pixel data or encoded file buffer
564
+ width: number, // Image width in pixels
565
+ height: number, // Image height in pixels
566
+ channels: number, // Channel count (1=grayscale, 3=RGB, 4=RGBA)
567
+ colorSpace: string, // "GRAY", "RGB", "RGBA", "BGR", "BGRA"
568
+ dtype: string // "uint8", "uint16", "float32"
569
+ }</pre>
570
+ <p>File buffers (JPEG, PNG, WebP, BMP) are automatically detected and decoded.</p>
571
+
572
+ <h3>Outputs</h3>
573
+ <p>Produces a single blended image in the specified format:</p>
574
+ <ul>
575
+ <li><b>Raw format:</b> Complete image object with pixel data and metadata</li>
576
+ <li><b>Encoded formats (JPG/PNG/WebP):</b> File buffer ready for storage or transmission</li>
577
+ </ul>
578
+ <p>Output dimensions match the larger of the two input images. Smaller images are automatically resized to prevent dimension mismatches.</p>
579
+
580
+ <h3>Blending Behavior</h3>
581
+
582
+ <h4>Traditional Blending Mode</h4>
583
+ <p>Mathematical mixing using OpenCV's <code>addWeighted</code> function:</p>
584
+ <ul>
585
+ <li><b>0%:</b> 100% Image 2, 0% Image 1</li>
586
+ <li><b>50%:</b> Equal contribution from both images</li>
587
+ <li><b>100%:</b> 100% Image 1, 0% Image 2</li>
588
+ </ul>
589
+ <pre>result = image1 × (opacity/100) + image2 × (1 - opacity/100)</pre>
590
+
591
+ <h4>Alpha Compositing Mode</h4>
592
+ <p>True layered compositing with transparency support:</p>
593
+ <ul>
594
+ <li><b>0%:</b> Base image only (overlay fully transparent)</li>
595
+ <li><b>50%:</b> Base image with 50% opacity overlay</li>
596
+ <li><b>100%:</b> Base image with full opacity overlay</li>
597
+ </ul>
598
+ <pre>result = overlay × (overlay_alpha × opacity) + base × (1 - overlay_alpha × opacity)</pre>
599
+
600
+ <h4>Background Removal Process</h4>
601
+ <p>When background removal is enabled in alpha compositing mode:</p>
602
+ <ol>
603
+ <li>Convert overlay image to HSV color space</li>
604
+ <li>Calculate color distance from target background color</li>
605
+ <li>Create alpha mask where matching pixels become transparent</li>
606
+ <li>Apply Gaussian blur for smooth edges</li>
607
+ <li>Perform alpha compositing with transparency</li>
608
+ </ol>
609
+
610
+ <h3>Automatic Image Processing</h3>
611
+ <h4>Dimension Handling</h4>
612
+ <ul>
613
+ <li><b>Same Size:</b> Direct blending with no resizing</li>
614
+ <li><b>Different Sizes:</b> Smaller image is resized to match the larger one using high-quality interpolation</li>
615
+ <li><b>Aspect Ratio:</b> Preserved during resize operations to prevent distortion</li>
616
+ </ul>
617
+
618
+ <h4>Color Space Conversion</h4>
619
+ <ul>
620
+ <li><b>Automatic Detection:</b> Color spaces are detected from image metadata or inferred from channel count</li>
621
+ <li><b>Smart Conversion:</b> Images are converted to a common format for blending (RGBA > BGRA > RGB > BGR > GRAY priority)</li>
622
+ <li><b>Quality Preservation:</b> Lossless conversions maintain image quality throughout the process</li>
623
+ </ul>
624
+
625
+ <h3>Examples</h3>
626
+ <h4>Photo Double Exposure</h4>
627
+ <p>Create artistic double exposure effects:</p>
628
+ <ul>
629
+ <li>Input: Portrait + landscape images</li>
630
+ <li>Opacity: 60-80% for subtle overlay</li>
631
+ <li>Output: PNG for transparency support</li>
632
+ </ul>
633
+
634
+ <h4>Background Replacement</h4>
635
+ <p>Blend foreground object with new background:</p>
636
+ <ul>
637
+ <li>Image 1: Foreground with transparency</li>
638
+ <li>Image 2: New background</li>
639
+ <li>Opacity: 90-100% to preserve foreground</li>
640
+ </ul>
641
+
642
+ <h4>Watermark Application</h4>
643
+ <p>Add semi-transparent watermarks:</p>
644
+ <ul>
645
+ <li>Image 1: Main content</li>
646
+ <li>Image 2: Watermark/logo</li>
647
+ <li>Opacity: 80-95% for subtle branding</li>
648
+ </ul>
649
+
650
+ <h4>Transition Effects</h4>
651
+ <p>Create smooth transitions between images:</p>
652
+ <ul>
653
+ <li>Use with flow control to animate opacity</li>
654
+ <li>Multiple blend nodes for complex transitions</li>
655
+ <li>Real-time adjustment via message properties</li>
656
+ </ul>
657
+
658
+ <h3>Node Interactions</h3>
659
+ <ul>
660
+ <li><b>Upstream:</b> Works with <code>image-in</code>, <code>array-in</code>, or any nodes producing image pairs</li>
661
+ <li><b>Downstream:</b> Connect to image writers, further processing nodes, or display components</li>
662
+ <li><b>Chaining:</b> Can be chained for complex multi-layer compositions</li>
663
+ <li><b>Flow Integration:</b> Supports flow and global context for cross-node data sharing</li>
664
+ </ul>
665
+
666
+
667
+ <h3>Error Handling</h3>
668
+ <ul>
669
+ <li><b>Missing Images:</b> Clear warnings when either input image is missing or invalid</li>
670
+ <li><b>Dimension Mismatch:</b> Automatic resizing with performance-optimized interpolation</li>
671
+ <li><b>Color Space Issues:</b> Intelligent conversion with format preservation</li>
672
+ <li><b>Memory Management:</b> Efficient processing of large images with automatic cleanup</li>
673
+ <li><b>Format Compatibility:</b> Graceful handling of different input formats and encodings</li>
674
+ </ul>
675
+
676
+ <h3>Performance</h3>
677
+ <ul>
678
+ <li><b>C++ Backend:</b> High-performance OpenCV implementation with SIMD optimizations</li>
679
+ <li><b>Memory Efficient:</b> Minimal memory allocation with intelligent buffer reuse</li>
680
+ <li><b>Parallel Processing:</b> Multi-threaded operations for large images</li>
681
+ <li><b>Status Timing:</b> Real-time metrics showing conversion, processing, and encoding times</li>
682
+ <li><b>Zero-Copy Operations:</b> Efficient data transfer between JavaScript and C++ layers</li>
683
+ <li><b>Optimized Builds:</b> Compiled with <code>-O3</code>, <code>-march=native</code> for maximum performance</li>
684
+ </ul>
685
+
686
+ <h3>Advanced Features</h3>
687
+ <ul>
688
+ <li><b>Live Preview:</b> Debug mode shows blended result in real-time</li>
689
+ <li><b>Opacity Animation:</b> Programmatic control for animated blending effects</li>
690
+ <li><b>Batch Processing:</b> Efficient handling of multiple image pairs</li>
691
+ <li><b>Context Integration:</b> Full support for flow and global context storage</li>
692
+ <li><b>Format Flexibility:</b> Seamless conversion between raw and encoded formats</li>
693
+ </ul>
694
+ </script>
695
+
368
696
  <script type="text/x-red" data-help-name="blend">
369
697
  <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
698
 
@@ -102,16 +102,22 @@ module.exports = function (RED) {
102
102
  const outputFormat = config.outputFormat || 'raw';
103
103
  const outputQuality = parseInt(config.outputQuality) || 90;
104
104
  const pngOptimize = config.pngOptimize || false;
105
+ const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
106
+ const cppFormat = useSharpWebp ? 'raw' : outputFormat;
105
107
  const alphaCompositing = config.alphaCompositing || false;
106
108
  const removeBackground = config.removeBackground || false;
107
109
  const backgroundColor = config.backgroundColor || '#ffffff';
108
110
  const colorTolerance = Math.max(0, Math.min(100, parseInt(config.colorTolerance) || 10)) / 100.0;
109
111
 
110
112
  /* ▸ Single call to the C++ addon --------------------------------- */
111
- const { image, timing = {} } =
112
- await Cpp.blend(img1, img2, opacity, outputFormat, outputQuality, pngOptimize,
113
+ let { image, timing = {} } =
114
+ await Cpp.blend(img1, img2, opacity, cppFormat, outputQuality, pngOptimize,
113
115
  alphaCompositing, removeBackground, backgroundColor, colorTolerance);
114
116
 
117
+ if (useSharpWebp) {
118
+ image = await NodeUtils.encodeWebpAdvanced(image, config);
119
+ }
120
+
115
121
  /* ▸ Write the result back to msg ---------------------------------- */
116
122
  RED.util.setMessageProperty(msg, config.outputPath || 'payload', image);
117
123
 
@@ -174,5 +180,6 @@ module.exports = function (RED) {
174
180
  });
175
181
  }
176
182
 
177
- RED.nodes.registerType('blend', BlendNode);
183
+ RED.nodes.registerType('rp-blend', BlendNode);
184
+ RED.nodes.registerType('blend', BlendNode); // legacy compat
178
185
  };
@@ -1,5 +1,5 @@
1
1
  <script type="text/javascript">
2
- RED.nodes.registerType('folder-in', {
2
+ var _rpNodeCfg = {
3
3
  category: 'RP Image',
4
4
  color: '#A6C8A6',
5
5
  defaults: {
@@ -25,7 +25,7 @@
25
25
  },
26
26
  onclick: function() {
27
27
  const node = this;
28
- const label = this.name || "folder-in";
28
+ const label = this.name || "rp-folder-in";
29
29
 
30
30
  $.ajax({
31
31
  url: "folder-in/" + this.id,
@@ -102,7 +102,58 @@
102
102
  // Initialize visibility
103
103
  updateDebugWidthVisibility();
104
104
  }
105
- });
105
+ };
106
+ RED.nodes.registerType('rp-folder-in', _rpNodeCfg);
107
+ RED.nodes.registerType('folder-in', Object.assign({}, _rpNodeCfg, { category: 'deprecated' }));
108
+ </script>
109
+
110
+ <script type="text/x-red" data-template-name="rp-folder-in">
111
+ <div class="form-row">
112
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
113
+ <input type="text" id="node-input-name" placeholder="Name">
114
+ </div>
115
+
116
+ <div class="form-row">
117
+ <label for="node-input-folderPath"><i class="fa fa-folder-open"></i> Folder Path</label>
118
+ <input type="text" id="node-input-folderPath" style="width: 70%;" placeholder="/path/to/image/folder">
119
+ <input type="hidden" id="node-input-folderPathType">
120
+ </div>
121
+
122
+ <hr>
123
+
124
+ <div class="form-row">
125
+ <label for="node-input-interval"><i class="fa fa-clock-o"></i> Interval (ms)</label>
126
+ <input type="text" id="node-input-interval" style="width: 120px;">
127
+ <input type="hidden" id="node-input-intervalType">
128
+ </div>
129
+
130
+ <div class="form-row">
131
+ <label for="node-input-mode"><i class="fa fa-repeat"></i> Mode</label>
132
+ <select id="node-input-mode" style="width: 200px;">
133
+ <option value="loop">Loop (repeat images)</option>
134
+ <option value="one-shot">One-shot (stop at end)</option>
135
+ </select>
136
+ </div>
137
+
138
+ <hr>
139
+
140
+ <div class="form-row">
141
+ <label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output to</label>
142
+ <input type="text" id="node-input-outputPath" style="width: 70%;">
143
+ <input type="hidden" id="node-input-outputPathType">
144
+ </div>
145
+
146
+ <!-- Debug Configuration -->
147
+ <div class="form-row">
148
+ <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
149
+ <input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
150
+ <label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show loaded images</label>
151
+ </div>
152
+ <div class="form-row" id="debug-width-row" style="display: none;">
153
+ <label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
154
+ <input type="text" id="node-input-debugWidth" style="width: 120px;">
155
+ <input type="hidden" id="node-input-debugWidthType">
156
+ </div>
106
157
  </script>
107
158
 
108
159
  <script type="text/x-red" data-template-name="folder-in">
@@ -154,6 +205,99 @@
154
205
  </div>
155
206
  </script>
156
207
 
208
+ <script type="text/x-red" data-help-name="rp-folder-in">
209
+ <p>Scans a folder for image files and emits them one by one at configurable intervals. Features a toggle button to start/stop emission.</p>
210
+
211
+ <h3>Details</h3>
212
+ <p>This node reads all image files from a specified folder and emits them sequentially at a configurable rate. It can operate in two modes: loop (continuously repeat images) or one-shot (stop after all images). The node features a physical button on the left side (like the inject node) to start and stop the emission process.</p>
213
+
214
+ <p><strong>Supported Image Formats:</strong> JPEG, PNG, WebP, BMP, GIF, TIFF</p>
215
+
216
+ <h3>Properties</h3>
217
+ <dl class="message-properties">
218
+ <dt>Folder Path <span class="property-type">string | msg | flow | global</span></dt>
219
+ <dd>The path to the folder containing image files. Can be a static string (absolute or relative path) or dynamically resolved from message properties, flow context, or global context. The node will scan this folder and find all supported image files.</dd>
220
+
221
+ <dt>Interval (ms) <span class="property-type">number</span></dt>
222
+ <dd>The time interval in milliseconds between each image emission. For example, 1000 = 1 second between images. Minimum recommended: 100ms.</dd>
223
+
224
+ <dt>Mode <span class="property-type">loop | one-shot</span></dt>
225
+ <dd>
226
+ <ul>
227
+ <li><strong>Loop:</strong> After emitting the last image, restart from the first image and continue indefinitely until stopped.</li>
228
+ <li><strong>One-shot:</strong> Stop automatically after emitting all images once.</li>
229
+ </ul>
230
+ </dd>
231
+
232
+ <dt>Output to <span class="property-type">msg | flow | global</span></dt>
233
+ <dd>The location where the resulting image object will be stored. Defaults to <code>msg.payload</code>.</dd>
234
+
235
+ <dt>Debug <span class="property-type">boolean</span></dt>
236
+ <dd>Enable inline image preview display for debugging purposes.</dd>
237
+ </dl>
238
+
239
+ <h3>Button Control</h3>
240
+ <p>Click the button on the left side of the node to toggle between running and stopped states:</p>
241
+ <ul>
242
+ <li><strong>Stopped (grey):</strong> No images are being emitted. Click to start.</li>
243
+ <li><strong>Running (green):</strong> Images are being emitted at the configured interval. Click to stop.</li>
244
+ </ul>
245
+ <p><strong>Note:</strong> This node does not have an input connector. It operates independently using only the button control.</p>
246
+
247
+ <h3>Outputs</h3>
248
+ <p>The node sets the property specified in 'Output to' with the processed image object using the standard format:</p>
249
+ <pre>{
250
+ data: Buffer, // Raw pixel data
251
+ width: number, // Image width in pixels
252
+ height: number, // Image height in pixels
253
+ channels: number, // Channel count (1, 3, 4)
254
+ colorSpace: string, // "GRAY", "RGB", "RGBA"
255
+ dtype: string // "uint8"
256
+ }</pre>
257
+
258
+ <p>Additionally, each message includes metadata in <code>msg._folderIn</code>:</p>
259
+ <pre>{
260
+ fileName: string, // Name of the current image file
261
+ filePath: string, // Full path to the current image file
262
+ index: number, // Current image index (0-based)
263
+ total: number // Total number of images in folder
264
+ }</pre>
265
+
266
+ <h3>Examples</h3>
267
+ <ul>
268
+ <li><strong>Slideshow:</strong> Set folder to <code>/images/slideshow</code>, interval to 2000ms (2 seconds), mode to "loop" for continuous slideshow</li>
269
+ <li><strong>Batch Processing:</strong> Set mode to "one-shot" and connect to processing nodes to automatically process all images in a folder</li>
270
+ <li><strong>Animation Preview:</strong> Set interval to 100ms to quickly preview a sequence of images</li>
271
+ <li><strong>Dataset Loading:</strong> Use "one-shot" mode to load a complete dataset for AI/ML processing</li>
272
+ </ul>
273
+
274
+ <h3>Status Display</h3>
275
+ <p>The node displays its current state and progress:</p>
276
+ <ul>
277
+ <li><strong>Stopped:</strong> Node is not emitting images</li>
278
+ <li><strong>Scanning folder:</strong> Reading directory contents</li>
279
+ <li><strong>Loading [filename]:</strong> Currently loading an image</li>
280
+ <li><strong>[n/total]: [filename]:</strong> Successfully emitted image n of total</li>
281
+ <li><strong>Completed all images:</strong> One-shot mode finished</li>
282
+ <li><strong>Error:</strong> Error occurred during operation</li>
283
+ </ul>
284
+
285
+ <h3>Error Handling</h3>
286
+ <p>If the folder path is invalid, contains no images, or an image cannot be read, the node will display a warning in the debug panel and update its status accordingly.</p>
287
+
288
+ <h3>Performance</h3>
289
+ <p>Image loading is performed asynchronously using Sharp for optimal performance. Each image is loaded on demand, so memory usage remains low even with large folders.</p>
290
+
291
+ <h3>Tips</h3>
292
+ <ul>
293
+ <li>Use relative paths for portability across systems</li>
294
+ <li>Images are emitted in alphabetical order by filename</li>
295
+ <li>Connect to transform nodes (resize, crop, etc.) for automated batch processing</li>
296
+ <li>Use the metadata in <code>msg._folderIn</code> to track progress or create custom workflows</li>
297
+ <li>Adjust interval based on your processing pipeline speed to avoid message queue buildup</li>
298
+ </ul>
299
+ </script>
300
+
157
301
  <script type="text/x-red" data-help-name="folder-in">
158
302
  <p>Scans a folder for image files and emits them one by one at configurable intervals. Features a toggle button to start/stop emission.</p>
159
303
 
@@ -342,5 +342,6 @@ module.exports = function(RED) {
342
342
  node.status({ fill: "grey", shape: "ring", text: "Stopped" });
343
343
  }
344
344
 
345
- RED.nodes.registerType("folder-in", FolderInNode);
345
+ RED.nodes.registerType("rp-folder-in", FolderInNode);
346
+ RED.nodes.registerType("folder-in", FolderInNode); // legacy compat
346
347
  };