minor fixes to the call of the decoding function.

This commit is contained in:
favoritas37 2015-04-26 14:11:54 +03:00
parent 357b658029
commit e317c87028
2 changed files with 13 additions and 6 deletions

View File

@ -78,7 +78,7 @@ public slots:
* The smoothTransformation flag determines whether the transformation will be smooth or fast. * The smoothTransformation flag determines whether the transformation will be smooth or fast.
* Smooth transformation provides better results but fast transformation is...faster. * Smooth transformation provides better results but fast transformation is...faster.
*/ */
QString decodeImage(QImage image, int maxWidth=-1, int maxHeight=-1, bool smoothTransformation = false); QString decodeImage(QImage &image, int maxWidth=-1, int maxHeight=-1, bool smoothTransformation = false);
/** /**
* The decoding function. Will try to decode the given image based on the enabled decoders. * The decoding function. Will try to decode the given image based on the enabled decoders.

View File

@ -95,7 +95,7 @@ void QZXing::setDecoder(const uint &hint)
emit enabledFormatsChanged(); emit enabledFormatsChanged();
} }
QString QZXing::decodeImage(QImage image, int maxWidth, int maxHeight, bool smoothTransformation) QString QZXing::decodeImage(QImage &image, int maxWidth, int maxHeight, bool smoothTransformation)
{ {
QTime t; QTime t;
t.start(); t.start();
@ -104,14 +104,15 @@ QString QZXing::decodeImage(QImage image, int maxWidth, int maxHeight, bool smoo
if(image.isNull()) if(image.isNull())
{ {
qDebug() << "Image Null";
emit decodingFinished(false); emit decodingFinished(false);
processingTime = -1; processingTime = -1;
return ""; return "";
} }
try{ CameraImageWrapper* ciw;
CameraImageWrapper* ciw;
try{
if(maxWidth > 0 || maxHeight > 0) if(maxWidth > 0 || maxHeight > 0)
ciw = CameraImageWrapper::Factory(image, maxWidth, maxHeight, smoothTransformation); ciw = CameraImageWrapper::Factory(image, maxWidth, maxHeight, smoothTransformation);
else else
@ -129,13 +130,18 @@ QString QZXing::decodeImage(QImage image, int maxWidth, int maxHeight, bool smoo
QString string = QString(res->getText()->getText().c_str()); QString string = QString(res->getText()->getText().c_str());
processingTime = t.elapsed(); processingTime = t.elapsed();
qDebug() << "Deconding succeeded: " << string;
delete ciw;
emit tagFound(string); emit tagFound(string);
emit decodingFinished(true); emit decodingFinished(true);
return string; return string;
} }
catch(zxing::Exception& e) catch(zxing::Exception& /*e*/)
{ {
qDebug() << "Deconding failed";
emit decodingFinished(false); emit decodingFinished(false);
if (ciw)
delete ciw;
processingTime = -1; processingTime = -1;
return ""; return "";
} }
@ -146,7 +152,8 @@ QString QZXing::decodeImageFromFile(QString imageFilePath, int maxWidth, int max
//used to have a check if this image exists //used to have a check if this image exists
//but was removed because if the image file path doesn't point to a valid image //but was removed because if the image file path doesn't point to a valid image
// then the QImage::isNull will return true and the decoding will fail eitherway. // then the QImage::isNull will return true and the decoding will fail eitherway.
return decodeImage(QImage(imageFilePath), maxWidth, maxHeight, smoothTransformation); QImage tmpImage = QImage(imageFilePath);
return decodeImage(tmpImage, maxWidth, maxHeight, smoothTransformation);
} }
QString QZXing::decodeImageQML(QObject *item) QString QZXing::decodeImageQML(QObject *item)