Support QZXingFilter orientation respect proposed in #120. Could be usefull for #204

This commit is contained in:
Nikolaos Ftylitakis 2021-08-11 12:23:06 +03:00
parent 4bba0dd140
commit bef8c129bf
2 changed files with 35 additions and 1 deletions

View File

@ -43,6 +43,7 @@ QZXingFilter::QZXingFilter(QObject *parent)
: QAbstractVideoFilter(parent) : QAbstractVideoFilter(parent)
, decoder(QZXing::DecoderFormat_QR_CODE) , decoder(QZXing::DecoderFormat_QR_CODE)
, decoding(false) , decoding(false)
, orientation_(0)
{ {
/// Connecting signals to handlers that will send signals to QML /// Connecting signals to handlers that will send signals to QML
connect(&decoder, &QZXing::decodingStarted, connect(&decoder, &QZXing::decodingStarted,
@ -69,6 +70,21 @@ void QZXingFilter::handleDecodingFinished(bool succeeded)
emit isDecodingChanged(); 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() QVideoFilterRunnable * QZXingFilter::createFilterRunnable()
{ {
return new QZXingFilterRunnable(this); return new QZXingFilterRunnable(this);
@ -372,7 +388,20 @@ void QZXingFilterRunnable::processVideoFrameProbed(SimpleVideoFrame & videoFrame
//QZXingImageProvider::getInstance()->storeImage(image); //QZXingImageProvider::getInstance()->storeImage(image);
decode(*image_ptr); 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; delete image_ptr;
} }

View File

@ -75,16 +75,20 @@ class QZXingFilter : public QAbstractVideoFilter
Q_PROPERTY(bool decoding READ isDecoding NOTIFY isDecodingChanged) Q_PROPERTY(bool decoding READ isDecoding NOTIFY isDecodingChanged)
Q_PROPERTY(QZXing* decoder READ getDecoder) Q_PROPERTY(QZXing* decoder READ getDecoder)
Q_PROPERTY(QRectF captureRect MEMBER captureRect NOTIFY captureRectChanged) Q_PROPERTY(QRectF captureRect MEMBER captureRect NOTIFY captureRectChanged)
Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
signals: signals:
void isDecodingChanged(); void isDecodingChanged();
void decodingFinished(bool succeeded, int decodeTime); void decodingFinished(bool succeeded, int decodeTime);
void decodingStarted(); void decodingStarted();
void captureRectChanged(); void captureRectChanged();
void orientationChanged(int orientation);
private slots: private slots:
void handleDecodingStarted(); void handleDecodingStarted();
void handleDecodingFinished(bool succeeded); void handleDecodingFinished(bool succeeded);
void setOrientation(int orientation);
int orientation() const;
private: /// Attributes private: /// Attributes
QZXing decoder; QZXing decoder;
@ -93,6 +97,7 @@ class QZXingFilter : public QAbstractVideoFilter
SimpleVideoFrame frame; SimpleVideoFrame frame;
QFuture<void> processThread; QFuture<void> processThread;
int orientation_;
public: /// Methods public: /// Methods
explicit QZXingFilter(QObject *parent = 0); explicit QZXingFilter(QObject *parent = 0);