@rosepetal/node-red-contrib-image-tools 1.6.4 → 1.8.1

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 (70) hide show
  1. package/.claude/rules/node-implementation-template.md +1 -1
  2. package/.github/workflows/build-prebuild.yml +1 -1
  3. package/README.md +41 -21
  4. package/docs/index.md +156 -0
  5. package/docs/nodes/blend/add-bbs.md +116 -0
  6. package/docs/nodes/blend/add-mask.md +67 -224
  7. package/docs/nodes/blend/add-masks.md +74 -196
  8. package/docs/nodes/blend/blend.md +84 -200
  9. package/docs/nodes/io/folder-in.md +92 -0
  10. package/docs/nodes/io/image-in.md +61 -52
  11. package/docs/nodes/io/image-out.md +114 -93
  12. package/docs/nodes/mix/advanced-mosaic.md +124 -78
  13. package/docs/nodes/mix/concat.md +71 -56
  14. package/docs/nodes/mix/mosaic.md +81 -91
  15. package/docs/nodes/specialized/cropBB.md +76 -214
  16. package/docs/nodes/specialized/heat-diff.md +111 -0
  17. package/docs/nodes/specialized/image-align.md +125 -387
  18. package/docs/nodes/transform/color-convert.md +101 -0
  19. package/docs/nodes/transform/crop.md +56 -58
  20. package/docs/nodes/transform/draw.md +46 -26
  21. package/docs/nodes/transform/filter.md +110 -46
  22. package/docs/nodes/transform/padding.md +55 -55
  23. package/docs/nodes/transform/resize.md +81 -56
  24. package/docs/nodes/transform/rotate.md +67 -50
  25. package/node-red-contrib-image-tools/lib/bmp-decode.js +18 -68
  26. package/node-red-contrib-image-tools/lib/cpp-bridge.js +202 -104
  27. package/node-red-contrib-image-tools/lib/node-utils.js +78 -78
  28. package/node-red-contrib-image-tools/nodes/io/folder-in.js +98 -46
  29. package/node-red-contrib-image-tools/nodes/io/image-in.js +3 -4
  30. package/node-red-contrib-image-tools/nodes/io/image-out.js +93 -146
  31. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +3 -3
  32. package/node-red-contrib-image-tools/nodes/specialized/heat-diff.js +3 -3
  33. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +11 -4
  34. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +5 -4
  35. package/node-red-contrib-image-tools/nodes/transform/color-convert.js +3 -3
  36. package/node-red-contrib-image-tools/nodes/transform/crop.js +3 -3
  37. package/node-red-contrib-image-tools/nodes/transform/filter.js +3 -3
  38. package/node-red-contrib-image-tools/nodes/transform/padding.js +3 -3
  39. package/node-red-contrib-image-tools/nodes/transform/resize.js +3 -3
  40. package/node-red-contrib-image-tools/nodes/transform/rotate.js +3 -3
  41. package/npm/darwin-arm64/package.json +1 -1
  42. package/npm/darwin-x64/package.json +1 -1
  43. package/npm/linux-arm64/package.json +1 -1
  44. package/npm/linux-x64/package.json +1 -1
  45. package/npm/linuxmusl-x64/package.json +1 -1
  46. package/npm/win32-x64/package.json +1 -1
  47. package/package.json +6 -6
  48. package/rosepetal-image-engine/binding.gyp +2 -1
  49. package/rosepetal-image-engine/src/add-bbs.cpp +123 -123
  50. package/rosepetal-image-engine/src/add-mask.cpp +30 -15
  51. package/rosepetal-image-engine/src/add-masks.cpp +145 -102
  52. package/rosepetal-image-engine/src/advanced-mosaic.cpp +200 -129
  53. package/rosepetal-image-engine/src/blend.cpp +34 -20
  54. package/rosepetal-image-engine/src/codec.cpp +157 -0
  55. package/rosepetal-image-engine/src/color-convert.cpp +22 -19
  56. package/rosepetal-image-engine/src/concat.cpp +38 -43
  57. package/rosepetal-image-engine/src/crop.cpp +23 -26
  58. package/rosepetal-image-engine/src/draw.cpp +33 -10
  59. package/rosepetal-image-engine/src/filter.cpp +22 -26
  60. package/rosepetal-image-engine/src/heat-diff.cpp +35 -8
  61. package/rosepetal-image-engine/src/image-align.cpp +107 -35
  62. package/rosepetal-image-engine/src/main.cpp +4 -0
  63. package/rosepetal-image-engine/src/mosaic.cpp +31 -40
  64. package/rosepetal-image-engine/src/padding.cpp +30 -29
  65. package/rosepetal-image-engine/src/resize.cpp +20 -25
  66. package/rosepetal-image-engine/src/rotate.cpp +22 -23
  67. package/rosepetal-image-engine/src/utils.h +243 -144
  68. package/scripts/build-opencv-static.sh +6 -0
  69. package/scripts/dual-register.js +32 -25
  70. package/scripts/sync-version.js +58 -41
