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 2007 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 "xfa/src/fxbarcode/qrcode/BC_QRCodeReader.h" | |
24 | |
25 #include <memory> | |
26 | |
27 #include "xfa/src/fxbarcode/BC_Binarizer.h" | |
28 #include "xfa/src/fxbarcode/BC_BinaryBitmap.h" | |
29 #include "xfa/src/fxbarcode/BC_BufferedImageLuminanceSource.h" | |
30 #include "xfa/src/fxbarcode/BC_LuminanceSource.h" | |
31 #include "xfa/src/fxbarcode/BC_Reader.h" | |
32 #include "xfa/src/fxbarcode/BC_ResultPoint.h" | |
33 #include "xfa/src/fxbarcode/common/BC_CommonDecoderResult.h" | |
34 #include "xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.h" | |
35 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" | |
36 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderDecoder.h" | |
37 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h" | |
38 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderMode.h" | |
39 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderVersion.h" | |
40 #include "xfa/src/fxbarcode/qrcode/BC_QRDataMask.h" | |
41 #include "xfa/src/fxbarcode/qrcode/BC_QRDetector.h" | |
42 #include "xfa/src/fxbarcode/qrcode/BC_QRDetectorResult.h" | |
43 | |
44 CBC_QRCodeReader::CBC_QRCodeReader() : m_decoder(NULL) {} | |
45 void CBC_QRCodeReader::Init() { | |
46 m_decoder = new CBC_QRCoderDecoder; | |
47 m_decoder->Init(); | |
48 } | |
49 CBC_QRCodeReader::~CBC_QRCodeReader() { | |
50 delete m_decoder; | |
51 } | |
52 CFX_ByteString CBC_QRCodeReader::Decode(CBC_BinaryBitmap* image, | |
53 int32_t hints, | |
54 int32_t& e) { | |
55 CBC_CommonBitMatrix* matrix = image->GetMatrix(e); | |
56 BC_EXCEPTION_CHECK_ReturnValue(e, ""); | |
57 CBC_QRDetector detector(matrix); | |
58 std::unique_ptr<CBC_QRDetectorResult> detectorResult( | |
59 detector.Detect(hints, e)); | |
60 BC_EXCEPTION_CHECK_ReturnValue(e, ""); | |
61 std::unique_ptr<CBC_CommonDecoderResult> decodeResult( | |
62 m_decoder->Decode(detectorResult->GetBits(), 0, e)); | |
63 BC_EXCEPTION_CHECK_ReturnValue(e, ""); | |
64 return (decodeResult->GetText()); | |
65 } | |
66 CFX_ByteString CBC_QRCodeReader::Decode(const CFX_WideString& filename, | |
67 int32_t hints, | |
68 int32_t byteModeDecode, | |
69 int32_t& e) { | |
70 CBC_BufferedImageLuminanceSource source(filename); | |
71 source.Init(e); | |
72 BC_EXCEPTION_CHECK_ReturnValue(e, ""); | |
73 CBC_GlobalHistogramBinarizer binarizer(&source); | |
74 CBC_BinaryBitmap bitmap(&binarizer); | |
75 CFX_ByteString bs = Decode(&bitmap, hints, e); | |
76 BC_EXCEPTION_CHECK_ReturnValue(e, ""); | |
77 return bs; | |
78 } | |
79 CFX_ByteString CBC_QRCodeReader::Decode(CFX_DIBitmap* pBitmap, | |
80 int32_t hints, | |
81 int32_t byteModeDecode, | |
82 int32_t& e) { | |
83 CBC_BufferedImageLuminanceSource source(pBitmap); | |
84 CBC_GlobalHistogramBinarizer binarizer(&source); | |
85 CBC_BinaryBitmap bitmap(&binarizer); | |
86 CFX_ByteString bs = Decode(&bitmap, hints, e); | |
87 BC_EXCEPTION_CHECK_ReturnValue(e, ""); | |
88 return bs; | |
89 } | |
90 CFX_ByteString CBC_QRCodeReader::Decode(CBC_BinaryBitmap* image, int32_t& e) { | |
91 CFX_ByteString bs = Decode(image, 0, e); | |
92 BC_EXCEPTION_CHECK_ReturnValue(e, ""); | |
93 return bs; | |
94 } | |
95 void CBC_QRCodeReader::ReleaseAll() { | |
96 if (CBC_ReedSolomonGF256::QRCodeFild) { | |
97 delete CBC_ReedSolomonGF256::QRCodeFild; | |
98 CBC_ReedSolomonGF256::QRCodeFild = NULL; | |
99 } | |
100 if (CBC_ReedSolomonGF256::DataMatrixField) { | |
101 delete CBC_ReedSolomonGF256::DataMatrixField; | |
102 CBC_ReedSolomonGF256::DataMatrixField = NULL; | |
103 } | |
104 CBC_QRCoderMode::Destroy(); | |
105 CBC_QRCoderErrorCorrectionLevel::Destroy(); | |
106 CBC_QRDataMask::Destroy(); | |
107 CBC_QRCoderVersion::Destroy(); | |
108 } | |
OLD | NEW |