@@ -20,9 +20,16 @@ struct ReadResult
20
20
{
21
21
std::string format{};
22
22
std::string text{};
23
+ std::string bytes{};
23
24
std::string error{};
24
25
Position position{};
25
26
std::string symbologyIdentifier{};
27
+
28
+ // The following seemed like the way to go, because the bytes member on the JS side would then automatically be a Uint8Array
29
+ // but unfortunatelly, I don't understand something about the memory management, because the resulting array could contain 8 bytes of garbage.
30
+ // ByteArray bytes;
31
+ // emscripten::val get_bytes() const { return emscripten::val(emscripten::typed_memory_view(bytes.size(), bytes.data())); }
32
+ // void set_bytes(emscripten::val) {} // dummy setter
26
33
};
27
34
28
35
std::vector<ReadResult> readBarcodes (ImageView iv, bool tryHarder, const std::string& format, int maxSymbols)
@@ -42,15 +49,16 @@ std::vector<ReadResult> readBarcodes(ImageView iv, bool tryHarder, const std::st
42
49
std::vector<ReadResult> readResults{};
43
50
readResults.reserve (results.size ());
44
51
45
- for (auto & result : results) {
46
- readResults.push_back ({ToString (result.format ()), result.text (), ToString (result.error ()), result.position (), result.symbologyIdentifier ()});
52
+ for (auto && result : results) {
53
+ readResults.push_back ({ToString (result.format ()), result.text (), std::string (result.bytes ().asString ()),
54
+ ToString (result.error ()), result.position (), result.symbologyIdentifier ()});
47
55
}
48
56
49
57
return readResults;
50
58
} catch (const std::exception& e) {
51
- return {{" " , " " , e.what ()}};
59
+ return {{" " , " " , {}, e.what ()}};
52
60
} catch (...) {
53
- return {{" " , " " , " Unknown error" }};
61
+ return {{" " , " " , {}, " Unknown error" }};
54
62
}
55
63
return {};
56
64
}
@@ -62,7 +70,7 @@ std::vector<ReadResult> readBarcodesFromImage(int bufferPtr, int bufferLength, b
62
70
stbi_load_from_memory (reinterpret_cast <const unsigned char *>(bufferPtr), bufferLength, &width, &height, &channels, 1 ),
63
71
stbi_image_free);
64
72
if (buffer == nullptr )
65
- return {{" " , " " , " Error loading image" }};
73
+ return {{" " , " " , {}, " Error loading image" }};
66
74
67
75
return readBarcodes ({buffer.get (), width, height, ImageFormat::Lum}, tryHarder, format, maxSymbols);
68
76
}
@@ -89,6 +97,7 @@ EMSCRIPTEN_BINDINGS(BarcodeReader)
89
97
value_object<ReadResult>(" ReadResult" )
90
98
.field (" format" , &ReadResult::format)
91
99
.field (" text" , &ReadResult::text)
100
+ .field (" bytes" , &ReadResult::bytes)
92
101
.field (" error" , &ReadResult::error)
93
102
.field (" position" , &ReadResult::position)
94
103
.field (" symbologyIdentifier" , &ReadResult::symbologyIdentifier);
0 commit comments