diff --git a/source/CameraImageWrapper.cpp b/source/CameraImageWrapper.cpp index 321ca69..06b2d2b 100644 --- a/source/CameraImageWrapper.cpp +++ b/source/CameraImageWrapper.cpp @@ -2,10 +2,8 @@ #include #include #include -#include -#include -std::vector allocatedObjects; +#include CameraImageWrapper::CameraImageWrapper() : LuminanceSource(0,0), isSmoothTransformationEnabled(false) { @@ -23,13 +21,6 @@ CameraImageWrapper::CameraImageWrapper(CameraImageWrapper& otherInstance) : Lumi CameraImageWrapper::~CameraImageWrapper() { - for(int i=0; i CameraImageWrapper::getMatrix() const char* matrix = new char[width*height]; char* m = matrix; - qDebug() << "getting matrix"; - - allocatedObjects.push_back((unsigned char*)matrix); - for(int y=0; y tmpRow; @@ -157,7 +141,13 @@ ArrayRef CameraImageWrapper::getMatrix() const } //pMatrix = matrix; - return ArrayRef(matrix, width*height); + ArrayRef arr = ArrayRef(matrix, width*height); + + if(matrix) + delete matrix; + + + return arr; } void CameraImageWrapper::setSmoothTransformation(bool enable) @@ -167,13 +157,10 @@ void CameraImageWrapper::setSmoothTransformation(bool enable) void CameraImageWrapper::scale(int maxWidth, int maxHeight) { - if((maxWidth != -1 || maxHeight != -1) && (image.width() > maxWidth || image.height() > maxHeight)) - { - qDebug() << "Scaling image to: width " << maxWidth << ", " << ", maxHeight: " << maxHeight; + if((maxWidth != 1 || maxHeight != 1) && (image.width() > maxWidth || image.height() > maxHeight)) image = image.scaled( maxWidth != -1 ? maxWidth : image.width(), maxHeight != -1 ? maxHeight : image.height(), Qt::KeepAspectRatio, isSmoothTransformationEnabled ? Qt::SmoothTransformation : Qt::FastTransformation); - } } diff --git a/source/CameraImageWrapper.h b/source/CameraImageWrapper.h index 79c9d77..b5b5c54 100644 --- a/source/CameraImageWrapper.h +++ b/source/CameraImageWrapper.h @@ -4,7 +4,6 @@ #include #include #include -#include using namespace zxing; diff --git a/source/QZXing.h b/source/QZXing.h index 2fb83e2..6b17035 100644 --- a/source/QZXing.h +++ b/source/QZXing.h @@ -116,19 +116,6 @@ public slots: */ void setDecoder(const uint& hint); - /** - * If set to true, the decoding takes place in a different thread. - * Note that if threading is used, the decodeImage function returns - * an empty string. To acquire the data the user needs to connect to the signal - * tagFound. - * - * This option was created for convinience in case the decoding functions are used - * at a low-power device with big images. - * - * (PS. not sure if it gives any advantage, it will be investigated further in the future) - */ - void setIsThreaded(bool enabledThreads); - signals: void decodingStarted(); void decodingFinished(bool succeeded); @@ -137,8 +124,6 @@ signals: private: void* decoder; - void* worker; - void* thread; DecoderFormatType enabledDecoders; QObject* imageHandler; int processingTime; diff --git a/source/QZXing.pri b/source/QZXing.pri index ad21e45..3594940 100644 --- a/source/QZXing.pri +++ b/source/QZXing.pri @@ -9,6 +9,8 @@ DEFINES += QZXING_LIBRARY \ INCLUDEPATH += $$PWD \ $$PWD/zxing + +HEADERS += $$PWD/QZXing_global.h \ HEADERS += $$PWD/QZXing_global.h \ $$PWD/CameraImageWrapper.h \ $$PWD/imagehandler.h \ @@ -121,8 +123,7 @@ HEADERS += $$PWD/QZXing_global.h \ $$PWD/zxing/bigint/BigIntegerUtils.hh \ $$PWD/zxing/bigint/BigIntegerLibrary.hh \ $$PWD/zxing/bigint/BigIntegerAlgorithms.hh \ - $$PWD/zxing/bigint/BigInteger.hh \ - qzxing/qzxingworker_p.h + $$PWD/zxing/bigint/BigInteger.hh SOURCES += $$PWD/CameraImageWrapper.cpp \ $$PWD/qzxing.cpp \ @@ -226,8 +227,7 @@ SOURCES += $$PWD/CameraImageWrapper.cpp \ $$PWD/zxing/bigint/BigUnsigned.cc \ $$PWD/zxing/bigint/BigIntegerUtils.cc \ $$PWD/zxing/bigint/BigIntegerAlgorithms.cc \ - $$PWD/zxing/bigint/BigInteger.cc \ - qzxing/qzxingworker_p.cpp + $$PWD/zxing/bigint/BigInteger.cc symbian { TARGET.UID3 = 0xE618743C diff --git a/source/qzxing.cpp b/source/qzxing.cpp index 5b4215d..0cbfa45 100644 --- a/source/qzxing.cpp +++ b/source/qzxing.cpp @@ -9,9 +9,6 @@ #include "imagehandler.h" #include -#include "qzxingworker_p.h" -#include - using namespace zxing; QZXing::QZXing(QObject *parent) : QObject(parent) @@ -28,16 +25,6 @@ QZXing::QZXing(QObject *parent) : QObject(parent) DecoderFormat_ITF | DecoderFormat_Aztec);*/ imageHandler = new ImageHandler(); - - QZXingWorker_p* worker_p = new QZXingWorker_p(); - connect(worker_p, SIGNAL(decodingFinished(bool)), this, SIGNAL(decodingFinished(bool))); - connect(worker_p, SIGNAL(decodingStarted()), this, SIGNAL(decodingStarted())); - connect(worker_p, SIGNAL(tagFound(QString)), this, SIGNAL(tagFound(QString))); - - thread = new QThread; - worker_p->moveToThread(static_cast(thread)); - - worker = worker_p; } QZXing::QZXing(QZXing::DecoderFormat decodeHints, QObject *parent) : QObject(parent) @@ -108,97 +95,61 @@ void QZXing::setDecoder(const uint &hint) emit enabledFormatsChanged(); } -void QZXing::setIsThreaded(bool enabledThreads) -{ - isThreaded = enabledThreads; -} - QString QZXing::decodeImage(QImage image, int maxWidth, int maxHeight, bool smoothTransformation) { + QTime t; + t.start(); + Ref res; + emit decodingStarted(); - qDebug() << "decoding"; - isThreaded = false; - - if(isThreaded) + if(image.isNull()) { -// QZXingWorker_p* worker = new QZXingWorker_p(); -// connect(worker, SIGNAL(decodingFinished(bool)), this, SIGNAL(decodingFinished(bool))); -// connect(worker, SIGNAL(decodingStarted()), this, SIGNAL(decodingStarted())); -// connect(worker, SIGNAL(tagFound(QString)), this, SIGNAL(tagFound(QString))); - //connect(worker, SIGNAL(quitThread()), thread, SLOT(quit())); - //connect(thread, SIGNAL(finished()), worker, SLOT(deleteLater())); - //connect(thread, SIGNAL(finished()), SLOT(deleteLater())); - - QZXingWorker_p* worker_p = static_cast(worker); - worker_p->setData(&processingTime, image, maxWidth, maxHeight, smoothTransformation, decoder, enabledDecoders); - static_cast(thread)->start(); - - QMetaObject::invokeMethod(worker_p, "decode", Qt::QueuedConnection); - + emit decodingFinished(false); + processingTime = -1; return ""; } - else + + try{ + CameraImageWrapper* ciw; + + if(maxWidth > 0 || maxHeight > 0) + { + ciw = new CameraImageWrapper(); + ciw->setSmoothTransformation(smoothTransformation); + ciw->setImage(image, maxWidth, maxHeight); + } + else + ciw = new CameraImageWrapper(image); + + Ref imageRef(ciw); + GlobalHistogramBinarizer* binz = new GlobalHistogramBinarizer(imageRef); + + Ref bz (binz); + BinaryBitmap* bb = new BinaryBitmap(bz); + + Ref ref(bb); + + res = ((MultiFormatReader*)decoder)->decode(ref, DecodeHints((int)enabledDecoders)); + + QString string = QString(res->getText()->getText().c_str()); + processingTime = t.elapsed(); + emit tagFound(string); + emit decodingFinished(true); + return string; + } + catch(zxing::Exception& e) { - QTime t; - t.start(); - Ref res; - emit decodingStarted(); - - if(image.isNull()) - { - emit decodingFinished(false); - processingTime = -1; - return ""; - } - - CameraImageWrapper* ciw = NULL; - - try{ - if(maxWidth > 0 || maxHeight > 0) - { - ciw = new CameraImageWrapper(); - ciw->setSmoothTransformation(smoothTransformation); - ciw->setImage(image, maxWidth, maxHeight); - } - else - ciw = new CameraImageWrapper(image); - - Ref imageRef(ciw); - GlobalHistogramBinarizer binz(imageRef); - - Ref bz (&binz); - BinaryBitmap bb(bz); - - Ref ref(&bb); - - res = ((MultiFormatReader*)decoder)->decode(ref, DecodeHints((int)enabledDecoders)); - - QString string = QString(res->getText()->getText().c_str()); - processingTime = t.elapsed(); - emit tagFound(string); - emit decodingFinished(true); - - delete ciw; - - return string; - } - catch(zxing::Exception& e) - { - if(!ciw) - delete ciw; - - emit decodingFinished(false); - processingTime = -1; - return ""; - } + emit decodingFinished(false); + processingTime = -1; + return ""; } } QString QZXing::decodeImageFromFile(QString imageFilePath, int maxWidth, int maxHeight, bool smoothTransformation) { - //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 - // then the QImage::isNull will return true and the decoding will fail eitherway. + //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 + // then the QImage::isNull will return true and the decoding will fail eitherway. return decodeImage(QImage(imageFilePath), maxWidth, maxHeight, smoothTransformation); } diff --git a/source/zxing/zxing/oned/UPCEReader.cpp b/source/zxing/zxing/oned/UPCEReader.cpp index 0a2f0f0..ce3a14b 100644 --- a/source/zxing/zxing/oned/UPCEReader.cpp +++ b/source/zxing/zxing/oned/UPCEReader.cpp @@ -136,7 +136,9 @@ Ref UPCEReader::convertUPCEtoUPCA(Ref const& upce_) { result.append(1, lastChar); break; } - result.append(1, upce[7]); + //result.append(1, upce[7]); + char c = (char)(*(upce.data()+7));//upce[upce.size()]; + result.append(1, c); return Ref(new String(result)); }