OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 // Original code is licensed as follows: | 6 // Original code is licensed as follows: |
7 /* | 7 /* |
8 * Copyright 2012 ZXing authors | 8 * Copyright 2012 ZXing authors |
9 * | 9 * |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
11 * you may not use this file except in compliance with the License. | 11 * you may not use this file except in compliance with the License. |
12 * You may obtain a copy of the License at | 12 * You may obtain a copy of the License at |
13 * | 13 * |
14 * http://www.apache.org/licenses/LICENSE-2.0 | 14 * http://www.apache.org/licenses/LICENSE-2.0 |
15 * | 15 * |
16 * Unless required by applicable law or agreed to in writing, software | 16 * Unless required by applicable law or agreed to in writing, software |
17 * distributed under the License is distributed on an "AS IS" BASIS, | 17 * distributed under the License is distributed on an "AS IS" BASIS, |
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
19 * See the License for the specific language governing permissions and | 19 * See the License for the specific language governing permissions and |
20 * limitations under the License. | 20 * limitations under the License. |
21 */ | 21 */ |
22 | 22 |
23 #include "../barcode.h" | 23 #include "../barcode.h" |
24 #include "BC_PDF417Common.h" | 24 #include "BC_PDF417Common.h" |
25 #include "BC_PDF417ECModulusPoly.h" | 25 #include "BC_PDF417ECModulusPoly.h" |
26 #include "BC_PDF417ECModulusGF.h" | 26 #include "BC_PDF417ECModulusGF.h" |
27 CBC_PDF417ECModulusGF* CBC_PDF417ECModulusGF::PDF417_GF = NULL; | 27 CBC_PDF417ECModulusGF* CBC_PDF417ECModulusGF::PDF417_GF = NULL; |
28 void CBC_PDF417ECModulusGF::Initialize(FX_INT32 &e) | 28 void CBC_PDF417ECModulusGF::Initialize(int32_t &e) |
29 { | 29 { |
30 PDF417_GF = FX_NEW CBC_PDF417ECModulusGF(CBC_PDF417Common::NUMBER_OF_CODEWOR
DS, 3, e); | 30 PDF417_GF = FX_NEW CBC_PDF417ECModulusGF(CBC_PDF417Common::NUMBER_OF_CODEWOR
DS, 3, e); |
31 } | 31 } |
32 void CBC_PDF417ECModulusGF::Finalize() | 32 void CBC_PDF417ECModulusGF::Finalize() |
33 { | 33 { |
34 delete PDF417_GF; | 34 delete PDF417_GF; |
35 } | 35 } |
36 CBC_PDF417ECModulusGF::CBC_PDF417ECModulusGF(FX_INT32 modulus, FX_INT32 generato
r, FX_INT32 &e) | 36 CBC_PDF417ECModulusGF::CBC_PDF417ECModulusGF(int32_t modulus, int32_t generator,
int32_t &e) |
37 { | 37 { |
38 m_modulus = modulus; | 38 m_modulus = modulus; |
39 m_expTable.SetSize(modulus); | 39 m_expTable.SetSize(modulus); |
40 m_logTable.SetSize(modulus); | 40 m_logTable.SetSize(modulus); |
41 FX_INT32 x = 1; | 41 int32_t x = 1; |
42 for (FX_INT32 i = 0; i < modulus; i++) { | 42 for (int32_t i = 0; i < modulus; i++) { |
43 m_expTable[i] = x; | 43 m_expTable[i] = x; |
44 x = (x * generator) % modulus; | 44 x = (x * generator) % modulus; |
45 } | 45 } |
46 for (FX_INT32 j = 0; j < modulus - 1; j++) { | 46 for (int32_t j = 0; j < modulus - 1; j++) { |
47 m_logTable[m_expTable[j]] = j; | 47 m_logTable[m_expTable[j]] = j; |
48 } | 48 } |
49 CFX_Int32Array zero; | 49 CFX_Int32Array zero; |
50 zero.Add(0); | 50 zero.Add(0); |
51 m_zero = FX_NEW CBC_PDF417ECModulusPoly(this, zero, e); | 51 m_zero = FX_NEW CBC_PDF417ECModulusPoly(this, zero, e); |
52 CFX_Int32Array one; | 52 CFX_Int32Array one; |
53 one.Add(1); | 53 one.Add(1); |
54 m_one = FX_NEW CBC_PDF417ECModulusPoly(this, one, e); | 54 m_one = FX_NEW CBC_PDF417ECModulusPoly(this, one, e); |
55 } | 55 } |
56 CBC_PDF417ECModulusGF::~CBC_PDF417ECModulusGF() | 56 CBC_PDF417ECModulusGF::~CBC_PDF417ECModulusGF() |
57 { | 57 { |
58 delete m_zero; | 58 delete m_zero; |
59 delete m_one; | 59 delete m_one; |
60 } | 60 } |
61 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusGF::getZero() | 61 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusGF::getZero() |
62 { | 62 { |
63 return m_zero; | 63 return m_zero; |
64 } | 64 } |
65 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusGF::getOne() | 65 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusGF::getOne() |
66 { | 66 { |
67 return m_one; | 67 return m_one; |
68 } | 68 } |
69 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusGF::buildMonomial(FX_INT32 degree, F
X_INT32 coefficient, FX_INT32 &e) | 69 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusGF::buildMonomial(int32_t degree, in
t32_t coefficient, int32_t &e) |
70 { | 70 { |
71 if (degree < 0) { | 71 if (degree < 0) { |
72 e = BCExceptionIllegalArgument; | 72 e = BCExceptionIllegalArgument; |
73 return NULL; | 73 return NULL; |
74 } | 74 } |
75 CBC_PDF417ECModulusPoly* modulusPoly = NULL; | 75 CBC_PDF417ECModulusPoly* modulusPoly = NULL; |
76 if (coefficient == 0) { | 76 if (coefficient == 0) { |
77 modulusPoly = FX_NEW CBC_PDF417ECModulusPoly(m_zero->getField(), m_zero-
>getCoefficients(), e); | 77 modulusPoly = FX_NEW CBC_PDF417ECModulusPoly(m_zero->getField(), m_zero-
>getCoefficients(), e); |
78 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 78 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
79 return modulusPoly; | 79 return modulusPoly; |
80 } | 80 } |
81 CFX_Int32Array coefficients; | 81 CFX_Int32Array coefficients; |
82 coefficients.SetSize(degree + 1); | 82 coefficients.SetSize(degree + 1); |
83 coefficients[0] = coefficient; | 83 coefficients[0] = coefficient; |
84 modulusPoly = FX_NEW CBC_PDF417ECModulusPoly(this, coefficients, e); | 84 modulusPoly = FX_NEW CBC_PDF417ECModulusPoly(this, coefficients, e); |
85 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 85 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
86 return modulusPoly; | 86 return modulusPoly; |
87 } | 87 } |
88 FX_INT32 CBC_PDF417ECModulusGF::add(FX_INT32 a, FX_INT32 b) | 88 int32_t CBC_PDF417ECModulusGF::add(int32_t a, int32_t b) |
89 { | 89 { |
90 return (a + b) % m_modulus; | 90 return (a + b) % m_modulus; |
91 } | 91 } |
92 FX_INT32 CBC_PDF417ECModulusGF::subtract(FX_INT32 a, FX_INT32 b) | 92 int32_t CBC_PDF417ECModulusGF::subtract(int32_t a, int32_t b) |
93 { | 93 { |
94 return (m_modulus + a - b) % m_modulus; | 94 return (m_modulus + a - b) % m_modulus; |
95 } | 95 } |
96 FX_INT32 CBC_PDF417ECModulusGF::exp(FX_INT32 a) | 96 int32_t CBC_PDF417ECModulusGF::exp(int32_t a) |
97 { | 97 { |
98 return m_expTable[a]; | 98 return m_expTable[a]; |
99 } | 99 } |
100 FX_INT32 CBC_PDF417ECModulusGF::log(FX_INT32 a, FX_INT32 &e) | 100 int32_t CBC_PDF417ECModulusGF::log(int32_t a, int32_t &e) |
101 { | 101 { |
102 if (a == 0) { | 102 if (a == 0) { |
103 e = BCExceptionIllegalArgument; | 103 e = BCExceptionIllegalArgument; |
104 return -1; | 104 return -1; |
105 } | 105 } |
106 return m_logTable[a]; | 106 return m_logTable[a]; |
107 } | 107 } |
108 FX_INT32 CBC_PDF417ECModulusGF::inverse(FX_INT32 a, FX_INT32 &e) | 108 int32_t CBC_PDF417ECModulusGF::inverse(int32_t a, int32_t &e) |
109 { | 109 { |
110 if (a == 0) { | 110 if (a == 0) { |
111 e = BCExceptionIllegalArgument; | 111 e = BCExceptionIllegalArgument; |
112 return -1; | 112 return -1; |
113 } | 113 } |
114 return m_expTable[m_modulus - m_logTable[a] - 1]; | 114 return m_expTable[m_modulus - m_logTable[a] - 1]; |
115 } | 115 } |
116 FX_INT32 CBC_PDF417ECModulusGF::multiply(FX_INT32 a, FX_INT32 b) | 116 int32_t CBC_PDF417ECModulusGF::multiply(int32_t a, int32_t b) |
117 { | 117 { |
118 if (a == 0 || b == 0) { | 118 if (a == 0 || b == 0) { |
119 return 0; | 119 return 0; |
120 } | 120 } |
121 return m_expTable[(m_logTable[a] + m_logTable[b]) % (m_modulus - 1)]; | 121 return m_expTable[(m_logTable[a] + m_logTable[b]) % (m_modulus - 1)]; |
122 } | 122 } |
123 FX_INT32 CBC_PDF417ECModulusGF::getSize() | 123 int32_t CBC_PDF417ECModulusGF::getSize() |
124 { | 124 { |
125 return m_modulus; | 125 return m_modulus; |
126 } | 126 } |
OLD | NEW |