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

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 (62) 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/color-convert.html +189 -0
  16. package/node-red-contrib-image-tools/nodes/transform/color-convert.js +153 -0
  17. package/node-red-contrib-image-tools/nodes/transform/crop.js +38 -17
  18. package/node-red-contrib-image-tools/nodes/transform/draw.js +28 -7
  19. package/node-red-contrib-image-tools/nodes/transform/filter.js +34 -15
  20. package/node-red-contrib-image-tools/nodes/transform/padding.js +30 -9
  21. package/node-red-contrib-image-tools/nodes/transform/resize.js +58 -33
  22. package/node-red-contrib-image-tools/nodes/transform/rotate.html +5 -5
  23. package/node-red-contrib-image-tools/nodes/transform/rotate.js +40 -20
  24. package/node-red-contrib-image-tools/package.json +2 -8
  25. package/package.json +2 -1
  26. package/rosepetal-image-engine/binding.gyp +7 -24
  27. package/rosepetal-image-engine/src/add-mask.cpp +2 -2
  28. package/rosepetal-image-engine/src/add-masks.cpp +2 -2
  29. package/rosepetal-image-engine/src/advanced-mosaic.cpp +7 -8
  30. package/rosepetal-image-engine/src/blend.cpp +2 -2
  31. package/rosepetal-image-engine/src/color-convert.cpp +184 -0
  32. package/rosepetal-image-engine/src/concat.cpp +4 -4
  33. package/rosepetal-image-engine/src/crop.cpp +7 -7
  34. package/rosepetal-image-engine/src/draw.cpp +1 -1
  35. package/rosepetal-image-engine/src/filter.cpp +7 -7
  36. package/rosepetal-image-engine/src/image-align.cpp +1 -1
  37. package/rosepetal-image-engine/src/main.cpp +2 -0
  38. package/rosepetal-image-engine/src/mosaic.cpp +8 -9
  39. package/rosepetal-image-engine/src/padding.cpp +8 -7
  40. package/rosepetal-image-engine/src/resize.cpp +105 -27
  41. package/rosepetal-image-engine/src/rotate.cpp +9 -12
  42. package/rosepetal-image-engine/src/utils.h +48 -10
  43. package/docs/nodes/io/array-in.md +0 -119
  44. package/docs/nodes/io/array-out.md +0 -150
  45. package/docs/nodes/io/array-select.md +0 -157
  46. package/docs/nodes/io/queue.md +0 -57
  47. package/docs/nodes/io/save-file.md +0 -30
  48. package/docs/nodes/util/block-detect.md +0 -46
  49. package/node-red-contrib-image-tools/nodes/io/array-in.html +0 -110
  50. package/node-red-contrib-image-tools/nodes/io/array-in.js +0 -113
  51. package/node-red-contrib-image-tools/nodes/io/array-out.html +0 -125
  52. package/node-red-contrib-image-tools/nodes/io/array-out.js +0 -213
  53. package/node-red-contrib-image-tools/nodes/io/array-select.html +0 -156
  54. package/node-red-contrib-image-tools/nodes/io/array-select.js +0 -187
  55. package/node-red-contrib-image-tools/nodes/io/queue.html +0 -119
  56. package/node-red-contrib-image-tools/nodes/io/queue.js +0 -191
  57. package/node-red-contrib-image-tools/nodes/io/save-file.html +0 -243
  58. package/node-red-contrib-image-tools/nodes/io/save-file.js +0 -440
  59. package/node-red-contrib-image-tools/nodes/util/block-detect.html +0 -85
  60. package/node-red-contrib-image-tools/nodes/util/block-detect.js +0 -136
  61. package/node-red-contrib-image-tools/nodes/util/clean-debug.html +0 -201
  62. package/node-red-contrib-image-tools/nodes/util/clean-debug.js +0 -393
@@ -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
  });
