MCPcopy Create free account
hub / github.com/cozmo/jsQR / readCodewords

Function readCodewords

src/decoder/decoder.ts:102–140  ·  view source on GitHub ↗
(matrix: BitMatrix, version: Version, formatInfo: FormatInformation)

Source from the content-addressed store, hash-verified

100}
101
102function 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
142function readVersion(matrix: BitMatrix): Version {
143 const dimension = matrix.height;

Callers 1

decodeMatrixFunction · 0.70

Calls 3

buildFunctionPatternMaskFunction · 0.70
pushBitFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…