| 309 | } |
| 310 | |
| 311 | static const Version* ReadVersion(const BitMatrix& image, int dimension, const PerspectiveTransform& mod2Pix) |
| 312 | { |
| 313 | int bits[2] = {}; |
| 314 | |
| 315 | for (bool mirror : {false, true}) { |
| 316 | // Read top-right/bottom-left version info: 3 wide by 6 tall (depending on mirrored) |
| 317 | int versionBits = 0; |
| 318 | for (int y = 5; y >= 0; --y) |
| 319 | for (int x = dimension - 9; x >= dimension - 11; --x) { |
| 320 | auto mod = mirror ? PointI{y, x} : PointI{x, y}; |
| 321 | auto pix = mod2Pix(centered(mod)); |
| 322 | if (!image.isIn(pix)) |
| 323 | versionBits = -1; |
| 324 | else |
| 325 | AppendBit(versionBits, image.get(pix)); |
| 326 | log(pix, 3); |
| 327 | } |
| 328 | bits[static_cast<int>(mirror)] = versionBits; |
| 329 | } |
| 330 | |
| 331 | return Version::DecodeVersionInformation(bits[0], bits[1]); |
| 332 | } |
| 333 | |
| 334 | DetectorResult SampleQR(const BitMatrix& image, const FinderPatternSet& fp) |
| 335 | { |