From d46cdd841c55f968bb310ff8a25344e9cdedee65 Mon Sep 17 00:00:00 2001 From: Jan Herling Date: Mon, 7 Oct 2024 11:39:42 -0700 Subject: [PATCH] Added missing casts in MicroQRCode Summary: The value of a boolean (true or false) is undefined, thus we need to convert the value to a specific value (I guess 1 and 0 is expected here). Reviewed By: thorntondr Differential Revision: D63985662 fbshipit-source-id: 28793d3d975b69d1882dd939f17b7f064cda7685 --- impl/ocean/cv/detector/qrcodes/MicroQRCode.h | 4 +-- .../detector/qrcodes/MicroQRCodeDecoder.cpp | 28 +++++++++---------- .../detector/qrcodes/MicroQRCodeDetector.cpp | 18 ++++++------ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/impl/ocean/cv/detector/qrcodes/MicroQRCode.h b/impl/ocean/cv/detector/qrcodes/MicroQRCode.h index 7eaf47952..8eadfd1c7 100644 --- a/impl/ocean/cv/detector/qrcodes/MicroQRCode.h +++ b/impl/ocean/cv/detector/qrcodes/MicroQRCode.h @@ -40,7 +40,7 @@ class MicroQRCode final : public QRCodeBase /// Indicates the smallest valid version number of Micro QR codes. static constexpr unsigned int MIN_VERSION = 1u; - + /// Indicates the largest valid version number of Micro QR codes. static constexpr unsigned int MAX_VERSION = 4u; @@ -84,7 +84,7 @@ class MicroQRCode final : public QRCodeBase * @return True if the symbol number is valid and the version and error correction capacity were successfully unpacked, otherwise false */ static inline bool unpackSymbolNumber(const unsigned int symbolNumber, unsigned int& version, ErrorCorrectionCapacity& errorCorrectionCapacity); - + protected: /** diff --git a/impl/ocean/cv/detector/qrcodes/MicroQRCodeDecoder.cpp b/impl/ocean/cv/detector/qrcodes/MicroQRCodeDecoder.cpp index 753041c76..521defe6c 100644 --- a/impl/ocean/cv/detector/qrcodes/MicroQRCodeDecoder.cpp +++ b/impl/ocean/cv/detector/qrcodes/MicroQRCodeDecoder.cpp @@ -822,7 +822,7 @@ static bool decodeFormatBits(const uint16_t formatBits, uint32_t& version, Micro uint16_t format = formatBits ^ 0x4445; quirc_decode_error_t err = correct_format(&format); - if (err) + if (err) { return false; } @@ -935,7 +935,7 @@ static void getCodewords(const std::vector& modules, const unsigned int i += 4u; } - if (modules[index] ^ dataMask(mask, x, y)) + if (modules[index] ^ uint8_t(dataMask(mask, x, y) ? 1u : 0u)) { uint8_t& codeword = codewords[i >> 3]; const unsigned int bit = 7u - (i & 7u); @@ -1003,13 +1003,13 @@ uint32_t MicroQRCodeDecoder::BitStream::consumeBits(const unsigned int numberOfB while (bitsTaken < bitsToRead) { - result = (result << 1u) | consumeBit(); + result = (result << 1u) | uint32_t(consumeBit() ? 1u : 0u); bitsTaken++; } // Pad with zeros if we ran out of bits result <<= (numberOfBits - bitsTaken); - + return result; } @@ -1052,7 +1052,7 @@ static bool decodeNumericSegment(const unsigned int version, MicroQRCodeDecoder: unsigned int characterCount = bitstream.consumeBits(characterCountBits); data.reserve(data.size() + characterCount); - + while (characterCount >= 3u) { if (bitstream.bitsRemaining() < 10u) @@ -1067,13 +1067,13 @@ static bool decodeNumericSegment(const unsigned int version, MicroQRCodeDecoder: return false; } - data.push_back((digits / 100u) + '0'); - data.push_back(((digits / 10u) % 10u) + '0'); - data.push_back((digits % 10u) + '0'); + data.push_back(uint8_t(digits / 100u) + uint8_t('0')); + data.push_back(uint8_t((digits / 10u) % 10u) + uint8_t('0')); + data.push_back(uint8_t(digits % 10u) + uint8_t('0')); characterCount -= 3u; } - + if (characterCount == 2u) { if (bitstream.bitsRemaining() < 7u) @@ -1088,8 +1088,8 @@ static bool decodeNumericSegment(const unsigned int version, MicroQRCodeDecoder: return false; } - data.push_back(digits / 10u + '0'); - data.push_back(digits % 10u + '0'); + data.push_back(uint8_t(digits / 10u) + uint8_t('0')); + data.push_back(uint8_t(digits % 10u) + uint8_t('0')); characterCount -= 2u; } @@ -1108,7 +1108,7 @@ static bool decodeNumericSegment(const unsigned int version, MicroQRCodeDecoder: return false; } - data.push_back(digit + '0'); + data.push_back(uint8_t(digit) + uint8_t('0')); characterCount -= 1u; } @@ -1201,7 +1201,7 @@ static bool decodeByteSegment(const unsigned int version, MicroQRCodeDecoder::Bi for (unsigned int i = 0u; i < characterCount; ++i) { - data.push_back(bitstream.consumeBits(8u)); + data.push_back(uint8_t(bitstream.consumeBits(8u))); } return true; @@ -1283,7 +1283,7 @@ static bool decodeModules(const std::vector& modules, unsigned int& ver ocean_assert(false && "Invalid number of modules"); return false; } - + // Read format information const uint16_t formatBits = readFormatBits(modules, modulesPerSide); MicroQRCodeEncoder::MaskingPattern maskingPattern; diff --git a/impl/ocean/cv/detector/qrcodes/MicroQRCodeDetector.cpp b/impl/ocean/cv/detector/qrcodes/MicroQRCodeDetector.cpp index 1ab24217b..17ca5b524 100644 --- a/impl/ocean/cv/detector/qrcodes/MicroQRCodeDetector.cpp +++ b/impl/ocean/cv/detector/qrcodes/MicroQRCodeDetector.cpp @@ -30,8 +30,8 @@ bool MicroQRCodeDetector::getTimingPatternModules(const uint8_t* const yFrame, c { ocean_assert(yFrame != nullptr && width != 0u && height != 0u); ocean_assert(topLeftCorner < 4u && timingAdjacentFinderCorner < 4u); - - if(!finderPattern.cornersKnown()) + + if (!finderPattern.cornersKnown()) { return false; } @@ -48,7 +48,8 @@ bool MicroQRCodeDetector::getTimingPatternModules(const uint8_t* const yFrame, c const unsigned int maxStepSize = Numeric::round32(moduleSize * Scalar(1.5)); Vector2 direction = edge.normalized(); - unsigned int columns, rows; + unsigned int columns = (unsigned int)(-1); + unsigned int rows = (unsigned int)(-1); // First check in the backward direction for a clear quiet zone @@ -64,7 +65,7 @@ bool MicroQRCodeDetector::getTimingPatternModules(const uint8_t* const yFrame, c Bresenham bresenhamBack(xBack, yBack, Numeric::round32(farPointBack.x()), Numeric::round32(farPointBack.y())); VectorT2 lastIn, firstOut; - if(xBack < width && yBack < height && TransitionDetector::findNextPixel(yFrame, xBack, yBack, width, height, paddingElements, bresenhamBack, maxStepSize, finderPattern.grayThreshold(), columns, rows, lastIn, firstOut)) + if (xBack < width && yBack < height && TransitionDetector::findNextPixel(yFrame, xBack, yBack, width, height, paddingElements, bresenhamBack, maxStepSize, finderPattern.grayThreshold(), columns, rows, lastIn, firstOut)) { // Found dark pixel in quiet zone return false; @@ -89,14 +90,15 @@ bool MicroQRCodeDetector::getTimingPatternModules(const uint8_t* const yFrame, c moduleCentersTmp.reserve(10); moduleCentersTmp.push_back(startPoint); - while(darkModule <= 5) + while (darkModule <= 5) { // Find the start and end of the next dark module bool foundDark = true; - for (bool start : {true, false}) + + for (const bool start : {true, false}) { - if ( x >= width || y >= height + if (x >= width || y >= height || (start && !TransitionDetector::findNextPixel(yFrame, x, y, width, height, paddingElements, bresenham, maxStepSize, finderPattern.grayThreshold(), columns, rows, lastIn, firstOut)) || (!start && !TransitionDetector::findNextPixel(yFrame, x, y, width, height, paddingElements, bresenham, maxStepSize, finderPattern.grayThreshold(), columns, rows, lastIn, firstOut))) { @@ -140,7 +142,7 @@ bool MicroQRCodeDetector::computePosesAndProvisionalVersions(const AnyCamera& an std::vector candidateVersions; HomogenousMatrices4 candidatePoses; - if(!finderPattern.cornersKnown()) + if (!finderPattern.cornersKnown()) { return false; }