@rosepetal/node-red-contrib-image-tools 1.2.0 → 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.
- package/node-red-contrib-image-tools/nodes/transform/color-convert.html +189 -0
- package/node-red-contrib-image-tools/nodes/transform/color-convert.js +153 -0
- package/node-red-contrib-image-tools/nodes/transform/rotate.html +5 -5
- package/node-red-contrib-image-tools/package.json +1 -0
- package/package.json +2 -1
- package/rosepetal-image-engine/binding.gyp +2 -1
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +4 -4
- package/rosepetal-image-engine/src/color-convert.cpp +184 -0
- package/rosepetal-image-engine/src/concat.cpp +2 -2
- package/rosepetal-image-engine/src/crop.cpp +4 -4
- package/rosepetal-image-engine/src/filter.cpp +4 -4
- package/rosepetal-image-engine/src/image-align.cpp +1 -1
- package/rosepetal-image-engine/src/main.cpp +2 -0
- package/rosepetal-image-engine/src/mosaic.cpp +4 -4
- package/rosepetal-image-engine/src/padding.cpp +4 -4
- package/rosepetal-image-engine/src/resize.cpp +4 -4
- package/rosepetal-image-engine/src/rotate.cpp +6 -6
- package/rosepetal-image-engine/src/utils.h +2 -2
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('color-convert', {
|
|
3
|
+
category : 'RP Image',
|
|
4
|
+
color : '#DDA0DD',
|
|
5
|
+
defaults : {
|
|
6
|
+
name : { value:"" },
|
|
7
|
+
inputPath : { value:"payload" },
|
|
8
|
+
inputPathType : { value:"msg" },
|
|
9
|
+
outputPath : { value:"payload" },
|
|
10
|
+
outputPathType : { value:"msg" },
|
|
11
|
+
outputFormat : { value:"raw" },
|
|
12
|
+
outputQuality : { value:90 },
|
|
13
|
+
pngOptimize : { value:false },
|
|
14
|
+
// Debug configuration
|
|
15
|
+
debugEnabled : { value:false },
|
|
16
|
+
debugWidth : { value:200 },
|
|
17
|
+
debugWidthType : { value:"num" },
|
|
18
|
+
targetColorSpace: { value:"RGB" }
|
|
19
|
+
},
|
|
20
|
+
inputs :1, outputs:1,
|
|
21
|
+
icon:"font-awesome/fa-paint-brush",
|
|
22
|
+
label:function(){ return this.name || "color-convert"; },
|
|
23
|
+
|
|
24
|
+
oneditprepare:function(){
|
|
25
|
+
$("#node-input-inputPath").typedInput({default:'msg',types:['msg','flow','global'],typeField:"#node-input-inputPathType"});
|
|
26
|
+
$("#node-input-outputPath").typedInput({default:'msg',types:['msg','flow','global'],typeField:"#node-input-outputPathType"});
|
|
27
|
+
|
|
28
|
+
function updateQualityVisibility(){
|
|
29
|
+
const format = $("#node-input-outputFormat").val();
|
|
30
|
+
$("#quality-row").toggle(format === "jpg" || format === "webp");
|
|
31
|
+
$("#png-optimize-row").toggle(format === "png");
|
|
32
|
+
}
|
|
33
|
+
$("#node-input-outputFormat").on("change", updateQualityVisibility);
|
|
34
|
+
updateQualityVisibility(); // initial state
|
|
35
|
+
|
|
36
|
+
// === Debug Display Logic ===
|
|
37
|
+
const debugCheckbox = $('#node-input-debugEnabled');
|
|
38
|
+
const debugWidthRow = $('#debug-width-row');
|
|
39
|
+
|
|
40
|
+
// Initialize debug width TypedInput
|
|
41
|
+
$("#node-input-debugWidth").typedInput({
|
|
42
|
+
default: 'num',
|
|
43
|
+
types: ['num', 'msg', 'flow', 'global'],
|
|
44
|
+
typeField: "#node-input-debugWidthType"
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Function to toggle debug width visibility
|
|
48
|
+
function updateDebugWidthVisibility() {
|
|
49
|
+
if (debugCheckbox.is(':checked')) {
|
|
50
|
+
debugWidthRow.show();
|
|
51
|
+
} else {
|
|
52
|
+
debugWidthRow.hide();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Initialize debug state on node open
|
|
57
|
+
updateDebugWidthVisibility();
|
|
58
|
+
|
|
59
|
+
// Handle debug checkbox changes
|
|
60
|
+
debugCheckbox.on('change', function() {
|
|
61
|
+
const enabled = this.checked;
|
|
62
|
+
updateDebugWidthVisibility();
|
|
63
|
+
$('#node-input-debugEnabled').data('debug-enabled', enabled);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<script type="text/x-red" data-template-name="color-convert">
|
|
70
|
+
<div class="form-row"><label for="node-input-name"><i class="fa fa-tag"></i> Name</label><input type="text" id="node-input-name"></div>
|
|
71
|
+
<hr>
|
|
72
|
+
<div class="form-row"><label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input</label><input type="text" id="node-input-inputPath" style="width:70%;"><input type="hidden" id="node-input-inputPathType"></div>
|
|
73
|
+
<div class="form-row"><label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output</label><input type="text" id="node-input-outputPath" style="width:70%;"><input type="hidden" id="node-input-outputPathType"></div>
|
|
74
|
+
<div class="form-row">
|
|
75
|
+
<label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
|
|
76
|
+
<select id="node-input-outputFormat" style="width: 200px;">
|
|
77
|
+
<option value="raw">Raw (fastest)</option>
|
|
78
|
+
<option value="jpg">JPEG</option>
|
|
79
|
+
<option value="png">PNG</option>
|
|
80
|
+
<option value="webp">WebP</option>
|
|
81
|
+
</select>
|
|
82
|
+
</div>
|
|
83
|
+
<div class="form-row" id="quality-row">
|
|
84
|
+
<label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
|
|
85
|
+
<input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
|
|
86
|
+
<span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
|
|
87
|
+
</div>
|
|
88
|
+
<div class="form-row" id="png-optimize-row" style="display: none;">
|
|
89
|
+
<label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
|
|
90
|
+
<input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
91
|
+
<label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
|
|
92
|
+
</div>
|
|
93
|
+
|
|
94
|
+
<!-- Debug Configuration -->
|
|
95
|
+
<div class="form-row">
|
|
96
|
+
<label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
|
|
97
|
+
<input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
98
|
+
<label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
|
|
99
|
+
</div>
|
|
100
|
+
<div class="form-row" id="debug-width-row" style="display: none;">
|
|
101
|
+
<label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
|
|
102
|
+
<input type="text" id="node-input-debugWidth" style="width: 120px;">
|
|
103
|
+
<input type="hidden" id="node-input-debugWidthType">
|
|
104
|
+
<span style="margin-left: 10px; color: #666;">pixels</span>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<hr>
|
|
108
|
+
<div class="form-row">
|
|
109
|
+
<label for="node-input-targetColorSpace"><i class="fa fa-paint-brush"></i> Target Color Space</label>
|
|
110
|
+
<select id="node-input-targetColorSpace" style="width: 200px;">
|
|
111
|
+
<option value="GRAY">Grayscale (GRAY)</option>
|
|
112
|
+
<option value="RGB">RGB</option>
|
|
113
|
+
<option value="RGBA">RGBA</option>
|
|
114
|
+
<option value="BGR">BGR</option>
|
|
115
|
+
<option value="BGRA">BGRA</option>
|
|
116
|
+
</select>
|
|
117
|
+
</div>
|
|
118
|
+
</script>
|
|
119
|
+
|
|
120
|
+
<script type="text/x-red" data-help-name="color-convert">
|
|
121
|
+
<p>Converts images between color spaces (GRAY, RGB, RGBA, BGR, BGRA) using high-performance C++ processing.</p>
|
|
122
|
+
|
|
123
|
+
<h3>Details</h3>
|
|
124
|
+
<p>This node converts images from one color space to another. The source color space is automatically detected from the input image metadata (or inferred from channel count). The target color space is selected in the node configuration. Supports both single images and arrays, processed in parallel.</p>
|
|
125
|
+
|
|
126
|
+
<h3>Properties</h3>
|
|
127
|
+
<dl class="message-properties">
|
|
128
|
+
<dt>Input from <span class="property-type">string</span></dt>
|
|
129
|
+
<dd>The location to read image data from. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
|
|
130
|
+
<dt>Output to <span class="property-type">string</span></dt>
|
|
131
|
+
<dd>The location where the converted image 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>
|
|
132
|
+
<dt>Output Format <span class="property-type">string</span></dt>
|
|
133
|
+
<dd>Choose output format: <code>raw</code> (fastest, standard image object), <code>jpg</code>, <code>png</code>, or <code>webp</code> (encoded file buffers).</dd>
|
|
134
|
+
<dt>Quality <span class="property-type">number</span></dt>
|
|
135
|
+
<dd>Compression quality for JPEG and WebP formats (1-100). Only visible when jpg or webp format is selected. Default: 90.</dd>
|
|
136
|
+
<dt>Target Color Space <span class="property-type">string</span></dt>
|
|
137
|
+
<dd>The target color space to convert images to. Options: <code>GRAY</code>, <code>RGB</code>, <code>RGBA</code>, <code>BGR</code>, <code>BGRA</code>. Default: RGB.</dd>
|
|
138
|
+
</dl>
|
|
139
|
+
|
|
140
|
+
<h3>Inputs</h3>
|
|
141
|
+
<dl class="message-properties">
|
|
142
|
+
<dt>payload <span class="property-type">object | array</span></dt>
|
|
143
|
+
<dd>Single image object or array of image objects in standard format: <code>{ data: Buffer, width: number, height: number, channels: number, colorSpace: string, dtype: string }</code></dd>
|
|
144
|
+
</dl>
|
|
145
|
+
|
|
146
|
+
<h3>Outputs</h3>
|
|
147
|
+
<dl class="message-properties">
|
|
148
|
+
<dt>payload <span class="property-type">object | array | Buffer</span></dt>
|
|
149
|
+
<dd>Converted image(s). Format depends on Output Format setting: raw image object(s) or encoded file buffer(s).</dd>
|
|
150
|
+
</dl>
|
|
151
|
+
|
|
152
|
+
<h3>Supported Conversions</h3>
|
|
153
|
+
<p>All 20 conversion paths between the 5 color spaces are supported:</p>
|
|
154
|
+
<ul>
|
|
155
|
+
<li><strong>GRAY →</strong> BGR, RGB, BGRA, RGBA</li>
|
|
156
|
+
<li><strong>BGR →</strong> GRAY, RGB, BGRA, RGBA</li>
|
|
157
|
+
<li><strong>RGB →</strong> GRAY, BGR, BGRA, RGBA</li>
|
|
158
|
+
<li><strong>BGRA →</strong> GRAY, BGR, RGB, RGBA</li>
|
|
159
|
+
<li><strong>RGBA →</strong> GRAY, BGR, RGB, BGRA</li>
|
|
160
|
+
</ul>
|
|
161
|
+
<p>If the source and target color space are the same, a fast passthrough is used (no conversion overhead).</p>
|
|
162
|
+
|
|
163
|
+
<h3>Examples</h3>
|
|
164
|
+
<ul>
|
|
165
|
+
<li><strong>RGB → GRAY:</strong> Convert a color image to grayscale (3 channels → 1 channel)</li>
|
|
166
|
+
<li><strong>GRAY → RGBA:</strong> Expand grayscale to RGBA with full alpha (1 channel → 4 channels)</li>
|
|
167
|
+
<li><strong>BGR → RGB:</strong> Swap blue and red channels for display compatibility</li>
|
|
168
|
+
<li><strong>RGB → BGRA:</strong> Add alpha channel and convert to OpenCV-native order</li>
|
|
169
|
+
</ul>
|
|
170
|
+
|
|
171
|
+
<h3>Node Interactions</h3>
|
|
172
|
+
<p><strong>Input Sources:</strong> Image-in, Array-out, other transform nodes</p>
|
|
173
|
+
<p><strong>Output Destinations:</strong> Other transform nodes, Mix nodes (concat, mosaic), Array-in for collections</p>
|
|
174
|
+
<p><strong>Common Workflows:</strong> Preparing images for specific processing pipelines, ensuring consistent color spaces before blending or concatenation</p>
|
|
175
|
+
|
|
176
|
+
<h3>Output Formats</h3>
|
|
177
|
+
<ul>
|
|
178
|
+
<li><strong>Raw:</strong> Standard image object (fastest, for further processing)</li>
|
|
179
|
+
<li><strong>JPEG:</strong> Compressed file buffer with quality setting</li>
|
|
180
|
+
<li><strong>PNG:</strong> Lossless compressed file buffer</li>
|
|
181
|
+
<li><strong>WebP:</strong> Modern compressed format with quality setting</li>
|
|
182
|
+
</ul>
|
|
183
|
+
|
|
184
|
+
<h3>Error Handling</h3>
|
|
185
|
+
<p>The node validates input data and displays warnings for invalid inputs. Unsupported conversion paths produce descriptive error messages. Processing errors are logged and the original message is passed through with error details.</p>
|
|
186
|
+
|
|
187
|
+
<h3>Performance</h3>
|
|
188
|
+
<p>Uses optimized C++ backend with OpenCV for high-performance color space conversion. Identity conversions (same source/target) use a zero-cost passthrough. Node status displays processing time. Array inputs are processed in parallel for optimal performance.</p>
|
|
189
|
+
</script>
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-RED logic for *rosepetal-color-convert* — color space conversion, timing formatted.
|
|
3
|
+
*/
|
|
4
|
+
const { performance } = require('perf_hooks');
|
|
5
|
+
const CppProcessor = require('../../lib/cpp-bridge.js');
|
|
6
|
+
|
|
7
|
+
module.exports = function (RED) {
|
|
8
|
+
const NodeUtils = require('../../lib/node-utils.js')(RED);
|
|
9
|
+
|
|
10
|
+
function ColorConvertNode(config) {
|
|
11
|
+
RED.nodes.createNode(this, config);
|
|
12
|
+
const node = this;
|
|
13
|
+
|
|
14
|
+
node.on('input', async (msg, send, done) => {
|
|
15
|
+
const inputPath = config.inputPath || 'payload';
|
|
16
|
+
const inputPathType = config.inputPathType || 'msg';
|
|
17
|
+
const outputPath = config.outputPath || 'payload';
|
|
18
|
+
const outputPathType = config.outputPathType || 'msg';
|
|
19
|
+
const { value: originalPayload, error: inputErr } =
|
|
20
|
+
NodeUtils.getInputValue(node, msg, inputPath, inputPathType);
|
|
21
|
+
if (inputErr) {
|
|
22
|
+
const hint = inputPathType === 'msg'
|
|
23
|
+
? `Set inputPath to an existing msg property (e.g. "payload"), or ensure "${inputPath}" exists before this node.`
|
|
24
|
+
: `Set inputPath to an existing ${inputPathType} context key, or ensure "${inputPath}" exists before this node.`;
|
|
25
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
26
|
+
node,
|
|
27
|
+
{
|
|
28
|
+
message: `Invalid inputPath "${inputPath}" (${inputPathType}): ${inputErr.message}`,
|
|
29
|
+
hint,
|
|
30
|
+
details: { inputPath, inputPathType, outputPath, outputPathType }
|
|
31
|
+
},
|
|
32
|
+
msg,
|
|
33
|
+
send,
|
|
34
|
+
done,
|
|
35
|
+
{ originalPayload: undefined, outputPath: null, outputPathType, outputType: 'preserve' }
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const t0 = performance.now();
|
|
41
|
+
node.status({});
|
|
42
|
+
const outputFormat = config.outputFormat || 'raw';
|
|
43
|
+
const outputQuality = parseInt(config.outputQuality) || 90;
|
|
44
|
+
const pngOptimize = config.pngOptimize || false;
|
|
45
|
+
const targetColorSpace = config.targetColorSpace || 'RGB';
|
|
46
|
+
|
|
47
|
+
// Validate input images with error passthrough
|
|
48
|
+
if (Array.isArray(originalPayload)) {
|
|
49
|
+
if (!NodeUtils.validateListImage(originalPayload, node)) {
|
|
50
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
51
|
+
node, 'Invalid image list structure', msg, send, done,
|
|
52
|
+
{ originalPayload, outputPath, outputPathType, outputType: 'preserve' }
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
if (!NodeUtils.validateSingleImage(originalPayload, node)) {
|
|
57
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
58
|
+
node, 'Invalid image structure', msg, send, done,
|
|
59
|
+
{ originalPayload, outputPath, outputPathType, outputType: 'preserve' }
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const imgs = Array.isArray(originalPayload) ? originalPayload : [originalPayload];
|
|
65
|
+
|
|
66
|
+
/* ——— launch conversions in parallel ——— */
|
|
67
|
+
const promises = imgs.map(img =>
|
|
68
|
+
CppProcessor.colorConvert(img, targetColorSpace, outputFormat, outputQuality, pngOptimize)
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const results = await Promise.all(promises);
|
|
72
|
+
|
|
73
|
+
/* ——— accumulate metrics ——— */
|
|
74
|
+
const { totalConvertMs, totalTaskMs, encodeMs, images } =
|
|
75
|
+
results.reduce((acc, { image, timing }) => {
|
|
76
|
+
acc.totalConvertMs += timing?.convertMs ?? 0;
|
|
77
|
+
acc.totalTaskMs += timing?.taskMs ?? 0;
|
|
78
|
+
acc.encodeMs += timing?.encodeMs ?? 0;
|
|
79
|
+
acc.images.push(image);
|
|
80
|
+
return acc;
|
|
81
|
+
}, { totalConvertMs: 0, totalTaskMs: 0, encodeMs: 0, images: [] });
|
|
82
|
+
|
|
83
|
+
const out = Array.isArray(originalPayload) ? images : images[0];
|
|
84
|
+
const durMs = performance.now() - t0;
|
|
85
|
+
|
|
86
|
+
NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, out);
|
|
87
|
+
|
|
88
|
+
// Debug image display
|
|
89
|
+
let debugFormat = null;
|
|
90
|
+
const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
|
|
91
|
+
if (debugEnabled) {
|
|
92
|
+
try {
|
|
93
|
+
let debugWidth = NodeUtils.resolveDimension(
|
|
94
|
+
node,
|
|
95
|
+
config.debugWidthType || 'num',
|
|
96
|
+
config.debugWidth,
|
|
97
|
+
msg
|
|
98
|
+
);
|
|
99
|
+
debugWidth = Math.max(1, parseInt(debugWidth) || 200);
|
|
100
|
+
|
|
101
|
+
const debugImage = images[0];
|
|
102
|
+
const debugResult = await NodeUtils.debugImageDisplay(
|
|
103
|
+
debugImage,
|
|
104
|
+
outputFormat,
|
|
105
|
+
outputQuality,
|
|
106
|
+
node,
|
|
107
|
+
debugEnabled,
|
|
108
|
+
debugWidth
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (debugResult) {
|
|
112
|
+
debugFormat = debugResult.formatMessage;
|
|
113
|
+
NodeUtils.setSuccessStatusWithDebug(node, imgs.length, durMs, {
|
|
114
|
+
convertMs: totalConvertMs,
|
|
115
|
+
taskMs: totalTaskMs,
|
|
116
|
+
encodeMs: encodeMs
|
|
117
|
+
}, debugFormat + (Array.isArray(originalPayload) ? ' (first)' : ''));
|
|
118
|
+
}
|
|
119
|
+
} catch (debugError) {
|
|
120
|
+
node.warn(`Debug display error: ${debugError.message}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Set regular status if debug not enabled or failed
|
|
125
|
+
if (!debugFormat) {
|
|
126
|
+
node.status({
|
|
127
|
+
fill : 'green',
|
|
128
|
+
shape : 'dot',
|
|
129
|
+
text : `OK: ${imgs.length} img in ${durMs.toFixed(2)} ms `
|
|
130
|
+
+ `(conv ${(totalConvertMs + encodeMs).toFixed(2)} ms `
|
|
131
|
+
+ `| task ${totalTaskMs.toFixed(2)} ms)`
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
NodeUtils.recordPerformanceMetrics(node, msg, {
|
|
136
|
+
convertMs: totalConvertMs,
|
|
137
|
+
encodeMs: encodeMs,
|
|
138
|
+
taskMs: totalTaskMs
|
|
139
|
+
}, durMs);
|
|
140
|
+
|
|
141
|
+
send(msg);
|
|
142
|
+
done && done();
|
|
143
|
+
} catch (err) {
|
|
144
|
+
NodeUtils.handleNodeErrorWithPassthrough(
|
|
145
|
+
node, err, msg, send, done, 'color-convert processing',
|
|
146
|
+
{ originalPayload, outputPath, outputPathType, outputType: 'preserve' }
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
RED.nodes.registerType('color-convert', ColorConvertNode);
|
|
153
|
+
};
|
|
@@ -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>
|
|
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>
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"padding": "nodes/transform/padding.js",
|
|
43
43
|
"filter": "nodes/transform/filter.js",
|
|
44
44
|
"draw": "nodes/transform/draw.js",
|
|
45
|
+
"color-convert": "nodes/transform/color-convert.js",
|
|
45
46
|
"mosaic": "nodes/mix/mosaic.js",
|
|
46
47
|
"advanced-mosaic": "nodes/mix/advanced-mosaic.js",
|
|
47
48
|
"blend": "nodes/blend/blend.js",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rosepetal/node-red-contrib-image-tools",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Node-RED Image Processing Toolkit",
|
|
5
5
|
"main": "install.sh",
|
|
6
6
|
"directories": {
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"padding": "node-red-contrib-image-tools/nodes/transform/padding.js",
|
|
60
60
|
"filter": "node-red-contrib-image-tools/nodes/transform/filter.js",
|
|
61
61
|
"draw": "node-red-contrib-image-tools/nodes/transform/draw.js",
|
|
62
|
+
"color-convert": "node-red-contrib-image-tools/nodes/transform/color-convert.js",
|
|
62
63
|
"mosaic": "node-red-contrib-image-tools/nodes/mix/mosaic.js",
|
|
63
64
|
"advanced-mosaic": "node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js",
|
|
64
65
|
"blend": "node-red-contrib-image-tools/nodes/blend/blend.js",
|
|
@@ -152,14 +152,14 @@ public:
|
|
|
152
152
|
}
|
|
153
153
|
// Default based on channel count
|
|
154
154
|
else {
|
|
155
|
-
channel = (images_[i].channels() == 4) ? "
|
|
156
|
-
: (images_[i].channels() == 3) ? "
|
|
155
|
+
channel = (images_[i].channels() == 4) ? "RGBA"
|
|
156
|
+
: (images_[i].channels() == 3) ? "RGB"
|
|
157
157
|
: "GRAY";
|
|
158
158
|
}
|
|
159
159
|
} else {
|
|
160
160
|
// Buffer input - determine from OpenCV Mat
|
|
161
|
-
channel = (images_[i].channels() == 4) ? "
|
|
162
|
-
: (images_[i].channels() == 3) ? "
|
|
161
|
+
channel = (images_[i].channels() == 4) ? "RGBA"
|
|
162
|
+
: (images_[i].channels() == 3) ? "RGB"
|
|
163
163
|
: "GRAY";
|
|
164
164
|
}
|
|
165
165
|
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// ───────── src/color-convert.cpp ───────────────────────────────────────────
|
|
2
|
+
#include <napi.h>
|
|
3
|
+
#include <opencv2/opencv.hpp>
|
|
4
|
+
#include <chrono>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <unordered_map>
|
|
7
|
+
#include "utils.h"
|
|
8
|
+
|
|
9
|
+
// ──────────────────────────────── Lookup key helper
|
|
10
|
+
static inline std::string MakeKey(const std::string& src, const std::string& dst) {
|
|
11
|
+
return src + ">" + dst;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// ──────────────────────────────── Complete conversion table (20 paths)
|
|
15
|
+
static const std::unordered_map<std::string, int>& ConversionTable() {
|
|
16
|
+
static const std::unordered_map<std::string, int> table = {
|
|
17
|
+
// GRAY →
|
|
18
|
+
{ MakeKey("GRAY","BGR"), cv::COLOR_GRAY2BGR },
|
|
19
|
+
{ MakeKey("GRAY","RGB"), cv::COLOR_GRAY2RGB },
|
|
20
|
+
{ MakeKey("GRAY","BGRA"), cv::COLOR_GRAY2BGRA },
|
|
21
|
+
{ MakeKey("GRAY","RGBA"), cv::COLOR_GRAY2RGBA },
|
|
22
|
+
// BGR →
|
|
23
|
+
{ MakeKey("BGR","GRAY"), cv::COLOR_BGR2GRAY },
|
|
24
|
+
{ MakeKey("BGR","RGB"), cv::COLOR_BGR2RGB },
|
|
25
|
+
{ MakeKey("BGR","BGRA"), cv::COLOR_BGR2BGRA },
|
|
26
|
+
{ MakeKey("BGR","RGBA"), cv::COLOR_BGR2RGBA },
|
|
27
|
+
// RGB →
|
|
28
|
+
{ MakeKey("RGB","GRAY"), cv::COLOR_RGB2GRAY },
|
|
29
|
+
{ MakeKey("RGB","BGR"), cv::COLOR_RGB2BGR },
|
|
30
|
+
{ MakeKey("RGB","BGRA"), cv::COLOR_RGB2BGRA },
|
|
31
|
+
{ MakeKey("RGB","RGBA"), cv::COLOR_RGB2RGBA },
|
|
32
|
+
// BGRA →
|
|
33
|
+
{ MakeKey("BGRA","GRAY"), cv::COLOR_BGRA2GRAY },
|
|
34
|
+
{ MakeKey("BGRA","BGR"), cv::COLOR_BGRA2BGR },
|
|
35
|
+
{ MakeKey("BGRA","RGB"), cv::COLOR_BGRA2RGB },
|
|
36
|
+
{ MakeKey("BGRA","RGBA"), cv::COLOR_BGRA2RGBA },
|
|
37
|
+
// RGBA →
|
|
38
|
+
{ MakeKey("RGBA","GRAY"), cv::COLOR_RGBA2GRAY },
|
|
39
|
+
{ MakeKey("RGBA","BGR"), cv::COLOR_RGBA2BGR },
|
|
40
|
+
{ MakeKey("RGBA","RGB"), cv::COLOR_RGBA2RGB },
|
|
41
|
+
{ MakeKey("RGBA","BGRA"), cv::COLOR_RGBA2BGRA },
|
|
42
|
+
};
|
|
43
|
+
return table;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ──────────────────────────────── Worker
|
|
47
|
+
class ColorConvertWorker : public Napi::AsyncWorker {
|
|
48
|
+
public:
|
|
49
|
+
ColorConvertWorker(Napi::Function& cb,
|
|
50
|
+
const Napi::Value& imgVal,
|
|
51
|
+
std::string targetColorSpace,
|
|
52
|
+
std::string outputFormat,
|
|
53
|
+
int quality = 90,
|
|
54
|
+
bool pngOptimize = false)
|
|
55
|
+
: Napi::AsyncWorker(cb),
|
|
56
|
+
targetCS(std::move(targetColorSpace)),
|
|
57
|
+
outputFormat(std::move(outputFormat)),
|
|
58
|
+
quality(quality),
|
|
59
|
+
pngOptimize(pngOptimize)
|
|
60
|
+
{
|
|
61
|
+
try {
|
|
62
|
+
inputMat = ConvertToMat(imgVal);
|
|
63
|
+
|
|
64
|
+
// Detect source color space
|
|
65
|
+
if (imgVal.IsObject() && !imgVal.IsBuffer()) {
|
|
66
|
+
Napi::Object obj = imgVal.As<Napi::Object>();
|
|
67
|
+
if (obj.Has("colorSpace")) {
|
|
68
|
+
sourceCS = obj.Get("colorSpace").As<Napi::String>().Utf8Value();
|
|
69
|
+
} else {
|
|
70
|
+
sourceCS = (inputMat.channels() == 4) ? "RGBA"
|
|
71
|
+
: (inputMat.channels() == 3) ? "RGB"
|
|
72
|
+
: "GRAY";
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
sourceCS = (inputMat.channels() == 4) ? "RGBA"
|
|
76
|
+
: (inputMat.channels() == 3) ? "RGB"
|
|
77
|
+
: "GRAY";
|
|
78
|
+
}
|
|
79
|
+
} catch (const Napi::Error& e) { SetError(e.Message()); }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
protected:
|
|
83
|
+
void Execute() override {
|
|
84
|
+
try {
|
|
85
|
+
auto t0 = std::chrono::steady_clock::now();
|
|
86
|
+
|
|
87
|
+
// Identity fast-path: same source and target
|
|
88
|
+
if (sourceCS == targetCS) {
|
|
89
|
+
resultMat = inputMat;
|
|
90
|
+
} else {
|
|
91
|
+
const std::string key = MakeKey(sourceCS, targetCS);
|
|
92
|
+
const auto& table = ConversionTable();
|
|
93
|
+
auto it = table.find(key);
|
|
94
|
+
if (it == table.end()) {
|
|
95
|
+
SetError("Unsupported color space conversion: " + sourceCS + " -> " + targetCS);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
cv::cvtColor(inputMat, resultMat, it->second);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
taskMs = std::chrono::duration<double, std::milli>(
|
|
102
|
+
std::chrono::steady_clock::now() - t0).count();
|
|
103
|
+
|
|
104
|
+
// Multi-format encoding
|
|
105
|
+
if (outputFormat != "raw") {
|
|
106
|
+
const cv::Mat srcForEncoding =
|
|
107
|
+
PrepareForEncoding(resultMat, targetCS, outputFormat);
|
|
108
|
+
encodeMs = EncodeToFormat(srcForEncoding, encodedBuf, outputFormat, quality, pngOptimize);
|
|
109
|
+
}
|
|
110
|
+
} catch (const std::exception& e) { SetError(e.what()); }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
void OnOK() override {
|
|
114
|
+
Napi::Env env = Env();
|
|
115
|
+
Napi::Value jsImg = (outputFormat != "raw")
|
|
116
|
+
? VectorToBuffer(env, std::move(encodedBuf))
|
|
117
|
+
: MatToRawJS(env, resultMat, targetCS);
|
|
118
|
+
|
|
119
|
+
Napi::Object res = Napi::Object::New(env);
|
|
120
|
+
res.Set("image", jsImg);
|
|
121
|
+
res.Set("timing", MakeTimingJS(env, 0.0, taskMs, encodeMs));
|
|
122
|
+
Callback().Call({ env.Null(), res });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
void OnError(const Napi::Error& e) override {
|
|
126
|
+
Callback().Call({ e.Value(), Env().Null() });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private:
|
|
130
|
+
cv::Mat inputMat, resultMat;
|
|
131
|
+
std::string sourceCS;
|
|
132
|
+
std::string targetCS;
|
|
133
|
+
std::string outputFormat;
|
|
134
|
+
int quality;
|
|
135
|
+
bool pngOptimize;
|
|
136
|
+
|
|
137
|
+
double taskMs = 0.0;
|
|
138
|
+
double encodeMs = 0.0;
|
|
139
|
+
std::vector<uchar> encodedBuf;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// ───────── Binding JS → C++ ────────────────────────────────────────────
|
|
143
|
+
// colorConvert(image, targetColorSpace, outputFormat, quality, pngOptimize, callback)
|
|
144
|
+
Napi::Value ColorConvert(const Napi::CallbackInfo& info)
|
|
145
|
+
{
|
|
146
|
+
Napi::Env env = info.Env();
|
|
147
|
+
if (info.Length() < 3 || info.Length() > 6 ||
|
|
148
|
+
!info[info.Length()-1].IsFunction())
|
|
149
|
+
return Napi::TypeError::New(env,
|
|
150
|
+
"colorConvert(image, targetColorSpace, [outputFormat], [quality], [pngOptimize], callback)").Value();
|
|
151
|
+
|
|
152
|
+
int i = 0;
|
|
153
|
+
Napi::Value img = info[i++];
|
|
154
|
+
std::string targetColorSpace = info[i++].As<Napi::String>().Utf8Value();
|
|
155
|
+
|
|
156
|
+
// Handle optional parameters
|
|
157
|
+
std::string outputFormat = "raw";
|
|
158
|
+
int quality = 90;
|
|
159
|
+
bool pngOptimize = false;
|
|
160
|
+
|
|
161
|
+
if (info.Length() - i >= 2) {
|
|
162
|
+
outputFormat = info[i++].As<Napi::String>().Utf8Value();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (info.Length() - i >= 2) {
|
|
166
|
+
quality = info[i++].As<Napi::Number>().Int32Value();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (info.Length() - i >= 2) {
|
|
170
|
+
pngOptimize = info[i++].As<Napi::Boolean>().Value();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
Napi::Function cb = info[i].As<Napi::Function>();
|
|
174
|
+
|
|
175
|
+
auto* worker = new ColorConvertWorker(
|
|
176
|
+
cb,
|
|
177
|
+
img,
|
|
178
|
+
targetColorSpace,
|
|
179
|
+
outputFormat,
|
|
180
|
+
quality,
|
|
181
|
+
pngOptimize);
|
|
182
|
+
worker->Queue();
|
|
183
|
+
return env.Undefined();
|
|
184
|
+
}
|
|
@@ -19,12 +19,12 @@ std::string DetectChannelFormat(const Napi::Value& jsImg, const cv::Mat& mat) {
|
|
|
19
19
|
// Default based on channel count
|
|
20
20
|
else {
|
|
21
21
|
const int channels = mat.channels();
|
|
22
|
-
return (channels == 4) ? "
|
|
22
|
+
return (channels == 4) ? "RGBA" : (channels == 3) ? "RGB" : "GRAY";
|
|
23
23
|
}
|
|
24
24
|
} else {
|
|
25
25
|
// Buffer input - determine from OpenCV Mat
|
|
26
26
|
const int channels = mat.channels();
|
|
27
|
-
return (channels == 4) ? "
|
|
27
|
+
return (channels == 4) ? "RGBA" : (channels == 3) ? "RGB" : "GRAY";
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -29,14 +29,14 @@ public:
|
|
|
29
29
|
}
|
|
30
30
|
// Default based on channel count
|
|
31
31
|
else {
|
|
32
|
-
channel_ = (input_.channels() == 4) ? "
|
|
33
|
-
: (input_.channels() == 3) ? "
|
|
32
|
+
channel_ = (input_.channels() == 4) ? "RGBA"
|
|
33
|
+
: (input_.channels() == 3) ? "RGB"
|
|
34
34
|
: "GRAY";
|
|
35
35
|
}
|
|
36
36
|
} else {
|
|
37
37
|
// Buffer input - determine from OpenCV Mat
|
|
38
|
-
channel_ = (input_.channels() == 4) ? "
|
|
39
|
-
: (input_.channels() == 3) ? "
|
|
38
|
+
channel_ = (input_.channels() == 4) ? "RGBA"
|
|
39
|
+
: (input_.channels() == 3) ? "RGB"
|
|
40
40
|
: "GRAY";
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -40,14 +40,14 @@ public:
|
|
|
40
40
|
}
|
|
41
41
|
// Default based on channel count
|
|
42
42
|
else {
|
|
43
|
-
channel_ = (input_.channels() == 4) ? "
|
|
44
|
-
: (input_.channels() == 3) ? "
|
|
43
|
+
channel_ = (input_.channels() == 4) ? "RGBA"
|
|
44
|
+
: (input_.channels() == 3) ? "RGB"
|
|
45
45
|
: "GRAY";
|
|
46
46
|
}
|
|
47
47
|
} else {
|
|
48
48
|
// Buffer input - determine from OpenCV Mat
|
|
49
|
-
channel_ = (input_.channels() == 4) ? "
|
|
50
|
-
: (input_.channels() == 3) ? "
|
|
49
|
+
channel_ = (input_.channels() == 4) ? "RGBA"
|
|
50
|
+
: (input_.channels() == 3) ? "RGB"
|
|
51
51
|
: "GRAY";
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -322,7 +322,7 @@ private:
|
|
|
322
322
|
}
|
|
323
323
|
// Default based on channel count
|
|
324
324
|
const int channels = mat.channels();
|
|
325
|
-
return (channels == 4) ? "
|
|
325
|
+
return (channels == 4) ? "RGBA" : (channels == 3) ? "RGB" : "GRAY";
|
|
326
326
|
}
|
|
327
327
|
|
|
328
328
|
// Convert image to grayscale
|
|
@@ -14,6 +14,7 @@ Napi::Value AddMasks(const Napi::CallbackInfo& info);
|
|
|
14
14
|
Napi::Value AddBBs(const Napi::CallbackInfo& info);
|
|
15
15
|
Napi::Value ImageAlign(const Napi::CallbackInfo& info);
|
|
16
16
|
Napi::Value Draw(const Napi::CallbackInfo& info);
|
|
17
|
+
Napi::Value ColorConvert(const Napi::CallbackInfo& info);
|
|
17
18
|
|
|
18
19
|
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
19
20
|
exports.Set(Napi::String::New(env, "resize"), Napi::Function::New(env, Resize));
|
|
@@ -30,6 +31,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
|
30
31
|
exports.Set(Napi::String::New(env, "addBBs"), Napi::Function::New(env, AddBBs));
|
|
31
32
|
exports.Set(Napi::String::New(env, "imageAlign"), Napi::Function::New(env, ImageAlign));
|
|
32
33
|
exports.Set(Napi::String::New(env, "draw"), Napi::Function::New(env, Draw));
|
|
34
|
+
exports.Set(Napi::String::New(env, "colorConvert"), Napi::Function::New(env, ColorConvert));
|
|
33
35
|
return exports;
|
|
34
36
|
}
|
|
35
37
|
|
|
@@ -69,14 +69,14 @@ public:
|
|
|
69
69
|
}
|
|
70
70
|
// Default based on channel count
|
|
71
71
|
else {
|
|
72
|
-
channel = (images_[i].channels() == 4) ? "
|
|
73
|
-
: (images_[i].channels() == 3) ? "
|
|
72
|
+
channel = (images_[i].channels() == 4) ? "RGBA"
|
|
73
|
+
: (images_[i].channels() == 3) ? "RGB"
|
|
74
74
|
: "GRAY";
|
|
75
75
|
}
|
|
76
76
|
} else {
|
|
77
77
|
// Buffer input - determine from OpenCV Mat
|
|
78
|
-
channel = (images_[i].channels() == 4) ? "
|
|
79
|
-
: (images_[i].channels() == 3) ? "
|
|
78
|
+
channel = (images_[i].channels() == 4) ? "RGBA"
|
|
79
|
+
: (images_[i].channels() == 3) ? "RGB"
|
|
80
80
|
: "GRAY";
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -34,14 +34,14 @@ public:
|
|
|
34
34
|
}
|
|
35
35
|
// Default based on channel count
|
|
36
36
|
else {
|
|
37
|
-
channel_ = (src_.channels() == 4) ? "
|
|
38
|
-
: (src_.channels() == 3) ? "
|
|
37
|
+
channel_ = (src_.channels() == 4) ? "RGBA"
|
|
38
|
+
: (src_.channels() == 3) ? "RGB"
|
|
39
39
|
: "GRAY";
|
|
40
40
|
}
|
|
41
41
|
} else {
|
|
42
42
|
// Buffer input - determine from OpenCV Mat
|
|
43
|
-
channel_ = (src_.channels() == 4) ? "
|
|
44
|
-
: (src_.channels() == 3) ? "
|
|
43
|
+
channel_ = (src_.channels() == 4) ? "RGBA"
|
|
44
|
+
: (src_.channels() == 3) ? "RGB"
|
|
45
45
|
: "GRAY";
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -41,14 +41,14 @@ ResizeWorker(Napi::Function& callback,
|
|
|
41
41
|
}
|
|
42
42
|
// Default based on channel count
|
|
43
43
|
else {
|
|
44
|
-
channelOrder = (inputMat.channels() == 4) ? "
|
|
45
|
-
: (inputMat.channels() == 3) ? "
|
|
44
|
+
channelOrder = (inputMat.channels() == 4) ? "RGBA"
|
|
45
|
+
: (inputMat.channels() == 3) ? "RGB"
|
|
46
46
|
: "GRAY";
|
|
47
47
|
}
|
|
48
48
|
} else {
|
|
49
49
|
// Buffer input - determine from OpenCV Mat
|
|
50
|
-
channelOrder = (inputMat.channels() == 4) ? "
|
|
51
|
-
: (inputMat.channels() == 3) ? "
|
|
50
|
+
channelOrder = (inputMat.channels() == 4) ? "RGBA"
|
|
51
|
+
: (inputMat.channels() == 3) ? "RGB"
|
|
52
52
|
: "GRAY";
|
|
53
53
|
}
|
|
54
54
|
} catch (const Napi::Error& e) {
|
|
@@ -34,14 +34,14 @@ public:
|
|
|
34
34
|
}
|
|
35
35
|
// Default based on channel count
|
|
36
36
|
else {
|
|
37
|
-
channelOrder = (inputMat.channels() == 4) ? "
|
|
38
|
-
: (inputMat.channels() == 3) ? "
|
|
37
|
+
channelOrder = (inputMat.channels() == 4) ? "RGBA"
|
|
38
|
+
: (inputMat.channels() == 3) ? "RGB"
|
|
39
39
|
: "GRAY";
|
|
40
40
|
}
|
|
41
41
|
} else {
|
|
42
42
|
// Buffer input - determine from OpenCV Mat
|
|
43
|
-
channelOrder = (inputMat.channels() == 4) ? "
|
|
44
|
-
: (inputMat.channels() == 3) ? "
|
|
43
|
+
channelOrder = (inputMat.channels() == 4) ? "RGBA"
|
|
44
|
+
: (inputMat.channels() == 3) ? "RGB"
|
|
45
45
|
: "GRAY";
|
|
46
46
|
}
|
|
47
47
|
} catch (const Napi::Error& e) { SetError(e.Message()); }
|
|
@@ -63,9 +63,9 @@ protected:
|
|
|
63
63
|
|
|
64
64
|
if (near(0) || near(90) || near(180) || near(270)) {
|
|
65
65
|
if (near(0)) resultMat = inputMat; // alias
|
|
66
|
-
else if (near(90)) cv::rotate(inputMat,resultMat,cv::
|
|
66
|
+
else if (near(90)) cv::rotate(inputMat,resultMat,cv::ROTATE_90_COUNTERCLOCKWISE);
|
|
67
67
|
else if (near(180)) cv::rotate(inputMat,resultMat,cv::ROTATE_180);
|
|
68
|
-
else cv::rotate(inputMat,resultMat,cv::
|
|
68
|
+
else cv::rotate(inputMat,resultMat,cv::ROTATE_90_CLOCKWISE);
|
|
69
69
|
} else {
|
|
70
70
|
// Ángulos arbitrarios (sempre PAD)
|
|
71
71
|
int w=inputMat.cols, h=inputMat.rows;
|
|
@@ -341,12 +341,12 @@ inline std::string DetectChannelFormatShared(const Napi::Value& jsImg, const cv:
|
|
|
341
341
|
// Default based on channel count
|
|
342
342
|
else {
|
|
343
343
|
const int channels = mat.channels();
|
|
344
|
-
return (channels == 4) ? "
|
|
344
|
+
return (channels == 4) ? "RGBA" : (channels == 3) ? "RGB" : "GRAY";
|
|
345
345
|
}
|
|
346
346
|
} else {
|
|
347
347
|
// Buffer input - determine from OpenCV Mat
|
|
348
348
|
const int channels = mat.channels();
|
|
349
|
-
return (channels == 4) ? "
|
|
349
|
+
return (channels == 4) ? "RGBA" : (channels == 3) ? "RGB" : "GRAY";
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
|