| 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 28 matching lines...) Expand all Loading... |
| 39 #include "xfa/fxbarcode/pdf417/BC_PDF417DetectionResultRowIndicatorColumn.h" | 39 #include "xfa/fxbarcode/pdf417/BC_PDF417DetectionResultRowIndicatorColumn.h" |
| 40 #include "xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.h" | 40 #include "xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.h" |
| 41 #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusGF.h" | 41 #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusGF.h" |
| 42 #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h" | 42 #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h" |
| 43 #include "xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.h" | 43 #include "xfa/fxbarcode/pdf417/BC_PDF417ScanningDecoder.h" |
| 44 #include "xfa/fxbarcode/utils.h" | 44 #include "xfa/fxbarcode/utils.h" |
| 45 | 45 |
| 46 int32_t CBC_PDF417ScanningDecoder::CODEWORD_SKEW_SIZE = 2; | 46 int32_t CBC_PDF417ScanningDecoder::CODEWORD_SKEW_SIZE = 2; |
| 47 int32_t CBC_PDF417ScanningDecoder::MAX_ERRORS = 3; | 47 int32_t CBC_PDF417ScanningDecoder::MAX_ERRORS = 3; |
| 48 int32_t CBC_PDF417ScanningDecoder::MAX_EC_CODEWORDS = 512; | 48 int32_t CBC_PDF417ScanningDecoder::MAX_EC_CODEWORDS = 512; |
| 49 CBC_PDF417ECErrorCorrection* CBC_PDF417ScanningDecoder::errorCorrection = NULL; | 49 CBC_PDF417ECErrorCorrection* CBC_PDF417ScanningDecoder::errorCorrection = |
| 50 nullptr; |
| 50 | 51 |
| 51 CBC_PDF417ScanningDecoder::CBC_PDF417ScanningDecoder() {} | 52 CBC_PDF417ScanningDecoder::CBC_PDF417ScanningDecoder() {} |
| 52 CBC_PDF417ScanningDecoder::~CBC_PDF417ScanningDecoder() {} | 53 CBC_PDF417ScanningDecoder::~CBC_PDF417ScanningDecoder() {} |
| 53 void CBC_PDF417ScanningDecoder::Initialize() { | 54 void CBC_PDF417ScanningDecoder::Initialize() { |
| 54 errorCorrection = new CBC_PDF417ECErrorCorrection; | 55 errorCorrection = new CBC_PDF417ECErrorCorrection; |
| 55 } | 56 } |
| 56 void CBC_PDF417ScanningDecoder::Finalize() { | 57 void CBC_PDF417ScanningDecoder::Finalize() { |
| 57 delete errorCorrection; | 58 delete errorCorrection; |
| 58 } | 59 } |
| 59 CBC_CommonDecoderResult* CBC_PDF417ScanningDecoder::decode( | 60 CBC_CommonDecoderResult* CBC_PDF417ScanningDecoder::decode( |
| 60 CBC_CommonBitMatrix* image, | 61 CBC_CommonBitMatrix* image, |
| 61 CBC_ResultPoint* imageTopLeft, | 62 CBC_ResultPoint* imageTopLeft, |
| 62 CBC_ResultPoint* imageBottomLeft, | 63 CBC_ResultPoint* imageBottomLeft, |
| 63 CBC_ResultPoint* imageTopRight, | 64 CBC_ResultPoint* imageTopRight, |
| 64 CBC_ResultPoint* imageBottomRight, | 65 CBC_ResultPoint* imageBottomRight, |
| 65 int32_t minCodewordWidth, | 66 int32_t minCodewordWidth, |
| 66 int32_t maxCodewordWidth, | 67 int32_t maxCodewordWidth, |
| 67 int32_t& e) { | 68 int32_t& e) { |
| 68 CBC_BoundingBox* boundingBox = new CBC_BoundingBox( | 69 CBC_BoundingBox* boundingBox = new CBC_BoundingBox( |
| 69 image, imageTopLeft, imageBottomLeft, imageTopRight, imageBottomRight, e); | 70 image, imageTopLeft, imageBottomLeft, imageTopRight, imageBottomRight, e); |
| 70 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 71 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 71 CBC_DetectionResultRowIndicatorColumn* leftRowIndicatorColumn = NULL; | 72 CBC_DetectionResultRowIndicatorColumn* leftRowIndicatorColumn = nullptr; |
| 72 CBC_DetectionResultRowIndicatorColumn* rightRowIndicatorColumn = NULL; | 73 CBC_DetectionResultRowIndicatorColumn* rightRowIndicatorColumn = nullptr; |
| 73 CBC_DetectionResult* detectionResult = NULL; | 74 CBC_DetectionResult* detectionResult = nullptr; |
| 74 for (int32_t i = 0; i < 2; i++) { | 75 for (int32_t i = 0; i < 2; i++) { |
| 75 if (imageTopLeft) { | 76 if (imageTopLeft) { |
| 76 leftRowIndicatorColumn = | 77 leftRowIndicatorColumn = |
| 77 getRowIndicatorColumn(image, boundingBox, *imageTopLeft, TRUE, | 78 getRowIndicatorColumn(image, boundingBox, *imageTopLeft, TRUE, |
| 78 minCodewordWidth, maxCodewordWidth); | 79 minCodewordWidth, maxCodewordWidth); |
| 79 } | 80 } |
| 80 if (imageTopRight) { | 81 if (imageTopRight) { |
| 81 rightRowIndicatorColumn = | 82 rightRowIndicatorColumn = |
| 82 getRowIndicatorColumn(image, boundingBox, *imageTopRight, FALSE, | 83 getRowIndicatorColumn(image, boundingBox, *imageTopRight, FALSE, |
| 83 minCodewordWidth, maxCodewordWidth); | 84 minCodewordWidth, maxCodewordWidth); |
| 84 } | 85 } |
| 85 detectionResult = merge(leftRowIndicatorColumn, rightRowIndicatorColumn, e); | 86 detectionResult = merge(leftRowIndicatorColumn, rightRowIndicatorColumn, e); |
| 86 if (e != BCExceptionNO) { | 87 if (e != BCExceptionNO) { |
| 87 e = BCExceptiontNotFoundInstance; | 88 e = BCExceptiontNotFoundInstance; |
| 88 delete leftRowIndicatorColumn; | 89 delete leftRowIndicatorColumn; |
| 89 delete rightRowIndicatorColumn; | 90 delete rightRowIndicatorColumn; |
| 90 delete boundingBox; | 91 delete boundingBox; |
| 91 return NULL; | 92 return nullptr; |
| 92 } | 93 } |
| 93 if (i == 0 && (detectionResult->getBoundingBox()->getMinY() < | 94 if (i == 0 && (detectionResult->getBoundingBox()->getMinY() < |
| 94 boundingBox->getMinY() || | 95 boundingBox->getMinY() || |
| 95 detectionResult->getBoundingBox()->getMaxY() > | 96 detectionResult->getBoundingBox()->getMaxY() > |
| 96 boundingBox->getMaxY())) { | 97 boundingBox->getMaxY())) { |
| 97 delete boundingBox; | 98 delete boundingBox; |
| 98 boundingBox = detectionResult->getBoundingBox(); | 99 boundingBox = detectionResult->getBoundingBox(); |
| 99 } else { | 100 } else { |
| 100 detectionResult->setBoundingBox(boundingBox); | 101 detectionResult->setBoundingBox(boundingBox); |
| 101 break; | 102 break; |
| 102 } | 103 } |
| 103 } | 104 } |
| 104 int32_t maxBarcodeColumn = detectionResult->getBarcodeColumnCount() + 1; | 105 int32_t maxBarcodeColumn = detectionResult->getBarcodeColumnCount() + 1; |
| 105 detectionResult->setDetectionResultColumn(0, leftRowIndicatorColumn); | 106 detectionResult->setDetectionResultColumn(0, leftRowIndicatorColumn); |
| 106 detectionResult->setDetectionResultColumn(maxBarcodeColumn, | 107 detectionResult->setDetectionResultColumn(maxBarcodeColumn, |
| 107 rightRowIndicatorColumn); | 108 rightRowIndicatorColumn); |
| 108 FX_BOOL leftToRight = leftRowIndicatorColumn != NULL; | 109 FX_BOOL leftToRight = !!leftRowIndicatorColumn; |
| 109 for (int32_t barcodeColumnCount = 1; barcodeColumnCount <= maxBarcodeColumn; | 110 for (int32_t barcodeColumnCount = 1; barcodeColumnCount <= maxBarcodeColumn; |
| 110 barcodeColumnCount++) { | 111 barcodeColumnCount++) { |
| 111 int32_t barcodeColumn = leftToRight ? barcodeColumnCount | 112 int32_t barcodeColumn = leftToRight ? barcodeColumnCount |
| 112 : maxBarcodeColumn - barcodeColumnCount; | 113 : maxBarcodeColumn - barcodeColumnCount; |
| 113 if (detectionResult->getDetectionResultColumn(barcodeColumn)) { | 114 if (detectionResult->getDetectionResultColumn(barcodeColumn)) { |
| 114 continue; | 115 continue; |
| 115 } | 116 } |
| 116 CBC_DetectionResultColumn* detectionResultColumn = NULL; | 117 CBC_DetectionResultColumn* detectionResultColumn = nullptr; |
| 117 if (barcodeColumn == 0 || barcodeColumn == maxBarcodeColumn) { | 118 if (barcodeColumn == 0 || barcodeColumn == maxBarcodeColumn) { |
| 118 detectionResultColumn = new CBC_DetectionResultRowIndicatorColumn( | 119 detectionResultColumn = new CBC_DetectionResultRowIndicatorColumn( |
| 119 boundingBox, barcodeColumn == 0); | 120 boundingBox, barcodeColumn == 0); |
| 120 } else { | 121 } else { |
| 121 detectionResultColumn = new CBC_DetectionResultColumn(boundingBox); | 122 detectionResultColumn = new CBC_DetectionResultColumn(boundingBox); |
| 122 } | 123 } |
| 123 detectionResult->setDetectionResultColumn(barcodeColumn, | 124 detectionResult->setDetectionResultColumn(barcodeColumn, |
| 124 detectionResultColumn); | 125 detectionResultColumn); |
| 125 int32_t startColumn = -1; | 126 int32_t startColumn = -1; |
| 126 int32_t previousStartColumn = startColumn; | 127 int32_t previousStartColumn = startColumn; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 146 maxCodewordWidth = maxCodewordWidth > codeword->getWidth() | 147 maxCodewordWidth = maxCodewordWidth > codeword->getWidth() |
| 147 ? maxCodewordWidth | 148 ? maxCodewordWidth |
| 148 : codeword->getWidth(); | 149 : codeword->getWidth(); |
| 149 } | 150 } |
| 150 } | 151 } |
| 151 } | 152 } |
| 152 CBC_CommonDecoderResult* decoderresult = | 153 CBC_CommonDecoderResult* decoderresult = |
| 153 createDecoderResult(detectionResult, e); | 154 createDecoderResult(detectionResult, e); |
| 154 if (e != BCExceptionNO) { | 155 if (e != BCExceptionNO) { |
| 155 delete detectionResult; | 156 delete detectionResult; |
| 156 return NULL; | 157 return nullptr; |
| 157 } | 158 } |
| 158 return decoderresult; | 159 return decoderresult; |
| 159 } | 160 } |
| 160 | 161 |
| 161 CFX_ByteString CBC_PDF417ScanningDecoder::toString( | 162 CFX_ByteString CBC_PDF417ScanningDecoder::toString( |
| 162 CBC_BarcodeValueArrayArray* barcodeMatrix) { | 163 CBC_BarcodeValueArrayArray* barcodeMatrix) { |
| 163 CFX_ByteString result; | 164 CFX_ByteString result; |
| 164 for (int32_t row = 0; row < barcodeMatrix->GetSize(); row++) { | 165 for (int32_t row = 0; row < barcodeMatrix->GetSize(); row++) { |
| 165 result += row; | 166 result += row; |
| 166 for (int32_t l = 0; l < barcodeMatrix->GetAt(row)->GetSize(); l++) { | 167 for (int32_t l = 0; l < barcodeMatrix->GetAt(row)->GetSize(); l++) { |
| 167 CBC_BarcodeValue* barcodeValue = barcodeMatrix->GetAt(row)->GetAt(l); | 168 CBC_BarcodeValue* barcodeValue = barcodeMatrix->GetAt(row)->GetAt(l); |
| 168 if (barcodeValue->getValue()->GetSize() == 0) { | 169 if (barcodeValue->getValue()->GetSize() == 0) { |
| 169 result += ""; | 170 result += ""; |
| 170 } else { | 171 } else { |
| 171 result += barcodeValue->getValue()->GetAt(0); | 172 result += barcodeValue->getValue()->GetAt(0); |
| 172 result += | 173 result += |
| 173 barcodeValue->getConfidence(barcodeValue->getValue()->GetAt(0)); | 174 barcodeValue->getConfidence(barcodeValue->getValue()->GetAt(0)); |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 } | 177 } |
| 177 return result; | 178 return result; |
| 178 } | 179 } |
| 179 | 180 |
| 180 CBC_DetectionResult* CBC_PDF417ScanningDecoder::merge( | 181 CBC_DetectionResult* CBC_PDF417ScanningDecoder::merge( |
| 181 CBC_DetectionResultRowIndicatorColumn* leftRowIndicatorColumn, | 182 CBC_DetectionResultRowIndicatorColumn* leftRowIndicatorColumn, |
| 182 CBC_DetectionResultRowIndicatorColumn* rightRowIndicatorColumn, | 183 CBC_DetectionResultRowIndicatorColumn* rightRowIndicatorColumn, |
| 183 int32_t& e) { | 184 int32_t& e) { |
| 184 if (leftRowIndicatorColumn == NULL && rightRowIndicatorColumn == NULL) { | 185 if (!leftRowIndicatorColumn && !rightRowIndicatorColumn) { |
| 185 e = BCExceptionIllegalArgument; | 186 e = BCExceptionIllegalArgument; |
| 186 return NULL; | 187 return nullptr; |
| 187 } | 188 } |
| 188 CBC_BarcodeMetadata* barcodeMetadata = | 189 CBC_BarcodeMetadata* barcodeMetadata = |
| 189 getBarcodeMetadata(leftRowIndicatorColumn, rightRowIndicatorColumn); | 190 getBarcodeMetadata(leftRowIndicatorColumn, rightRowIndicatorColumn); |
| 190 if (barcodeMetadata == NULL) { | 191 if (!barcodeMetadata) { |
| 191 e = BCExceptionCannotMetadata; | 192 e = BCExceptionCannotMetadata; |
| 192 return NULL; | 193 return nullptr; |
| 193 } | 194 } |
| 194 CBC_BoundingBox* leftboundingBox = | 195 CBC_BoundingBox* leftboundingBox = |
| 195 adjustBoundingBox(leftRowIndicatorColumn, e); | 196 adjustBoundingBox(leftRowIndicatorColumn, e); |
| 196 if (e != BCExceptionNO) { | 197 if (e != BCExceptionNO) { |
| 197 delete barcodeMetadata; | 198 delete barcodeMetadata; |
| 198 return NULL; | 199 return nullptr; |
| 199 } | 200 } |
| 200 CBC_BoundingBox* rightboundingBox = | 201 CBC_BoundingBox* rightboundingBox = |
| 201 adjustBoundingBox(rightRowIndicatorColumn, e); | 202 adjustBoundingBox(rightRowIndicatorColumn, e); |
| 202 if (e != BCExceptionNO) { | 203 if (e != BCExceptionNO) { |
| 203 delete barcodeMetadata; | 204 delete barcodeMetadata; |
| 204 return NULL; | 205 return nullptr; |
| 205 } | 206 } |
| 206 CBC_BoundingBox* boundingBox = | 207 CBC_BoundingBox* boundingBox = |
| 207 CBC_BoundingBox::merge(leftboundingBox, rightboundingBox, e); | 208 CBC_BoundingBox::merge(leftboundingBox, rightboundingBox, e); |
| 208 if (e != BCExceptionNO) { | 209 if (e != BCExceptionNO) { |
| 209 delete barcodeMetadata; | 210 delete barcodeMetadata; |
| 210 return NULL; | 211 return nullptr; |
| 211 } | 212 } |
| 212 CBC_DetectionResult* detectionresult = | 213 CBC_DetectionResult* detectionresult = |
| 213 new CBC_DetectionResult(barcodeMetadata, boundingBox); | 214 new CBC_DetectionResult(barcodeMetadata, boundingBox); |
| 214 return detectionresult; | 215 return detectionresult; |
| 215 } | 216 } |
| 216 CBC_BoundingBox* CBC_PDF417ScanningDecoder::adjustBoundingBox( | 217 CBC_BoundingBox* CBC_PDF417ScanningDecoder::adjustBoundingBox( |
| 217 CBC_DetectionResultRowIndicatorColumn* rowIndicatorColumn, | 218 CBC_DetectionResultRowIndicatorColumn* rowIndicatorColumn, |
| 218 int32_t& e) { | 219 int32_t& e) { |
| 219 if (rowIndicatorColumn == NULL) { | 220 if (!rowIndicatorColumn) |
| 220 return NULL; | 221 return nullptr; |
| 221 } | 222 |
| 222 CFX_Int32Array* rowHeights = rowIndicatorColumn->getRowHeights(e); | 223 CFX_Int32Array* rowHeights = rowIndicatorColumn->getRowHeights(e); |
| 223 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 224 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 224 int32_t maxRowHeight = getMax(*rowHeights); | 225 int32_t maxRowHeight = getMax(*rowHeights); |
| 225 int32_t missingStartRows = 0; | 226 int32_t missingStartRows = 0; |
| 226 for (int32_t i = 0; i < rowHeights->GetSize(); i++) { | 227 for (int32_t i = 0; i < rowHeights->GetSize(); i++) { |
| 227 int32_t rowHeight = rowHeights->GetAt(i); | 228 int32_t rowHeight = rowHeights->GetAt(i); |
| 228 missingStartRows += maxRowHeight - rowHeight; | 229 missingStartRows += maxRowHeight - rowHeight; |
| 229 if (rowHeight > 0) { | 230 if (rowHeight > 0) { |
| 230 break; | 231 break; |
| 231 } | 232 } |
| 232 } | 233 } |
| 233 CFX_ArrayTemplate<CBC_Codeword*>* codewords = | 234 CFX_ArrayTemplate<CBC_Codeword*>* codewords = |
| 234 rowIndicatorColumn->getCodewords(); | 235 rowIndicatorColumn->getCodewords(); |
| 235 for (int32_t row = 0; missingStartRows > 0 && codewords->GetAt(row) == NULL; | 236 for (int32_t row = 0; missingStartRows > 0 && !codewords->GetAt(row); row++) { |
| 236 row++) { | |
| 237 missingStartRows--; | 237 missingStartRows--; |
| 238 } | 238 } |
| 239 int32_t missingEndRows = 0; | 239 int32_t missingEndRows = 0; |
| 240 for (int32_t row1 = rowHeights->GetSize() - 1; row1 >= 0; row1--) { | 240 for (int32_t row1 = rowHeights->GetSize() - 1; row1 >= 0; row1--) { |
| 241 missingEndRows += maxRowHeight - rowHeights->GetAt(row1); | 241 missingEndRows += maxRowHeight - rowHeights->GetAt(row1); |
| 242 if (rowHeights->GetAt(row1) > 0) { | 242 if (rowHeights->GetAt(row1) > 0) { |
| 243 break; | 243 break; |
| 244 } | 244 } |
| 245 } | 245 } |
| 246 for (int32_t row2 = codewords->GetSize() - 1; | 246 for (int32_t row2 = codewords->GetSize() - 1; |
| 247 missingEndRows > 0 && codewords->GetAt(row2) == NULL; row2--) { | 247 missingEndRows > 0 && !codewords->GetAt(row2); row2--) { |
| 248 missingEndRows--; | 248 missingEndRows--; |
| 249 } | 249 } |
| 250 CBC_BoundingBox* boundingBox = | 250 CBC_BoundingBox* boundingBox = |
| 251 rowIndicatorColumn->getBoundingBox()->addMissingRows( | 251 rowIndicatorColumn->getBoundingBox()->addMissingRows( |
| 252 missingStartRows, missingEndRows, rowIndicatorColumn->isLeft(), e); | 252 missingStartRows, missingEndRows, rowIndicatorColumn->isLeft(), e); |
| 253 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 253 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 254 return boundingBox; | 254 return boundingBox; |
| 255 } | 255 } |
| 256 int32_t CBC_PDF417ScanningDecoder::getMax(CFX_Int32Array& values) { | 256 int32_t CBC_PDF417ScanningDecoder::getMax(CFX_Int32Array& values) { |
| 257 int32_t maxValue = -1; | 257 int32_t maxValue = -1; |
| 258 for (int32_t i = 0; i < values.GetSize(); i++) { | 258 for (int32_t i = 0; i < values.GetSize(); i++) { |
| 259 int32_t value = values.GetAt(i); | 259 int32_t value = values.GetAt(i); |
| 260 maxValue = maxValue > value ? maxValue : value; | 260 maxValue = maxValue > value ? maxValue : value; |
| 261 } | 261 } |
| 262 return maxValue; | 262 return maxValue; |
| 263 } | 263 } |
| 264 CBC_BarcodeMetadata* CBC_PDF417ScanningDecoder::getBarcodeMetadata( | 264 CBC_BarcodeMetadata* CBC_PDF417ScanningDecoder::getBarcodeMetadata( |
| 265 CBC_DetectionResultRowIndicatorColumn* leftRowIndicatorColumn, | 265 CBC_DetectionResultRowIndicatorColumn* leftRowIndicatorColumn, |
| 266 CBC_DetectionResultRowIndicatorColumn* rightRowIndicatorColumn) { | 266 CBC_DetectionResultRowIndicatorColumn* rightRowIndicatorColumn) { |
| 267 CBC_BarcodeMetadata* leftBarcodeMetadata = NULL; | 267 CBC_BarcodeMetadata* leftBarcodeMetadata = |
| 268 CBC_BarcodeMetadata* rightBarcodeMetadata = NULL; | 268 leftRowIndicatorColumn ? leftRowIndicatorColumn->getBarcodeMetadata() |
| 269 if (leftRowIndicatorColumn == NULL || | 269 : nullptr; |
| 270 (leftBarcodeMetadata = leftRowIndicatorColumn->getBarcodeMetadata()) == | 270 if (!leftBarcodeMetadata) { |
| 271 NULL) { | 271 return rightRowIndicatorColumn |
| 272 return rightRowIndicatorColumn == NULL | 272 ? rightRowIndicatorColumn->getBarcodeMetadata() |
| 273 ? NULL | 273 : nullptr; |
| 274 : rightRowIndicatorColumn->getBarcodeMetadata(); | |
| 275 } | 274 } |
| 276 if (rightRowIndicatorColumn == NULL || | 275 |
| 277 (rightBarcodeMetadata = rightRowIndicatorColumn->getBarcodeMetadata()) == | 276 CBC_BarcodeMetadata* rightBarcodeMetadata = |
| 278 NULL) { | 277 rightRowIndicatorColumn ? rightRowIndicatorColumn->getBarcodeMetadata() |
| 279 return leftRowIndicatorColumn == NULL | 278 : nullptr; |
| 280 ? NULL | 279 if (!rightBarcodeMetadata) { |
| 281 : leftRowIndicatorColumn->getBarcodeMetadata(); | 280 return leftRowIndicatorColumn ? leftRowIndicatorColumn->getBarcodeMetadata() |
| 281 : nullptr; |
| 282 } | 282 } |
| 283 |
| 283 if (leftBarcodeMetadata->getColumnCount() != | 284 if (leftBarcodeMetadata->getColumnCount() != |
| 284 rightBarcodeMetadata->getColumnCount() && | 285 rightBarcodeMetadata->getColumnCount() && |
| 285 leftBarcodeMetadata->getErrorCorrectionLevel() != | 286 leftBarcodeMetadata->getErrorCorrectionLevel() != |
| 286 rightBarcodeMetadata->getErrorCorrectionLevel() && | 287 rightBarcodeMetadata->getErrorCorrectionLevel() && |
| 287 leftBarcodeMetadata->getRowCount() != | 288 leftBarcodeMetadata->getRowCount() != |
| 288 rightBarcodeMetadata->getRowCount()) { | 289 rightBarcodeMetadata->getRowCount()) { |
| 289 delete leftBarcodeMetadata; | 290 delete leftBarcodeMetadata; |
| 290 delete rightBarcodeMetadata; | 291 delete rightBarcodeMetadata; |
| 291 return NULL; | 292 return nullptr; |
| 292 } | 293 } |
| 293 delete rightBarcodeMetadata; | 294 delete rightBarcodeMetadata; |
| 294 return leftBarcodeMetadata; | 295 return leftBarcodeMetadata; |
| 295 } | 296 } |
| 296 CBC_DetectionResultRowIndicatorColumn* | 297 CBC_DetectionResultRowIndicatorColumn* |
| 297 CBC_PDF417ScanningDecoder::getRowIndicatorColumn(CBC_CommonBitMatrix* image, | 298 CBC_PDF417ScanningDecoder::getRowIndicatorColumn(CBC_CommonBitMatrix* image, |
| 298 CBC_BoundingBox* boundingBox, | 299 CBC_BoundingBox* boundingBox, |
| 299 CBC_ResultPoint startPoint, | 300 CBC_ResultPoint startPoint, |
| 300 FX_BOOL leftToRight, | 301 FX_BOOL leftToRight, |
| 301 int32_t minCodewordWidth, | 302 int32_t minCodewordWidth, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 } else { | 440 } else { |
| 440 ambiguousIndexCount[i] = 0; | 441 ambiguousIndexCount[i] = 0; |
| 441 if (i == ambiguousIndexCount.GetSize() - 1) { | 442 if (i == ambiguousIndexCount.GetSize() - 1) { |
| 442 e = BCExceptionChecksumInstance; | 443 e = BCExceptionChecksumInstance; |
| 443 return nullptr; | 444 return nullptr; |
| 444 } | 445 } |
| 445 } | 446 } |
| 446 } | 447 } |
| 447 } | 448 } |
| 448 e = BCExceptionChecksumInstance; | 449 e = BCExceptionChecksumInstance; |
| 449 return NULL; | 450 return nullptr; |
| 450 } | 451 } |
| 451 CBC_BarcodeValueArrayArray* CBC_PDF417ScanningDecoder::createBarcodeMatrix( | 452 CBC_BarcodeValueArrayArray* CBC_PDF417ScanningDecoder::createBarcodeMatrix( |
| 452 CBC_DetectionResult* detectionResult) { | 453 CBC_DetectionResult* detectionResult) { |
| 453 CBC_BarcodeValueArrayArray* barcodeMatrix = new CBC_BarcodeValueArrayArray; | 454 CBC_BarcodeValueArrayArray* barcodeMatrix = new CBC_BarcodeValueArrayArray; |
| 454 barcodeMatrix->SetSize(detectionResult->getBarcodeRowCount()); | 455 barcodeMatrix->SetSize(detectionResult->getBarcodeRowCount()); |
| 455 for (int32_t row = 0; row < barcodeMatrix->GetSize(); row++) { | 456 for (int32_t row = 0; row < barcodeMatrix->GetSize(); row++) { |
| 456 CBC_BarcodeValueArray* temp = new CBC_BarcodeValueArray; | 457 CBC_BarcodeValueArray* temp = new CBC_BarcodeValueArray; |
| 457 temp->SetSize(detectionResult->getBarcodeColumnCount() + 2); | 458 temp->SetSize(detectionResult->getBarcodeColumnCount() + 2); |
| 458 for (int32_t column = 0; | 459 for (int32_t column = 0; |
| 459 column < detectionResult->getBarcodeColumnCount() + 2; column++) { | 460 column < detectionResult->getBarcodeColumnCount() + 2; column++) { |
| 460 temp->SetAt(column, new CBC_BarcodeValue()); | 461 temp->SetAt(column, new CBC_BarcodeValue()); |
| 461 } | 462 } |
| 462 barcodeMatrix->SetAt(row, temp); | 463 barcodeMatrix->SetAt(row, temp); |
| 463 } | 464 } |
| 464 for (int32_t i = 0; | 465 for (int32_t i = 0; |
| 465 i < detectionResult->getDetectionResultColumns().GetSize(); i++) { | 466 i < detectionResult->getDetectionResultColumns().GetSize(); i++) { |
| 466 CBC_DetectionResultColumn* detectionResultColumn = | 467 CBC_DetectionResultColumn* detectionResultColumn = |
| 467 (CBC_DetectionResultColumn*)detectionResult->getDetectionResultColumns() | 468 (CBC_DetectionResultColumn*)detectionResult->getDetectionResultColumns() |
| 468 .GetAt(i); | 469 .GetAt(i); |
| 469 if (detectionResultColumn == NULL) { | 470 if (!detectionResultColumn) |
| 470 continue; | 471 continue; |
| 471 } | 472 |
| 472 CFX_ArrayTemplate<CBC_Codeword*>* temp = | 473 CFX_ArrayTemplate<CBC_Codeword*>* temp = |
| 473 detectionResultColumn->getCodewords(); | 474 detectionResultColumn->getCodewords(); |
| 474 for (int32_t l = 0; l < temp->GetSize(); l++) { | 475 for (int32_t l = 0; l < temp->GetSize(); l++) { |
| 475 CBC_Codeword* codeword = temp->GetAt(l); | 476 CBC_Codeword* codeword = temp->GetAt(l); |
| 476 if (codeword == NULL || codeword->getRowNumber() == -1) { | 477 if (!codeword || codeword->getRowNumber() == -1) |
| 477 continue; | 478 continue; |
| 478 } | 479 |
| 479 barcodeMatrix->GetAt(codeword->getRowNumber()) | 480 barcodeMatrix->GetAt(codeword->getRowNumber()) |
| 480 ->GetAt(i) | 481 ->GetAt(i) |
| 481 ->setValue(codeword->getValue()); | 482 ->setValue(codeword->getValue()); |
| 482 } | 483 } |
| 483 } | 484 } |
| 484 return barcodeMatrix; | 485 return barcodeMatrix; |
| 485 } | 486 } |
| 486 FX_BOOL CBC_PDF417ScanningDecoder::isValidBarcodeColumn( | 487 FX_BOOL CBC_PDF417ScanningDecoder::isValidBarcodeColumn( |
| 487 CBC_DetectionResult* detectionResult, | 488 CBC_DetectionResult* detectionResult, |
| 488 int32_t barcodeColumn) { | 489 int32_t barcodeColumn) { |
| 489 return barcodeColumn >= 0 && | 490 return barcodeColumn >= 0 && |
| 490 barcodeColumn <= detectionResult->getBarcodeColumnCount() + 1; | 491 barcodeColumn <= detectionResult->getBarcodeColumnCount() + 1; |
| 491 } | 492 } |
| 492 int32_t CBC_PDF417ScanningDecoder::getStartColumn( | 493 int32_t CBC_PDF417ScanningDecoder::getStartColumn( |
| 493 CBC_DetectionResult* detectionResult, | 494 CBC_DetectionResult* detectionResult, |
| 494 int32_t barcodeColumn, | 495 int32_t barcodeColumn, |
| 495 int32_t imageRow, | 496 int32_t imageRow, |
| 496 FX_BOOL leftToRight) { | 497 FX_BOOL leftToRight) { |
| 497 int32_t offset = leftToRight ? 1 : -1; | 498 int32_t offset = leftToRight ? 1 : -1; |
| 498 CBC_Codeword* codeword = NULL; | 499 CBC_Codeword* codeword = nullptr; |
| 499 if (isValidBarcodeColumn(detectionResult, barcodeColumn - offset)) { | 500 if (isValidBarcodeColumn(detectionResult, barcodeColumn - offset)) { |
| 500 codeword = detectionResult->getDetectionResultColumn(barcodeColumn - offset) | 501 codeword = detectionResult->getDetectionResultColumn(barcodeColumn - offset) |
| 501 ->getCodeword(imageRow); | 502 ->getCodeword(imageRow); |
| 502 } | 503 } |
| 503 if (codeword) { | 504 if (codeword) { |
| 504 return leftToRight ? codeword->getEndX() : codeword->getStartX(); | 505 return leftToRight ? codeword->getEndX() : codeword->getStartX(); |
| 505 } | 506 } |
| 506 codeword = detectionResult->getDetectionResultColumn(barcodeColumn) | 507 codeword = detectionResult->getDetectionResultColumn(barcodeColumn) |
| 507 ->getCodewordNearby(imageRow); | 508 ->getCodewordNearby(imageRow); |
| 508 if (codeword) { | 509 if (codeword) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 int32_t maxColumn, | 547 int32_t maxColumn, |
| 547 FX_BOOL leftToRight, | 548 FX_BOOL leftToRight, |
| 548 int32_t startColumn, | 549 int32_t startColumn, |
| 549 int32_t imageRow, | 550 int32_t imageRow, |
| 550 int32_t minCodewordWidth, | 551 int32_t minCodewordWidth, |
| 551 int32_t maxCodewordWidth) { | 552 int32_t maxCodewordWidth) { |
| 552 startColumn = adjustCodewordStartColumn(image, minColumn, maxColumn, | 553 startColumn = adjustCodewordStartColumn(image, minColumn, maxColumn, |
| 553 leftToRight, startColumn, imageRow); | 554 leftToRight, startColumn, imageRow); |
| 554 CFX_Int32Array* moduleBitCount = getModuleBitCount( | 555 CFX_Int32Array* moduleBitCount = getModuleBitCount( |
| 555 image, minColumn, maxColumn, leftToRight, startColumn, imageRow); | 556 image, minColumn, maxColumn, leftToRight, startColumn, imageRow); |
| 556 if (moduleBitCount == NULL) { | 557 if (!moduleBitCount) |
| 557 return NULL; | 558 return nullptr; |
| 558 } | 559 |
| 559 int32_t endColumn; | 560 int32_t endColumn; |
| 560 int32_t codewordBitCount = CBC_PDF417Common::getBitCountSum(*moduleBitCount); | 561 int32_t codewordBitCount = CBC_PDF417Common::getBitCountSum(*moduleBitCount); |
| 561 if (leftToRight) { | 562 if (leftToRight) { |
| 562 endColumn = startColumn + codewordBitCount; | 563 endColumn = startColumn + codewordBitCount; |
| 563 } else { | 564 } else { |
| 564 for (int32_t i = 0; i<moduleBitCount->GetSize()>> 1; i++) { | 565 for (int32_t i = 0; i<moduleBitCount->GetSize()>> 1; i++) { |
| 565 int32_t tmpCount = moduleBitCount->GetAt(i); | 566 int32_t tmpCount = moduleBitCount->GetAt(i); |
| 566 moduleBitCount->SetAt( | 567 moduleBitCount->SetAt( |
| 567 i, moduleBitCount->GetAt(moduleBitCount->GetSize() - 1 - i)); | 568 i, moduleBitCount->GetAt(moduleBitCount->GetSize() - 1 - i)); |
| 568 moduleBitCount->SetAt(moduleBitCount->GetSize() - 1 - i, tmpCount); | 569 moduleBitCount->SetAt(moduleBitCount->GetSize() - 1 - i, tmpCount); |
| 569 } | 570 } |
| 570 endColumn = startColumn; | 571 endColumn = startColumn; |
| 571 startColumn = endColumn - codewordBitCount; | 572 startColumn = endColumn - codewordBitCount; |
| 572 } | 573 } |
| 573 int32_t decodedValue = | 574 int32_t decodedValue = |
| 574 CBC_PDF417CodewordDecoder::getDecodedValue(*moduleBitCount); | 575 CBC_PDF417CodewordDecoder::getDecodedValue(*moduleBitCount); |
| 575 int32_t codeword = CBC_PDF417Common::getCodeword(decodedValue); | 576 int32_t codeword = CBC_PDF417Common::getCodeword(decodedValue); |
| 576 delete moduleBitCount; | 577 delete moduleBitCount; |
| 577 if (codeword == -1) { | 578 if (codeword == -1) { |
| 578 return NULL; | 579 return nullptr; |
| 579 } | 580 } |
| 580 return new CBC_Codeword(startColumn, endColumn, | 581 return new CBC_Codeword(startColumn, endColumn, |
| 581 getCodewordBucketNumber(decodedValue), codeword); | 582 getCodewordBucketNumber(decodedValue), codeword); |
| 582 } | 583 } |
| 583 CFX_Int32Array* CBC_PDF417ScanningDecoder::getModuleBitCount( | 584 CFX_Int32Array* CBC_PDF417ScanningDecoder::getModuleBitCount( |
| 584 CBC_CommonBitMatrix* image, | 585 CBC_CommonBitMatrix* image, |
| 585 int32_t minColumn, | 586 int32_t minColumn, |
| 586 int32_t maxColumn, | 587 int32_t maxColumn, |
| 587 FX_BOOL leftToRight, | 588 FX_BOOL leftToRight, |
| 588 int32_t startColumn, | 589 int32_t startColumn, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 605 previousPixelValue = !previousPixelValue; | 606 previousPixelValue = !previousPixelValue; |
| 606 } | 607 } |
| 607 } | 608 } |
| 608 if (moduleNumber == moduleBitCount->GetSize() || | 609 if (moduleNumber == moduleBitCount->GetSize() || |
| 609 (((leftToRight && imageColumn == maxColumn) || | 610 (((leftToRight && imageColumn == maxColumn) || |
| 610 (!leftToRight && imageColumn == minColumn)) && | 611 (!leftToRight && imageColumn == minColumn)) && |
| 611 moduleNumber == moduleBitCount->GetSize() - 1)) { | 612 moduleNumber == moduleBitCount->GetSize() - 1)) { |
| 612 return moduleBitCount; | 613 return moduleBitCount; |
| 613 } | 614 } |
| 614 delete moduleBitCount; | 615 delete moduleBitCount; |
| 615 return NULL; | 616 return nullptr; |
| 616 } | 617 } |
| 617 int32_t CBC_PDF417ScanningDecoder::getNumberOfECCodeWords( | 618 int32_t CBC_PDF417ScanningDecoder::getNumberOfECCodeWords( |
| 618 int32_t barcodeECLevel) { | 619 int32_t barcodeECLevel) { |
| 619 return 2 << barcodeECLevel; | 620 return 2 << barcodeECLevel; |
| 620 } | 621 } |
| 621 int32_t CBC_PDF417ScanningDecoder::adjustCodewordStartColumn( | 622 int32_t CBC_PDF417ScanningDecoder::adjustCodewordStartColumn( |
| 622 CBC_CommonBitMatrix* image, | 623 CBC_CommonBitMatrix* image, |
| 623 int32_t minColumn, | 624 int32_t minColumn, |
| 624 int32_t maxColumn, | 625 int32_t maxColumn, |
| 625 FX_BOOL leftToRight, | 626 FX_BOOL leftToRight, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 648 return minCodewordWidth - CODEWORD_SKEW_SIZE <= codewordSize && | 649 return minCodewordWidth - CODEWORD_SKEW_SIZE <= codewordSize && |
| 649 codewordSize <= maxCodewordWidth + CODEWORD_SKEW_SIZE; | 650 codewordSize <= maxCodewordWidth + CODEWORD_SKEW_SIZE; |
| 650 } | 651 } |
| 651 CBC_CommonDecoderResult* CBC_PDF417ScanningDecoder::decodeCodewords( | 652 CBC_CommonDecoderResult* CBC_PDF417ScanningDecoder::decodeCodewords( |
| 652 CFX_Int32Array& codewords, | 653 CFX_Int32Array& codewords, |
| 653 int32_t ecLevel, | 654 int32_t ecLevel, |
| 654 CFX_Int32Array& erasures, | 655 CFX_Int32Array& erasures, |
| 655 int32_t& e) { | 656 int32_t& e) { |
| 656 if (codewords.GetSize() == 0) { | 657 if (codewords.GetSize() == 0) { |
| 657 e = BCExceptionFormatInstance; | 658 e = BCExceptionFormatInstance; |
| 658 return NULL; | 659 return nullptr; |
| 659 } | 660 } |
| 660 int32_t numECCodewords = 1 << (ecLevel + 1); | 661 int32_t numECCodewords = 1 << (ecLevel + 1); |
| 661 correctErrors(codewords, erasures, numECCodewords, e); | 662 correctErrors(codewords, erasures, numECCodewords, e); |
| 662 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 663 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 663 verifyCodewordCount(codewords, numECCodewords, e); | 664 verifyCodewordCount(codewords, numECCodewords, e); |
| 664 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 665 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 665 CFX_ByteString bytestring; | 666 CFX_ByteString bytestring; |
| 666 CBC_CommonDecoderResult* decoderResult = CBC_DecodedBitStreamPaser::decode( | 667 CBC_CommonDecoderResult* decoderResult = CBC_DecodedBitStreamPaser::decode( |
| 667 codewords, bytestring.FormatInteger(ecLevel), e); | 668 codewords, bytestring.FormatInteger(ecLevel), e); |
| 668 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 669 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 669 return decoderResult; | 670 return decoderResult; |
| 670 } | 671 } |
| 671 int32_t CBC_PDF417ScanningDecoder::correctErrors(CFX_Int32Array& codewords, | 672 int32_t CBC_PDF417ScanningDecoder::correctErrors(CFX_Int32Array& codewords, |
| 672 CFX_Int32Array& erasures, | 673 CFX_Int32Array& erasures, |
| 673 int32_t numECCodewords, | 674 int32_t numECCodewords, |
| 674 int32_t& e) { | 675 int32_t& e) { |
| 675 if ((erasures.GetSize() != 0 && | 676 if ((erasures.GetSize() != 0 && |
| 676 erasures.GetSize() > (numECCodewords / 2 + MAX_ERRORS)) || | 677 erasures.GetSize() > (numECCodewords / 2 + MAX_ERRORS)) || |
| 677 numECCodewords < 0 || numECCodewords > MAX_EC_CODEWORDS) { | 678 numECCodewords < 0 || numECCodewords > MAX_EC_CODEWORDS) { |
| 678 e = BCExceptionChecksumInstance; | 679 e = BCExceptionChecksumInstance; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 int32_t result = getCodewordBucketNumber(*array); | 729 int32_t result = getCodewordBucketNumber(*array); |
| 729 delete array; | 730 delete array; |
| 730 return result; | 731 return result; |
| 731 } | 732 } |
| 732 int32_t CBC_PDF417ScanningDecoder::getCodewordBucketNumber( | 733 int32_t CBC_PDF417ScanningDecoder::getCodewordBucketNumber( |
| 733 CFX_Int32Array& moduleBitCount) { | 734 CFX_Int32Array& moduleBitCount) { |
| 734 return (moduleBitCount.GetAt(0) - moduleBitCount.GetAt(2) + | 735 return (moduleBitCount.GetAt(0) - moduleBitCount.GetAt(2) + |
| 735 moduleBitCount.GetAt(4) - moduleBitCount.GetAt(6) + 9) % | 736 moduleBitCount.GetAt(4) - moduleBitCount.GetAt(6) + 9) % |
| 736 9; | 737 9; |
| 737 } | 738 } |
| OLD | NEW |