Skip to content

Commit

Permalink
Merge pull request #80 from err4nt/master
Browse files Browse the repository at this point in the history
Add YUYV image format support to QZXingFilter
  • Loading branch information
ftylitak authored Apr 25, 2018
2 parents 669a9b5 + 62e66b1 commit d61f2ac
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/QZXingFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ void QZXingFilterRunnable::processVideoFrameProbed(SimpleVideoFrame & videoFrame
int w_2;
int wh_54;

uint32_t *yuvPtr = (uint32_t *)data;

/// Create QImage from QVideoFrame.
QImage *image_ptr = nullptr;

Expand Down Expand Up @@ -280,7 +282,23 @@ void QZXingFilterRunnable::processVideoFrameProbed(SimpleVideoFrame & videoFrame
}
}
break;
/// TODO: Handle (create QImages from) YUV formats.
case QVideoFrame::Format_YUYV:
image_ptr = new QImage(captureRect.targetWidth, captureRect.targetHeight, QImage::Format_Grayscale8);
pixel = image_ptr->bits();

for (int y = captureRect.startY; y < captureRect.endY; y++){
uint32_t *row = &yuvPtr[y*(width/2)-(width/4)];
for (int x = captureRect.startX; x < captureRect.endX; x++){
uint32_t pxl = row[x];
const int y0 = (unsigned char)((uint8_t *)&pxl)[0];
const int u = (unsigned char)((uint8_t *)&pxl)[1];
const int v = (unsigned char)((uint8_t *)&pxl)[3];
*pixel = yuvToGray(y0, u, v);
++pixel;
}
}
break;
/// TODO: Handle (create QImages from) YUV formats.
default:
QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(videoFrame.pixelFormat);
image_ptr = new QImage(data, width, height, imageFormat);
Expand All @@ -300,11 +318,11 @@ void QZXingFilterRunnable::processVideoFrameProbed(SimpleVideoFrame & videoFrame
if (captureRect.isValid && image_ptr->size() != _captureRect.size())
image_ptr = new QImage(image_ptr->copy(_captureRect));

// qDebug() << "image.size()" << image.size();
// qDebug() << "image.format()" << image.format();
// qDebug() << "videoFrame.pixelFormat" << videoFrame.pixelFormat;
// const QString path = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/qrtest/test_" + QString::number(i % 100) + ".png";
// qDebug() << "saving image" << i << "at:" << path << image.save(path);
//qDebug() << "image.size()" << image_ptr->size();
//qDebug() << "image.format()" << image_ptr->format();
//qDebug() << "videoFrame.pixelFormat" << videoFrame.pixelFormat;
//const QString path = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/qrtest/test_" + QString::number(i % 100) + ".png";
//qDebug() << "saving image" << i << "at:" << path << image_ptr->save(path);

//QZXingImageProvider::getInstance()->storeImage(image);

Expand Down

0 comments on commit d61f2ac

Please sign in to comment.