8
8
9
9
#include " ReadBarcode.h"
10
10
11
+ #include < cstdlib>
12
+ #include < exception>
13
+ #include < string>
14
+ #include < string_view>
15
+ #include < utility>
16
+
11
17
using namespace ZXing ;
12
18
13
19
static thread_local std::string lastErrorMsg;
@@ -22,12 +28,15 @@ static char* copy(std::string_view sv)
22
28
return ret;
23
29
}
24
30
25
- static Results ReadBarcodesAndSetLastError (const zxing_ImageView* iv, const zxing_ReaderOptions* opts)
31
+ static Results ReadBarcodesAndSetLastError (const zxing_ImageView* iv, const zxing_ReaderOptions* opts, int maxSymbols )
26
32
{
27
33
try {
28
- if (iv)
29
- return ReadBarcodes (*iv, opts ? *opts : ReaderOptions{});
30
- else
34
+ if (iv) {
35
+ auto o = opts ? *opts : ReaderOptions{};
36
+ if (maxSymbols)
37
+ o.setMaxNumberOfSymbols (maxSymbols);
38
+ return ReadBarcodes (*iv, o);
39
+ } else
31
40
lastErrorMsg = " ImageView param is NULL" ;
32
41
} catch (std::exception & e) {
33
42
lastErrorMsg = e.what ();
@@ -233,13 +242,13 @@ bool zxing_Result_isMirrored(const zxing_Result* result)
233
242
234
243
zxing_Result* zxing_ReadBarcode (const zxing_ImageView* iv, const zxing_ReaderOptions* opts)
235
244
{
236
- auto res = ReadBarcodesAndSetLastError (iv, opts);
245
+ auto res = ReadBarcodesAndSetLastError (iv, opts, 1 );
237
246
return !res.empty () ? new Result (std::move (res.front ())) : NULL ;
238
247
}
239
248
240
249
zxing_Results* zxing_ReadBarcodes (const zxing_ImageView* iv, const zxing_ReaderOptions* opts)
241
250
{
242
- auto res = ReadBarcodesAndSetLastError (iv, opts);
251
+ auto res = ReadBarcodesAndSetLastError (iv, opts, 0 );
243
252
return !res.empty () ? new Results (std::move (res)) : NULL ;
244
253
}
245
254
0 commit comments