mirror of
https://github.com/status-im/qzxing.git
synced 2025-02-09 17:44:27 +00:00
saving merge
This commit is contained in:
commit
e70dd5e1a2
@ -41,7 +41,9 @@
|
||||
#include "QCameraControllerWidget.h"
|
||||
//#include <QDebug>
|
||||
#include <QCameraFlashControl>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QMessageBox>
|
||||
#include <QStandardPaths>
|
||||
|
||||
/*****************************************************************************
|
||||
* QCameraControllerWidget
|
||||
@ -125,11 +127,17 @@ QCameraControllerWidget::QCameraControllerWidget(QWidget *parent) :
|
||||
|
||||
setLayout(hboxl);
|
||||
|
||||
QStringList list = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
|
||||
if(list.isEmpty())
|
||||
imagePath = qApp->applicationDirPath();
|
||||
else
|
||||
imagePath = list.at(0);
|
||||
|
||||
fileWatcher = new QFileSystemWatcher();
|
||||
fileWatcher->addPath(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
|
||||
fileWatcher->addPath(imagePath);
|
||||
connect(fileWatcher, SIGNAL( directoryChanged (const QString &)), this, SLOT(deleteImage(const QString &)));
|
||||
|
||||
imageFolder = QDir(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
|
||||
imageFolder = QDir(imagePath);
|
||||
QStringList filters;
|
||||
filters << "camera*";
|
||||
imageFolder.setNameFilters(filters);
|
||||
@ -280,6 +288,7 @@ void QCameraControllerWidget::captureImage()
|
||||
|
||||
void QCameraControllerWidget::onImageCaptured(int id, const QImage &preview)
|
||||
{
|
||||
Q_UNUSED(id);
|
||||
// m_stillImageCapture->cancelCapture();
|
||||
// showViewFinder = false;
|
||||
m_focusing = false;
|
||||
@ -291,6 +300,7 @@ void QCameraControllerWidget::onImageCaptured(int id, const QImage &preview)
|
||||
|
||||
void QCameraControllerWidget::deleteImage(const QString & folderPath)
|
||||
{
|
||||
Q_UNUSED(folderPath);
|
||||
//qdebug() << "Detected change to folder: " << folderPath;
|
||||
QStringList files = imageFolder.entryList(imageFolder.nameFilters());
|
||||
|
||||
@ -300,8 +310,7 @@ void QCameraControllerWidget::deleteImage(const QString & folderPath)
|
||||
//qdebug() << "Checking file: " << image;
|
||||
if(image.startsWith("camera"))
|
||||
{
|
||||
QString path(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
|
||||
QDir pathDir(path);
|
||||
QDir pathDir(imagePath);
|
||||
pathDir.remove(image);
|
||||
//qdebug() << "file deleted: " << image;
|
||||
|
||||
@ -354,6 +363,7 @@ void QCameraControllerWidget::updateVideo()
|
||||
|
||||
void QCameraControllerWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
//QMainWindow::paintEvent(event);
|
||||
|
||||
QPainter painter(this);
|
||||
|
@ -58,7 +58,7 @@
|
||||
|
||||
#include "myvideosurface.h"
|
||||
#include "button.h"
|
||||
|
||||
#include <QStackedWidget>
|
||||
|
||||
class QCameraControllerWidget: public QWidget, public VideoIF
|
||||
{
|
||||
@ -117,6 +117,7 @@ private:
|
||||
QCameraFocus* cameraFocus;
|
||||
QFileSystemWatcher* fileWatcher;
|
||||
QDir imageFolder;
|
||||
QString imagePath;
|
||||
};
|
||||
|
||||
#endif // QCAMERA_H
|
||||
|
@ -31,7 +31,7 @@
|
||||
#ifndef QQRDECODER_H
|
||||
#define QQRDECODER_H
|
||||
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QMainWindow>
|
||||
#include <QPixmap>
|
||||
#include "ui_QQrDecoder.h"
|
||||
#include <qzxing.h>
|
||||
|
@ -1,15 +1,9 @@
|
||||
TEMPLATE = app
|
||||
TARGET = QQrDecoder
|
||||
QT += core \
|
||||
gui \
|
||||
declarative
|
||||
QT += core gui multimedia widgets
|
||||
|
||||
VERSION = 2.0.0
|
||||
|
||||
CONFIG += mobility
|
||||
MOBILITY = multimedia #\
|
||||
#systeminfo
|
||||
|
||||
RESOURCES += resources.qrc
|
||||
|
||||
include(../../source/QZXing.pri)
|
||||
|
@ -46,7 +46,6 @@
|
||||
Button::Button(QWidget *parent, Qt::WindowFlags f) :
|
||||
QLabel(parent, f)
|
||||
{
|
||||
m_downPixmap = 0;
|
||||
m_disabled = false;
|
||||
m_toggled = false;
|
||||
m_toggle_enabled = false;
|
||||
|
@ -114,7 +114,7 @@ ArrayRef<char> CameraImageWrapper::getMatrix() const
|
||||
ArrayRef<char> tmpRow;
|
||||
tmpRow = getRow(y, ArrayRef<char>(width));
|
||||
#if __cplusplus > 199711L
|
||||
memcpy(m, tmpRow->values()..data(), width);
|
||||
memcpy(m, tmpRow->values().data(), width);
|
||||
#else
|
||||
memcpy(m, &tmpRow->values()[0], width);
|
||||
#endif
|
||||
|
@ -75,6 +75,10 @@ public:
|
||||
}
|
||||
#endif
|
||||
|
||||
QString decoderFormatToString(int fmt);
|
||||
QString foundedFormat() const;
|
||||
QString charSet() const;
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* The decoding function. Will try to decode the given image based on the enabled decoders.
|
||||
@ -92,7 +96,6 @@ public slots:
|
||||
* The input image is read from a local image file.
|
||||
*/
|
||||
QString decodeImageFromFile(const QString& imageFilePath, int maxWidth=-1, int maxHeight=-1, bool smoothTransformation = false);
|
||||
|
||||
/**
|
||||
* The decoding function accessible from QML. (Suggested for Qt 4.x)
|
||||
*/
|
||||
@ -123,6 +126,7 @@ public slots:
|
||||
QString decodeSubImageQML(const QUrl &imageUrl,
|
||||
const double offsetX = 0, const double offsetY = 0,
|
||||
const double width = 0, const double height = 0);
|
||||
|
||||
/**
|
||||
* Get the prossecing time in millisecond of the last decode operation.
|
||||
* Added mainly as a statistic measure.
|
||||
@ -147,12 +151,16 @@ signals:
|
||||
void decodingFinished(bool succeeded);
|
||||
void tagFound(QString tag);
|
||||
void enabledFormatsChanged();
|
||||
void tagFoundAdvanced(QString tag, QString format, QString charSet);
|
||||
void error(QString msg);
|
||||
|
||||
private:
|
||||
zxing::MultiFormatReader *decoder;
|
||||
DecoderFormatType enabledDecoders;
|
||||
ImageHandler *imageHandler;
|
||||
int processingTime;
|
||||
QString foundedFmt;
|
||||
QString charSet_;
|
||||
|
||||
/**
|
||||
* If true, the decoding operation will take place at a different thread.
|
||||
|
@ -1,7 +1,7 @@
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_VERSION, 4.7): QT += declarative
|
||||
greaterThan(QT_VERSION, 5.0): QT += quick
|
||||
greaterThan(QT_VERSION, 4.7): lessThan(QT_VERSION, 5.0): QT += declarative
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += quick
|
||||
|
||||
DEFINES += QZXING_LIBRARY \
|
||||
ZXING_ICONV_CONST \
|
||||
@ -284,3 +284,7 @@ win32-g++{
|
||||
|
||||
SOURCES += $$PWD/zxing/win32/zxing/win_iconv.c
|
||||
}
|
||||
|
||||
!win32{
|
||||
DEFINES += NO_ICONV
|
||||
}
|
||||
|
@ -45,6 +45,73 @@ QZXing::QZXing(QZXing::DecoderFormat decodeHints, QObject *parent) : QObject(par
|
||||
setDecoder(decodeHints);
|
||||
}
|
||||
|
||||
QString QZXing::decoderFormatToString(int fmt)
|
||||
{
|
||||
switch (fmt) {
|
||||
case 1:
|
||||
return "AZTEC";
|
||||
|
||||
case 2:
|
||||
return "CODABAR";
|
||||
|
||||
case 3:
|
||||
return "CODE_39";
|
||||
|
||||
case 4:
|
||||
return "CODE_93";
|
||||
|
||||
case 5:
|
||||
return "CODE_128";
|
||||
|
||||
case 6:
|
||||
return "DATA_MATRIX";
|
||||
|
||||
case 7:
|
||||
return "EAN_8";
|
||||
|
||||
case 8:
|
||||
return "EAN_13";
|
||||
|
||||
case 9:
|
||||
return "ITF";
|
||||
|
||||
case 10:
|
||||
return "MAXICODE";
|
||||
|
||||
case 11:
|
||||
return "PDF_417";
|
||||
|
||||
case 12:
|
||||
return "QR_CODE";
|
||||
|
||||
case 13:
|
||||
return "RSS_14";
|
||||
|
||||
case 14:
|
||||
return "RSS_EXPANDED";
|
||||
|
||||
case 15:
|
||||
return "UPC_A";
|
||||
|
||||
case 16:
|
||||
return "UPC_E";
|
||||
|
||||
case 17:
|
||||
return "UPC_EAN_EXTENSION";
|
||||
} // switch
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QZXing::foundedFormat() const
|
||||
{
|
||||
return foundedFmt;
|
||||
}
|
||||
|
||||
QString QZXing::charSet() const
|
||||
{
|
||||
return charSet_;
|
||||
}
|
||||
|
||||
void QZXing::setDecoder(const uint &hint)
|
||||
{
|
||||
unsigned int newHints = 0;
|
||||
@ -114,16 +181,14 @@ QString QZXing::decodeImage(QImage &image, int maxWidth, int maxHeight, bool smo
|
||||
|
||||
if(image.isNull())
|
||||
{
|
||||
qDebug() << "Image Null";
|
||||
emit decodingFinished(false);
|
||||
processingTime = -1;
|
||||
processingTime = t.elapsed();
|
||||
return "";
|
||||
}
|
||||
|
||||
CameraImageWrapper* ciw;
|
||||
|
||||
CameraImageWrapper *ciw = NULL;
|
||||
try {
|
||||
if(maxWidth > 0 || maxHeight > 0)
|
||||
if ((maxWidth > 0) || (maxHeight > 0))
|
||||
ciw = CameraImageWrapper::Factory(image, maxWidth, maxHeight, smoothTransformation);
|
||||
else
|
||||
ciw = new CameraImageWrapper(image);
|
||||
@ -139,17 +204,27 @@ QString QZXing::decodeImage(QImage &image, int maxWidth, int maxHeight, bool smo
|
||||
res = decoder->decode(ref, DecodeHints((int)enabledDecoders));
|
||||
|
||||
QString string = QString(res->getText()->getText().c_str());
|
||||
processingTime = t.elapsed();
|
||||
qDebug() << "Deconding succeeded: " << string;
|
||||
if (!string.isEmpty() && (string.length() > 0)) {
|
||||
int fmt = res->getBarcodeFormat().value;
|
||||
foundedFmt = decoderFormatToString(fmt);
|
||||
charSet_ = QString::fromStdString(res->getCharSet());
|
||||
if (!charSet_.isEmpty()) {
|
||||
QTextCodec *codec = QTextCodec::codecForName(res->getCharSet().c_str());
|
||||
if (codec)
|
||||
string = codec->toUnicode(res->getText()->getText().c_str());
|
||||
}
|
||||
emit tagFound(string);
|
||||
emit tagFoundAdvanced(string, foundedFmt, charSet_);
|
||||
}
|
||||
processingTime = t.elapsed();
|
||||
emit decodingFinished(true);
|
||||
return string;
|
||||
}
|
||||
catch(zxing::Exception& /*e*/)
|
||||
catch(zxing::Exception &e)
|
||||
{
|
||||
qDebug() << "Deconding failed";
|
||||
emit error(QString(e.what()));
|
||||
emit decodingFinished(false);
|
||||
processingTime = -1;
|
||||
processingTime = t.elapsed();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -175,6 +250,7 @@ QString QZXing::decodeSubImageQML(QObject* item,
|
||||
{
|
||||
if(item == NULL)
|
||||
{
|
||||
processingTime = 0;
|
||||
emit decodingFinished(false);
|
||||
return "";
|
||||
}
|
||||
@ -188,6 +264,7 @@ QString QZXing::decodeImageQML(const QUrl &imageUrl)
|
||||
{
|
||||
return decodeSubImageQML(imageUrl);
|
||||
}
|
||||
|
||||
QString QZXing::decodeSubImageQML(const QUrl &imageUrl,
|
||||
const double offsetX, const double offsetY,
|
||||
const double width, const double height)
|
||||
@ -216,7 +293,3 @@ uint QZXing::getEnabledFormats() const
|
||||
{
|
||||
return enabledDecoders;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -33,8 +33,8 @@ using zxing::BarcodeFormat;
|
||||
Result::Result(Ref<String> text,
|
||||
ArrayRef<char> rawBytes,
|
||||
ArrayRef< Ref<ResultPoint> > resultPoints,
|
||||
BarcodeFormat format) :
|
||||
text_(text), rawBytes_(rawBytes), resultPoints_(resultPoints), format_(format) {
|
||||
BarcodeFormat format, std::string charSet) :
|
||||
text_(text), rawBytes_(rawBytes), resultPoints_(resultPoints), format_(format), charSet_(charSet) {
|
||||
}
|
||||
|
||||
Result::~Result() {
|
||||
@ -59,3 +59,8 @@ ArrayRef< Ref<ResultPoint> >& Result::getResultPoints() {
|
||||
zxing::BarcodeFormat Result::getBarcodeFormat() const {
|
||||
return format_;
|
||||
}
|
||||
|
||||
std::string Result::getCharSet() const
|
||||
{
|
||||
return charSet_;
|
||||
}
|
||||
|
@ -35,18 +35,21 @@ private:
|
||||
ArrayRef<char> rawBytes_;
|
||||
ArrayRef< Ref<ResultPoint> > resultPoints_;
|
||||
BarcodeFormat format_;
|
||||
//NOTE: My
|
||||
std::string charSet_;
|
||||
|
||||
public:
|
||||
Result(Ref<String> text,
|
||||
ArrayRef<char> rawBytes,
|
||||
ArrayRef< Ref<ResultPoint> > resultPoints,
|
||||
BarcodeFormat format);
|
||||
BarcodeFormat format, std::string charSet = "");
|
||||
~Result();
|
||||
Ref<String> getText();
|
||||
ArrayRef<char> getRawBytes();
|
||||
ArrayRef< Ref<ResultPoint> > const& getResultPoints() const;
|
||||
ArrayRef< Ref<ResultPoint> >& getResultPoints();
|
||||
BarcodeFormat getBarcodeFormat() const;
|
||||
std::string getCharSet() const;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream &out, Result& result);
|
||||
};
|
||||
|
@ -27,15 +27,15 @@ using namespace zxing;
|
||||
DecoderResult::DecoderResult(ArrayRef<char> rawBytes,
|
||||
Ref<String> text,
|
||||
ArrayRef< ArrayRef<char> >& byteSegments,
|
||||
string const& ecLevel) :
|
||||
string const& ecLevel, string charSet) :
|
||||
rawBytes_(rawBytes),
|
||||
text_(text),
|
||||
byteSegments_(byteSegments),
|
||||
ecLevel_(ecLevel) {}
|
||||
ecLevel_(ecLevel), charSet_(charSet) {}
|
||||
|
||||
DecoderResult::DecoderResult(ArrayRef<char> rawBytes,
|
||||
Ref<String> text)
|
||||
: rawBytes_(rawBytes), text_(text) {}
|
||||
: rawBytes_(rawBytes), text_(text),charSet_("") {}
|
||||
|
||||
ArrayRef<char> DecoderResult::getRawBytes() {
|
||||
return rawBytes_;
|
||||
@ -44,3 +44,8 @@ ArrayRef<char> DecoderResult::getRawBytes() {
|
||||
Ref<String> DecoderResult::getText() {
|
||||
return text_;
|
||||
}
|
||||
|
||||
string DecoderResult::charSet()
|
||||
{
|
||||
return charSet_;
|
||||
}
|
||||
|
@ -33,17 +33,21 @@ private:
|
||||
Ref<String> text_;
|
||||
ArrayRef< ArrayRef<char> > byteSegments_;
|
||||
std::string ecLevel_;
|
||||
std::string charSet_;
|
||||
|
||||
public:
|
||||
DecoderResult(ArrayRef<char> rawBytes,
|
||||
Ref<String> text,
|
||||
ArrayRef< ArrayRef<char> >& byteSegments,
|
||||
std::string const& ecLevel);
|
||||
std::string const& ecLevel,
|
||||
std::string charSet = "");
|
||||
|
||||
DecoderResult(ArrayRef<char> rawBytes, Ref<String> text);
|
||||
|
||||
ArrayRef<char> getRawBytes();
|
||||
Ref<String> getText();
|
||||
// NOTE: my
|
||||
std::string charSet();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ namespace zxing {
|
||||
ArrayRef< Ref<ResultPoint> > points (detectorResult->getPoints());
|
||||
Ref<DecoderResult> decoderResult(decoder_.decode(detectorResult->getBits()));
|
||||
Ref<Result> result(
|
||||
new Result(decoderResult->getText(), decoderResult->getRawBytes(), points, BarcodeFormat::QR_CODE));
|
||||
new Result(decoderResult->getText(), decoderResult->getRawBytes(), points, BarcodeFormat::QR_CODE, decoderResult->charSet()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ private:
|
||||
static void decodeHanziSegment(Ref<BitSource> bits, std::string &result, int count);
|
||||
static void decodeKanjiSegment(Ref<BitSource> bits, std::string &result, int count);
|
||||
static void decodeByteSegment(Ref<BitSource> bits, std::string &result, int count);
|
||||
static void decodeByteSegment(Ref<BitSource> bits_,
|
||||
static std::string decodeByteSegment(Ref<BitSource> bits_,
|
||||
std::string& result,
|
||||
int count,
|
||||
zxing::common::CharacterSetECI* currentCharacterSetECI,
|
||||
|
@ -102,6 +102,7 @@ void DecodedBitStreamParser::append(std::string &result,
|
||||
result.append((const char *)bufOut);
|
||||
delete[] bufOut;
|
||||
#else
|
||||
Q_UNUSED(src);
|
||||
result.append((const char *)bufIn, nIn);
|
||||
#endif
|
||||
}
|
||||
@ -181,7 +182,7 @@ void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, std::string
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits_,
|
||||
std::string DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits_,
|
||||
string& result,
|
||||
int count,
|
||||
CharacterSetECI* currentCharacterSetECI,
|
||||
@ -217,6 +218,7 @@ void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits_,
|
||||
throw FormatException();
|
||||
}
|
||||
byteSegments->values().push_back(bytes_);
|
||||
return encoding;
|
||||
}
|
||||
|
||||
void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, std::string &result, int count) {
|
||||
@ -357,8 +359,9 @@ DecodedBitStreamParser::decode(ArrayRef<char> bytes,
|
||||
string result;
|
||||
result.reserve(50);
|
||||
ArrayRef< ArrayRef<char> > byteSegments (0);
|
||||
try {
|
||||
CharacterSetECI* currentCharacterSetECI = 0;
|
||||
string charSet = "";
|
||||
try {
|
||||
bool fc1InEffect = false;
|
||||
Mode* mode = 0;
|
||||
do {
|
||||
@ -410,7 +413,7 @@ DecodedBitStreamParser::decode(ArrayRef<char> bytes,
|
||||
} else if (mode == &Mode::ALPHANUMERIC) {
|
||||
decodeAlphanumericSegment(bits_, result, count, fc1InEffect);
|
||||
} else if (mode == &Mode::BYTE) {
|
||||
decodeByteSegment(bits_, result, count, currentCharacterSetECI, byteSegments, hints);
|
||||
charSet = decodeByteSegment(bits_, result, count, currentCharacterSetECI, byteSegments, hints);
|
||||
} else if (mode == &Mode::KANJI) {
|
||||
decodeKanjiSegment(bits_, result, count);
|
||||
} else {
|
||||
@ -425,7 +428,6 @@ DecodedBitStreamParser::decode(ArrayRef<char> bytes,
|
||||
// from readBits() calls
|
||||
throw FormatException();
|
||||
}
|
||||
|
||||
return Ref<DecoderResult>(new DecoderResult(bytes, Ref<String>(new String(result)), byteSegments, (string)ecLevel));
|
||||
return Ref<DecoderResult>(new DecoderResult(bytes, Ref<String>(new String(result)), byteSegments, (string)ecLevel, charSet));
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ int MatrixUtil::findMSBSet(int value)
|
||||
{
|
||||
int numDigits = 0;
|
||||
while (value != 0) {
|
||||
(size_t)value >> 1; // ??value >>>= 1;
|
||||
value >>= 1;
|
||||
++numDigits;
|
||||
}
|
||||
return numDigits;
|
||||
|
Loading…
x
Reference in New Issue
Block a user