7#include "bitvector_p.h"
8#include "reedsolomon_p.h"
17static int highestBit(
int n)
20 while (n >= (1 << i)) {
26ReedSolomon::ReedSolomon(
int polynom,
int symbolCount)
27 : m_symCount(symbolCount)
29 m_symSize = highestBit(polynom);
32 const auto logmod = (1 << m_symSize) - 1;
33 m_logTable.reset(
new int[logmod + 1]);
34 m_antiLogTable.reset(
new int[logmod]);
36 for (
int p = 1, v = 0; v < logmod; v++) {
37 m_antiLogTable[v] = p;
40 if (p & (1 << m_symSize)) {
46 m_polynom.reset(
new int[m_symCount + 1]);
48 for (
int i = 1; i <= m_symCount; ++i) {
50 for (
int k = i - 1; k > 0; --k) {
52 m_polynom[k] = m_antiLogTable[(m_logTable[m_polynom[k]] + i) % logmod];
54 m_polynom[k] ^= m_polynom[k - 1];
56 m_polynom[0] = m_antiLogTable[(m_logTable[m_polynom[0]] + i) % logmod];
60ReedSolomon::~ReedSolomon() =
default;
62BitVector ReedSolomon::encode(
const BitVector &input)
const
64 std::unique_ptr<int[]> result(
new int[m_symCount]);
65 for (
int i = 0; i < m_symCount; ++i) {
69 const auto logmod = (1 << m_symSize) - 1;
70 for (
int i = 0; i < input.size() / m_symSize; i++) {
71 auto m = result[m_symCount - 1] ^ input.valueAtMSB(i * m_symSize, m_symSize);
72 for (
int k = m_symCount - 1; k > 0; --k) {
73 if (m && m_polynom[k]) {
74 result[k] = result[k - 1] ^ m_antiLogTable[(m_logTable[m] + m_logTable[m_polynom[k]]) % logmod];
76 result[k] = result[k - 1];
79 if (m && m_polynom[0]) {
80 result[0] = m_antiLogTable[(m_logTable[m] + m_logTable[m_polynom[0]]) % logmod];
87 for (
int i = m_symCount - 1; i >= 0; --i) {
88 v.appendMSB(result[i], m_symSize);
Provides classes and methods for generating barcodes.