MCPcopy Create free account
hub / github.com/devilsen/CZXing / Decode

Function Decode

czxing/src/main/cpp/zxing/src/qrcode/QRDecoder.cpp:317–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

315}
316
317DecoderResult Decode(const BitMatrix& bits)
318{
319 const Version* pversion = ReadVersion(bits);
320 if (!pversion)
321 return FormatError("Invalid version");
322 const Version& version = *pversion;
323
324 auto formatInfo = ReadFormatInformation(bits, version.isMicroQRCode());
325 if (!formatInfo.isValid())
326 return FormatError("Invalid format information");
327
328 // Read codewords
329 ByteArray codewords = ReadCodewords(bits, version, formatInfo);
330 if (codewords.empty())
331 return FormatError("Failed to read codewords");
332
333 // Separate into data blocks
334 std::vector<DataBlock> dataBlocks = DataBlock::GetDataBlocks(codewords, version, formatInfo.ecLevel);
335 if (dataBlocks.empty())
336 return FormatError("Failed to get data blocks");
337
338 // Count total number of data bytes
339 const auto op = [](auto totalBytes, const auto& dataBlock){ return totalBytes + dataBlock.numDataCodewords();};
340 const auto totalBytes = std::accumulate(std::begin(dataBlocks), std::end(dataBlocks), int{}, op);
341 ByteArray resultBytes(totalBytes);
342 auto resultIterator = resultBytes.begin();
343
344 // Error-correct and copy data blocks together into a stream of bytes
345 for (auto& dataBlock : dataBlocks)
346 {
347 ByteArray& codewordBytes = dataBlock.codewords();
348 int numDataCodewords = dataBlock.numDataCodewords();
349
350 if (!CorrectErrors(codewordBytes, numDataCodewords))
351 return ChecksumError();
352
353 resultIterator = std::copy_n(codewordBytes.begin(), numDataCodewords, resultIterator);
354 }
355
356 // Decode the contents of that stream of bytes
357 return DecodeBitStream(std::move(resultBytes), version, formatInfo.ecLevel).setIsMirrored(formatInfo.isMirrored);
358}
359
360} // namespace ZXing::QRCode

Callers 1

decodeMethod · 0.70

Calls 11

ReadFormatInformationFunction · 0.85
ReadCodewordsFunction · 0.85
GetDataBlocksFunction · 0.85
moveFunction · 0.85
isMicroQRCodeMethod · 0.80
numDataCodewordsMethod · 0.80
ReadVersionFunction · 0.70
CorrectErrorsFunction · 0.70
isValidMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected