| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 // Original code is licensed as follows: | |
| 7 /* | |
| 8 * Copyright 2009 ZXing authors | |
| 9 * | |
| 10 * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 11 * you may not use this file except in compliance with the License. | |
| 12 * You may obtain a copy of the License at | |
| 13 * | |
| 14 * http://www.apache.org/licenses/LICENSE-2.0 | |
| 15 * | |
| 16 * Unless required by applicable law or agreed to in writing, software | |
| 17 * distributed under the License is distributed on an "AS IS" BASIS, | |
| 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 19 * See the License for the specific language governing permissions and | |
| 20 * limitations under the License. | |
| 21 */ | |
| 22 | |
| 23 #include "barcode.h" | |
| 24 #include "include/BC_Reader.h" | |
| 25 #include "include/BC_BinaryBitmap.h" | |
| 26 #include "include/BC_ResultPoint.h" | |
| 27 #include "include/BC_PDF417DetectorResult.h" | |
| 28 #include "include/BC_BinaryBitmap.h" | |
| 29 #include "include/BC_CommonBitMatrix.h" | |
| 30 #include "include/BC_CommonBitArray.h" | |
| 31 #include "include/BC_PDF417Detector.h" | |
| 32 #include "include/BC_PDF417DetectorResult.h" | |
| 33 #include "include/BC_DecoderResult.h" | |
| 34 #include "include/BC_PDF417Codeword.h" | |
| 35 #include "include/BC_CommonBitMatrix.h" | |
| 36 #include "include/BC_PDF417Common.h" | |
| 37 #include "include/BC_PDF417BarcodeValue.h" | |
| 38 #include "include/BC_PDF417BarcodeMetadata.h" | |
| 39 #include "include/BC_PDF417BoundingBox.h" | |
| 40 #include "include/BC_PDF417DetectionResultColumn.h" | |
| 41 #include "include/BC_PDF417DetectionResultRowIndicatorColumn.h" | |
| 42 #include "include/BC_PDF417DetectionResult.h" | |
| 43 #include "include/BC_PDF417DecodedBitStreamParser.h" | |
| 44 #include "include/BC_PDF417CodewordDecoder.h" | |
| 45 #include "include/BC_PDF417DecodedBitStreamParser.h" | |
| 46 #include "include/BC_PDF417ECModulusPoly.h" | |
| 47 #include "include/BC_PDF417ECModulusGF.h" | |
| 48 #include "include/BC_PDF417ECErrorCorrection.h" | |
| 49 #include "include/BC_PDF417DecodedBitStreamParser.h" | |
| 50 #include "include/BC_CommonDecoderResult.h" | |
| 51 #include "include/BC_PDF417ScanningDecoder.h" | |
| 52 #include "include/BC_PDF417Reader.h" | |
| 53 #define Integer_MAX_VALUE 2147483647 | |
| 54 CBC_PDF417Reader::CBC_PDF417Reader() | |
| 55 { | |
| 56 } | |
| 57 CBC_PDF417Reader::~CBC_PDF417Reader() | |
| 58 { | |
| 59 } | |
| 60 CFX_ByteString CBC_PDF417Reader::Decode(CBC_BinaryBitmap *image, FX_INT32 &e) | |
| 61 { | |
| 62 return Decode(image, 0, e); | |
| 63 } | |
| 64 CFX_ByteString CBC_PDF417Reader::Decode(CBC_BinaryBitmap *image, FX_BOOL multipl
e, FX_INT32 hints, FX_INT32 &e) | |
| 65 { | |
| 66 CFX_ByteString results; | |
| 67 CBC_PDF417DetectorResult* detectorResult = CBC_Detector::detect(image, hints
, multiple, e); | |
| 68 BC_EXCEPTION_CHECK_ReturnValue(e, ""); | |
| 69 for (FX_INT32 i = 0; i < detectorResult->getPoints()->GetSize(); i++) { | |
| 70 CFX_PtrArray* points = (CFX_PtrArray*)detectorResult->getPoints()->GetAt
(i); | |
| 71 CBC_CommonDecoderResult* ResultTemp = CBC_PDF417ScanningDecoder::decode(
detectorResult->getBits(), (CBC_ResultPoint*)points->GetAt(4), (CBC_ResultPoint*
)points->GetAt(5), | |
| 72 (CBC_ResultPoint*)points->GetAt(6)
, (CBC_ResultPoint*)points->GetAt(7), getMinCodewordWidth(*points), getMaxCodewo
rdWidth(*points), e); | |
| 73 if (ResultTemp == NULL) { | |
| 74 delete detectorResult; | |
| 75 e = BCExceptiontNotFoundInstance; | |
| 76 return ""; | |
| 77 } | |
| 78 results += ResultTemp->GetText(); | |
| 79 delete ResultTemp; | |
| 80 } | |
| 81 delete detectorResult; | |
| 82 return results; | |
| 83 } | |
| 84 CFX_ByteString CBC_PDF417Reader::Decode(CBC_BinaryBitmap *image, FX_INT32 hints,
FX_INT32 &e) | |
| 85 { | |
| 86 CFX_ByteString bs = Decode(image, FALSE, 0, e); | |
| 87 BC_EXCEPTION_CHECK_ReturnValue(e, ""); | |
| 88 return bs; | |
| 89 } | |
| 90 FX_INT32 CBC_PDF417Reader::getMaxWidth(CBC_ResultPoint* p1, CBC_ResultPoint* p2) | |
| 91 { | |
| 92 if (p1 == NULL || p2 == NULL) { | |
| 93 return 0; | |
| 94 } | |
| 95 return (FX_INT32) FXSYS_fabs(p1->GetX() - p2->GetX()); | |
| 96 } | |
| 97 FX_INT32 CBC_PDF417Reader::getMinWidth(CBC_ResultPoint* p1, CBC_ResultPoint* p2) | |
| 98 { | |
| 99 if (p1 == NULL || p2 == NULL) { | |
| 100 return Integer_MAX_VALUE; | |
| 101 } | |
| 102 return (FX_INT32) FXSYS_fabs(p1->GetX() - p2->GetX()); | |
| 103 } | |
| 104 FX_INT32 CBC_PDF417Reader::getMaxCodewordWidth(CFX_PtrArray& p) | |
| 105 { | |
| 106 FX_INT32 a = getMaxWidth((CBC_ResultPoint*)p.GetAt(6), (CBC_ResultPoint*)p.G
etAt(2)) * CBC_PDF417Common::MODULES_IN_CODEWORD / CBC_PDF417Common::MODULES_IN_
STOP_PATTERN; | |
| 107 FX_INT32 b = getMaxWidth((CBC_ResultPoint*)p.GetAt(7), (CBC_ResultPoint*)p.G
etAt(3)) * CBC_PDF417Common::MODULES_IN_CODEWORD / CBC_PDF417Common::MODULES_IN_
STOP_PATTERN; | |
| 108 FX_INT32 c = getMaxWidth((CBC_ResultPoint*)p.GetAt(0), (CBC_ResultPoint*)p.G
etAt(4)) < a ? getMaxWidth((CBC_ResultPoint*)p.GetAt(0), (CBC_ResultPoint*)p.Get
At(4)) : a; | |
| 109 FX_INT32 d = getMaxWidth((CBC_ResultPoint*)p.GetAt(1), (CBC_ResultPoint*)p.G
etAt(5)) < b ? getMaxWidth((CBC_ResultPoint*)p.GetAt(1), (CBC_ResultPoint*)p.Get
At(5)) : b; | |
| 110 return c < d ? c : d; | |
| 111 } | |
| 112 FX_INT32 CBC_PDF417Reader::getMinCodewordWidth(CFX_PtrArray& p) | |
| 113 { | |
| 114 FX_INT32 a = getMinWidth((CBC_ResultPoint*)p.GetAt(6), (CBC_ResultPoint*)p.G
etAt(2)) * CBC_PDF417Common::MODULES_IN_CODEWORD / CBC_PDF417Common::MODULES_IN_
STOP_PATTERN; | |
| 115 FX_INT32 b = getMinWidth((CBC_ResultPoint*)p.GetAt(7), (CBC_ResultPoint*)p.G
etAt(3)) * CBC_PDF417Common::MODULES_IN_CODEWORD / CBC_PDF417Common::MODULES_IN_
STOP_PATTERN; | |
| 116 FX_INT32 c = getMinWidth((CBC_ResultPoint*)p.GetAt(0), (CBC_ResultPoint*)p.G
etAt(4)) < a ? getMinWidth((CBC_ResultPoint*)p.GetAt(0), (CBC_ResultPoint*)p.Get
At(4)) : a; | |
| 117 FX_INT32 d = getMinWidth((CBC_ResultPoint*)p.GetAt(1), (CBC_ResultPoint*)p.G
etAt(5)) < b ? getMinWidth((CBC_ResultPoint*)p.GetAt(1), (CBC_ResultPoint*)p.Get
At(5)) : b; | |
| 118 return c < d ? c : d; | |
| 119 } | |
| OLD | NEW |