diff --git a/src/QZXing.cpp b/src/QZXing.cpp index 54a8f7d..61770d7 100644 --- a/src/QZXing.cpp +++ b/src/QZXing.cpp @@ -417,43 +417,34 @@ 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); + if(hints.containsFormat(BarcodeFormat::UPC_EAN_EXTENSION) && + !allowedExtensions_.empty() && + !(hints & DecodeHints::PRODUCT_HINT).isEmpty() ) + hints.setAllowedEanExtensions(std::set()); try { res = decoder->decode(bb, hints); processingTime = t.elapsed(); lastDecodeOperationSucceded_ = true; } catch(zxing::Exception &/*e*/) {} + } - if (!lastDecodeOperationSucceded_ && - hints.containsFormat(BarcodeFormat::UPC_EAN_EXTENSION) && - !allowedExtensions_.empty() && - !(hints & DecodeHints::PRODUCT_HINT).isEmpty() ) { - hints.setAllowedEanExtensions(std::set()); + if (!lastDecodeOperationSucceded_&& tryHarder_ && bb->isRotateSupported()) { + Ref bbTmp = bb; + + for (int i=0; (i<3 && !lastDecodeOperationSucceded_); i++) { + Ref rotatedImage(bbTmp->rotateCounterClockwise()); + bbTmp = rotatedImage; try { - res = decoder->decode(bb, hints); + res = decoder->decode(rotatedImage, hints); processingTime = t.elapsed(); lastDecodeOperationSucceded_ = true; } catch(zxing::Exception &/*e*/) {} } - - if (tryHarder_ && bb->isRotateSupported()) { - Ref bbTmp = bb; - - for (int i=0; (i<3 && !lastDecodeOperationSucceded_); i++) { - Ref rotatedImage(bbTmp->rotateCounterClockwise()); - bbTmp = rotatedImage; - - try { - res = decoder->decode(rotatedImage, hints); - processingTime = t.elapsed(); - lastDecodeOperationSucceded_ = true; - } catch(zxing::Exception &/*e*/) {} - } - } } if (lastDecodeOperationSucceded_) { @@ -604,11 +595,11 @@ QImage QZXing::encodeData(const QString &data, const QZXingEncoderConfig &encode data.toStdWString(), encoderConfig.errorCorrectionLevel == EncodeErrorCorrectionLevel_H ? qrcode::ErrorCorrectionLevel::H : - (encoderConfig.errorCorrectionLevel == EncodeErrorCorrectionLevel_Q ? - qrcode::ErrorCorrectionLevel::Q : - (encoderConfig.errorCorrectionLevel == EncodeErrorCorrectionLevel_M ? - qrcode::ErrorCorrectionLevel::M : - qrcode::ErrorCorrectionLevel::L))); + (encoderConfig.errorCorrectionLevel == EncodeErrorCorrectionLevel_Q ? + qrcode::ErrorCorrectionLevel::Q : + (encoderConfig.errorCorrectionLevel == EncodeErrorCorrectionLevel_M ? + qrcode::ErrorCorrectionLevel::M : + qrcode::ErrorCorrectionLevel::L))); Ref bytesRef = barcode->getMatrix(); const std::vector< std::vector >& bytes = bytesRef->getArray();