78 class OCEAN_CV_DETECTOR_QRCODES_EXPORT
Segment
99 inline unsigned int characters()
const;
105 inline const BitBuffer& bitBuffer()
const;
137 static inline void bitBufferAppend(
const unsigned int value,
size_t bits,
BitBuffer& bitBuffer);
144 static inline bool isNumericData(
const std::string& data);
152 static inline bool isAlphanumericData(
const std::string& data);
161 static inline const std::string& getAlphanumericCharset();
207 static uint8_t
multiply(
const uint8_t a,
const uint8_t b);
221 template <u
int32_t tBlockLength, u
int32_t tDataLength, u
int32_t tGeneratorPolynomial>
222 static inline uint32_t computePolynomialDivisonRemainderBCH(
const uint32_t data);
229 static inline uint32_t computeHammingWeight(uint32_t value);
234 static inline std::string translateStatusCode(
const StatusCode statusCode);
238 encodationMode_(mode),
239 characters_(characters),
240 bitBuffer_(bitBuffer)
247 return encodationMode_;
262 for (
size_t i = 0; i < data.size(); ++i)
264 if (std::isdigit((
unsigned char)data[i]) ==
false)
270 return data.size() != 0;
280 const std::string& alphanumericCharset = getAlphanumericCharset();
282 for (
const char character : data)
284 if (alphanumericCharset.find(character) == std::string::npos)
295 const static std::string alphanumericCharset =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
296 ocean_assert(alphanumericCharset.size() == 45);
298 return alphanumericCharset;
303 ocean_assert(bits <=
sizeof(
unsigned int) * 8);
310 for (
size_t i = bits - 1; i < bits; --i)
312 bitBuffer.push_back((value >> i) & 1);
316 template <u
int32_t tBlockLength, u
int32_t tDataLength, u
int32_t tGeneratorPolynomial>
319 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.");
320 static_assert(tGeneratorPolynomial != 0u && tGeneratorPolynomial >> tBlockLength == 0u,
"The generator polynomial cannot be zero and must fit into the block length");
321 ocean_assert(data >> tBlockLength == 0u);
348 constexpr uint32_t errorCorrectionBits = tBlockLength - tDataLength;
350 uint32_t remainder = data;
352 for (uint32_t i = 0u; i < tDataLength; ++i)
354 ocean_assert(tDataLength >= i + 1u);
355 const uint32_t shift = tDataLength - i - 1u;
357 if (remainder & (1u << (shift + errorCorrectionBits)))
359 remainder ^= tGeneratorPolynomial << shift;
363 ocean_assert(tGeneratorPolynomial > remainder);
369 uint32_t weight = 0u;
373 value = value & (value - 1u);
387 return "CODE_CAPACITY_EXCEEDED";
389 return "INVALID_DATA";
391 return "INVALID_ERROR_CORRECTION_CAPACITY";
393 return "UNKNOWN_ERROR";
396 ocean_assert(
false &&
"Never be here!");
EncodingMode
Definition of encoding modes.
Definition: QRCodeBase.h:72
Definition of the ReedSolomon class.
Definition: QRCodeEncoderBase.h:179
std::vector< uint8_t > Coefficients
Coefficients of the divisor polynomial, stored from highest to lower power (excluding the leading ter...
Definition: QRCodeEncoderBase.h:183
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:79
static bool isAlphanumericData(const std::string &data)
Test to check if data contains only alphanumeric characters.
Definition: QRCodeEncoderBase.h:273
static StatusCode generateSegmentNumeric(const std::string &data, Segments &segments)
Encode a sequence of digits (0-9) and store it in a segment.
static StatusCode generateSegmentsBytes(const std::vector< uint8_t > &data, Segments &segments)
Encode a sequence of bytes and store it in a segment.
QRCode::EncodingMode encodationMode() const
Returns the encodation mode set for this segment.
Definition: QRCodeEncoderBase.h:245
static bool isNumericData(const std::string &data)
Test to check if data is numeric (consisting of only digits)
Definition: QRCodeEncoderBase.h:260
unsigned int characters_
The number of characters stored in this segment.
Definition: QRCodeEncoderBase.h:169
QRCode::EncodingMode encodationMode_
The mode used to encode the data of this segment.
Definition: QRCodeEncoderBase.h:166
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:301
BitBuffer bitBuffer_
The actual encoded data (sequence of bits)
Definition: QRCodeEncoderBase.h:172
unsigned int characters() const
Returns the number of characters stored in this segment.
Definition: QRCodeEncoderBase.h:250
Segment(const QRCode::EncodingMode mode, const unsigned int characters, BitBuffer &bitBuffer)
Constructor for segments.
Definition: QRCodeEncoderBase.h:237
const BitBuffer & bitBuffer() const
Returns the encoded bits stored in this segment.
Definition: QRCodeEncoderBase.h:255
static const std::string & getAlphanumericCharset()
Returns the character set for the alphanumeric data mode The character set for the alphanumeric data ...
Definition: QRCodeEncoderBase.h:293
static StatusCode generateSegmentAlphanumeric(const std::string &data, Segments &segments)
Encode a sequence of alphanumeric characters (cf.
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:317
std::vector< uint8_t > BitBuffer
Typedef for a bit buffer.
Definition: QRCodeEncoderBase.h:45
static std::string translateStatusCode(const StatusCode statusCode)
Translates the given status code into a human readable string.
Definition: QRCodeEncoderBase.h:380
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
uint8_t Codeword
Codeword: sequence of 8 bits.
Definition: QRCodeEncoderBase.h:39
StatusCode
Enum for the error codes returned by the encoding functions.
Definition: QRCodeEncoderBase.h:57
@ SC_INVALID_ERROR_CORRECTION_CAPACITY
Definition: QRCodeEncoderBase.h:68
@ SC_CODE_CAPACITY_EXCEEDED
The data given exceeds the maximum capacity of the QR code.
Definition: QRCodeEncoderBase.h:62
@ SC_UNKNOWN_ERROR
The encoding failed due to an unknown reason.
Definition: QRCodeEncoderBase.h:71
@ SC_INVALID_DATA
The data given is not valid.
Definition: QRCodeEncoderBase.h:65
@ SC_SUCCESS
The encoding was successful.
Definition: QRCodeEncoderBase.h:59
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