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 "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" | |
24 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h" | |
25 | |
26 CBC_ReedSolomonGF256* CBC_ReedSolomonGF256::QRCodeFild = NULL; | |
27 CBC_ReedSolomonGF256* CBC_ReedSolomonGF256::DataMatrixField = NULL; | |
28 void CBC_ReedSolomonGF256::Initialize() { | |
29 QRCodeFild = new CBC_ReedSolomonGF256(0x011D); | |
30 QRCodeFild->Init(); | |
31 DataMatrixField = new CBC_ReedSolomonGF256(0x012D); | |
32 DataMatrixField->Init(); | |
33 } | |
34 void CBC_ReedSolomonGF256::Finalize() { | |
35 if (QRCodeFild) { | |
36 delete QRCodeFild; | |
37 } | |
38 QRCodeFild = NULL; | |
39 if (DataMatrixField) { | |
40 delete DataMatrixField; | |
41 } | |
42 DataMatrixField = NULL; | |
43 } | |
44 CBC_ReedSolomonGF256::CBC_ReedSolomonGF256(int32_t primitive) { | |
45 int32_t x = 1; | |
46 for (int32_t j = 0; j < 256; j++) { | |
47 m_expTable[j] = x; | |
48 x <<= 1; | |
49 if (x >= 0x100) { | |
50 x ^= primitive; | |
51 } | |
52 } | |
53 for (int32_t i = 0; i < 255; i++) { | |
54 m_logTable[m_expTable[i]] = i; | |
55 } | |
56 m_logTable[0] = 0; | |
57 } | |
58 void CBC_ReedSolomonGF256::Init() { | |
59 m_zero = new CBC_ReedSolomonGF256Poly(this, 0); | |
60 m_one = new CBC_ReedSolomonGF256Poly(this, 1); | |
61 } | |
62 CBC_ReedSolomonGF256::~CBC_ReedSolomonGF256() { | |
63 delete m_zero; | |
64 delete m_one; | |
65 } | |
66 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetZero() { | |
67 return m_zero; | |
68 } | |
69 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetOne() { | |
70 return m_one; | |
71 } | |
72 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::BuildMonomial( | |
73 int32_t degree, | |
74 int32_t coefficient, | |
75 int32_t& e) { | |
76 if (degree < 0) { | |
77 e = BCExceptionDegreeIsNegative; | |
78 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | |
79 } | |
80 if (coefficient == 0) { | |
81 CBC_ReedSolomonGF256Poly* temp = m_zero->Clone(e); | |
82 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | |
83 return temp; | |
84 } | |
85 CFX_Int32Array coefficients; | |
86 coefficients.SetSize(degree + 1); | |
87 coefficients[0] = coefficient; | |
88 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); | |
89 temp->Init(this, &coefficients, e); | |
90 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | |
91 return temp; | |
92 } | |
93 int32_t CBC_ReedSolomonGF256::AddOrSubtract(int32_t a, int32_t b) { | |
94 return a ^ b; | |
95 } | |
96 int32_t CBC_ReedSolomonGF256::Exp(int32_t a) { | |
97 return m_expTable[a]; | |
98 } | |
99 int32_t CBC_ReedSolomonGF256::Log(int32_t a, int32_t& e) { | |
100 if (a == 0) { | |
101 e = BCExceptionAIsZero; | |
102 BC_EXCEPTION_CHECK_ReturnValue(e, 0); | |
103 } | |
104 return m_logTable[a]; | |
105 } | |
106 int32_t CBC_ReedSolomonGF256::Inverse(int32_t a, int32_t& e) { | |
107 if (a == 0) { | |
108 e = BCExceptionAIsZero; | |
109 BC_EXCEPTION_CHECK_ReturnValue(e, 0); | |
110 } | |
111 return m_expTable[255 - m_logTable[a]]; | |
112 } | |
113 int32_t CBC_ReedSolomonGF256::Multiply(int32_t a, int32_t b) { | |
114 if (a == 0 || b == 0) { | |
115 return 0; | |
116 } | |
117 if (a == 1) { | |
118 return b; | |
119 } | |
120 if (b == 1) { | |
121 return a; | |
122 } | |
123 return m_expTable[(m_logTable[a] + m_logTable[b]) % 255]; | |
124 } | |
OLD | NEW |