Skip to content

Commit

Permalink
Isuue #1 fixed (174x100 yuv data abnormality)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterAler committed Jun 27, 2020
1 parent 8c0c28f commit 5382b36
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 7 additions & 0 deletions OpenGLDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ void OpenGLDisplay::paintGL()
glActiveTexture(GL_TEXTURE0);
// Use the texture generated from y to generate texture
glBindTexture(GL_TEXTURE_2D, impl->id_y);

// Fixes abnormality with 174x100 yuv data
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);

// Use the memory mBufYuv data to create a real y data texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, impl->mVideoW, impl->mVideoH, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, impl->mBufYuv);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ a simple frame (okay, with YUV 2 RGB conversion) doesn't feel like something, wh

## How it works?

Since Qt supports OpenGL ES with shaders and other fine stuff (starting with Qt 5.6 or so), you can obtain
Since Qt supports modern OpenGL (and even OpenGL ES) with shaders and other fine stuff (starting with Qt 5.6 or so), you can obtain
a well-behaving rendering widget, possible to be embedded in your widget app.

Cross-platform and _maybe_ even portable (depends on the drivers/hardware support etc).
Expand Down
13 changes: 6 additions & 7 deletions TestWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "TestWidget.h"
#include "ui_TestWidget.h"

#include <fstream>

#include <QApplication>
#include <QFile>
#include <QByteArray>
Expand Down Expand Up @@ -73,14 +75,11 @@ void TestWidget::readAllSampleFile()
impl->mSize = QFile(YUV_FILE_PATH).size();
impl->mBuffer = new unsigned char[impl->mSize];

FILE* f = fopen(YUV_FILE_PATH, "rb");
unsigned readSize = fread(impl->mBuffer, 1, impl->mSize, f);
std::ifstream yuv_file(YUV_FILE_PATH, std::ios::binary);
yuv_file.read(reinterpret_cast<char*>(impl->mBuffer), impl->mSize);

if (readSize < impl->mSize && ferror(f))
{
qDebug() << "YUV file read error readSize: " << readSize;
}
fclose(f);
if (yuv_file.tellg() < impl->mSize)
qWarning() << "YUV file read error, could read only: " << yuv_file.tellg();

impl->ui->playAllButton->setEnabled(true);
}
Expand Down

0 comments on commit 5382b36

Please sign in to comment.