OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 // Original code is licensed as follows: | 6 // Original code is licensed as follows: |
7 /* | 7 /* |
8 * Copyright 2013 ZXing authors | 8 * Copyright 2013 ZXing authors |
9 * | 9 * |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
11 * you may not use this file except in compliance with 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 | 12 * You may obtain a copy of the License at |
13 * | 13 * |
14 * http://www.apache.org/licenses/LICENSE-2.0 | 14 * http://www.apache.org/licenses/LICENSE-2.0 |
15 * | 15 * |
16 * Unless required by applicable law or agreed to in writing, software | 16 * Unless required by applicable law or agreed to in writing, software |
17 * distributed under the License is distributed on an "AS IS" BASIS, | 17 * distributed under the License is distributed on an "AS IS" BASIS, |
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
19 * See the License for the specific language governing permissions and | 19 * See the License for the specific language governing permissions and |
20 * limitations under the License. | 20 * limitations under the License. |
21 */ | 21 */ |
22 | 22 |
23 #include "../barcode.h" | 23 #include "../barcode.h" |
24 #include "../BC_ResultPoint.h" | 24 #include "../BC_ResultPoint.h" |
25 #include "../common/BC_CommonBitMatrix.h" | 25 #include "../common/BC_CommonBitMatrix.h" |
26 #include "BC_PDF417BoundingBox.h" | 26 #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) | 27 CBC_BoundingBox::CBC_BoundingBox(CBC_CommonBitMatrix* image, CBC_ResultPoint* to
pLeft, CBC_ResultPoint* bottomLeft, CBC_ResultPoint* topRight, CBC_ResultPoint*
bottomRight, int32_t &e) |
28 { | 28 { |
29 if ((topLeft == NULL && topRight == NULL) || | 29 if ((topLeft == NULL && topRight == NULL) || |
30 (bottomLeft == NULL && bottomRight == NULL) || | 30 (bottomLeft == NULL && bottomRight == NULL) || |
31 (topLeft != NULL && bottomLeft == NULL) || | 31 (topLeft != NULL && bottomLeft == NULL) || |
32 (topRight != NULL && bottomRight == NULL)) { | 32 (topRight != NULL && bottomRight == NULL)) { |
33 e = BCExceptionNotFoundInstance; | 33 e = BCExceptionNotFoundInstance; |
34 } | 34 } |
35 init(image, topLeft, bottomLeft, topRight, bottomRight); | 35 init(image, topLeft, bottomLeft, topRight, bottomRight); |
36 } | 36 } |
37 CBC_BoundingBox::CBC_BoundingBox(CBC_BoundingBox* boundingBox) | 37 CBC_BoundingBox::CBC_BoundingBox(CBC_BoundingBox* boundingBox) |
38 { | 38 { |
39 init(boundingBox->m_image, boundingBox->m_topLeft, boundingBox->m_bottomLeft
, boundingBox->m_topRight, boundingBox->m_bottomRight); | 39 init(boundingBox->m_image, boundingBox->m_topLeft, boundingBox->m_bottomLeft
, boundingBox->m_topRight, boundingBox->m_bottomRight); |
40 } | 40 } |
41 CBC_BoundingBox::~CBC_BoundingBox() | 41 CBC_BoundingBox::~CBC_BoundingBox() |
42 { | 42 { |
43 if (m_topLeft) { | 43 if (m_topLeft) { |
44 delete m_topLeft; | 44 delete m_topLeft; |
45 } | 45 } |
46 if (m_bottomLeft) { | 46 if (m_bottomLeft) { |
47 delete m_bottomLeft; | 47 delete m_bottomLeft; |
48 } | 48 } |
49 if (m_topRight) { | 49 if (m_topRight) { |
50 delete m_topRight; | 50 delete m_topRight; |
51 } | 51 } |
52 if (m_bottomRight) { | 52 if (m_bottomRight) { |
53 delete m_bottomRight; | 53 delete m_bottomRight; |
54 } | 54 } |
55 } | 55 } |
56 CBC_BoundingBox* CBC_BoundingBox::merge(CBC_BoundingBox* leftBox, CBC_BoundingBo
x* rightBox, FX_INT32 &e) | 56 CBC_BoundingBox* CBC_BoundingBox::merge(CBC_BoundingBox* leftBox, CBC_BoundingBo
x* rightBox, int32_t &e) |
57 { | 57 { |
58 CBC_BoundingBox* boundingBox = NULL; | 58 CBC_BoundingBox* boundingBox = NULL; |
59 if (leftBox == NULL) { | 59 if (leftBox == NULL) { |
60 boundingBox = FX_NEW CBC_BoundingBox(rightBox); | 60 boundingBox = FX_NEW CBC_BoundingBox(rightBox); |
61 return boundingBox; | 61 return boundingBox; |
62 } | 62 } |
63 if (rightBox == NULL) { | 63 if (rightBox == NULL) { |
64 boundingBox = FX_NEW CBC_BoundingBox(leftBox); | 64 boundingBox = FX_NEW CBC_BoundingBox(leftBox); |
65 return boundingBox; | 65 return boundingBox; |
66 } | 66 } |
67 boundingBox = FX_NEW CBC_BoundingBox(leftBox->m_image, leftBox->m_topLeft, l
eftBox->m_bottomLeft, rightBox->m_topRight, rightBox->m_bottomRight, e); | 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); | 68 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
69 return boundingBox; | 69 return boundingBox; |
70 } | 70 } |
71 CBC_BoundingBox* CBC_BoundingBox::addMissingRows(FX_INT32 missingStartRows, FX_I
NT32 missingEndRows, FX_BOOL isLeft, FX_INT32 &e) | 71 CBC_BoundingBox* CBC_BoundingBox::addMissingRows(int32_t missingStartRows, int32
_t missingEndRows, FX_BOOL isLeft, int32_t &e) |
72 { | 72 { |
73 CBC_ResultPoint* newTopLeft = m_topLeft; | 73 CBC_ResultPoint* newTopLeft = m_topLeft; |
74 CBC_ResultPoint* newBottomLeft = m_bottomLeft; | 74 CBC_ResultPoint* newBottomLeft = m_bottomLeft; |
75 CBC_ResultPoint* newTopRight = m_topRight; | 75 CBC_ResultPoint* newTopRight = m_topRight; |
76 CBC_ResultPoint* newBottomRight = m_bottomRight; | 76 CBC_ResultPoint* newBottomRight = m_bottomRight; |
77 CBC_ResultPoint* newTop = NULL; | 77 CBC_ResultPoint* newTop = NULL; |
78 CBC_ResultPoint* newBottom = NULL; | 78 CBC_ResultPoint* newBottom = NULL; |
79 if (missingStartRows > 0) { | 79 if (missingStartRows > 0) { |
80 CBC_ResultPoint* top = isLeft ? m_topLeft : m_topRight; | 80 CBC_ResultPoint* top = isLeft ? m_topLeft : m_topRight; |
81 FX_INT32 newMinY = (FX_INT32) top->GetY() - missingStartRows; | 81 int32_t newMinY = (int32_t) top->GetY() - missingStartRows; |
82 if (newMinY < 0) { | 82 if (newMinY < 0) { |
83 newMinY = 0; | 83 newMinY = 0; |
84 } | 84 } |
85 newTop = FX_NEW CBC_ResultPoint((FX_FLOAT)top->GetX(), (FX_FLOAT)newMinY
); | 85 newTop = FX_NEW CBC_ResultPoint((FX_FLOAT)top->GetX(), (FX_FLOAT)newMinY
); |
86 if (isLeft) { | 86 if (isLeft) { |
87 newTopLeft = newTop; | 87 newTopLeft = newTop; |
88 } else { | 88 } else { |
89 newTopRight = newTop; | 89 newTopRight = newTop; |
90 } | 90 } |
91 } | 91 } |
92 if (missingEndRows > 0) { | 92 if (missingEndRows > 0) { |
93 CBC_ResultPoint* bottom = isLeft ? m_bottomLeft : m_bottomRight; | 93 CBC_ResultPoint* bottom = isLeft ? m_bottomLeft : m_bottomRight; |
94 FX_INT32 newMaxY = (FX_INT32) bottom->GetY() + missingEndRows; | 94 int32_t newMaxY = (int32_t) bottom->GetY() + missingEndRows; |
95 if (newMaxY >= m_image->GetHeight()) { | 95 if (newMaxY >= m_image->GetHeight()) { |
96 newMaxY = m_image->GetHeight() - 1; | 96 newMaxY = m_image->GetHeight() - 1; |
97 } | 97 } |
98 newBottom = FX_NEW CBC_ResultPoint((FX_FLOAT)bottom->GetX(), (FX_FLOAT)n
ewMaxY); | 98 newBottom = FX_NEW CBC_ResultPoint((FX_FLOAT)bottom->GetX(), (FX_FLOAT)n
ewMaxY); |
99 if (isLeft) { | 99 if (isLeft) { |
100 newBottomLeft = newBottom; | 100 newBottomLeft = newBottom; |
101 } else { | 101 } else { |
102 newBottomRight = newBottom; | 102 newBottomRight = newBottom; |
103 } | 103 } |
104 } | 104 } |
(...skipping 13 matching lines...) Expand all Loading... |
118 calculateMinMaxValues(); | 118 calculateMinMaxValues(); |
119 } | 119 } |
120 void CBC_BoundingBox::setBottomRight(CBC_ResultPoint bottomRight) | 120 void CBC_BoundingBox::setBottomRight(CBC_ResultPoint bottomRight) |
121 { | 121 { |
122 if (m_bottomRight) { | 122 if (m_bottomRight) { |
123 delete m_bottomRight; | 123 delete m_bottomRight; |
124 } | 124 } |
125 m_bottomRight = FX_NEW CBC_ResultPoint(bottomRight.GetX(), bottomRight.GetY(
)); | 125 m_bottomRight = FX_NEW CBC_ResultPoint(bottomRight.GetX(), bottomRight.GetY(
)); |
126 calculateMinMaxValues(); | 126 calculateMinMaxValues(); |
127 } | 127 } |
128 FX_INT32 CBC_BoundingBox::getMinX() | 128 int32_t CBC_BoundingBox::getMinX() |
129 { | 129 { |
130 return m_minX; | 130 return m_minX; |
131 } | 131 } |
132 FX_INT32 CBC_BoundingBox::getMaxX() | 132 int32_t CBC_BoundingBox::getMaxX() |
133 { | 133 { |
134 return m_maxX; | 134 return m_maxX; |
135 } | 135 } |
136 FX_INT32 CBC_BoundingBox::getMinY() | 136 int32_t CBC_BoundingBox::getMinY() |
137 { | 137 { |
138 return m_minY; | 138 return m_minY; |
139 } | 139 } |
140 FX_INT32 CBC_BoundingBox::getMaxY() | 140 int32_t CBC_BoundingBox::getMaxY() |
141 { | 141 { |
142 return m_maxY; | 142 return m_maxY; |
143 } | 143 } |
144 CBC_ResultPoint* CBC_BoundingBox::getTopLeft() | 144 CBC_ResultPoint* CBC_BoundingBox::getTopLeft() |
145 { | 145 { |
146 return m_topLeft; | 146 return m_topLeft; |
147 } | 147 } |
148 CBC_ResultPoint* CBC_BoundingBox::getTopRight() | 148 CBC_ResultPoint* CBC_BoundingBox::getTopRight() |
149 { | 149 { |
150 return m_topRight; | 150 return m_topRight; |
(...skipping 29 matching lines...) Expand all Loading... |
180 } | 180 } |
181 void CBC_BoundingBox::calculateMinMaxValues() | 181 void CBC_BoundingBox::calculateMinMaxValues() |
182 { | 182 { |
183 if (m_topLeft == NULL) { | 183 if (m_topLeft == NULL) { |
184 m_topLeft = FX_NEW CBC_ResultPoint(0, m_topRight->GetY()); | 184 m_topLeft = FX_NEW CBC_ResultPoint(0, m_topRight->GetY()); |
185 m_bottomLeft = FX_NEW CBC_ResultPoint(0, m_bottomRight->GetY()); | 185 m_bottomLeft = FX_NEW CBC_ResultPoint(0, m_bottomRight->GetY()); |
186 } else if (m_topRight == NULL) { | 186 } else if (m_topRight == NULL) { |
187 m_topRight = FX_NEW CBC_ResultPoint((FX_FLOAT)m_image->GetWidth() - 1, (
FX_FLOAT)m_topLeft->GetY()); | 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()); | 188 m_bottomRight = FX_NEW CBC_ResultPoint((FX_FLOAT)m_image->GetWidth() - 1
, (FX_FLOAT)m_bottomLeft->GetY()); |
189 } | 189 } |
190 m_minX = (FX_INT32) (m_topLeft->GetX() < m_bottomLeft->GetX() ? m_topLeft->G
etX() : m_bottomLeft->GetX()); | 190 m_minX = (int32_t) (m_topLeft->GetX() < m_bottomLeft->GetX() ? m_topLeft->Ge
tX() : m_bottomLeft->GetX()); |
191 m_maxX = (FX_INT32) (m_topRight->GetX() > m_bottomRight->GetX() ? m_topRight
->GetX() : m_bottomRight->GetX()); | 191 m_maxX = (int32_t) (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()); | 192 m_minY = (int32_t) (m_topLeft->GetY() < m_topRight->GetY() ? m_topLeft->Get
Y() : m_topRight->GetY()); |
193 m_maxY = (FX_INT32) (m_bottomLeft->GetY() > m_bottomRight->GetY() ? m_botto
mLeft->GetY() : m_bottomRight->GetY()); | 193 m_maxY = (int32_t) (m_bottomLeft->GetY() > m_bottomRight->GetY() ? m_bottom
Left->GetY() : m_bottomRight->GetY()); |
194 } | 194 } |
OLD | NEW |