@rosepetal/node-red-contrib-image-tools 1.2.0 → 1.2.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.
Files changed (48) hide show
  1. package/node-red-contrib-image-tools/lib/node-utils.js +64 -0
  2. package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +23 -0
  3. package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +8 -2
  4. package/node-red-contrib-image-tools/nodes/blend/add-mask.html +24 -1
  5. package/node-red-contrib-image-tools/nodes/blend/add-mask.js +13 -7
  6. package/node-red-contrib-image-tools/nodes/blend/add-masks.html +23 -0
  7. package/node-red-contrib-image-tools/nodes/blend/add-masks.js +8 -2
  8. package/node-red-contrib-image-tools/nodes/blend/blend.html +24 -1
  9. package/node-red-contrib-image-tools/nodes/blend/blend.js +8 -2
  10. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +23 -0
  11. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +9 -3
  12. package/node-red-contrib-image-tools/nodes/mix/concat.html +24 -1
  13. package/node-red-contrib-image-tools/nodes/mix/concat.js +8 -2
  14. package/node-red-contrib-image-tools/nodes/mix/mosaic.html +23 -0
  15. package/node-red-contrib-image-tools/nodes/mix/mosaic.js +8 -2
  16. package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +24 -1
  17. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +9 -1
  18. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +25 -2
  19. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +7 -1
  20. package/node-red-contrib-image-tools/nodes/transform/color-convert.html +213 -0
  21. package/node-red-contrib-image-tools/nodes/transform/color-convert.js +161 -0
  22. package/node-red-contrib-image-tools/nodes/transform/crop.html +25 -1
  23. package/node-red-contrib-image-tools/nodes/transform/crop.js +9 -1
  24. package/node-red-contrib-image-tools/nodes/transform/draw.html +24 -0
  25. package/node-red-contrib-image-tools/nodes/transform/draw.js +8 -2
  26. package/node-red-contrib-image-tools/nodes/transform/filter.html +25 -1
  27. package/node-red-contrib-image-tools/nodes/transform/filter.js +9 -1
  28. package/node-red-contrib-image-tools/nodes/transform/padding.html +25 -1
  29. package/node-red-contrib-image-tools/nodes/transform/padding.js +9 -1
  30. package/node-red-contrib-image-tools/nodes/transform/resize.html +26 -2
  31. package/node-red-contrib-image-tools/nodes/transform/resize.js +9 -1
  32. package/node-red-contrib-image-tools/nodes/transform/rotate.html +30 -6
  33. package/node-red-contrib-image-tools/nodes/transform/rotate.js +9 -1
  34. package/node-red-contrib-image-tools/package.json +1 -0
  35. package/package.json +2 -1
  36. package/rosepetal-image-engine/binding.gyp +2 -1
  37. package/rosepetal-image-engine/src/advanced-mosaic.cpp +4 -4
  38. package/rosepetal-image-engine/src/color-convert.cpp +184 -0
  39. package/rosepetal-image-engine/src/concat.cpp +2 -2
  40. package/rosepetal-image-engine/src/crop.cpp +4 -4
  41. package/rosepetal-image-engine/src/filter.cpp +4 -4
  42. package/rosepetal-image-engine/src/image-align.cpp +1 -1
  43. package/rosepetal-image-engine/src/main.cpp +2 -0
  44. package/rosepetal-image-engine/src/mosaic.cpp +4 -4
  45. package/rosepetal-image-engine/src/padding.cpp +4 -4
  46. package/rosepetal-image-engine/src/resize.cpp +4 -4
  47. package/rosepetal-image-engine/src/rotate.cpp +6 -6
  48. package/rosepetal-image-engine/src/utils.h +2 -2
@@ -344,6 +344,70 @@ module.exports = function(RED) {
344
344
  return numericValue;
345
345
  }
346
346
 
