| 151 | }; |
| 152 | |
| 153 | Result DataBarReader::decodePattern(int rowNumber, PatternView& next, |
| 154 | std::unique_ptr<RowReader::DecodingState>& state) const |
| 155 | { |
| 156 | #if 0 // non-stacked version |
| 157 | next = next.subView(-1, FULL_PAIR_SIZE + 1); // +1 reflects the guard pattern on the right, see IsRightPair()); |
| 158 | // yes: the first view we test is at index 1 (black bar at 0 would be the guard pattern) |
| 159 | while (next.shift(2)) { |
| 160 | if (IsLeftPair(next)) { |
| 161 | if (auto leftPair = ReadPair(next, false); leftPair && next.shift(FULL_PAIR_SIZE) && IsRightPair(next)) { |
| 162 | if (auto rightPair = ReadPair(next, true); rightPair && ChecksumIsValid(leftPair, rightPair)) { |
| 163 | return {ConstructText(leftPair, rightPair), rowNumber, leftPair.xStart, rightPair.xStop, |
| 164 | BarcodeFormat::DataBar}; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | #else |
| 170 | if (!state) |
| 171 | state.reset(new State); |
| 172 | auto* prevState = static_cast<State*>(state.get()); |
| 173 | |
| 174 | next = next.subView(0, FULL_PAIR_SIZE + 1); // +1 reflects the guard pattern on the right, see IsRightPair() |
| 175 | // yes: the first view we test is at index 1 (black bar at 0 would be the guard pattern) |
| 176 | while (next.shift(1)) { |
| 177 | if (IsLeftPair(next)) { |
| 178 | if (auto leftPair = ReadPair(next, false)) { |
| 179 | leftPair.y = rowNumber; |
| 180 | prevState->leftPairs.insert(leftPair); |
| 181 | next.shift(FULL_PAIR_SIZE - 1); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | if (next.shift(1) && IsRightPair(next)) { |
| 186 | if (auto rightPair = ReadPair(next, true)) { |
| 187 | rightPair.y = rowNumber; |
| 188 | prevState->rightPairs.insert(rightPair); |
| 189 | next.shift(FULL_PAIR_SIZE + 2); |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | for (const auto& leftPair : prevState->leftPairs) |
| 195 | for (const auto& rightPair : prevState->rightPairs) |
| 196 | if (ChecksumIsValid(leftPair, rightPair)) { |
| 197 | // Symbology identifier ISO/IEC 24724:2011 Section 9 and GS1 General Specifications 5.1.3 Figure 5.1.3-2 |
| 198 | Result res{DecoderResult(Content(ByteArray(ConstructText(leftPair, rightPair)), {'e', '0'})) |
| 199 | .setLineCount(EstimateLineCount(leftPair, rightPair)), |
| 200 | EstimatePosition(leftPair, rightPair), BarcodeFormat::DataBar}; |
| 201 | |
| 202 | prevState->leftPairs.erase(leftPair); |
| 203 | prevState->rightPairs.erase(rightPair); |
| 204 | return res; |
| 205 | } |
| 206 | #endif |
| 207 | |
| 208 | // guarantee progress (see loop in ODReader.cpp) |
| 209 | next = {}; |
| 210 |
nothing calls this directly
no test coverage detected