Line | Branch | Exec | Source |
---|---|---|---|
1 | /* GATE PROJECT LICENSE: | ||
2 | +----------------------------------------------------------------------------+ | ||
3 | | Copyright(c) 2018-2025, Stefan Meislinger | | ||
4 | | All rights reserved. | | ||
5 | | | | ||
6 | | Redistribution and use in source and binary forms, with or without | | ||
7 | | modification, are permitted provided that the following conditions are met:| | ||
8 | | | | ||
9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
10 | | this list of conditions and the following disclaimer. | | ||
11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
12 | | notice, this list of conditions and the following disclaimer in the | | ||
13 | | documentation and/or other materials provided with the distribution. | | ||
14 | | | | ||
15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
26 | +----------------------------------------------------------------------------+ | ||
27 | */ | ||
28 | |||
29 | #include "gate/tech/barcodes.hpp" | ||
30 | #include "gate/wrappers.hpp" | ||
31 | |||
32 | namespace gate | ||
33 | { | ||
34 | namespace tech | ||
35 | { | ||
36 | |||
37 | typedef gate::graph::RasterImage RasterImage; | ||
38 | |||
39 | uint32_t const IBarcodeProcessor::ScanFlag_Default = GATE_TECH_BARCODE_SCANNER_FLAG_DEFAULT; | ||
40 | uint32_t const IBarcodeProcessor::ScanFlag_Quick = GATE_TECH_BARCODE_SCANNER_FLAG_QUICK; | ||
41 | uint32_t const IBarcodeProcessor::ScanFlag_Intensive = GATE_TECH_BARCODE_SCANNER_FLAG_INTENSIVE; | ||
42 | |||
43 | 6 | IBarcodeProcessor::~IBarcodeProcessor() noexcept | |
44 | { | ||
45 | 6 | } | |
46 | |||
47 | |||
48 | 2 | static Optional<String> generic_barcode_scan(gate_tech_barcode_scanner_t scanner, | |
49 | RasterImage const& image, | ||
50 | uint32_t flags, char const* source_func) | ||
51 | { | ||
52 | 2 | Optional<String> ret; | |
53 | 2 | gate_string_t output = GATE_STRING_INIT_EMPTY; | |
54 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | result_t result = scanner(image.c_impl(), flags, &output); |
55 |
1/3✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
2 | switch (result) |
56 | { | ||
57 | 2 | case GATE_RESULT_OK: | |
58 | { | ||
59 | try | ||
60 | { | ||
61 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | ret.create(String::createFrom(output)); |
62 | } | ||
63 | ✗ | catch (...) | |
64 | { | ||
65 | ✗ | gate_string_release(&output); | |
66 | ✗ | throw; | |
67 | } | ||
68 | 2 | break; | |
69 | } | ||
70 | ✗ | case GATE_RESULT_NOMATCH: | |
71 | { | ||
72 | // just return empty optional object | ||
73 | ✗ | break; | |
74 | } | ||
75 | ✗ | default: | |
76 | { | ||
77 | ✗ | raiseException(result, "Failed to scan barcode", source_func); | |
78 | ✗ | break; | |
79 | } | ||
80 | } | ||
81 | 4 | return ret; | |
82 | } | ||
83 | |||
84 | 2 | static RasterImage generic_barcode_print(gate_tech_barcode_printer_t printer, | |
85 | String const& data, | ||
86 | uint32_t flags, char const* source_func) | ||
87 | { | ||
88 | 2 | RasterImage image; | |
89 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
|
2 | result_t result = printer(data.c_impl(), flags, image.c_impl()); |
90 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
91 | 2 | return image; | |
92 | } | ||
93 | |||
94 | |||
95 | |||
96 | |||
97 | 1 | DtmxBarcodeProcessor::DtmxBarcodeProcessor() | |
98 | //: impl(NULL) | ||
99 | { | ||
100 | 1 | } | |
101 | |||
102 | 2 | DtmxBarcodeProcessor::~DtmxBarcodeProcessor() noexcept | |
103 | { | ||
104 | 2 | } | |
105 | |||
106 | 1 | Optional<String> DtmxBarcodeProcessor::scan(RasterImage const& image, uint32_t flags) | |
107 | { | ||
108 | 1 | return generic_barcode_scan(&gate_tech_dmtx_scan, image, flags, "DtmxBarcodeProcessor::scan"); | |
109 | } | ||
110 | 1 | RasterImage DtmxBarcodeProcessor::print(String const& data) | |
111 | { | ||
112 | 1 | return generic_barcode_print(&gate_tech_dmtx_print, data, 0, "DtmxBarcodeProcessor::print"); | |
113 | } | ||
114 | |||
115 | |||
116 | |||
117 | |||
118 | 1 | QRCodeBarcodeProcessor::QRCodeBarcodeProcessor() | |
119 | //: impl(NULL) | ||
120 | { | ||
121 | 1 | } | |
122 | 2 | QRCodeBarcodeProcessor::~QRCodeBarcodeProcessor() noexcept | |
123 | { | ||
124 | 2 | } | |
125 | |||
126 | ✗ | Optional<String> QRCodeBarcodeProcessor::scan(RasterImage const& image, uint32_t flags) | |
127 | { | ||
128 | ✗ | return generic_barcode_scan(&gate_tech_qrcode_scan, image, flags, "QRCodeBarcodeProcessor::scan"); | |
129 | } | ||
130 | ✗ | RasterImage QRCodeBarcodeProcessor::print(String const& data) | |
131 | { | ||
132 | ✗ | return generic_barcode_print(&gate_tech_qrcode_print, data, 0, "QRCodeBarcodeProcessor::print"); | |
133 | } | ||
134 | |||
135 | |||
136 | |||
137 | |||
138 | 1 | EanBarcodeProcessor::EanBarcodeProcessor() | |
139 | //: impl(NULL) | ||
140 | { | ||
141 | 1 | } | |
142 | 2 | EanBarcodeProcessor::~EanBarcodeProcessor() noexcept | |
143 | { | ||
144 | 2 | } | |
145 | |||
146 | 1 | Optional<String> EanBarcodeProcessor::scan(RasterImage const& image, uint32_t flags) | |
147 | { | ||
148 | 1 | return generic_barcode_scan(&gate_tech_eanbarcode_scan, image, flags, "EanBarcodeProcessor::scan"); | |
149 | } | ||
150 | 1 | RasterImage EanBarcodeProcessor::print(String const& data) | |
151 | { | ||
152 | 1 | return generic_barcode_print(&gate_tech_eanbarcode_print, data, 0, "EanBarcodeProcessor::print"); | |
153 | } | ||
154 | |||
155 | } // end of namespace tech | ||
156 | } // end of namespace gate | ||
157 |