OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 /* | 6 /* |
7 * Copyright 2011 ZXing authors | 7 * Copyright 2011 ZXing authors |
8 * | 8 * |
9 * Licensed under the Apache License, Version 2.0 (the "License"); | 9 * Licensed under the Apache License, Version 2.0 (the "License"); |
10 * you may not use this file except in compliance with the License. | 10 * you may not use this file except in compliance with the License. |
11 * You may obtain a copy of the License at | 11 * You may obtain a copy of the License at |
12 * | 12 * |
13 * http://www.apache.org/licenses/LICENSE-2.0 | 13 * http://www.apache.org/licenses/LICENSE-2.0 |
14 * | 14 * |
15 * Unless required by applicable law or agreed to in writing, software | 15 * Unless required by applicable law or agreed to in writing, software |
16 * distributed under the License is distributed on an "AS IS" BASIS, | 16 * distributed under the License is distributed on an "AS IS" BASIS, |
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 * See the License for the specific language governing permissions and | 18 * See the License for the specific language governing permissions and |
19 * limitations under the License. | 19 * limitations under the License. |
20 */ | 20 */ |
21 | 21 |
22 #include "xfa/fxbarcode/cbc_qrcode.h" | 22 #include "xfa/fxbarcode/cbc_qrcode.h" |
23 | 23 |
24 #include "xfa/fxbarcode/BC_BinaryBitmap.h" | 24 #include "xfa/fxbarcode/BC_BinaryBitmap.h" |
25 #include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" | 25 #include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" |
26 #include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" | 26 #include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" |
27 #include "xfa/fxbarcode/qrcode/BC_QRCodeReader.h" | 27 #include "xfa/fxbarcode/qrcode/BC_QRCodeReader.h" |
28 #include "xfa/fxbarcode/qrcode/BC_QRCodeWriter.h" | 28 #include "xfa/fxbarcode/qrcode/BC_QRCodeWriter.h" |
29 | 29 |
30 CBC_QRCode::CBC_QRCode() { | 30 CBC_QRCode::CBC_QRCode() |
31 m_pBCReader = (CBC_Reader*)new (CBC_QRCodeReader); | 31 : CBC_CodeBase(new CBC_QRCodeReader, new CBC_QRCodeWriter) { |
32 ((CBC_QRCodeReader*)m_pBCReader)->Init(); | 32 static_cast<CBC_QRCodeReader*>(m_pBCReader.get())->Init(); |
33 m_pBCWriter = (CBC_Writer*)new (CBC_QRCodeWriter); | |
34 } | 33 } |
35 | 34 |
36 CBC_QRCode::~CBC_QRCode() { | 35 CBC_QRCode::~CBC_QRCode() {} |
37 delete (m_pBCReader); | |
38 delete (m_pBCWriter); | |
39 } | |
40 | 36 |
41 FX_BOOL CBC_QRCode::SetVersion(int32_t version) { | 37 FX_BOOL CBC_QRCode::SetVersion(int32_t version) { |
42 if (version < 0 || version > 40) | 38 if (version < 0 || version > 40) |
43 return FALSE; | 39 return FALSE; |
44 if (!m_pBCWriter) | 40 return m_pBCWriter && |
45 return FALSE; | 41 static_cast<CBC_QRCodeWriter*>(m_pBCWriter.get())->SetVersion(version); |
46 return ((CBC_QRCodeWriter*)m_pBCWriter)->SetVersion(version); | |
47 } | 42 } |
48 | 43 |
49 FX_BOOL CBC_QRCode::SetErrorCorrectionLevel(int32_t level) { | 44 FX_BOOL CBC_QRCode::SetErrorCorrectionLevel(int32_t level) { |
50 if (level < 0 || level > 3) | 45 if (level < 0 || level > 3) |
51 return FALSE; | 46 return FALSE; |
52 if (!m_pBCWriter) | 47 |
53 return FALSE; | 48 return m_pBCWriter && |
54 return ((CBC_TwoDimWriter*)m_pBCWriter)->SetErrorCorrectionLevel(level); | 49 static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) |
| 50 ->SetErrorCorrectionLevel(level); |
55 } | 51 } |
56 | 52 |
57 FX_BOOL CBC_QRCode::Encode(const CFX_WideStringC& contents, | 53 FX_BOOL CBC_QRCode::Encode(const CFX_WideStringC& contents, |
58 FX_BOOL isDevice, | 54 FX_BOOL isDevice, |
59 int32_t& e) { | 55 int32_t& e) { |
60 int32_t outWidth = 0; | 56 int32_t outWidth = 0; |
61 int32_t outHeight = 0; | 57 int32_t outHeight = 0; |
62 uint8_t* data = | 58 CBC_QRCodeWriter* pWriter = static_cast<CBC_QRCodeWriter*>(m_pBCWriter.get()); |
63 ((CBC_QRCodeWriter*)m_pBCWriter) | 59 uint8_t* data = pWriter->Encode(CFX_WideString(contents), |
64 ->Encode(CFX_WideString(contents), | 60 pWriter->GetErrorCorrectionLevel(), outWidth, |
65 ((CBC_QRCodeWriter*)m_pBCWriter)->GetErrorCorrectionLevel(), | 61 outHeight, e); |
66 outWidth, outHeight, e); | |
67 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 62 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
68 ((CBC_TwoDimWriter*)m_pBCWriter)->RenderResult(data, outWidth, outHeight, e); | 63 pWriter->RenderResult(data, outWidth, outHeight, e); |
69 FX_Free(data); | 64 FX_Free(data); |
70 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 65 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
71 return TRUE; | 66 return TRUE; |
72 } | 67 } |
73 | 68 |
74 FX_BOOL CBC_QRCode::RenderDevice(CFX_RenderDevice* device, | 69 FX_BOOL CBC_QRCode::RenderDevice(CFX_RenderDevice* device, |
75 const CFX_Matrix* matrix, | 70 const CFX_Matrix* matrix, |
76 int32_t& e) { | 71 int32_t& e) { |
77 ((CBC_TwoDimWriter*)m_pBCWriter)->RenderDeviceResult(device, matrix); | 72 static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) |
| 73 ->RenderDeviceResult(device, matrix); |
78 return TRUE; | 74 return TRUE; |
79 } | 75 } |
80 | 76 |
81 FX_BOOL CBC_QRCode::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { | 77 FX_BOOL CBC_QRCode::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { |
82 ((CBC_TwoDimWriter*)m_pBCWriter)->RenderBitmapResult(pOutBitmap, e); | 78 static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) |
| 79 ->RenderBitmapResult(pOutBitmap, e); |
83 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 80 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
84 return TRUE; | 81 return TRUE; |
85 } | 82 } |
86 | 83 |
87 CFX_WideString CBC_QRCode::Decode(uint8_t* buf, | 84 CFX_WideString CBC_QRCode::Decode(uint8_t* buf, |
88 int32_t width, | 85 int32_t width, |
89 int32_t height, | 86 int32_t height, |
90 int32_t& e) { | 87 int32_t& e) { |
91 CFX_WideString str; | 88 CFX_WideString str; |
92 return str; | 89 return str; |
93 } | 90 } |
94 | 91 |
95 CFX_WideString CBC_QRCode::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { | 92 CFX_WideString CBC_QRCode::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { |
96 CBC_BufferedImageLuminanceSource source(pBitmap); | 93 CBC_BufferedImageLuminanceSource source(pBitmap); |
97 CBC_GlobalHistogramBinarizer binarizer(&source); | 94 CBC_GlobalHistogramBinarizer binarizer(&source); |
98 CBC_BinaryBitmap bitmap(&binarizer); | 95 CBC_BinaryBitmap bitmap(&binarizer); |
99 CFX_ByteString retStr = m_pBCReader->Decode(&bitmap, 0, e); | 96 CFX_ByteString retStr = m_pBCReader->Decode(&bitmap, 0, e); |
100 BC_EXCEPTION_CHECK_ReturnValue(e, CFX_WideString()); | 97 BC_EXCEPTION_CHECK_ReturnValue(e, CFX_WideString()); |
101 return CFX_WideString::FromUTF8(retStr.AsStringC()); | 98 return CFX_WideString::FromUTF8(retStr.AsStringC()); |
102 } | 99 } |
OLD | NEW |