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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/.gitattributes +6 -0
  2. package/.github/workflows/build-prebuild.yml +326 -0
  3. package/LICENSE +13 -0
  4. package/README.md +161 -0
  5. package/artifacts/darwin-arm64/package.json +25 -0
  6. package/artifacts/linux-arm64/package.json +26 -0
  7. package/artifacts/linux-x64/package.json +26 -0
  8. package/artifacts/linuxmusl-x64/package.json +26 -0
  9. package/assets/flow_time_example.gif +0 -0
  10. package/assets/nodes/io/array-in-demo.gif +0 -0
  11. package/assets/nodes/io/array-out-demo.gif +0 -0
  12. package/assets/nodes/io/array-select-demo.gif +0 -0
  13. package/assets/nodes/io/image-in-demo.gif +0 -0
  14. package/assets/nodes/mix/concat-demo.gif +0 -0
  15. package/assets/nodes/mix/mosaic-demo.gif +0 -0
  16. package/assets/nodes/transform/crop-demo.gif +0 -0
  17. package/assets/nodes/transform/filter-demo.gif +0 -0
  18. package/assets/nodes/transform/padding-demo.gif +0 -0
  19. package/assets/nodes/transform/resize-demo.gif +0 -0
  20. package/assets/nodes/transform/rotate-demo.gif +0 -0
  21. package/docs/nodes/blend/add-mask.md +275 -0
  22. package/docs/nodes/blend/add-masks.md +284 -0
  23. package/docs/nodes/blend/blend.md +248 -0
  24. package/docs/nodes/io/array-in.md +119 -0
  25. package/docs/nodes/io/array-out.md +150 -0
  26. package/docs/nodes/io/array-select.md +157 -0
  27. package/docs/nodes/io/image-in.md +131 -0
  28. package/docs/nodes/io/image-out.md +179 -0
  29. package/docs/nodes/io/queue.md +57 -0
  30. package/docs/nodes/io/save-file.md +30 -0
  31. package/docs/nodes/mix/advanced-mosaic.md +108 -0
  32. package/docs/nodes/mix/concat.md +127 -0
  33. package/docs/nodes/mix/mosaic.md +146 -0
  34. package/docs/nodes/specialized/cropBB.md +271 -0
  35. package/docs/nodes/specialized/image-align.md +426 -0
  36. package/docs/nodes/transform/crop.md +132 -0
  37. package/docs/nodes/transform/draw.md +77 -0
  38. package/docs/nodes/transform/filter.md +84 -0
  39. package/docs/nodes/transform/padding.md +133 -0
  40. package/docs/nodes/transform/resize.md +158 -0
  41. package/docs/nodes/transform/rotate.md +121 -0
  42. package/docs/nodes/util/block-detect.md +46 -0
  43. package/install.sh +144 -0
  44. package/node-red-contrib-image-tools/lib/cpp-bridge.js +224 -0
  45. package/node-red-contrib-image-tools/lib/node-utils.js +529 -0
  46. package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +590 -0
  47. package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +241 -0
  48. package/node-red-contrib-image-tools/nodes/blend/add-mask.html +449 -0
  49. package/node-red-contrib-image-tools/nodes/blend/add-mask.js +170 -0
  50. package/node-red-contrib-image-tools/nodes/blend/add-masks.html +703 -0
  51. package/node-red-contrib-image-tools/nodes/blend/add-masks.js +321 -0
  52. package/node-red-contrib-image-tools/nodes/blend/blend.html +552 -0
  53. package/node-red-contrib-image-tools/nodes/blend/blend.js +124 -0
  54. package/node-red-contrib-image-tools/nodes/io/array-in.html +110 -0
  55. package/node-red-contrib-image-tools/nodes/io/array-in.js +113 -0
  56. package/node-red-contrib-image-tools/nodes/io/array-out.html +125 -0
  57. package/node-red-contrib-image-tools/nodes/io/array-out.js +213 -0
  58. package/node-red-contrib-image-tools/nodes/io/array-select.html +156 -0
  59. package/node-red-contrib-image-tools/nodes/io/array-select.js +187 -0
  60. package/node-red-contrib-image-tools/nodes/io/folder-in.html +248 -0
  61. package/node-red-contrib-image-tools/nodes/io/folder-in.js +335 -0
  62. package/node-red-contrib-image-tools/nodes/io/image-in.html +146 -0
  63. package/node-red-contrib-image-tools/nodes/io/image-in.js +143 -0
  64. package/node-red-contrib-image-tools/nodes/io/image-out.html +506 -0
  65. package/node-red-contrib-image-tools/nodes/io/image-out.js +545 -0
  66. package/node-red-contrib-image-tools/nodes/io/queue.html +119 -0
  67. package/node-red-contrib-image-tools/nodes/io/queue.js +191 -0
  68. package/node-red-contrib-image-tools/nodes/io/save-file.html +243 -0
  69. package/node-red-contrib-image-tools/nodes/io/save-file.js +440 -0
  70. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +2149 -0
  71. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +195 -0
  72. package/node-red-contrib-image-tools/nodes/mix/concat.html +390 -0
  73. package/node-red-contrib-image-tools/nodes/mix/concat.js +112 -0
  74. package/node-red-contrib-image-tools/nodes/mix/mosaic.html +550 -0
  75. package/node-red-contrib-image-tools/nodes/mix/mosaic.js +151 -0
  76. package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +268 -0
  77. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +277 -0
  78. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +528 -0
  79. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +306 -0
  80. package/node-red-contrib-image-tools/nodes/transform/crop.html +410 -0
  81. package/node-red-contrib-image-tools/nodes/transform/crop.js +149 -0
  82. package/node-red-contrib-image-tools/nodes/transform/draw.html +719 -0
  83. package/node-red-contrib-image-tools/nodes/transform/draw.js +509 -0
  84. package/node-red-contrib-image-tools/nodes/transform/filter.html +578 -0
  85. package/node-red-contrib-image-tools/nodes/transform/filter.js +177 -0
  86. package/node-red-contrib-image-tools/nodes/transform/padding.html +475 -0
  87. package/node-red-contrib-image-tools/nodes/transform/padding.js +142 -0
  88. package/node-red-contrib-image-tools/nodes/transform/resize.html +429 -0
  89. package/node-red-contrib-image-tools/nodes/transform/resize.js +162 -0
  90. package/node-red-contrib-image-tools/nodes/transform/rotate.html +299 -0
  91. package/node-red-contrib-image-tools/nodes/transform/rotate.js +141 -0
  92. package/node-red-contrib-image-tools/nodes/util/block-detect.html +85 -0
  93. package/node-red-contrib-image-tools/nodes/util/block-detect.js +136 -0
  94. package/node-red-contrib-image-tools/nodes/util/clean-debug.html +201 -0
  95. package/node-red-contrib-image-tools/nodes/util/clean-debug.js +393 -0
  96. package/node-red-contrib-image-tools/package.json +64 -0
  97. package/npm/darwin-arm64/lib/.gitkeep +1 -0
  98. package/npm/darwin-arm64/package.json +25 -0
  99. package/npm/darwin-x64/lib/.gitkeep +1 -0
  100. package/npm/darwin-x64/package.json +25 -0
  101. package/npm/linux-arm64/lib/.gitkeep +1 -0
  102. package/npm/linux-arm64/package.json +26 -0
  103. package/npm/linux-x64/lib/.gitkeep +1 -0
  104. package/npm/linux-x64/package.json +26 -0
  105. package/npm/linuxmusl-x64/lib/.gitkeep +1 -0
  106. package/npm/linuxmusl-x64/package.json +26 -0
  107. package/npm/win32-x64/lib/.gitkeep +1 -0
  108. package/npm/win32-x64/package.json +25 -0
  109. package/package.json +74 -0
  110. package/rosepetal-image-engine/binding.gyp +153 -0
  111. package/rosepetal-image-engine/package.json +19 -0
  112. package/rosepetal-image-engine/src/add-bbs.cpp +433 -0
  113. package/rosepetal-image-engine/src/add-mask.cpp +240 -0
  114. package/rosepetal-image-engine/src/add-masks.cpp +638 -0
  115. package/rosepetal-image-engine/src/advanced-mosaic.cpp +740 -0
  116. package/rosepetal-image-engine/src/blend.cpp +200 -0
  117. package/rosepetal-image-engine/src/concat.cpp +329 -0
  118. package/rosepetal-image-engine/src/crop.cpp +139 -0
  119. package/rosepetal-image-engine/src/draw.cpp +414 -0
  120. package/rosepetal-image-engine/src/filter.cpp +230 -0
  121. package/rosepetal-image-engine/src/filters/kernels.h +171 -0
  122. package/rosepetal-image-engine/src/image-align.cpp +551 -0
  123. package/rosepetal-image-engine/src/main.cpp +36 -0
  124. package/rosepetal-image-engine/src/mosaic.cpp +373 -0
  125. package/rosepetal-image-engine/src/padding.cpp +124 -0
  126. package/rosepetal-image-engine/src/resize.cpp +210 -0
  127. package/rosepetal-image-engine/src/rotate.cpp +177 -0
  128. package/rosepetal-image-engine/src/utils.h +563 -0
  129. package/rosepetal-image-engine/test-formats.js +119 -0
  130. package/scripts/build-opencv-static.ps1 +166 -0
  131. package/scripts/build-opencv-static.sh +147 -0
