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_datamatrix.h" | 22 #include "xfa/fxbarcode/cbc_datamatrix.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/datamatrix/BC_DataMatrixReader.h" | 27 #include "xfa/fxbarcode/datamatrix/BC_DataMatrixReader.h" |
28 #include "xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.h" | 28 #include "xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.h" |
29 | 29 |
30 CBC_DataMatrix::CBC_DataMatrix() { | 30 CBC_DataMatrix::CBC_DataMatrix() |
31 m_pBCReader = (CBC_Reader*)new (CBC_DataMatrixReader); | 31 : CBC_CodeBase(new CBC_DataMatrixReader, new CBC_DataMatrixWriter) { |
32 ((CBC_DataMatrixReader*)m_pBCReader)->Init(); | 32 static_cast<CBC_DataMatrixReader*>(m_pBCReader.get())->Init(); |
33 m_pBCWriter = (CBC_Writer*)new (CBC_DataMatrixWriter); | |
34 } | 33 } |
35 | 34 |
36 CBC_DataMatrix::~CBC_DataMatrix() { | 35 CBC_DataMatrix::~CBC_DataMatrix() {} |
37 delete (m_pBCReader); | |
38 delete (m_pBCWriter); | |
39 } | |
40 | 36 |
41 FX_BOOL CBC_DataMatrix::Encode(const CFX_WideStringC& contents, | 37 FX_BOOL CBC_DataMatrix::Encode(const CFX_WideStringC& contents, |
42 FX_BOOL isDevice, | 38 FX_BOOL isDevice, |
43 int32_t& e) { | 39 int32_t& e) { |
44 int32_t outWidth = 0; | 40 int32_t outWidth = 0; |
45 int32_t outHeight = 0; | 41 int32_t outHeight = 0; |
46 uint8_t* data = | 42 uint8_t* data = |
47 ((CBC_DataMatrixWriter*)m_pBCWriter) | 43 static_cast<CBC_DataMatrixWriter*>(m_pBCWriter.get()) |
48 ->Encode(CFX_WideString(contents), outWidth, outHeight, e); | 44 ->Encode(CFX_WideString(contents), outWidth, outHeight, e); |
49 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 45 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
50 ((CBC_TwoDimWriter*)m_pBCWriter)->RenderResult(data, outWidth, outHeight, e); | 46 static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) |
| 47 ->RenderResult(data, outWidth, outHeight, e); |
51 FX_Free(data); | 48 FX_Free(data); |
52 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 49 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
53 return TRUE; | 50 return TRUE; |
54 } | 51 } |
55 | 52 |
56 FX_BOOL CBC_DataMatrix::RenderDevice(CFX_RenderDevice* device, | 53 FX_BOOL CBC_DataMatrix::RenderDevice(CFX_RenderDevice* device, |
57 const CFX_Matrix* matrix, | 54 const CFX_Matrix* matrix, |
58 int32_t& e) { | 55 int32_t& e) { |
59 ((CBC_TwoDimWriter*)m_pBCWriter)->RenderDeviceResult(device, matrix); | 56 static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) |
| 57 ->RenderDeviceResult(device, matrix); |
60 return TRUE; | 58 return TRUE; |
61 } | 59 } |
62 | 60 |
63 FX_BOOL CBC_DataMatrix::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { | 61 FX_BOOL CBC_DataMatrix::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { |
64 ((CBC_TwoDimWriter*)m_pBCWriter)->RenderBitmapResult(pOutBitmap, e); | 62 static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) |
| 63 ->RenderBitmapResult(pOutBitmap, e); |
65 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 64 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
66 return TRUE; | 65 return TRUE; |
67 } | 66 } |
68 | 67 |
69 CFX_WideString CBC_DataMatrix::Decode(uint8_t* buf, | 68 CFX_WideString CBC_DataMatrix::Decode(uint8_t* buf, |
70 int32_t width, | 69 int32_t width, |
71 int32_t height, | 70 int32_t height, |
72 int32_t& e) { | 71 int32_t& e) { |
73 CFX_WideString str; | 72 CFX_WideString str; |
74 return str; | 73 return str; |
75 } | 74 } |
76 | 75 |
77 CFX_WideString CBC_DataMatrix::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { | 76 CFX_WideString CBC_DataMatrix::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { |
78 CBC_BufferedImageLuminanceSource source(pBitmap); | 77 CBC_BufferedImageLuminanceSource source(pBitmap); |
79 CBC_GlobalHistogramBinarizer binarizer(&source); | 78 CBC_GlobalHistogramBinarizer binarizer(&source); |
80 CBC_BinaryBitmap bitmap(&binarizer); | 79 CBC_BinaryBitmap bitmap(&binarizer); |
81 CFX_ByteString retStr = m_pBCReader->Decode(&bitmap, 0, e); | 80 CFX_ByteString retStr = m_pBCReader->Decode(&bitmap, 0, e); |
82 BC_EXCEPTION_CHECK_ReturnValue(e, CFX_WideString()); | 81 BC_EXCEPTION_CHECK_ReturnValue(e, CFX_WideString()); |
83 return CFX_WideString::FromUTF8(retStr.AsStringC()); | 82 return CFX_WideString::FromUTF8(retStr.AsStringC()); |
84 } | 83 } |
OLD | NEW |