[libcamera-devel,3/4] qcam: viewfinder_gl: RAW10P: handle the padding bytes properly
diff mbox series

Message ID 20210113130832.15549-4-andrey.konovalov@linaro.org
State Superseded
Headers show
Series
  • qcam: viewfinder_gl: add RAW10P and RAW12P format support
Related show

Commit Message

Andrey Konovalov Jan. 13, 2021, 1:08 p.m. UTC
The texture size must account for the padding bytes which may be present
at the end of the lines in the frame.

Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
---
 src/qcam/viewfinder_gl.cpp | 11 +++++++----
 src/qcam/viewfinder_gl.h   |  1 +
 2 files changed, 8 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp
index b324d77f..9db536a6 100644
--- a/src/qcam/viewfinder_gl.cpp
+++ b/src/qcam/viewfinder_gl.cpp
@@ -111,6 +111,10 @@  void ViewFinderGL::render(libcamera::FrameBuffer *buffer, MappedBuffer *map)
 		renderComplete(buffer_);
 
 	data_ = static_cast<unsigned char *>(map->memory);
+	/*
+	 * \todo Get the stride from the buffer instead of computing it naively
+	 */
+	stride_ = buffer->metadata().planes[0].bytesused / size_.height();
 	update();
 	buffer_ = buffer;
 }
@@ -594,14 +598,13 @@  void ViewFinderGL::doRender()
 		/*
 		 * Packed raw Bayer 10-bit formats are stored in GL_RED texture.
 		 * The texture width is 10/8 of the image width.
-		 * TODO: account for padding bytes at the end of the line.
 		 */
 		glActiveTexture(GL_TEXTURE0);
 		configureTexture(*textures_[0]);
 		glTexImage2D(GL_TEXTURE_2D,
 			     0,
 			     GL_RED,
-			     size_.width() * 5 / 4,
+			     stride_,
 			     size_.height(),
 			     0,
 			     GL_RED,
@@ -611,12 +614,12 @@  void ViewFinderGL::doRender()
 		shaderProgram_.setUniformValue(textureUniformBayerFirstRed_,
 					       firstRed_);
 		shaderProgram_.setUniformValue(textureUniformSize_,
-					       size_.width() * 5 / 4,
+					       stride_,
 					       size_.height(),
 					       size_.width(),
 					       size_.height());
 		shaderProgram_.setUniformValue(textureUniformStep_,
-					       1.0f / (size_.width() * 5 / 4 - 1),
+					       1.0f / (stride_ - 1),
 					       1.0f / (size_.height() - 1));
 		break;
 
diff --git a/src/qcam/viewfinder_gl.h b/src/qcam/viewfinder_gl.h
index 337718e3..49f8364a 100644
--- a/src/qcam/viewfinder_gl.h
+++ b/src/qcam/viewfinder_gl.h
@@ -66,6 +66,7 @@  private:
 	libcamera::FrameBuffer *buffer_;
 	libcamera::PixelFormat format_;
 	QSize size_;
+	int stride_;
 	unsigned char *data_;
 
 	/* Shaders */