mirror of https://github.com/status-im/qzxing.git
Fix unmap in case of early return of frame processing
Added support to image rotate based on the orientation of the frame #199
This commit is contained in:
parent
1f819ed0f0
commit
7d3b430b9e
|
@ -37,6 +37,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_;
|
||||
}
|
||||
|
||||
void QZXingFilter::setVideoSink(QObject *videoSink){
|
||||
m_videoSink = qobject_cast<QVideoSink*>(videoSink);
|
||||
|
||||
|
@ -52,16 +67,10 @@ void QZXingFilter::processFrame(const QVideoFrame &frame) {
|
|||
const QVideoFrame &f = frame;
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
if(isDecoding() || !processThread.isFinished()) return;
|
||||
|
||||
if(!isDecoding() && processThread.isFinished()){
|
||||
decoding = true;
|
||||
|
||||
QImage image = f.toImage();
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
f.unmap();
|
||||
#endif
|
||||
|
||||
processThread = QtConcurrent::run([=](){
|
||||
if(image.isNull())
|
||||
{
|
||||
|
@ -77,6 +86,18 @@ void QZXingFilter::processFrame(const QVideoFrame &frame) {
|
|||
frameToProcess = image.copy(rect);
|
||||
}
|
||||
|
||||
if (!orientation_) {
|
||||
decoder.decodeImage(frameToProcess);
|
||||
} else {
|
||||
QTransform transformation;
|
||||
transformation.translate(frameToProcess.rect().center().x(), frameToProcess.rect().center().y());
|
||||
transformation.rotate(-orientation_);
|
||||
|
||||
QImage translatedImage = frameToProcess.transformed(transformation);
|
||||
|
||||
decoder.decodeImage(translatedImage);
|
||||
}
|
||||
|
||||
// static int i=0;
|
||||
// qDebug() << "image.size()" << frameToProcess.size();
|
||||
// qDebug() << "image.format()" << frameToProcess.format();
|
||||
|
@ -86,3 +107,8 @@ void QZXingFilter::processFrame(const QVideoFrame &frame) {
|
|||
decoder.decodeImage(frameToProcess, frameToProcess.width(), frameToProcess.height());
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
f.unmap();
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -32,22 +32,27 @@ class QZXingFilter : public QObject
|
|||
Q_PROPERTY(QZXing* decoder READ getDecoder)
|
||||
Q_PROPERTY(QRectF captureRect MEMBER captureRect NOTIFY captureRectChanged)
|
||||
Q_PROPERTY(QObject* videoSink WRITE setVideoSink)
|
||||
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 processFrame(const QVideoFrame &frame);
|
||||
void setOrientation(int orientation);
|
||||
int orientation() const;
|
||||
|
||||
private: /// Attributes
|
||||
QZXing decoder;
|
||||
bool decoding;
|
||||
QRectF captureRect;
|
||||
int orientation_;
|
||||
|
||||
QVideoSink *m_videoSink;
|
||||
QFuture<void> processThread;
|
||||
|
|
Loading…
Reference in New Issue