1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2026 Axel Waggershauser
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <optional>
#include <span>
#include <stdexcept>
#include <string>
namespace ZXing {
enum class RSField
{
Aztec4,
Aztec6,
Aztec8,
Aztec10,
Aztec12,
DataMatrix,
MaxiCode,
PDF417,
QRCode
};
inline RSField GF2nAztec(int wordSize)
{
switch (wordSize) {
case 4: return RSField::Aztec4;
case 6: return RSField::Aztec6;
case 8: return RSField::Aztec8;
case 10: return RSField::Aztec10;
case 12: return RSField::Aztec12;
default: throw std::invalid_argument("Unsupported word size " + std::to_string(wordSize));
}
}
/**
* @brief ReedSolomonDecode fixes errors in a codeword containing both data and parity symbols.
*
* @param codeword data and error-correction/parity symbols; corrected in place on success
* @param numECC number of error-correction/parity symbols
* @param erasures positions of known erasures in the codeword
* @return optional unused error correction in the range [0, 1] if codeword errors could successfully be fixed (or there have not been
* any), std::nullopt otherwise
*/
std::optional<double> ReedSolomonDecode(RSField field, std::span<int> codeword, int numECC, std::span<const int> erasures = {});
std::optional<double> ReedSolomonDecode(RSField field, std::span<uint8_t> codeword, int numECC,
std::span<const int> erasures = {});
/**
* @brief ReedSolomonEncode generates error correction symbols for the given data symbols.
*
* @param field The Galois field to use for encoding.
* @param data The input data symbols.
* @param parity The output buffer for the generated error correction symbols.
*/
void ReedSolomonEncode(RSField field, std::span<const uint8_t> data, std::span<uint8_t> parity);
/// @brief ReedSolomonEncode replaces the last numECC symbols in codeword with parity symbols
void ReedSolomonEncode(RSField field, std::span<uint8_t> codeword, int numECC);
void ReedSolomonEncode(RSField field, std::span<int> codeword, int numECC);
} // ZXing