From 6020e45b406e7a130024de87101b4493543f9deb Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 2 May 2016 13:47:17 -0700 Subject: Replace CFX_PtrArray with typesafe CFX_ArrayTemplate, part 11 Last part. Remove CFX_PtrArray typedef. Review-Url: https://codereview.chromium.org/1941863002 --- core/fxcrt/include/fx_basic.h | 1 - xfa/fxbarcode/pdf417/BC_PDF417BarcodeValue.h | 8 +- .../pdf417/BC_PDF417ECErrorCorrection.cpp | 15 +-- xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.h | 9 +- xfa/fxbarcode/pdf417/BC_PDF417Reader.cpp | 90 +++++++--------- xfa/fxbarcode/pdf417/BC_PDF417Reader.h | 6 +- xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.cpp | 95 +++++++--------- xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.h | 10 +- xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp | 120 +++++++++------------ xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h | 21 ++-- xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp | 23 ++-- xfa/fxbarcode/qrcode/BC_QRCoderVersion.h | 2 +- 12 files changed, 183 insertions(+), 217 deletions(-) diff --git a/core/fxcrt/include/fx_basic.h b/core/fxcrt/include/fx_basic.h index 5ec55062aa..7437d9567c 100644 --- a/core/fxcrt/include/fx_basic.h +++ b/core/fxcrt/include/fx_basic.h @@ -376,7 +376,6 @@ typedef CFX_ArrayTemplate CFX_WideStringCArray; typedef CFX_ArrayTemplate CFX_FloatArray; typedef CFX_ArrayTemplate CFX_ByteArray; typedef CFX_ArrayTemplate CFX_Int32Array; -typedef CFX_ArrayTemplate CFX_PtrArray; #endif // PDF_ENABLE_XFA #ifdef PDF_ENABLE_XFA diff --git a/xfa/fxbarcode/pdf417/BC_PDF417BarcodeValue.h b/xfa/fxbarcode/pdf417/BC_PDF417BarcodeValue.h index 29f0a833a9..0be71a1fb2 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417BarcodeValue.h +++ b/xfa/fxbarcode/pdf417/BC_PDF417BarcodeValue.h @@ -9,10 +9,11 @@ #include "core/fxcrt/include/fx_basic.h" -class CBC_BarcodeValue { +class CBC_BarcodeValue final { public: CBC_BarcodeValue(); - virtual ~CBC_BarcodeValue(); + ~CBC_BarcodeValue(); + void setValue(int32_t value); CFX_Int32Array* getValue(); int32_t getConfidence(int32_t value); @@ -22,4 +23,7 @@ class CBC_BarcodeValue { CFX_Int32Array m_values; }; +using CBC_BarcodeValueArray = CFX_ArrayTemplate; +using CBC_BarcodeValueArrayArray = CFX_ArrayTemplate; + #endif // XFA_FXBARCODE_PDF417_BC_PDF417BARCODEVALUE_H_ diff --git a/xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.cpp b/xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.cpp index 2c96f7005f..6a1f46fd02 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.cpp +++ b/xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.cpp @@ -65,7 +65,7 @@ int32_t CBC_PDF417ECErrorCorrection::decode(CFX_Int32Array& received, delete syndrome; return -1; } - CFX_PtrArray* sigmaOmega = + CFX_ArrayTemplate* sigmaOmega = runEuclideanAlgorithm(buildmonomial, syndrome, numECCodewords, e); delete buildmonomial; delete syndrome; @@ -123,11 +123,11 @@ int32_t CBC_PDF417ECErrorCorrection::decode(CFX_Int32Array& received, delete sigmaOmega; return result; } -CFX_PtrArray* CBC_PDF417ECErrorCorrection::runEuclideanAlgorithm( - CBC_PDF417ECModulusPoly* a, - CBC_PDF417ECModulusPoly* b, - int32_t R, - int32_t& e) { +CFX_ArrayTemplate* +CBC_PDF417ECErrorCorrection::runEuclideanAlgorithm(CBC_PDF417ECModulusPoly* a, + CBC_PDF417ECModulusPoly* b, + int32_t R, + int32_t& e) { if (a->getDegree() < b->getDegree()) { CBC_PDF417ECModulusPoly* temp = a; a = b; @@ -262,7 +262,8 @@ CFX_PtrArray* CBC_PDF417ECErrorCorrection::runEuclideanAlgorithm( CBC_PDF417ECModulusPoly* omega = r->multiply(inverse, e); delete rtemp; BC_EXCEPTION_CHECK_ReturnValue(e, NULL); - CFX_PtrArray* modulusPoly = new CFX_PtrArray; + CFX_ArrayTemplate* modulusPoly = + new CFX_ArrayTemplate(); modulusPoly->Add(sigma); modulusPoly->Add(omega); return modulusPoly; diff --git a/xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.h b/xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.h index d7b56defe9..95e691a60a 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.h +++ b/xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.h @@ -22,10 +22,11 @@ class CBC_PDF417ECErrorCorrection { private: static CBC_PDF417ECModulusGF* m_field; - static CFX_PtrArray* runEuclideanAlgorithm(CBC_PDF417ECModulusPoly* a, - CBC_PDF417ECModulusPoly* b, - int32_t R, - int32_t& e); + static CFX_ArrayTemplate* runEuclideanAlgorithm( + CBC_PDF417ECModulusPoly* a, + CBC_PDF417ECModulusPoly* b, + int32_t R, + int32_t& e); static CFX_Int32Array* findErrorLocations( CBC_PDF417ECModulusPoly* errorLocator, int32_t& e); diff --git a/xfa/fxbarcode/pdf417/BC_PDF417Reader.cpp b/xfa/fxbarcode/pdf417/BC_PDF417Reader.cpp index 4d953e006a..e68969ef30 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417Reader.cpp +++ b/xfa/fxbarcode/pdf417/BC_PDF417Reader.cpp @@ -20,7 +20,9 @@ * limitations under the License. */ +#include #include +#include #include "xfa/fxbarcode/BC_BinaryBitmap.h" #include "xfa/fxbarcode/BC_BinaryBitmap.h" @@ -64,27 +66,25 @@ CFX_ByteString CBC_PDF417Reader::Decode(CBC_BinaryBitmap* image, int32_t hints, int32_t& e) { CFX_ByteString results; - CBC_PDF417DetectorResult* detectorResult = - CBC_Detector::detect(image, hints, multiple, e); + std::unique_ptr detectorResult( + CBC_Detector::detect(image, hints, multiple, e)); BC_EXCEPTION_CHECK_ReturnValue(e, ""); for (int32_t i = 0; i < detectorResult->getPoints()->GetSize(); i++) { - CFX_PtrArray* points = (CFX_PtrArray*)detectorResult->getPoints()->GetAt(i); - CBC_CommonDecoderResult* ResultTemp = CBC_PDF417ScanningDecoder::decode( - detectorResult->getBits(), (CBC_ResultPoint*)points->GetAt(4), - (CBC_ResultPoint*)points->GetAt(5), (CBC_ResultPoint*)points->GetAt(6), - (CBC_ResultPoint*)points->GetAt(7), getMinCodewordWidth(*points), - getMaxCodewordWidth(*points), e); - if (ResultTemp == NULL) { - delete detectorResult; + CBC_ResultPointArray* points = detectorResult->getPoints()->GetAt(i); + std::unique_ptr ResultTemp( + CBC_PDF417ScanningDecoder::decode( + detectorResult->getBits(), points->GetAt(4), points->GetAt(5), + points->GetAt(6), points->GetAt(7), getMinCodewordWidth(*points), + getMaxCodewordWidth(*points), e)); + if (!ResultTemp) { e = BCExceptiontNotFoundInstance; - return ""; + return CFX_ByteString(); } results += ResultTemp->GetText(); - delete ResultTemp; } - delete detectorResult; return results; } + CFX_ByteString CBC_PDF417Reader::Decode(CBC_BinaryBitmap* image, int32_t hints, int32_t& e) { @@ -105,45 +105,29 @@ int32_t CBC_PDF417Reader::getMinWidth(CBC_ResultPoint* p1, return std::numeric_limits::max(); return (int32_t)FXSYS_fabs(p1->GetX() - p2->GetX()); } -int32_t CBC_PDF417Reader::getMaxCodewordWidth(CFX_PtrArray& p) { - int32_t a = - getMaxWidth((CBC_ResultPoint*)p.GetAt(6), (CBC_ResultPoint*)p.GetAt(2)) * - CBC_PDF417Common::MODULES_IN_CODEWORD / - CBC_PDF417Common::MODULES_IN_STOP_PATTERN; - int32_t b = - getMaxWidth((CBC_ResultPoint*)p.GetAt(7), (CBC_ResultPoint*)p.GetAt(3)) * - CBC_PDF417Common::MODULES_IN_CODEWORD / - CBC_PDF417Common::MODULES_IN_STOP_PATTERN; - int32_t c = getMaxWidth((CBC_ResultPoint*)p.GetAt(0), - (CBC_ResultPoint*)p.GetAt(4)) < a - ? getMaxWidth((CBC_ResultPoint*)p.GetAt(0), - (CBC_ResultPoint*)p.GetAt(4)) - : a; - int32_t d = getMaxWidth((CBC_ResultPoint*)p.GetAt(1), - (CBC_ResultPoint*)p.GetAt(5)) < b - ? getMaxWidth((CBC_ResultPoint*)p.GetAt(1), - (CBC_ResultPoint*)p.GetAt(5)) - : b; - return c < d ? c : d; + +int32_t CBC_PDF417Reader::getMaxCodewordWidth( + const CFX_ArrayTemplate& p) { + int32_t a = getMaxWidth(p.GetAt(6), p.GetAt(2)) * + CBC_PDF417Common::MODULES_IN_CODEWORD / + CBC_PDF417Common::MODULES_IN_STOP_PATTERN; + int32_t b = getMaxWidth(p.GetAt(7), p.GetAt(3)) * + CBC_PDF417Common::MODULES_IN_CODEWORD / + CBC_PDF417Common::MODULES_IN_STOP_PATTERN; + int32_t c = std::min(a, getMaxWidth(p.GetAt(0), p.GetAt(4))); + int32_t d = std::min(b, getMaxWidth(p.GetAt(1), p.GetAt(5))); + return std::min(c, d); } -int32_t CBC_PDF417Reader::getMinCodewordWidth(CFX_PtrArray& p) { - int32_t a = - getMinWidth((CBC_ResultPoint*)p.GetAt(6), (CBC_ResultPoint*)p.GetAt(2)) * - CBC_PDF417Common::MODULES_IN_CODEWORD / - CBC_PDF417Common::MODULES_IN_STOP_PATTERN; - int32_t b = - getMinWidth((CBC_ResultPoint*)p.GetAt(7), (CBC_ResultPoint*)p.GetAt(3)) * - CBC_PDF417Common::MODULES_IN_CODEWORD / - CBC_PDF417Common::MODULES_IN_STOP_PATTERN; - int32_t c = getMinWidth((CBC_ResultPoint*)p.GetAt(0), - (CBC_ResultPoint*)p.GetAt(4)) < a - ? getMinWidth((CBC_ResultPoint*)p.GetAt(0), - (CBC_ResultPoint*)p.GetAt(4)) - : a; - int32_t d = getMinWidth((CBC_ResultPoint*)p.GetAt(1), - (CBC_ResultPoint*)p.GetAt(5)) < b - ? getMinWidth((CBC_ResultPoint*)p.GetAt(1), - (CBC_ResultPoint*)p.GetAt(5)) - : b; - return c < d ? c : d; + +int32_t CBC_PDF417Reader::getMinCodewordWidth( + const CFX_ArrayTemplate& p) { + int32_t a = getMinWidth(p.GetAt(6), p.GetAt(2)) * + CBC_PDF417Common::MODULES_IN_CODEWORD / + CBC_PDF417Common::MODULES_IN_STOP_PATTERN; + int32_t b = getMinWidth(p.GetAt(7), p.GetAt(3)) * + CBC_PDF417Common::MODULES_IN_CODEWORD / + CBC_PDF417Common::MODULES_IN_STOP_PATTERN; + int32_t c = std::min(a, getMinWidth(p.GetAt(0), p.GetAt(4))); + int32_t d = std::min(b, getMinWidth(p.GetAt(1), p.GetAt(5))); + return std::min(c, d); } diff --git a/xfa/fxbarcode/pdf417/BC_PDF417Reader.h b/xfa/fxbarcode/pdf417/BC_PDF417Reader.h index 808de29014..73499b9cdf 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417Reader.h +++ b/xfa/fxbarcode/pdf417/BC_PDF417Reader.h @@ -28,8 +28,10 @@ class CBC_PDF417Reader : public CBC_Reader { private: static int32_t getMaxWidth(CBC_ResultPoint* p1, CBC_ResultPoint* p2); static int32_t getMinWidth(CBC_ResultPoint* p1, CBC_ResultPoint* p2); - static int32_t getMaxCodewordWidth(CFX_PtrArray& p); - static int32_t getMinCodewordWidth(CFX_PtrArray& p); + static int32_t getMaxCodewordWidth( + const CFX_ArrayTemplate& p); + static int32_t getMinCodewordWidth( + const CFX_ArrayTemplate& p); }; #endif // XFA_FXBARCODE_PDF417_BC_PDF417READER_H_ diff --git a/xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.cpp b/xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.cpp index e0eaf3e91f..4c3d4dbdf2 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.cpp +++ b/xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.cpp @@ -20,6 +20,8 @@ * limitations under the License. */ +#include + #include "xfa/fxbarcode/BC_DecoderResult.h" #include "xfa/fxbarcode/BC_ResultPoint.h" #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" @@ -155,16 +157,14 @@ CBC_CommonDecoderResult* CBC_PDF417ScanningDecoder::decode( } return decoderresult; } + CFX_ByteString CBC_PDF417ScanningDecoder::toString( - CFX_PtrArray* barcodeMatrix) { + CBC_BarcodeValueArrayArray* barcodeMatrix) { CFX_ByteString result; for (int32_t row = 0; row < barcodeMatrix->GetSize(); row++) { result += row; - int32_t l = 0; - for (; l < ((CFX_PtrArray*)barcodeMatrix->GetAt(row))->GetSize(); l++) { - CBC_BarcodeValue* barcodeValue = - (CBC_BarcodeValue*)((CFX_PtrArray*)barcodeMatrix->GetAt(row)) - ->GetAt(l); + for (int32_t l = 0; l < barcodeMatrix->GetAt(row)->GetSize(); l++) { + CBC_BarcodeValue* barcodeValue = barcodeMatrix->GetAt(row)->GetAt(l); if (barcodeValue->getValue()->GetSize() == 0) { result += ""; } else { @@ -176,6 +176,7 @@ CFX_ByteString CBC_PDF417ScanningDecoder::toString( } return result; } + CBC_DetectionResult* CBC_PDF417ScanningDecoder::merge( CBC_DetectionResultRowIndicatorColumn* leftRowIndicatorColumn, CBC_DetectionResultRowIndicatorColumn* rightRowIndicatorColumn, @@ -323,13 +324,13 @@ CBC_PDF417ScanningDecoder::getRowIndicatorColumn(CBC_CommonBitMatrix* image, } return rowIndicatorColumn; } + void CBC_PDF417ScanningDecoder::adjustCodewordCount( CBC_DetectionResult* detectionResult, - CFX_PtrArray* barcodeMatrix, + CBC_BarcodeValueArrayArray* barcodeMatrix, int32_t& e) { - CFX_Int32Array* numberOfCodewords = - ((CBC_BarcodeValue*)((CFX_PtrArray*)barcodeMatrix->GetAt(0))->GetAt(1)) - ->getValue(); + std::unique_ptr numberOfCodewords( + barcodeMatrix->GetAt(0)->GetAt(1)->getValue()); int32_t calculatedNumberOfCodewords = detectionResult->getBarcodeColumnCount() * detectionResult->getBarcodeRowCount() - @@ -339,47 +340,39 @@ void CBC_PDF417ScanningDecoder::adjustCodewordCount( calculatedNumberOfCodewords > CBC_PDF417Common::MAX_CODEWORDS_IN_BARCODE) { e = BCExceptiontNotFoundInstance; - delete numberOfCodewords; BC_EXCEPTION_CHECK_ReturnVoid(e); } - ((CBC_BarcodeValue*)((CFX_PtrArray*)barcodeMatrix->GetAt(0))->GetAt(1)) - ->setValue(calculatedNumberOfCodewords); + barcodeMatrix->GetAt(0)->GetAt(1)->setValue(calculatedNumberOfCodewords); } else if (numberOfCodewords->GetAt(0) != calculatedNumberOfCodewords) { - ((CBC_BarcodeValue*)((CFX_PtrArray*)barcodeMatrix->GetAt(0))->GetAt(1)) - ->setValue(calculatedNumberOfCodewords); + barcodeMatrix->GetAt(0)->GetAt(1)->setValue(calculatedNumberOfCodewords); } - delete numberOfCodewords; } + CBC_CommonDecoderResult* CBC_PDF417ScanningDecoder::createDecoderResult( CBC_DetectionResult* detectionResult, int32_t& e) { - CFX_PtrArray* barcodeMatrix = createBarcodeMatrix(detectionResult); - adjustCodewordCount(detectionResult, barcodeMatrix, e); + std::unique_ptr barcodeMatrix( + createBarcodeMatrix(detectionResult)); + adjustCodewordCount(detectionResult, barcodeMatrix.get(), e); if (e != BCExceptionNO) { for (int32_t i = 0; i < barcodeMatrix->GetSize(); i++) { - CFX_PtrArray* temp = (CFX_PtrArray*)barcodeMatrix->GetAt(i); - for (int32_t j = 0; j < temp->GetSize(); j++) { - delete (CBC_BarcodeValue*)temp->GetAt(j); - } - temp->RemoveAll(); + CBC_BarcodeValueArray* temp = barcodeMatrix->GetAt(i); + for (int32_t j = 0; j < temp->GetSize(); j++) + delete temp->GetAt(j); delete temp; } - barcodeMatrix->RemoveAll(); - delete barcodeMatrix; - return NULL; + return nullptr; } CFX_Int32Array erasures; CFX_Int32Array codewords; codewords.SetSize(detectionResult->getBarcodeRowCount() * detectionResult->getBarcodeColumnCount()); - CFX_PtrArray ambiguousIndexValuesList; + CFX_ArrayTemplate ambiguousIndexValuesList; CFX_Int32Array ambiguousIndexesList; for (int32_t row = 0; row < detectionResult->getBarcodeRowCount(); row++) { for (int32_t l = 0; l < detectionResult->getBarcodeColumnCount(); l++) { CFX_Int32Array* values = - ((CBC_BarcodeValue*)((CFX_PtrArray*)barcodeMatrix->GetAt(row)) - ->GetAt(l + 1)) - ->getValue(); + barcodeMatrix->GetAt(row)->GetAt(l + 1)->getValue(); int32_t codewordIndex = row * detectionResult->getBarcodeColumnCount() + l; if (values->GetSize() == 0) { @@ -392,35 +385,33 @@ CBC_CommonDecoderResult* CBC_PDF417ScanningDecoder::createDecoderResult( } } } - CFX_PtrArray ambiguousIndexValues; + CFX_ArrayTemplate ambiguousIndexValues; ambiguousIndexValues.SetSize(ambiguousIndexValuesList.GetSize()); for (int32_t i = 0; i < ambiguousIndexValues.GetSize(); i++) { ambiguousIndexValues.SetAt(i, ambiguousIndexValuesList.GetAt(i)); } for (int32_t l = 0; l < barcodeMatrix->GetSize(); l++) { - CFX_PtrArray* temp = (CFX_PtrArray*)barcodeMatrix->GetAt(l); - for (int32_t j = 0; j < temp->GetSize(); j++) { - delete (CBC_BarcodeValue*)temp->GetAt(j); - } + CBC_BarcodeValueArray* temp = barcodeMatrix->GetAt(l); + for (int32_t j = 0; j < temp->GetSize(); j++) + delete temp->GetAt(j); temp->RemoveAll(); delete temp; } - barcodeMatrix->RemoveAll(); - delete barcodeMatrix; CBC_CommonDecoderResult* decoderResult = createDecoderResultFromAmbiguousValues( detectionResult->getBarcodeECLevel(), codewords, erasures, ambiguousIndexesList, ambiguousIndexValues, e); - BC_EXCEPTION_CHECK_ReturnValue(e, NULL); + BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); return decoderResult; } + CBC_CommonDecoderResult* CBC_PDF417ScanningDecoder::createDecoderResultFromAmbiguousValues( int32_t ecLevel, CFX_Int32Array& codewords, CFX_Int32Array& erasureArray, CFX_Int32Array& ambiguousIndexes, - CFX_PtrArray& ambiguousIndexValues, + CFX_ArrayTemplate& ambiguousIndexValues, int32_t& e) { CFX_Int32Array ambiguousIndexCount; ambiguousIndexCount.SetSize(ambiguousIndexes.GetSize()); @@ -428,8 +419,7 @@ CBC_PDF417ScanningDecoder::createDecoderResultFromAmbiguousValues( while (tries-- > 0) { for (int32_t l = 0; l < ambiguousIndexCount.GetSize(); l++) { codewords[ambiguousIndexes[l]] = - ((CFX_Int32Array*)ambiguousIndexValues.GetAt(l)) - ->GetAt(ambiguousIndexCount[l]); + ambiguousIndexValues.GetAt(l)->GetAt(ambiguousIndexCount[l]); } CBC_CommonDecoderResult* decoderResult = decodeCodewords(codewords, ecLevel, erasureArray, e); @@ -445,7 +435,7 @@ CBC_PDF417ScanningDecoder::createDecoderResultFromAmbiguousValues( } for (int32_t i = 0; i < ambiguousIndexCount.GetSize(); i++) { if (ambiguousIndexCount[i] < - ((CFX_Int32Array*)(ambiguousIndexValues.GetAt(i)))->GetSize() - 1) { + ambiguousIndexValues.GetAt(i)->GetSize() - 1) { ambiguousIndexCount[i]++; break; } else { @@ -460,28 +450,24 @@ CBC_PDF417ScanningDecoder::createDecoderResultFromAmbiguousValues( e = BCExceptionChecksumInstance; return NULL; } -CFX_PtrArray* CBC_PDF417ScanningDecoder::createBarcodeMatrix( +CBC_BarcodeValueArrayArray* CBC_PDF417ScanningDecoder::createBarcodeMatrix( CBC_DetectionResult* detectionResult) { - CFX_PtrArray* barcodeMatrix = new CFX_PtrArray; + CBC_BarcodeValueArrayArray* barcodeMatrix = new CBC_BarcodeValueArrayArray; barcodeMatrix->SetSize(detectionResult->getBarcodeRowCount()); - CFX_PtrArray* temp = NULL; - int32_t colume = 0; for (int32_t row = 0; row < barcodeMatrix->GetSize(); row++) { - temp = new CFX_PtrArray; + CBC_BarcodeValueArray* temp = new CBC_BarcodeValueArray; temp->SetSize(detectionResult->getBarcodeColumnCount() + 2); - for (colume = 0; colume < detectionResult->getBarcodeColumnCount() + 2; - colume++) { - temp->SetAt(colume, new CBC_BarcodeValue()); + for (int32_t column = 0; + column < detectionResult->getBarcodeColumnCount() + 2; column++) { + temp->SetAt(column, new CBC_BarcodeValue()); } barcodeMatrix->SetAt(row, temp); } - colume = -1; for (int32_t i = 0; i < detectionResult->getDetectionResultColumns().GetSize(); i++) { CBC_DetectionResultColumn* detectionResultColumn = (CBC_DetectionResultColumn*)detectionResult->getDetectionResultColumns() .GetAt(i); - colume++; if (detectionResultColumn == NULL) { continue; } @@ -492,9 +478,8 @@ CFX_PtrArray* CBC_PDF417ScanningDecoder::createBarcodeMatrix( if (codeword == NULL || codeword->getRowNumber() == -1) { continue; } - ((CBC_BarcodeValue*)((CFX_PtrArray*)barcodeMatrix->GetAt( - codeword->getRowNumber())) - ->GetAt(colume)) + barcodeMatrix->GetAt(codeword->getRowNumber()) + ->GetAt(i) ->setValue(codeword->getValue()); } } diff --git a/xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.h b/xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.h index 6dbc125c31..aa99d5a0d4 100644 --- a/xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.h +++ b/xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.h @@ -7,6 +7,8 @@ #ifndef XFA_FXBARCODE_PDF417_BC_PDF417SCANNINGDECODER_H_ #define XFA_FXBARCODE_PDF417_BC_PDF417SCANNINGDECODER_H_ +#include "xfa/fxbarcode/pdf417/BC_PDF417BarcodeValue.h" + class CBC_CommonDecoderResult; class CBC_CommonBitMatrix; class CBC_Codeword; @@ -30,7 +32,7 @@ class CBC_PDF417ScanningDecoder { int32_t minCodewordWidth, int32_t maxCodewordWidth, int32_t& e); - static CFX_ByteString toString(CFX_PtrArray* barcodeMatrix); + static CFX_ByteString toString(CBC_BarcodeValueArrayArray* barcodeMatrix); private: static int32_t CODEWORD_SKEW_SIZE; @@ -56,7 +58,7 @@ class CBC_PDF417ScanningDecoder { int32_t minCodewordWidth, int32_t maxCodewordWidth); static void adjustCodewordCount(CBC_DetectionResult* detectionResult, - CFX_PtrArray* barcodeMatrix, + CBC_BarcodeValueArrayArray* barcodeMatrix, int32_t& e); static CBC_CommonDecoderResult* createDecoderResult( CBC_DetectionResult* detectionResult, @@ -66,9 +68,9 @@ class CBC_PDF417ScanningDecoder { CFX_Int32Array& codewords, CFX_Int32Array& erasureArray, CFX_Int32Array& ambiguousIndexes, - CFX_PtrArray& ambiguousIndexValues, + CFX_ArrayTemplate& ambiguousIndexValues, int32_t& e); - static CFX_PtrArray* createBarcodeMatrix( + static CBC_BarcodeValueArrayArray* createBarcodeMatrix( CBC_DetectionResult* detectionResult); static FX_BOOL isValidBarcodeColumn(CBC_DetectionResult* detectionResult, int32_t barcodeColumn); diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp index ded0df694b..eb7642649d 100644 --- a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp +++ b/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.cpp @@ -88,7 +88,7 @@ void CBC_QRCoderEncoder::Encode(const CFX_ByteString& content, } void CBC_QRCoderEncoder::AppendECI(CBC_QRCoderBitVector* bits) {} void CBC_QRCoderEncoder::AppendDataModeLenghInfo( - CFX_PtrArray& splitResult, + const CFX_ArrayTemplate& splitResult, CBC_QRCoderBitVector& headerAndDataBits, CBC_QRCoderMode* tempMode, CBC_QRCoder* qrCode, @@ -141,7 +141,7 @@ void CBC_QRCoderEncoder::AppendDataModeLenghInfo( } } void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, - CFX_PtrArray& result) { + CFX_ArrayTemplate* result) { int32_t index = 0, flag = 0; while ( (((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || @@ -150,7 +150,7 @@ void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, index += 2; } if (index != flag) { - result.Add( + result->Add( new Make_Pair(CBC_QRCoderMode::sGBK, content.Mid(flag, index - flag))); } flag = index; @@ -174,7 +174,7 @@ void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, } } if (index != flag) { - result.Add( + result->Add( new Make_Pair(CBC_QRCoderMode::sBYTE, content.Mid(flag, index - flag))); } flag = index; @@ -186,8 +186,8 @@ void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, index++; } if (index != flag) { - result.Add(new Make_Pair(CBC_QRCoderMode::sNUMERIC, - content.Mid(flag, index - flag))); + result->Add(new Make_Pair(CBC_QRCoderMode::sNUMERIC, + content.Mid(flag, index - flag))); } flag = index; if (index >= content.GetLength()) { @@ -198,15 +198,14 @@ void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, index++; } if (index != flag) { - result.Add(new Make_Pair(CBC_QRCoderMode::sALPHANUMERIC, - content.Mid(flag, index - flag))); + result->Add(new Make_Pair(CBC_QRCoderMode::sALPHANUMERIC, + content.Mid(flag, index - flag))); } flag = index; - if (index >= content.GetLength()) { - return; - } - SplitString(content.Mid(index, content.GetLength() - index), result); + if (index < content.GetLength()) + SplitString(content.Mid(index, content.GetLength() - index), result); } + int32_t CBC_QRCoderEncoder::GetSpanByVersion(CBC_QRCoderMode* modeFirst, CBC_QRCoderMode* modeSecond, int32_t versionNum, @@ -253,16 +252,17 @@ int32_t CBC_QRCoderEncoder::GetSpanByVersion(CBC_QRCoderMode* modeFirst, } return -1; } -void CBC_QRCoderEncoder::MergeString(CFX_PtrArray& result, + +void CBC_QRCoderEncoder::MergeString(CFX_ArrayTemplate* result, int32_t versionNum, int32_t& e) { Make_Pair* first = NULL; Make_Pair* second = NULL; size_t mergeNum = 0; int32_t i; - for (i = 0; ((i < result.GetSize()) && (i + 1 < result.GetSize())); i++) { - first = (Make_Pair*)result[i]; - second = (Make_Pair*)result[i + 1]; + for (i = 0; ((i < result->GetSize()) && (i + 1 < result->GetSize())); i++) { + first = (*result)[i]; + second = (*result)[i + 1]; if (first->m_mode == CBC_QRCoderMode::sALPHANUMERIC) { int32_t tmp = GetSpanByVersion(CBC_QRCoderMode::sALPHANUMERIC, CBC_QRCoderMode::sBYTE, versionNum, e); @@ -272,7 +272,7 @@ void CBC_QRCoderEncoder::MergeString(CFX_PtrArray& result, CFX_ByteString str = first->m_string + second->m_string; second->m_string = str; delete first; - result.RemoveAt(i); + result->RemoveAt(i); i--; mergeNum++; } @@ -280,7 +280,7 @@ void CBC_QRCoderEncoder::MergeString(CFX_PtrArray& result, if (second->m_mode == CBC_QRCoderMode::sBYTE) { first->m_string += second->m_string; delete second; - result.RemoveAt(i + 1); + result->RemoveAt(i + 1); i--; mergeNum++; } @@ -293,7 +293,7 @@ void CBC_QRCoderEncoder::MergeString(CFX_PtrArray& result, CFX_ByteString str = first->m_string + second->m_string; second->m_string = str; delete first; - result.RemoveAt(i); + result->RemoveAt(i); i--; mergeNum++; } @@ -305,7 +305,7 @@ void CBC_QRCoderEncoder::MergeString(CFX_PtrArray& result, CFX_ByteString str = first->m_string + second->m_string; second->m_string = str; delete first; - result.RemoveAt(i); + result->RemoveAt(i); i--; mergeNum++; } @@ -353,20 +353,18 @@ void CBC_QRCoderEncoder::EncodeWithSpecifyVersion( int32_t& e) { CFX_ByteString encoding = "utf8"; CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; - CFX_PtrArray splitResult; + CFX_ArrayTemplate splitResult; CBC_QRCoderBitVector dataBits; dataBits.Init(); - SplitString(content, splitResult); - MergeString(splitResult, versionSpecify, e); + SplitString(content, &splitResult); + MergeString(&splitResult, versionSpecify, e); BC_EXCEPTION_CHECK_ReturnVoid(e) CBC_QRCoderMode* tempMode = NULL; for (int32_t i = 0; i < splitResult.GetSize(); i++) { - AppendBytes(((Make_Pair*)splitResult[i])->m_string, - ((Make_Pair*)splitResult[i])->m_mode, &dataBits, encoding, e); + AppendBytes(splitResult[i]->m_string, splitResult[i]->m_mode, &dataBits, + encoding, e); if (e != BCExceptionNO) { - for (int32_t y = 0; y < splitResult.GetSize(); y++) { - delete (Make_Pair*)splitResult[y]; - } - splitResult.RemoveAll(); + for (int32_t y = 0; y < splitResult.GetSize(); y++) + delete splitResult[y]; return; } } @@ -375,34 +373,25 @@ void CBC_QRCoderEncoder::EncodeWithSpecifyVersion( headerAndDataBits.Init(); InitQRCode(numInputBytes, versionSpecify, ecLevel, mode, qrCode, e); if (e != BCExceptionNO) { - for (int32_t k = 0; k < splitResult.GetSize(); k++) { - delete (Make_Pair*)splitResult[k]; - } - splitResult.RemoveAll(); + for (int32_t k = 0; k < splitResult.GetSize(); k++) + delete splitResult[k]; return; } AppendDataModeLenghInfo(splitResult, headerAndDataBits, tempMode, qrCode, encoding, e); if (e != BCExceptionNO) { - for (int32_t k = 0; k < splitResult.GetSize(); k++) { - delete (Make_Pair*)splitResult[k]; - } - splitResult.RemoveAll(); + for (int32_t k = 0; k < splitResult.GetSize(); k++) + delete splitResult[k]; return; } numInputBytes = headerAndDataBits.sizeInBytes(); TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits, e); - if (e != BCExceptionNO) { - for (int32_t k = 0; k < splitResult.GetSize(); k++) { - delete (Make_Pair*)splitResult[k]; - } - splitResult.RemoveAll(); - return; - } for (int32_t j = 0; j < splitResult.GetSize(); j++) { - delete (Make_Pair*)splitResult[j]; + delete splitResult[j]; } - splitResult.RemoveAll(); + if (e != BCExceptionNO) + return; + CBC_QRCoderBitVector finalBits; finalBits.Init(); InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), @@ -433,21 +422,19 @@ void CBC_QRCoderEncoder::EncodeWithAutoVersion( int32_t& e) { CFX_ByteString encoding = "utf8"; CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; - CFX_PtrArray splitResult; + CFX_ArrayTemplate splitResult; CBC_QRCoderBitVector dataBits; dataBits.Init(); - SplitString(content, splitResult); - MergeString(splitResult, 8, e); + SplitString(content, &splitResult); + MergeString(&splitResult, 8, e); BC_EXCEPTION_CHECK_ReturnVoid(e); CBC_QRCoderMode* tempMode = NULL; for (int32_t i = 0; i < splitResult.GetSize(); i++) { - AppendBytes(((Make_Pair*)splitResult[i])->m_string, - ((Make_Pair*)splitResult[i])->m_mode, &dataBits, encoding, e); + AppendBytes(splitResult[i]->m_string, splitResult[i]->m_mode, &dataBits, + encoding, e); if (e != BCExceptionNO) { - for (int32_t l = 0; l < splitResult.GetSize(); l++) { - delete (Make_Pair*)splitResult[l]; - } - splitResult.RemoveAll(); + for (int32_t l = 0; l < splitResult.GetSize(); l++) + delete splitResult[l]; return; } } @@ -482,17 +469,14 @@ catchException: e = BCExceptionNO; goto sign; } else { - for (int32_t j = 0; j < splitResult.GetSize(); j++) { - delete (Make_Pair*)splitResult[j]; - } - splitResult.RemoveAll(); + for (int32_t j = 0; j < splitResult.GetSize(); j++) + delete splitResult[j]; return; } } - for (int32_t k = 0; k < splitResult.GetSize(); k++) { - delete (Make_Pair*)splitResult[k]; - } - splitResult.RemoveAll(); + for (int32_t k = 0; k < splitResult.GetSize(); k++) + delete splitResult[k]; + CBC_QRCoderBitVector finalBits; finalBits.Init(); InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), @@ -863,7 +847,7 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits, int32_t dataBytesOffset = 0; int32_t maxNumDataBytes = 0; int32_t maxNumEcBytes = 0; - CFX_PtrArray blocks; + CFX_ArrayTemplate blocks; int32_t i; for (i = 0; i < numRSBlocks; i++) { int32_t numDataBytesInBlock; @@ -887,8 +871,7 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits, } for (int32_t x = 0; x < maxNumDataBytes; x++) { for (int32_t j = 0; j < blocks.GetSize(); j++) { - CBC_CommonByteArray* dataBytes = - ((CBC_QRCoderBlockPair*)blocks[j])->GetDataBytes(); + CBC_CommonByteArray* dataBytes = blocks[j]->GetDataBytes(); if (x < dataBytes->Size()) { result->AppendBits(dataBytes->At(x), 8, e); BC_EXCEPTION_CHECK_ReturnVoid(e); @@ -897,8 +880,7 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits, } for (int32_t y = 0; y < maxNumEcBytes; y++) { for (int32_t l = 0; l < blocks.GetSize(); l++) { - CBC_CommonByteArray* ecBytes = - ((CBC_QRCoderBlockPair*)blocks[l])->GetErrorCorrectionBytes(); + CBC_CommonByteArray* ecBytes = blocks[l]->GetErrorCorrectionBytes(); if (y < ecBytes->Size()) { result->AppendBits(ecBytes->At(y), 8, e); BC_EXCEPTION_CHECK_ReturnVoid(e); @@ -906,7 +888,7 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits, } } for (int32_t k = 0; k < blocks.GetSize(); k++) { - delete (CBC_QRCoderBlockPair*)blocks[k]; + delete blocks[k]; } if (numTotalBytes != result->sizeInBytes()) { e = BCExceptionSizeInBytesDiffer; diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h b/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h index bbdec5bf1e..be0a76c337 100644 --- a/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h +++ b/xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h @@ -16,6 +16,7 @@ class CBC_QRCoderMode; class CBC_QRCoderBitVector; class CBC_CommonByteArray; class CBC_CommonByteMatrix; +class Make_Pair; class CBC_QRCoderEncoder { private: @@ -120,14 +121,18 @@ class CBC_QRCoderEncoder { CBC_QRCoderMode* modeSecond, int32_t versionNum, int32_t& e); - static void MergeString(CFX_PtrArray& result, int32_t versionNum, int32_t& e); - static void SplitString(const CFX_ByteString& content, CFX_PtrArray& result); - static void AppendDataModeLenghInfo(CFX_PtrArray& splitResult, - CBC_QRCoderBitVector& headerAndDataBits, - CBC_QRCoderMode* tempMode, - CBC_QRCoder* qrCode, - CFX_ByteString& encoding, - int32_t& e); + static void MergeString(CFX_ArrayTemplate* result, + int32_t versionNum, + int32_t& e); + static void SplitString(const CFX_ByteString& content, + CFX_ArrayTemplate* result); + static void AppendDataModeLenghInfo( + const CFX_ArrayTemplate& splitResult, + CBC_QRCoderBitVector& headerAndDataBits, + CBC_QRCoderMode* tempMode, + CBC_QRCoder* qrCode, + CFX_ByteString& encoding, + int32_t& e); }; #endif // XFA_FXBARCODE_QRCODE_BC_QRCODERENCODER_H_ diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp index e92267819c..9c3a1cc138 100644 --- a/xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp +++ b/xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp @@ -35,17 +35,18 @@ const int32_t CBC_QRCoderVersion::VERSION_DECODE_INFO[] = { 0x15683, 0x168C9, 0x177EC, 0x18EC4, 0x191E1, 0x1AFAB, 0x1B08E, 0x1CC1A, 0x1D33F, 0x1ED75, 0x1F250, 0x209D5, 0x216F0, 0x228BA, 0x2379F, 0x24B0B, 0x2542E, 0x26A64, 0x27541, 0x28C69}; -CFX_PtrArray* CBC_QRCoderVersion::VERSION = NULL; + +CFX_ArrayTemplate* CBC_QRCoderVersion::VERSION = nullptr; void CBC_QRCoderVersion::Initialize() { - VERSION = new CFX_PtrArray(); + VERSION = new CFX_ArrayTemplate(); } void CBC_QRCoderVersion::Finalize() { - for (int32_t i = 0; i < VERSION->GetSize(); i++) { - CBC_QRCoderVersion* v = (CBC_QRCoderVersion*)(VERSION->GetAt(i)); - delete v; - } + for (int32_t i = 0; i < VERSION->GetSize(); i++) + delete VERSION->GetAt(i); + delete VERSION; + VERSION = nullptr; } CBC_QRCoderVersion::CBC_QRCoderVersion(int32_t versionNumber, CBC_QRCoderECBlocks* ecBlocks1, @@ -755,11 +756,11 @@ CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber( e = BCExceptionIllegalArgument; BC_EXCEPTION_CHECK_ReturnValue(e, NULL); } - return (CBC_QRCoderVersion*)(*VERSION)[versionNumber - 1]; + return (*VERSION)[versionNumber - 1]; } + void CBC_QRCoderVersion::Destroy() { - int32_t i; - for (i = 0; i < VERSION->GetSize(); i++) { - delete ((CBC_QRCoderVersion*)(*VERSION)[i]); - } + for (int32_t i = 0; i < VERSION->GetSize(); i++) + delete (*VERSION)[i]; + VERSION->RemoveAll(); } diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderVersion.h b/xfa/fxbarcode/qrcode/BC_QRCoderVersion.h index 05bd71934d..deae8933e6 100644 --- a/xfa/fxbarcode/qrcode/BC_QRCoderVersion.h +++ b/xfa/fxbarcode/qrcode/BC_QRCoderVersion.h @@ -44,7 +44,7 @@ class CBC_QRCoderVersion { CBC_QRCoderECBlocks* ecBlocks4); static const int32_t VERSION_DECODE_INFO[34]; - static CFX_PtrArray* VERSION; + static CFX_ArrayTemplate* VERSION; int32_t m_versionNumber; int32_t m_totalCodeWords; -- cgit v1.2.3