59 MP_PATTERN_UNKNOWN = uint32_t(-1)
62 static constexpr uint32_t INVALID_VALUE = uint32_t(-1);
110 static inline uint32_t encodeFormatBits(
const uint32_t format);
145 static inline unsigned int totalNumberRawDataModules(
const unsigned int version);
178 static inline bool computeTotalBitsUsed(
const Segments& segments,
const unsigned int version,
unsigned int& bitsUsed);
198 static void applyMaskPattern(std::vector<uint8_t>& modules,
const unsigned int version,
const std::vector<uint8_t>& functionPatternMask,
const MaskingPattern mask);
257 static void setVersionInformation(std::vector<uint8_t>& modules,
const unsigned int version, std::vector<uint8_t>& functionPatternMask);
271 static inline unsigned int getBitsInCharacterCountIndicator(
const unsigned int version,
const MicroQRCode::EncodingMode mode);
277 ocean_assert((
unsigned int)mode < 4u);
279 constexpr
unsigned int encodationModeBitSequences[4] =
287 ocean_assert(encodationModeBitSequences[(
unsigned int)mode] >> 3u == 0u);
288 return encodationModeBitSequences[(
unsigned int)mode];
295 ocean_assert((
unsigned int)mode < 4u);
297 constexpr
unsigned int characterCountIndicators[16] =
311 const unsigned int column = version - 1u;
312 ocean_assert(column < 4u);
314 return characterCountIndicators[(
unsigned int)mode * 4u + column];
321 ocean_assert(maskingPattern >> 2u == 0u);
328 ocean_assert(formatBits >> 15u == 0u);
330 uint32_t minDistanceFormat = uint32_t(-1);
331 uint32_t minDistance = uint32_t(-1);
332 uint32_t minDistanceCounter = 0u;
334 for (uint32_t referenceFormat = 0u; referenceFormat < 32u; ++referenceFormat)
339 if (distance < minDistance)
341 minDistance = distance;
342 minDistanceFormat = referenceFormat;
343 minDistanceCounter = 1u;
345 else if (distance == minDistance)
347 minDistanceCounter++;
353 if (minDistanceCounter != 1u || minDistance >= 4u)
358 ocean_assert(minDistance != uint32_t(-1) && minDistanceFormat != uint32_t(-1));
359 ocean_assert(minDistanceFormat >> 5u == 0u);
361 switch (minDistanceFormat >> 2u)
404 ocean_assert(
false &&
"Never be here!");
416 ocean_assert(format >> 5u == 0u);
423 const uint32_t remainder = computePolynomialDivisonRemainderBCH<15u, 5u, 0b10100110111u>(format << 10u);
426 const uint32_t formatBitsUnmasked = (format << 10u) ^ remainder;
427 const uint32_t formatBitsMasked = formatBitsUnmasked ^ 0b100010001000101u;
428 ocean_assert(formatBitsMasked >> 15u == 0u);
430 return formatBitsMasked;
438 static constexpr
unsigned int rawDataModuleTable[4] = {36u, 80, 132u, 192u};
440 const unsigned int rawDataModules = rawDataModuleTable[version - 1];
443 return rawDataModules;
449 static constexpr int8_t ECC_CODEWORDS[8] = {2, 5, 6, 6, 8, 8, 10, 14};
451 return ECC_CODEWORDS[
getSymbolNumber(version, errorCorrectionCapacity)];
465 for (
const Segment& segment : segments)
468 const unsigned int modeIndicatorBits = version - 1u;
472 if (segment.characters() >= (1u << characterCountBits)
479 bitsUsed += modeIndicatorBits + characterCountBits;
480 bitsUsed += (
unsigned int)segment.bitBuffer().size();
490 switch(errorCorrectionCapacity)
493 ocean_assert(version == 1u);
503 return 2u * version - 3u;
510 return 2u * version - 2u;
524 ocean_assert(
false &&
"Never be here!");
This class implements an encoder and decoder for QR codes.
Definition: MicroQRCodeEncoder.h:37
static void applyMaskPattern(std::vector< uint8_t > &modules, const unsigned int version, const std::vector< uint8_t > &functionPatternMask, const MaskingPattern mask)
Applies a data shuffle mask to the specified modules Note: Calling this function on the same data and...
static void setFormatInformation(std::vector< uint8_t > &modules, const unsigned int version, const MicroQRCode::ErrorCorrectionCapacity errorCorrectionCapacity, const MaskingPattern mask, std::vector< uint8_t > &functionPatternMask)
Sets (draws) the format information (15 bits) into the modules of a Micro QR code Note: format inform...
static bool computeTotalBitsUsed(const Segments &segments, const unsigned int version, unsigned int &bitsUsed)
Computes the number of bits used given some data (segments) for a specified version of a QR code (thi...
Definition: MicroQRCodeEncoder.h:459
static unsigned int totalNumberErrorCorrectionCodewords(const unsigned int version, const MicroQRCode::ErrorCorrectionCapacity errorCorrectionCapacity)
Return the number of codeword bits for a specified version and error correction level.
Definition: MicroQRCodeEncoder.h:446
static QRCodeEncoderBase::StatusCode encodeText(const std::string &text, const MicroQRCode::ErrorCorrectionCapacity errorCorrectionCapacity, MicroQRCode &qrcode)
Encode text and store it in a QR code, will automatically choose the most efficient encodation mode.
static void setVersionInformation(std::vector< uint8_t > &modules, const unsigned int version, std::vector< uint8_t > &functionPatternMask)
Sets (draws) the version information (2x15 bits) into the modules of a QR code.
static void addErrorCorrectionAndCreateQRCode(const unsigned int version, const MicroQRCode::ErrorCorrectionCapacity errorCorrectionCapacity, const Codewords &rawCodewords, MaskingPattern mask, std::vector< uint8_t > &modules)
Helper function to initialize a Micro QR code instance.
static Codewords addErrorCorrection(const Codewords &codewords, const unsigned int version, const MicroQRCode::ErrorCorrectionCapacity errorCorrectionCapacity)
Generates the error correction codewords appends to the raw codewords.
MaskingPattern
Enum for the mask patterns used to shuffle modules of a Micro QR code.
Definition: MicroQRCodeEncoder.h:45
static QRCodeEncoderBase::StatusCode encodeSegments(const Segments &segments, const MicroQRCode::ErrorCorrectionCapacity errorCorrectionCapacity, std::vector< uint8_t > &modules, unsigned int &version, MicroQRCode::ErrorCorrectionCapacity &finalErrorCorrectionCapacity, unsigned int minVersion=1u, unsigned int maxVersion=MicroQRCode::MAX_VERSION, const MaskingPattern mask=MP_PATTERN_UNKNOWN, const bool maximizeErrorCorrectionCapacity=true)
Encodes segments and writes them into a Micro QR code.
static uint32_t encodeFormatBits(const uint32_t format)
Encodes the format information as a sequence of 15 bits with error correction ((15,...
Definition: MicroQRCodeEncoder.h:414
static std::vector< uint8_t > setFunctionPatterns(std::vector< uint8_t > &modules, const unsigned int version, const MicroQRCode::ErrorCorrectionCapacity errorCorrectionCapacity)
Sets (draws) the modules (bits) of all function patterns Function patterns include: finder pattern,...
static constexpr uint32_t INVALID_VALUE
Definition: MicroQRCodeEncoder.h:62
static uint32_t encodeFormat(const unsigned int version, const MicroQRCode::ErrorCorrectionCapacity errorCorrectionCapacity, const MaskingPattern maskingPattern)
Encodes the error correction level and the index of the masking pattern as a sequence of 15 bits with...
Definition: MicroQRCodeEncoder.h:317
static QRCodeEncoderBase::StatusCode encodeBinary(const std::vector< uint8_t > &data, const MicroQRCode::ErrorCorrectionCapacity errorCorrectionCapacity, MicroQRCode &qrcode)
Encode binary data and store it in a QR code, will always use the byte encodation mode.
static bool decodeFormatBits(const uint32_t formatBits, unsigned int &version, MicroQRCode::ErrorCorrectionCapacity &errorCorrectionCapacity, MaskingPattern &maskingPattern)
Decodes a sequence of 15 bits and extracts the encoded error correction level and index of the maskin...
Definition: MicroQRCodeEncoder.h:326
static void setCodewords(std::vector< uint8_t > &modules, const Codewords &codewords, const unsigned int version, const MicroQRCode::ErrorCorrectionCapacity errorCorrectionCapacity, const std::vector< uint8_t > &functionPatternMask)
Sets (draws) the codewords (zig-zag scan) Note: the size of the codewords must match exactly the vers...
static unsigned int computeMaskPatternScore(const std::vector< uint8_t > &modules, const unsigned int version)
Computes a score (fitness value) for a module configuration, cf.
static uint32_t getSymbolNumber(const unsigned int version, const MicroQRCode::ErrorCorrectionCapacity errorCorrectionCapacity)
Gets the symbol number for the version and error correction capacity.
Definition: MicroQRCodeEncoder.h:486
static unsigned int totalNumberDataCodewordBits(const unsigned int version, const MicroQRCode::ErrorCorrectionCapacity errorCorrectionCapacity)
Return the number of codeword bits for a specified version and error correction level.
Definition: MicroQRCodeEncoder.h:454
static unsigned int getBitsInCharacterCountIndicator(const unsigned int version, const MicroQRCode::EncodingMode mode)
Returns the number of bits per character for a specific version and encodation mode,...
Definition: MicroQRCodeEncoder.h:291
static unsigned int totalNumberRawDataModules(const unsigned int version)
Returns the number of modules that can be used to store data for a given Micro QR code version This i...
Definition: MicroQRCodeEncoder.h:433
static unsigned int encodationModeIndicatorBitSequence(const MicroQRCode::EncodingMode mode)
Returns the bit sequence identifying the encodation mode set (up to 4 bits long, cf.
Definition: MicroQRCodeEncoder.h:274
Definition of a Micro QR code.
Definition: MicroQRCode.h:35
static constexpr unsigned int MIN_VERSION
Indicates the smallest valid version number of Micro QR codes.
Definition: MicroQRCode.h:42
unsigned int modulesPerSide() const override
Returns the number of modules per side of the Micro QR code.
Definition: MicroQRCode.h:176
static constexpr unsigned int MAX_VERSION
Indicates the largest valid version number of Micro QR codes.
Definition: MicroQRCode.h:45
EncodingMode
Definition of encoding modes.
Definition: QRCodeBase.h:72
@ EM_ALPHANUMERIC
Mode that supports A-Z, 0-9 and a few others, cf. ALPHANUMERIC_CHARSET
Definition: QRCodeBase.h:76
@ EM_NUMERIC
Mode that supports digits 0-9.
Definition: QRCodeBase.h:74
@ EM_BYTE
Mode that represents data as a sequence of bytes.
Definition: QRCodeBase.h:78
@ EM_KANJI
Mode that handles Kanji characters in accordance with the Shift JIS system based on JIS X 0208.
Definition: QRCodeBase.h:83
ErrorCorrectionCapacity
Enumeration of the levels of error correction The value of the enums correspond to the standard-defin...
Definition: QRCodeBase.h:53
@ ECC_15
Indicates that 15% of the modules reserved error correction.
Definition: QRCodeBase.h:57
@ ECC_30
Indicates that 30% of the modules reserved error correction.
Definition: QRCodeBase.h:61
@ ECC_25
Indicates that 25% of the modules reserved error correction.
Definition: QRCodeBase.h:59
@ ECC_INVALID
Indicator for an invalid error correction capacity.
Definition: QRCodeBase.h:65
@ ECC_07
Indicates that 7% of the modules reserved error correction.
Definition: QRCodeBase.h:55
@ ECC_DETECTION_ONLY
Indicates that the capacity is limited to error detection only (used only by Micro QR Code version M1...
Definition: QRCodeBase.h:63
Definition of the segment class A sequence is a sequence of data encoded according to the rules of on...
Definition: QRCodeEncoderBase.h:79
This class implements basic QRCodeEncoder functionality.
Definition: QRCodeEncoderBase.h:35
static uint32_t computeHammingWeight(uint32_t value)
Determines the number of 1-bits in an integer value (Hamming weight)
Definition: QRCodeEncoderBase.h:367
std::vector< Segment > Segments
Typedef for a vector of segments.
Definition: QRCodeEncoderBase.h:48
StatusCode
Enum for the error codes returned by the encoding functions.
Definition: QRCodeEncoderBase.h:57
std::vector< Codeword > Codewords
Vector of codewords.
Definition: QRCodeEncoderBase.h:42
This class provides basic numeric functionalities.
Definition: Numeric.h:57
std::vector< QRCode > QRCodes
Definition of a vector of QR codes.
Definition: QRCode.h:25
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15