(matrix: BitMatrix)
| 286 | } |
| 287 | |
| 288 | function 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 | |
| 327 | export function decode(matrix: BitMatrix): DecodedQR { |
| 328 | if (matrix == null) { |
no test coverage detected
searching dependent graphs…