@rosepetal/node-red-contrib-image-tools 1.6.3 → 1.7.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.
- package/.claude/rules/node-implementation-template.md +1 -1
- package/README.md +2 -0
- package/node-red-contrib-image-tools/lib/bmp-decode.js +18 -68
- package/node-red-contrib-image-tools/lib/cpp-bridge.js +202 -104
- package/node-red-contrib-image-tools/lib/node-utils.js +78 -78
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +11 -4
- package/node-red-contrib-image-tools/nodes/blend/add-mask.html +11 -4
- package/node-red-contrib-image-tools/nodes/blend/add-masks.html +11 -4
- package/node-red-contrib-image-tools/nodes/blend/blend.html +11 -4
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +98 -46
- package/node-red-contrib-image-tools/nodes/io/image-in.js +3 -4
- package/node-red-contrib-image-tools/nodes/io/image-out.html +11 -4
- package/node-red-contrib-image-tools/nodes/io/image-out.js +93 -146
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +11 -4
- package/node-red-contrib-image-tools/nodes/mix/concat.html +11 -4
- package/node-red-contrib-image-tools/nodes/mix/mosaic.html +11 -4
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +3 -3
- package/node-red-contrib-image-tools/nodes/specialized/heat-diff.js +3 -3
- package/node-red-contrib-image-tools/nodes/specialized/image-align.html +3 -2
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +3 -3
- package/node-red-contrib-image-tools/nodes/transform/color-convert.js +3 -3
- package/node-red-contrib-image-tools/nodes/transform/crop.html +11 -4
- package/node-red-contrib-image-tools/nodes/transform/crop.js +3 -3
- package/node-red-contrib-image-tools/nodes/transform/filter.html +11 -4
- package/node-red-contrib-image-tools/nodes/transform/filter.js +3 -3
- package/node-red-contrib-image-tools/nodes/transform/padding.html +11 -4
- package/node-red-contrib-image-tools/nodes/transform/padding.js +3 -3
- package/node-red-contrib-image-tools/nodes/transform/resize.html +3 -3
- package/node-red-contrib-image-tools/nodes/transform/resize.js +3 -3
- package/node-red-contrib-image-tools/nodes/transform/rotate.html +11 -4
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +3 -3
- package/npm/darwin-arm64/package.json +1 -1
- package/npm/darwin-x64/package.json +1 -1
- package/npm/linux-arm64/package.json +1 -1
- package/npm/linux-x64/package.json +1 -1
- package/npm/linuxmusl-x64/package.json +1 -1
- package/npm/win32-x64/package.json +1 -1
- package/package.json +6 -6
- package/rosepetal-image-engine/binding.gyp +2 -1
- package/rosepetal-image-engine/src/add-bbs.cpp +123 -123
- package/rosepetal-image-engine/src/add-mask.cpp +30 -15
- package/rosepetal-image-engine/src/add-masks.cpp +145 -102
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +200 -129
- package/rosepetal-image-engine/src/blend.cpp +34 -20
- package/rosepetal-image-engine/src/codec.cpp +157 -0
- package/rosepetal-image-engine/src/color-convert.cpp +22 -19
- package/rosepetal-image-engine/src/concat.cpp +38 -43
- package/rosepetal-image-engine/src/crop.cpp +23 -26
- package/rosepetal-image-engine/src/draw.cpp +33 -10
- package/rosepetal-image-engine/src/filter.cpp +22 -26
- package/rosepetal-image-engine/src/heat-diff.cpp +31 -8
- package/rosepetal-image-engine/src/image-align.cpp +36 -32
- package/rosepetal-image-engine/src/main.cpp +4 -0
- package/rosepetal-image-engine/src/mosaic.cpp +31 -40
- package/rosepetal-image-engine/src/padding.cpp +30 -29
- package/rosepetal-image-engine/src/resize.cpp +20 -25
- package/rosepetal-image-engine/src/rotate.cpp +22 -23
- package/rosepetal-image-engine/src/utils.h +243 -144
- package/scripts/dual-register.js +32 -25
- 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
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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:
|
|
158
|
+
// BMP: encoded by the native engine on the thread pool (Sharp cannot write BMP)
|
|
107
159
|
if (format === 'bmp') {
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
630
|
+
async function enforceMaxImages(folderPath, maxCount) {
|
|
591
631
|
if (maxCount <= 0) return;
|
|
592
632
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
649
|
+
await fs.unlink(path.join(folderPath, name));
|
|
643
650
|
} catch (err) {
|
|
644
651
|
if (err.code !== 'ENOENT') throw err;
|
|
645
652
|
}
|
|
646
|
-
cachedMap
|
|
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
|
|
@@ -1745,6 +1745,10 @@
|
|
|
1745
1745
|
|
|
1746
1746
|
const nodeElement = document.getElementById(nodeId);
|
|
1747
1747
|
if (!nodeElement) return;
|
|
1748
|
+
|
|
1749
|
+
// Size to the server-resized debug image (no display cap)
|
|
1750
|
+
var debugWidth = data.debugWidth || 200;
|
|
1751
|
+
var debugHeight = data.debugHeight || 200;
|
|
1748
1752
|
|
|
1749
1753
|
let debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
1750
1754
|
|
|
@@ -1754,8 +1758,8 @@
|
|
|
1754
1758
|
debugContainer.id = 'debug-img-container-' + nodeId;
|
|
1755
1759
|
debugContainer.setAttribute('x', '70');
|
|
1756
1760
|
debugContainer.setAttribute('y', '5');
|
|
1757
|
-
debugContainer.setAttribute('width',
|
|
1758
|
-
debugContainer.setAttribute('height',
|
|
1761
|
+
debugContainer.setAttribute('width', debugWidth.toString());
|
|
1762
|
+
debugContainer.setAttribute('height', debugHeight.toString());
|
|
1759
1763
|
debugContainer.style.overflow = 'visible';
|
|
1760
1764
|
|
|
1761
1765
|
// Create simple image directly inside foreignObject
|
|
@@ -1765,8 +1769,8 @@
|
|
|
1765
1769
|
img.style.height = 'auto';
|
|
1766
1770
|
img.style.display = 'block';
|
|
1767
1771
|
img.style.cursor = 'pointer';
|
|
1768
|
-
img.style.maxHeight = '
|
|
1769
|
-
img.style.maxWidth = '
|
|
1772
|
+
img.style.maxHeight = 'none';
|
|
1773
|
+
img.style.maxWidth = 'none';
|
|
1770
1774
|
|
|
1771
1775
|
img.onclick = function() {
|
|
1772
1776
|
removeDebugImage(nodeId);
|
|
@@ -1774,6 +1778,9 @@
|
|
|
1774
1778
|
|
|
1775
1779
|
debugContainer.appendChild(img);
|
|
1776
1780
|
nodeElement.appendChild(debugContainer);
|
|
1781
|
+
} else {
|
|
1782
|
+
debugContainer.setAttribute('width', debugWidth.toString());
|
|
1783
|
+
debugContainer.setAttribute('height', debugHeight.toString());
|
|
1777
1784
|
}
|
|
1778
1785
|
|
|
1779
1786
|
const img = document.getElementById('debug-img-' + nodeId);
|
|
@@ -143,6 +143,10 @@
|
|
|
143
143
|
|
|
144
144
|
const nodeElement = document.getElementById(nodeId);
|
|
145
145
|
if (!nodeElement) return;
|
|
146
|
+
|
|
147
|
+
// Size to the server-resized debug image (no display cap)
|
|
148
|
+
var debugWidth = data.debugWidth || 200;
|
|
149
|
+
var debugHeight = data.debugHeight || 200;
|
|
146
150
|
|
|
147
151
|
let debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
148
152
|
|
|
@@ -152,8 +156,8 @@
|
|
|
152
156
|
debugContainer.id = 'debug-img-container-' + nodeId;
|
|
153
157
|
debugContainer.setAttribute('x', '70');
|
|
154
158
|
debugContainer.setAttribute('y', '5');
|
|
155
|
-
debugContainer.setAttribute('width',
|
|
156
|
-
debugContainer.setAttribute('height',
|
|
159
|
+
debugContainer.setAttribute('width', debugWidth.toString());
|
|
160
|
+
debugContainer.setAttribute('height', debugHeight.toString());
|
|
157
161
|
debugContainer.style.overflow = 'visible';
|
|
158
162
|
|
|
159
163
|
// Create simple image directly inside foreignObject
|
|
@@ -163,8 +167,8 @@
|
|
|
163
167
|
img.style.height = 'auto';
|
|
164
168
|
img.style.display = 'block';
|
|
165
169
|
img.style.cursor = 'pointer';
|
|
166
|
-
img.style.maxHeight = '
|
|
167
|
-
img.style.maxWidth = '
|
|
170
|
+
img.style.maxHeight = 'none';
|
|
171
|
+
img.style.maxWidth = 'none';
|
|
168
172
|
|
|
169
173
|
img.onclick = function() {
|
|
170
174
|
removeDebugImage(nodeId);
|
|
@@ -172,6 +176,9 @@
|
|
|
172
176
|
|
|
173
177
|
debugContainer.appendChild(img);
|
|
174
178
|
nodeElement.appendChild(debugContainer);
|
|
179
|
+
} else {
|
|
180
|
+
debugContainer.setAttribute('width', debugWidth.toString());
|
|
181
|
+
debugContainer.setAttribute('height', debugHeight.toString());
|
|
175
182
|
}
|
|
176
183
|
|
|
177
184
|
const img = document.getElementById('debug-img-' + nodeId);
|
|
@@ -237,6 +237,10 @@
|
|
|
237
237
|
|
|
238
238
|
const nodeElement = document.getElementById(nodeId);
|
|
239
239
|
if (!nodeElement) return;
|
|
240
|
+
|
|
241
|
+
// Size to the server-resized debug image (no display cap)
|
|
242
|
+
var debugWidth = data.debugWidth || 200;
|
|
243
|
+
var debugHeight = data.debugHeight || 200;
|
|
240
244
|
|
|
241
245
|
let debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
242
246
|
|
|
@@ -246,8 +250,8 @@
|
|
|
246
250
|
debugContainer.id = 'debug-img-container-' + nodeId;
|
|
247
251
|
debugContainer.setAttribute('x', '70');
|
|
248
252
|
debugContainer.setAttribute('y', '5');
|
|
249
|
-
debugContainer.setAttribute('width',
|
|
250
|
-
debugContainer.setAttribute('height',
|
|
253
|
+
debugContainer.setAttribute('width', debugWidth.toString());
|
|
254
|
+
debugContainer.setAttribute('height', debugHeight.toString());
|
|
251
255
|
debugContainer.style.overflow = 'visible';
|
|
252
256
|
|
|
253
257
|
// Create simple image directly inside foreignObject
|
|
@@ -257,8 +261,8 @@
|
|
|
257
261
|
img.style.height = 'auto';
|
|
258
262
|
img.style.display = 'block';
|
|
259
263
|
img.style.cursor = 'pointer';
|
|
260
|
-
img.style.maxHeight = '
|
|
261
|
-
img.style.maxWidth = '
|
|
264
|
+
img.style.maxHeight = 'none';
|
|
265
|
+
img.style.maxWidth = 'none';
|
|
262
266
|
|
|
263
267
|
img.onclick = function() {
|
|
264
268
|
removeDebugImage(nodeId);
|
|
@@ -266,6 +270,9 @@
|
|
|
266
270
|
|
|
267
271
|
debugContainer.appendChild(img);
|
|
268
272
|
nodeElement.appendChild(debugContainer);
|
|
273
|
+
} else {
|
|
274
|
+
debugContainer.setAttribute('width', debugWidth.toString());
|
|
275
|
+
debugContainer.setAttribute('height', debugHeight.toString());
|
|
269
276
|
}
|
|
270
277
|
|
|
271
278
|
const img = document.getElementById('debug-img-' + nodeId);
|
|
@@ -190,9 +190,9 @@ module.exports = function (RED) {
|
|
|
190
190
|
});
|
|
191
191
|
|
|
192
192
|
if (useSharpWebp) {
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
178
|
-
|
|
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 */
|
|
@@ -335,8 +335,9 @@
|
|
|
335
335
|
|
|
336
336
|
const debugWidth = data.debugWidth || 200;
|
|
337
337
|
const debugHeight = data.debugHeight || 200;
|
|
338
|
-
|
|
339
|
-
const
|
|
338
|
+
// Display at the server-resized debug dimensions (no display cap)
|
|
339
|
+
const maxDisplayWidth = debugWidth;
|
|
340
|
+
const displayHeight = debugHeight;
|
|
340
341
|
|
|
341
342
|
let debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
342
343
|
|
|
@@ -389,9 +389,9 @@ module.exports = function (RED) {
|
|
|
389
389
|
const images = results.map(r => r.image);
|
|
390
390
|
|
|
391
391
|
if (useSharpWebp) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
392
|
+
// Encode all images concurrently (Sharp runs on the libuv thread pool)
|
|
393
|
+
const webps = await Promise.all(images.map((img) => NodeUtils.encodeWebpAdvanced(img, config)));
|
|
394
|
+
webps.forEach((webp, i) => { images[i] = webp; });
|
|
395
395
|
}
|
|
396
396
|
|
|
397
397
|
/* ▸ 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
|
-
|
|
87
|
-
|
|
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];
|
|
@@ -170,6 +170,10 @@
|
|
|
170
170
|
|
|
171
171
|
const nodeElement = document.getElementById(nodeId);
|
|
172
172
|
if (!nodeElement) return;
|
|
173
|
+
|
|
174
|
+
// Size to the server-resized debug image (no display cap)
|
|
175
|
+
var debugWidth = data.debugWidth || 200;
|
|
176
|
+
var debugHeight = data.debugHeight || 200;
|
|
173
177
|
|
|
174
178
|
let debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
175
179
|
|
|
@@ -179,8 +183,8 @@
|
|
|
179
183
|
debugContainer.id = 'debug-img-container-' + nodeId;
|
|
180
184
|
debugContainer.setAttribute('x', '70');
|
|
181
185
|
debugContainer.setAttribute('y', '5');
|
|
182
|
-
debugContainer.setAttribute('width',
|
|
183
|
-
debugContainer.setAttribute('height',
|
|
186
|
+
debugContainer.setAttribute('width', debugWidth.toString());
|
|
187
|
+
debugContainer.setAttribute('height', debugHeight.toString());
|
|
184
188
|
debugContainer.style.overflow = 'visible';
|
|
185
189
|
|
|
186
190
|
// Create simple image directly inside foreignObject
|
|
@@ -190,8 +194,8 @@
|
|
|
190
194
|
img.style.height = 'auto';
|
|
191
195
|
img.style.display = 'block';
|
|
192
196
|
img.style.cursor = 'pointer';
|
|
193
|
-
img.style.maxHeight = '
|
|
194
|
-
img.style.maxWidth = '
|
|
197
|
+
img.style.maxHeight = 'none';
|
|
198
|
+
img.style.maxWidth = 'none';
|
|
195
199
|
|
|
196
200
|
img.onclick = function() {
|
|
197
201
|
removeDebugImage(nodeId);
|
|
@@ -199,6 +203,9 @@
|
|
|
199
203
|
|
|
200
204
|
debugContainer.appendChild(img);
|
|
201
205
|
nodeElement.appendChild(debugContainer);
|
|
206
|
+
} else {
|
|
207
|
+
debugContainer.setAttribute('width', debugWidth.toString());
|
|
208
|
+
debugContainer.setAttribute('height', debugHeight.toString());
|
|
202
209
|
}
|
|
203
210
|
|
|
204
211
|
const img = document.getElementById('debug-img-' + nodeId);
|
|
@@ -95,9 +95,9 @@ module.exports = function (RED) {
|
|
|
95
95
|
}, { totalConvertMs: 0, totalTaskMs: 0, totalEncodeMs: 0, images: [] });
|
|
96
96
|
|
|
97
97
|
if (useSharpWebp) {
|
|
98
|
-
|
|
99
|
-
|
|
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 */
|
|
@@ -228,6 +228,10 @@
|
|
|
228
228
|
|
|
229
229
|
const nodeElement = document.getElementById(nodeId);
|
|
230
230
|
if (!nodeElement) return;
|
|
231
|
+
|
|
232
|
+
// Size to the server-resized debug image (no display cap)
|
|
233
|
+
var debugWidth = data.debugWidth || 200;
|
|
234
|
+
var debugHeight = data.debugHeight || 200;
|
|
231
235
|
|
|
232
236
|
let debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
233
237
|
|
|
@@ -237,8 +241,8 @@
|
|
|
237
241
|
debugContainer.id = 'debug-img-container-' + nodeId;
|
|
238
242
|
debugContainer.setAttribute('x', '70');
|
|
239
243
|
debugContainer.setAttribute('y', '5');
|
|
240
|
-
debugContainer.setAttribute('width',
|
|
241
|
-
debugContainer.setAttribute('height',
|
|
244
|
+
debugContainer.setAttribute('width', debugWidth.toString());
|
|
245
|
+
debugContainer.setAttribute('height', debugHeight.toString());
|
|
242
246
|
debugContainer.style.overflow = 'visible';
|
|
243
247
|
|
|
244
248
|
// Create simple image directly inside foreignObject
|
|
@@ -248,8 +252,8 @@
|
|
|
248
252
|
img.style.height = 'auto';
|
|
249
253
|
img.style.display = 'block';
|
|
250
254
|
img.style.cursor = 'pointer';
|
|
251
|
-
img.style.maxHeight = '
|
|
252
|
-
img.style.maxWidth = '
|
|
255
|
+
img.style.maxHeight = 'none';
|
|
256
|
+
img.style.maxWidth = 'none';
|
|
253
257
|
|
|
254
258
|
img.onclick = function() {
|
|
255
259
|
removeDebugImage(nodeId);
|
|
@@ -257,6 +261,9 @@
|
|
|
257
261
|
|
|
258
262
|
debugContainer.appendChild(img);
|
|
259
263
|
nodeElement.appendChild(debugContainer);
|
|
264
|
+
} else {
|
|
265
|
+
debugContainer.setAttribute('width', debugWidth.toString());
|
|
266
|
+
debugContainer.setAttribute('height', debugHeight.toString());
|
|
260
267
|
}
|
|
261
268
|
|
|
262
269
|
const img = document.getElementById('debug-img-' + nodeId);
|
|
@@ -148,9 +148,9 @@ module.exports = function (RED) {
|
|
|
148
148
|
);
|
|
149
149
|
|
|
150
150
|
if (useSharpWebp) {
|
|
151
|
-
|
|
152
|
-
|
|
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
|
|
@@ -156,6 +156,10 @@
|
|
|
156
156
|
|
|
157
157
|
const nodeElement = document.getElementById(nodeId);
|
|
158
158
|
if (!nodeElement) return;
|
|
159
|
+
|
|
160
|
+
// Size to the server-resized debug image (no display cap)
|
|
161
|
+
var debugWidth = data.debugWidth || 200;
|
|
162
|
+
var debugHeight = data.debugHeight || 200;
|
|
159
163
|
|
|
160
164
|
let debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
161
165
|
|
|
@@ -165,8 +169,8 @@
|
|
|
165
169
|
debugContainer.id = 'debug-img-container-' + nodeId;
|
|
166
170
|
debugContainer.setAttribute('x', '70');
|
|
167
171
|
debugContainer.setAttribute('y', '5');
|
|
168
|
-
debugContainer.setAttribute('width',
|
|
169
|
-
debugContainer.setAttribute('height',
|
|
172
|
+
debugContainer.setAttribute('width', debugWidth.toString());
|
|
173
|
+
debugContainer.setAttribute('height', debugHeight.toString());
|
|
170
174
|
debugContainer.style.overflow = 'visible';
|
|
171
175
|
|
|
172
176
|
// Create simple image directly inside foreignObject
|
|
@@ -176,8 +180,8 @@
|
|
|
176
180
|
img.style.height = 'auto';
|
|
177
181
|
img.style.display = 'block';
|
|
178
182
|
img.style.cursor = 'pointer';
|
|
179
|
-
img.style.maxHeight = '
|
|
180
|
-
img.style.maxWidth = '
|
|
183
|
+
img.style.maxHeight = 'none';
|
|
184
|
+
img.style.maxWidth = 'none';
|
|
181
185
|
|
|
182
186
|
img.onclick = function() {
|
|
183
187
|
removeDebugImage(nodeId);
|
|
@@ -185,6 +189,9 @@
|
|
|
185
189
|
|
|
186
190
|
debugContainer.appendChild(img);
|
|
187
191
|
nodeElement.appendChild(debugContainer);
|
|
192
|
+
} else {
|
|
193
|
+
debugContainer.setAttribute('width', debugWidth.toString());
|
|
194
|
+
debugContainer.setAttribute('height', debugHeight.toString());
|
|
188
195
|
}
|
|
189
196
|
|
|
190
197
|
const img = document.getElementById('debug-img-' + nodeId);
|