| 59 | } |
| 60 | |
| 61 | Results MultiFormatReader::readMultiple(const BinaryBitmap& image, int maxSymbols) const |
| 62 | { |
| 63 | std::vector<Result> res; |
| 64 | |
| 65 | for (const auto& reader : _readers) { |
| 66 | if (image.inverted() && !reader->supportsInversion) |
| 67 | continue; |
| 68 | auto r = reader->decode(image, maxSymbols); |
| 69 | if (!_hints.returnErrors()) { |
| 70 | //TODO: C++20 res.erase_if() |
| 71 | auto it = std::remove_if(res.begin(), res.end(), [](auto&& r) { return !r.isValid(); }); |
| 72 | res.erase(it, res.end()); |
| 73 | } |
| 74 | maxSymbols -= Size(r); |
| 75 | res.insert(res.end(), std::move_iterator(r.begin()), std::move_iterator(r.end())); |
| 76 | if (maxSymbols <= 0) |
| 77 | break; |
| 78 | } |
| 79 | |
| 80 | // sort results based on their position on the image |
| 81 | std::sort(res.begin(), res.end(), [](const Result& l, const Result& r) { |
| 82 | auto lp = l.position().topLeft(); |
| 83 | auto rp = r.position().topLeft(); |
| 84 | return lp.y < rp.y || (lp.y == rp.y && lp.x < rp.x); |
| 85 | }); |
| 86 | |
| 87 | return res; |
| 88 | } |
| 89 | |
| 90 | } // ZXing |