@@ -15,10 +15,30 @@ module.exports = function (RED) {
15
15
  node.on('input', async (msg, send, done) => {
16
16
  /* paths */
17
17
  const inPath = cfg.inputPath || 'payload';
18
+ const inputPathType = cfg.inputPathType || 'msg';
18
19
  const outPath = cfg.outputPath || 'payload';
20
+ const outputPathType = cfg.outputPathType || 'msg';
19
21
 
20
22
  /* image / array - capture original for error passthrough */
21
- const originalPayload = RED.util.getMessageProperty(msg, inPath);
23
+ const { value: originalPayload, error: inputErr } =
24
+ NodeUtils.getInputValue(node, msg, inPath, inputPathType);
25
+ if (inputErr) {
26
+ const hint = inputPathType === 'msg'
27
+ ? `Set inputPath to an existing msg property (e.g. "payload"), or ensure "${inPath}" exists before this node.`
28
+ : `Set inputPath to an existing ${inputPathType} context key, or ensure "${inPath}" exists before this node.`;
29
+ return NodeUtils.handleValidationErrorWithPassthrough(
30
+ node,
31
+ {
32
+ message: `Invalid inputPath "${inPath}" (${inputPathType}): ${inputErr.message}`,
33
+ hint,
34
+ details: { inputPath: inPath, inputPathType, outputPath: outPath, 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();
@@ -29,14 +49,14 @@ module.exports = function (RED) {
29
49
  if (!NodeUtils.validateListImage(originalPayload, node)) {
30
50
  return NodeUtils.handleValidationErrorWithPassthrough(
31
51
  node, 'Invalid image list structure', msg, send, done,
32
- { originalPayload, outputPath: outPath, outputType: 'preserve' }
52
+ { originalPayload, outputPath: outPath, outputPathType, outputType: 'preserve' }
33
53
  );
34
54
  }
35
55
  } else {
36
56
  if (!NodeUtils.validateSingleImage(originalPayload, node)) {
37
57
  return NodeUtils.handleValidationErrorWithPassthrough(
38
58
  node, 'Invalid image structure', msg, send, done,
39
- { originalPayload, outputPath: outPath, outputType: 'preserve' }
59
+ { originalPayload, outputPath: outPath, outputPathType, outputType: 'preserve' }
40
60
  );
41
61
  }
42
62
  }
@@ -70,30 +90,31 @@ module.exports = function (RED) {
70
90
  return r.image;
71
91
  });
72
92
 
73
- RED.util.setMessageProperty(msg, outPath, Array.isArray(originalPayload) ? outImgs : outImgs[0]);
93
+ NodeUtils.setOutputValue(node, msg, outPath, outputPathType, Array.isArray(originalPayload) ? outImgs : outImgs[0]);
74
94
 
75
95
  // Debug image display
76
96
  const elapsedTime = performance.now() - t0;
77
97
  let debugFormat = null;
78
- if (cfg.debugEnabled) {
98
+ const debugEnabled = cfg.debugEnabled === true || cfg.debugEnabled === 'true';
99
+ if (debugEnabled) {
79
100
  try {
80
101
  // Resolve and validate debug width
81
102
  let debugWidth = NodeUtils.resolveDimension(
82
103
  node,
83
- cfg.debugWidthType,
104
+ cfg.debugWidthType || 'num',
84
105
  cfg.debugWidth,
85
106
  msg
86
107
  );
87
108
  debugWidth = Math.max(1, parseInt(debugWidth) || 200); // Ensure positive, default 200
88
109
 
89
110
  // For arrays, show the first image as representative
90
- const debugImage = Array.isArray(originalPayload) ? outImgs[0] : outImgs[0];
111
+ const debugImage = outImgs[0];
91
112
  const debugResult = await NodeUtils.debugImageDisplay(
92
113
  debugImage,
93
114
  outputFormat,
94
115
  outputQuality,
95
116
  node,
96
- true,
117
+ debugEnabled,
97
118
  debugWidth
98
119
  );
99
120
 
@@ -132,7 +153,7 @@ module.exports = function (RED) {
132
153
  } catch (err) {
133
154
  NodeUtils.handleNodeErrorWithPassthrough(
134
155
  node, err, msg, send, done, 'padding processing',
135
- { originalPayload, outputPath: outPath, outputType: 'preserve' }
156
+ { originalPayload, outputPath: outPath, outputPathType, outputType: 'preserve' }
136
157
  );
137
158
  }
138
159
  });
@@ -14,16 +14,36 @@ module.exports = function (RED) {
14
14
  const node = this;
15
15
 
16
16
  node.on('input', async (msg, send, done) => {
17
+ const inputPath = config.inputPath || 'payload';
18
+ const inputPathType = config.inputPathType || 'msg';
19
+ const outputPath = config.outputPath || 'payload';
20
+ const outputPathType = config.outputPathType || 'msg';
21
+ const { value: originalPayload, error: inputErr } =
22
+ NodeUtils.getInputValue(node, msg, inputPath, inputPathType);
23
+ if (inputErr) {
24
+ const hint = inputPathType === 'msg'
25
+ ? `Set inputPath to an existing msg property (e.g. "payload"), or ensure "${inputPath}" exists before this node.`
26
+ : `Set inputPath to an existing ${inputPathType} context key, or ensure "${inputPath}" exists before this node.`;
27
+ return NodeUtils.handleValidationErrorWithPassthrough(
28
+ node,
29
+ {
30
+ message: `Invalid inputPath "${inputPath}" (${inputPathType}): ${inputErr.message}`,
31
+ hint,
32
+ details: { inputPath, inputPathType, outputPath, outputPathType }
33
+ },
34
+ msg,
35
+ send,
36
+ done,
37
+ { originalPayload: undefined, outputPath: null, outputPathType, outputType: 'preserve' }
38
+ );
39
+ }
40
+
17
41
  try {
18
42
  const startTime = performance.now();
19
43
  node.status({});
20
- const inputPath = config.inputPath || 'payload';
21
- const outputPath = config.outputPath || 'payload';
22
44
  const outputFormat = config.outputFormat || 'raw';
23
45
  const outputQuality = parseInt(config.outputQuality) || 90;
24
46
  const pngOptimize = config.pngOptimize || false;
25
-
26
- const originalPayload = RED.util.getMessageProperty(msg, inputPath);
27
47
  const inputList = Array.isArray(originalPayload)
28
48
  ? originalPayload
29
49
  : [originalPayload];
@@ -33,47 +53,51 @@ module.exports = function (RED) {
33
53
  if (!NodeUtils.validateListImage(originalPayload, node)) {
34
54
  return NodeUtils.handleValidationErrorWithPassthrough(
35
55
  node, 'Invalid image list structure', msg, send, done,
36
- { originalPayload, outputPath, outputType: 'preserve' }
56
+ { originalPayload, outputPath, outputPathType, outputType: 'preserve' }
37
57
  );
38
58
  }
39
59
  } else {
40
60
  if (!NodeUtils.validateSingleImage(originalPayload, node)) {
41
61
  return NodeUtils.handleValidationErrorWithPassthrough(
42
62
  node, 'Invalid image structure', msg, send, done,
43
- { originalPayload, outputPath, outputType: 'preserve' }
63
+ { originalPayload, outputPath, outputPathType, outputType: 'preserve' }
44
64
  );
45
65
  }
46
66
  }
47
67
 
48
- const promises = inputList.map((inputImage) => {
49
- // Resolve dimension values (can come from msg/flow/global)
50
- let wVal = NodeUtils.resolveDimension(
51
- node,
52
- config.widthType,
53
- config.widthValue,
54
- msg
55
- );
56
- let hVal = NodeUtils.resolveDimension(
57
- node,
58
- config.heightType,
59
- config.heightValue,
60
- msg
61
- );
68
+ // Resolve dimension values once per message (can come from msg/flow/global)
69
+ let wVal = NodeUtils.resolveDimension(
70
+ node,
71
+ config.widthType,
72
+ config.widthValue,
73
+ msg
74
+ );
75
+ let hVal = NodeUtils.resolveDimension(
76
+ node,
77
+ config.heightType,
78
+ config.heightValue,
79
+ msg
80
+ );
81
+
82
+ // Convert to Number; use 0 as "Auto" sentinel for the native addon.
83
+ // (NaN is unsafe with -ffast-math builds and can lead to huge allocations.)
84
+ wVal = wVal === null || wVal === '' ? 0 : Number(wVal);
85
+ hVal = hVal === null || hVal === '' ? 0 : Number(hVal);
62
86
 
63
- // Convert to Number or NaN (C++ interprets NaN as "Auto")
64
- wVal = wVal === null || wVal === '' ? NaN : Number(wVal);
65
- hVal = hVal === null || hVal === '' ? NaN : Number(hVal);
87
+ if (!Number.isFinite(wVal) || !Number.isFinite(hVal)) {
88
+ throw new Error('Resize width/height must be finite numbers');
89
+ }
66
90
 
67
- // Direct call to addon: (image, wMode, wVal, hMode, hVal, outputFormat, quality, pngOptimize)
68
- return CppProcessor.resize(
91
+ const promises = inputList.map((inputImage) =>
92
+ CppProcessor.resize(
69
93
  inputImage,
70
94
  config.widthMode, wVal,
71
95
  config.heightMode, hVal,
72
96
  outputFormat,
73
97
  outputQuality,
74
98
  pngOptimize
75
- );
76
- });
99
+ )
100
+ );
77
101
  const results = await Promise.all(promises);
78
102
 
79
103
  // Aggregate timings and prepare output
@@ -94,25 +118,26 @@ module.exports = function (RED) {
94
118
 
95
119
  // Debug image display
96
120
  let debugFormat = null;
97
- if (config.debugEnabled) {
121
+ const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
122
+ if (debugEnabled) {
98
123
  try {
99
124
  // Resolve and validate debug width
100
125
  let debugWidth = NodeUtils.resolveDimension(
101
126
  node,
102
- config.debugWidthType,
127
+ config.debugWidthType || 'num',
103
128
  config.debugWidth,
104
129
  msg
105
130
  );
106
131
  debugWidth = Math.max(1, parseInt(debugWidth) || 200); // Ensure positive, default 200
107
132
 
108
133
  // For arrays, show the first image as representative
109
- const debugImage = Array.isArray(originalPayload) ? images[0] : images[0];
134
+ const debugImage = images[0];
110
135
  const debugResult = await NodeUtils.debugImageDisplay(
111
136
  debugImage,
112
137
  outputFormat,
113
138
  outputQuality,
114
139
  node,
115
- true,
140
+ debugEnabled,
116
141
  debugWidth
117
142
  );
118
143
 
@@ -145,14 +170,14 @@ module.exports = function (RED) {
145
170
  taskMs: totalTaskMs
146
171
  }, elapsedTime);
147
172
 
148
- RED.util.setMessageProperty(msg, outputPath, out);
173
+ NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, out);
149
174
 
150
175
  send(msg);
151
176
  done && done();
152
177
  } catch (err) {
153
178
  NodeUtils.handleNodeErrorWithPassthrough(
154
179
  node, err, msg, send, done, 'resize processing',
155
- { originalPayload, outputPath, outputType: 'preserve' }
180
+ { originalPayload, outputPath, outputPathType, outputType: 'preserve' }
156
181
  );
157
182
  }
158
183
  });
@@ -226,7 +226,7 @@
226
226
  <p>Rotates images by a specified angle with customizable padding color using high-performance C++ processing.</p>
227
227
 
228
228
  <h3>Details</h3>
229
- <p>This node rotates images clockwise by a specified angle in degrees. When rotation creates areas outside the original image bounds, these areas are filled with the specified padding color. The rotation operation supports both single images and arrays, with dynamic angle values from various sources.</p>
229
+ <p>This node rotates images counter-clockwise by a specified angle in degrees. When rotation creates areas outside the original image bounds, these areas are filled with the specified padding color. The rotation operation supports both single images and arrays, with dynamic angle values from various sources.</p>
230
230
 
231
231
  <h3>Properties</h3>
232
232
  <dl class="message-properties">
@@ -239,7 +239,7 @@
239
239
  <dt>Quality <span class="property-type">number</span></dt>
240
240
  <dd>Compression quality for JPEG and WebP formats (1-100). Only visible when jpg or webp format is selected. Default: 90.</dd>
241
241
  <dt>Angle <span class="property-type">number|string</span></dt>
242
- <dd>Rotation angle in degrees (clockwise). Can be a fixed number or dynamic value from msg property, flow, or global context. Supports decimal values.</dd>
242
+ <dd>Rotation angle in degrees (counter-clockwise). Can be a fixed number or dynamic value from msg property, flow, or global context. Supports decimal values.</dd>
243
243
  <dt>Pad Color <span class="property-type">string</span></dt>
244
244
  <dd>Color to fill areas created by rotation, specified as hexadecimal color (#RRGGBB). Default: #000000 (black).</dd>
245
245
  </dl>
@@ -258,7 +258,7 @@
258
258
 
259
259
  <h3>Rotation Behavior</h3>
260
260
  <ul>
261
- <li><strong>Direction:</strong> Clockwise rotation (positive angles)</li>
261
+ <li><strong>Direction:</strong> Counter-clockwise rotation (positive angles)</li>
262
262
  <li><strong>Angle Range:</strong> Any angle supported (0-360° and beyond)</li>
263
263
  <li><strong>Padding:</strong> Areas outside original bounds filled with specified color</li>
264
264
  <li><strong>Precision:</strong> Decimal angles supported (e.g., 45.5°, 30.25°)</li>
@@ -267,8 +267,8 @@
267
267
 
268
268
  <h3>Examples</h3>
269
269
  <ul>
270
- <li><strong>90° Rotation:</strong> Angle: 90 → Image rotated 90° clockwise</li>
271
- <li><strong>Custom Angle:</strong> Angle: 45.5 → Image rotated 45.5° clockwise</li>
270
+ <li><strong>90° Rotation:</strong> Angle: 90 → Image rotated 90° counter-clockwise</li>
271
+ <li><strong>Custom Angle:</strong> Angle: 45.5 → Image rotated 45.5° counter-clockwise</li>
272
272
  <li><strong>Dynamic Angle:</strong> Angle: msg.rotationAngle → Use angle from message property</li>
273
273
  <li><strong>White Padding:</strong> Pad Color: #FFFFFF → White background for rotated areas</li>
274
274
  <li><strong>Transparent Padding:</strong> For RGBA images, use appropriate color with alpha channel</li>