OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 // Original code is licensed as follows: | |
7 /* | |
8 * Copyright 2007 ZXing authors | |
9 * | |
10 * Licensed under the Apache License, Version 2.0 (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 | |
13 * | |
14 * http://www.apache.org/licenses/LICENSE-2.0 | |
15 * | |
16 * Unless required by applicable law or agreed to in writing, software | |
17 * distributed under the License is distributed on an "AS IS" BASIS, | |
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
19 * See the License for the specific language governing permissions and | |
20 * limitations under the License. | |
21 */ | |
22 | |
23 #include "barcode.h" | |
24 #include "include/BC_ReedSolomonGF256Poly.h" | |
25 #include "include/BC_ReedSolomonGF256.h" | |
26 CBC_ReedSolomonGF256 *CBC_ReedSolomonGF256::QRCodeFild = NULL; | |
27 CBC_ReedSolomonGF256 *CBC_ReedSolomonGF256::DataMatrixField = NULL; | |
28 void CBC_ReedSolomonGF256::Initialize() | |
29 { | |
30 QRCodeFild = FX_NEW CBC_ReedSolomonGF256(0x011D); | |
31 QRCodeFild->Init(); | |
32 DataMatrixField = FX_NEW CBC_ReedSolomonGF256(0x012D); | |
33 DataMatrixField->Init(); | |
34 } | |
35 void CBC_ReedSolomonGF256::Finalize() | |
36 { | |
37 if (QRCodeFild) { | |
38 delete QRCodeFild; | |
39 } | |
40 QRCodeFild = NULL; | |
41 if (DataMatrixField) { | |
42 delete DataMatrixField; | |
43 } | |
44 DataMatrixField = NULL; | |
45 } | |
46 CBC_ReedSolomonGF256::CBC_ReedSolomonGF256(FX_INT32 primitive) | |
47 { | |
48 FX_INT32 x = 1; | |
49 for(FX_INT32 j = 0; j < 256; j++) { | |
50 m_expTable[j] = x; | |
51 x <<= 1; | |
52 if(x >= 0x100) { | |
53 x ^= primitive; | |
54 } | |
55 } | |
56 for(FX_INT32 i = 0; i < 255; i++) { | |
57 m_logTable[m_expTable[i]] = i; | |
58 } | |
59 m_logTable[0] = 0; | |
60 } | |
61 void CBC_ReedSolomonGF256::Init() | |
62 { | |
63 m_zero = FX_NEW CBC_ReedSolomonGF256Poly(this, 0); | |
64 m_one = FX_NEW CBC_ReedSolomonGF256Poly(this, 1); | |
65 } | |
66 CBC_ReedSolomonGF256::~CBC_ReedSolomonGF256() | |
67 { | |
68 if(m_zero != NULL) { | |
69 delete m_zero; | |
70 m_zero = NULL; | |
71 } | |
72 if(m_one != NULL) { | |
73 delete m_one; | |
74 m_one = NULL; | |
75 } | |
76 } | |
77 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetZero() | |
78 { | |
79 return m_zero; | |
80 } | |
81 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetOne() | |
82 { | |
83 return m_one; | |
84 } | |
85 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::BuildMonomial(FX_INT32 degree, F
X_INT32 coefficient, FX_INT32 &e) | |
86 { | |
87 if(degree < 0) { | |
88 e = BCExceptionDegreeIsNegative; | |
89 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | |
90 } | |
91 if(coefficient == 0) { | |
92 CBC_ReedSolomonGF256Poly* temp = m_zero->Clone(e); | |
93 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | |
94 return temp; | |
95 } | |
96 CFX_Int32Array coefficients; | |
97 coefficients.SetSize(degree + 1); | |
98 coefficients[0] = coefficient; | |
99 CBC_ReedSolomonGF256Poly *temp = FX_NEW CBC_ReedSolomonGF256Poly(); | |
100 temp->Init(this, &coefficients, e); | |
101 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | |
102 return temp; | |
103 } | |
104 FX_INT32 CBC_ReedSolomonGF256::AddOrSubtract(FX_INT32 a, FX_INT32 b) | |
105 { | |
106 return a ^ b; | |
107 } | |
108 FX_INT32 CBC_ReedSolomonGF256::Exp(FX_INT32 a) | |
109 { | |
110 return m_expTable[a]; | |
111 } | |
112 FX_INT32 CBC_ReedSolomonGF256::Log(FX_INT32 a, FX_INT32 &e) | |
113 { | |
114 if(a == 0) { | |
115 e = BCExceptionAIsZero; | |
116 BC_EXCEPTION_CHECK_ReturnValue(e, 0); | |
117 } | |
118 return m_logTable[a]; | |
119 } | |
120 FX_INT32 CBC_ReedSolomonGF256::Inverse(FX_INT32 a, FX_INT32 &e) | |
121 { | |
122 if(a == 0) { | |
123 e = BCExceptionAIsZero; | |
124 BC_EXCEPTION_CHECK_ReturnValue(e, 0); | |
125 } | |
126 return m_expTable[255 - m_logTable[a]]; | |
127 } | |
128 FX_INT32 CBC_ReedSolomonGF256::Multiply(FX_INT32 a, FX_INT32 b) | |
129 { | |
130 if(a == 0 || b == 0) { | |
131 return 0; | |
132 } | |
133 if(a == 1) { | |
134 return b; | |
135 } | |
136 if(b == 1) { | |
137 return a; | |
138 } | |
139 return m_expTable[(m_logTable[a] + m_logTable[b]) % 255]; | |
140 } | |
OLD | NEW |