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 2013 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/pdf417/BC_PDF417BoundingBox.h" | |
24 #include "xfa/src/fxbarcode/pdf417/BC_PDF417Codeword.h" | |
25 #include "xfa/src/fxbarcode/pdf417/BC_PDF417DetectionResultColumn.h" | |
26 | |
27 int32_t CBC_DetectionResultColumn::MAX_NEARBY_DISTANCE = 5; | |
28 | |
29 CBC_DetectionResultColumn::CBC_DetectionResultColumn( | |
30 CBC_BoundingBox* boundingBox) { | |
31 m_boundingBox = boundingBox; | |
32 m_codewords = new CFX_PtrArray; | |
33 m_codewords->SetSize(boundingBox->getMaxY() - boundingBox->getMinY() + 1); | |
34 } | |
35 CBC_DetectionResultColumn::~CBC_DetectionResultColumn() { | |
36 for (int32_t i = 0; i < m_codewords->GetSize(); i++) { | |
37 delete (CBC_Codeword*)m_codewords->GetAt(i); | |
38 } | |
39 m_codewords->RemoveAll(); | |
40 delete m_codewords; | |
41 } | |
42 CBC_Codeword* CBC_DetectionResultColumn::getCodewordNearby(int32_t imageRow) { | |
43 CBC_Codeword* codeword = getCodeword(imageRow); | |
44 if (codeword) { | |
45 return codeword; | |
46 } | |
47 for (int32_t i = 1; i < MAX_NEARBY_DISTANCE; i++) { | |
48 int32_t nearImageRow = imageRowToCodewordIndex(imageRow) - i; | |
49 if (nearImageRow >= 0) { | |
50 codeword = (CBC_Codeword*)m_codewords->GetAt(nearImageRow); | |
51 if (codeword) { | |
52 return codeword; | |
53 } | |
54 } | |
55 nearImageRow = imageRowToCodewordIndex(imageRow) + i; | |
56 if (nearImageRow < m_codewords->GetSize()) { | |
57 codeword = (CBC_Codeword*)m_codewords->GetAt(nearImageRow); | |
58 if (codeword) { | |
59 return codeword; | |
60 } | |
61 } | |
62 } | |
63 return NULL; | |
64 } | |
65 int32_t CBC_DetectionResultColumn::imageRowToCodewordIndex(int32_t imageRow) { | |
66 return imageRow - m_boundingBox->getMinY(); | |
67 } | |
68 int32_t CBC_DetectionResultColumn::codewordIndexToImageRow( | |
69 int32_t codewordIndex) { | |
70 return m_boundingBox->getMinY() + codewordIndex; | |
71 } | |
72 void CBC_DetectionResultColumn::setCodeword(int32_t imageRow, | |
73 CBC_Codeword* codeword) { | |
74 m_codewords->SetAt(imageRowToCodewordIndex(imageRow), codeword); | |
75 } | |
76 CBC_Codeword* CBC_DetectionResultColumn::getCodeword(int32_t imageRow) { | |
77 return (CBC_Codeword*)m_codewords->GetAt(imageRowToCodewordIndex(imageRow)); | |
78 } | |
79 CBC_BoundingBox* CBC_DetectionResultColumn::getBoundingBox() { | |
80 return m_boundingBox; | |
81 } | |
82 CFX_PtrArray* CBC_DetectionResultColumn::getCodewords() { | |
83 return m_codewords; | |
84 } | |
85 CFX_ByteString CBC_DetectionResultColumn::toString() { | |
86 CFX_ByteString result; | |
87 int32_t row = 0; | |
88 for (int32_t i = 0; i < m_codewords->GetSize(); i++) { | |
89 CBC_Codeword* codeword = (CBC_Codeword*)m_codewords->GetAt(i); | |
90 if (codeword == NULL) { | |
91 result += (FX_CHAR)row; | |
92 row++; | |
93 continue; | |
94 } | |
95 result += (FX_CHAR)row; | |
96 result += codeword->getRowNumber(); | |
97 result += codeword->getValue(); | |
98 row++; | |
99 } | |
100 return result; | |
101 } | |
OLD | NEW |