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 "barcode.h" | |
24 #include "include/BC_ResultPoint.h" | |
25 #include "include/BC_CommonBitMatrix.h" | |
26 #include "include/BC_PDF417BoundingBox.h" | |
27 CBC_BoundingBox::CBC_BoundingBox(CBC_CommonBitMatrix* image, CBC_ResultPoint* to
pLeft, CBC_ResultPoint* bottomLeft, CBC_ResultPoint* topRight, CBC_ResultPoint*
bottomRight, FX_INT32 &e) | |
28 { | |
29 if ((topLeft == NULL && topRight == NULL) || | |
30 (bottomLeft == NULL && bottomRight == NULL) || | |
31 (topLeft != NULL && bottomLeft == NULL) || | |
32 (topRight != NULL && bottomRight == NULL)) { | |
33 e = BCExceptionNotFoundInstance; | |
34 } | |
35 init(image, topLeft, bottomLeft, topRight, bottomRight); | |
36 } | |
37 CBC_BoundingBox::CBC_BoundingBox(CBC_BoundingBox* boundingBox) | |
38 { | |
39 init(boundingBox->m_image, boundingBox->m_topLeft, boundingBox->m_bottomLeft
, boundingBox->m_topRight, boundingBox->m_bottomRight); | |
40 } | |
41 CBC_BoundingBox::~CBC_BoundingBox() | |
42 { | |
43 if (m_topLeft) { | |
44 delete m_topLeft; | |
45 } | |
46 if (m_bottomLeft) { | |
47 delete m_bottomLeft; | |
48 } | |
49 if (m_topRight) { | |
50 delete m_topRight; | |
51 } | |
52 if (m_bottomRight) { | |
53 delete m_bottomRight; | |
54 } | |
55 } | |
56 CBC_BoundingBox* CBC_BoundingBox::merge(CBC_BoundingBox* leftBox, CBC_BoundingBo
x* rightBox, FX_INT32 &e) | |
57 { | |
58 CBC_BoundingBox* boundingBox = NULL; | |
59 if (leftBox == NULL) { | |
60 boundingBox = FX_NEW CBC_BoundingBox(rightBox); | |
61 return boundingBox; | |
62 } | |
63 if (rightBox == NULL) { | |
64 boundingBox = FX_NEW CBC_BoundingBox(leftBox); | |
65 return boundingBox; | |
66 } | |
67 boundingBox = FX_NEW CBC_BoundingBox(leftBox->m_image, leftBox->m_topLeft, l
eftBox->m_bottomLeft, rightBox->m_topRight, rightBox->m_bottomRight, e); | |
68 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | |
69 return boundingBox; | |
70 } | |
71 CBC_BoundingBox* CBC_BoundingBox::addMissingRows(FX_INT32 missingStartRows, FX_I
NT32 missingEndRows, FX_BOOL isLeft, FX_INT32 &e) | |
72 { | |
73 CBC_ResultPoint* newTopLeft = m_topLeft; | |
74 CBC_ResultPoint* newBottomLeft = m_bottomLeft; | |
75 CBC_ResultPoint* newTopRight = m_topRight; | |
76 CBC_ResultPoint* newBottomRight = m_bottomRight; | |
77 CBC_ResultPoint* newTop = NULL; | |
78 CBC_ResultPoint* newBottom = NULL; | |
79 if (missingStartRows > 0) { | |
80 CBC_ResultPoint* top = isLeft ? m_topLeft : m_topRight; | |
81 FX_INT32 newMinY = (FX_INT32) top->GetY() - missingStartRows; | |
82 if (newMinY < 0) { | |
83 newMinY = 0; | |
84 } | |
85 newTop = FX_NEW CBC_ResultPoint((FX_FLOAT)top->GetX(), (FX_FLOAT)newMinY
); | |
86 if (isLeft) { | |
87 newTopLeft = newTop; | |
88 } else { | |
89 newTopRight = newTop; | |
90 } | |
91 } | |
92 if (missingEndRows > 0) { | |
93 CBC_ResultPoint* bottom = isLeft ? m_bottomLeft : m_bottomRight; | |
94 FX_INT32 newMaxY = (FX_INT32) bottom->GetY() + missingEndRows; | |
95 if (newMaxY >= m_image->GetHeight()) { | |
96 newMaxY = m_image->GetHeight() - 1; | |
97 } | |
98 newBottom = FX_NEW CBC_ResultPoint((FX_FLOAT)bottom->GetX(), (FX_FLOAT)n
ewMaxY); | |
99 if (isLeft) { | |
100 newBottomLeft = newBottom; | |
101 } else { | |
102 newBottomRight = newBottom; | |
103 } | |
104 } | |
105 calculateMinMaxValues(); | |
106 CBC_BoundingBox* boundingBox = FX_NEW CBC_BoundingBox(m_image, newTopLeft, n
ewBottomLeft, newTopRight, newBottomRight, e); | |
107 delete newTop; | |
108 delete newBottom; | |
109 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | |
110 return boundingBox; | |
111 } | |
112 void CBC_BoundingBox::setTopRight(CBC_ResultPoint topRight) | |
113 { | |
114 if (m_topRight) { | |
115 delete m_topRight; | |
116 } | |
117 m_topRight = FX_NEW CBC_ResultPoint(topRight.GetX(), topRight.GetY()); | |
118 calculateMinMaxValues(); | |
119 } | |
120 void CBC_BoundingBox::setBottomRight(CBC_ResultPoint bottomRight) | |
121 { | |
122 if (m_bottomRight) { | |
123 delete m_bottomRight; | |
124 } | |
125 m_bottomRight = FX_NEW CBC_ResultPoint(bottomRight.GetX(), bottomRight.GetY(
)); | |
126 calculateMinMaxValues(); | |
127 } | |
128 FX_INT32 CBC_BoundingBox::getMinX() | |
129 { | |
130 return m_minX; | |
131 } | |
132 FX_INT32 CBC_BoundingBox::getMaxX() | |
133 { | |
134 return m_maxX; | |
135 } | |
136 FX_INT32 CBC_BoundingBox::getMinY() | |
137 { | |
138 return m_minY; | |
139 } | |
140 FX_INT32 CBC_BoundingBox::getMaxY() | |
141 { | |
142 return m_maxY; | |
143 } | |
144 CBC_ResultPoint* CBC_BoundingBox::getTopLeft() | |
145 { | |
146 return m_topLeft; | |
147 } | |
148 CBC_ResultPoint* CBC_BoundingBox::getTopRight() | |
149 { | |
150 return m_topRight; | |
151 } | |
152 CBC_ResultPoint* CBC_BoundingBox::getBottomLeft() | |
153 { | |
154 return m_bottomLeft; | |
155 } | |
156 CBC_ResultPoint* CBC_BoundingBox::getBottomRight() | |
157 { | |
158 return m_bottomRight; | |
159 } | |
160 void CBC_BoundingBox::init(CBC_CommonBitMatrix* image, CBC_ResultPoint* topLeft,
CBC_ResultPoint* bottomLeft, CBC_ResultPoint* topRight, CBC_ResultPoint* bottom
Right) | |
161 { | |
162 m_topLeft = NULL; | |
163 m_bottomLeft = NULL; | |
164 m_topRight = NULL; | |
165 m_bottomRight = NULL; | |
166 m_image = image; | |
167 if (topLeft) { | |
168 m_topLeft = FX_NEW CBC_ResultPoint(topLeft->GetX(), topLeft->GetY()); | |
169 } | |
170 if (bottomLeft) { | |
171 m_bottomLeft = FX_NEW CBC_ResultPoint(bottomLeft->GetX(), bottomLeft->Ge
tY()); | |
172 } | |
173 if (topRight) { | |
174 m_topRight = FX_NEW CBC_ResultPoint(topRight->GetX(), topRight->GetY()); | |
175 } | |
176 if (bottomRight) { | |
177 m_bottomRight = FX_NEW CBC_ResultPoint(bottomRight->GetX(), bottomRight-
>GetY()); | |
178 } | |
179 calculateMinMaxValues(); | |
180 } | |
181 void CBC_BoundingBox::calculateMinMaxValues() | |
182 { | |
183 if (m_topLeft == NULL) { | |
184 m_topLeft = FX_NEW CBC_ResultPoint(0, m_topRight->GetY()); | |
185 m_bottomLeft = FX_NEW CBC_ResultPoint(0, m_bottomRight->GetY()); | |
186 } else if (m_topRight == NULL) { | |
187 m_topRight = FX_NEW CBC_ResultPoint((FX_FLOAT)m_image->GetWidth() - 1, (
FX_FLOAT)m_topLeft->GetY()); | |
188 m_bottomRight = FX_NEW CBC_ResultPoint((FX_FLOAT)m_image->GetWidth() - 1
, (FX_FLOAT)m_bottomLeft->GetY()); | |
189 } | |
190 m_minX = (FX_INT32) (m_topLeft->GetX() < m_bottomLeft->GetX() ? m_topLeft->G
etX() : m_bottomLeft->GetX()); | |
191 m_maxX = (FX_INT32) (m_topRight->GetX() > m_bottomRight->GetX() ? m_topRight
->GetX() : m_bottomRight->GetX()); | |
192 m_minY = (FX_INT32) (m_topLeft->GetY() < m_topRight->GetY() ? m_topLeft->Ge
tY() : m_topRight->GetY()); | |
193 m_maxY = (FX_INT32) (m_bottomLeft->GetY() > m_bottomRight->GetY() ? m_botto
mLeft->GetY() : m_bottomRight->GetY()); | |
194 } | |
OLD | NEW |