@@ -0,0 +1,146 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('image-in', {
3
+ category: 'RP Image',
4
+ color: '#A6C8A6',
5
+ defaults: {
6
+ name: { value: "" },
7
+ filePath: { value: "", required: true },
8
+ filePathType: { value: "str" },
9
+ // Nuevas propiedades para el destino de salida
10
+ outputPath: { value: "payload" },
11
+ outputPathType: { value: "msg" },
12
+ // Debug configuration
13
+ debugEnabled: { value: false },
14
+ debugWidth: { value: 200 },
15
+ debugWidthType: { value: "num" }
16
+ },
17
+ inputs: 1,
18
+ outputs: 1,
19
+ icon: "font-awesome/fa-file-image-o",
20
+ label: function() {
21
+ return this.name || this.filePath.split('/').pop() || "image in";
22
+ },
23
+ oneditprepare: function() {
24
+ // Inicializamos el widget TypedInput para el archivo de entrada
25
+ $("#node-input-filePath").typedInput({
26
+ default: 'str',
27
+ types: ['str', 'msg', 'flow', 'global'],
28
+ typeField: "#node-input-filePathType"
29
+ });
30
+
31
+ // Inicializamos el widget TypedInput para el campo de salida
32
+ $("#node-input-outputPath").typedInput({
33
+ default: 'msg', // Por defecto, la salida va al 'msg'
34
+ types: ['msg', 'flow', 'global'], // Opciones disponibles
35
+ typeField: "#node-input-outputPathType" // Campo oculto para guardar el tipo
36
+ });
37
+
38
+ // === Debug Display Logic ===
39
+ const debugCheckbox = $('#node-input-debugEnabled');
40
+ const debugWidthRow = $('#debug-width-row');
41
+
42
+ // Initialize debug width TypedInput
43
+ $("#node-input-debugWidth").typedInput({
44
+ default: 'num',
45
+ types: ['num', 'msg', 'flow', 'global'],
46
+ typeField: "#node-input-debugWidthType"
47
+ });
48
+
49
+ // Show/hide debug width based on checkbox
50
+ function updateDebugWidthVisibility() {
51
+ if (debugCheckbox.prop('checked')) {
52
+ debugWidthRow.show();
53
+ } else {
54
+ debugWidthRow.hide();
55
+ }
56
+ }
57
+
58
+ debugCheckbox.change(function() {
59
+ const enabled = $(this).prop('checked');
60
+ updateDebugWidthVisibility();
61
+ // Store debug state for runtime access
62
+ $('#node-input-debugEnabled').data('debug-enabled', enabled);
63
+ });
64
+
65
+ // Initialize visibility
66
+ updateDebugWidthVisibility();
67
+ }
68
+ });
69
+ </script>
70
+
71
+ <script type="text/x-red" data-template-name="image-in">
72
+ <div class="form-row">
73
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
74
+ <input type="text" id="node-input-name" placeholder="Name">
75
+ </div>
76
+ <div class="form-row">
77
+ <label for="node-input-filePath"><i class="fa fa-folder-open"></i> File Path</label>
78
+ <input type="text" id="node-input-filePath" style="width: 70%;" placeholder="/path/to/your/image.jpg">
79
+ <input type="hidden" id="node-input-filePathType">
80
+ </div>
81
+ <hr>
82
+ <div class="form-row">
83
+ <label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output to</label>
84
+ <input type="text" id="node-input-outputPath" style="width: 70%;">
85
+ <input type="hidden" id="node-input-outputPathType">
86
+ </div>
87
+
88
+ <!-- Debug Configuration -->
89
+ <div class="form-row">
90
+ <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
91
+ <input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
92
+ <label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show loaded image</label>
93
+ </div>
94
+ <div class="form-row" id="debug-width-row" style="display: none;">
95
+ <label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
96
+ <input type="text" id="node-input-debugWidth" style="width: 120px;">
97
+ <input type="hidden" id="node-input-debugWidthType">
98
+ </div>
99
+ </script>
100
+
101
+ <script type="text/x-red" data-help-name="image-in">
102
+ <p>Loads an image file from the filesystem and outputs it as a raw image object for processing in the Node-RED flow.</p>
103
+
104
+ <h3>Details</h3>
105
+ <p>This node reads image files from disk and converts them into the standard image format used throughout the Rosepetal Image Tools. It supports various image formats including JPEG, PNG, WebP, and BMP. The image is decoded using a high-performance C++ backend with OpenCV.</p>
106
+
107
+ <h3>Properties</h3>
108
+ <dl class="message-properties">
109
+ <dt>File Path <span class="property-type">string | msg | flow | global</span></dt>
110
+ <dd>The path to the image file on the server filesystem. Can be a static string (absolute or relative path) or dynamically resolved from message properties, flow context, or global context. Supports common image formats: JPEG, PNG, WebP, BMP.</dd>
111
+ <dt>Output to <span class="property-type">string</span></dt>
112
+ <dd>The location where the resulting image object will be stored. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
113
+ </dl>
114
+
115
+ <h3>Inputs</h3>
116
+ <dl class="message-properties">
117
+ <dt>payload <span class="property-type">any</span></dt>
118
+ <dd>Input message (content is ignored, only triggers the node operation).</dd>
119
+ </dl>
120
+
121
+ <h3>Outputs</h3>
122
+ <p>The node sets the property specified in 'Output to' with the processed image object using the standard format:</p>
123
+ <pre>{
124
+ data: Buffer, // Raw pixel data
125
+ width: number, // Image width in pixels
126
+ height: number, // Image height in pixels
127
+ channels: number, // Channel count (1, 3, 4)
128
+ colorSpace: string, // "GRAY", "RGB", "RGBA", "BGR", "BGRA"
129
+ dtype: string // "uint8", "uint16", "float32"
130
+ }</pre>
131
+
132
+ <h3>Examples</h3>
133
+ <ul>
134
+ <li><strong>Static Path:</strong> Set File Path to <code>/path/to/image.jpg</code> (string type) and Output to <code>msg.payload</code></li>
135
+ <li><strong>Dynamic Path from Message:</strong> Set File Path from <code>msg.imagePath</code> to load different images based on message content</li>
136
+ <li><strong>Flow Context Path:</strong> Set File Path from <code>flow.currentImageFile</code> to use a path stored in flow context</li>
137
+ <li><strong>Multiple Images:</strong> Connect to an array-out node to work with image collections</li>
138
+ <li><strong>Processing Pipeline:</strong> Connect to transform nodes like resize, rotate, or crop for image manipulation</li>
139
+ </ul>
140
+
141
+ <h3>Error Handling</h3>
142
+ <p>If the file path is invalid or the image cannot be read, the node will display a warning and not propagate the message. Check the debug panel for specific error details.</p>
143
+
144
+ <h3>Performance</h3>
145
+ <p>Image loading is performed asynchronously using the C++ backend for optimal performance. The node status displays processing time information.</p>
146
+ </script>
@@ -0,0 +1,143 @@
1
+ /**
2
+ * @file Node.js logic for the Image-In node with dynamic output path.
3
+ * Uses Sharp for complete image decoding and metadata extraction.
4
+ * @author Rosepetal
5
+ */
6
+
7
+ const sharp = require('sharp');
8
+ const fs = require('fs').promises;
9
+
10
+ module.exports = function(RED) {
11
+ const NodeUtils = require('../../lib/node-utils.js')(RED);
12
+
13
+ function ImageInNode(config) {
14
+ RED.nodes.createNode(this, config);
15
+ const node = this;
16
+
17
+ node.on('input', async function(msg, send, done) {
18
+ try {
19
+ let filePath;
20
+ if (config.filePathType === 'msg' || config.filePathType === 'flow' || config.filePathType === 'global') {
21
+ filePath = RED.util.evaluateNodeProperty(config.filePath, config.filePathType, node, msg);
22
+ } else {
23
+ filePath = config.filePath; // str type
24
+ }
25
+
26
+ if (!filePath) {
27
+ node.warn("File path is not configured or resolved.");
28
+ return;
29
+ }
30
+
31
+ node.status({ fill: "blue", shape: "dot", text: "reading..." });
32
+
33
+ // Check file accessibility
34
+ try {
35
+ await fs.access(filePath, fs.constants.R_OK);
36
+ } catch (accessErr) {
37
+ node.warn(`Cannot access file: ${filePath}`);
38
+ return;
39
+ }
40
+
41
+ // Use Sharp to decode image with full metadata
42
+ const { data, info } = await sharp(filePath)
43
+ .raw()
44
+ .toBuffer({ resolveWithObject: true });
45
+
46
+ // Determine colorSpace from Sharp info
47
+ let colorSpace;
48
+ switch (info.channels) {
49
+ case 1: colorSpace = 'GRAY'; break;
50
+ case 3: colorSpace = 'RGB'; break;
51
+ case 4: colorSpace = 'RGBA'; break;
52
+ default: throw new Error(`Unsupported number of channels: ${info.channels}`);
53
+ }
54
+
55
+ // Create complete image structure with all metadata
56
+ const outputImageObject = {
57
+ data: data,
58
+ width: info.width,
59
+ height: info.height,
60
+ channels: info.channels,
61
+ colorSpace: colorSpace,
62
+ dtype: "uint8"
63
+ };
64
+
65
+ // Debug image display if enabled
66
+ if (config.debugEnabled) {
67
+ try {
68
+ // Resolve debug width
69
+ let debugWidth = NodeUtils.resolveDimension(
70
+ node,
71
+ config.debugWidthType || "num",
72
+ config.debugWidth || 200,
73
+ msg
74
+ );
75
+ debugWidth = Math.max(1, parseInt(debugWidth) || 200);
76
+
77
+ // Since we already have the image loaded, reuse it for debug display
78
+ // Convert to JPEG buffer for debug display using the Sharp instance
79
+ const debugBuffer = await sharp(data, {
80
+ raw: { width: info.width, height: info.height, channels: info.channels }
81
+ })
82
+ .resize(debugWidth, null, {
83
+ withoutEnlargement: false,
84
+ fit: 'inside'
85
+ })
86
+ .jpeg({ quality: 90 })
87
+ .toBuffer();
88
+
89
+ // Create debug result manually since we're using Sharp directly
90
+ const base64 = debugBuffer.toString('base64');
91
+ const debugMetadata = await sharp(debugBuffer).metadata();
92
+
93
+ // Send image to frontend via WebSocket for inline display
94
+ try {
95
+ RED.comms.publish("debug-image", {
96
+ id: node.id,
97
+ data: base64,
98
+ format: 'jpg debug',
99
+ mimeType: 'jpeg',
100
+ size: debugBuffer.length,
101
+ debugWidth: debugMetadata.width || debugWidth,
102
+ debugHeight: debugMetadata.height || debugWidth
103
+ });
104
+ } catch (wsError) {
105
+ node.warn(`Debug WebSocket error: ${wsError.message}`);
106
+ }
107
+
108
+ } catch (debugError) {
109
+ node.warn(`Debug display error: ${debugError.message}`);
110
+ }
111
+ }
112
+
113
+ const outputPath = config.outputPath || "payload";
114
+ const outputPathType = config.outputPathType || "msg";
115
+
116
+ if (outputPathType === 'msg') {
117
+ RED.util.setMessageProperty(msg, outputPath, outputImageObject);
118
+ } else if (outputPathType === 'flow') {
119
+ node.context().flow.set(outputPath, outputImageObject);
120
+ } else if (outputPathType === 'global') {
121
+ node.context().global.set(outputPath, outputImageObject);
122
+ }
123
+
124
+ // Update status with debug info if enabled
125
+ let statusText = `${info.width}x${info.height} to ${outputPathType}.${outputPath}`;
126
+ if (config.debugEnabled) {
127
+ statusText += ' | jpg debug';
128
+ }
129
+ node.status({ fill: "green", shape: "dot", text: statusText });
130
+
131
+ send(msg);
132
+ if (done) { done(); }
133
+
134
+ } catch (err) {
135
+ node.status({ fill: "red", shape: "ring", text: "Error" });
136
+ node.warn(`Error reading image file: ${err.message}`);
137
+ // Don't send message on error
138
+ if (done) { done(); }
139
+ }
140
+ });
141
+ }
142
+ RED.nodes.registerType("image-in", ImageInNode);
143
+ };