@rosepetal/node-red-contrib-image-tools 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +1 -13
  2. package/node-red-contrib-image-tools/lib/node-utils.js +218 -17
  3. package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +64 -9
  4. package/node-red-contrib-image-tools/nodes/blend/add-mask.js +81 -9
  5. package/node-red-contrib-image-tools/nodes/blend/add-masks.js +64 -8
  6. package/node-red-contrib-image-tools/nodes/blend/blend.js +64 -10
  7. package/node-red-contrib-image-tools/nodes/io/folder-in.js +12 -1
  8. package/node-red-contrib-image-tools/nodes/io/image-in.js +10 -2
  9. package/node-red-contrib-image-tools/nodes/io/image-out.js +25 -3
  10. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +52 -26
  11. package/node-red-contrib-image-tools/nodes/mix/concat.js +46 -9
  12. package/node-red-contrib-image-tools/nodes/mix/mosaic.js +52 -15
  13. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +53 -5
  14. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +54 -7
  15. package/node-red-contrib-image-tools/nodes/transform/crop.js +38 -17
  16. package/node-red-contrib-image-tools/nodes/transform/draw.js +28 -7
  17. package/node-red-contrib-image-tools/nodes/transform/filter.js +34 -15
  18. package/node-red-contrib-image-tools/nodes/transform/padding.js +30 -9
  19. package/node-red-contrib-image-tools/nodes/transform/resize.js +58 -33
  20. package/node-red-contrib-image-tools/nodes/transform/rotate.js +40 -20
  21. package/node-red-contrib-image-tools/package.json +1 -8
  22. package/package.json +1 -1
  23. package/rosepetal-image-engine/binding.gyp +5 -23
  24. package/rosepetal-image-engine/src/add-mask.cpp +2 -2
  25. package/rosepetal-image-engine/src/add-masks.cpp +2 -2
  26. package/rosepetal-image-engine/src/advanced-mosaic.cpp +3 -4
  27. package/rosepetal-image-engine/src/blend.cpp +2 -2
  28. package/rosepetal-image-engine/src/concat.cpp +2 -2
  29. package/rosepetal-image-engine/src/crop.cpp +3 -3
  30. package/rosepetal-image-engine/src/draw.cpp +1 -1
  31. package/rosepetal-image-engine/src/filter.cpp +3 -3
  32. package/rosepetal-image-engine/src/mosaic.cpp +4 -5
  33. package/rosepetal-image-engine/src/padding.cpp +4 -3
  34. package/rosepetal-image-engine/src/resize.cpp +101 -23
  35. package/rosepetal-image-engine/src/rotate.cpp +3 -6
  36. package/rosepetal-image-engine/src/utils.h +46 -8
  37. package/docs/nodes/io/array-in.md +0 -119
  38. package/docs/nodes/io/array-out.md +0 -150
  39. package/docs/nodes/io/array-select.md +0 -157
  40. package/docs/nodes/io/queue.md +0 -57
  41. package/docs/nodes/io/save-file.md +0 -30
  42. package/docs/nodes/util/block-detect.md +0 -46
  43. package/node-red-contrib-image-tools/nodes/io/array-in.html +0 -110
  44. package/node-red-contrib-image-tools/nodes/io/array-in.js +0 -113
  45. package/node-red-contrib-image-tools/nodes/io/array-out.html +0 -125
  46. package/node-red-contrib-image-tools/nodes/io/array-out.js +0 -213
  47. package/node-red-contrib-image-tools/nodes/io/array-select.html +0 -156
  48. package/node-red-contrib-image-tools/nodes/io/array-select.js +0 -187
  49. package/node-red-contrib-image-tools/nodes/io/queue.html +0 -119
  50. package/node-red-contrib-image-tools/nodes/io/queue.js +0 -191
  51. package/node-red-contrib-image-tools/nodes/io/save-file.html +0 -243
  52. package/node-red-contrib-image-tools/nodes/io/save-file.js +0 -440
  53. package/node-red-contrib-image-tools/nodes/util/block-detect.html +0 -85
  54. package/node-red-contrib-image-tools/nodes/util/block-detect.js +0 -136
  55. package/node-red-contrib-image-tools/nodes/util/clean-debug.html +0 -201
  56. package/node-red-contrib-image-tools/nodes/util/clean-debug.js +0 -393
