mirror of https://github.com/status-im/qzxing.git
This commit is contained in:
parent
4bba0dd140
commit
bef8c129bf
|
@ -43,6 +43,7 @@ QZXingFilter::QZXingFilter(QObject *parent)
|
|||
: QAbstractVideoFilter(parent)
|
||||
, decoder(QZXing::DecoderFormat_QR_CODE)
|
||||
, decoding(false)
|
||||
, orientation_(0)
|
||||
{
|
||||
/// Connecting signals to handlers that will send signals to QML
|
||||
connect(&decoder, &QZXing::decodingStarted,
|
||||
|
@ -69,6 +70,21 @@ void QZXingFilter::handleDecodingFinished(bool succeeded)
|
|||
emit isDecodingChanged();
|
||||
}
|
||||
|
||||
void QZXingFilter::setOrientation(int orientation)
|
||||
{
|
||||
if (orientation_ == orientation) {
|
||||
return;
|
||||
}
|
||||
|
||||
orientation_ = orientation;
|
||||
emit orientationChanged(orientation_);
|
||||
}
|
||||
|
||||
int QZXingFilter::orientation() const
|
||||
{
|
||||
return orientation_;
|
||||
}
|
||||
|
||||
QVideoFilterRunnable * QZXingFilter::createFilterRunnable()
|
||||
{
|
||||
return new QZXingFilterRunnable(this);
|
||||
|
@ -372,7 +388,20 @@ void QZXingFilterRunnable::processVideoFrameProbed(SimpleVideoFrame & videoFrame
|
|||
|
||||
//QZXingImageProvider::getInstance()->storeImage(image);
|
||||
|
||||
int orientation = filter ? filter->orientation() : 0;
|
||||
|
||||
if (!orientation) {
|
||||
decode(*image_ptr);
|
||||
} else {
|
||||
QImage translatedImage = image_ptr->transformed([](QPoint center, int orientation) {
|
||||
QMatrix matrix;
|
||||
matrix.translate(center.x(), center.y());
|
||||
matrix.rotate(-orientation);
|
||||
return matrix;
|
||||
} (image_ptr->rect().center(), orientation));
|
||||
|
||||
decode(translatedImage);
|
||||
}
|
||||
|
||||
delete image_ptr;
|
||||
}
|
||||
|
|
|
@ -75,16 +75,20 @@ class QZXingFilter : public QAbstractVideoFilter
|
|||
Q_PROPERTY(bool decoding READ isDecoding NOTIFY isDecodingChanged)
|
||||
Q_PROPERTY(QZXing* decoder READ getDecoder)
|
||||
Q_PROPERTY(QRectF captureRect MEMBER captureRect NOTIFY captureRectChanged)
|
||||
Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
|
||||
|
||||
signals:
|
||||
void isDecodingChanged();
|
||||
void decodingFinished(bool succeeded, int decodeTime);
|
||||
void decodingStarted();
|
||||
void captureRectChanged();
|
||||
void orientationChanged(int orientation);
|
||||
|
||||
private slots:
|
||||
void handleDecodingStarted();
|
||||
void handleDecodingFinished(bool succeeded);
|
||||
void setOrientation(int orientation);
|
||||
int orientation() const;
|
||||
|
||||
private: /// Attributes
|
||||
QZXing decoder;
|
||||
|
@ -93,6 +97,7 @@ class QZXingFilter : public QAbstractVideoFilter
|
|||
|
||||
SimpleVideoFrame frame;
|
||||
QFuture<void> processThread;
|
||||
int orientation_;
|
||||
|
||||
public: /// Methods
|
||||
explicit QZXingFilter(QObject *parent = 0);
|
||||
|
|
Loading…
Reference in New Issue