| 117 | |
| 118 | template<typename POINT> |
| 119 | CodeWord ReadCodeWord(BitMatrixCursor<POINT>& cur, int expectedCluster = -1) |
| 120 | { |
| 121 | auto readCodeWord = [expectedCluster](auto& cur) -> CodeWord { |
| 122 | auto np = NormalizedPattern<8, 17>(cur.template readPattern<Pattern417>()); |
| 123 | int cluster = (np[0] - np[2] + np[4] - np[6] + 9) % 9; |
| 124 | int code = expectedCluster == -1 || cluster == expectedCluster ? CodewordDecoder::GetCodeword(ToInt(np)) : -1; |
| 125 | |
| 126 | return {cluster, code}; |
| 127 | }; |
| 128 | |
| 129 | auto curBackup = cur; |
| 130 | auto cw = readCodeWord(cur); |
| 131 | if (!cw) { |
| 132 | for (auto offset : {curBackup.left(), curBackup.right()}) { |
| 133 | auto curAlt = curBackup.movedBy(offset); |
| 134 | if (!curAlt.isIn()) // curBackup might be the first or last image row |
| 135 | continue; |
| 136 | if (auto cwAlt = readCodeWord(curAlt)) { |
| 137 | cur = curAlt; |
| 138 | return cwAlt; |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | return cw; |
| 143 | } |
| 144 | |
| 145 | static int Row(CodeWord rowIndicator) |
| 146 | { |
no test coverage detected