47 MP_PATTERN_0 = 0b000u,
50 MP_PATTERN_1 = 0b001u,
53 MP_PATTERN_2 = 0b010u,
56 MP_PATTERN_3 = 0b011u,
59 MP_PATTERN_4 = 0b100u,
62 MP_PATTERN_5 = 0b101u,
65 MP_PATTERN_6 = 0b110u,
68 MP_PATTERN_7 = 0b111u,
71 MP_PATTERN_UNKNOWN = uint32_t(-1)
75 static const int8_t ECC_CODEWORDS_PER_BLOCK[4][41];
78 static const int8_t NUM_ERROR_CORRECTION_BLOCKS[4][41];
123 static inline uint32_t encodeVersion(
const uint32_t version);
132 static inline bool decodeVersionBits(
const uint32_t versionBits, uint32_t& version);
147 static inline uint32_t encodeFormatBits(
const uint32_t format);
183 static inline unsigned int totalNumberRawDataModules(
const unsigned int version);
200 static inline bool computeTotalBitsUsed(
const Segments& segments,
const unsigned int version,
unsigned int& bitsUsed);
220 static void applyMaskPattern(std::vector<uint8_t>& modules,
const unsigned int version,
const std::vector<uint8_t>& functionPatternMask,
const MaskingPattern mask);
257 static void setCodewords(std::vector<uint8_t>& modules,
const Codewords& codewords,
const unsigned int version,
const std::vector<uint8_t>& functionPatternMask);
278 static void setVersionInformation(std::vector<uint8_t>& modules,
const unsigned int version, std::vector<uint8_t>& functionPatternMask);
293 static inline unsigned int getBitsInCharacterCountIndicator(
const unsigned int version,
const QRCode::EncodingMode mode);
299 ocean_assert((
unsigned int)mode < 7u);
301 const unsigned int encodationModeBitSequences[7] =
314 ocean_assert(encodationModeBitSequences[(
unsigned int)mode] >> 4u == 0u);
315 return encodationModeBitSequences[(
unsigned int)mode];
322 ocean_assert((
unsigned int)mode < 5u);
324 const unsigned int characterCountIndicators[15] =
338 const unsigned int column = (version + 7u) / 17u;
339 ocean_assert(column < 3u);
341 return characterCountIndicators[(
unsigned int)mode * 3u + column];
346 ocean_assert(errorCorrectionCapacity >> 2u == 0u && maskingPattern >> 3u == 0u);
352 ocean_assert(formatBits >> 15u == 0u);
354 uint32_t minDistanceFormat = uint32_t(-1);
355 uint32_t minDistance = uint32_t(-1);
356 uint32_t minDistanceCounter = 0u;
358 for (uint32_t referenceFormat = 0u; referenceFormat < 32u; ++referenceFormat)
363 if (distance < minDistance)
365 minDistance = distance;
366 minDistanceFormat = referenceFormat;
367 minDistanceCounter = 1u;
369 else if (distance == minDistance)
371 minDistanceCounter++;
377 if (minDistanceCounter != 1u || minDistance >= 4u)
382 ocean_assert(minDistance != uint32_t(-1) && minDistanceFormat != uint32_t(-1));
383 ocean_assert(minDistanceFormat >> 5u == 0u);
385 switch (minDistanceFormat >> 3u)
404 ocean_assert(
false &&
"Never be here!");
417 ocean_assert(version >> 6u == 0u);
424 const uint32_t remainder = computePolynomialDivisonRemainderBCH<18u, 6u, 0b1111100100101u>(version << 12u);
425 const uint32_t versionBits = (version << 12u) ^ remainder;
426 ocean_assert(versionBits >> 18u == 0u);
433 ocean_assert(versionBits >> 18u == 0u);
435 uint32_t minDistanceVersion = uint32_t(-1);
436 uint32_t minDistance = uint32_t(-1);
437 uint32_t minDistanceCounter = 0u;
442 const uint32_t referenceVersionBits =
encodeVersion(referenceVersion);
445 if (distance < minDistance)
447 minDistance = distance;
448 minDistanceVersion = referenceVersion;
449 minDistanceCounter = 1u;
451 else if (distance == minDistance)
453 minDistanceCounter++;
459 if (minDistanceCounter != 1u || minDistance >= 5u)
464 ocean_assert(minDistance != uint32_t(-1) && minDistanceVersion != uint32_t(-1));
465 ocean_assert(minDistanceVersion >> 6u == 0u);
467 version = minDistanceVersion;
474 ocean_assert(format >> 5u == 0u);
481 const uint32_t remainder = computePolynomialDivisonRemainderBCH<15u, 5u, 0b10100110111u>(format << 10u);
484 const uint32_t formatBitsUnmasked = (format << 10u) ^ remainder;
485 const uint32_t formatBitsMasked = formatBitsUnmasked ^ 0b101010000010010u;
486 ocean_assert(formatBitsMasked >> 15u == 0u);
488 return formatBitsMasked;
502 unsigned int rawDataModules = (16u * version + 128u) * version + 64u;
507 const unsigned int alignmentPatterns = (version / 7u) + 2u;
509 ocean_assert(rawDataModules >= (25u * alignmentPatterns - 10u) * alignmentPatterns - 55u);
510 rawDataModules -= (25u * alignmentPatterns - 10u) * alignmentPatterns - 55u;
514 ocean_assert(rawDataModules >= 36u);
515 rawDataModules -= 36u;
520 return rawDataModules;
526 ocean_assert(uint32_t(errorCorrectionCapacity) < 4u);
537 for (
const Segment& segment : segments)
540 constexpr
unsigned int modeIndicatorBits = 4u;
544 if (segment.characters() >= (1u << characterCountBits)
551 bitsUsed += modeIndicatorBits + characterCountBits;
552 bitsUsed += (
unsigned int)segment.bitBuffer().size();
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_ECI
Mode that allows the output data stream to have interpretations different from that of the default ch...
Definition: QRCodeBase.h:85
@ 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
@ EM_STRUCTURED_APPEND
Structured Append mode is used to split the encodation of the data from a message over a number of QR...
Definition: QRCodeBase.h:87
@ EM_FNC1
Mode that is used for messages containing data formatted either in accordance with the UCC/EAN Applic...
Definition: QRCodeBase.h:89
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_07
Indicates that 7% of the modules reserved error correction.
Definition: QRCodeBase.h:55
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 implements an encoder and decoder for QR codes.
Definition: QRCodeEncoder.h:37
static bool decodeVersionBits(const uint32_t versionBits, uint32_t &version)
Decodes a sequence of 18 bits and extracts the encoded version number Note: the version bit sequence ...
Definition: QRCodeEncoder.h:431
static StatusCode encodeSegments(const Segments &segments, const QRCode::ErrorCorrectionCapacity errorCorrectionCapacity, std::vector< uint8_t > &modules, unsigned int &version, QRCode::ErrorCorrectionCapacity &finalErrorCorrectionCapacity, const unsigned int minVersion=1u, const unsigned int maxVersion=QRCode::MAX_VERSION, const MaskingPattern mask=MP_PATTERN_UNKNOWN, const bool maximizeErrorCorrectionCapacity=true)
Encodes segments and writes them into a QR code.
static const int8_t ECC_CODEWORDS_PER_BLOCK[4][41]
Number of error correction codewords (rows: 0 - low, 1 - medium, 2 - quartile, 3 - high,...
Definition: QRCodeEncoder.h:75
static StatusCode addErrorCorrectionAndCreateQRCode(const unsigned int version, const QRCode::ErrorCorrectionCapacity errorCorrectionCapacity, const Codewords &rawCodewords, MaskingPattern mask, std::vector< uint8_t > &modules)
Helper function to initialize a QR code instance.
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 uint32_t encodeFormatBits(const uint32_t format)
Encodes the format information as a sequence of 15 bits with error correction ((15,...
Definition: QRCodeEncoder.h:472
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 StatusCode encodeText(const std::string &text, const QRCode::ErrorCorrectionCapacity errorCorrectionCapacity, QRCode &qrcode)
Encode text and store it in a QR code, will automatically choose the most efficient encodation mode.
static StatusCode encodeBinary(const std::vector< uint8_t > &data, QRCode::ErrorCorrectionCapacity errorCorrectionCapacity, QRCode &qrcode)
Encode binary data and store it in a QR code, will always use the byte encodation mode.
static unsigned int encodationModeIndicatorBitSequence(const QRCode::EncodingMode mode)
Returns the bit sequence identifying the encodation mode set (up to 4 bits long, cf.
Definition: QRCodeEncoder.h:296
static unsigned int totalNumberDataCodewords(const unsigned int version, const QRCode::ErrorCorrectionCapacity errorCorrectionCapacity)
Return the number of codewords for a specified version and error correction level.
Definition: QRCodeEncoder.h:523
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: QRCodeEncoder.h:531
static bool decodeFormatBits(const uint32_t formatBits, QRCode::ErrorCorrectionCapacity &errorCorrectionCapacity, MaskingPattern &maskingPattern)
Decodes a sequence of 15 bits and extracts the encoded error correction level and index of the maskin...
Definition: QRCodeEncoder.h:350
static unsigned int getBitsInCharacterCountIndicator(const unsigned int version, const QRCode::EncodingMode mode)
Returns the number of bits per character for a specific version and encodation mode,...
Definition: QRCodeEncoder.h:318
static uint32_t encodeFormat(const QRCode::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: QRCodeEncoder.h:344
static VectorsI2 computeAlignmentPatternPositions(const unsigned int version)
Computes the 2D locations of the alignment patterns for a specified version of a QR code.
static void setFormatInformation(std::vector< uint8_t > &modules, const unsigned int version, const QRCode::ErrorCorrectionCapacity errorCorrectionCapacity, const MaskingPattern mask, std::vector< uint8_t > &functionPatternMask)
Sets (draws) the format information (2x5 bits) into the modules of a QR code Note: format information...
static std::vector< uint8_t > setFunctionPatterns(std::vector< uint8_t > &modules, const unsigned int version, const QRCode::ErrorCorrectionCapacity errorCorrectionCapacity)
Sets (draws) the modules (bits) of all function patterns Function patterns include: finder patterns,...
static unsigned int computeMaskPatternPenalty(const std::vector< uint8_t > &modules, const unsigned int version)
Computes a penalty value (fitness value) for a module configuration, cf.
MaskingPattern
Enum for the mask patterns used to shuffle modules of a QR code.
Definition: QRCodeEncoder.h:45
static void setCodewords(std::vector< uint8_t > &modules, const Codewords &codewords, const unsigned int version, 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 totalNumberRawDataModules(const unsigned int version)
Returns the number of modules that can be used to store data for a given QR code version This is the ...
Definition: QRCodeEncoder.h:491
static Codewords addErrorCorrectionAndInterleave(const Codewords &codewords, const unsigned int version, const QRCode::ErrorCorrectionCapacity errorCorrectionCapacity)
Generates the error correction codewords and interleaves the with the raw codewords.
static uint32_t encodeVersion(const uint32_t version)
Encodes the version numbers as a sequences of 18 bits with error correction ((18, 6) BCH code).
Definition: QRCodeEncoder.h:414
static const int8_t NUM_ERROR_CORRECTION_BLOCKS[4][41]
Number of error correction blocks (rows: 0 - low, 1 - medium, 2 - quartile, 3 - high,...
Definition: QRCodeEncoder.h:78
Definition of a QR code.
Definition: QRCode.h:35
static constexpr unsigned int MIN_VERSION
Indicates the smallest valid version number of QR codes.
Definition: QRCode.h:42
static constexpr unsigned int MAX_VERSION
Indicates the largest valid version number of QR codes.
Definition: QRCode.h:45
unsigned int modulesPerSide() const override
Returns the number of modules per side of the QR code.
Definition: QRCode.h:129
This class provides basic numeric functionalities.
Definition: Numeric.h:57
std::vector< VectorI2 > VectorsI2
Definition of a vector holding VectorI2 objects.
Definition: Vector2.h:85
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