Skip to content

Commit

Permalink
Merge pull request #207 from ftylitak/qzxingfilter-orientation-support
Browse files Browse the repository at this point in the history
QZXingFilter orientation support
  • Loading branch information
ftylitak authored Aug 12, 2021
2 parents 4bba0dd + 4db0aa2 commit 2fd4dd6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/QZXingLive/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ ApplicationWindow
QZXingFilter
{
id: zxingFilter
orientation: videoOutput.orientation
captureRect: {
// setup bindings
videoOutput.contentRect;
Expand Down
30 changes: 29 additions & 1 deletion src/QZXingFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions src/QZXingFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -93,6 +97,7 @@ class QZXingFilter : public QAbstractVideoFilter

SimpleVideoFrame frame;
QFuture<void> processThread;
int orientation_;

public: /// Methods
explicit QZXingFilter(QObject *parent = 0);
Expand Down

0 comments on commit 2fd4dd6

Please sign in to comment.