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"); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 87 } |
88 int32_t result = m_coefficients[0]; | 88 int32_t result = m_coefficients[0]; |
89 for (int32_t i = 1; i < size; i++) { | 89 for (int32_t i = 1; i < size; i++) { |
90 result = m_field->add(m_field->multiply(a, result), m_coefficients[i]); | 90 result = m_field->add(m_field->multiply(a, result), m_coefficients[i]); |
91 } | 91 } |
92 return result; | 92 return result; |
93 } | 93 } |
94 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::add( | 94 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::add( |
95 CBC_PDF417ECModulusPoly* other, | 95 CBC_PDF417ECModulusPoly* other, |
96 int32_t& e) { | 96 int32_t& e) { |
97 CBC_PDF417ECModulusPoly* modulusPoly = NULL; | 97 CBC_PDF417ECModulusPoly* modulusPoly = nullptr; |
98 if (isZero()) { | 98 if (isZero()) { |
99 modulusPoly = new CBC_PDF417ECModulusPoly(other->getField(), | 99 modulusPoly = new CBC_PDF417ECModulusPoly(other->getField(), |
100 other->getCoefficients(), e); | 100 other->getCoefficients(), e); |
101 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 101 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
102 return modulusPoly; | 102 return modulusPoly; |
103 } | 103 } |
104 if (other->isZero()) { | 104 if (other->isZero()) { |
105 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, m_coefficients, e); | 105 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, m_coefficients, e); |
106 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 106 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
107 return modulusPoly; | 107 return modulusPoly; |
108 } | 108 } |
109 CFX_Int32Array smallerCoefficients; | 109 CFX_Int32Array smallerCoefficients; |
110 smallerCoefficients.Copy(m_coefficients); | 110 smallerCoefficients.Copy(m_coefficients); |
111 CFX_Int32Array largerCoefficients; | 111 CFX_Int32Array largerCoefficients; |
112 largerCoefficients.Copy(other->m_coefficients); | 112 largerCoefficients.Copy(other->m_coefficients); |
113 if (smallerCoefficients.GetSize() > largerCoefficients.GetSize()) { | 113 if (smallerCoefficients.GetSize() > largerCoefficients.GetSize()) { |
114 CFX_Int32Array temp; | 114 CFX_Int32Array temp; |
115 temp.Copy(smallerCoefficients); | 115 temp.Copy(smallerCoefficients); |
116 smallerCoefficients.Copy(largerCoefficients); | 116 smallerCoefficients.Copy(largerCoefficients); |
117 largerCoefficients.Copy(temp); | 117 largerCoefficients.Copy(temp); |
118 } | 118 } |
119 CFX_Int32Array sumDiff; | 119 CFX_Int32Array sumDiff; |
120 sumDiff.SetSize(largerCoefficients.GetSize()); | 120 sumDiff.SetSize(largerCoefficients.GetSize()); |
121 int32_t lengthDiff = | 121 int32_t lengthDiff = |
122 largerCoefficients.GetSize() - smallerCoefficients.GetSize(); | 122 largerCoefficients.GetSize() - smallerCoefficients.GetSize(); |
123 for (int32_t l = 0; l < lengthDiff; l++) { | 123 for (int32_t l = 0; l < lengthDiff; l++) { |
124 sumDiff.SetAt(l, largerCoefficients.GetAt(l)); | 124 sumDiff.SetAt(l, largerCoefficients.GetAt(l)); |
125 } | 125 } |
126 for (int32_t i = lengthDiff; i < largerCoefficients.GetSize(); i++) { | 126 for (int32_t i = lengthDiff; i < largerCoefficients.GetSize(); i++) { |
127 sumDiff[i] = m_field->add(smallerCoefficients[i - lengthDiff], | 127 sumDiff[i] = m_field->add(smallerCoefficients[i - lengthDiff], |
128 largerCoefficients[i]); | 128 largerCoefficients[i]); |
129 } | 129 } |
130 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, sumDiff, e); | 130 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, sumDiff, e); |
131 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 131 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
132 return modulusPoly; | 132 return modulusPoly; |
133 } | 133 } |
134 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::subtract( | 134 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::subtract( |
135 CBC_PDF417ECModulusPoly* other, | 135 CBC_PDF417ECModulusPoly* other, |
136 int32_t& e) { | 136 int32_t& e) { |
137 CBC_PDF417ECModulusPoly* modulusPoly = NULL; | 137 CBC_PDF417ECModulusPoly* modulusPoly = nullptr; |
138 if (other->isZero()) { | 138 if (other->isZero()) { |
139 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, m_coefficients, e); | 139 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, m_coefficients, e); |
140 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 140 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
141 return modulusPoly; | 141 return modulusPoly; |
142 } | 142 } |
143 CBC_PDF417ECModulusPoly* poly = other->negative(e); | 143 CBC_PDF417ECModulusPoly* poly = other->negative(e); |
144 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 144 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
145 modulusPoly = add(poly, e); | 145 modulusPoly = add(poly, e); |
146 delete poly; | 146 delete poly; |
147 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 147 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
148 return modulusPoly; | 148 return modulusPoly; |
149 } | 149 } |
150 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::multiply( | 150 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::multiply( |
151 CBC_PDF417ECModulusPoly* other, | 151 CBC_PDF417ECModulusPoly* other, |
152 int32_t& e) { | 152 int32_t& e) { |
153 CBC_PDF417ECModulusPoly* modulusPoly = NULL; | 153 CBC_PDF417ECModulusPoly* modulusPoly = nullptr; |
154 if (isZero() || other->isZero()) { | 154 if (isZero() || other->isZero()) { |
155 modulusPoly = | 155 modulusPoly = |
156 new CBC_PDF417ECModulusPoly(m_field->getZero()->getField(), | 156 new CBC_PDF417ECModulusPoly(m_field->getZero()->getField(), |
157 m_field->getZero()->getCoefficients(), e); | 157 m_field->getZero()->getCoefficients(), e); |
158 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 158 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
159 return modulusPoly; | 159 return modulusPoly; |
160 } | 160 } |
161 CFX_Int32Array aCoefficients; | 161 CFX_Int32Array aCoefficients; |
162 aCoefficients.Copy(m_coefficients); | 162 aCoefficients.Copy(m_coefficients); |
163 int32_t aLength = aCoefficients.GetSize(); | 163 int32_t aLength = aCoefficients.GetSize(); |
164 CFX_Int32Array bCoefficients; | 164 CFX_Int32Array bCoefficients; |
165 bCoefficients.Copy(other->m_coefficients); | 165 bCoefficients.Copy(other->m_coefficients); |
166 int32_t bLength = bCoefficients.GetSize(); | 166 int32_t bLength = bCoefficients.GetSize(); |
167 CFX_Int32Array product; | 167 CFX_Int32Array product; |
168 product.SetSize(aLength + bLength - 1); | 168 product.SetSize(aLength + bLength - 1); |
169 for (int32_t i = 0; i < aLength; i++) { | 169 for (int32_t i = 0; i < aLength; i++) { |
170 int32_t aCoeff = aCoefficients[i]; | 170 int32_t aCoeff = aCoefficients[i]; |
171 for (int32_t j = 0; j < bLength; j++) { | 171 for (int32_t j = 0; j < bLength; j++) { |
172 product[i + j] = m_field->add( | 172 product[i + j] = m_field->add( |
173 product[i + j], m_field->multiply(aCoeff, bCoefficients[j])); | 173 product[i + j], m_field->multiply(aCoeff, bCoefficients[j])); |
174 } | 174 } |
175 } | 175 } |
176 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, product, e); | 176 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, product, e); |
177 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 177 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
178 return modulusPoly; | 178 return modulusPoly; |
179 } | 179 } |
180 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::negative(int32_t& e) { | 180 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::negative(int32_t& e) { |
181 int32_t size = m_coefficients.GetSize(); | 181 int32_t size = m_coefficients.GetSize(); |
182 CFX_Int32Array negativeCoefficients; | 182 CFX_Int32Array negativeCoefficients; |
183 negativeCoefficients.SetSize(size); | 183 negativeCoefficients.SetSize(size); |
184 for (int32_t i = 0; i < size; i++) { | 184 for (int32_t i = 0; i < size; i++) { |
185 negativeCoefficients[i] = m_field->subtract(0, m_coefficients[i]); | 185 negativeCoefficients[i] = m_field->subtract(0, m_coefficients[i]); |
186 } | 186 } |
187 CBC_PDF417ECModulusPoly* modulusPoly = | 187 CBC_PDF417ECModulusPoly* modulusPoly = |
188 new CBC_PDF417ECModulusPoly(m_field, negativeCoefficients, e); | 188 new CBC_PDF417ECModulusPoly(m_field, negativeCoefficients, e); |
189 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 189 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
190 return modulusPoly; | 190 return modulusPoly; |
191 } | 191 } |
192 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::multiply(int32_t scalar, | 192 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::multiply(int32_t scalar, |
193 int32_t& e) { | 193 int32_t& e) { |
194 CBC_PDF417ECModulusPoly* modulusPoly = NULL; | 194 CBC_PDF417ECModulusPoly* modulusPoly = nullptr; |
195 if (scalar == 0) { | 195 if (scalar == 0) { |
196 modulusPoly = | 196 modulusPoly = |
197 new CBC_PDF417ECModulusPoly(m_field->getZero()->getField(), | 197 new CBC_PDF417ECModulusPoly(m_field->getZero()->getField(), |
198 m_field->getZero()->getCoefficients(), e); | 198 m_field->getZero()->getCoefficients(), e); |
199 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 199 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
200 return modulusPoly; | 200 return modulusPoly; |
201 } | 201 } |
202 if (scalar == 1) { | 202 if (scalar == 1) { |
203 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, m_coefficients, e); | 203 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, m_coefficients, e); |
204 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 204 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
205 return modulusPoly; | 205 return modulusPoly; |
206 } | 206 } |
207 int32_t size = m_coefficients.GetSize(); | 207 int32_t size = m_coefficients.GetSize(); |
208 CFX_Int32Array product; | 208 CFX_Int32Array product; |
209 product.SetSize(size); | 209 product.SetSize(size); |
210 for (int32_t i = 0; i < size; i++) { | 210 for (int32_t i = 0; i < size; i++) { |
211 product[i] = m_field->multiply(m_coefficients[i], scalar); | 211 product[i] = m_field->multiply(m_coefficients[i], scalar); |
212 } | 212 } |
213 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, product, e); | 213 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, product, e); |
214 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 214 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
215 return modulusPoly; | 215 return modulusPoly; |
216 } | 216 } |
217 | 217 |
218 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::multiplyByMonomial( | 218 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::multiplyByMonomial( |
219 int32_t degree, | 219 int32_t degree, |
220 int32_t coefficient, | 220 int32_t coefficient, |
221 int32_t& e) { | 221 int32_t& e) { |
222 if (degree < 0) { | 222 if (degree < 0) { |
223 e = BCExceptionIllegalArgument; | 223 e = BCExceptionIllegalArgument; |
224 return nullptr; | 224 return nullptr; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 result += 'x'; | 314 result += 'x'; |
315 } else { | 315 } else { |
316 result += "x^"; | 316 result += "x^"; |
317 result += degree; | 317 result += degree; |
318 } | 318 } |
319 } | 319 } |
320 } | 320 } |
321 } | 321 } |
322 return result; | 322 return result; |
323 } | 323 } |
OLD | NEW |