diff --git a/examples/QZXingLive/main.qml b/examples/QZXingLive/main.qml index 5c171e1..142fcbe 100644 --- a/examples/QZXingLive/main.qml +++ b/examples/QZXingLive/main.qml @@ -85,6 +85,7 @@ ApplicationWindow QZXingFilter { id: zxingFilter + orientation: videoOutput.orientation captureRect: { // setup bindings videoOutput.contentRect; diff --git a/src/QZXingFilter.cpp b/src/QZXingFilter.cpp index 19bb8b6..3fdeb6c 100644 --- a/src/QZXingFilter.cpp +++ b/src/QZXingFilter.cpp @@ -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,19 @@ void QZXingFilterRunnable::processVideoFrameProbed(SimpleVideoFrame & videoFrame //QZXingImageProvider::getInstance()->storeImage(image); - decode(*image_ptr); + int orientation = filter ? filter->orientation() : 0; + + if (!orientation) { + decode(*image_ptr); + } else { + QTransform transformation; + transformation.translate(image_ptr->rect().center().x(), image_ptr->rect().center().y()); + transformation.rotate(-orientation); + + QImage translatedImage = image_ptr->transformed(transformation); + + decode(translatedImage); + } delete image_ptr; } diff --git a/src/QZXingFilter.h b/src/QZXingFilter.h index d963f3e..e504789 100644 --- a/src/QZXingFilter.h +++ b/src/QZXingFilter.h @@ -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 processThread; + int orientation_; public: /// Methods explicit QZXingFilter(QObject *parent = 0);