| 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"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" | 24 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" |
| 25 #include "xfa/fxbarcode/pdf417/BC_PDF417BoundingBox.h" | 25 #include "xfa/fxbarcode/pdf417/BC_PDF417BoundingBox.h" |
| 26 #include "xfa/fxbarcode/utils.h" | 26 #include "xfa/fxbarcode/utils.h" |
| 27 | 27 |
| 28 CBC_BoundingBox::CBC_BoundingBox(CBC_CommonBitMatrix* image, | 28 CBC_BoundingBox::CBC_BoundingBox(CBC_CommonBitMatrix* image, |
| 29 CBC_ResultPoint* topLeft, | 29 CBC_ResultPoint* topLeft, |
| 30 CBC_ResultPoint* bottomLeft, | 30 CBC_ResultPoint* bottomLeft, |
| 31 CBC_ResultPoint* topRight, | 31 CBC_ResultPoint* topRight, |
| 32 CBC_ResultPoint* bottomRight, | 32 CBC_ResultPoint* bottomRight, |
| 33 int32_t& e) { | 33 int32_t& e) { |
| 34 if ((topLeft == NULL && topRight == NULL) || | 34 if ((!topLeft && !topRight) || (!bottomLeft && !bottomRight) || |
| 35 (bottomLeft == NULL && bottomRight == NULL) || | 35 (topLeft && !bottomLeft) || (topRight && !bottomRight)) { |
| 36 (topLeft && bottomLeft == NULL) || (topRight && bottomRight == NULL)) { | |
| 37 e = BCExceptionNotFoundInstance; | 36 e = BCExceptionNotFoundInstance; |
| 38 } | 37 } |
| 39 init(image, topLeft, bottomLeft, topRight, bottomRight); | 38 init(image, topLeft, bottomLeft, topRight, bottomRight); |
| 40 } | 39 } |
| 41 CBC_BoundingBox::CBC_BoundingBox(CBC_BoundingBox* boundingBox) { | 40 CBC_BoundingBox::CBC_BoundingBox(CBC_BoundingBox* boundingBox) { |
| 42 init(boundingBox->m_image, boundingBox->m_topLeft, boundingBox->m_bottomLeft, | 41 init(boundingBox->m_image, boundingBox->m_topLeft, boundingBox->m_bottomLeft, |
| 43 boundingBox->m_topRight, boundingBox->m_bottomRight); | 42 boundingBox->m_topRight, boundingBox->m_bottomRight); |
| 44 } | 43 } |
| 45 | 44 |
| 46 CBC_BoundingBox::~CBC_BoundingBox() { | 45 CBC_BoundingBox::~CBC_BoundingBox() { |
| 47 delete m_topLeft; | 46 delete m_topLeft; |
| 48 delete m_bottomLeft; | 47 delete m_bottomLeft; |
| 49 delete m_topRight; | 48 delete m_topRight; |
| 50 delete m_bottomRight; | 49 delete m_bottomRight; |
| 51 } | 50 } |
| 52 | 51 |
| 53 CBC_BoundingBox* CBC_BoundingBox::merge(CBC_BoundingBox* leftBox, | 52 CBC_BoundingBox* CBC_BoundingBox::merge(CBC_BoundingBox* leftBox, |
| 54 CBC_BoundingBox* rightBox, | 53 CBC_BoundingBox* rightBox, |
| 55 int32_t& e) { | 54 int32_t& e) { |
| 56 CBC_BoundingBox* boundingBox = NULL; | 55 CBC_BoundingBox* boundingBox = nullptr; |
| 57 if (leftBox == NULL) { | 56 if (!leftBox) { |
| 58 boundingBox = new CBC_BoundingBox(rightBox); | 57 boundingBox = new CBC_BoundingBox(rightBox); |
| 59 return boundingBox; | 58 return boundingBox; |
| 60 } | 59 } |
| 61 if (rightBox == NULL) { | 60 if (!rightBox) { |
| 62 boundingBox = new CBC_BoundingBox(leftBox); | 61 boundingBox = new CBC_BoundingBox(leftBox); |
| 63 return boundingBox; | 62 return boundingBox; |
| 64 } | 63 } |
| 65 boundingBox = new CBC_BoundingBox(leftBox->m_image, leftBox->m_topLeft, | 64 boundingBox = new CBC_BoundingBox(leftBox->m_image, leftBox->m_topLeft, |
| 66 leftBox->m_bottomLeft, rightBox->m_topRight, | 65 leftBox->m_bottomLeft, rightBox->m_topRight, |
| 67 rightBox->m_bottomRight, e); | 66 rightBox->m_bottomRight, e); |
| 68 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 67 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 69 return boundingBox; | 68 return boundingBox; |
| 70 } | 69 } |
| 71 CBC_BoundingBox* CBC_BoundingBox::addMissingRows(int32_t missingStartRows, | 70 CBC_BoundingBox* CBC_BoundingBox::addMissingRows(int32_t missingStartRows, |
| 72 int32_t missingEndRows, | 71 int32_t missingEndRows, |
| 73 FX_BOOL isLeft, | 72 FX_BOOL isLeft, |
| 74 int32_t& e) { | 73 int32_t& e) { |
| 75 CBC_ResultPoint* newTopLeft = m_topLeft; | 74 CBC_ResultPoint* newTopLeft = m_topLeft; |
| 76 CBC_ResultPoint* newBottomLeft = m_bottomLeft; | 75 CBC_ResultPoint* newBottomLeft = m_bottomLeft; |
| 77 CBC_ResultPoint* newTopRight = m_topRight; | 76 CBC_ResultPoint* newTopRight = m_topRight; |
| 78 CBC_ResultPoint* newBottomRight = m_bottomRight; | 77 CBC_ResultPoint* newBottomRight = m_bottomRight; |
| 79 CBC_ResultPoint* newTop = NULL; | 78 CBC_ResultPoint* newTop = nullptr; |
| 80 CBC_ResultPoint* newBottom = NULL; | 79 CBC_ResultPoint* newBottom = nullptr; |
| 81 if (missingStartRows > 0) { | 80 if (missingStartRows > 0) { |
| 82 CBC_ResultPoint* top = isLeft ? m_topLeft : m_topRight; | 81 CBC_ResultPoint* top = isLeft ? m_topLeft : m_topRight; |
| 83 int32_t newMinY = (int32_t)top->GetY() - missingStartRows; | 82 int32_t newMinY = (int32_t)top->GetY() - missingStartRows; |
| 84 if (newMinY < 0) { | 83 if (newMinY < 0) { |
| 85 newMinY = 0; | 84 newMinY = 0; |
| 86 } | 85 } |
| 87 newTop = new CBC_ResultPoint((FX_FLOAT)top->GetX(), (FX_FLOAT)newMinY); | 86 newTop = new CBC_ResultPoint((FX_FLOAT)top->GetX(), (FX_FLOAT)newMinY); |
| 88 if (isLeft) { | 87 if (isLeft) { |
| 89 newTopLeft = newTop; | 88 newTopLeft = newTop; |
| 90 } else { | 89 } else { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 103 newBottomLeft = newBottom; | 102 newBottomLeft = newBottom; |
| 104 } else { | 103 } else { |
| 105 newBottomRight = newBottom; | 104 newBottomRight = newBottom; |
| 106 } | 105 } |
| 107 } | 106 } |
| 108 calculateMinMaxValues(); | 107 calculateMinMaxValues(); |
| 109 CBC_BoundingBox* boundingBox = new CBC_BoundingBox( | 108 CBC_BoundingBox* boundingBox = new CBC_BoundingBox( |
| 110 m_image, newTopLeft, newBottomLeft, newTopRight, newBottomRight, e); | 109 m_image, newTopLeft, newBottomLeft, newTopRight, newBottomRight, e); |
| 111 delete newTop; | 110 delete newTop; |
| 112 delete newBottom; | 111 delete newBottom; |
| 113 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 112 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 114 return boundingBox; | 113 return boundingBox; |
| 115 } | 114 } |
| 116 void CBC_BoundingBox::setTopRight(CBC_ResultPoint topRight) { | 115 void CBC_BoundingBox::setTopRight(CBC_ResultPoint topRight) { |
| 117 if (m_topRight) { | 116 if (m_topRight) { |
| 118 delete m_topRight; | 117 delete m_topRight; |
| 119 } | 118 } |
| 120 m_topRight = new CBC_ResultPoint(topRight.GetX(), topRight.GetY()); | 119 m_topRight = new CBC_ResultPoint(topRight.GetX(), topRight.GetY()); |
| 121 calculateMinMaxValues(); | 120 calculateMinMaxValues(); |
| 122 } | 121 } |
| 123 void CBC_BoundingBox::setBottomRight(CBC_ResultPoint bottomRight) { | 122 void CBC_BoundingBox::setBottomRight(CBC_ResultPoint bottomRight) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 149 return m_bottomLeft; | 148 return m_bottomLeft; |
| 150 } | 149 } |
| 151 CBC_ResultPoint* CBC_BoundingBox::getBottomRight() { | 150 CBC_ResultPoint* CBC_BoundingBox::getBottomRight() { |
| 152 return m_bottomRight; | 151 return m_bottomRight; |
| 153 } | 152 } |
| 154 void CBC_BoundingBox::init(CBC_CommonBitMatrix* image, | 153 void CBC_BoundingBox::init(CBC_CommonBitMatrix* image, |
| 155 CBC_ResultPoint* topLeft, | 154 CBC_ResultPoint* topLeft, |
| 156 CBC_ResultPoint* bottomLeft, | 155 CBC_ResultPoint* bottomLeft, |
| 157 CBC_ResultPoint* topRight, | 156 CBC_ResultPoint* topRight, |
| 158 CBC_ResultPoint* bottomRight) { | 157 CBC_ResultPoint* bottomRight) { |
| 159 m_topLeft = NULL; | 158 m_topLeft = nullptr; |
| 160 m_bottomLeft = NULL; | 159 m_bottomLeft = nullptr; |
| 161 m_topRight = NULL; | 160 m_topRight = nullptr; |
| 162 m_bottomRight = NULL; | 161 m_bottomRight = nullptr; |
| 163 m_image = image; | 162 m_image = image; |
| 164 if (topLeft) { | 163 if (topLeft) { |
| 165 m_topLeft = new CBC_ResultPoint(topLeft->GetX(), topLeft->GetY()); | 164 m_topLeft = new CBC_ResultPoint(topLeft->GetX(), topLeft->GetY()); |
| 166 } | 165 } |
| 167 if (bottomLeft) { | 166 if (bottomLeft) { |
| 168 m_bottomLeft = new CBC_ResultPoint(bottomLeft->GetX(), bottomLeft->GetY()); | 167 m_bottomLeft = new CBC_ResultPoint(bottomLeft->GetX(), bottomLeft->GetY()); |
| 169 } | 168 } |
| 170 if (topRight) { | 169 if (topRight) { |
| 171 m_topRight = new CBC_ResultPoint(topRight->GetX(), topRight->GetY()); | 170 m_topRight = new CBC_ResultPoint(topRight->GetX(), topRight->GetY()); |
| 172 } | 171 } |
| 173 if (bottomRight) { | 172 if (bottomRight) { |
| 174 m_bottomRight = | 173 m_bottomRight = |
| 175 new CBC_ResultPoint(bottomRight->GetX(), bottomRight->GetY()); | 174 new CBC_ResultPoint(bottomRight->GetX(), bottomRight->GetY()); |
| 176 } | 175 } |
| 177 calculateMinMaxValues(); | 176 calculateMinMaxValues(); |
| 178 } | 177 } |
| 179 void CBC_BoundingBox::calculateMinMaxValues() { | 178 void CBC_BoundingBox::calculateMinMaxValues() { |
| 180 if (m_topLeft == NULL) { | 179 if (!m_topLeft) { |
| 181 m_topLeft = new CBC_ResultPoint(0, m_topRight->GetY()); | 180 m_topLeft = new CBC_ResultPoint(0, m_topRight->GetY()); |
| 182 m_bottomLeft = new CBC_ResultPoint(0, m_bottomRight->GetY()); | 181 m_bottomLeft = new CBC_ResultPoint(0, m_bottomRight->GetY()); |
| 183 } else if (m_topRight == NULL) { | 182 } else if (!m_topRight) { |
| 184 m_topRight = new CBC_ResultPoint((FX_FLOAT)m_image->GetWidth() - 1, | 183 m_topRight = new CBC_ResultPoint((FX_FLOAT)m_image->GetWidth() - 1, |
| 185 (FX_FLOAT)m_topLeft->GetY()); | 184 (FX_FLOAT)m_topLeft->GetY()); |
| 186 m_bottomRight = new CBC_ResultPoint((FX_FLOAT)m_image->GetWidth() - 1, | 185 m_bottomRight = new CBC_ResultPoint((FX_FLOAT)m_image->GetWidth() - 1, |
| 187 (FX_FLOAT)m_bottomLeft->GetY()); | 186 (FX_FLOAT)m_bottomLeft->GetY()); |
| 188 } | 187 } |
| 189 m_minX = (int32_t)(m_topLeft->GetX() < m_bottomLeft->GetX() | 188 m_minX = (int32_t)(m_topLeft->GetX() < m_bottomLeft->GetX() |
| 190 ? m_topLeft->GetX() | 189 ? m_topLeft->GetX() |
| 191 : m_bottomLeft->GetX()); | 190 : m_bottomLeft->GetX()); |
| 192 m_maxX = (int32_t)(m_topRight->GetX() > m_bottomRight->GetX() | 191 m_maxX = (int32_t)(m_topRight->GetX() > m_bottomRight->GetX() |
| 193 ? m_topRight->GetX() | 192 ? m_topRight->GetX() |
| 194 : m_bottomRight->GetX()); | 193 : m_bottomRight->GetX()); |
| 195 m_minY = | 194 m_minY = |
| 196 (int32_t)(m_topLeft->GetY() < m_topRight->GetY() ? m_topLeft->GetY() | 195 (int32_t)(m_topLeft->GetY() < m_topRight->GetY() ? m_topLeft->GetY() |
| 197 : m_topRight->GetY()); | 196 : m_topRight->GetY()); |
| 198 m_maxY = (int32_t)(m_bottomLeft->GetY() > m_bottomRight->GetY() | 197 m_maxY = (int32_t)(m_bottomLeft->GetY() > m_bottomRight->GetY() |
| 199 ? m_bottomLeft->GetY() | 198 ? m_bottomLeft->GetY() |
| 200 : m_bottomRight->GetY()); | 199 : m_bottomRight->GetY()); |
| 201 } | 200 } |
| OLD | NEW |