Skip to content

Commit

Permalink
Added missing casts in MicroQRCode
Browse files Browse the repository at this point in the history
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
  • Loading branch information
janherling authored and facebook-github-bot committed Oct 7, 2024
1 parent bf9e526 commit d46cdd8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions impl/ocean/cv/detector/qrcodes/MicroQRCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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:

/**
Expand Down
28 changes: 14 additions & 14 deletions impl/ocean/cv/detector/qrcodes/MicroQRCodeDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -935,7 +935,7 @@ static void getCodewords(const std::vector<uint8_t>& 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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1283,7 +1283,7 @@ static bool decodeModules(const std::vector<uint8_t>& 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;
Expand Down
18 changes: 10 additions & 8 deletions impl/ocean/cv/detector/qrcodes/MicroQRCodeDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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

Expand All @@ -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<unsigned int> lastIn, firstOut;
if(xBack < width && yBack < height && TransitionDetector::findNextPixel<true>(yFrame, xBack, yBack, width, height, paddingElements, bresenhamBack, maxStepSize, finderPattern.grayThreshold(), columns, rows, lastIn, firstOut))
if (xBack < width && yBack < height && TransitionDetector::findNextPixel<true>(yFrame, xBack, yBack, width, height, paddingElements, bresenhamBack, maxStepSize, finderPattern.grayThreshold(), columns, rows, lastIn, firstOut))
{
// Found dark pixel in quiet zone
return false;
Expand All @@ -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<true>(yFrame, x, y, width, height, paddingElements, bresenham, maxStepSize, finderPattern.grayThreshold(), columns, rows, lastIn, firstOut))
|| (!start && !TransitionDetector::findNextPixel<false>(yFrame, x, y, width, height, paddingElements, bresenham, maxStepSize, finderPattern.grayThreshold(), columns, rows, lastIn, firstOut)))
{
Expand Down Expand Up @@ -140,7 +142,7 @@ bool MicroQRCodeDetector::computePosesAndProvisionalVersions(const AnyCamera& an
std::vector<unsigned int> candidateVersions;
HomogenousMatrices4 candidatePoses;

if(!finderPattern.cornersKnown())
if (!finderPattern.cornersKnown())
{
return false;
}
Expand Down

0 comments on commit d46cdd8

Please sign in to comment.