57 class OCEAN_CV_DETECTOR_QRCODES_EXPORT
Segment
78 inline unsigned int characters()
const;
84 inline const BitBuffer& bitBuffer()
const;
116 static inline void bitBufferAppend(
const unsigned int value,
size_t bits,
BitBuffer& bitBuffer);
123 static inline bool isNumericData(
const std::string& data);
131 static inline bool isAlphanumericData(
const std::string& data);
140 static inline const std::string& getAlphanumericCharset();
186 static uint8_t
multiply(
const uint8_t a,
const uint8_t b);
200 template <u
int32_t tBlockLength, u
int32_t tDataLength, u
int32_t tGeneratorPolynomial>
201 static inline uint32_t computePolynomialDivisonRemainderBCH(
const uint32_t data);
208 static inline uint32_t computeHammingWeight(uint32_t value);
212 encodationMode_(mode),
213 characters_(characters),
214 bitBuffer_(bitBuffer)
221 return encodationMode_;
236 for (
size_t i = 0; i < data.size(); ++i)
238 if (std::isdigit((
unsigned char)data[i]) ==
false)
244 return data.size() != 0;
254 const std::string& alphanumericCharset = getAlphanumericCharset();
256 for (
const char character : data)
258 if (alphanumericCharset.find(character) == std::string::npos)
269 const static std::string alphanumericCharset =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
270 ocean_assert(alphanumericCharset.size() == 45);
272 return alphanumericCharset;
277 ocean_assert(bits <=
sizeof(
unsigned int) * 8);
284 for (
size_t i = bits - 1; i < bits; --i)
286 bitBuffer.push_back((value >> i) & 1);
290 template <u
int32_t tBlockLength, u
int32_t tDataLength, u
int32_t tGeneratorPolynomial>
293 static_assert(tBlockLength != 0u && tDataLength != 0u && tBlockLength > tDataLength,
"The block length must be larger than the number of data bits and both must be nonzero.");
294 static_assert(tGeneratorPolynomial != 0u && tGeneratorPolynomial >> tBlockLength == 0u,
"The generator polynomial cannot be zero and must fit into the block length");
295 ocean_assert(data >> tBlockLength == 0u);
322 constexpr uint32_t errorCorrectionBits = tBlockLength - tDataLength;
324 uint32_t remainder = data;
326 for (uint32_t i = 0u; i < tDataLength; ++i)
328 ocean_assert(tDataLength >= i + 1u);
329 const uint32_t shift = tDataLength - i - 1u;
331 if (remainder & (1u << (shift + errorCorrectionBits)))
333 remainder ^= tGeneratorPolynomial << shift;
337 ocean_assert(tGeneratorPolynomial > remainder);
343 uint32_t weight = 0u;
347 value = value & (value - 1u);
EncodingMode
Definition of encoding modes.
Definition: QRCodeBase.h:72
Definition of the ReedSolomon class.
Definition: QRCodeEncoderBase.h:158
std::vector< uint8_t > Coefficients
Coefficients of the divisor polynomial, stored from highest to lower power (excluding the leading ter...
Definition: QRCodeEncoderBase.h:162
static Coefficients generateCoefficients(const unsigned int degree)
Generates the Reed-Solomon coefficients for a divisor polynomial of degree N.
static Codewords computeRemainders(const Codewords &codewords, const Coefficients &coefficients)
Computes the Reed-Solomon error correction codewords for a sequence of data codewords.
static uint8_t multiply(const uint8_t a, const uint8_t b)
Return the product of two fields modulo GF(2^8/0x11D)
Definition of the segment class A sequence is a sequence of data encoded according to the rules of on...
Definition: QRCodeEncoderBase.h:58
static bool isAlphanumericData(const std::string &data)
Test to check if data contains only alphanumeric characters.
Definition: QRCodeEncoderBase.h:247
static bool generateSegmentsBytes(const std::vector< uint8_t > &data, Segments &segments)
Encode a sequence of bytes and store it in a segment.
static bool generateSegmentAlphanumeric(const std::string &data, Segments &segments)
Encode a sequence of alphanumeric characters (cf.
QRCode::EncodingMode encodationMode() const
Returns the encodation mode set for this segment.
Definition: QRCodeEncoderBase.h:219
static bool isNumericData(const std::string &data)
Test to check if data is numeric (consisting of only digits)
Definition: QRCodeEncoderBase.h:234
unsigned int characters_
The number of characters stored in this segment.
Definition: QRCodeEncoderBase.h:148
QRCode::EncodingMode encodationMode_
The mode used to encode the data of this segment.
Definition: QRCodeEncoderBase.h:145
static void bitBufferAppend(const unsigned int value, size_t bits, BitBuffer &bitBuffer)
Helper function to append a certain number of bits of a number to a bit buffer.
Definition: QRCodeEncoderBase.h:275
BitBuffer bitBuffer_
The actual encoded data (sequence of bits)
Definition: QRCodeEncoderBase.h:151
unsigned int characters() const
Returns the number of characters stored in this segment.
Definition: QRCodeEncoderBase.h:224
Segment(const QRCode::EncodingMode mode, const unsigned int characters, BitBuffer &bitBuffer)
Constructor for segments.
Definition: QRCodeEncoderBase.h:211
const BitBuffer & bitBuffer() const
Returns the encoded bits stored in this segment.
Definition: QRCodeEncoderBase.h:229
static bool generateSegmentNumeric(const std::string &data, Segments &segments)
Encode a sequence of digits (0-9) and store it in a segment.
static const std::string & getAlphanumericCharset()
Returns the character set for the alphanumeric data mode The character set for the alphanumeric data ...
Definition: QRCodeEncoderBase.h:267
This class implements basic QRCodeEncoder functionality.
Definition: QRCodeEncoderBase.h:35
static uint32_t computePolynomialDivisonRemainderBCH(const uint32_t data)
Computes the remainder of a polynomial long division for (n, k) BCH codes Notation: n : block length ...
Definition: QRCodeEncoderBase.h:291
std::vector< uint8_t > BitBuffer
Typedef for a bit buffer.
Definition: QRCodeEncoderBase.h:45
static uint32_t computeHammingWeight(uint32_t value)
Determines the number of 1-bits in an integer value (Hamming weight)
Definition: QRCodeEncoderBase.h:341
std::vector< Segment > Segments
Typedef for a vector of segments.
Definition: QRCodeEncoderBase.h:48
uint8_t Codeword
Codeword: sequence of 8 bits.
Definition: QRCodeEncoderBase.h:39
std::vector< Codeword > Codewords
Vector of codewords.
Definition: QRCodeEncoderBase.h:42
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