comparison mupdf-source/thirdparty/zxing-cpp/core/src/GenericGF.cpp @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /*
2 * Copyright 2016 Nu-book Inc.
3 * Copyright 2016 ZXing authors
4 */
5 // SPDX-License-Identifier: Apache-2.0
6
7 #include "GenericGF.h"
8
9 namespace ZXing {
10
11 const GenericGF &
12 GenericGF::AztecData12()
13 {
14 static GenericGF inst(0x1069, 4096, 1); // x^12 + x^6 + x^5 + x^3 + 1
15 return inst;
16 }
17
18 const GenericGF &
19 GenericGF::AztecData10()
20 {
21 static GenericGF inst(0x409, 1024, 1); // x^10 + x^3 + 1
22 return inst;
23 }
24
25 const GenericGF &
26 GenericGF::AztecData6()
27 {
28 static GenericGF inst(0x43, 64, 1); // x^6 + x + 1
29 return inst;
30 }
31
32 const GenericGF &
33 GenericGF::AztecParam()
34 {
35 static GenericGF inst(0x13, 16, 1); // x^4 + x + 1
36 return inst;
37 }
38
39 const GenericGF &
40 GenericGF::QRCodeField256()
41 {
42 static GenericGF inst(0x011D, 256, 0); // x^8 + x^4 + x^3 + x^2 + 1
43 return inst;
44 }
45
46 const GenericGF &
47 GenericGF::DataMatrixField256()
48 {
49 static GenericGF inst(0x012D, 256, 1); // x^8 + x^5 + x^3 + x^2 + 1
50 return inst;
51 }
52
53 const GenericGF &
54 GenericGF::AztecData8()
55 {
56 static const GenericGF inst(0x012D, 256, 1); // = DATA_MATRIX_FIELD_256;
57 return inst;
58 }
59
60 const GenericGF &
61 GenericGF::MaxiCodeField64()
62 {
63 static const GenericGF inst(0x43, 64, 1); // = AZTEC_DATA_6;
64 return inst;
65 }
66
67
68 /**
69 * Create a representation of GF(size) using the given primitive polynomial.
70 *
71 * @param primitive irreducible polynomial whose coefficients are represented by
72 * the bits of an int, where the least-significant bit represents the constant
73 * coefficient
74 * @param size the size of the field
75 * @param b the factor b in the generator polynomial can be 0- or 1-based
76 * (g(x) = (x+a^b)(x+a^(b+1))...(x+a^(b+2t-1))).
77 * In most cases it should be 1, but for QR code it is 0.
78 */
79 GenericGF::GenericGF(int primitive, int size, int b) :
80 _size(size),
81 _generatorBase(b)
82 {
83 #ifdef ZX_REED_SOLOMON_USE_MORE_MEMORY_FOR_SPEED
84 _expTable.resize(size * 2, 0);
85 #else
86 _expTable.resize(size, 0);
87 #endif
88 _logTable.resize(size, 0);
89 int x = 1;
90 for (int i = 0; i < size; ++i) {
91 _expTable[i] = x;
92 x *= 2; // we're assuming the generator alpha is 2
93 if (x >= size) {
94 x ^= primitive;
95 x &= size - 1;
96 }
97 }
98
99 #ifdef ZX_REED_SOLOMON_USE_MORE_MEMORY_FOR_SPEED
100 for (int i = size - 1; i < size * 2; ++i)
101 _expTable[i] = _expTable[i - (size - 1)];
102 #endif
103
104 for (int i = 0; i < size - 1; ++i)
105 _logTable[_expTable[i]] = i;
106 // logTable[0] == 0 but this should never be used
107 }
108
109 } // namespace ZXing