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 2007 ZXing authors | 8 * Copyright 2007 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 return temp; | 99 return temp; |
100 } | 100 } |
101 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::AddOrSubtract( | 101 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::AddOrSubtract( |
102 CBC_ReedSolomonGF256Poly* other, | 102 CBC_ReedSolomonGF256Poly* other, |
103 int32_t& e) { | 103 int32_t& e) { |
104 if (IsZero()) { | 104 if (IsZero()) { |
105 return other->Clone(e); | 105 return other->Clone(e); |
106 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 106 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
107 } | 107 } |
108 if (other->IsZero()) { | 108 if (other->IsZero()) { |
109 return this->Clone(e); | 109 return Clone(e); |
110 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 110 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
111 } | 111 } |
112 CFX_Int32Array smallerCoefficients; | 112 CFX_Int32Array smallerCoefficients; |
113 smallerCoefficients.Copy(m_coefficients); | 113 smallerCoefficients.Copy(m_coefficients); |
114 CFX_Int32Array largerCoefficients; | 114 CFX_Int32Array largerCoefficients; |
115 largerCoefficients.Copy(*(other->GetCoefficients())); | 115 largerCoefficients.Copy(*(other->GetCoefficients())); |
116 if (smallerCoefficients.GetSize() > largerCoefficients.GetSize()) { | 116 if (smallerCoefficients.GetSize() > largerCoefficients.GetSize()) { |
117 CFX_Int32Array temp; | 117 CFX_Int32Array temp; |
118 temp.Copy(smallerCoefficients); | 118 temp.Copy(smallerCoefficients); |
119 smallerCoefficients.Copy(largerCoefficients); | 119 smallerCoefficients.Copy(largerCoefficients); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 return temp; | 165 return temp; |
166 } | 166 } |
167 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(int32_t scalar, | 167 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(int32_t scalar, |
168 int32_t& e) { | 168 int32_t& e) { |
169 if (scalar == 0) { | 169 if (scalar == 0) { |
170 CBC_ReedSolomonGF256Poly* temp = m_field->GetZero()->Clone(e); | 170 CBC_ReedSolomonGF256Poly* temp = m_field->GetZero()->Clone(e); |
171 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 171 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
172 return temp; | 172 return temp; |
173 } | 173 } |
174 if (scalar == 1) { | 174 if (scalar == 1) { |
175 return this->Clone(e); | 175 return Clone(e); |
176 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 176 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
177 } | 177 } |
178 int32_t size = m_coefficients.GetSize(); | 178 int32_t size = m_coefficients.GetSize(); |
179 CFX_Int32Array product; | 179 CFX_Int32Array product; |
180 product.SetSize(size); | 180 product.SetSize(size); |
181 for (int32_t i = 0; i < size; i++) { | 181 for (int32_t i = 0; i < size; i++) { |
182 product[i] = m_field->Multiply(m_coefficients[i], scalar); | 182 product[i] = m_field->Multiply(m_coefficients[i], scalar); |
183 } | 183 } |
184 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); | 184 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); |
185 temp->Init(m_field, &product, e); | 185 temp->Init(m_field, &product, e); |
(...skipping 26 matching lines...) Expand all Loading... |
212 } | 212 } |
213 CFX_PtrArray* CBC_ReedSolomonGF256Poly::Divide(CBC_ReedSolomonGF256Poly* other, | 213 CFX_PtrArray* CBC_ReedSolomonGF256Poly::Divide(CBC_ReedSolomonGF256Poly* other, |
214 int32_t& e) { | 214 int32_t& e) { |
215 if (other->IsZero()) { | 215 if (other->IsZero()) { |
216 e = BCExceptionDivideByZero; | 216 e = BCExceptionDivideByZero; |
217 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 217 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
218 } | 218 } |
219 CBC_ReedSolomonGF256Poly* rsg1 = m_field->GetZero()->Clone(e); | 219 CBC_ReedSolomonGF256Poly* rsg1 = m_field->GetZero()->Clone(e); |
220 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 220 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
221 CBC_AutoPtr<CBC_ReedSolomonGF256Poly> quotient(rsg1); | 221 CBC_AutoPtr<CBC_ReedSolomonGF256Poly> quotient(rsg1); |
222 CBC_ReedSolomonGF256Poly* rsg2 = this->Clone(e); | 222 CBC_ReedSolomonGF256Poly* rsg2 = Clone(e); |
223 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 223 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
224 CBC_AutoPtr<CBC_ReedSolomonGF256Poly> remainder(rsg2); | 224 CBC_AutoPtr<CBC_ReedSolomonGF256Poly> remainder(rsg2); |
225 int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree()); | 225 int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree()); |
226 int32_t inverseDenominatorLeadingTeam = | 226 int32_t inverseDenominatorLeadingTeam = |
227 m_field->Inverse(denominatorLeadingTerm, e); | 227 m_field->Inverse(denominatorLeadingTerm, e); |
228 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 228 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
229 while (remainder->GetDegree() >= other->GetDegree() && !remainder->IsZero()) { | 229 while (remainder->GetDegree() >= other->GetDegree() && !remainder->IsZero()) { |
230 int32_t degreeDifference = remainder->GetDegree() - other->GetDegree(); | 230 int32_t degreeDifference = remainder->GetDegree() - other->GetDegree(); |
231 int32_t scale = | 231 int32_t scale = |
232 m_field->Multiply(remainder->GetCoefficients((remainder->GetDegree())), | 232 m_field->Multiply(remainder->GetCoefficients((remainder->GetDegree())), |
(...skipping 17 matching lines...) Expand all Loading... |
250 remainder = temp1; | 250 remainder = temp1; |
251 } | 251 } |
252 CFX_PtrArray* tempPtrA = new CFX_PtrArray; | 252 CFX_PtrArray* tempPtrA = new CFX_PtrArray; |
253 tempPtrA->Add(quotient.release()); | 253 tempPtrA->Add(quotient.release()); |
254 tempPtrA->Add(remainder.release()); | 254 tempPtrA->Add(remainder.release()); |
255 return tempPtrA; | 255 return tempPtrA; |
256 } | 256 } |
257 CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() { | 257 CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() { |
258 m_coefficients.RemoveAll(); | 258 m_coefficients.RemoveAll(); |
259 } | 259 } |
OLD | NEW |