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

Function decodeMatrix

src/decoder/decoder.ts:288–325  ·  view source on GitHub ↗
(matrix: BitMatrix)

Source from the content-addressed store, hash-verified

286}
287
288function decodeMatrix(matrix: BitMatrix) {
289 const version = readVersion(matrix);
290 if (!version) {
291 return null;
292 }
293
294 const formatInfo = readFormatInformation(matrix);
295 if (!formatInfo) {
296 return null;
297 }
298
299 const codewords = readCodewords(matrix, version, formatInfo);
300 const dataBlocks = getDataBlocks(codewords, version, formatInfo.errorCorrectionLevel);
301 if (!dataBlocks) {
302 return null;
303 }
304
305 // Count total number of data bytes
306 const totalBytes = dataBlocks.reduce((a, b) => a + b.numDataCodewords, 0);
307 const resultBytes = new Uint8ClampedArray(totalBytes);
308
309 let resultIndex = 0;
310 for (const dataBlock of dataBlocks) {
311 const correctedBytes = rsDecode(dataBlock.codewords, dataBlock.codewords.length - dataBlock.numDataCodewords);
312 if (!correctedBytes) {
313 return null;
314 }
315 for (let i = 0; i < dataBlock.numDataCodewords; i++) {
316 resultBytes[resultIndex++] = correctedBytes[i];
317 }
318 }
319
320 try {
321 return decodeData(resultBytes, version.versionNumber);
322 } catch {
323 return null;
324 }
325}
326
327export function decode(matrix: BitMatrix): DecodedQR {
328 if (matrix == null) {

Callers 1

decodeFunction · 0.70

Calls 4

readVersionFunction · 0.70
readFormatInformationFunction · 0.70
readCodewordsFunction · 0.70
getDataBlocksFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…