Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(569)

Side by Side Diff: xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp

Issue 1937513002: Replace CFX_PtrArray with typesafe CFX_ArrayTemplate, part 8 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Flip if/else. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 if (noError) { 52 if (noError) {
53 return; 53 return;
54 } 54 }
55 CBC_ReedSolomonGF256Poly syndrome; 55 CBC_ReedSolomonGF256Poly syndrome;
56 syndrome.Init(m_field, &syndromeCoefficients, e); 56 syndrome.Init(m_field, &syndromeCoefficients, e);
57 BC_EXCEPTION_CHECK_ReturnVoid(e); 57 BC_EXCEPTION_CHECK_ReturnVoid(e);
58 std::unique_ptr<CBC_ReedSolomonGF256Poly> temp( 58 std::unique_ptr<CBC_ReedSolomonGF256Poly> temp(
59 m_field->BuildMonomial(twoS, 1, e)); 59 m_field->BuildMonomial(twoS, 1, e));
60 BC_EXCEPTION_CHECK_ReturnVoid(e); 60 BC_EXCEPTION_CHECK_ReturnVoid(e);
61 std::unique_ptr<CFX_PtrArray> sigmaOmega( 61 std::unique_ptr<CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>> sigmaOmega(
62 RunEuclideanAlgorithm(temp.get(), &syndrome, twoS, e)); 62 RunEuclideanAlgorithm(temp.get(), &syndrome, twoS, e));
63 BC_EXCEPTION_CHECK_ReturnVoid(e); 63 BC_EXCEPTION_CHECK_ReturnVoid(e);
64 std::unique_ptr<CBC_ReedSolomonGF256Poly> sigma( 64 std::unique_ptr<CBC_ReedSolomonGF256Poly> sigma((*sigmaOmega)[0]);
65 (CBC_ReedSolomonGF256Poly*)(*sigmaOmega)[0]); 65 std::unique_ptr<CBC_ReedSolomonGF256Poly> omega((*sigmaOmega)[1]);
66 std::unique_ptr<CBC_ReedSolomonGF256Poly> omega(
67 (CBC_ReedSolomonGF256Poly*)(*sigmaOmega)[1]);
68 std::unique_ptr<CFX_Int32Array> errorLocations( 66 std::unique_ptr<CFX_Int32Array> errorLocations(
69 FindErrorLocations(sigma.get(), e)); 67 FindErrorLocations(sigma.get(), e));
70 BC_EXCEPTION_CHECK_ReturnVoid(e); 68 BC_EXCEPTION_CHECK_ReturnVoid(e);
71 std::unique_ptr<CFX_Int32Array> errorMagnitudes( 69 std::unique_ptr<CFX_Int32Array> errorMagnitudes(
72 FindErrorMagnitudes(omega.get(), errorLocations.get(), dataMatrix, e)); 70 FindErrorMagnitudes(omega.get(), errorLocations.get(), dataMatrix, e));
73 BC_EXCEPTION_CHECK_ReturnVoid(e); 71 BC_EXCEPTION_CHECK_ReturnVoid(e);
74 for (int32_t k = 0; k < errorLocations->GetSize(); k++) { 72 for (int32_t k = 0; k < errorLocations->GetSize(); k++) {
75 int32_t position = 73 int32_t position =
76 received->GetSize() - 1 - m_field->Log((*errorLocations)[k], e); 74 received->GetSize() - 1 - m_field->Log((*errorLocations)[k], e);
77 BC_EXCEPTION_CHECK_ReturnVoid(e); 75 BC_EXCEPTION_CHECK_ReturnVoid(e);
78 if (position < 0) { 76 if (position < 0) {
79 e = BCExceptionBadErrorLocation; 77 e = BCExceptionBadErrorLocation;
80 BC_EXCEPTION_CHECK_ReturnVoid(e); 78 BC_EXCEPTION_CHECK_ReturnVoid(e);
81 } 79 }
82 (*received)[position] = CBC_ReedSolomonGF256::AddOrSubtract( 80 (*received)[position] = CBC_ReedSolomonGF256::AddOrSubtract(
83 (*received)[position], (*errorMagnitudes)[k]); 81 (*received)[position], (*errorMagnitudes)[k]);
84 } 82 }
85 } 83 }
86 CFX_PtrArray* CBC_ReedSolomonDecoder::RunEuclideanAlgorithm( 84
87 CBC_ReedSolomonGF256Poly* a, 85 CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>*
88 CBC_ReedSolomonGF256Poly* b, 86 CBC_ReedSolomonDecoder::RunEuclideanAlgorithm(CBC_ReedSolomonGF256Poly* a,
89 int32_t R, 87 CBC_ReedSolomonGF256Poly* b,
90 int32_t& e) { 88 int32_t R,
89 int32_t& e) {
91 if (a->GetDegree() < b->GetDegree()) { 90 if (a->GetDegree() < b->GetDegree()) {
92 CBC_ReedSolomonGF256Poly* temp = a; 91 CBC_ReedSolomonGF256Poly* temp = a;
93 a = b; 92 a = b;
94 b = temp; 93 b = temp;
95 } 94 }
96 std::unique_ptr<CBC_ReedSolomonGF256Poly> rLast(a->Clone(e)); 95 std::unique_ptr<CBC_ReedSolomonGF256Poly> rLast(a->Clone(e));
97 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 96 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
98 std::unique_ptr<CBC_ReedSolomonGF256Poly> r(b->Clone(e)); 97 std::unique_ptr<CBC_ReedSolomonGF256Poly> r(b->Clone(e));
99 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 98 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
100 std::unique_ptr<CBC_ReedSolomonGF256Poly> sLast(m_field->GetOne()->Clone(e)); 99 std::unique_ptr<CBC_ReedSolomonGF256Poly> sLast(m_field->GetOne()->Clone(e));
101 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 100 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
102 std::unique_ptr<CBC_ReedSolomonGF256Poly> s(m_field->GetZero()->Clone(e)); 101 std::unique_ptr<CBC_ReedSolomonGF256Poly> s(m_field->GetZero()->Clone(e));
103 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 102 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
104 std::unique_ptr<CBC_ReedSolomonGF256Poly> tLast(m_field->GetZero()->Clone(e)); 103 std::unique_ptr<CBC_ReedSolomonGF256Poly> tLast(m_field->GetZero()->Clone(e));
105 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 104 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
106 std::unique_ptr<CBC_ReedSolomonGF256Poly> t(m_field->GetOne()->Clone(e)); 105 std::unique_ptr<CBC_ReedSolomonGF256Poly> t(m_field->GetOne()->Clone(e));
107 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 106 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
108 while (r->GetDegree() >= R / 2) { 107 while (r->GetDegree() >= R / 2) {
109 std::unique_ptr<CBC_ReedSolomonGF256Poly> rLastLast = std::move(rLast); 108 std::unique_ptr<CBC_ReedSolomonGF256Poly> rLastLast = std::move(rLast);
110 std::unique_ptr<CBC_ReedSolomonGF256Poly> sLastLast = std::move(sLast); 109 std::unique_ptr<CBC_ReedSolomonGF256Poly> sLastLast = std::move(sLast);
111 std::unique_ptr<CBC_ReedSolomonGF256Poly> tLastlast = std::move(tLast); 110 std::unique_ptr<CBC_ReedSolomonGF256Poly> tLastlast = std::move(tLast);
112 rLast = std::move(r); 111 rLast = std::move(r);
113 sLast = std::move(s); 112 sLast = std::move(s);
114 tLast = std::move(t); 113 tLast = std::move(t);
115 if (rLast->IsZero()) { 114 if (rLast->IsZero()) {
116 e = BCExceptionR_I_1IsZero; 115 e = BCExceptionR_I_1IsZero;
117 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 116 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
118 } 117 }
119 r.reset(rLastLast->Clone(e)); 118 r.reset(rLastLast->Clone(e));
120 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 119 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
121 std::unique_ptr<CBC_ReedSolomonGF256Poly> q(m_field->GetZero()->Clone(e)); 120 std::unique_ptr<CBC_ReedSolomonGF256Poly> q(m_field->GetZero()->Clone(e));
122 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 121 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
123 int32_t denominatorLeadingTerm = rLast->GetCoefficients(rLast->GetDegree()); 122 int32_t denominatorLeadingTerm = rLast->GetCoefficients(rLast->GetDegree());
124 int32_t dltInverse = m_field->Inverse(denominatorLeadingTerm, e); 123 int32_t dltInverse = m_field->Inverse(denominatorLeadingTerm, e);
125 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 124 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
126 while (r->GetDegree() >= rLast->GetDegree() && !(r->IsZero())) { 125 while (r->GetDegree() >= rLast->GetDegree() && !(r->IsZero())) {
127 int32_t degreeDiff = r->GetDegree() - rLast->GetDegree(); 126 int32_t degreeDiff = r->GetDegree() - rLast->GetDegree();
128 int32_t scale = 127 int32_t scale =
129 m_field->Multiply(r->GetCoefficients(r->GetDegree()), dltInverse); 128 m_field->Multiply(r->GetCoefficients(r->GetDegree()), dltInverse);
130 std::unique_ptr<CBC_ReedSolomonGF256Poly> build( 129 std::unique_ptr<CBC_ReedSolomonGF256Poly> build(
131 m_field->BuildMonomial(degreeDiff, scale, e)); 130 m_field->BuildMonomial(degreeDiff, scale, e));
132 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 131 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
133 q.reset(q->AddOrSubtract(build.get(), e)); 132 q.reset(q->AddOrSubtract(build.get(), e));
134 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 133 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
135 std::unique_ptr<CBC_ReedSolomonGF256Poly> multiply( 134 std::unique_ptr<CBC_ReedSolomonGF256Poly> multiply(
136 rLast->MultiplyByMonomial(degreeDiff, scale, e)); 135 rLast->MultiplyByMonomial(degreeDiff, scale, e));
137 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 136 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
138 r.reset(r->AddOrSubtract(multiply.get(), e)); 137 r.reset(r->AddOrSubtract(multiply.get(), e));
139 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 138 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
140 } 139 }
141 std::unique_ptr<CBC_ReedSolomonGF256Poly> temp1( 140 std::unique_ptr<CBC_ReedSolomonGF256Poly> temp1(
142 q->Multiply(sLast.get(), e)); 141 q->Multiply(sLast.get(), e));
143 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 142 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
144 s.reset(temp1->AddOrSubtract(sLastLast.get(), e)); 143 s.reset(temp1->AddOrSubtract(sLastLast.get(), e));
145 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 144 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
146 std::unique_ptr<CBC_ReedSolomonGF256Poly> temp5( 145 std::unique_ptr<CBC_ReedSolomonGF256Poly> temp5(
147 q->Multiply(tLast.get(), e)); 146 q->Multiply(tLast.get(), e));
148 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 147 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
149 t.reset(temp5->AddOrSubtract(tLastlast.get(), e)); 148 t.reset(temp5->AddOrSubtract(tLastlast.get(), e));
150 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 149 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
151 } 150 }
152 int32_t sigmaTildeAtZero = t->GetCoefficients(0); 151 int32_t sigmaTildeAtZero = t->GetCoefficients(0);
153 if (sigmaTildeAtZero == 0) { 152 if (sigmaTildeAtZero == 0) {
154 e = BCExceptionIsZero; 153 e = BCExceptionIsZero;
155 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 154 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
156 } 155 }
157 int32_t inverse = m_field->Inverse(sigmaTildeAtZero, e); 156 int32_t inverse = m_field->Inverse(sigmaTildeAtZero, e);
158 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 157 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
159 std::unique_ptr<CBC_ReedSolomonGF256Poly> sigma(t->Multiply(inverse, e)); 158 std::unique_ptr<CBC_ReedSolomonGF256Poly> sigma(t->Multiply(inverse, e));
160 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 159 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
161 std::unique_ptr<CBC_ReedSolomonGF256Poly> omega(r->Multiply(inverse, e)); 160 std::unique_ptr<CBC_ReedSolomonGF256Poly> omega(r->Multiply(inverse, e));
162 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 161 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
163 CFX_PtrArray* temp = new CFX_PtrArray; 162 CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* temp =
163 new CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>();
164 temp->Add(sigma.release()); 164 temp->Add(sigma.release());
165 temp->Add(omega.release()); 165 temp->Add(omega.release());
166 return temp; 166 return temp;
167 } 167 }
168 CFX_Int32Array* CBC_ReedSolomonDecoder::FindErrorLocations( 168 CFX_Int32Array* CBC_ReedSolomonDecoder::FindErrorLocations(
169 CBC_ReedSolomonGF256Poly* errorLocator, 169 CBC_ReedSolomonGF256Poly* errorLocator,
170 int32_t& e) { 170 int32_t& e) {
171 int32_t numErrors = errorLocator->GetDegree(); 171 int32_t numErrors = errorLocator->GetDegree();
172 if (numErrors == 1) { 172 if (numErrors == 1) {
173 std::unique_ptr<CFX_Int32Array> temp(new CFX_Int32Array); 173 std::unique_ptr<CFX_Int32Array> temp(new CFX_Int32Array);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 xiInverse))); 212 xiInverse)));
213 } 213 }
214 } 214 }
215 int32_t temp = m_field->Inverse(denominator, temp); 215 int32_t temp = m_field->Inverse(denominator, temp);
216 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 216 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
217 (*result)[i] = 217 (*result)[i] =
218 m_field->Multiply(errorEvaluator->EvaluateAt(xiInverse), temp); 218 m_field->Multiply(errorEvaluator->EvaluateAt(xiInverse), temp);
219 } 219 }
220 return result.release(); 220 return result.release();
221 } 221 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.h ('k') | xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698