From dbc01a383ccc14a97fe3c6dd06cc912f1c3de1d6 Mon Sep 17 00:00:00 2001 From: ftylitak Date: Wed, 23 Oct 2019 22:30:11 +0300 Subject: [PATCH] Restore old code for decoding YUV420P. By mistake it was merged with changes that related to NV21(MACOS). possible fix for #143 --- src/QZXingFilter.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/QZXingFilter.cpp b/src/QZXingFilter.cpp index d61abb8..5d12fec 100644 --- a/src/QZXingFilter.cpp +++ b/src/QZXingFilter.cpp @@ -292,6 +292,29 @@ void QZXingFilterRunnable::processVideoFrameProbed(SimpleVideoFrame & videoFrame image_ptr = new QImage(data, width, height, QImage::Format_RGB16); break; case QVideoFrame::Format_YUV420P: + /// Format_YUV420P format, encountered on raspberry pi + image_ptr = new QImage(captureRect.targetWidth, captureRect.targetHeight, QImage::Format_Grayscale8); + pixel = image_ptr->bits(); + wh = width * height; + w_2 = width / 2; + wh_54 = wh * 5 / 4; + + for (int y = captureRect.startY; y < captureRect.endY; y++) { + const int Y_offset = y * width; + const int y_2 = y / 2; + const int U_offset = y_2 * w_2 + wh; + const int V_offset = y_2 * w_2 + wh_54; + for (int x = captureRect.startX; x < captureRect.endX; x++) { + const int x_2 = x / 2; + const uchar Y = data[Y_offset + x]; + const uchar U = data[U_offset + x_2]; + const uchar V = data[V_offset + x_2]; + *pixel = yuvToGray(Y, U, V); + ++pixel; + } + } + + break; case QVideoFrame::Format_NV12: /// nv12 format, encountered on macOS image_ptr = new QImage(captureRect.targetWidth, captureRect.targetHeight, QImage::Format_Grayscale8);