| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 97 } |
| 98 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Clone(int32_t& e) { | 98 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Clone(int32_t& e) { |
| 99 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); | 99 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); |
| 100 temp->Init(m_field, &m_coefficients, e); | 100 temp->Init(m_field, &m_coefficients, e); |
| 101 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 101 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 102 return temp; | 102 return temp; |
| 103 } | 103 } |
| 104 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::AddOrSubtract( | 104 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::AddOrSubtract( |
| 105 CBC_ReedSolomonGF256Poly* other, | 105 CBC_ReedSolomonGF256Poly* other, |
| 106 int32_t& e) { | 106 int32_t& e) { |
| 107 if (IsZero()) { | 107 if (IsZero()) |
| 108 return other->Clone(e); | 108 return other->Clone(e); |
| 109 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 109 if (other->IsZero()) |
| 110 } | |
| 111 if (other->IsZero()) { | |
| 112 return Clone(e); | 110 return Clone(e); |
| 113 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 111 |
| 114 } | |
| 115 CFX_Int32Array smallerCoefficients; | 112 CFX_Int32Array smallerCoefficients; |
| 116 smallerCoefficients.Copy(m_coefficients); | 113 smallerCoefficients.Copy(m_coefficients); |
| 117 CFX_Int32Array largerCoefficients; | 114 CFX_Int32Array largerCoefficients; |
| 118 largerCoefficients.Copy(*(other->GetCoefficients())); | 115 largerCoefficients.Copy(*(other->GetCoefficients())); |
| 119 if (smallerCoefficients.GetSize() > largerCoefficients.GetSize()) { | 116 if (smallerCoefficients.GetSize() > largerCoefficients.GetSize()) { |
| 120 CFX_Int32Array temp; | 117 CFX_Int32Array temp; |
| 121 temp.Copy(smallerCoefficients); | 118 temp.Copy(smallerCoefficients); |
| 122 smallerCoefficients.Copy(largerCoefficients); | 119 smallerCoefficients.Copy(largerCoefficients); |
| 123 largerCoefficients.Copy(temp); | 120 largerCoefficients.Copy(temp); |
| 124 } | 121 } |
| 125 CFX_Int32Array sumDiff; | 122 CFX_Int32Array sumDiff; |
| 126 sumDiff.SetSize(largerCoefficients.GetSize()); | 123 sumDiff.SetSize(largerCoefficients.GetSize()); |
| 127 int32_t lengthDiff = | 124 int32_t lengthDiff = |
| 128 largerCoefficients.GetSize() - smallerCoefficients.GetSize(); | 125 largerCoefficients.GetSize() - smallerCoefficients.GetSize(); |
| 129 for (int32_t i = 0; i < lengthDiff; i++) { | 126 for (int32_t i = 0; i < lengthDiff; i++) { |
| 130 sumDiff[i] = largerCoefficients[i]; | 127 sumDiff[i] = largerCoefficients[i]; |
| 131 } | 128 } |
| 132 for (int32_t j = lengthDiff; j < largerCoefficients.GetSize(); j++) { | 129 for (int32_t j = lengthDiff; j < largerCoefficients.GetSize(); j++) { |
| 133 sumDiff[j] = (CBC_ReedSolomonGF256::AddOrSubtract( | 130 sumDiff[j] = (CBC_ReedSolomonGF256::AddOrSubtract( |
| 134 smallerCoefficients[j - lengthDiff], largerCoefficients[j])); | 131 smallerCoefficients[j - lengthDiff], largerCoefficients[j])); |
| 135 } | 132 } |
| 136 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); | 133 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); |
| 137 temp->Init(m_field, &sumDiff, e); | 134 temp->Init(m_field, &sumDiff, e); |
| 138 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 135 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 139 return temp; | 136 return temp; |
| 140 } | 137 } |
| 141 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply( | 138 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply( |
| 142 CBC_ReedSolomonGF256Poly* other, | 139 CBC_ReedSolomonGF256Poly* other, |
| 143 int32_t& e) { | 140 int32_t& e) { |
| 144 if (IsZero() || other->IsZero()) { | 141 if (IsZero() || other->IsZero()) |
| 145 CBC_ReedSolomonGF256Poly* temp = m_field->GetZero()->Clone(e); | 142 return m_field->GetZero()->Clone(e); |
| 146 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 143 |
| 147 return temp; | |
| 148 } | |
| 149 CFX_Int32Array aCoefficients; | 144 CFX_Int32Array aCoefficients; |
| 150 aCoefficients.Copy(m_coefficients); | 145 aCoefficients.Copy(m_coefficients); |
| 151 int32_t aLength = m_coefficients.GetSize(); | 146 int32_t aLength = m_coefficients.GetSize(); |
| 152 CFX_Int32Array bCoefficients; | 147 CFX_Int32Array bCoefficients; |
| 153 bCoefficients.Copy(*(other->GetCoefficients())); | 148 bCoefficients.Copy(*(other->GetCoefficients())); |
| 154 int32_t bLength = other->GetCoefficients()->GetSize(); | 149 int32_t bLength = other->GetCoefficients()->GetSize(); |
| 155 CFX_Int32Array product; | 150 CFX_Int32Array product; |
| 156 product.SetSize(aLength + bLength - 1); | 151 product.SetSize(aLength + bLength - 1); |
| 157 for (int32_t i = 0; i < aLength; i++) { | 152 for (int32_t i = 0; i < aLength; i++) { |
| 158 int32_t aCoeff = m_coefficients[i]; | 153 int32_t aCoeff = m_coefficients[i]; |
| 159 for (int32_t j = 0; j < bLength; j++) { | 154 for (int32_t j = 0; j < bLength; j++) { |
| 160 product[i + j] = CBC_ReedSolomonGF256::AddOrSubtract( | 155 product[i + j] = CBC_ReedSolomonGF256::AddOrSubtract( |
| 161 product[i + j], | 156 product[i + j], |
| 162 m_field->Multiply(aCoeff, other->GetCoefficients()->operator[](j))); | 157 m_field->Multiply(aCoeff, other->GetCoefficients()->operator[](j))); |
| 163 } | 158 } |
| 164 } | 159 } |
| 165 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); | 160 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); |
| 166 temp->Init(m_field, &product, e); | 161 temp->Init(m_field, &product, e); |
| 167 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 162 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 168 return temp; | 163 return temp; |
| 169 } | 164 } |
| 170 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(int32_t scalar, | 165 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(int32_t scalar, |
| 171 int32_t& e) { | 166 int32_t& e) { |
| 172 if (scalar == 0) { | 167 if (scalar == 0) |
| 173 CBC_ReedSolomonGF256Poly* temp = m_field->GetZero()->Clone(e); | 168 return m_field->GetZero()->Clone(e); |
| 174 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 169 if (scalar == 1) |
| 175 return temp; | |
| 176 } | |
| 177 if (scalar == 1) { | |
| 178 return Clone(e); | 170 return Clone(e); |
| 179 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 171 |
| 180 } | |
| 181 int32_t size = m_coefficients.GetSize(); | 172 int32_t size = m_coefficients.GetSize(); |
| 182 CFX_Int32Array product; | 173 CFX_Int32Array product; |
| 183 product.SetSize(size); | 174 product.SetSize(size); |
| 184 for (int32_t i = 0; i < size; i++) { | 175 for (int32_t i = 0; i < size; i++) { |
| 185 product[i] = m_field->Multiply(m_coefficients[i], scalar); | 176 product[i] = m_field->Multiply(m_coefficients[i], scalar); |
| 186 } | 177 } |
| 187 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); | 178 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); |
| 188 temp->Init(m_field, &product, e); | 179 temp->Init(m_field, &product, e); |
| 189 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 180 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 190 return temp; | 181 return temp; |
| 191 } | 182 } |
| 192 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::MultiplyByMonomial( | 183 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::MultiplyByMonomial( |
| 193 int32_t degree, | 184 int32_t degree, |
| 194 int32_t coefficient, | 185 int32_t coefficient, |
| 195 int32_t& e) { | 186 int32_t& e) { |
| 196 if (degree < 0) { | 187 if (degree < 0) { |
| 197 e = BCExceptionDegreeIsNegative; | 188 e = BCExceptionDegreeIsNegative; |
| 198 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 189 return nullptr; |
| 199 } | 190 } |
| 200 if (coefficient == 0) { | 191 if (coefficient == 0) |
| 201 CBC_ReedSolomonGF256Poly* temp = m_field->GetZero()->Clone(e); | 192 return m_field->GetZero()->Clone(e); |
| 202 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 193 |
| 203 return temp; | |
| 204 } | |
| 205 int32_t size = m_coefficients.GetSize(); | 194 int32_t size = m_coefficients.GetSize(); |
| 206 CFX_Int32Array product; | 195 CFX_Int32Array product; |
| 207 product.SetSize(size + degree); | 196 product.SetSize(size + degree); |
| 208 for (int32_t i = 0; i < size; i++) { | 197 for (int32_t i = 0; i < size; i++) { |
| 209 product[i] = (m_field->Multiply(m_coefficients[i], coefficient)); | 198 product[i] = (m_field->Multiply(m_coefficients[i], coefficient)); |
| 210 } | 199 } |
| 211 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); | 200 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); |
| 212 temp->Init(m_field, &product, e); | 201 temp->Init(m_field, &product, e); |
| 213 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 202 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 214 return temp; | 203 return temp; |
| 215 } | 204 } |
| 216 | 205 |
| 217 CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* CBC_ReedSolomonGF256Poly::Divide( | 206 CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* CBC_ReedSolomonGF256Poly::Divide( |
| 218 CBC_ReedSolomonGF256Poly* other, | 207 CBC_ReedSolomonGF256Poly* other, |
| 219 int32_t& e) { | 208 int32_t& e) { |
| 220 if (other->IsZero()) { | 209 if (other->IsZero()) { |
| 221 e = BCExceptionDivideByZero; | 210 e = BCExceptionDivideByZero; |
| 222 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); | 211 return nullptr; |
| 223 } | 212 } |
| 224 std::unique_ptr<CBC_ReedSolomonGF256Poly> quotient( | 213 std::unique_ptr<CBC_ReedSolomonGF256Poly> quotient( |
| 225 m_field->GetZero()->Clone(e)); | 214 m_field->GetZero()->Clone(e)); |
| 226 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); | 215 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 227 std::unique_ptr<CBC_ReedSolomonGF256Poly> remainder(Clone(e)); | 216 std::unique_ptr<CBC_ReedSolomonGF256Poly> remainder(Clone(e)); |
| 228 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); | 217 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 229 int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree()); | 218 int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree()); |
| 230 int32_t inverseDenominatorLeadingTeam = | 219 int32_t inverseDenominatorLeadingTeam = |
| 231 m_field->Inverse(denominatorLeadingTerm, e); | 220 m_field->Inverse(denominatorLeadingTerm, e); |
| 232 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); | 221 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 249 CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* tempPtrA = | 238 CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* tempPtrA = |
| 250 new CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>(); | 239 new CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>(); |
| 251 tempPtrA->Add(quotient.release()); | 240 tempPtrA->Add(quotient.release()); |
| 252 tempPtrA->Add(remainder.release()); | 241 tempPtrA->Add(remainder.release()); |
| 253 return tempPtrA; | 242 return tempPtrA; |
| 254 } | 243 } |
| 255 | 244 |
| 256 CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() { | 245 CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() { |
| 257 m_coefficients.RemoveAll(); | 246 m_coefficients.RemoveAll(); |
| 258 } | 247 } |
| OLD | NEW |