@@ -12,30 +12,84 @@ try {
12
12
  }
13
13
  const fs = require('fs').promises;
14
14
  const path = require('path');
15
+ const Cpp = require('../../lib/cpp-bridge.js');
15
16
 
16
17
  module.exports = function(RED) {
17
18
  const NodeUtils = require('../../lib/node-utils.js')(RED);
18
19
 
20
+ // Per-folder cache: file name → mtimeMs. Our own writes and unlinks keep it
21
+ // exact; a full readdir is only repeated every DIR_RESYNC_MS to pick up
22
+ // changes made by other processes.
19
23
  const dirCache = new Map();
24
+ const dirSyncedAt = new Map();
25
+ const dirScanInFlight = new Map();
26
+ const DIR_RESYNC_MS = 5000;
27
+ const STAT_CONCURRENCY = 32; // keep the libuv thread pool free for image work
28
+
29
+ // Concurrency-limited async map (results keep input order).
30
+ async function mapLimit(items, limit, fn) {
31
+ const results = new Array(items.length);
32
+ let next = 0;
33
+ async function worker() {
34
+ while (next < items.length) {
35
+ const i = next++;
36
+ results[i] = await fn(items[i], i);
37
+ }
38
+ }
39
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
40
+ return results;
41
+ }
42
+
43
+ async function statNames(folderPath, names) {
44
+ const stats = await mapLimit(names, STAT_CONCURRENCY, async (name) => {
45
+ try {
46
+ const st = await fs.stat(path.join(folderPath, name));
47
+ return { name, mtimeMs: st.mtimeMs };
48
+ } catch {
49
+ return null; // vanished between readdir and stat
50
+ }
51
+ });
52
+ return stats.filter(Boolean);
53
+ }
54
+
55
+ // Reconciles the cache with the directory listing (adds unknown files with
56
+ // their mtime, drops files that no longer exist).
57
+ async function syncDirCache(folderPath, map) {
58
+ const entries = await fs.readdir(folderPath, { withFileTypes: true });
59
+ const diskFiles = new Set();
60
+ for (const e of entries) {
61
+ if (e.isFile()) diskFiles.add(e.name);
62
+ }
63
+ for (const name of map.keys()) {
64
+ if (!diskFiles.has(name)) map.delete(name);
65
+ }
66
+ const unknown = [];
67
+ for (const name of diskFiles) {
68
+ if (!map.has(name)) unknown.push(name);
69
+ }
70
+ if (unknown.length > 0) {
71
+ for (const { name, mtimeMs } of await statNames(folderPath, unknown)) map.set(name, mtimeMs);
72
+ }
73
+ dirSyncedAt.set(folderPath, Date.now());
74
+ }
20
75
 
21
76
  async function getCachedDir(folderPath) {
22
77
  if (dirCache.has(folderPath)) return dirCache.get(folderPath);
23
- const map = new Map();
24
- try {
25
- const entries = await fs.readdir(folderPath, { withFileTypes: true });
26
- const files = entries.filter(e => e.isFile());
27
- const stats = await Promise.all(
28
- files.map(async (f) => {
29
- const st = await fs.stat(path.join(folderPath, f.name));
30
- return { name: f.name, mtimeMs: st.mtimeMs };
31
- })
32
- );
33
- for (const { name, mtimeMs } of stats) map.set(name, mtimeMs);
34
- } catch {
35
- // folder doesn't exist yet — empty cache is fine
36
- }
37
- dirCache.set(folderPath, map);
38
- return map;
78
+ if (dirScanInFlight.has(folderPath)) return dirScanInFlight.get(folderPath);
79
+ const scan = (async () => {
80
+ const map = new Map();
81
+ try {
82
+ await syncDirCache(folderPath, map);
83
+ } catch {
84
+ // folder doesn't exist yet — empty cache is fine
85
+ dirSyncedAt.set(folderPath, Date.now());
86
+ }
87
+ dirCache.set(folderPath, map);
88
+ dirScanInFlight.delete(folderPath);
89
+ return map;
90
+ })();
91
+ dirScanInFlight.set(folderPath, scan);
92
+ return scan;
39
93
  }
40
94
 
41
95
  function ImageOutNode(config) {
@@ -100,32 +154,18 @@ module.exports = function(RED) {
100
154
  if (!validated) throw new Error("Invalid image structure");
101
155
 
102
156
  const colorSpace = validated.colorSpace;
103
- const channels = validated.channels;
104
- let data = validated.data;
105
157
 
106
- // BMP: encode raw pixels directly (no Sharp)
158
+ // BMP: encoded by the native engine on the thread pool (Sharp cannot write BMP)
107
159
  if (format === 'bmp') {
108
- let nativeData = data;
109
- if (colorSpace === 'RGB' || colorSpace === 'RGBA') {
110
- nativeData = Buffer.from(data);
111
- for (let i = 0; i < nativeData.length; i += channels) {
112
- const t = nativeData[i]; nativeData[i] = nativeData[i + 2]; nativeData[i + 2] = t;
113
- }
114
- }
115
- const buf = Buffer.isBuffer(nativeData) ? nativeData : Buffer.from(nativeData);
116
- return encodeBmpRaw(buf, validated.width, validated.height, channels);
160
+ const { image: bmp } = await Cpp.encode(validated, 'bmp');
161
+ return bmp;
117
162
  }
118
163
 
119
- // BGR/BGRA → RGB/RGBA for Sharp
120
- if (colorSpace === 'BGR' || colorSpace === 'BGRA') {
121
- data = Buffer.from(data);
122
- for (let i = 0; i < data.length; i += channels) {
123
- const t = data[i]; data[i] = data[i + 2]; data[i + 2] = t;
124
- }
125
- }
164
+ // BGR/BGRA → RGB/RGBA for Sharp (native, off the event loop)
165
+ const rgb = await NodeUtils.toSharpRaw(validated);
126
166
 
127
- const inst = sharp(data, {
128
- raw: { width: validated.width, height: validated.height, channels }
167
+ const inst = sharp(rgb.data, {
168
+ raw: { width: rgb.width, height: rgb.height, channels: rgb.channels }
129
169
  });
130
170
  if (colorSpace === 'GRAY') inst.toColourspace('b-w');
131
171
 
@@ -343,7 +383,7 @@ module.exports = function(RED) {
343
383
 
344
384
  if (maxImages > 0) {
345
385
  try {
346
- await enforceMaxImages(folderPath, maxImages, dirCache.get(folderPath));
386
+ await enforceMaxImages(folderPath, maxImages);
347
387
  } catch (policyErr) {
348
388
  node.warn(`Max images enforcement failed: ${policyErr.message}`);
349
389
  }
@@ -508,7 +548,7 @@ module.exports = function(RED) {
508
548
 
509
549
  if (maxImages > 0) {
510
550
  try {
511
- await enforceMaxImages(folderPath, maxImages, dirCache.get(folderPath));
551
+ await enforceMaxImages(folderPath, maxImages);
512
552
  } catch (policyErr) {
513
553
  node.warn(`Max images enforcement failed: ${policyErr.message}`);
514
554
  }
@@ -587,124 +627,31 @@ module.exports = function(RED) {
587
627
  }
588
628
  }
589
629
 
590
- async function enforceMaxImages(folderPath, maxCount, cachedMap) {
630
+ async function enforceMaxImages(folderPath, maxCount) {
591
631
  if (maxCount <= 0) return;
592
632
 
593
- const entries = await fs.readdir(folderPath, { withFileTypes: true });
594
- const diskFiles = new Set();
595
- for (const e of entries) {
596
- if (e.isFile()) diskFiles.add(e.name);
597
- }
598
- if (diskFiles.size <= maxCount) {
599
- if (cachedMap) {
600
- for (const name of cachedMap.keys()) {
601
- if (!diskFiles.has(name)) cachedMap.delete(name);
602
- }
603
- }
604
- return;
633
+ // The cache is authoritative for our own writes; re-list the directory
634
+ // only every DIR_RESYNC_MS (instead of on every message) to catch files
635
+ // added or removed by other processes.
636
+ const cachedMap = await getCachedDir(folderPath);
637
+ if (Date.now() - (dirSyncedAt.get(folderPath) || 0) >= DIR_RESYNC_MS) {
638
+ await syncDirCache(folderPath, cachedMap);
605
639
  }
606
640
 
607
- if (cachedMap) {
608
- for (const name of cachedMap.keys()) {
609
- if (!diskFiles.has(name)) cachedMap.delete(name);
610
- }
611
- const unknown = [];
612
- for (const name of diskFiles) {
613
- if (!cachedMap.has(name)) unknown.push(name);
614
- }
615
- if (unknown.length > 0) {
616
- const stats = await Promise.all(
617
- unknown.map(async (name) => {
618
- const st = await fs.stat(path.join(folderPath, name));
619
- return { name, mtimeMs: st.mtimeMs };
620
- })
621
- );
622
- for (const { name, mtimeMs } of stats) cachedMap.set(name, mtimeMs);
623
- }
624
- }
641
+ if (cachedMap.size <= maxCount) return;
625
642
 
626
- let sorted;
627
- if (cachedMap && cachedMap.size > 0) {
628
- sorted = Array.from(cachedMap.entries()).map(([name, mtimeMs]) => ({ name, mtimeMs }));
629
- } else {
630
- sorted = await Promise.all(
631
- Array.from(diskFiles).map(async (name) => {
632
- const st = await fs.stat(path.join(folderPath, name));
633
- return { name, mtimeMs: st.mtimeMs };
634
- })
635
- );
636
- }
643
+ const sorted = Array.from(cachedMap, ([name, mtimeMs]) => ({ name, mtimeMs }));
637
644
  sorted.sort((a, b) => a.mtimeMs - b.mtimeMs);
638
645
 
639
- const toRemove = sorted.length - maxCount;
640
- for (let i = 0; i < toRemove; i++) {
646
+ const toRemove = sorted.slice(0, sorted.length - maxCount);
647
+ await mapLimit(toRemove, STAT_CONCURRENCY, async ({ name }) => {
641
648
  try {
642
- await fs.unlink(path.join(folderPath, sorted[i].name));
649
+ await fs.unlink(path.join(folderPath, name));
643
650
  } catch (err) {
644
651
  if (err.code !== 'ENOENT') throw err;
645
652
  }
646
- cachedMap?.delete(sorted[i].name);
647
- }
648
- }
649
-
650
- function encodeBmpRaw(pixelData, width, height, channels) {
651
- const bitsPerPixel = channels * 8;
652
- const rowBytes = width * channels;
653
- const rowPadding = (4 - (rowBytes % 4)) % 4;
654
- const paddedRowSize = rowBytes + rowPadding;
655
-
656
- const hasPalette = channels === 1;
657
- const paletteSize = hasPalette ? 256 * 4 : 0;
658
- const headerSize = 14;
659
- const infoHeaderSize = 40;
660
- const pixelDataOffset = headerSize + infoHeaderSize + paletteSize;
661
- const pixelDataSize = paddedRowSize * height;
662
- const fileSize = pixelDataOffset + pixelDataSize;
663
-
664
- const buf = Buffer.alloc(fileSize);
665
-
666
- // File header
667
- buf.write('BM', 0);
668
- buf.writeUInt32LE(fileSize, 2);
669
- buf.writeUInt32LE(0, 6); // reserved
670
- buf.writeUInt32LE(pixelDataOffset, 10);
671
-
672
- // Info header (BITMAPINFOHEADER)
673
- buf.writeUInt32LE(infoHeaderSize, 14);
674
- buf.writeInt32LE(width, 18);
675
- buf.writeInt32LE(height, 22); // positive = bottom-up
676
- buf.writeUInt16LE(1, 26); // planes
677
- buf.writeUInt16LE(bitsPerPixel, 28);
678
- buf.writeUInt32LE(0, 30); // compression (BI_RGB)
679
- buf.writeUInt32LE(pixelDataSize, 34);
680
- buf.writeInt32LE(2835, 38); // X pixels per meter (~72 DPI)
681
- buf.writeInt32LE(2835, 42); // Y pixels per meter
682
- buf.writeUInt32LE(hasPalette ? 256 : 0, 46);
683
- buf.writeUInt32LE(0, 50); // important colors
684
-
685
- // Grayscale palette
686
- if (hasPalette) {
687
- let offset = headerSize + infoHeaderSize;
688
- for (let i = 0; i < 256; i++) {
689
- buf[offset++] = i; // B
690
- buf[offset++] = i; // G
691
- buf[offset++] = i; // R
692
- buf[offset++] = 0; // reserved
693
- }
694
- }
695
-
696
- // Pixel data (bottom-up row order)
697
- const padBytes = Buffer.alloc(rowPadding);
698
- for (let y = height - 1; y >= 0; y--) {
699
- const srcOffset = y * rowBytes;
700
- const dstOffset = pixelDataOffset + (height - 1 - y) * paddedRowSize;
701
- pixelData.copy(buf, dstOffset, srcOffset, srcOffset + rowBytes);
702
- if (rowPadding > 0) {
703
- padBytes.copy(buf, dstOffset + rowBytes);
704
- }
705
- }
706
-
707
- return buf;
653
+ cachedMap.delete(name);
654
+ });
708
655
  }
709
656
 
710
657
  // Handle cleanup
@@ -190,9 +190,9 @@ module.exports = function (RED) {
190
190
  });
191
191
 
192
192
  if (useSharpWebp) {
193
- for (let i = 0; i < allCrops.length; i++) {
194
- allCrops[i] = await NodeUtils.encodeWebpAdvanced(allCrops[i], config);
195
- }
193
+ // Encode all images concurrently (Sharp runs on the libuv thread pool)
194
+ const webps = await Promise.all(allCrops.map((img) => NodeUtils.encodeWebpAdvanced(img, config)));
195
+ webps.forEach((webp, i) => { allCrops[i] = webp; });
196
196
  }
197
197
 
198
198
  /* Set output */
@@ -174,9 +174,9 @@ module.exports = function (RED) {
174
174
  const images = imageEnabled ? results.map(r => r.image) : [];
175
175
 
176
176
  if (useSharpWebp) {
177
- for (let i = 0; i < images.length; i++) {
178
- images[i] = await NodeUtils.encodeWebpAdvanced(images[i], config);
179
- }
177
+ // Encode all images concurrently (Sharp runs on the libuv thread pool)
178
+ const webps = await Promise.all(images.map((img) => NodeUtils.encodeWebpAdvanced(img, config)));
179
+ webps.forEach((webp, i) => { images[i] = webp; });
180
180
  }
181
181
 
182
182
  /* Write result — array in, array out; stats-only leaves the output path untouched */
@@ -217,14 +217,17 @@
217
217
  case 'features+ecc':
218
218
  description = 'ORB seeds an ECC refinement pass. Most accurate; recommended default.';
219
219
  break;
220
+ case 'shift':
221
+ description = 'Exhaustive translation search. For low-texture or line-scan images where features fail; always a pure shift.';
222
+ break;
220
223
  }
221
224
  $('#pipeline-description').text(description);
222
225
  // ECC Refine policy is only meaningful when ECC actually runs
223
226
  $('#ecc-refine-row').toggle(pipeline === 'features+ecc');
224
227
  $('#ecc-refine-description').toggle(pipeline === 'features+ecc');
225
228
  // Detector is only used by the feature-seed stage
226
- $('#detector-row').toggle(pipeline !== 'ecc');
227
- $('#detector-description').toggle(pipeline !== 'ecc');
229
+ $('#detector-row').toggle(pipeline === 'features' || pipeline === 'features+ecc');
230
+ $('#detector-description').toggle(pipeline === 'features' || pipeline === 'features+ecc');
228
231
  }
229
232
 
230
233
  $('#node-input-pipeline').on('change', updatePipelineDescription);
@@ -511,6 +514,7 @@
511
514
  <option value="ecc">ECC only (intensity)</option>
512
515
  <option value="features">Features only (ORB)</option>
513
516
  <option value="features+ecc">Features &rarr; ECC refine</option>
517
+ <option value="shift">Shift search (translation)</option>
514
518
  </select>
515
519
  </div>
516
520
  <div class="form-row">
@@ -702,6 +706,7 @@
702
706
  <option value="ecc">ECC only (intensity)</option>
703
707
  <option value="features">Features only (ORB)</option>
704
708
  <option value="features+ecc">Features &rarr; ECC refine</option>
709
+ <option value="shift">Shift search (translation)</option>
705
710
  </select>
706
711
  </div>
707
712
  <div class="form-row">
@@ -816,6 +821,7 @@
816
821
  <li><code>ecc</code> &mdash; intensity-based ECC only, identity init. Legacy behavior. Fast for small misalignments but diverges when golden and scan are far apart.</li>
817
822
  <li><code>features</code> &mdash; ORB+RANSAC feature matching only. Robust to large misalignments and rotation/scale; no sub-pixel refinement.</li>
818
823
  <li><code>features+ecc</code> &mdash; ORB result seeds an ECC refinement pass. Best accuracy. Recommended default for new nodes.</li>
824
+ <li><code>shift</code> &mdash; exhaustive translation search: the centre of the target slides over the reference within &plusmn;10&nbsp;% of the height and &plusmn;4&nbsp;% of the width (at least 150 / 60 px), after removing each column and line mean (line-scan column gains, lamp flicker). Always a pure translation, whatever <em>Motion Model</em> says; sub-pixel peak. Fails (no matrix) on a weak match or when the best shift sits on the window edge. For low-texture images or wood grain where feature points are scarce or ambiguous.</li>
819
825
  </ul>
820
826
  New nodes default to <code>features+ecc</code>; existing saved flows that lack this field fall back to <code>ecc</code> for full backward compatibility. If ECC diverges after a successful feature seed, the seed itself is returned (rather than failing the alignment).
821
827
  </dd>
@@ -862,7 +868,7 @@
862
868
  <li><code>success</code>: boolean indicating alignment success</li>
863
869
  <li><code>timing</code>: processing timing breakdown</li>
864
870
  <li><code>preset</code>: speed preset used</li>
865
- <li><code>pipeline</code>: pipeline used (<code>ecc</code>, <code>features</code>, or <code>features+ecc</code>)</li>
871
+ <li><code>pipeline</code>: pipeline used (<code>ecc</code>, <code>features</code>, <code>features+ecc</code>, or <code>shift</code>)</li>
866
872
  <li><code>eccRefine</code>: ECC refinement policy used (<code>always</code>, <code>auto</code>, or <code>never</code>)</li>
867
873
  <li><code>detector</code>: feature detector used (<code>orb</code> or <code>sift</code>)</li>
868
874
  <li><code>motionModel</code>: motion model used (<code>translation</code>, <code>euclidean</code>, <code>affine</code>, or <code>homography</code>)</li>
@@ -971,6 +977,7 @@ msg.payload = targetImageObject;</code></pre>
971
977
  <li><code>ecc</code> &mdash; intensity-based ECC only, identity init. Legacy behavior. Fast for small misalignments but diverges when golden and scan are far apart.</li>
972
978
  <li><code>features</code> &mdash; ORB+RANSAC feature matching only. Robust to large misalignments and rotation/scale; no sub-pixel refinement.</li>
973
979
  <li><code>features+ecc</code> &mdash; ORB result seeds an ECC refinement pass. Best accuracy. Recommended default for new nodes.</li>
980
+ <li><code>shift</code> &mdash; exhaustive translation search: the centre of the target slides over the reference within &plusmn;10&nbsp;% of the height and &plusmn;4&nbsp;% of the width (at least 150 / 60 px), after removing each column and line mean (line-scan column gains, lamp flicker). Always a pure translation, whatever <em>Motion Model</em> says; sub-pixel peak. Fails (no matrix) on a weak match or when the best shift sits on the window edge. For low-texture images or wood grain where feature points are scarce or ambiguous.</li>
974
981
  </ul>
975
982
  New nodes default to <code>features+ecc</code>; existing saved flows that lack this field fall back to <code>ecc</code> for full backward compatibility. If ECC diverges after a successful feature seed, the seed itself is returned (rather than failing the alignment).
976
983
  </dd>
@@ -1017,7 +1024,7 @@ msg.payload = targetImageObject;</code></pre>
1017
1024
  <li><code>success</code>: boolean indicating alignment success</li>
1018
1025
  <li><code>timing</code>: processing timing breakdown</li>
1019
1026
  <li><code>preset</code>: speed preset used</li>
1020
- <li><code>pipeline</code>: pipeline used (<code>ecc</code>, <code>features</code>, or <code>features+ecc</code>)</li>
1027
+ <li><code>pipeline</code>: pipeline used (<code>ecc</code>, <code>features</code>, <code>features+ecc</code>, or <code>shift</code>)</li>
1021
1028
  <li><code>eccRefine</code>: ECC refinement policy used (<code>always</code>, <code>auto</code>, or <code>never</code>)</li>
1022
1029
  <li><code>detector</code>: feature detector used (<code>orb</code> or <code>sift</code>)</li>
1023
1030
  <li><code>motionModel</code>: motion model used (<code>translation</code>, <code>euclidean</code>, <code>affine</code>, or <code>homography</code>)</li>
@@ -92,10 +92,11 @@ module.exports = function (RED) {
92
92
  // ecc - intensity-based ECC only (legacy default)
93
93
  // features - ORB+RANSAC only, no ECC refinement
94
94
  // features+ecc - ORB seed -> ECC refinement (best accuracy)
95
+ // shift - exhaustive translation search (low-texture / line-scan images)
95
96
  // Default 'ecc' for back-compat with flows saved before this field existed;
96
97
  // new nodes get 'features+ecc' via the HTML defaults block.
97
98
  const pipeline = config.pipeline || 'ecc';
98
- const VALID_PIPELINES = ['ecc', 'features', 'features+ecc'];
99
+ const VALID_PIPELINES = ['ecc', 'features', 'features+ecc', 'shift'];
99
100
  if (!VALID_PIPELINES.includes(pipeline)) {
100
101
  return NodeUtils.handleValidationErrorWithPassthrough(
101
102
  node,
@@ -389,9 +390,9 @@ module.exports = function (RED) {
389
390
  const images = results.map(r => r.image);
390
391
 
391
392
  if (useSharpWebp) {
392
- for (let i = 0; i < images.length; i++) {
393
- images[i] = await NodeUtils.encodeWebpAdvanced(images[i], config);
394
- }
393
+ // Encode all images concurrently (Sharp runs on the libuv thread pool)
394
+ const webps = await Promise.all(images.map((img) => NodeUtils.encodeWebpAdvanced(img, config)));
395
+ webps.forEach((webp, i) => { images[i] = webp; });
395
396
  }
396
397
 
397
398
  /* ▸ Status: standardized success formatting ----------------------- */
@@ -83,9 +83,9 @@ module.exports = function (RED) {
83
83
  }, { totalConvertMs: 0, totalTaskMs: 0, encodeMs: 0, images: [] });
84
84
 
85
85
  if (useSharpWebp) {
86
- for (let i = 0; i < images.length; i++) {
87
- images[i] = await NodeUtils.encodeWebpAdvanced(images[i], config);
88
- }
86
+ // Encode all images concurrently (Sharp runs on the libuv thread pool)
87
+ const webps = await Promise.all(images.map((img) => NodeUtils.encodeWebpAdvanced(img, config)));
88
+ webps.forEach((webp, i) => { images[i] = webp; });
89
89
  }
90
90
 
91
91
  const out = Array.isArray(originalPayload) ? images : images[0];
@@ -95,9 +95,9 @@ module.exports = function (RED) {
95
95
  }, { totalConvertMs: 0, totalTaskMs: 0, totalEncodeMs: 0, images: [] });
96
96
 
97
97
  if (useSharpWebp) {
98
- for (let i = 0; i < images.length; i++) {
99
- images[i] = await NodeUtils.encodeWebpAdvanced(images[i], config);
100
- }
98
+ // Encode all images concurrently (Sharp runs on the libuv thread pool)
99
+ const webps = await Promise.all(images.map((img) => NodeUtils.encodeWebpAdvanced(img, config)));
100
+ webps.forEach((webp, i) => { images[i] = webp; });
101
101
  }
102
102
 
103
103
  /* salida */
@@ -148,9 +148,9 @@ module.exports = function (RED) {
148
148
  );
149
149
 
150
150
  if (useSharpWebp) {
151
- for (let i = 0; i < images.length; i++) {
152
- images[i] = await NodeUtils.encodeWebpAdvanced(images[i], config);
153
- }
151
+ // Encode all images concurrently (Sharp runs on the libuv thread pool)
152
+ const webps = await Promise.all(images.map((img) => NodeUtils.encodeWebpAdvanced(img, config)));
153
+ webps.forEach((webp, i) => { images[i] = webp; });
154
154
  }
155
155
 
156
156
  // Prepare output
@@ -93,9 +93,9 @@ module.exports = function (RED) {
93
93
  });
94
94
 
95
95
  if (useSharpWebp) {
96
- for (let i = 0; i < outImgs.length; i++) {
97
- outImgs[i] = await NodeUtils.encodeWebpAdvanced(outImgs[i], cfg);
98
- }
96
+ // Encode all images concurrently (Sharp runs on the libuv thread pool)
97
+ const webps = await Promise.all(outImgs.map((img) => NodeUtils.encodeWebpAdvanced(img, cfg)));
98
+ webps.forEach((webp, i) => { outImgs[i] = webp; });
99
99
  }
100
100
 
101
101
  NodeUtils.setOutputValue(node, msg, outPath, outputPathType, Array.isArray(originalPayload) ? outImgs : outImgs[0]);
@@ -116,9 +116,9 @@ module.exports = function (RED) {
116
116
  );
117
117
 
118
118
  if (useSharpWebp) {
119
- for (let i = 0; i < images.length; i++) {
120
- images[i] = await NodeUtils.encodeWebpAdvanced(images[i], config);
121
- }
119
+ // Encode all images concurrently (Sharp runs on the libuv thread pool)
120
+ const webps = await Promise.all(images.map((img) => NodeUtils.encodeWebpAdvanced(img, config)));
121
+ webps.forEach((webp, i) => { images[i] = webp; });
122
122
  }
123
123
 
124
124
  const out = Array.isArray(originalPayload) ? images : images[0];
@@ -87,9 +87,9 @@ module.exports = function (RED) {
87
87
  }, { totalConvertMs: 0, totalTaskMs: 0, encodeMs: 0, images: [] });
88
88
 
89
89
  if (useSharpWebp) {
90
- for (let i = 0; i < images.length; i++) {
91
- images[i] = await NodeUtils.encodeWebpAdvanced(images[i], config);
92
- }
90
+ // Encode all images concurrently (Sharp runs on the libuv thread pool)
91
+ const webps = await Promise.all(images.map((img) => NodeUtils.encodeWebpAdvanced(img, config)));
92
+ webps.forEach((webp, i) => { images[i] = webp; });
93
93
  }
94
94
 
95
95
  const out = Array.isArray(originalPayload) ? images : images[0];
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-darwin-arm64",
3
- "version": "1.6.4",
3
+ "version": "1.8.1",
4
4
  "description": "Prebuilt native binary for macOS ARM64 (Apple Silicon)",
5
5
  "os": ["darwin"],
6
6
  "cpu": ["arm64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-darwin-x64",
3
- "version": "1.6.4",
3
+ "version": "1.8.1",
4
4
  "description": "Prebuilt native binary for macOS x64 (Intel)",
5
5
  "os": ["darwin"],
6
6
  "cpu": ["x64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-linux-arm64",
3
- "version": "1.6.4",
3
+ "version": "1.8.1",
4
4
  "description": "Prebuilt native binary for Linux ARM64 (glibc)",
5
5
  "os": ["linux"],
6
6
  "cpu": ["arm64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-linux-x64",
3
- "version": "1.6.4",
3
+ "version": "1.8.1",
4
4
  "description": "Prebuilt native binary for Linux x64 (glibc)",
5
5
  "os": ["linux"],
6
6
  "cpu": ["x64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools-linuxmusl-x64",
3
- "version": "1.6.4",
3
+ "version": "1.8.1",
4
4
  "description": "Prebuilt native binary for Linux x64 (musl/Alpine)",
5
5
  "os": ["linux"],
6
6
  "cpu": ["x64"],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/rosepetal-engine-win32-x64",
3
- "version": "1.6.4",
3
+ "version": "1.8.1",
4
4
  "description": "Prebuilt rosepetal-image-engine binary for Windows x64",
5
5
  "os": ["win32"],
6
6
  "cpu": ["x64"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools",
3
- "version": "1.6.4",
3
+ "version": "1.8.1",
4
4
  "description": "Node-RED Image Processing Toolkit",
5
5
  "main": "install.sh",
6
6
  "directories": {
@@ -36,11 +36,11 @@
36
36
  "sharp": "^0.34.2"
37
37
  },
38
38
  "optionalDependencies": {
39
- "@rosepetal/node-red-contrib-image-tools-linux-x64": "1.6.4",
40
- "@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.6.4",
41
- "@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.6.4",
42
- "@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.6.4",
43
- "@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.6.4"
39
+ "@rosepetal/node-red-contrib-image-tools-linux-x64": "1.8.1",
40
+ "@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.8.1",
41
+ "@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.8.1",
42
+ "@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.8.1",
43
+ "@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.8.1"
44
44
  },
45
45
  "node-red": {
46
46
  "version": ">=1.0.0",
@@ -23,7 +23,8 @@
23
23
  "src/image-align.cpp",
24
24
  "src/draw.cpp",
25
25
  "src/color-convert.cpp",
26
- "src/heat-diff.cpp"
26
+ "src/heat-diff.cpp",
27
+ "src/codec.cpp"
27
28
  ],
28
29
  "defines": [
29
30
  "NAPI_CPP_EXCEPTIONS"