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