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