mirror of
https://github.com/status-im/qzxing.git
synced 2025-01-27 11:14:49 +00:00
Testing threaded operations. Experiencing memory leak and crashes.
This commit is contained in:
parent
4eb0ea479c
commit
659215a660
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,6 +2,7 @@
|
|||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
CameraImageWrapper::CameraImageWrapper() : LuminanceSource(0,0), isSmoothTransformationEnabled(false)
|
CameraImageWrapper::CameraImageWrapper() : LuminanceSource(0,0), isSmoothTransformationEnabled(false)
|
||||||
{
|
{
|
||||||
@ -63,6 +64,9 @@ bool CameraImageWrapper::setImage(QString fileName, int maxWidth, int maxHeight)
|
|||||||
|
|
||||||
scale(maxWidth, maxHeight);
|
scale(maxWidth, maxHeight);
|
||||||
|
|
||||||
|
width = image.width();
|
||||||
|
height = image.height();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +79,9 @@ bool CameraImageWrapper::setImage(QImage newImage, int maxWidth, int maxHeight)
|
|||||||
|
|
||||||
scale(maxWidth, maxHeight);
|
scale(maxWidth, maxHeight);
|
||||||
|
|
||||||
|
width = image.width();
|
||||||
|
height = image.height();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,10 +150,13 @@ void CameraImageWrapper::setSmoothTransformation(bool enable)
|
|||||||
|
|
||||||
void CameraImageWrapper::scale(int maxWidth, int maxHeight)
|
void CameraImageWrapper::scale(int maxWidth, int maxHeight)
|
||||||
{
|
{
|
||||||
if((maxWidth != 1 || maxHeight != 1) && (image.width() > maxWidth || image.height() > maxHeight))
|
if((maxWidth != -1 || maxHeight != -1) && (image.width() > maxWidth || image.height() > maxHeight))
|
||||||
|
{
|
||||||
|
qDebug() << "Scaling image to: width " << maxWidth << ", " << ", maxHeight: " << maxHeight;
|
||||||
image = image.scaled(
|
image = image.scaled(
|
||||||
maxWidth != -1 ? maxWidth : image.width(),
|
maxWidth != -1 ? maxWidth : image.width(),
|
||||||
maxHeight != -1 ? maxHeight : image.height(),
|
maxHeight != -1 ? maxHeight : image.height(),
|
||||||
Qt::KeepAspectRatio,
|
Qt::KeepAspectRatio,
|
||||||
isSmoothTransformationEnabled ? Qt::SmoothTransformation : Qt::FastTransformation);
|
isSmoothTransformationEnabled ? Qt::SmoothTransformation : Qt::FastTransformation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,6 @@ DEFINES += QZXING_LIBRARY \
|
|||||||
INCLUDEPATH += $$PWD \
|
INCLUDEPATH += $$PWD \
|
||||||
$$PWD/zxing
|
$$PWD/zxing
|
||||||
|
|
||||||
|
|
||||||
HEADERS += $$PWD/QZXing_global.h \
|
|
||||||
HEADERS += $$PWD/QZXing_global.h \
|
HEADERS += $$PWD/QZXing_global.h \
|
||||||
$$PWD/CameraImageWrapper.h \
|
$$PWD/CameraImageWrapper.h \
|
||||||
$$PWD/imagehandler.h \
|
$$PWD/imagehandler.h \
|
||||||
|
@ -115,6 +115,10 @@ QString QZXing::decodeImage(QImage image, int maxWidth, int maxHeight, bool smoo
|
|||||||
connect(worker, SIGNAL(decodingFinished(bool)), this, SIGNAL(decodingFinished(bool)));
|
connect(worker, SIGNAL(decodingFinished(bool)), this, SIGNAL(decodingFinished(bool)));
|
||||||
connect(worker, SIGNAL(decodingStarted()), this, SIGNAL(decodingStarted()));
|
connect(worker, SIGNAL(decodingStarted()), this, SIGNAL(decodingStarted()));
|
||||||
connect(worker, SIGNAL(tagFound(QString)), this, SIGNAL(tagFound(QString)));
|
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()));
|
||||||
|
|
||||||
worker->setData(&processingTime, image, maxWidth, maxHeight, smoothTransformation, decoder, enabledDecoders);
|
worker->setData(&processingTime, image, maxWidth, maxHeight, smoothTransformation, decoder, enabledDecoders);
|
||||||
worker->moveToThread(thread);
|
worker->moveToThread(thread);
|
||||||
|
|
||||||
@ -151,12 +155,12 @@ QString QZXing::decodeImage(QImage image, int maxWidth, int maxHeight, bool smoo
|
|||||||
ciw = new CameraImageWrapper(image);
|
ciw = new CameraImageWrapper(image);
|
||||||
|
|
||||||
Ref<LuminanceSource> imageRef(ciw);
|
Ref<LuminanceSource> imageRef(ciw);
|
||||||
GlobalHistogramBinarizer* binz = new GlobalHistogramBinarizer(imageRef);
|
GlobalHistogramBinarizer binz(imageRef);
|
||||||
|
|
||||||
Ref<Binarizer> bz (binz);
|
Ref<Binarizer> bz (&binz);
|
||||||
BinaryBitmap* bb = new BinaryBitmap(bz);
|
BinaryBitmap bb(bz);
|
||||||
|
|
||||||
Ref<BinaryBitmap> ref(bb);
|
Ref<BinaryBitmap> ref(&bb);
|
||||||
|
|
||||||
res = ((MultiFormatReader*)decoder)->decode(ref, DecodeHints((int)enabledDecoders));
|
res = ((MultiFormatReader*)decoder)->decode(ref, DecodeHints((int)enabledDecoders));
|
||||||
|
|
||||||
@ -166,8 +170,6 @@ QString QZXing::decodeImage(QImage image, int maxWidth, int maxHeight, bool smoo
|
|||||||
emit decodingFinished(true);
|
emit decodingFinished(true);
|
||||||
|
|
||||||
delete ciw;
|
delete ciw;
|
||||||
delete binz;
|
|
||||||
delete bb;
|
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
@ -10,15 +10,18 @@
|
|||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <qzxing.h>
|
#include <qzxing.h>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
using namespace zxing;
|
using namespace zxing;
|
||||||
|
|
||||||
QZXingWorker_p::QZXingWorker_p(QObject *parent) :
|
QZXingWorker_p::QZXingWorker_p(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent), maxWidth(-1), maxHeight(-1), smoothTransformation(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QZXingWorker_p::decode()
|
QString QZXingWorker_p::decode()
|
||||||
{
|
{
|
||||||
|
qDebug() << "Entered threaded decoding";
|
||||||
QTime t;
|
QTime t;
|
||||||
t.start();
|
t.start();
|
||||||
Ref<Result> res;
|
Ref<Result> res;
|
||||||
@ -27,47 +30,47 @@ QString QZXingWorker_p::decode()
|
|||||||
if(image.isNull())
|
if(image.isNull())
|
||||||
{
|
{
|
||||||
emit decodingFinished(false);
|
emit decodingFinished(false);
|
||||||
*processingTime = -1;
|
|
||||||
|
//*processingTime = -1;
|
||||||
|
|
||||||
|
qDebug() << "Exited threaded decoding, error";
|
||||||
|
|
||||||
|
emit quitThread();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
CameraImageWrapper* ciw;
|
CameraImageWrapper ciw;
|
||||||
|
|
||||||
if(maxWidth > 0 || maxHeight > 0)
|
ciw.setSmoothTransformation(smoothTransformation);
|
||||||
{
|
ciw.setImage(image, maxWidth, maxHeight);
|
||||||
ciw = new CameraImageWrapper();
|
|
||||||
ciw->setSmoothTransformation(smoothTransformation);
|
|
||||||
ciw->setImage(image, maxWidth, maxHeight);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ciw = new CameraImageWrapper(image);
|
|
||||||
|
|
||||||
Ref<LuminanceSource> imageRef(ciw);
|
Ref<LuminanceSource> imageRef(&ciw);
|
||||||
GlobalHistogramBinarizer* binz = new GlobalHistogramBinarizer(imageRef);
|
GlobalHistogramBinarizer binz(imageRef);
|
||||||
|
|
||||||
Ref<Binarizer> bz (binz);
|
Ref<Binarizer> bz (&binz);
|
||||||
BinaryBitmap* bb = new BinaryBitmap(bz);
|
BinaryBitmap bb(bz);
|
||||||
|
|
||||||
Ref<BinaryBitmap> ref(bb);
|
Ref<BinaryBitmap> ref(&bb);
|
||||||
|
|
||||||
res = ((MultiFormatReader*)decoder)->decode(ref, DecodeHints((int)enabledDecoders));
|
res = ((MultiFormatReader*)decoder)->decode(ref, DecodeHints((int)enabledDecoders));
|
||||||
|
|
||||||
QString string = QString(res->getText()->getText().c_str());
|
QString string = QString(res->getText()->getText().c_str());
|
||||||
*processingTime = t.elapsed();
|
// *processingTime = t.elapsed();
|
||||||
emit tagFound(string);
|
emit tagFound(string);
|
||||||
emit decodingFinished(true);
|
emit decodingFinished(true);
|
||||||
|
|
||||||
delete ciw;
|
qDebug() << "Exited threaded decoding";
|
||||||
delete binz;
|
emit quitThread();
|
||||||
delete bb;
|
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
catch(zxing::Exception& e)
|
catch(zxing::Exception& e)
|
||||||
{
|
{
|
||||||
emit decodingFinished(false);
|
emit decodingFinished(false);
|
||||||
*processingTime = -1;
|
// *processingTime = -1;
|
||||||
|
|
||||||
|
qDebug() << "Exited threaded decoding, error";
|
||||||
|
emit quitThread();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ signals:
|
|||||||
void decodingStarted();
|
void decodingStarted();
|
||||||
void decodingFinished(bool succeeded);
|
void decodingFinished(bool succeeded);
|
||||||
void tagFound(QString tag);
|
void tagFound(QString tag);
|
||||||
|
|
||||||
|
void quitThread();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setData(int* processingTime, QImage image, int maxWidth, int maxHeight, bool smoothTransformation,
|
void setData(int* processingTime, QImage image, int maxWidth, int maxHeight, bool smoothTransformation,
|
||||||
|
@ -27,9 +27,9 @@
|
|||||||
namespace zxing {
|
namespace zxing {
|
||||||
|
|
||||||
class LuminanceSource : public Counted {
|
class LuminanceSource : public Counted {
|
||||||
private:
|
protected:
|
||||||
const int width;
|
int width;
|
||||||
const int height;
|
int height;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LuminanceSource(int width, int height);
|
LuminanceSource(int width, int height);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user