@rosepetal/node-red-contrib-image-tools 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +6 -0
- package/.github/workflows/build-prebuild.yml +326 -0
- package/LICENSE +13 -0
- package/README.md +161 -0
- package/artifacts/darwin-arm64/package.json +25 -0
- package/artifacts/linux-arm64/package.json +26 -0
- package/artifacts/linux-x64/package.json +26 -0
- package/artifacts/linuxmusl-x64/package.json +26 -0
- package/assets/flow_time_example.gif +0 -0
- package/assets/nodes/io/array-in-demo.gif +0 -0
- package/assets/nodes/io/array-out-demo.gif +0 -0
- package/assets/nodes/io/array-select-demo.gif +0 -0
- package/assets/nodes/io/image-in-demo.gif +0 -0
- package/assets/nodes/mix/concat-demo.gif +0 -0
- package/assets/nodes/mix/mosaic-demo.gif +0 -0
- package/assets/nodes/transform/crop-demo.gif +0 -0
- package/assets/nodes/transform/filter-demo.gif +0 -0
- package/assets/nodes/transform/padding-demo.gif +0 -0
- package/assets/nodes/transform/resize-demo.gif +0 -0
- package/assets/nodes/transform/rotate-demo.gif +0 -0
- package/docs/nodes/blend/add-mask.md +275 -0
- package/docs/nodes/blend/add-masks.md +284 -0
- package/docs/nodes/blend/blend.md +248 -0
- package/docs/nodes/io/array-in.md +119 -0
- package/docs/nodes/io/array-out.md +150 -0
- package/docs/nodes/io/array-select.md +157 -0
- package/docs/nodes/io/image-in.md +131 -0
- package/docs/nodes/io/image-out.md +179 -0
- package/docs/nodes/io/queue.md +57 -0
- package/docs/nodes/io/save-file.md +30 -0
- package/docs/nodes/mix/advanced-mosaic.md +108 -0
- package/docs/nodes/mix/concat.md +127 -0
- package/docs/nodes/mix/mosaic.md +146 -0
- package/docs/nodes/specialized/cropBB.md +271 -0
- package/docs/nodes/specialized/image-align.md +426 -0
- package/docs/nodes/transform/crop.md +132 -0
- package/docs/nodes/transform/draw.md +77 -0
- package/docs/nodes/transform/filter.md +84 -0
- package/docs/nodes/transform/padding.md +133 -0
- package/docs/nodes/transform/resize.md +158 -0
- package/docs/nodes/transform/rotate.md +121 -0
- package/docs/nodes/util/block-detect.md +46 -0
- package/install.sh +144 -0
- package/node-red-contrib-image-tools/lib/cpp-bridge.js +224 -0
- package/node-red-contrib-image-tools/lib/node-utils.js +529 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +590 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +241 -0
- package/node-red-contrib-image-tools/nodes/blend/add-mask.html +449 -0
- package/node-red-contrib-image-tools/nodes/blend/add-mask.js +170 -0
- package/node-red-contrib-image-tools/nodes/blend/add-masks.html +703 -0
- package/node-red-contrib-image-tools/nodes/blend/add-masks.js +321 -0
- package/node-red-contrib-image-tools/nodes/blend/blend.html +552 -0
- package/node-red-contrib-image-tools/nodes/blend/blend.js +124 -0
- package/node-red-contrib-image-tools/nodes/io/array-in.html +110 -0
- package/node-red-contrib-image-tools/nodes/io/array-in.js +113 -0
- package/node-red-contrib-image-tools/nodes/io/array-out.html +125 -0
- package/node-red-contrib-image-tools/nodes/io/array-out.js +213 -0
- package/node-red-contrib-image-tools/nodes/io/array-select.html +156 -0
- package/node-red-contrib-image-tools/nodes/io/array-select.js +187 -0
- package/node-red-contrib-image-tools/nodes/io/folder-in.html +248 -0
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +335 -0
- package/node-red-contrib-image-tools/nodes/io/image-in.html +146 -0
- package/node-red-contrib-image-tools/nodes/io/image-in.js +143 -0
- package/node-red-contrib-image-tools/nodes/io/image-out.html +506 -0
- package/node-red-contrib-image-tools/nodes/io/image-out.js +545 -0
- package/node-red-contrib-image-tools/nodes/io/queue.html +119 -0
- package/node-red-contrib-image-tools/nodes/io/queue.js +191 -0
- package/node-red-contrib-image-tools/nodes/io/save-file.html +243 -0
- package/node-red-contrib-image-tools/nodes/io/save-file.js +440 -0
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +2149 -0
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +195 -0
- package/node-red-contrib-image-tools/nodes/mix/concat.html +390 -0
- package/node-red-contrib-image-tools/nodes/mix/concat.js +112 -0
- package/node-red-contrib-image-tools/nodes/mix/mosaic.html +550 -0
- package/node-red-contrib-image-tools/nodes/mix/mosaic.js +151 -0
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +268 -0
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +277 -0
- package/node-red-contrib-image-tools/nodes/specialized/image-align.html +528 -0
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +306 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.html +410 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.js +149 -0
- package/node-red-contrib-image-tools/nodes/transform/draw.html +719 -0
- package/node-red-contrib-image-tools/nodes/transform/draw.js +509 -0
- package/node-red-contrib-image-tools/nodes/transform/filter.html +578 -0
- package/node-red-contrib-image-tools/nodes/transform/filter.js +177 -0
- package/node-red-contrib-image-tools/nodes/transform/padding.html +475 -0
- package/node-red-contrib-image-tools/nodes/transform/padding.js +142 -0
- package/node-red-contrib-image-tools/nodes/transform/resize.html +429 -0
- package/node-red-contrib-image-tools/nodes/transform/resize.js +162 -0
- package/node-red-contrib-image-tools/nodes/transform/rotate.html +299 -0
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +141 -0
- package/node-red-contrib-image-tools/nodes/util/block-detect.html +85 -0
- package/node-red-contrib-image-tools/nodes/util/block-detect.js +136 -0
- package/node-red-contrib-image-tools/nodes/util/clean-debug.html +201 -0
- package/node-red-contrib-image-tools/nodes/util/clean-debug.js +393 -0
- package/node-red-contrib-image-tools/package.json +64 -0
- package/npm/darwin-arm64/lib/.gitkeep +1 -0
- package/npm/darwin-arm64/package.json +25 -0
- package/npm/darwin-x64/lib/.gitkeep +1 -0
- package/npm/darwin-x64/package.json +25 -0
- package/npm/linux-arm64/lib/.gitkeep +1 -0
- package/npm/linux-arm64/package.json +26 -0
- package/npm/linux-x64/lib/.gitkeep +1 -0
- package/npm/linux-x64/package.json +26 -0
- package/npm/linuxmusl-x64/lib/.gitkeep +1 -0
- package/npm/linuxmusl-x64/package.json +26 -0
- package/npm/win32-x64/lib/.gitkeep +1 -0
- package/npm/win32-x64/package.json +25 -0
- package/package.json +74 -0
- package/rosepetal-image-engine/binding.gyp +153 -0
- package/rosepetal-image-engine/package.json +19 -0
- package/rosepetal-image-engine/src/add-bbs.cpp +433 -0
- package/rosepetal-image-engine/src/add-mask.cpp +240 -0
- package/rosepetal-image-engine/src/add-masks.cpp +638 -0
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +740 -0
- package/rosepetal-image-engine/src/blend.cpp +200 -0
- package/rosepetal-image-engine/src/concat.cpp +329 -0
- package/rosepetal-image-engine/src/crop.cpp +139 -0
- package/rosepetal-image-engine/src/draw.cpp +414 -0
- package/rosepetal-image-engine/src/filter.cpp +230 -0
- package/rosepetal-image-engine/src/filters/kernels.h +171 -0
- package/rosepetal-image-engine/src/image-align.cpp +551 -0
- package/rosepetal-image-engine/src/main.cpp +36 -0
- package/rosepetal-image-engine/src/mosaic.cpp +373 -0
- package/rosepetal-image-engine/src/padding.cpp +124 -0
- package/rosepetal-image-engine/src/resize.cpp +210 -0
- package/rosepetal-image-engine/src/rotate.cpp +177 -0
- package/rosepetal-image-engine/src/utils.h +563 -0
- package/rosepetal-image-engine/test-formats.js +119 -0
- package/scripts/build-opencv-static.ps1 +166 -0
- package/scripts/build-opencv-static.sh +147 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Node-RED logic for the Filter node with C++ backend
|
|
3
|
+
* Applies various image processing kernels: blur, sharpen, edge, emboss, gaussian
|
|
4
|
+
* @author Rosepetal
|
|
5
|
+
*/
|
|
6
|
+
const { performance } = require('perf_hooks');
|
|
7
|
+
const CppProcessor = require('../../lib/cpp-bridge.js');
|
|
8
|
+
|
|
9
|
+
module.exports = function (RED) {
|
|
10
|
+
const NodeUtils = require('../../lib/node-utils.js')(RED);
|
|
11
|
+
|
|
12
|
+
function FilterNode(config) {
|
|
13
|
+
RED.nodes.createNode(this, config);
|
|
14
|
+
const node = this;
|
|
15
|
+
|
|
16
|
+
node.on('input', async (msg, send, done) => {
|
|
17
|
+
try {
|
|
18
|
+
const startTime = performance.now();
|
|
19
|
+
node.status({});
|
|
20
|
+
|
|
21
|
+
// I/O paths
|
|
22
|
+
const inputPath = config.inputPath || 'payload';
|
|
23
|
+
const outputPath = config.outputPath || 'payload';
|
|
24
|
+
const outputFormat = config.outputFormat || 'raw';
|
|
25
|
+
const outputQuality = parseInt(config.outputQuality) || 90;
|
|
26
|
+
const pngOptimize = config.pngOptimize || false;
|
|
27
|
+
|
|
28
|
+
// Filter parameters
|
|
29
|
+
const filterType = config.filterType || 'blur';
|
|
30
|
+
|
|
31
|
+
// Resolve kernel size and intensity from config
|
|
32
|
+
let kernelSize = parseInt(NodeUtils.resolveDimension(
|
|
33
|
+
node,
|
|
34
|
+
config.kernelSizeType || 'num',
|
|
35
|
+
config.kernelSize || '3',
|
|
36
|
+
msg
|
|
37
|
+
));
|
|
38
|
+
|
|
39
|
+
let intensity = parseFloat(NodeUtils.resolveDimension(
|
|
40
|
+
node,
|
|
41
|
+
config.intensityType || 'num',
|
|
42
|
+
config.intensity || '1.0',
|
|
43
|
+
msg
|
|
44
|
+
));
|
|
45
|
+
|
|
46
|
+
// Validate parameters
|
|
47
|
+
kernelSize = Math.max(3, Math.min(kernelSize, 15));
|
|
48
|
+
if (kernelSize % 2 === 0) kernelSize++; // Ensure odd size
|
|
49
|
+
intensity = Math.max(0.0, Math.min(intensity, 2.0));
|
|
50
|
+
|
|
51
|
+
// Get input image(s)
|
|
52
|
+
const originalPayload = RED.util.getMessageProperty(msg, inputPath);
|
|
53
|
+
|
|
54
|
+
// Validate input images
|
|
55
|
+
if (Array.isArray(originalPayload)) {
|
|
56
|
+
if (!NodeUtils.validateListImage(originalPayload, node)) {
|
|
57
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
58
|
+
node, 'Invalid image list structure', msg, send, done,
|
|
59
|
+
{ originalPayload, outputPath, outputType: 'preserve' }
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
if (!NodeUtils.validateSingleImage(originalPayload, node)) {
|
|
64
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
65
|
+
node, 'Invalid image structure', msg, send, done,
|
|
66
|
+
{ originalPayload, outputPath, outputType: 'preserve' }
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const inputList = Array.isArray(originalPayload)
|
|
72
|
+
? originalPayload
|
|
73
|
+
: [originalPayload];
|
|
74
|
+
|
|
75
|
+
// Process images in parallel
|
|
76
|
+
const promises = inputList.map((inputImage) => {
|
|
77
|
+
return CppProcessor.filter(
|
|
78
|
+
inputImage,
|
|
79
|
+
filterType,
|
|
80
|
+
kernelSize,
|
|
81
|
+
intensity,
|
|
82
|
+
outputFormat,
|
|
83
|
+
outputQuality,
|
|
84
|
+
pngOptimize
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const results = await Promise.all(promises);
|
|
89
|
+
|
|
90
|
+
// Aggregate timing information
|
|
91
|
+
const { totalConvertMs, totalTaskMs, encodeMs, images } =
|
|
92
|
+
results.reduce(
|
|
93
|
+
(acc, { image, timing }) => {
|
|
94
|
+
acc.totalConvertMs += timing?.convertMs ?? 0;
|
|
95
|
+
acc.totalTaskMs += timing?.taskMs ?? 0;
|
|
96
|
+
acc.encodeMs += timing?.encodeMs ?? 0;
|
|
97
|
+
acc.images.push(image);
|
|
98
|
+
return acc;
|
|
99
|
+
},
|
|
100
|
+
{ totalConvertMs: 0, totalTaskMs: 0, encodeMs: 0, images: [] }
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// Prepare output
|
|
104
|
+
const output = Array.isArray(originalPayload) ? images : images[0];
|
|
105
|
+
|
|
106
|
+
// Update node status with timing information
|
|
107
|
+
const elapsedTime = performance.now() - startTime;
|
|
108
|
+
|
|
109
|
+
// Debug image display
|
|
110
|
+
let debugFormat = null;
|
|
111
|
+
if (config.debugEnabled) {
|
|
112
|
+
try {
|
|
113
|
+
// Resolve and validate debug width
|
|
114
|
+
let debugWidth = NodeUtils.resolveDimension(
|
|
115
|
+
node,
|
|
116
|
+
config.debugWidthType,
|
|
117
|
+
config.debugWidth,
|
|
118
|
+
msg
|
|
119
|
+
);
|
|
120
|
+
debugWidth = Math.max(1, parseInt(debugWidth) || 200); // Ensure positive, default 200
|
|
121
|
+
|
|
122
|
+
// For arrays, show the first image as representative
|
|
123
|
+
const debugImage = Array.isArray(originalPayload) ? images[0] : images[0];
|
|
124
|
+
const debugResult = await NodeUtils.debugImageDisplay(
|
|
125
|
+
debugImage,
|
|
126
|
+
outputFormat,
|
|
127
|
+
outputQuality,
|
|
128
|
+
node,
|
|
129
|
+
true,
|
|
130
|
+
debugWidth
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
if (debugResult) {
|
|
134
|
+
debugFormat = debugResult.formatMessage;
|
|
135
|
+
// Update node status with debug info
|
|
136
|
+
NodeUtils.setSuccessStatusWithDebug(node, results.length, elapsedTime, {
|
|
137
|
+
convertMs: totalConvertMs,
|
|
138
|
+
taskMs: totalTaskMs,
|
|
139
|
+
encodeMs: encodeMs
|
|
140
|
+
}, debugFormat + (Array.isArray(originalPayload) ? ' (first)' : ''));
|
|
141
|
+
}
|
|
142
|
+
} catch (debugError) {
|
|
143
|
+
node.warn(`Debug display error: ${debugError.message}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Set regular status if debug not enabled or failed
|
|
148
|
+
if (!debugFormat) {
|
|
149
|
+
node.status({
|
|
150
|
+
fill: 'green',
|
|
151
|
+
shape: 'dot',
|
|
152
|
+
text: `OK: ${results.length} img in ${elapsedTime.toFixed(2)} ms (conv. ${(totalConvertMs + encodeMs).toFixed(2)} ms | task ${totalTaskMs.toFixed(2)} ms)`
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
NodeUtils.recordPerformanceMetrics(node, msg, {
|
|
157
|
+
convertMs: totalConvertMs,
|
|
158
|
+
encodeMs: encodeMs,
|
|
159
|
+
taskMs: totalTaskMs
|
|
160
|
+
}, elapsedTime);
|
|
161
|
+
|
|
162
|
+
// Set output and send message
|
|
163
|
+
RED.util.setMessageProperty(msg, outputPath, output);
|
|
164
|
+
send(msg);
|
|
165
|
+
done && done();
|
|
166
|
+
|
|
167
|
+
} catch (err) {
|
|
168
|
+
NodeUtils.handleNodeErrorWithPassthrough(
|
|
169
|
+
node, err, msg, send, done, 'filter processing',
|
|
170
|
+
{ originalPayload, outputPath, outputType: 'preserve' }
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
RED.nodes.registerType('filter', FilterNode);
|
|
177
|
+
};
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
<!-- 1 ▸ Runtime registration ------------------------------------------------>
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('padding', {
|
|
4
|
+
category : 'RP Image',
|
|
5
|
+
color : '#DDA0DD',
|
|
6
|
+
icon : 'font-awesome/fa-square-o',
|
|
7
|
+
defaults : {
|
|
8
|
+
name:{value:""},
|
|
9
|
+
|
|
10
|
+
/* I/O */
|
|
11
|
+
inputPath :{value:"payload"}, inputPathType :{value:"msg"},
|
|
12
|
+
outputPath:{value:"payload"}, outputPathType:{value:"msg"},
|
|
13
|
+
outputFormat:{value:"raw"},
|
|
14
|
+
outputQuality:{value:90},
|
|
15
|
+
pngOptimize:{value:false},
|
|
16
|
+
// Debug configuration
|
|
17
|
+
debugEnabled:{value:false},
|
|
18
|
+
debugWidth:{value:200},
|
|
19
|
+
debugWidthType:{value:"num"},
|
|
20
|
+
|
|
21
|
+
/* margins (pixels) */
|
|
22
|
+
top :{value:"0"}, topType :{value:"num"},
|
|
23
|
+
bottom:{value:"0"}, bottomType:{value:"num"},
|
|
24
|
+
left :{value:"0"}, leftType :{value:"num"},
|
|
25
|
+
right :{value:"0"}, rightType :{value:"num"},
|
|
26
|
+
|
|
27
|
+
/* colour */
|
|
28
|
+
padColor:{value:"#000000"}
|
|
29
|
+
},
|
|
30
|
+
inputs:1, outputs:1,
|
|
31
|
+
label:function(){ return this.name || "padding"; },
|
|
32
|
+
|
|
33
|
+
oneditprepare:function(){
|
|
34
|
+
/* I/O path typed‑inputs */
|
|
35
|
+
$("#node-input-inputPath").typedInput({
|
|
36
|
+
default:'msg', types:['msg','flow','global'],
|
|
37
|
+
typeField:"#node-input-inputPathType"
|
|
38
|
+
});
|
|
39
|
+
$("#node-input-outputPath").typedInput({
|
|
40
|
+
default:'msg', types:['msg','flow','global'],
|
|
41
|
+
typeField:"#node-input-outputPathType"
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/* margins typed‑inputs */
|
|
45
|
+
["top","bottom","left","right"].forEach(id=>{
|
|
46
|
+
$("#node-input-"+id).typedInput({
|
|
47
|
+
default:'num',
|
|
48
|
+
types:['num','msg','flow','global'],
|
|
49
|
+
typeField:"#node-input-"+id+"Type"
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
function updateQualityVisibility(){
|
|
54
|
+
const format = $("#node-input-outputFormat").val();
|
|
55
|
+
$("#quality-row").toggle(format === "jpg" || format === "webp");
|
|
56
|
+
$("#png-optimize-row").toggle(format === "png");
|
|
57
|
+
}
|
|
58
|
+
$("#node-input-outputFormat").on("change", updateQualityVisibility);
|
|
59
|
+
updateQualityVisibility(); // initial state
|
|
60
|
+
|
|
61
|
+
// === Debug Display Logic ===
|
|
62
|
+
const debugCheckbox = $('#node-input-debugEnabled');
|
|
63
|
+
const debugWidthRow = $('#debug-width-row');
|
|
64
|
+
|
|
65
|
+
// Initialize debug width TypedInput
|
|
66
|
+
$("#node-input-debugWidth").typedInput({
|
|
67
|
+
default: 'num',
|
|
68
|
+
types: ['num', 'msg', 'flow', 'global'],
|
|
69
|
+
typeField: "#node-input-debugWidthType"
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Function to toggle debug width visibility
|
|
73
|
+
function updateDebugWidthVisibility() {
|
|
74
|
+
if (debugCheckbox.is(':checked')) {
|
|
75
|
+
debugWidthRow.show();
|
|
76
|
+
} else {
|
|
77
|
+
debugWidthRow.hide();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Initialize debug state on node open
|
|
82
|
+
updateDebugWidthVisibility();
|
|
83
|
+
|
|
84
|
+
// Handle debug checkbox changes
|
|
85
|
+
debugCheckbox.on('change', function() {
|
|
86
|
+
const enabled = this.checked;
|
|
87
|
+
updateDebugWidthVisibility();
|
|
88
|
+
// Store debug state for runtime access
|
|
89
|
+
$('#node-input-debugEnabled').data('debug-enabled', enabled);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Debug image display renderer - shared across all image processing nodes
|
|
95
|
+
if (!window.debugImageRendererInitialized) {
|
|
96
|
+
window.debugImageRendererInitialized = true;
|
|
97
|
+
|
|
98
|
+
(function() {
|
|
99
|
+
var isSubscribed = false;
|
|
100
|
+
|
|
101
|
+
function subscribeToDebugImages() {
|
|
102
|
+
if (isSubscribed || typeof RED === 'undefined' || !RED.comms) return;
|
|
103
|
+
isSubscribed = true;
|
|
104
|
+
|
|
105
|
+
RED.comms.subscribe('debug-image', function(event, data) {
|
|
106
|
+
if (!data || !data.id) return;
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
renderDebugImage(data);
|
|
110
|
+
} catch (err) {
|
|
111
|
+
console.warn('Debug image render error:', err);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function renderDebugImage(data) {
|
|
117
|
+
const nodeId = data.id;
|
|
118
|
+
const base64Data = data.data;
|
|
119
|
+
const format = data.format || 'unknown';
|
|
120
|
+
const mimeType = data.mimeType || 'jpeg';
|
|
121
|
+
|
|
122
|
+
if (!base64Data) {
|
|
123
|
+
removeDebugImage(nodeId);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const nodeElement = document.getElementById(nodeId);
|
|
128
|
+
if (!nodeElement) return;
|
|
129
|
+
|
|
130
|
+
let debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
131
|
+
|
|
132
|
+
if (!debugContainer) {
|
|
133
|
+
// Create SVG foreignObject to embed HTML content in SVG
|
|
134
|
+
debugContainer = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
|
|
135
|
+
debugContainer.id = 'debug-img-container-' + nodeId;
|
|
136
|
+
debugContainer.setAttribute('x', '70');
|
|
137
|
+
debugContainer.setAttribute('y', '5');
|
|
138
|
+
debugContainer.setAttribute('width', '120');
|
|
139
|
+
debugContainer.setAttribute('height', '120');
|
|
140
|
+
debugContainer.style.overflow = 'visible';
|
|
141
|
+
|
|
142
|
+
// Create simple image directly inside foreignObject
|
|
143
|
+
const img = document.createElement('img');
|
|
144
|
+
img.id = 'debug-img-' + nodeId;
|
|
145
|
+
img.style.width = '100%';
|
|
146
|
+
img.style.height = 'auto';
|
|
147
|
+
img.style.display = 'block';
|
|
148
|
+
img.style.cursor = 'pointer';
|
|
149
|
+
img.style.maxHeight = '100px';
|
|
150
|
+
img.style.maxWidth = '100px';
|
|
151
|
+
|
|
152
|
+
img.onclick = function() {
|
|
153
|
+
removeDebugImage(nodeId);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
debugContainer.appendChild(img);
|
|
157
|
+
nodeElement.appendChild(debugContainer);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const img = document.getElementById('debug-img-' + nodeId);
|
|
161
|
+
|
|
162
|
+
if (img) {
|
|
163
|
+
img.src = `data:image/${mimeType};base64,${base64Data}`;
|
|
164
|
+
img.title = 'Debug image (click to hide)';
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function removeDebugImage(nodeId) {
|
|
169
|
+
const debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
170
|
+
if (debugContainer) {
|
|
171
|
+
debugContainer.remove();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function initializeWhenReady() {
|
|
176
|
+
if (typeof RED !== 'undefined' && RED.comms) {
|
|
177
|
+
subscribeToDebugImages();
|
|
178
|
+
|
|
179
|
+
// Clean up orphaned debug images periodically
|
|
180
|
+
setInterval(function() {
|
|
181
|
+
const debugContainers = document.querySelectorAll('[id^="debug-img-container-"]');
|
|
182
|
+
debugContainers.forEach(container => {
|
|
183
|
+
const nodeId = container.id.replace('debug-img-container-', '');
|
|
184
|
+
const nodeElement = document.getElementById(nodeId);
|
|
185
|
+
if (!nodeElement) {
|
|
186
|
+
container.remove();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}, 5000);
|
|
190
|
+
} else {
|
|
191
|
+
setTimeout(initializeWhenReady, 100);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (document.readyState === 'loading') {
|
|
196
|
+
document.addEventListener('DOMContentLoaded', initializeWhenReady);
|
|
197
|
+
} else {
|
|
198
|
+
initializeWhenReady();
|
|
199
|
+
}
|
|
200
|
+
})();
|
|
201
|
+
}
|
|
202
|
+
</script>
|
|
203
|
+
|
|
204
|
+
<!-- 2 ▸ Edit‑dialog template ------------------------------------------------>
|
|
205
|
+
<script type="text/x-red" data-template-name="padding">
|
|
206
|
+
<div class="form-row">
|
|
207
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
208
|
+
<input type="text" id="node-input-name">
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
<hr>
|
|
212
|
+
|
|
213
|
+
<div class="form-row">
|
|
214
|
+
<label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input</label>
|
|
215
|
+
<input type="text" id="node-input-inputPath" style="width:70%;">
|
|
216
|
+
<input type="hidden" id="node-input-inputPathType">
|
|
217
|
+
</div>
|
|
218
|
+
<div class="form-row">
|
|
219
|
+
<label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output</label>
|
|
220
|
+
<input type="text" id="node-input-outputPath" style="width:70%;">
|
|
221
|
+
<input type="hidden" id="node-input-outputPathType">
|
|
222
|
+
</div>
|
|
223
|
+
<div class="form-row">
|
|
224
|
+
<label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
|
|
225
|
+
<select id="node-input-outputFormat" style="width: 200px;">
|
|
226
|
+
<option value="raw">Raw (fastest)</option>
|
|
227
|
+
<option value="jpg">JPEG</option>
|
|
228
|
+
<option value="png">PNG</option>
|
|
229
|
+
<option value="webp">WebP</option>
|
|
230
|
+
</select>
|
|
231
|
+
</div>
|
|
232
|
+
<div class="form-row" id="quality-row">
|
|
233
|
+
<label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
|
|
234
|
+
<input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
|
|
235
|
+
<span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
|
|
236
|
+
</div>
|
|
237
|
+
<div class="form-row" id="png-optimize-row" style="display: none;">
|
|
238
|
+
<label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
|
|
239
|
+
<input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
240
|
+
<label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
|
|
241
|
+
</div>
|
|
242
|
+
|
|
243
|
+
<!-- Debug Configuration -->
|
|
244
|
+
<div class="form-row">
|
|
245
|
+
<label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
|
|
246
|
+
<input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
247
|
+
<label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
|
|
248
|
+
</div>
|
|
249
|
+
<div class="form-row" id="debug-width-row" style="display: none;">
|
|
250
|
+
<label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
|
|
251
|
+
<input type="text" id="node-input-debugWidth" style="width: 120px;">
|
|
252
|
+
<input type="hidden" id="node-input-debugWidthType">
|
|
253
|
+
<span style="margin-left: 10px; color: #666;">pixels</span>
|
|
254
|
+
</div>
|
|
255
|
+
|
|
256
|
+
<hr>
|
|
257
|
+
|
|
258
|
+
<strong>Margins (pixels)</strong>
|
|
259
|
+
<div class="form-row">
|
|
260
|
+
<label>Top</label>
|
|
261
|
+
<input type="text" id="node-input-top" style="width:65%;">
|
|
262
|
+
<input type="hidden" id="node-input-topType">
|
|
263
|
+
</div>
|
|
264
|
+
<div class="form-row">
|
|
265
|
+
<label>Bottom</label>
|
|
266
|
+
<input type="text" id="node-input-bottom" style="width:65%;">
|
|
267
|
+
<input type="hidden" id="node-input-bottomType">
|
|
268
|
+
</div>
|
|
269
|
+
<div class="form-row">
|
|
270
|
+
<label>Left</label>
|
|
271
|
+
<input type="text" id="node-input-left" style="width:65%;">
|
|
272
|
+
<input type="hidden" id="node-input-leftType">
|
|
273
|
+
</div>
|
|
274
|
+
<div class="form-row">
|
|
275
|
+
<label>Right</label>
|
|
276
|
+
<input type="text" id="node-input-right" style="width:65%;">
|
|
277
|
+
<input type="hidden" id="node-input-rightType">
|
|
278
|
+
</div>
|
|
279
|
+
|
|
280
|
+
<div class="form-row">
|
|
281
|
+
<label for="node-input-padColor"><i class="fa fa-tint"></i> Colour</label>
|
|
282
|
+
<input type="color" id="node-input-padColor" style="width:80px;">
|
|
283
|
+
</div>
|
|
284
|
+
</script>
|
|
285
|
+
|
|
286
|
+
<!-- 3 ▸ Help panel --------------------------------------------------------->
|
|
287
|
+
<script type="text/x-red" data-help-name="padding">
|
|
288
|
+
<p>The <strong>padding</strong> node adds solid color borders around images with pixel-perfect precision. It supports independent margin control for each side and works with both single images and arrays, using high-performance C++ backend processing with OpenCV.</p>
|
|
289
|
+
|
|
290
|
+
<h3>Details</h3>
|
|
291
|
+
<p>This node extends images by adding colored pixels around their edges, effectively increasing the canvas size. The padding operation preserves the original image content while adding configurable margins on all sides. The node maintains the original image's color space and data type while seamlessly integrating the padding color.</p>
|
|
292
|
+
|
|
293
|
+
<h3>Properties</h3>
|
|
294
|
+
<dl class="message-properties">
|
|
295
|
+
<dt>Name <span class="property-type">string</span></dt>
|
|
296
|
+
<dd>Optional display name for the node</dd>
|
|
297
|
+
|
|
298
|
+
<dt>Input from <span class="property-type">msg | flow | global</span></dt>
|
|
299
|
+
<dd>Source path for image data (default: <code>msg.payload</code>)</dd>
|
|
300
|
+
|
|
301
|
+
<dt>Output to <span class="property-type">msg | flow | global</span></dt>
|
|
302
|
+
<dd>Destination path for processed image (default: <code>msg.payload</code>)</dd>
|
|
303
|
+
|
|
304
|
+
<dt>Output Format <span class="property-type">string</span></dt>
|
|
305
|
+
<dd>Image output format: <code>raw</code>, <code>jpg</code>, <code>png</code>, or <code>webp</code></dd>
|
|
306
|
+
|
|
307
|
+
<dt>Quality <span class="property-type">number</span></dt>
|
|
308
|
+
<dd>Compression quality 1-100 for JPEG and WebP formats</dd>
|
|
309
|
+
|
|
310
|
+
<dt>Top <span class="property-type">number | msg | flow | global</span></dt>
|
|
311
|
+
<dd>Pixels to add above the image (default: 0)</dd>
|
|
312
|
+
|
|
313
|
+
<dt>Bottom <span class="property-type">number | msg | flow | global</span></dt>
|
|
314
|
+
<dd>Pixels to add below the image (default: 0)</dd>
|
|
315
|
+
|
|
316
|
+
<dt>Left <span class="property-type">number | msg | flow | global</span></dt>
|
|
317
|
+
<dd>Pixels to add to the left of the image (default: 0)</dd>
|
|
318
|
+
|
|
319
|
+
<dt>Right <span class="property-type">number | msg | flow | global</span></dt>
|
|
320
|
+
<dd>Pixels to add to the right of the image (default: 0)</dd>
|
|
321
|
+
|
|
322
|
+
<dt>Colour <span class="property-type">color</span></dt>
|
|
323
|
+
<dd>Hex color code for padding areas (default: #000000)</dd>
|
|
324
|
+
</dl>
|
|
325
|
+
|
|
326
|
+
<h3>Inputs</h3>
|
|
327
|
+
<dl class="message-properties">
|
|
328
|
+
<dt>payload <span class="property-type">object | array</span></dt>
|
|
329
|
+
<dd>Image object(s) in standard format:
|
|
330
|
+
<pre>{
|
|
331
|
+
data: Buffer, // Raw pixel data or file buffer
|
|
332
|
+
width: number, // Image width in pixels
|
|
333
|
+
height: number, // Image height in pixels
|
|
334
|
+
channels: number, // Channel count (1, 3, 4)
|
|
335
|
+
colorSpace: string, // "GRAY", "RGB", "RGBA", "BGR", "BGRA"
|
|
336
|
+
dtype: string // "uint8", "uint16", "float32"
|
|
337
|
+
}</pre>
|
|
338
|
+
</dd>
|
|
339
|
+
<dt>margin values <span class="property-type">number</span></dt>
|
|
340
|
+
<dd>When margin parameters use dynamic sources, values are read from specified paths</dd>
|
|
341
|
+
</dl>
|
|
342
|
+
|
|
343
|
+
<h3>Outputs</h3>
|
|
344
|
+
<dl class="message-properties">
|
|
345
|
+
<dt>payload <span class="property-type">object | array | Buffer</span></dt>
|
|
346
|
+
<dd>Processed image(s) with padding applied. Format depends on Output Format setting</dd>
|
|
347
|
+
|
|
348
|
+
<dt>Raw format output</dt>
|
|
349
|
+
<dd>Image object with updated dimensions:
|
|
350
|
+
<pre>{
|
|
351
|
+
data: Buffer, // Padded image data
|
|
352
|
+
width: number, // Original width + left + right
|
|
353
|
+
height: number, // Original height + top + bottom
|
|
354
|
+
channels: number, // Unchanged from input
|
|
355
|
+
colorSpace: string, // Unchanged from input
|
|
356
|
+
dtype: string // Unchanged from input
|
|
357
|
+
}</pre>
|
|
358
|
+
</dd>
|
|
359
|
+
|
|
360
|
+
<dt>Encoded format output</dt>
|
|
361
|
+
<dd>Compressed image buffer (JPEG/PNG/WebP) ready for storage or transmission</dd>
|
|
362
|
+
</dl>
|
|
363
|
+
|
|
364
|
+
<h3>Padding Behavior</h3>
|
|
365
|
+
<h4>Dimension Calculation</h4>
|
|
366
|
+
<ul>
|
|
367
|
+
<li><strong>New Width:</strong> original_width + left + right</li>
|
|
368
|
+
<li><strong>New Height:</strong> original_height + top + bottom</li>
|
|
369
|
+
<li><strong>Minimum Values:</strong> All margin values must be ≥ 0</li>
|
|
370
|
+
<li><strong>Zero Padding:</strong> When all margins are 0, returns original image unchanged</li>
|
|
371
|
+
</ul>
|
|
372
|
+
|
|
373
|
+
<h4>Color Handling</h4>
|
|
374
|
+
<ul>
|
|
375
|
+
<li><strong>Color Format:</strong> Input as hex color (#RRGGBB)</li>
|
|
376
|
+
<li><strong>Channel Mapping:</strong> Automatically converts to image's color space</li>
|
|
377
|
+
<li><strong>Grayscale Images:</strong> Uses luminance value of selected color</li>
|
|
378
|
+
<li><strong>Alpha Channels:</strong> Padding areas receive full opacity (255)</li>
|
|
379
|
+
</ul>
|
|
380
|
+
|
|
381
|
+
<h4>Data Type Preservation</h4>
|
|
382
|
+
<ul>
|
|
383
|
+
<li><strong>uint8:</strong> Color values scaled to 0-255 range</li>
|
|
384
|
+
<li><strong>uint16:</strong> Color values scaled to 0-65535 range</li>
|
|
385
|
+
<li><strong>float32:</strong> Color values normalized to 0.0-1.0 range</li>
|
|
386
|
+
</ul>
|
|
387
|
+
|
|
388
|
+
<h3>Examples</h3>
|
|
389
|
+
<h4>Basic Uniform Padding</h4>
|
|
390
|
+
<pre>// Add 10 pixels of black padding on all sides
|
|
391
|
+
{
|
|
392
|
+
top: 10, bottom: 10, left: 10, right: 10,
|
|
393
|
+
padColor: "#000000"
|
|
394
|
+
}</pre>
|
|
395
|
+
|
|
396
|
+
<h4>Asymmetric Padding</h4>
|
|
397
|
+
<pre>// Create letterbox effect with white top/bottom bars
|
|
398
|
+
{
|
|
399
|
+
top: 50, bottom: 50, left: 0, right: 0,
|
|
400
|
+
padColor: "#FFFFFF"
|
|
401
|
+
}</pre>
|
|
402
|
+
|
|
403
|
+
<h4>Dynamic Margins</h4>
|
|
404
|
+
<pre>// Use message properties for responsive padding
|
|
405
|
+
msg.topPadding = 20;
|
|
406
|
+
msg.sidePadding = 15;
|
|
407
|
+
// Configure node: top from msg.topPadding, left/right from msg.sidePadding</pre>
|
|
408
|
+
|
|
409
|
+
<h4>Colorful Borders</h4>
|
|
410
|
+
<pre>// Add colored border for visual emphasis
|
|
411
|
+
{
|
|
412
|
+
top: 5, bottom: 5, left: 5, right: 5,
|
|
413
|
+
padColor: "#FF0000" // Red border
|
|
414
|
+
}</pre>
|
|
415
|
+
|
|
416
|
+
<h3>Node Interactions</h3>
|
|
417
|
+
<h4>Pre-Processing Chain</h4>
|
|
418
|
+
<ul>
|
|
419
|
+
<li><strong>image-in → crop → padding:</strong> Crop then add border</li>
|
|
420
|
+
<li><strong>array-select → padding:</strong> Add padding to selected images</li>
|
|
421
|
+
<li><strong>filter → padding:</strong> Apply effects then add border frame</li>
|
|
422
|
+
</ul>
|
|
423
|
+
|
|
424
|
+
<h4>Post-Processing Chain</h4>
|
|
425
|
+
<ul>
|
|
426
|
+
<li><strong>padding → resize:</strong> Add padding then scale to final size</li>
|
|
427
|
+
<li><strong>padding → concat:</strong> Pad images before combining</li>
|
|
428
|
+
<li><strong>padding → array-out:</strong> Apply borders then encode for output</li>
|
|
429
|
+
</ul>
|
|
430
|
+
|
|
431
|
+
<h4>Common Workflows</h4>
|
|
432
|
+
<ul>
|
|
433
|
+
<li><strong>Thumbnail Generation:</strong> resize → padding → array-out (consistent dimensions)</li>
|
|
434
|
+
<li><strong>Gallery Layout:</strong> padding → concat → mosaic (spaced grid layout)</li>
|
|
435
|
+
<li><strong>Frame Creation:</strong> padding → filter → padding (nested border effects)</li>
|
|
436
|
+
</ul>
|
|
437
|
+
|
|
438
|
+
<h3>Output Formats</h3>
|
|
439
|
+
<dl class="message-properties">
|
|
440
|
+
<dt>raw <span class="property-type">object</span></dt>
|
|
441
|
+
<dd>Fastest option. Returns processed image object for further Node-RED processing</dd>
|
|
442
|
+
|
|
443
|
+
<dt>jpg <span class="property-type">Buffer</span></dt>
|
|
444
|
+
<dd>JPEG-compressed buffer with configurable quality (1-100). Good for photographs</dd>
|
|
445
|
+
|
|
446
|
+
<dt>png <span class="property-type">Buffer</span></dt>
|
|
447
|
+
<dd>PNG-compressed buffer with lossless compression. Preserves transparency</dd>
|
|
448
|
+
|
|
449
|
+
<dt>webp <span class="property-type">Buffer</span></dt>
|
|
450
|
+
<dd>WebP-compressed buffer with configurable quality. Modern format with excellent compression</dd>
|
|
451
|
+
</dl>
|
|
452
|
+
|
|
453
|
+
<h3>Error Handling</h3>
|
|
454
|
+
<ul>
|
|
455
|
+
<li><strong>Invalid Input:</strong> Non-image objects trigger warnings and prevent processing</li>
|
|
456
|
+
<li><strong>Negative Margins:</strong> Values < 0 are treated as 0 with warning</li>
|
|
457
|
+
<li><strong>Missing Properties:</strong> Incomplete image objects are rejected with detailed error messages</li>
|
|
458
|
+
<li><strong>Memory Limits:</strong> Very large padding operations may fail with memory errors</li>
|
|
459
|
+
<li><strong>Color Format:</strong> Invalid hex colors default to black (#000000)</li>
|
|
460
|
+
<li><strong>Dynamic Values:</strong> Missing or invalid dynamic values default to 0</li>
|
|
461
|
+
</ul>
|
|
462
|
+
|
|
463
|
+
<h3>Performance</h3>
|
|
464
|
+
<ul>
|
|
465
|
+
<li><strong>C++ Backend:</strong> High-performance OpenCV-based processing</li>
|
|
466
|
+
<li><strong>Array Support:</strong> Parallel processing of image arrays using Promise.all()</li>
|
|
467
|
+
<li><strong>Memory Efficiency:</strong> Optimized memory allocation for large images</li>
|
|
468
|
+
<li><strong>Status Display:</strong> Real-time timing information (conversion, processing, encoding)</li>
|
|
469
|
+
<li><strong>Zero-Copy:</strong> Minimal memory copying for efficient processing</li>
|
|
470
|
+
<li><strong>Performance Metrics:</strong> Typical processing: <1ms per megapixel for raw output</li>
|
|
471
|
+
</ul>
|
|
472
|
+
|
|
473
|
+
<p><strong>Note:</strong> The node status bar displays detailed timing information: conversion time (input processing) + task time (padding operation) + encoding time (output formatting).</p>
|
|
474
|
+
</script>
|
|
475
|
+
|