@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.
- package/.gitattributes +6 -0
- package/.github/workflows/build-prebuild.yml +326 -0
- package/LICENSE +13 -0
- package/README.md +161 -0
- package/artifacts/darwin-arm64/package.json +25 -0
- package/artifacts/linux-arm64/package.json +26 -0
- package/artifacts/linux-x64/package.json +26 -0
- package/artifacts/linuxmusl-x64/package.json +26 -0
- package/assets/flow_time_example.gif +0 -0
- package/assets/nodes/io/array-in-demo.gif +0 -0
- package/assets/nodes/io/array-out-demo.gif +0 -0
- package/assets/nodes/io/array-select-demo.gif +0 -0
- package/assets/nodes/io/image-in-demo.gif +0 -0
- package/assets/nodes/mix/concat-demo.gif +0 -0
- package/assets/nodes/mix/mosaic-demo.gif +0 -0
- package/assets/nodes/transform/crop-demo.gif +0 -0
- package/assets/nodes/transform/filter-demo.gif +0 -0
- package/assets/nodes/transform/padding-demo.gif +0 -0
- package/assets/nodes/transform/resize-demo.gif +0 -0
- package/assets/nodes/transform/rotate-demo.gif +0 -0
- package/docs/nodes/blend/add-mask.md +275 -0
- package/docs/nodes/blend/add-masks.md +284 -0
- package/docs/nodes/blend/blend.md +248 -0
- package/docs/nodes/io/array-in.md +119 -0
- package/docs/nodes/io/array-out.md +150 -0
- package/docs/nodes/io/array-select.md +157 -0
- package/docs/nodes/io/image-in.md +131 -0
- package/docs/nodes/io/image-out.md +179 -0
- package/docs/nodes/io/queue.md +57 -0
- package/docs/nodes/io/save-file.md +30 -0
- package/docs/nodes/mix/advanced-mosaic.md +108 -0
- package/docs/nodes/mix/concat.md +127 -0
- package/docs/nodes/mix/mosaic.md +146 -0
- package/docs/nodes/specialized/cropBB.md +271 -0
- package/docs/nodes/specialized/image-align.md +426 -0
- package/docs/nodes/transform/crop.md +132 -0
- package/docs/nodes/transform/draw.md +77 -0
- package/docs/nodes/transform/filter.md +84 -0
- package/docs/nodes/transform/padding.md +133 -0
- package/docs/nodes/transform/resize.md +158 -0
- package/docs/nodes/transform/rotate.md +121 -0
- package/docs/nodes/util/block-detect.md +46 -0
- package/install.sh +144 -0
- package/node-red-contrib-image-tools/lib/cpp-bridge.js +224 -0
- package/node-red-contrib-image-tools/lib/node-utils.js +529 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +590 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +241 -0
- package/node-red-contrib-image-tools/nodes/blend/add-mask.html +449 -0
- package/node-red-contrib-image-tools/nodes/blend/add-mask.js +170 -0
- package/node-red-contrib-image-tools/nodes/blend/add-masks.html +703 -0
- package/node-red-contrib-image-tools/nodes/blend/add-masks.js +321 -0
- package/node-red-contrib-image-tools/nodes/blend/blend.html +552 -0
- package/node-red-contrib-image-tools/nodes/blend/blend.js +124 -0
- package/node-red-contrib-image-tools/nodes/io/array-in.html +110 -0
- package/node-red-contrib-image-tools/nodes/io/array-in.js +113 -0
- package/node-red-contrib-image-tools/nodes/io/array-out.html +125 -0
- package/node-red-contrib-image-tools/nodes/io/array-out.js +213 -0
- package/node-red-contrib-image-tools/nodes/io/array-select.html +156 -0
- package/node-red-contrib-image-tools/nodes/io/array-select.js +187 -0
- package/node-red-contrib-image-tools/nodes/io/folder-in.html +248 -0
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +335 -0
- package/node-red-contrib-image-tools/nodes/io/image-in.html +146 -0
- package/node-red-contrib-image-tools/nodes/io/image-in.js +143 -0
- package/node-red-contrib-image-tools/nodes/io/image-out.html +506 -0
- package/node-red-contrib-image-tools/nodes/io/image-out.js +545 -0
- package/node-red-contrib-image-tools/nodes/io/queue.html +119 -0
- package/node-red-contrib-image-tools/nodes/io/queue.js +191 -0
- package/node-red-contrib-image-tools/nodes/io/save-file.html +243 -0
- package/node-red-contrib-image-tools/nodes/io/save-file.js +440 -0
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +2149 -0
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +195 -0
- package/node-red-contrib-image-tools/nodes/mix/concat.html +390 -0
- package/node-red-contrib-image-tools/nodes/mix/concat.js +112 -0
- package/node-red-contrib-image-tools/nodes/mix/mosaic.html +550 -0
- package/node-red-contrib-image-tools/nodes/mix/mosaic.js +151 -0
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +268 -0
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +277 -0
- package/node-red-contrib-image-tools/nodes/specialized/image-align.html +528 -0
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +306 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.html +410 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.js +149 -0
- package/node-red-contrib-image-tools/nodes/transform/draw.html +719 -0
- package/node-red-contrib-image-tools/nodes/transform/draw.js +509 -0
- package/node-red-contrib-image-tools/nodes/transform/filter.html +578 -0
- package/node-red-contrib-image-tools/nodes/transform/filter.js +177 -0
- package/node-red-contrib-image-tools/nodes/transform/padding.html +475 -0
- package/node-red-contrib-image-tools/nodes/transform/padding.js +142 -0
- package/node-red-contrib-image-tools/nodes/transform/resize.html +429 -0
- package/node-red-contrib-image-tools/nodes/transform/resize.js +162 -0
- package/node-red-contrib-image-tools/nodes/transform/rotate.html +299 -0
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +141 -0
- package/node-red-contrib-image-tools/nodes/util/block-detect.html +85 -0
- package/node-red-contrib-image-tools/nodes/util/block-detect.js +136 -0
- package/node-red-contrib-image-tools/nodes/util/clean-debug.html +201 -0
- package/node-red-contrib-image-tools/nodes/util/clean-debug.js +393 -0
- package/node-red-contrib-image-tools/package.json +64 -0
- package/npm/darwin-arm64/lib/.gitkeep +1 -0
- package/npm/darwin-arm64/package.json +25 -0
- package/npm/darwin-x64/lib/.gitkeep +1 -0
- package/npm/darwin-x64/package.json +25 -0
- package/npm/linux-arm64/lib/.gitkeep +1 -0
- package/npm/linux-arm64/package.json +26 -0
- package/npm/linux-x64/lib/.gitkeep +1 -0
- package/npm/linux-x64/package.json +26 -0
- package/npm/linuxmusl-x64/lib/.gitkeep +1 -0
- package/npm/linuxmusl-x64/package.json +26 -0
- package/npm/win32-x64/lib/.gitkeep +1 -0
- package/npm/win32-x64/package.json +25 -0
- package/package.json +74 -0
- package/rosepetal-image-engine/binding.gyp +153 -0
- package/rosepetal-image-engine/package.json +19 -0
- package/rosepetal-image-engine/src/add-bbs.cpp +433 -0
- package/rosepetal-image-engine/src/add-mask.cpp +240 -0
- package/rosepetal-image-engine/src/add-masks.cpp +638 -0
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +740 -0
- package/rosepetal-image-engine/src/blend.cpp +200 -0
- package/rosepetal-image-engine/src/concat.cpp +329 -0
- package/rosepetal-image-engine/src/crop.cpp +139 -0
- package/rosepetal-image-engine/src/draw.cpp +414 -0
- package/rosepetal-image-engine/src/filter.cpp +230 -0
- package/rosepetal-image-engine/src/filters/kernels.h +171 -0
- package/rosepetal-image-engine/src/image-align.cpp +551 -0
- package/rosepetal-image-engine/src/main.cpp +36 -0
- package/rosepetal-image-engine/src/mosaic.cpp +373 -0
- package/rosepetal-image-engine/src/padding.cpp +124 -0
- package/rosepetal-image-engine/src/resize.cpp +210 -0
- package/rosepetal-image-engine/src/rotate.cpp +177 -0
- package/rosepetal-image-engine/src/utils.h +563 -0
- package/rosepetal-image-engine/test-formats.js +119 -0
- package/scripts/build-opencv-static.ps1 +166 -0
- package/scripts/build-opencv-static.sh +147 -0
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
// Fichero: src/utils.h
|
|
2
|
+
|
|
3
|
+
#ifndef UTILS_H
|
|
4
|
+
#define UTILS_H
|
|
5
|
+
|
|
6
|
+
#include <napi.h>
|
|
7
|
+
#include <opencv2/opencv.hpp>
|
|
8
|
+
#include <vector>
|
|
9
|
+
#include <string>
|
|
10
|
+
#include <chrono>
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Converts JS input to cv::Mat supporting:
|
|
14
|
+
* - Image object: {data, width, height, channels, colorSpace, dtype}
|
|
15
|
+
* - Buffer: Raw image file data (JPEG/PNG/WebP)
|
|
16
|
+
*/
|
|
17
|
+
inline cv::Mat ConvertToMat(const Napi::Value& input) {
|
|
18
|
+
Napi::Env env = input.Env();
|
|
19
|
+
|
|
20
|
+
// --- 1. Raw image object -------------------------
|
|
21
|
+
if (input.IsObject() && !input.IsBuffer()) {
|
|
22
|
+
Napi::Object obj = input.As<Napi::Object>();
|
|
23
|
+
if (obj.Has("data") && obj.Has("width") && obj.Has("height")) {
|
|
24
|
+
|
|
25
|
+
auto dataBuf = obj.Get("data").As<Napi::Buffer<uint8_t>>();
|
|
26
|
+
|
|
27
|
+
int width = obj.Get("width").As<Napi::Number>().Int32Value();
|
|
28
|
+
int height = obj.Get("height").As<Napi::Number>().Int32Value();
|
|
29
|
+
|
|
30
|
+
// Determine channel count and color space
|
|
31
|
+
int channels = 3; // default
|
|
32
|
+
std::string colorSpace = "RGB"; // default
|
|
33
|
+
|
|
34
|
+
if (obj.Has("channels")) {
|
|
35
|
+
auto channelsVal = obj.Get("channels");
|
|
36
|
+
|
|
37
|
+
if (channelsVal.IsNumber()) {
|
|
38
|
+
channels = channelsVal.As<Napi::Number>().Int32Value();
|
|
39
|
+
|
|
40
|
+
// Get colorSpace if available
|
|
41
|
+
if (obj.Has("colorSpace")) {
|
|
42
|
+
colorSpace = obj.Get("colorSpace").As<Napi::String>().Utf8Value();
|
|
43
|
+
} else {
|
|
44
|
+
// Default colorSpace based on channels
|
|
45
|
+
switch (channels) {
|
|
46
|
+
case 1: colorSpace = "GRAY"; break;
|
|
47
|
+
case 3: colorSpace = "RGB"; break;
|
|
48
|
+
case 4: colorSpace = "RGBA"; break;
|
|
49
|
+
default:
|
|
50
|
+
throw Napi::Error::New(env, "Unsupported channel count: " + std::to_string(channels));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
throw Napi::Error::New(env, "Channels must be a number");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Determine OpenCV type based on dtype and channels
|
|
59
|
+
int cvType = CV_8UC3; // default
|
|
60
|
+
|
|
61
|
+
if (obj.Has("dtype")) {
|
|
62
|
+
std::string dtype = obj.Get("dtype").As<Napi::String>().Utf8Value();
|
|
63
|
+
if (dtype == "uint8") {
|
|
64
|
+
switch (channels) {
|
|
65
|
+
case 1: cvType = CV_8UC1; break;
|
|
66
|
+
case 3: cvType = CV_8UC3; break;
|
|
67
|
+
case 4: cvType = CV_8UC4; break;
|
|
68
|
+
default: throw Napi::Error::New(env, "Unsupported channel count for uint8: " + std::to_string(channels));
|
|
69
|
+
}
|
|
70
|
+
} else if (dtype == "uint16") {
|
|
71
|
+
switch (channels) {
|
|
72
|
+
case 1: cvType = CV_16UC1; break;
|
|
73
|
+
case 3: cvType = CV_16UC3; break;
|
|
74
|
+
case 4: cvType = CV_16UC4; break;
|
|
75
|
+
default: throw Napi::Error::New(env, "Unsupported channel count for uint16: " + std::to_string(channels));
|
|
76
|
+
}
|
|
77
|
+
} else if (dtype == "float32") {
|
|
78
|
+
switch (channels) {
|
|
79
|
+
case 1: cvType = CV_32FC1; break;
|
|
80
|
+
case 3: cvType = CV_32FC3; break;
|
|
81
|
+
case 4: cvType = CV_32FC4; break;
|
|
82
|
+
default: throw Napi::Error::New(env, "Unsupported channel count for float32: " + std::to_string(channels));
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
throw Napi::Error::New(env, "Unsupported dtype: " + dtype);
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
// Default uint8 handling
|
|
89
|
+
switch (channels) {
|
|
90
|
+
case 1: cvType = CV_8UC1; break;
|
|
91
|
+
case 3: cvType = CV_8UC3; break;
|
|
92
|
+
case 4: cvType = CV_8UC4; break;
|
|
93
|
+
default: throw Napi::Error::New(env, "Unsupported channel count: " + std::to_string(channels));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return cv::Mat(height, width, cvType, dataBuf.Data());
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// --- 2. Direct Buffer (JPEG/PNG/WebP file data) -------------------------
|
|
102
|
+
if (input.IsBuffer()) {
|
|
103
|
+
auto buf = input.As<Napi::Buffer<uint8_t>>();
|
|
104
|
+
cv::Mat tmp(1, buf.Length(), CV_8UC1, buf.Data());
|
|
105
|
+
cv::Mat img = cv::imdecode(tmp, cv::IMREAD_UNCHANGED);
|
|
106
|
+
|
|
107
|
+
if (img.empty()) {
|
|
108
|
+
throw Napi::Error::New(env, "Failed to decode image buffer.");
|
|
109
|
+
}
|
|
110
|
+
return img; // BGR/BGRA/GRAY according to file format
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
throw Napi::Error::New(env,
|
|
114
|
+
"Invalid input: Expected Buffer or image object with {data, width, height}.");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
// Convierte a BGR 3-canales para JPEG si hace falta
|
|
120
|
+
inline cv::Mat ToBgrForJpg(const cv::Mat& src, const std::string& order) {
|
|
121
|
+
if (src.channels() == 1 || order == "BGR") return src; // ya OK
|
|
122
|
+
cv::Mat dst;
|
|
123
|
+
if (order == "RGB") cv::cvtColor(src, dst, cv::COLOR_RGB2BGR);
|
|
124
|
+
else if (order == "BGRA") cv::cvtColor(src, dst, cv::COLOR_BGRA2BGR);
|
|
125
|
+
else if (order == "RGBA") cv::cvtColor(src, dst, cv::COLOR_RGBA2BGR);
|
|
126
|
+
else dst = src; // fallback
|
|
127
|
+
return dst;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
// Multi-format image encoding system supporting JPG, PNG, WebP
|
|
132
|
+
enum class ImageFormat {
|
|
133
|
+
RAW = 0,
|
|
134
|
+
JPG = 1,
|
|
135
|
+
PNG = 2,
|
|
136
|
+
WEBP = 3
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// Convert format string to enum
|
|
140
|
+
inline ImageFormat ParseImageFormat(const std::string& format) {
|
|
141
|
+
if (format == "jpg" || format == "jpeg") return ImageFormat::JPG;
|
|
142
|
+
if (format == "png") return ImageFormat::PNG;
|
|
143
|
+
if (format == "webp") return ImageFormat::WEBP;
|
|
144
|
+
return ImageFormat::RAW;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Fast JPEG compression function
|
|
148
|
+
inline double EncodeToJpgFast(const cv::Mat& src,
|
|
149
|
+
std::vector<uchar>& out,
|
|
150
|
+
int quality = 90) // 90 = buen balance
|
|
151
|
+
{
|
|
152
|
+
const int64 t0 = cv::getTickCount();
|
|
153
|
+
|
|
154
|
+
// --- ruta OpenCV ---------------------------
|
|
155
|
+
out.reserve(src.total() >> 1); // evita realloc (~50 %)
|
|
156
|
+
std::vector<int> p{ cv::IMWRITE_JPEG_QUALITY, quality,
|
|
157
|
+
cv::IMWRITE_JPEG_PROGRESSIVE, 0,
|
|
158
|
+
cv::IMWRITE_JPEG_OPTIMIZE, 0 };
|
|
159
|
+
cv::imencode(".jpg", src, out, p);
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
return (cv::getTickCount() - t0) / cv::getTickFrequency() * 1e3;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Enhanced multi-format encoding function
|
|
166
|
+
inline double EncodeToFormat(const cv::Mat& src,
|
|
167
|
+
std::vector<uchar>& out,
|
|
168
|
+
const std::string& format,
|
|
169
|
+
int quality = 90,
|
|
170
|
+
bool pngOptimize = false)
|
|
171
|
+
{
|
|
172
|
+
const int64 t0 = cv::getTickCount();
|
|
173
|
+
ImageFormat fmt = ParseImageFormat(format);
|
|
174
|
+
|
|
175
|
+
switch (fmt) {
|
|
176
|
+
case ImageFormat::JPG: {
|
|
177
|
+
out.reserve(src.total() >> 1);
|
|
178
|
+
std::vector<int> params{
|
|
179
|
+
cv::IMWRITE_JPEG_QUALITY, quality,
|
|
180
|
+
cv::IMWRITE_JPEG_PROGRESSIVE, 0,
|
|
181
|
+
cv::IMWRITE_JPEG_OPTIMIZE, 0
|
|
182
|
+
};
|
|
183
|
+
cv::imencode(".jpg", src, out, params);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
case ImageFormat::PNG: {
|
|
187
|
+
out.reserve(src.total());
|
|
188
|
+
// Use compression level 0 (fastest) when pngOptimize is false, 6 (balanced) when true
|
|
189
|
+
int compressionLevel = pngOptimize ? 6 : 0;
|
|
190
|
+
std::vector<int> params{
|
|
191
|
+
cv::IMWRITE_PNG_COMPRESSION, compressionLevel,
|
|
192
|
+
cv::IMWRITE_PNG_STRATEGY, cv::IMWRITE_PNG_STRATEGY_DEFAULT
|
|
193
|
+
};
|
|
194
|
+
cv::imencode(".png", src, out, params);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case ImageFormat::WEBP: {
|
|
198
|
+
out.reserve(src.total() >> 1);
|
|
199
|
+
std::vector<int> params{
|
|
200
|
+
cv::IMWRITE_WEBP_QUALITY, quality
|
|
201
|
+
};
|
|
202
|
+
cv::imencode(".webp", src, out, params);
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
default:
|
|
206
|
+
// RAW format - should not reach here, handled at higher level
|
|
207
|
+
throw std::runtime_error("RAW format encoding not supported");
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return (cv::getTickCount() - t0) / cv::getTickFrequency() * 1e3;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
// Devuelve "BGRA", "BGR" o "GRAY" a partir de "int8_BGRA", "int16_GRAY", etc.
|
|
216
|
+
inline std::string ExtractChannelOrder(const std::string& chFull) {
|
|
217
|
+
auto pos = chFull.find('_');
|
|
218
|
+
return pos == std::string::npos ? chFull : chFull.substr(pos + 1);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
// Convierte "#RRGGBB" o "rgb(r,g,b)" ā cv::Scalar(B,G,R). Devuelve `def` si falla.
|
|
223
|
+
inline cv::Scalar ParseColor(const std::string& s,
|
|
224
|
+
const cv::Scalar& def = {0,0,0})
|
|
225
|
+
{
|
|
226
|
+
if (s.empty()) return def;
|
|
227
|
+
|
|
228
|
+
if (s[0] == '#') { // forma #RRGGBB
|
|
229
|
+
unsigned v = std::stoul(s.substr(1), nullptr, 16);
|
|
230
|
+
return cv::Scalar(v & 0xFF, (v >> 8) & 0xFF, (v >> 16) & 0xFF);
|
|
231
|
+
}
|
|
232
|
+
int r, g, b;
|
|
233
|
+
if (std::sscanf(s.c_str(), "rgb(%d,%d,%d)", &r, &g, &b) == 3)
|
|
234
|
+
return cv::Scalar(b, g, r);
|
|
235
|
+
|
|
236
|
+
return def;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Cede un std::vector<uchar> al JS sin copia (zero-copy).
|
|
240
|
+
inline Napi::Value VectorToBuffer(Napi::Env env, std::vector<uchar>&& v)
|
|
241
|
+
{
|
|
242
|
+
auto* vec = new std::vector<uchar>(std::move(v)); // ⢠heap
|
|
243
|
+
return Napi::Buffer<uchar>::New(
|
|
244
|
+
env, vec->data(), vec->size(),
|
|
245
|
+
[](Napi::Env, uchar*, std::vector<uchar>* p) { delete p; }, vec);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Converts cv::Mat to new JS format {width, height, channels, colorSpace, dtype, data}
|
|
249
|
+
inline Napi::Object MatToRawJS(Napi::Env env,
|
|
250
|
+
const cv::Mat& m,
|
|
251
|
+
const std::string& colorSpace)
|
|
252
|
+
{
|
|
253
|
+
Napi::Object o = Napi::Object::New(env);
|
|
254
|
+
o.Set("width", Napi::Number::New(env, m.cols));
|
|
255
|
+
o.Set("height", Napi::Number::New(env, m.rows));
|
|
256
|
+
o.Set("channels", Napi::Number::New(env, m.channels()));
|
|
257
|
+
o.Set("colorSpace", Napi::String::New(env, colorSpace));
|
|
258
|
+
|
|
259
|
+
// Determine dtype from OpenCV depth
|
|
260
|
+
std::string dtype;
|
|
261
|
+
switch (m.depth()) {
|
|
262
|
+
case CV_8U: dtype = "uint8"; break;
|
|
263
|
+
case CV_16U: dtype = "uint16"; break;
|
|
264
|
+
case CV_32F: dtype = "float32"; break;
|
|
265
|
+
default: dtype = "uint8"; break; // fallback
|
|
266
|
+
}
|
|
267
|
+
o.Set("dtype", Napi::String::New(env, dtype));
|
|
268
|
+
|
|
269
|
+
// Copy data
|
|
270
|
+
size_t bytes = m.total() * m.elemSize();
|
|
271
|
+
auto* raw = new uint8_t[bytes];
|
|
272
|
+
std::memcpy(raw, m.data, bytes);
|
|
273
|
+
|
|
274
|
+
o.Set("data", Napi::Buffer<uint8_t>::New(
|
|
275
|
+
env, raw, bytes,
|
|
276
|
+
[](Napi::Env, uint8_t* p) { delete[] p; }));
|
|
277
|
+
|
|
278
|
+
return o;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Crea el objeto { convertMs, taskMs, encodeMs } para devolver a JS.
|
|
282
|
+
inline Napi::Object MakeTimingJS(Napi::Env env,
|
|
283
|
+
double convertMs,
|
|
284
|
+
double taskMs,
|
|
285
|
+
double encodeMs = 0.0)
|
|
286
|
+
{
|
|
287
|
+
Napi::Object t = Napi::Object::New(env);
|
|
288
|
+
t.Set("convertMs", Napi::Number::New(env, convertMs));
|
|
289
|
+
t.Set("taskMs", Napi::Number::New(env, taskMs));
|
|
290
|
+
t.Set("encodeMs", Napi::Number::New(env, encodeMs));
|
|
291
|
+
return t;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Helper function to detect channel format for individual images (shared between blend and concat)
|
|
295
|
+
inline std::string DetectChannelFormatShared(const Napi::Value& jsImg, const cv::Mat& mat) {
|
|
296
|
+
if (jsImg.IsObject() && !jsImg.IsBuffer()) {
|
|
297
|
+
Napi::Object obj = jsImg.As<Napi::Object>();
|
|
298
|
+
|
|
299
|
+
// Check for colorSpace field first
|
|
300
|
+
if (obj.Has("colorSpace")) {
|
|
301
|
+
return obj.Get("colorSpace").As<Napi::String>().Utf8Value();
|
|
302
|
+
}
|
|
303
|
+
// Default based on channel count
|
|
304
|
+
else {
|
|
305
|
+
const int channels = mat.channels();
|
|
306
|
+
return (channels == 4) ? "BGRA" : (channels == 3) ? "BGR" : "GRAY";
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
// Buffer input - determine from OpenCV Mat
|
|
310
|
+
const int channels = mat.channels();
|
|
311
|
+
return (channels == 4) ? "BGRA" : (channels == 3) ? "BGR" : "GRAY";
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Helper function to convert image to target channel format (shared between blend and concat)
|
|
316
|
+
inline cv::Mat ConvertToTargetFormatShared(const cv::Mat& src, const std::string& srcFormat, const std::string& targetFormat) {
|
|
317
|
+
if (srcFormat == targetFormat) {
|
|
318
|
+
return src; // No conversion needed
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
cv::Mat dst;
|
|
322
|
+
|
|
323
|
+
// Convert to target format
|
|
324
|
+
if (srcFormat == "GRAY" && targetFormat == "BGR") {
|
|
325
|
+
cv::cvtColor(src, dst, cv::COLOR_GRAY2BGR);
|
|
326
|
+
} else if (srcFormat == "GRAY" && targetFormat == "RGB") {
|
|
327
|
+
cv::cvtColor(src, dst, cv::COLOR_GRAY2RGB);
|
|
328
|
+
} else if (srcFormat == "GRAY" && targetFormat == "BGRA") {
|
|
329
|
+
cv::cvtColor(src, dst, cv::COLOR_GRAY2BGRA);
|
|
330
|
+
} else if (srcFormat == "GRAY" && targetFormat == "RGBA") {
|
|
331
|
+
cv::cvtColor(src, dst, cv::COLOR_GRAY2RGBA);
|
|
332
|
+
} else if (srcFormat == "BGR" && targetFormat == "RGB") {
|
|
333
|
+
cv::cvtColor(src, dst, cv::COLOR_BGR2RGB);
|
|
334
|
+
} else if (srcFormat == "RGB" && targetFormat == "BGR") {
|
|
335
|
+
cv::cvtColor(src, dst, cv::COLOR_RGB2BGR);
|
|
336
|
+
} else if (srcFormat == "BGR" && targetFormat == "BGRA") {
|
|
337
|
+
cv::cvtColor(src, dst, cv::COLOR_BGR2BGRA);
|
|
338
|
+
} else if (srcFormat == "BGR" && targetFormat == "RGBA") {
|
|
339
|
+
cv::cvtColor(src, dst, cv::COLOR_BGR2RGBA);
|
|
340
|
+
} else if (srcFormat == "RGB" && targetFormat == "RGBA") {
|
|
341
|
+
cv::cvtColor(src, dst, cv::COLOR_RGB2RGBA);
|
|
342
|
+
} else if (srcFormat == "RGB" && targetFormat == "BGRA") {
|
|
343
|
+
cv::cvtColor(src, dst, cv::COLOR_RGB2BGRA);
|
|
344
|
+
} else if (srcFormat == "BGRA" && targetFormat == "BGR") {
|
|
345
|
+
cv::cvtColor(src, dst, cv::COLOR_BGRA2BGR);
|
|
346
|
+
} else if (srcFormat == "RGBA" && targetFormat == "RGB") {
|
|
347
|
+
cv::cvtColor(src, dst, cv::COLOR_RGBA2RGB);
|
|
348
|
+
} else if (srcFormat == "BGRA" && targetFormat == "RGBA") {
|
|
349
|
+
cv::cvtColor(src, dst, cv::COLOR_BGRA2RGBA);
|
|
350
|
+
} else if (srcFormat == "RGBA" && targetFormat == "BGRA") {
|
|
351
|
+
cv::cvtColor(src, dst, cv::COLOR_RGBA2BGRA);
|
|
352
|
+
} else {
|
|
353
|
+
// Fallback: return source if no conversion available
|
|
354
|
+
dst = src;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return dst;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Helper function to determine the best output channel format from two inputs (shared between blend and add-mask)
|
|
361
|
+
inline std::string DetermineOutputFormat(const std::string& format1, const std::string& format2) {
|
|
362
|
+
// Priority: RGBA > BGRA > RGB > BGR > GRAY
|
|
363
|
+
if (format1 == "RGBA" || format2 == "RGBA") return "RGBA";
|
|
364
|
+
if (format1 == "BGRA" || format2 == "BGRA") return "BGRA";
|
|
365
|
+
if (format1 == "RGB" || format2 == "RGB") return "RGB";
|
|
366
|
+
if (format1 == "BGR" || format2 == "BGR") return "BGR";
|
|
367
|
+
return "GRAY";
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Background removal function - removes specified color with tolerance
|
|
371
|
+
inline cv::Mat removeColorBackground(const cv::Mat& src, const cv::Scalar& bgColor, double tolerance) {
|
|
372
|
+
cv::Mat result;
|
|
373
|
+
cv::Mat hsv_src, hsv_bg;
|
|
374
|
+
|
|
375
|
+
// Validate input image channels
|
|
376
|
+
int srcChannels = src.channels();
|
|
377
|
+
if (srcChannels > 4) {
|
|
378
|
+
throw std::runtime_error("Invalid image: too many channels (" + std::to_string(srcChannels) + "). Expected 1, 3, or 4 channels.");
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// Convert source to HSV for better color matching
|
|
382
|
+
if (srcChannels == 4) {
|
|
383
|
+
// BGRA to HSV (ignore alpha channel for color matching)
|
|
384
|
+
cv::cvtColor(src, hsv_src, cv::COLOR_BGRA2BGR);
|
|
385
|
+
cv::cvtColor(hsv_src, hsv_src, cv::COLOR_BGR2HSV);
|
|
386
|
+
} else if (srcChannels == 3) {
|
|
387
|
+
// BGR to HSV
|
|
388
|
+
cv::cvtColor(src, hsv_src, cv::COLOR_BGR2HSV);
|
|
389
|
+
} else if (srcChannels == 1) {
|
|
390
|
+
// Grayscale to HSV
|
|
391
|
+
cv::Mat gray_bgr;
|
|
392
|
+
cv::cvtColor(src, gray_bgr, cv::COLOR_GRAY2BGR);
|
|
393
|
+
cv::cvtColor(gray_bgr, hsv_src, cv::COLOR_BGR2HSV);
|
|
394
|
+
} else {
|
|
395
|
+
throw std::runtime_error("Invalid image: unsupported channel count (" + std::to_string(srcChannels) + ")");
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Convert background color to HSV
|
|
399
|
+
cv::Mat bg_mat = cv::Mat::ones(1, 1, CV_8UC3);
|
|
400
|
+
bg_mat.at<cv::Vec3b>(0, 0) = cv::Vec3b((uchar)bgColor[2], (uchar)bgColor[1], (uchar)bgColor[0]); // BGR
|
|
401
|
+
cv::cvtColor(bg_mat, hsv_bg, cv::COLOR_BGR2HSV);
|
|
402
|
+
cv::Vec3b target_hsv = hsv_bg.at<cv::Vec3b>(0, 0);
|
|
403
|
+
|
|
404
|
+
// Create mask based on color distance in HSV space
|
|
405
|
+
cv::Mat mask = cv::Mat::zeros(hsv_src.size(), CV_8UC1);
|
|
406
|
+
|
|
407
|
+
// Calculate tolerance thresholds
|
|
408
|
+
double h_tolerance = tolerance * 180; // Hue range: 0-180
|
|
409
|
+
double s_tolerance = tolerance * 255; // Saturation range: 0-255
|
|
410
|
+
double v_tolerance = tolerance * 255; // Value range: 0-255
|
|
411
|
+
|
|
412
|
+
for (int y = 0; y < hsv_src.rows; y++) {
|
|
413
|
+
for (int x = 0; x < hsv_src.cols; x++) {
|
|
414
|
+
cv::Vec3b pixel_hsv = hsv_src.at<cv::Vec3b>(y, x);
|
|
415
|
+
|
|
416
|
+
// Calculate distance in HSV space
|
|
417
|
+
double h_diff = std::abs(pixel_hsv[0] - target_hsv[0]);
|
|
418
|
+
double s_diff = std::abs(pixel_hsv[1] - target_hsv[1]);
|
|
419
|
+
double v_diff = std::abs(pixel_hsv[2] - target_hsv[2]);
|
|
420
|
+
|
|
421
|
+
// Handle hue wraparound (0 and 180 are close)
|
|
422
|
+
if (h_diff > 90) h_diff = 180 - h_diff;
|
|
423
|
+
|
|
424
|
+
// Check if pixel matches background color within tolerance
|
|
425
|
+
if (h_diff <= h_tolerance && s_diff <= s_tolerance && v_diff <= v_tolerance) {
|
|
426
|
+
mask.at<uchar>(y, x) = 255; // Mark for removal
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// Apply Gaussian blur to mask edges for smooth transitions
|
|
432
|
+
if (tolerance > 0.01) {
|
|
433
|
+
cv::GaussianBlur(mask, mask, cv::Size(5, 5), 1.0);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Create BGRA result with proper channel handling
|
|
437
|
+
std::vector<cv::Mat> channels;
|
|
438
|
+
|
|
439
|
+
if (srcChannels == 1) {
|
|
440
|
+
// Grayscale input - convert to BGR first
|
|
441
|
+
cv::Mat bgr_src;
|
|
442
|
+
cv::cvtColor(src, bgr_src, cv::COLOR_GRAY2BGR);
|
|
443
|
+
cv::split(bgr_src, channels);
|
|
444
|
+
} else if (srcChannels == 3) {
|
|
445
|
+
// BGR input - use directly
|
|
446
|
+
cv::split(src, channels);
|
|
447
|
+
} else if (srcChannels == 4) {
|
|
448
|
+
// BGRA input - use first 3 channels, ignore existing alpha
|
|
449
|
+
cv::split(src, channels);
|
|
450
|
+
channels.resize(3); // Keep only BGR channels
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// Create alpha channel (inverse of mask - transparent where mask is white)
|
|
454
|
+
cv::Mat alpha;
|
|
455
|
+
cv::bitwise_not(mask, alpha);
|
|
456
|
+
channels.push_back(alpha);
|
|
457
|
+
|
|
458
|
+
// Merge to BGRA (should always have exactly 4 channels)
|
|
459
|
+
cv::merge(channels, result);
|
|
460
|
+
|
|
461
|
+
return result;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// Alpha compositing function - proper layered compositing
|
|
465
|
+
inline cv::Mat alphaComposite(const cv::Mat& base, const cv::Mat& overlay, double overlayOpacity) {
|
|
466
|
+
cv::Mat result;
|
|
467
|
+
|
|
468
|
+
// Validate input images
|
|
469
|
+
if (base.channels() > 4 || overlay.channels() > 4) {
|
|
470
|
+
throw std::runtime_error("Invalid images for alpha compositing: too many channels. Base: " +
|
|
471
|
+
std::to_string(base.channels()) + ", Overlay: " +
|
|
472
|
+
std::to_string(overlay.channels()));
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// Ensure both images are in BGRA format for alpha compositing
|
|
476
|
+
cv::Mat base_bgra, overlay_bgra;
|
|
477
|
+
|
|
478
|
+
if (base.channels() == 4) {
|
|
479
|
+
base_bgra = base;
|
|
480
|
+
} else if (base.channels() == 3) {
|
|
481
|
+
cv::cvtColor(base, base_bgra, cv::COLOR_BGR2BGRA);
|
|
482
|
+
} else if (base.channels() == 1) {
|
|
483
|
+
cv::cvtColor(base, base_bgra, cv::COLOR_GRAY2BGRA);
|
|
484
|
+
} else {
|
|
485
|
+
throw std::runtime_error("Unsupported base image channel count: " + std::to_string(base.channels()));
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
if (overlay.channels() == 4) {
|
|
489
|
+
overlay_bgra = overlay;
|
|
490
|
+
} else if (overlay.channels() == 3) {
|
|
491
|
+
cv::cvtColor(overlay, overlay_bgra, cv::COLOR_BGR2BGRA);
|
|
492
|
+
} else if (overlay.channels() == 1) {
|
|
493
|
+
cv::cvtColor(overlay, overlay_bgra, cv::COLOR_GRAY2BGRA);
|
|
494
|
+
} else {
|
|
495
|
+
throw std::runtime_error("Unsupported overlay image channel count: " + std::to_string(overlay.channels()));
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// Ensure same dimensions
|
|
499
|
+
if (base_bgra.size() != overlay_bgra.size()) {
|
|
500
|
+
cv::Size targetSize(std::max(base_bgra.cols, overlay_bgra.cols),
|
|
501
|
+
std::max(base_bgra.rows, overlay_bgra.rows));
|
|
502
|
+
if (base_bgra.size() != targetSize) {
|
|
503
|
+
cv::resize(base_bgra, base_bgra, targetSize);
|
|
504
|
+
}
|
|
505
|
+
if (overlay_bgra.size() != targetSize) {
|
|
506
|
+
cv::resize(overlay_bgra, overlay_bgra, targetSize);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
result = cv::Mat::zeros(base_bgra.size(), CV_8UC4);
|
|
511
|
+
|
|
512
|
+
// Perform alpha compositing pixel by pixel
|
|
513
|
+
for (int y = 0; y < result.rows; y++) {
|
|
514
|
+
for (int x = 0; x < result.cols; x++) {
|
|
515
|
+
cv::Vec4b base_pixel = base_bgra.at<cv::Vec4b>(y, x);
|
|
516
|
+
cv::Vec4b overlay_pixel = overlay_bgra.at<cv::Vec4b>(y, x);
|
|
517
|
+
|
|
518
|
+
// Normalize alpha values [0, 1]
|
|
519
|
+
double base_alpha = base_pixel[3] / 255.0;
|
|
520
|
+
double overlay_alpha = (overlay_pixel[3] / 255.0) * overlayOpacity;
|
|
521
|
+
|
|
522
|
+
// Alpha compositing formula: result = overlay * overlay_alpha + base * (1 - overlay_alpha)
|
|
523
|
+
// But we need to handle the case where overlay is transparent
|
|
524
|
+
double result_alpha = overlay_alpha + base_alpha * (1.0 - overlay_alpha);
|
|
525
|
+
|
|
526
|
+
cv::Vec4b result_pixel;
|
|
527
|
+
|
|
528
|
+
if (result_alpha > 0.001) { // Avoid division by very small numbers
|
|
529
|
+
for (int c = 0; c < 3; c++) { // BGR channels
|
|
530
|
+
double result_color = (overlay_pixel[c] * overlay_alpha +
|
|
531
|
+
base_pixel[c] * base_alpha * (1.0 - overlay_alpha)) / result_alpha;
|
|
532
|
+
result_pixel[c] = cv::saturate_cast<uchar>(result_color);
|
|
533
|
+
}
|
|
534
|
+
result_pixel[3] = cv::saturate_cast<uchar>(result_alpha * 255);
|
|
535
|
+
} else {
|
|
536
|
+
// Fully transparent
|
|
537
|
+
result_pixel = cv::Vec4b(0, 0, 0, 0);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
result.at<cv::Vec4b>(y, x) = result_pixel;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
return result;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// Parse color string to cv::Scalar, supporting hex colors
|
|
548
|
+
inline cv::Scalar parseColorString(const std::string& colorStr) {
|
|
549
|
+
if (colorStr.empty()) {
|
|
550
|
+
return cv::Scalar(255, 255, 255); // Default white
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
if (colorStr[0] == '#' && colorStr.length() == 7) {
|
|
554
|
+
// Hex color #RRGGBB
|
|
555
|
+
unsigned long rgb = std::stoul(colorStr.substr(1), nullptr, 16);
|
|
556
|
+
return cv::Scalar((rgb & 0xFF), ((rgb >> 8) & 0xFF), ((rgb >> 16) & 0xFF)); // BGR
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// Default fallback
|
|
560
|
+
return cv::Scalar(255, 255, 255);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
#endif // UTILS_H
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Quick test script to verify multi-format implementation
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const CppProcessor = require('../node-red-contrib-image-tools/lib/cpp-bridge.js');
|
|
8
|
+
|
|
9
|
+
console.log('š§ Testing Multi-Format Image Processing...\n');
|
|
10
|
+
|
|
11
|
+
// Create test image data
|
|
12
|
+
const width = 50;
|
|
13
|
+
const height = 50;
|
|
14
|
+
const channels = 3;
|
|
15
|
+
const imageData = Buffer.alloc(width * height * channels);
|
|
16
|
+
|
|
17
|
+
// Fill with gradient pattern
|
|
18
|
+
for (let y = 0; y < height; y++) {
|
|
19
|
+
for (let x = 0; x < width; x++) {
|
|
20
|
+
const index = (y * width + x) * channels;
|
|
21
|
+
imageData[index] = Math.floor((x / width) * 255); // Red gradient
|
|
22
|
+
imageData[index + 1] = Math.floor((y / height) * 255); // Green gradient
|
|
23
|
+
imageData[index + 2] = 128; // Blue constant
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const testImage = {
|
|
28
|
+
data: imageData,
|
|
29
|
+
width: width,
|
|
30
|
+
height: height,
|
|
31
|
+
channels: channels,
|
|
32
|
+
colorSpace: 'RGB',
|
|
33
|
+
dtype: 'uint8'
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
console.log(`š Test Image: ${width}x${height}, ${channels} channels, ${imageData.length} bytes\n`);
|
|
37
|
+
|
|
38
|
+
// Test formats
|
|
39
|
+
const formats = ['raw', 'jpg', 'png', 'webp'];
|
|
40
|
+
const testPromises = [];
|
|
41
|
+
|
|
42
|
+
formats.forEach(format => {
|
|
43
|
+
const quality = (format === 'jpg' || format === 'webp') ? 85 : 90;
|
|
44
|
+
|
|
45
|
+
console.log(`š Testing ${format.toUpperCase()} format...`);
|
|
46
|
+
|
|
47
|
+
// Test resize with this format
|
|
48
|
+
const promise = CppProcessor.resize(testImage, 'percentage', 75, 'percentage', 75, format, quality)
|
|
49
|
+
.then(result => {
|
|
50
|
+
// Handle different return formats
|
|
51
|
+
let resultSize;
|
|
52
|
+
if (format === 'raw') {
|
|
53
|
+
// Raw format returns an object with data property
|
|
54
|
+
if (result.image && result.image.data) {
|
|
55
|
+
resultSize = result.image.data.length;
|
|
56
|
+
} else {
|
|
57
|
+
throw new Error('Raw format missing image.data');
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
// Encoded formats return buffer directly as image
|
|
61
|
+
if (Buffer.isBuffer(result.image)) {
|
|
62
|
+
resultSize = result.image.length;
|
|
63
|
+
} else {
|
|
64
|
+
throw new Error('Encoded format should return Buffer');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const timing = result.timing || {};
|
|
69
|
+
const totalTime = (timing.convertMs || 0) + (timing.taskMs || 0) + (timing.encodeMs || 0);
|
|
70
|
+
|
|
71
|
+
console.log(`ā
${format.toString().padEnd(4)} format: SUCCESS - Size: ${resultSize}b, Time: ${totalTime.toFixed(1)}ms`);
|
|
72
|
+
return { format, success: true, size: resultSize, timing: totalTime };
|
|
73
|
+
})
|
|
74
|
+
.catch(error => {
|
|
75
|
+
console.log(`ā ${format.toString().padEnd(4)} format: FAILED - ${error.message}`);
|
|
76
|
+
return { format, success: false, error: error.message };
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
testPromises.push(promise);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
Promise.all(testPromises)
|
|
83
|
+
.then(results => {
|
|
84
|
+
console.log('\n=== TEST SUMMARY ===');
|
|
85
|
+
|
|
86
|
+
const successful = results.filter(r => r.success);
|
|
87
|
+
const failed = results.filter(r => !r.success);
|
|
88
|
+
|
|
89
|
+
console.log(`Total Tests: ${results.length}`);
|
|
90
|
+
console.log(`Successful: ${successful.length}`);
|
|
91
|
+
console.log(`Failed: ${failed.length}`);
|
|
92
|
+
console.log(`Success Rate: ${(successful.length / results.length * 100).toFixed(1)}%\n`);
|
|
93
|
+
|
|
94
|
+
if (successful.length > 0) {
|
|
95
|
+
console.log('ā
SUCCESSFUL FORMATS:');
|
|
96
|
+
successful.forEach(result => {
|
|
97
|
+
console.log(` ${result.format}: ${result.size}b, ${result.timing.toFixed(1)}ms`);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (failed.length > 0) {
|
|
102
|
+
console.log('\nā FAILED FORMATS:');
|
|
103
|
+
failed.forEach(result => {
|
|
104
|
+
console.log(` ${result.format}: ${result.error}`);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (successful.length === formats.length) {
|
|
109
|
+
console.log('\nš All format tests passed! Ready for Node-RED testing.');
|
|
110
|
+
process.exit(0);
|
|
111
|
+
} else {
|
|
112
|
+
console.log('\nā ļø Some format tests failed. Check C++ implementation.');
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
.catch(error => {
|
|
117
|
+
console.error('š„ Test framework error:', error.message);
|
|
118
|
+
process.exit(1);
|
|
119
|
+
});
|