347
+ /**
348
+ * Returns true when any advanced WebP option is explicitly set in the node config.
349
+ * When false the fast C++ encoding path is used unchanged.
350
+ */
351
+ utils.hasAdvancedWebpOptions = function(config) {
352
+ if (!config) return false;
353
+ if (config.webpLossless === true || config.webpLossless === 'true') return true;
354
+ if (config.webpSmartSubsample === true || config.webpSmartSubsample === 'true') return true;
355
+ if (config.webpEffort !== undefined && config.webpEffort !== '' && config.webpEffort !== null) return true;
356
+ return false;
357
+ }
358
+
359
+ /**
360
+ * Builds a Sharp `.webp()` options object from node config.
361
+ */
362
+ utils.buildWebpOptions = function(config) {
363
+ const opts = {};
364
+ const quality = parseInt(config.outputQuality);
365
+ if (Number.isFinite(quality) && quality >= 1 && quality <= 100) opts.quality = quality;
366
+ else opts.quality = CONSTANTS.DEFAULT_JPEG_QUALITY;
367
+
368
+ if (config.webpLossless === true || config.webpLossless === 'true') opts.lossless = true;
369
+ if (config.webpSmartSubsample === true || config.webpSmartSubsample === 'true') opts.smartSubsample = true;
370
+ const effort = parseInt(config.webpEffort);
371
+ if (Number.isFinite(effort) && effort >= 0 && effort <= 6) opts.effort = effort;
372
+ return opts;
373
+ }
374
+
375
+ /**
376
+ * Encodes a raw image object to WebP via Sharp with advanced options.
377
+ * Modeled on rawToJpeg() — performs BGR→RGB swap and feeds Sharp.
378
+ */
379
+ utils.encodeWebpAdvanced = async function(image, config) {
380
+ if (!sharp) {
381
+ throw new Error('Sharp is not available. Install "sharp" in your Node-RED userDir and restart Node-RED.');
382
+ }
383
+ const normalized = utils.validateImageStructure(image, { warn: () => {} });
384
+ if (!normalized)
385
+ throw new Error('Invalid raw image object supplied to encodeWebpAdvanced');
386
+
387
+ const colorSpace = normalized.colorSpace;
388
+ const channels = normalized.channels;
389
+ let data = normalized.data;
390
+
391
+ // BGR/BGRA → RGB/RGBA for Sharp
392
+ if (colorSpace === 'BGR' || colorSpace === 'BGRA') {
393
+ data = Buffer.from(data);
394
+ for (let i = 0; i < data.length; i += channels) {
395
+ const t = data[i];
396
+ data[i] = data[i + 2];
397
+ data[i + 2] = t;
398
+ }
399
+ }
400
+
401
+ const sh = sharp(data, {
402
+ raw: { width: normalized.width, height: normalized.height, channels }
403
+ });
404
+
405
+ if (colorSpace === 'GRAY') sh.toColourspace('b-w');
406
+
407
+ const webpOpts = utils.buildWebpOptions(config);
408
+ return sh.webp(webpOpts).toBuffer();
409
+ }
410
+
347
411
  utils.rawToJpeg = async function (image, quality = CONSTANTS.DEFAULT_JPEG_QUALITY) {
348
412
  if (!sharp) {
349
413
  throw new Error('Sharp is not available. Install "sharp" in your Node-RED userDir and restart Node-RED.');
@@ -13,6 +13,9 @@
13
13
  outputFormat:{value:"raw"},
14
14
  outputQuality:{value:90},
15
15
  pngOptimize:{value:false},
16
+ webpLossless:{value:false},
17
+ webpSmartSubsample:{value:false},
18
+ webpEffort:{value:""},
16
19
  // Debug configuration
17
20
  debugEnabled:{value:false},
18
21
  debugWidth:{value:200},
@@ -72,6 +75,11 @@
72
75
  const format = $("#node-input-outputFormat").val();
73
76
  $("#quality-row").toggle(format === "jpg" || format === "webp");
74
77
  $("#png-optimize-row").toggle(format === "png");
78
+ // Show WebP advanced options only when WebP is selected
79
+ const isWebp = format === 'webp';
80
+ $("#webp-lossless-row").toggle(isWebp);
81
+ $("#webp-smartsubsample-row").toggle(isWebp);
82
+ $("#webp-effort-row").toggle(isWebp);
75
83
  }
76
84
  $("#node-input-outputFormat").on("change", updateQualityVisibility);
77
85
  updateQualityVisibility();
@@ -435,6 +443,21 @@
435
443
  <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
436
444
  <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
437
445
  </div>
446
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
447
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
448
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
449
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
450
+ </div>
451
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
452
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
453
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
454
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
455
+ </div>
456
+ <div class="form-row" id="webp-effort-row" style="display: none;">
457
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
458
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
459
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
460
+ </div>
438
461
 
439
462
  <!-- Debug Configuration -->
440
463
  <div class="form-row">
@@ -201,6 +201,8 @@ module.exports = function (RED) {
201
201
  const outputFormat = config.outputFormat || 'raw';
202
202
  const outputQuality = parseInt(config.outputQuality) || 90;
203
203
  const pngOptimize = config.pngOptimize || false;
204
+ const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
205
+ const cppFormat = useSharpWebp ? 'raw' : outputFormat;
204
206
 
205
207
  // Build class color map from configuration
206
208
  const classColorMap = {};
@@ -213,7 +215,7 @@ module.exports = function (RED) {
213
215
  }
214
216
 
215
217
  /* ▸ Single call to the C++ addon --------------------------------- */
216
- const { image: result, timing = {}, boxCount } =
218
+ let { image: result, timing = {}, boxCount } =
217
219
  await Cpp.addBBs(
218
220
  baseImg,
219
221
  boxesArray, // Pass direct array to C++
@@ -225,11 +227,15 @@ module.exports = function (RED) {
225
227
  fontSize,
226
228
  'above', // Always position labels above the box
227
229
  labelBackground,
228
- outputFormat,
230
+ cppFormat,
229
231
  outputQuality,
230
232
  pngOptimize
231
233
  );
232
234
 
235
+ if (useSharpWebp) {
236
+ result = await NodeUtils.encodeWebpAdvanced(result, config);
237
+ }
238
+
233
239
  /* ▸ Write the result back to msg ---------------------------------- */
234
240
  RED.util.setMessageProperty(msg, config.outputPath || 'payload', result);
235
241
 
@@ -13,6 +13,9 @@
13
13
  outputFormat:{value:"raw"},
14
14
  outputQuality:{value:90},
15
15
  pngOptimize:{value:false},
16
+ webpLossless:{value:false},
17
+ webpSmartSubsample:{value:false},
18
+ webpEffort:{value:""},
16
19
  // Debug configuration
17
20
  debugEnabled:{value:false},
18
21
  debugWidth:{value:200},
@@ -63,6 +66,11 @@
63
66
  const format = $("#node-input-outputFormat").val();
64
67
  $("#quality-row").toggle(format === "jpg" || format === "webp");
65
68
  $("#png-optimize-row").toggle(format === "png");
69
+ // Show WebP advanced options only when WebP is selected
70
+ const isWebp = format === 'webp';
71
+ $("#webp-lossless-row").toggle(isWebp);
72
+ $("#webp-smartsubsample-row").toggle(isWebp);
73
+ $("#webp-effort-row").toggle(isWebp);
66
74
  }
67
75
  $("#node-input-outputFormat").on("change", updateQualityVisibility);
68
76
  updateQualityVisibility(); // initial state
@@ -250,7 +258,22 @@
250
258
  <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
251
259
  <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
252
260
  </div>
253
-
261
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
262
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
263
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
264
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
265
+ </div>
266
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
267
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
268
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
269
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
270
+ </div>
271
+ <div class="form-row" id="webp-effort-row" style="display: none;">
272
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
273
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
274
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
275
+ </div>
276
+
254
277
  <!-- Debug Configuration -->
255
278
  <div class="form-row">
256
279
  <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
@@ -152,7 +152,9 @@ module.exports = function (RED) {
152
152
  const outputFormat = config.outputFormat || 'raw';
153
153
  const outputQuality = parseInt(config.outputQuality) || 90;
154
154
  const pngOptimize = config.pngOptimize || false;
155
-
155
+ const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
156
+ const cppFormat = useSharpWebp ? 'raw' : outputFormat;
157
+
156
158
  // Color processing
157
159
  const fillColor = config.fillColor || '#ffffff';
158
160
 
@@ -165,17 +167,21 @@ module.exports = function (RED) {
165
167
  }
166
168
 
167
169
  /* ▸ Single call to the C++ addon --------------------------------- */
168
- const { image: result, timing = {} } =
170
+ let { image: result, timing = {} } =
169
171
  await Cpp.addMask(
170
- baseImg,
171
- polygon,
172
- maskStrength,
172
+ baseImg,
173
+ polygon,
174
+ maskStrength,
173
175
  fillR, fillG, fillB,
174
- outputFormat,
175
- outputQuality,
176
+ cppFormat,
177
+ outputQuality,
176
178
  pngOptimize
177
179
  );
178
180
 
181
+ if (useSharpWebp) {
182
+ result = await NodeUtils.encodeWebpAdvanced(result, config);
183
+ }
184
+
179
185
  /* ▸ Write the result back to msg ---------------------------------- */
180
186
  RED.util.setMessageProperty(msg, config.outputPath || 'payload', result);
181
187
 
@@ -13,6 +13,9 @@
13
13
  outputFormat:{value:"raw"},
14
14
  outputQuality:{value:90},
15
15
  pngOptimize:{value:false},
16
+ webpLossless:{value:false},
17
+ webpSmartSubsample:{value:false},
18
+ webpEffort:{value:""},
16
19
  // Debug configuration
17
20
  debugEnabled:{value:false},
18
21
  debugWidth:{value:200},
@@ -65,6 +68,11 @@
65
68
  const format = $("#node-input-outputFormat").val();
66
69
  $("#quality-row").toggle(format === "jpg" || format === "webp");
67
70
  $("#png-optimize-row").toggle(format === "png");
71
+ // Show WebP advanced options only when WebP is selected
72
+ const isWebp = format === 'webp';
73
+ $("#webp-lossless-row").toggle(isWebp);
74
+ $("#webp-smartsubsample-row").toggle(isWebp);
75
+ $("#webp-effort-row").toggle(isWebp);
68
76
  }
69
77
  $("#node-input-outputFormat").on("change", updateQualityVisibility);
70
78
  updateQualityVisibility(); // initial state
@@ -579,6 +587,21 @@
579
587
  <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
580
588
  <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
581
589
  </div>
590
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
591
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
592
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
593
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
594
+ </div>
595
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
596
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
597
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
598
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
599
+ </div>
600
+ <div class="form-row" id="webp-effort-row" style="display: none;">
601
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
602
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
603
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
604
+ </div>
582
605
 
583
606
  <!-- Debug Configuration -->
584
607
  <div class="form-row">
@@ -283,6 +283,8 @@ module.exports = function (RED) {
283
283
  const outputFormat = config.outputFormat || 'raw';
284
284
  const outputQuality = parseInt(config.outputQuality) || 90;
285
285
  const pngOptimize = config.pngOptimize || false;
286
+ const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
287
+ const cppFormat = useSharpWebp ? 'raw' : outputFormat;
286
288
 
287
289
  // Build class color map and priority order from configuration
288
290
  const classColorMap = {};
@@ -298,7 +300,7 @@ module.exports = function (RED) {
298
300
  }
299
301
 
300
302
  /* ▸ Single call to the C++ addon --------------------------------- */
301
- const { image: result, timing = {} } =
303
+ let { image: result, timing = {} } =
302
304
  await Cpp.addMasks(
303
305
  baseImg,
304
306
  masksArray,
@@ -306,11 +308,15 @@ module.exports = function (RED) {
306
308
  classPriorityOrder, // Priority order for overlap resolution
307
309
  maskStrength,
308
310
  true, // Always auto-generate colors for undefined classes
309
- outputFormat,
311
+ cppFormat,
310
312
  outputQuality,
311
313
  pngOptimize
312
314
  );
313
315
 
316
+ if (useSharpWebp) {
317
+ result = await NodeUtils.encodeWebpAdvanced(result, config);
318
+ }
319
+
314
320
  /* ▸ Write the result back to msg ---------------------------------- */
315
321
  RED.util.setMessageProperty(msg, config.outputPath || 'payload', result);
316
322
 
@@ -13,6 +13,9 @@
13
13
  outputFormat:{value:"raw"},
14
14
  outputQuality:{value:90},
15
15
  pngOptimize:{value:false},
16
+ webpLossless:{value:false},
17
+ webpSmartSubsample:{value:false},
18
+ webpEffort:{value:""},
16
19
  // Debug configuration
17
20
  debugEnabled:{value:false},
18
21
  debugWidth:{value:200},
@@ -116,6 +119,11 @@
116
119
  const format = $("#node-input-outputFormat").val();
117
120
  $("#quality-row").toggle(format === "jpg" || format === "webp");
118
121
  $("#png-optimize-row").toggle(format === "png");
122
+ // Show WebP advanced options only when WebP is selected
123
+ const isWebp = format === 'webp';
124
+ $("#webp-lossless-row").toggle(isWebp);
125
+ $("#webp-smartsubsample-row").toggle(isWebp);
126
+ $("#webp-effort-row").toggle(isWebp);
119
127
  }
120
128
  $("#node-input-outputFormat").on("change", updateQualityVisibility);
121
129
  updateQualityVisibility(); // initial state
@@ -303,7 +311,22 @@
303
311
  <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
304
312
  <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
305
313
  </div>
306
-
314
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
315
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
316
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
317
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
318
+ </div>
319
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
320
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
321
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
322
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
323
+ </div>
324
+ <div class="form-row" id="webp-effort-row" style="display: none;">
325
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
326
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
327
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
328
+ </div>
329
+
307
330
  <!-- Debug Configuration -->
308
331
  <div class="form-row">
309
332
  <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
@@ -102,16 +102,22 @@ module.exports = function (RED) {
102
102
  const outputFormat = config.outputFormat || 'raw';
103
103
  const outputQuality = parseInt(config.outputQuality) || 90;
104
104
  const pngOptimize = config.pngOptimize || false;
105
+ const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
106
+ const cppFormat = useSharpWebp ? 'raw' : outputFormat;
105
107
  const alphaCompositing = config.alphaCompositing || false;
106
108
  const removeBackground = config.removeBackground || false;
107
109
  const backgroundColor = config.backgroundColor || '#ffffff';
108
110
  const colorTolerance = Math.max(0, Math.min(100, parseInt(config.colorTolerance) || 10)) / 100.0;
109
111
 
110
112
  /* ▸ Single call to the C++ addon --------------------------------- */
111
- const { image, timing = {} } =
112
- await Cpp.blend(img1, img2, opacity, outputFormat, outputQuality, pngOptimize,
113
+ let { image, timing = {} } =
114
+ await Cpp.blend(img1, img2, opacity, cppFormat, outputQuality, pngOptimize,
113
115
  alphaCompositing, removeBackground, backgroundColor, colorTolerance);
114
116
 
117
+ if (useSharpWebp) {
118
+ image = await NodeUtils.encodeWebpAdvanced(image, config);
119
+ }
120
+
115
121
  /* ▸ Write the result back to msg ---------------------------------- */
116
122
  RED.util.setMessageProperty(msg, config.outputPath || 'payload', image);
117
123
 
@@ -15,6 +15,9 @@
15
15
  outputFormat:{value:"raw"},
16
16
  outputQuality:{value:90},
17
17
  pngOptimize:{value:false},
18
+ webpLossless:{value:false},
19
+ webpSmartSubsample:{value:false},
20
+ webpEffort:{value:""},
18
21
  // Debug configuration
19
22
  debugEnabled:{value:false},
20
23
  debugWidth:{value:200},
@@ -74,6 +77,11 @@
74
77
  const format = $("#node-input-outputFormat").val();
75
78
  $("#quality-row").toggle(format === "jpg" || format === "webp");
76
79
  $("#png-optimize-row").toggle(format === "png");
80
+ // Show WebP advanced options only when WebP is selected
81
+ const isWebp = format === 'webp';
82
+ $("#webp-lossless-row").toggle(isWebp);
83
+ $("#webp-smartsubsample-row").toggle(isWebp);
84
+ $("#webp-effort-row").toggle(isWebp);
77
85
  }
78
86
  $("#node-input-outputFormat").on("change", updateQualityVisibility);
79
87
  updateQualityVisibility(); // initial state
@@ -1847,6 +1855,21 @@
1847
1855
  <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
1848
1856
  <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
1849
1857
  </div>
1858
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
1859
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
1860
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
1861
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
1862
+ </div>
1863
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
1864
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
1865
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
1866
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
1867
+ </div>
1868
+ <div class="form-row" id="webp-effort-row" style="display: none;">
1869
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
1870
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
1871
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
1872
+ </div>
1850
1873
 
1851
1874
  <!-- Debug Configuration -->
1852
1875
  <div class="form-row">
@@ -49,6 +49,8 @@ module.exports = function (RED) {
49
49
  const outputFormat = config.outputFormat || 'raw';
50
50
  const outputQuality = parseInt(config.outputQuality) || 90;
51
51
  const pngOptimize = config.pngOptimize || false;
52
+ const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
53
+ const cppFormat = useSharpWebp ? 'raw' : outputFormat;
52
54
  const propagateMasks = !!config.propagateMasks;
53
55
  const masksPath = config.masksPath || 'masks';
54
56
  const masksPathType = config.masksPathType || 'msg';
@@ -115,7 +117,7 @@ module.exports = function (RED) {
115
117
 
116
118
  /* Single ultra-fast C++ call */
117
119
  const options = {
118
- outputFormat,
120
+ outputFormat: cppFormat,
119
121
  quality: outputQuality,
120
122
  pngOptimize
121
123
  };
@@ -123,7 +125,7 @@ module.exports = function (RED) {
123
125
  options.masks = masksArray;
124
126
  }
125
127
 
126
- const { image, masks: transformedMasks, timing = {} } = await CppProcessor.advancedMosaic(
128
+ let { image, masks: transformedMasks, timing = {} } = await CppProcessor.advancedMosaic(
127
129
  imageArray,
128
130
  canvasWidth,
129
131
  canvasHeight,
@@ -133,6 +135,10 @@ module.exports = function (RED) {
133
135
  options
134
136
  );
135
137
 
138
+ if (useSharpWebp) {
139
+ image = await NodeUtils.encodeWebpAdvanced(image, config);
140
+ }
141
+
136
142
  const maskCount = Array.isArray(transformedMasks) ? transformedMasks.length : (propagateMasks && masksArray ? masksArray.length : 0);
137
143
 
138
144
  /* Set output */
@@ -210,7 +216,7 @@ module.exports = function (RED) {
210
216
  outputPath,
211
217
  outputPathType,
212
218
  outputType: 'single',
213
- context: { inputPath, inputPathType, outputPath, outputPathType, masksPath, masksPathType }
219
+ context: { inputPath, inputPathType, outputPath, outputPathType }
214
220
  }
215
221
  );
216
222
  }
@@ -12,6 +12,9 @@
12
12
  outputFormat:{value:"raw"},
13
13
  outputQuality:{value:90},
14
14
  pngOptimize:{value:false},
15
+ webpLossless:{value:false},
16
+ webpSmartSubsample:{value:false},
17
+ webpEffort:{value:""},
15
18
  // Debug configuration
16
19
  debugEnabled:{value:false},
17
20
  debugWidth:{value:200},
@@ -42,6 +45,11 @@
42
45
  const format = $("#node-input-outputFormat").val();
43
46
  $("#quality-row").toggle(format === "jpg" || format === "webp");
44
47
  $("#png-optimize-row").toggle(format === "png");
48
+ // Show WebP advanced options only when WebP is selected
49
+ const isWebp = format === 'webp';
50
+ $("#webp-lossless-row").toggle(isWebp);
51
+ $("#webp-smartsubsample-row").toggle(isWebp);
52
+ $("#webp-effort-row").toggle(isWebp);
45
53
  }
46
54
  $("#node-input-outputFormat").on("change", updateQualityVisibility);
47
55
  updateQualityVisibility(); // initial state
@@ -219,7 +227,22 @@
219
227
  <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
220
228
  <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
221
229
  </div>
222
-
230
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
231
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
232
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
233
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
234
+ </div>
235
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
236
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
237
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
238
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
239
+ </div>
240
+ <div class="form-row" id="webp-effort-row" style="display: none;">
241
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
242
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
243
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
244
+ </div>
245
+
223
246
  <!-- Debug Configuration -->
224
247
  <div class="form-row">
225
248
  <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
@@ -76,11 +76,17 @@ module.exports = function (RED) {
76
76
  const outputFormat = config.outputFormat || 'raw';
77
77
  const outputQuality = parseInt(config.outputQuality) || 90;
78
78
  const pngOptimize = config.pngOptimize || false;
79
+ const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
80
+ const cppFormat = useSharpWebp ? 'raw' : outputFormat;
79
81
  const padColorHex = config.padColor || '#000000';
80
82
 
81
83
  /* ▸ Single call to the C++ addon --------------------------------- */
82
- const { image, timing = {} } =
83
- await Cpp.concat(imgs, direction, strategy, padColorHex, outputFormat, outputQuality, pngOptimize);
84
+ let { image, timing = {} } =
85
+ await Cpp.concat(imgs, direction, strategy, padColorHex, cppFormat, outputQuality, pngOptimize);
86
+
87
+ if (useSharpWebp) {
88
+ image = await NodeUtils.encodeWebpAdvanced(image, config);
89
+ }
84
90
 
85
91
  /* ▸ Write the single result back to msg -------------------------- */
86
92
  NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, image);
@@ -15,6 +15,9 @@
15
15
  outputFormat:{value:"raw"},
16
16
  outputQuality:{value:90},
17
17
  pngOptimize:{value:false},
18
+ webpLossless:{value:false},
19
+ webpSmartSubsample:{value:false},
20
+ webpEffort:{value:""},
18
21
  // Debug configuration
19
22
  debugEnabled:{value:false},
20
23
  debugWidth:{value:200},
@@ -136,6 +139,11 @@
136
139
  const format = $("#node-input-outputFormat").val();
137
140
  $("#quality-row").toggle(format === "jpg" || format === "webp");
138
141
  $("#png-optimize-row").toggle(format === "png");
142
+ // Show WebP advanced options only when WebP is selected
143
+ const isWebp = format === 'webp';
144
+ $("#webp-lossless-row").toggle(isWebp);
145
+ $("#webp-smartsubsample-row").toggle(isWebp);
146
+ $("#webp-effort-row").toggle(isWebp);
139
147
  }
140
148
  $("#node-input-outputFormat").on("change", updateQualityVisibility);
141
149
  updateQualityVisibility(); // initial state
@@ -324,6 +332,21 @@
324
332
  <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
325
333
  <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
326
334
  </div>
335
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
336
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
337
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
338
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
339
+ </div>
340
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
341
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
342
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
343
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
344
+ </div>
345
+ <div class="form-row" id="webp-effort-row" style="display: none;">
346
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
347
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
348
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
349
+ </div>
327
350
 
328
351
  <!-- Debug Configuration -->
329
352
  <div class="form-row">
@@ -50,6 +50,8 @@ module.exports = function (RED) {
50
50
  const outputFormat = config.outputFormat || 'raw';
51
51
  const outputQuality = parseInt(config.outputQuality) || 90;
52
52
  const pngOptimize = config.pngOptimize || false;
53
+ const useSharpWebp = outputFormat === 'webp' && NodeUtils.hasAdvancedWebpOptions(config);
54
+ const cppFormat = useSharpWebp ? 'raw' : outputFormat;
53
55
 
54
56
  /* Canvas configuration */
55
57
  const canvasWidth = Number(NodeUtils.resolveDimension(node, config.canvasWidthType, config.canvasWidth, msg));
@@ -93,18 +95,22 @@ module.exports = function (RED) {
93
95
  }
94
96
 
95
97
  /* Single ultra-fast C++ call */
96
- const { image, timing = {} } = await CppProcessor.mosaic(
98
+ let { image, timing = {} } = await CppProcessor.mosaic(
97
99
  imageArray,
98
100
  canvasWidth,
99
101
  canvasHeight,
100
102
  backgroundColor,
101
103
  validPositions,
102
104
  normalized,
103
- outputFormat,
105
+ cppFormat,
104
106
  outputQuality,
105
107
  pngOptimize
106
108
  );
107
109
 
110
+ if (useSharpWebp) {
111
+ image = await NodeUtils.encodeWebpAdvanced(image, config);
112
+ }
113
+
108
114
  /* Set output */
109
115
  NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, image);
110
116