code cleanup in QZXing.cpp to properly respect 'tryHarder' operation and avoid executing extra decoding operations unless instacted. #151

This commit is contained in:
Nikos Ftylitakis 2020-01-24 20:08:04 +02:00
parent 6e14a1167f
commit f0a78867d6
1 changed files with 18 additions and 27 deletions

View File

@ -417,20 +417,12 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo
lastDecodeOperationSucceded_ = true;
} catch(zxing::Exception &/*e*/){}
if(!lastDecodeOperationSucceded_)
if(!lastDecodeOperationSucceded_ && tryHarder_)
{
hints.setTryHarder(true);
try {
res = decoder->decode(bb, hints);
processingTime = t.elapsed();
lastDecodeOperationSucceded_ = true;
} catch(zxing::Exception &/*e*/) {}
if (!lastDecodeOperationSucceded_ &&
hints.containsFormat(BarcodeFormat::UPC_EAN_EXTENSION) &&
if(hints.containsFormat(BarcodeFormat::UPC_EAN_EXTENSION) &&
!allowedExtensions_.empty() &&
!(hints & DecodeHints::PRODUCT_HINT).isEmpty() ) {
!(hints & DecodeHints::PRODUCT_HINT).isEmpty() )
hints.setAllowedEanExtensions(std::set<int>());
try {
@ -440,7 +432,7 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo
} catch(zxing::Exception &/*e*/) {}
}
if (tryHarder_ && bb->isRotateSupported()) {
if (!lastDecodeOperationSucceded_&& tryHarder_ && bb->isRotateSupported()) {
Ref<BinaryBitmap> bbTmp = bb;
for (int i=0; (i<3 && !lastDecodeOperationSucceded_); i++) {
@ -454,7 +446,6 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo
} catch(zxing::Exception &/*e*/) {}
}
}
}
if (lastDecodeOperationSucceded_) {
QString string = QString(res->getText()->getText().c_str());