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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 int32_t minCodewordWidth, | 61 int32_t minCodewordWidth, |
62 int32_t maxCodewordWidth, | 62 int32_t maxCodewordWidth, |
63 int32_t& e) { | 63 int32_t& e) { |
64 CBC_BoundingBox* boundingBox = new CBC_BoundingBox( | 64 CBC_BoundingBox* boundingBox = new CBC_BoundingBox( |
65 image, imageTopLeft, imageBottomLeft, imageTopRight, imageBottomRight, e); | 65 image, imageTopLeft, imageBottomLeft, imageTopRight, imageBottomRight, e); |
66 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 66 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
67 CBC_DetectionResultRowIndicatorColumn* leftRowIndicatorColumn = NULL; | 67 CBC_DetectionResultRowIndicatorColumn* leftRowIndicatorColumn = NULL; |
68 CBC_DetectionResultRowIndicatorColumn* rightRowIndicatorColumn = NULL; | 68 CBC_DetectionResultRowIndicatorColumn* rightRowIndicatorColumn = NULL; |
69 CBC_DetectionResult* detectionResult = NULL; | 69 CBC_DetectionResult* detectionResult = NULL; |
70 for (int32_t i = 0; i < 2; i++) { | 70 for (int32_t i = 0; i < 2; i++) { |
71 if (imageTopLeft != NULL) { | 71 if (imageTopLeft) { |
72 leftRowIndicatorColumn = | 72 leftRowIndicatorColumn = |
73 getRowIndicatorColumn(image, boundingBox, *imageTopLeft, TRUE, | 73 getRowIndicatorColumn(image, boundingBox, *imageTopLeft, TRUE, |
74 minCodewordWidth, maxCodewordWidth); | 74 minCodewordWidth, maxCodewordWidth); |
75 } | 75 } |
76 if (imageTopRight != NULL) { | 76 if (imageTopRight) { |
77 rightRowIndicatorColumn = | 77 rightRowIndicatorColumn = |
78 getRowIndicatorColumn(image, boundingBox, *imageTopRight, FALSE, | 78 getRowIndicatorColumn(image, boundingBox, *imageTopRight, FALSE, |
79 minCodewordWidth, maxCodewordWidth); | 79 minCodewordWidth, maxCodewordWidth); |
80 } | 80 } |
81 detectionResult = merge(leftRowIndicatorColumn, rightRowIndicatorColumn, e); | 81 detectionResult = merge(leftRowIndicatorColumn, rightRowIndicatorColumn, e); |
82 if (e != BCExceptionNO) { | 82 if (e != BCExceptionNO) { |
83 e = BCExceptiontNotFoundInstance; | 83 e = BCExceptiontNotFoundInstance; |
84 delete leftRowIndicatorColumn; | 84 delete leftRowIndicatorColumn; |
85 delete rightRowIndicatorColumn; | 85 delete rightRowIndicatorColumn; |
86 delete boundingBox; | 86 delete boundingBox; |
(...skipping 12 matching lines...) Expand all Loading... |
99 } | 99 } |
100 int32_t maxBarcodeColumn = detectionResult->getBarcodeColumnCount() + 1; | 100 int32_t maxBarcodeColumn = detectionResult->getBarcodeColumnCount() + 1; |
101 detectionResult->setDetectionResultColumn(0, leftRowIndicatorColumn); | 101 detectionResult->setDetectionResultColumn(0, leftRowIndicatorColumn); |
102 detectionResult->setDetectionResultColumn(maxBarcodeColumn, | 102 detectionResult->setDetectionResultColumn(maxBarcodeColumn, |
103 rightRowIndicatorColumn); | 103 rightRowIndicatorColumn); |
104 FX_BOOL leftToRight = leftRowIndicatorColumn != NULL; | 104 FX_BOOL leftToRight = leftRowIndicatorColumn != NULL; |
105 for (int32_t barcodeColumnCount = 1; barcodeColumnCount <= maxBarcodeColumn; | 105 for (int32_t barcodeColumnCount = 1; barcodeColumnCount <= maxBarcodeColumn; |
106 barcodeColumnCount++) { | 106 barcodeColumnCount++) { |
107 int32_t barcodeColumn = leftToRight ? barcodeColumnCount | 107 int32_t barcodeColumn = leftToRight ? barcodeColumnCount |
108 : maxBarcodeColumn - barcodeColumnCount; | 108 : maxBarcodeColumn - barcodeColumnCount; |
109 if (detectionResult->getDetectionResultColumn(barcodeColumn) != NULL) { | 109 if (detectionResult->getDetectionResultColumn(barcodeColumn)) { |
110 continue; | 110 continue; |
111 } | 111 } |
112 CBC_DetectionResultColumn* detectionResultColumn = NULL; | 112 CBC_DetectionResultColumn* detectionResultColumn = NULL; |
113 if (barcodeColumn == 0 || barcodeColumn == maxBarcodeColumn) { | 113 if (barcodeColumn == 0 || barcodeColumn == maxBarcodeColumn) { |
114 detectionResultColumn = new CBC_DetectionResultRowIndicatorColumn( | 114 detectionResultColumn = new CBC_DetectionResultRowIndicatorColumn( |
115 boundingBox, barcodeColumn == 0); | 115 boundingBox, barcodeColumn == 0); |
116 } else { | 116 } else { |
117 detectionResultColumn = new CBC_DetectionResultColumn(boundingBox); | 117 detectionResultColumn = new CBC_DetectionResultColumn(boundingBox); |
118 } | 118 } |
119 detectionResult->setDetectionResultColumn(barcodeColumn, | 119 detectionResult->setDetectionResultColumn(barcodeColumn, |
120 detectionResultColumn); | 120 detectionResultColumn); |
121 int32_t startColumn = -1; | 121 int32_t startColumn = -1; |
122 int32_t previousStartColumn = startColumn; | 122 int32_t previousStartColumn = startColumn; |
123 for (int32_t imageRow = boundingBox->getMinY(); | 123 for (int32_t imageRow = boundingBox->getMinY(); |
124 imageRow <= boundingBox->getMaxY(); imageRow++) { | 124 imageRow <= boundingBox->getMaxY(); imageRow++) { |
125 startColumn = | 125 startColumn = |
126 getStartColumn(detectionResult, barcodeColumn, imageRow, leftToRight); | 126 getStartColumn(detectionResult, barcodeColumn, imageRow, leftToRight); |
127 if (startColumn < 0 || startColumn > boundingBox->getMaxX()) { | 127 if (startColumn < 0 || startColumn > boundingBox->getMaxX()) { |
128 if (previousStartColumn == -1) { | 128 if (previousStartColumn == -1) { |
129 continue; | 129 continue; |
130 } | 130 } |
131 startColumn = previousStartColumn; | 131 startColumn = previousStartColumn; |
132 } | 132 } |
133 CBC_Codeword* codeword = detectCodeword( | 133 CBC_Codeword* codeword = detectCodeword( |
134 image, boundingBox->getMinX(), boundingBox->getMaxX(), leftToRight, | 134 image, boundingBox->getMinX(), boundingBox->getMaxX(), leftToRight, |
135 startColumn, imageRow, minCodewordWidth, maxCodewordWidth); | 135 startColumn, imageRow, minCodewordWidth, maxCodewordWidth); |
136 if (codeword != NULL) { | 136 if (codeword) { |
137 detectionResultColumn->setCodeword(imageRow, codeword); | 137 detectionResultColumn->setCodeword(imageRow, codeword); |
138 previousStartColumn = startColumn; | 138 previousStartColumn = startColumn; |
139 minCodewordWidth = minCodewordWidth < codeword->getWidth() | 139 minCodewordWidth = minCodewordWidth < codeword->getWidth() |
140 ? minCodewordWidth | 140 ? minCodewordWidth |
141 : codeword->getWidth(); | 141 : codeword->getWidth(); |
142 maxCodewordWidth = maxCodewordWidth > codeword->getWidth() | 142 maxCodewordWidth = maxCodewordWidth > codeword->getWidth() |
143 ? maxCodewordWidth | 143 ? maxCodewordWidth |
144 : codeword->getWidth(); | 144 : codeword->getWidth(); |
145 } | 145 } |
146 } | 146 } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 for (int32_t i = 0; i < 2; i++) { | 301 for (int32_t i = 0; i < 2; i++) { |
302 int32_t increment = i == 0 ? 1 : -1; | 302 int32_t increment = i == 0 ? 1 : -1; |
303 int32_t startColumn = (int32_t)startPoint.GetX(); | 303 int32_t startColumn = (int32_t)startPoint.GetX(); |
304 for (int32_t imageRow = (int32_t)startPoint.GetY(); | 304 for (int32_t imageRow = (int32_t)startPoint.GetY(); |
305 imageRow <= boundingBox->getMaxY() && | 305 imageRow <= boundingBox->getMaxY() && |
306 imageRow >= boundingBox->getMinY(); | 306 imageRow >= boundingBox->getMinY(); |
307 imageRow += increment) { | 307 imageRow += increment) { |
308 CBC_Codeword* codeword = | 308 CBC_Codeword* codeword = |
309 detectCodeword(image, 0, image->GetWidth(), leftToRight, startColumn, | 309 detectCodeword(image, 0, image->GetWidth(), leftToRight, startColumn, |
310 imageRow, minCodewordWidth, maxCodewordWidth); | 310 imageRow, minCodewordWidth, maxCodewordWidth); |
311 if (codeword != NULL) { | 311 if (codeword) { |
312 rowIndicatorColumn->setCodeword(imageRow, codeword); | 312 rowIndicatorColumn->setCodeword(imageRow, codeword); |
313 if (leftToRight) { | 313 if (leftToRight) { |
314 startColumn = codeword->getStartX(); | 314 startColumn = codeword->getStartX(); |
315 } else { | 315 } else { |
316 startColumn = codeword->getEndX(); | 316 startColumn = codeword->getEndX(); |
317 } | 317 } |
318 } | 318 } |
319 } | 319 } |
320 } | 320 } |
321 return rowIndicatorColumn; | 321 return rowIndicatorColumn; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 CBC_DetectionResult* detectionResult, | 506 CBC_DetectionResult* detectionResult, |
507 int32_t barcodeColumn, | 507 int32_t barcodeColumn, |
508 int32_t imageRow, | 508 int32_t imageRow, |
509 FX_BOOL leftToRight) { | 509 FX_BOOL leftToRight) { |
510 int32_t offset = leftToRight ? 1 : -1; | 510 int32_t offset = leftToRight ? 1 : -1; |
511 CBC_Codeword* codeword = NULL; | 511 CBC_Codeword* codeword = NULL; |
512 if (isValidBarcodeColumn(detectionResult, barcodeColumn - offset)) { | 512 if (isValidBarcodeColumn(detectionResult, barcodeColumn - offset)) { |
513 codeword = detectionResult->getDetectionResultColumn(barcodeColumn - offset) | 513 codeword = detectionResult->getDetectionResultColumn(barcodeColumn - offset) |
514 ->getCodeword(imageRow); | 514 ->getCodeword(imageRow); |
515 } | 515 } |
516 if (codeword != NULL) { | 516 if (codeword) { |
517 return leftToRight ? codeword->getEndX() : codeword->getStartX(); | 517 return leftToRight ? codeword->getEndX() : codeword->getStartX(); |
518 } | 518 } |
519 codeword = detectionResult->getDetectionResultColumn(barcodeColumn) | 519 codeword = detectionResult->getDetectionResultColumn(barcodeColumn) |
520 ->getCodewordNearby(imageRow); | 520 ->getCodewordNearby(imageRow); |
521 if (codeword != NULL) { | 521 if (codeword) { |
522 return leftToRight ? codeword->getStartX() : codeword->getEndX(); | 522 return leftToRight ? codeword->getStartX() : codeword->getEndX(); |
523 } | 523 } |
524 if (isValidBarcodeColumn(detectionResult, barcodeColumn - offset)) { | 524 if (isValidBarcodeColumn(detectionResult, barcodeColumn - offset)) { |
525 codeword = detectionResult->getDetectionResultColumn(barcodeColumn - offset) | 525 codeword = detectionResult->getDetectionResultColumn(barcodeColumn - offset) |
526 ->getCodewordNearby(imageRow); | 526 ->getCodewordNearby(imageRow); |
527 } | 527 } |
528 if (codeword != NULL) { | 528 if (codeword) { |
529 return leftToRight ? codeword->getEndX() : codeword->getStartX(); | 529 return leftToRight ? codeword->getEndX() : codeword->getStartX(); |
530 } | 530 } |
531 int32_t skippedColumns = 0; | 531 int32_t skippedColumns = 0; |
532 while (isValidBarcodeColumn(detectionResult, barcodeColumn - offset)) { | 532 while (isValidBarcodeColumn(detectionResult, barcodeColumn - offset)) { |
533 barcodeColumn -= offset; | 533 barcodeColumn -= offset; |
534 for (int32_t i = 0; | 534 for (int32_t i = 0; |
535 i < detectionResult->getDetectionResultColumn(barcodeColumn) | 535 i < detectionResult->getDetectionResultColumn(barcodeColumn) |
536 ->getCodewords() | 536 ->getCodewords() |
537 ->GetSize(); | 537 ->GetSize(); |
538 i++) { | 538 i++) { |
539 CBC_Codeword* previousRowCodeword = | 539 CBC_Codeword* previousRowCodeword = |
540 (CBC_Codeword*)detectionResult->getDetectionResultColumn( | 540 (CBC_Codeword*)detectionResult->getDetectionResultColumn( |
541 barcodeColumn) | 541 barcodeColumn) |
542 ->getCodewords() | 542 ->getCodewords() |
543 ->GetAt(i); | 543 ->GetAt(i); |
544 if (previousRowCodeword != NULL) { | 544 if (previousRowCodeword) { |
545 return (leftToRight ? previousRowCodeword->getEndX() | 545 return (leftToRight ? previousRowCodeword->getEndX() |
546 : previousRowCodeword->getStartX()) + | 546 : previousRowCodeword->getStartX()) + |
547 offset * skippedColumns * (previousRowCodeword->getEndX() - | 547 offset * skippedColumns * (previousRowCodeword->getEndX() - |
548 previousRowCodeword->getStartX()); | 548 previousRowCodeword->getStartX()); |
549 } | 549 } |
550 } | 550 } |
551 skippedColumns++; | 551 skippedColumns++; |
552 } | 552 } |
553 return leftToRight ? detectionResult->getBoundingBox()->getMinX() | 553 return leftToRight ? detectionResult->getBoundingBox()->getMinX() |
554 : detectionResult->getBoundingBox()->getMaxX(); | 554 : detectionResult->getBoundingBox()->getMaxX(); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 int32_t result = getCodewordBucketNumber(*array); | 741 int32_t result = getCodewordBucketNumber(*array); |
742 delete array; | 742 delete array; |
743 return result; | 743 return result; |
744 } | 744 } |
745 int32_t CBC_PDF417ScanningDecoder::getCodewordBucketNumber( | 745 int32_t CBC_PDF417ScanningDecoder::getCodewordBucketNumber( |
746 CFX_Int32Array& moduleBitCount) { | 746 CFX_Int32Array& moduleBitCount) { |
747 return (moduleBitCount.GetAt(0) - moduleBitCount.GetAt(2) + | 747 return (moduleBitCount.GetAt(0) - moduleBitCount.GetAt(2) + |
748 moduleBitCount.GetAt(4) - moduleBitCount.GetAt(6) + 9) % | 748 moduleBitCount.GetAt(4) - moduleBitCount.GetAt(6) + 9) % |
749 9; | 749 9; |
750 } | 750 } |
OLD | NEW |