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