@@ -14,13 +14,39 @@ module.exports = function (RED) {
14
14
  const node = this;
15
15
 
16
16
  node.on('input', async (msg, send, done) => {
17
+ /* I/O paths */
18
+ const inputPath = config.inputPath || 'payload';
19
+ const inputPathType = config.inputPathType || 'msg';
20
+ const outputPath = config.outputPath || 'payload';
21
+ const outputPathType = config.outputPathType || 'msg';
22
+
23
+ const { value: inputImages, error: inputErr } =
24
+ NodeUtils.getInputValue(node, msg, inputPath, inputPathType);
25
+ if (inputErr) {
26
+ const hint = inputPathType === 'msg'
27
+ ? `Set inputPath to an existing msg property (e.g. "payload"), or ensure "${inputPath}" exists before this node.`
28
+ : `Set inputPath to an existing ${inputPathType} context key, or ensure "${inputPath}" exists before this node.`;
29
+ return NodeUtils.handleValidationErrorWithPassthrough(
30
+ node,
31
+ {
32
+ message: `Invalid inputPath "${inputPath}" (${inputPathType}): ${inputErr.message}`,
33
+ hint,
34
+ details: { inputPath, inputPathType, outputPath, outputPathType }
35
+ },
36
+ msg,
37
+ send,
38
+ done,
39
+ { originalPayload: undefined, outputPath: null, outputPathType, outputType: 'preserve' }
40
+ );
41
+ }
42
+
43
+ const imageArrayForPassthrough = Array.isArray(inputImages) ? inputImages : [inputImages];
44
+ const passthroughImage = imageArrayForPassthrough[0];
45
+
17
46
  try {
18
47
  const t0 = performance.now();
19
48
  node.status({});
20
49
 
21
- /* I/O paths */
22
- const inputPath = config.inputPath || 'payload';
23
- const outputPath = config.outputPath || 'payload';
24
50
  const outputFormat = config.outputFormat || 'raw';
25
51
  const outputQuality = parseInt(config.outputQuality) || 90;
26
52
  const pngOptimize = config.pngOptimize || false;
@@ -35,17 +61,21 @@ module.exports = function (RED) {
35
61
  const positions = config.positions || [];
36
62
 
37
63
  /* Input images array */
38
- const inputImages = RED.util.getMessageProperty(msg, inputPath);
39
- const imageArray = Array.isArray(inputImages) ? inputImages : [inputImages];
40
-
41
- // Capture first image for error passthrough
42
- const firstImage = imageArray[0];
64
+ const imageArray = imageArrayForPassthrough;
43
65
 
44
66
  // Validate input images - mosaic expects array input
45
67
  if (!NodeUtils.validateListImage(imageArray, node)) {
46
68
  return NodeUtils.handleValidationErrorWithPassthrough(
47
- node, 'Invalid image list', msg, send, done,
48
- { originalPayload: firstImage, outputPath, outputType: 'single' }
69
+ node,
70
+ {
71
+ message: 'Invalid image list',
72
+ hint: `Ensure "${inputPath}" is an array of valid images. Use the "image-in" node or pass Buffers/Raw image objects.`,
73
+ details: { inputPath, inputPathType, outputPath, outputPathType }
74
+ },
75
+ msg,
76
+ send,
77
+ done,
78
+ { originalPayload: passthroughImage, outputPath, outputPathType, outputType: 'single' }
49
79
  );
50
80
  }
51
81
 
@@ -76,7 +106,7 @@ module.exports = function (RED) {
76
106
  );
77
107
 
78
108
  /* Set output */
79
- RED.util.setMessageProperty(msg, outputPath, image);
109
+ NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, image);
80
110
 
81
111
  /* Performance status - same format as other nodes */
82
112
  const { convertMs = 0, taskMs = 0, encodeMs = 0 } = timing;
@@ -84,12 +114,13 @@ module.exports = function (RED) {
84
114
 
85
115
  // Debug image display
86
116
  let debugFormat = null;
87
- if (config.debugEnabled) {
117
+ const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
118
+ if (debugEnabled) {
88
119
  try {
89
120
  // Resolve and validate debug width
90
121
  let debugWidth = NodeUtils.resolveDimension(
91
122
  node,
92
- config.debugWidthType,
123
+ config.debugWidthType || 'num',
93
124
  config.debugWidth,
94
125
  msg
95
126
  );
@@ -100,7 +131,7 @@ module.exports = function (RED) {
100
131
  outputFormat,
101
132
  outputQuality,
102
133
  node,
103
- true,
134
+ debugEnabled,
104
135
  debugWidth
105
136
  );
106
137
 
@@ -141,7 +172,13 @@ module.exports = function (RED) {
141
172
  } catch (err) {
142
173
  NodeUtils.handleNodeErrorWithPassthrough(
143
174
  node, err, msg, send, done, 'mosaic processing',
144
- { originalPayload: firstImage, outputPath, outputType: 'single' }
175
+ {
176
+ originalPayload: passthroughImage,
177
+ outputPath,
178
+ outputPathType,
179
+ outputType: 'single',
180
+ context: { inputPath, inputPathType, outputPath, outputPathType }
181
+ }
145
182
  );
146
183
  }
147
184
  });
@@ -32,8 +32,39 @@ module.exports = function (RED) {
32
32
  const minConfidence = NodeUtils.resolveDimension(node, config.minConfidenceType, config.minConfidence, msg) || 0.5;
33
33
 
34
34
  /* Get input data */
35
- const imageData = RED.util.getMessageProperty(msg, imageInputPath);
36
- const bboxData = RED.util.getMessageProperty(msg, bboxInputPath);
35
+ const { value: imageData, error: imageErr } =
36
+ NodeUtils.safeGetMessageProperty(msg, imageInputPath);
37
+ if (imageErr) {
38
+ return NodeUtils.handleValidationErrorWithPassthrough(
39
+ node,
40
+ {
41
+ message: `Invalid imageInputPath "${imageInputPath}": ${imageErr.message}`,
42
+ hint: `Ensure "${imageInputPath}" exists on msg and contains an image (or array of images).`,
43
+ details: { imageInputPath, bboxInputPath, outputPath }
44
+ },
45
+ msg,
46
+ send,
47
+ done,
48
+ { originalPayload: [], outputPath, outputType: 'empty-array' }
49
+ );
50
+ }
51
+
52
+ const { value: bboxData, error: bboxErr } =
53
+ NodeUtils.safeGetMessageProperty(msg, bboxInputPath);
54
+ if (bboxErr) {
55
+ return NodeUtils.handleValidationErrorWithPassthrough(
56
+ node,
57
+ {
58
+ message: `Invalid bboxInputPath "${bboxInputPath}": ${bboxErr.message}`,
59
+ hint: `Ensure "${bboxInputPath}" exists on msg and contains a detection array (raw_boxes/confidence/tag).`,
60
+ details: { imageInputPath, bboxInputPath, outputPath }
61
+ },
62
+ msg,
63
+ send,
64
+ done,
65
+ { originalPayload: [], outputPath, outputType: 'empty-array' }
66
+ );
67
+ }
37
68
 
38
69
  if (!imageData) {
39
70
  return NodeUtils.handleValidationErrorWithPassthrough(
@@ -86,6 +117,22 @@ module.exports = function (RED) {
86
117
  // For now, assume single image with all detections
87
118
  // In the future, could handle multiple images with detection arrays
88
119
  const image = images[0]; // Use first image
120
+
121
+ // cropBB needs image dimensions to convert normalized boxes -> pixels.
122
+ if (!image || typeof image.width !== 'number' || typeof image.height !== 'number') {
123
+ return NodeUtils.handleValidationErrorWithPassthrough(
124
+ node,
125
+ {
126
+ message: 'cropBB requires raw images with width/height metadata',
127
+ hint: `Use the "image-in" node (raw output) before cropBB, or pass raw image objects instead of encoded Buffers.`,
128
+ details: { imageInputPath, bboxInputPath, outputPath }
129
+ },
130
+ msg,
131
+ send,
132
+ done,
133
+ { originalPayload: [], outputPath, outputType: 'empty-array' }
134
+ );
135
+ }
89
136
 
90
137
  /* Filter detections by confidence and extract bounding boxes */
91
138
  const validBboxes = [];
@@ -148,9 +195,10 @@ module.exports = function (RED) {
148
195
 
149
196
  // Debug image display for first crop if enabled
150
197
  let debugFormat = null;
151
- if (config.debugEnabled && allCrops.length > 0) {
198
+ const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
199
+ if (debugEnabled && allCrops.length > 0) {
152
200
  try {
153
- let debugWidth = NodeUtils.resolveDimension(node, config.debugWidthType, config.debugWidth, msg) || 200;
201
+ let debugWidth = NodeUtils.resolveDimension(node, config.debugWidthType || 'num', config.debugWidth, msg) || 200;
154
202
  debugWidth = Math.max(1, parseInt(debugWidth));
155
203
 
156
204
  const debugResult = await NodeUtils.debugImageDisplay(
@@ -158,7 +206,7 @@ module.exports = function (RED) {
158
206
  outputFormat,
159
207
  outputQuality,
160
208
  node,
161
- true,
209
+ debugEnabled,
162
210
  debugWidth
163
211
  );
164
212
 
@@ -16,8 +16,42 @@ module.exports = function (RED) {
16
16
  node.on('input', async (msg, send, done) => {
17
17
  // Capture images early for error passthrough
18
18
  const outputPath = config.outputPath || 'payload';
19
- const referenceImage = RED.util.getMessageProperty(msg, config.referenceImagePath || 'payload.reference');
20
- const targetImage = RED.util.getMessageProperty(msg, config.targetImagePath || 'payload.target');
19
+ const referenceImagePath = config.referenceImagePath || 'payload.reference';
20
+ const targetImagePath = config.targetImagePath || 'payload.target';
21
+
22
+ const { value: referenceImage, error: refErr } =
23
+ NodeUtils.safeGetMessageProperty(msg, referenceImagePath);
24
+ if (refErr) {
25
+ return NodeUtils.handleValidationErrorWithPassthrough(
26
+ node,
27
+ {
28
+ message: `Invalid referenceImagePath "${referenceImagePath}": ${refErr.message}`,
29
+ hint: `Ensure "${referenceImagePath}" exists on msg and contains an image.`,
30
+ details: { referenceImagePath, targetImagePath, outputPath }
31
+ },
32
+ msg,
33
+ send,
34
+ done,
35
+ { originalPayload: undefined, outputPath: null, outputType: 'preserve' }
36
+ );
37
+ }
38
+
39
+ const { value: targetImage, error: targetErr } =
40
+ NodeUtils.safeGetMessageProperty(msg, targetImagePath);
41
+ if (targetErr) {
42
+ return NodeUtils.handleValidationErrorWithPassthrough(
43
+ node,
44
+ {
45
+ message: `Invalid targetImagePath "${targetImagePath}": ${targetErr.message}`,
46
+ hint: `Ensure "${targetImagePath}" exists on msg and contains an image.`,
47
+ details: { referenceImagePath, targetImagePath, outputPath }
48
+ },
49
+ msg,
50
+ send,
51
+ done,
52
+ { originalPayload: referenceImage, outputPath, outputType: 'single' }
53
+ );
54
+ }
21
55
 
22
56
  // For error passthrough: prefer target, fallback to reference, else undefined
23
57
  const passthroughImage = targetImage || referenceImage || undefined;
@@ -55,7 +89,14 @@ module.exports = function (RED) {
55
89
  let polygon = null;
56
90
  let isPolygonArray = false;
57
91
  if (transformPolygon) {
58
- polygon = RED.util.getMessageProperty(msg, config.polygonPath || 'payload.polygon');
92
+ const polygonPath = config.polygonPath || 'payload.polygon';
93
+ const { value, error } = NodeUtils.safeGetMessageProperty(msg, polygonPath);
94
+ if (error) {
95
+ node.warn(`Invalid polygonPath "${polygonPath}": ${error.message} (polygon transform skipped)`);
96
+ polygon = null;
97
+ } else {
98
+ polygon = value;
99
+ }
59
100
 
60
101
  // Validate polygon coordinates
61
102
  if (polygon) {
@@ -221,12 +262,13 @@ module.exports = function (RED) {
221
262
 
222
263
  // Debug image display
223
264
  let debugFormat = null;
224
- if (config.debugEnabled) {
265
+ const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
266
+ if (debugEnabled) {
225
267
  try {
226
268
  // Resolve and validate debug width
227
269
  let debugWidth = NodeUtils.resolveDimension(
228
270
  node,
229
- config.debugWidthType,
271
+ config.debugWidthType || 'num',
230
272
  config.debugWidth,
231
273
  msg
232
274
  );
@@ -237,7 +279,7 @@ module.exports = function (RED) {
237
279
  outputFormat,
238
280
  outputQuality,
239
281
  node,
240
- true,
282
+ debugEnabled,
241
283
  debugWidth
242
284
  );
243
285
 
@@ -296,7 +338,12 @@ module.exports = function (RED) {
296
338
  } catch (err) {
297
339
  NodeUtils.handleNodeErrorWithPassthrough(
298
340
  node, err, msg, send, done, 'image-align processing',
299
- { originalPayload: passthroughImage, outputPath, outputType: 'single' }
341
+ {
342
+ originalPayload: passthroughImage,
343
+ outputPath,
344
+ outputType: 'single',
345
+ context: { referenceImagePath, targetImagePath, outputPath }
346
+ }
300
347
  );
301
348
  }
302
349
  });
@@ -15,10 +15,30 @@ module.exports = function (RED) {
15
15
  node.on('input', async (msg, send, done) => {
16
16
  /* rutas I/O */
17
17
  const inputPath = config.inputPath || 'payload';
18
+ const inputPathType = config.inputPathType || 'msg';
18
19
  const outputPath = config.outputPath || 'payload';
20
+ const outputPathType = config.outputPathType || 'msg';
19
21
 
20
22
  /* Capture original payload for error passthrough */
21
- const originalPayload = RED.util.getMessageProperty(msg, inputPath);
23
+ const { value: originalPayload, error: inputErr } =
24
+ NodeUtils.getInputValue(node, msg, inputPath, inputPathType);
25
+ if (inputErr) {
26
+ const hint = inputPathType === 'msg'
27
+ ? `Set inputPath to an existing msg property (e.g. "payload"), or ensure "${inputPath}" exists before this node.`
28
+ : `Set inputPath to an existing ${inputPathType} context key, or ensure "${inputPath}" exists before this node.`;
29
+ return NodeUtils.handleValidationErrorWithPassthrough(
30
+ node,
31
+ {
32
+ message: `Invalid inputPath "${inputPath}" (${inputPathType}): ${inputErr.message}`,
33
+ hint,
34
+ details: { inputPath, inputPathType, outputPath, outputPathType }
35
+ },
36
+ msg,
37
+ send,
38
+ done,
39
+ { originalPayload: undefined, outputPath: null, outputPathType, outputType: 'preserve' }
40
+ );
41
+ }
22
42
 
23
43
  try {
24
44
  const t0 = performance.now();
@@ -38,27 +58,27 @@ module.exports = function (RED) {
38
58
  if (!NodeUtils.validateListImage(originalPayload, node)) {
39
59
  return NodeUtils.handleValidationErrorWithPassthrough(
40
60
  node, 'Invalid image list structure', msg, send, done,
41
- { originalPayload, outputPath, outputType: 'preserve' }
61
+ { originalPayload, outputPath, outputPathType, outputType: 'preserve' }
42
62
  );
43
63
  }
44
64
  } else {
45
65
  if (!NodeUtils.validateSingleImage(originalPayload, node)) {
46
66
  return NodeUtils.handleValidationErrorWithPassthrough(
47
67
  node, 'Invalid image structure', msg, send, done,
48
- { originalPayload, outputPath, outputType: 'preserve' }
68
+ { originalPayload, outputPath, outputPathType, outputType: 'preserve' }
49
69
  );
50
70
  }
51
71
  }
52
72
 
53
- /* lanzar recortes en paralelo */
54
- const jobs = imgs.map(img => {
55
- const x = Number(NodeUtils.resolveDimension(node, config.cropXType, config.cropX, msg));
56
- const y = Number(NodeUtils.resolveDimension(node, config.cropYType, config.cropY, msg));
57
- const width = Number(NodeUtils.resolveDimension(node, config.widthType, config.width, msg));
58
- const height = Number(NodeUtils.resolveDimension(node, config.heightType, config.height, msg));
73
+ const x = Number(NodeUtils.resolveDimension(node, config.cropXType, config.cropX, msg));
74
+ const y = Number(NodeUtils.resolveDimension(node, config.cropYType, config.cropY, msg));
75
+ const width = Number(NodeUtils.resolveDimension(node, config.widthType, config.width, msg));
76
+ const height = Number(NodeUtils.resolveDimension(node, config.heightType, config.height, msg));
59
77
 
60
- return CppProcessor.crop(img, x, y, width, height, normalized, outputFormat, outputQuality, pngOptimize);
61
- });
78
+ /* lanzar recortes en paralelo */
79
+ const jobs = imgs.map(img =>
80
+ CppProcessor.crop(img, x, y, width, height, normalized, outputFormat, outputQuality, pngOptimize)
81
+ );
62
82
 
63
83
  const results = await Promise.all(jobs);
64
84
 
@@ -74,32 +94,33 @@ module.exports = function (RED) {
74
94
 
75
95
  /* salida */
76
96
  const out = Array.isArray(originalPayload) ? images : images[0];
77
- RED.util.setMessageProperty(msg, outputPath, out);
97
+ NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, out);
78
98
 
79
99
  /* status con mismo formato que resize/rotate */
80
100
  const dur = performance.now() - t0;
81
101
 
82
102
  // Debug image display
83
103
  let debugFormat = null;
84
- if (config.debugEnabled) {
104
+ const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
105
+ if (debugEnabled) {
85
106
  try {
86
107
  // Resolve and validate debug width
87
108
  let debugWidth = NodeUtils.resolveDimension(
88
109
  node,
89
- config.debugWidthType,
110
+ config.debugWidthType || 'num',
90
111
  config.debugWidth,
91
112
  msg
92
113
  );
93
114
  debugWidth = Math.max(1, parseInt(debugWidth) || 200); // Ensure positive, default 200
94
115
 
95
116
  // For arrays, show the first image as representative
96
- const debugImage = Array.isArray(originalPayload) ? images[0] : images[0];
117
+ const debugImage = images[0];
97
118
  const debugResult = await NodeUtils.debugImageDisplay(
98
119
  debugImage,
99
120
  outputFormat,
100
121
  outputQuality,
101
122
  node,
102
- true,
123
+ debugEnabled,
103
124
  debugWidth
104
125
  );
105
126
 
@@ -139,7 +160,7 @@ module.exports = function (RED) {
139
160
  } catch (err) {
140
161
  NodeUtils.handleNodeErrorWithPassthrough(
141
162
  node, err, msg, send, done, 'crop processing',
142
- { originalPayload, outputPath, outputType: 'preserve' }
163
+ { originalPayload, outputPath, outputPathType, outputType: 'preserve' }
143
164
  );
144
165
  }
145
166
  });
@@ -14,8 +14,28 @@ module.exports = function (RED) {
14
14
 
15
15
  node.on('input', async (msg, send, done) => {
16
16
  const inputPath = config.inputPath || 'payload';
17
+ const inputPathType = config.inputPathType || 'msg';
17
18
  const outputPath = config.outputPath || 'payload';
18
- const originalPayload = RED.util.getMessageProperty(msg, inputPath);
19
+ const outputPathType = config.outputPathType || 'msg';
20
+ const { value: originalPayload, error: inputErr } =
21
+ NodeUtils.getInputValue(node, msg, inputPath, inputPathType);
22
+ if (inputErr) {
23
+ const hint = inputPathType === 'msg'
24
+ ? `Set inputPath to an existing msg property (e.g. "payload"), or ensure "${inputPath}" exists before this node.`
25
+ : `Set inputPath to an existing ${inputPathType} context key, or ensure "${inputPath}" exists before this node.`;
26
+ return NodeUtils.handleValidationErrorWithPassthrough(
27
+ node,
28
+ {
29
+ message: `Invalid inputPath "${inputPath}" (${inputPathType}): ${inputErr.message}`,
30
+ hint,
31
+ details: { inputPath, inputPathType, outputPath, outputPathType }
32
+ },
33
+ msg,
34
+ send,
35
+ done,
36
+ { originalPayload: undefined, outputPath: null, outputPathType, outputType: 'preserve' }
37
+ );
38
+ }
19
39
 
20
40
  try {
21
41
  const startTime = performance.now();
@@ -29,7 +49,7 @@ module.exports = function (RED) {
29
49
  if (!baseImage) {
30
50
  return NodeUtils.handleValidationErrorWithPassthrough(
31
51
  node, 'Invalid image structure', msg, send, done,
32
- { originalPayload, outputPath, outputType: 'preserve' }
52
+ { originalPayload, outputPath, outputPathType, outputType: 'preserve' }
33
53
  );
34
54
  }
35
55
 
@@ -49,16 +69,17 @@ module.exports = function (RED) {
49
69
  pngOptimize
50
70
  );
51
71
 
52
- RED.util.setMessageProperty(msg, outputPath, resultImage);
72
+ NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, resultImage);
53
73
 
54
74
  const elapsed = performance.now() - startTime;
55
75
  let debugFormat = null;
56
76
 
57
- if (config.debugEnabled) {
77
+ const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
78
+ if (debugEnabled) {
58
79
  try {
59
80
  let debugWidth = NodeUtils.resolveDimension(
60
81
  node,
61
- config.debugWidthType,
82
+ config.debugWidthType || 'num',
62
83
  config.debugWidth,
63
84
  msg
64
85
  );
@@ -69,7 +90,7 @@ module.exports = function (RED) {
69
90
  outputFormat,
70
91
  outputQuality,
71
92
  node,
72
- true,
93
+ debugEnabled,
73
94
  debugWidth
74
95
  );
75
96
 
@@ -99,7 +120,7 @@ module.exports = function (RED) {
99
120
  } catch (err) {
100
121
  NodeUtils.handleNodeErrorWithPassthrough(
101
122
  node, err, msg, send, done, 'draw processing',
102
- { originalPayload, outputPath, outputType: 'preserve' }
123
+ { originalPayload, outputPath, outputPathType, outputType: 'preserve' }
103
124
  );
104
125
  }
105
126
  });
@@ -14,13 +14,34 @@ module.exports = function (RED) {
14
14
  const node = this;
15
15
 
16
16
  node.on('input', async (msg, send, done) => {
17
+ // I/O paths
18
+ const inputPath = config.inputPath || 'payload';
19
+ const inputPathType = config.inputPathType || 'msg';
20
+ const outputPath = config.outputPath || 'payload';
21
+ const outputPathType = config.outputPathType || 'msg';
22
+ const { value: originalPayload, error: inputErr } =
23
+ NodeUtils.getInputValue(node, msg, inputPath, inputPathType);
24
+ if (inputErr) {
25
+ const hint = inputPathType === 'msg'
26
+ ? `Set inputPath to an existing msg property (e.g. "payload"), or ensure "${inputPath}" exists before this node.`
27
+ : `Set inputPath to an existing ${inputPathType} context key, or ensure "${inputPath}" exists before this node.`;
28
+ return NodeUtils.handleValidationErrorWithPassthrough(
29
+ node,
30
+ {
31
+ message: `Invalid inputPath "${inputPath}" (${inputPathType}): ${inputErr.message}`,
32
+ hint,
33
+ details: { inputPath, inputPathType, outputPath, outputPathType }
34
+ },
35
+ msg,
36
+ send,
37
+ done,
38
+ { originalPayload: undefined, outputPath: null, outputPathType, outputType: 'preserve' }
39
+ );
40
+ }
41
+
17
42
  try {
18
43
  const startTime = performance.now();
19
44
  node.status({});
20
-
21
- // I/O paths
22
- const inputPath = config.inputPath || 'payload';
23
- const outputPath = config.outputPath || 'payload';
24
45
  const outputFormat = config.outputFormat || 'raw';
25
46
  const outputQuality = parseInt(config.outputQuality) || 90;
26
47
  const pngOptimize = config.pngOptimize || false;
@@ -48,22 +69,19 @@ module.exports = function (RED) {
48
69
  if (kernelSize % 2 === 0) kernelSize++; // Ensure odd size
49
70
  intensity = Math.max(0.0, Math.min(intensity, 2.0));
50
71
 
51
- // Get input image(s)
52
- const originalPayload = RED.util.getMessageProperty(msg, inputPath);
53
-
54
72
  // Validate input images
55
73
  if (Array.isArray(originalPayload)) {
56
74
  if (!NodeUtils.validateListImage(originalPayload, node)) {
57
75
  return NodeUtils.handleValidationErrorWithPassthrough(
58
76
  node, 'Invalid image list structure', msg, send, done,
59
- { originalPayload, outputPath, outputType: 'preserve' }
77
+ { originalPayload, outputPath, outputPathType, outputType: 'preserve' }
60
78
  );
61
79
  }
62
80
  } else {
63
81
  if (!NodeUtils.validateSingleImage(originalPayload, node)) {
64
82
  return NodeUtils.handleValidationErrorWithPassthrough(
65
83
  node, 'Invalid image structure', msg, send, done,
66
- { originalPayload, outputPath, outputType: 'preserve' }
84
+ { originalPayload, outputPath, outputPathType, outputType: 'preserve' }
67
85
  );
68
86
  }
69
87
  }
@@ -108,25 +126,26 @@ module.exports = function (RED) {
108
126
 
109
127
  // Debug image display
110
128
  let debugFormat = null;
111
- if (config.debugEnabled) {
129
+ const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
130
+ if (debugEnabled) {
112
131
  try {
113
132
  // Resolve and validate debug width
114
133
  let debugWidth = NodeUtils.resolveDimension(
115
134
  node,
116
- config.debugWidthType,
135
+ config.debugWidthType || 'num',
117
136
  config.debugWidth,
118
137
  msg
119
138
  );
120
139
  debugWidth = Math.max(1, parseInt(debugWidth) || 200); // Ensure positive, default 200
121
140
 
122
141
  // For arrays, show the first image as representative
123
- const debugImage = Array.isArray(originalPayload) ? images[0] : images[0];
142
+ const debugImage = images[0];
124
143
  const debugResult = await NodeUtils.debugImageDisplay(
125
144
  debugImage,
126
145
  outputFormat,
127
146
  outputQuality,
128
147
  node,
129
- true,
148
+ debugEnabled,
130
149
  debugWidth
131
150
  );
132
151
 
@@ -160,14 +179,14 @@ module.exports = function (RED) {
160
179
  }, elapsedTime);
161
180
 
162
181
  // Set output and send message
163
- RED.util.setMessageProperty(msg, outputPath, output);
182
+ NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, output);
164
183
  send(msg);
165
184
  done && done();
166
185
 
167
186
  } catch (err) {
168
187
  NodeUtils.handleNodeErrorWithPassthrough(
169
188
  node, err, msg, send, done, 'filter processing',
170
- { originalPayload, outputPath, outputType: 'preserve' }
189
+ { originalPayload, outputPath, outputPathType, outputType: 'preserve' }
171
190
  );
172
191
  }
173
192
  });