2011-11-16 13:40:46 +00:00
|
|
|
#include "qzxing.h"
|
|
|
|
|
|
|
|
#include <zxing/common/GlobalHistogramBinarizer.h>
|
|
|
|
#include <zxing/Binarizer.h>
|
|
|
|
#include <zxing/BinaryBitmap.h>
|
|
|
|
#include <zxing/MultiFormatReader.h>
|
|
|
|
#include <zxing/DecodeHints.h>
|
|
|
|
#include "CameraImageWrapper.h"
|
2012-05-14 14:01:57 +00:00
|
|
|
#include "imagehandler.h"
|
2011-11-16 13:40:46 +00:00
|
|
|
|
|
|
|
using namespace zxing;
|
|
|
|
|
2011-11-29 14:38:16 +00:00
|
|
|
QZXing::QZXing(QObject *parent) : QObject(parent)
|
2011-11-16 13:40:46 +00:00
|
|
|
{
|
|
|
|
decoder = new MultiFormatReader();
|
2011-11-29 14:38:16 +00:00
|
|
|
setDecoder(DecoderFormat_QR_CODE |
|
|
|
|
DecoderFormat_DATA_MATRIX |
|
|
|
|
DecoderFormat_UPC_E |
|
|
|
|
DecoderFormat_UPC_A |
|
|
|
|
DecoderFormat_EAN_8 |
|
|
|
|
DecoderFormat_EAN_13 |
|
|
|
|
DecoderFormat_CODE_128 |
|
|
|
|
DecoderFormat_CODE_39 |
|
2012-05-14 14:01:57 +00:00
|
|
|
DecoderFormat_ITF |
|
|
|
|
DecoderFormat_Aztec);
|
|
|
|
imageHandler = new ImageHandler();
|
2011-11-16 13:40:46 +00:00
|
|
|
}
|
|
|
|
|
2011-11-26 12:59:57 +00:00
|
|
|
void QZXing::setDecoder(DecoderFormatType hint)
|
2011-11-16 13:40:46 +00:00
|
|
|
{
|
2011-11-26 12:59:57 +00:00
|
|
|
DecodeHints newHints;
|
2011-11-16 13:40:46 +00:00
|
|
|
|
|
|
|
if(hint & DecoderFormat_QR_CODE)
|
2011-11-29 14:38:16 +00:00
|
|
|
newHints.addFormat((BarcodeFormat)BarcodeFormat_QR_CODE);
|
2011-11-16 13:40:46 +00:00
|
|
|
|
|
|
|
if(hint & DecoderFormat_DATA_MATRIX)
|
2011-11-29 14:38:16 +00:00
|
|
|
newHints.addFormat((BarcodeFormat)BarcodeFormat_DATA_MATRIX);
|
2011-11-16 13:40:46 +00:00
|
|
|
|
|
|
|
if(hint & DecoderFormat_UPC_E)
|
2011-11-29 14:38:16 +00:00
|
|
|
newHints.addFormat((BarcodeFormat)BarcodeFormat_UPC_E);
|
2011-11-16 13:40:46 +00:00
|
|
|
|
|
|
|
if(hint & DecoderFormat_UPC_A)
|
2011-11-29 14:38:16 +00:00
|
|
|
newHints.addFormat((BarcodeFormat)BarcodeFormat_UPC_A);
|
2011-11-16 13:40:46 +00:00
|
|
|
|
|
|
|
if(hint & DecoderFormat_EAN_8)
|
2011-11-29 14:38:16 +00:00
|
|
|
newHints.addFormat((BarcodeFormat)BarcodeFormat_EAN_8);
|
2011-11-16 13:40:46 +00:00
|
|
|
|
|
|
|
if(hint & DecoderFormat_EAN_13)
|
2011-11-29 14:38:16 +00:00
|
|
|
newHints.addFormat((BarcodeFormat)BarcodeFormat_EAN_13);
|
2011-11-16 13:40:46 +00:00
|
|
|
|
|
|
|
if(hint & DecoderFormat_CODE_128)
|
2011-11-29 14:38:16 +00:00
|
|
|
newHints.addFormat((BarcodeFormat)BarcodeFormat_CODE_128);
|
2011-11-16 13:40:46 +00:00
|
|
|
|
|
|
|
if(hint & DecoderFormat_CODE_39)
|
2011-11-29 14:38:16 +00:00
|
|
|
newHints.addFormat((BarcodeFormat)BarcodeFormat_CODE_39);
|
2011-11-16 13:40:46 +00:00
|
|
|
|
|
|
|
if(hint & DecoderFormat_ITF)
|
2011-11-29 14:38:16 +00:00
|
|
|
newHints.addFormat((BarcodeFormat)BarcodeFormat_ITF);
|
2011-11-16 13:40:46 +00:00
|
|
|
|
2012-05-13 20:47:37 +00:00
|
|
|
if(hint & DecoderFormat_Aztec)
|
|
|
|
newHints.addFormat((BarcodeFormat)BarcodeFormat_AZTEC);
|
|
|
|
|
2011-11-26 12:59:57 +00:00
|
|
|
supportedFormats = newHints.getCurrentHint();
|
2011-11-16 13:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString QZXing::decodeImage(QImage image)
|
|
|
|
{
|
|
|
|
Ref<Result> res;
|
|
|
|
emit decodingStarted();
|
|
|
|
|
|
|
|
try{
|
|
|
|
Ref<LuminanceSource> imageRef(new CameraImageWrapper(image));
|
|
|
|
GlobalHistogramBinarizer* binz = new GlobalHistogramBinarizer(imageRef);
|
|
|
|
|
|
|
|
Ref<Binarizer> bz (binz);
|
|
|
|
BinaryBitmap* bb = new BinaryBitmap(bz);
|
|
|
|
|
|
|
|
Ref<BinaryBitmap> ref(bb);
|
|
|
|
|
2011-11-29 14:38:16 +00:00
|
|
|
res = ((MultiFormatReader*)decoder)->decode(ref, DecodeHints((int)supportedFormats));
|
2011-11-16 13:40:46 +00:00
|
|
|
|
|
|
|
QString string = QString(res->getText()->getText().c_str());
|
|
|
|
emit tagFound(string);
|
|
|
|
emit decodingFinished(true);
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
catch(zxing::Exception& e)
|
|
|
|
{
|
|
|
|
emit decodingFinished(false);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
2012-05-14 14:01:57 +00:00
|
|
|
|
|
|
|
QString QZXing::decodeImageQML(QObject *item)
|
|
|
|
{
|
|
|
|
return decodeSubImageQML(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QZXing::decodeSubImageQML(QObject* item,
|
|
|
|
const double offsetX, const double offsetY,
|
|
|
|
const double width, const double height)
|
|
|
|
{
|
|
|
|
if(item == NULL)
|
|
|
|
{
|
|
|
|
emit decodingFinished(false);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage img = ((ImageHandler*)imageHandler)->extractQImage(item, offsetX, offsetY, width, height);
|
|
|
|
|
|
|
|
return decodeImage(img);
|
|
|
|
}
|
|
|
|
|
|
|
|
|