(matrix: BitMatrix, version: Version, formatInfo: FormatInformation)
| 100 | } |
| 101 | |
| 102 | function readCodewords(matrix: BitMatrix, version: Version, formatInfo: FormatInformation) { |
| 103 | const dataMask = DATA_MASKS[formatInfo.dataMask]; |
| 104 | const dimension = matrix.height; |
| 105 | |
| 106 | const functionPatternMask = buildFunctionPatternMask(version); |
| 107 | |
| 108 | const codewords: number[] = []; |
| 109 | let currentByte = 0; |
| 110 | let bitsRead = 0; |
| 111 | |
| 112 | // Read columns in pairs, from right to left |
| 113 | let readingUp = true; |
| 114 | for (let columnIndex = dimension - 1; columnIndex > 0; columnIndex -= 2) { |
| 115 | if (columnIndex === 6) { // Skip whole column with vertical alignment pattern; |
| 116 | columnIndex--; |
| 117 | } |
| 118 | for (let i = 0; i < dimension; i++) { |
| 119 | const y = readingUp ? dimension - 1 - i : i; |
| 120 | for (let columnOffset = 0; columnOffset < 2; columnOffset++) { |
| 121 | const x = columnIndex - columnOffset; |
| 122 | if (!functionPatternMask.get(x, y)) { |
| 123 | bitsRead++; |
| 124 | let bit = matrix.get(x, y); |
| 125 | if (dataMask({y, x})) { |
| 126 | bit = !bit; |
| 127 | } |
| 128 | currentByte = pushBit(bit, currentByte); |
| 129 | if (bitsRead === 8) { // Whole bytes |
| 130 | codewords.push(currentByte); |
| 131 | bitsRead = 0; |
| 132 | currentByte = 0; |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | readingUp = !readingUp; |
| 138 | } |
| 139 | return codewords; |
| 140 | } |
| 141 | |
| 142 | function readVersion(matrix: BitMatrix): Version { |
| 143 | const dimension = matrix.height; |
no test coverage detected
searching dependent graphs…