| 75 | } |
| 76 | |
| 77 | Version *BitMatrixParser::readVersion() { |
| 78 | if (parsedVersion_ != 0) { |
| 79 | return parsedVersion_; |
| 80 | } |
| 81 | |
| 82 | int dimension = bitMatrix_->getHeight(); |
| 83 | |
| 84 | int provisionalVersion = (dimension - 17) >> 2; |
| 85 | if (provisionalVersion <= 6) { |
| 86 | return Version::getVersionForNumber(provisionalVersion); |
| 87 | } |
| 88 | |
| 89 | // Read top-right version info: 3 wide by 6 tall |
| 90 | int versionBits = 0; |
| 91 | for (int y = 5; y >= 0; y--) { |
| 92 | int xMin = dimension - 11; |
| 93 | for (int x = dimension - 9; x >= xMin; x--) { |
| 94 | versionBits = copyBit(x, y, versionBits); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | parsedVersion_ = Version::decodeVersionInformation(versionBits); |
| 99 | if (parsedVersion_ != 0 && parsedVersion_->getDimensionForVersion() == dimension) { |
| 100 | return parsedVersion_; |
| 101 | } |
| 102 | |
| 103 | // Hmm, failed. Try bottom left: 6 wide by 3 tall |
| 104 | versionBits = 0; |
| 105 | for (int x = 5; x >= 0; x--) { |
| 106 | int yMin = dimension - 11; |
| 107 | for (int y = dimension - 9; y >= yMin; y--) { |
| 108 | versionBits = copyBit(x, y, versionBits); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | parsedVersion_ = Version::decodeVersionInformation(versionBits); |
| 113 | if (parsedVersion_ != 0 && parsedVersion_->getDimensionForVersion() == dimension) { |
| 114 | return parsedVersion_; |
| 115 | } |
| 116 | throw ReaderException("Could not decode version"); |
| 117 | } |
| 118 | |
| 119 | ArrayRef<char> BitMatrixParser::readCodewords() { |
| 120 | Ref<FormatInformation> formatInfo = readFormatInformation(); |
no test coverage detected