From patchwork Mon Sep 6 22:56:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13694 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 4F606BE175 for ; Mon, 6 Sep 2021 22:57:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 03E9F69185; Tue, 7 Sep 2021 00:57:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cBvLb4kf"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F2236918A for ; Tue, 7 Sep 2021 00:57:10 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ACB44993; Tue, 7 Sep 2021 00:57:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630969029; bh=mjp6bsNyrmQYd+BbqSpInOVicnd2/UieEMCHU/KAj4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cBvLb4kfbJWZkxpC22qvt40OtzHLlDyPKC7ft1aRh0BlskJL7OhhuZwLBVe9f7mc9 29hhH417R4kx4LTjSPSUMyqV2DlXHexXk/au/mulFHwqGRUWeDElMlLxqo0rp3K1Kk NkhsZCwnMH/SqZKm5MkgnnAhyos46xRuthg/wz6s= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Sep 2021 01:56:34 +0300 Message-Id: <20210906225636.14683-28-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210906225420.13275-1-laurent.pinchart@ideasonboard.com> References: <20210906225420.13275-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 28/30] qcam: viewfinder_gl: Support multi-planar buffers X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Now that the ViewFinderGL receives an Image, it can trivially support multi-planar buffers. Signed-off-by: Laurent Pinchart Reviewed-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham --- src/qcam/viewfinder_gl.cpp | 38 +++++++++++++++++--------------------- src/qcam/viewfinder_gl.h | 2 +- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp index 87e4fe03cb8d..32232faa2ad8 100644 --- a/src/qcam/viewfinder_gl.cpp +++ b/src/qcam/viewfinder_gl.cpp @@ -56,7 +56,7 @@ static const QList supportedFormats{ }; ViewFinderGL::ViewFinderGL(QWidget *parent) - : QOpenGLWidget(parent), buffer_(nullptr), data_(nullptr), + : QOpenGLWidget(parent), buffer_(nullptr), image_(nullptr), vertexBuffer_(QOpenGLBuffer::VertexBuffer) { } @@ -102,6 +102,7 @@ void ViewFinderGL::stop() if (buffer_) { renderComplete(buffer_); buffer_ = nullptr; + image_ = nullptr; } } @@ -114,15 +115,10 @@ QImage ViewFinderGL::getCurrentImage() void ViewFinderGL::render(libcamera::FrameBuffer *buffer, Image *image) { - if (buffer->planes().size() != 1) { - qWarning() << "Multi-planar buffers are not supported"; - return; - } - if (buffer_) renderComplete(buffer_); - data_ = image->data(0).data(); + image_ = image; /* * \todo Get the stride from the buffer instead of computing it naively */ @@ -489,7 +485,7 @@ void ViewFinderGL::doRender() 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, - data_); + image_->data(0).data()); shaderProgram_.setUniformValue(textureUniformY_, 0); /* Activate texture UV/VU */ @@ -503,7 +499,7 @@ void ViewFinderGL::doRender() 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, - data_ + size_.width() * size_.height()); + image_->data(1).data()); shaderProgram_.setUniformValue(textureUniformU_, 1); break; @@ -519,7 +515,7 @@ void ViewFinderGL::doRender() 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, - data_); + image_->data(0).data()); shaderProgram_.setUniformValue(textureUniformY_, 0); /* Activate texture U */ @@ -533,7 +529,7 @@ void ViewFinderGL::doRender() 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, - data_ + size_.width() * size_.height()); + image_->data(1).data()); shaderProgram_.setUniformValue(textureUniformU_, 1); /* Activate texture V */ @@ -547,7 +543,7 @@ void ViewFinderGL::doRender() 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, - data_ + size_.width() * size_.height() * 5 / 4); + image_->data(2).data()); shaderProgram_.setUniformValue(textureUniformV_, 2); break; @@ -563,7 +559,7 @@ void ViewFinderGL::doRender() 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, - data_); + image_->data(0).data()); shaderProgram_.setUniformValue(textureUniformY_, 0); /* Activate texture V */ @@ -577,7 +573,7 @@ void ViewFinderGL::doRender() 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, - data_ + size_.width() * size_.height()); + image_->data(1).data()); shaderProgram_.setUniformValue(textureUniformV_, 2); /* Activate texture U */ @@ -591,7 +587,7 @@ void ViewFinderGL::doRender() 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, - data_ + size_.width() * size_.height() * 5 / 4); + image_->data(2).data()); shaderProgram_.setUniformValue(textureUniformU_, 1); break; @@ -602,7 +598,7 @@ void ViewFinderGL::doRender() /* * Packed YUV formats are stored in a RGBA texture to match the * OpenGL texel size with the 4 bytes repeating pattern in YUV. - * The texture width is thus half of the image with. + * The texture width is thus half of the image_ with. */ glActiveTexture(GL_TEXTURE0); configureTexture(*textures_[0]); @@ -614,7 +610,7 @@ void ViewFinderGL::doRender() 0, GL_RGBA, GL_UNSIGNED_BYTE, - data_); + image_->data(0).data()); shaderProgram_.setUniformValue(textureUniformY_, 0); /* @@ -642,7 +638,7 @@ void ViewFinderGL::doRender() 0, GL_RGBA, GL_UNSIGNED_BYTE, - data_); + image_->data(0).data()); shaderProgram_.setUniformValue(textureUniformY_, 0); break; @@ -658,7 +654,7 @@ void ViewFinderGL::doRender() 0, GL_RGB, GL_UNSIGNED_BYTE, - data_); + image_->data(0).data()); shaderProgram_.setUniformValue(textureUniformY_, 0); break; @@ -689,7 +685,7 @@ void ViewFinderGL::doRender() 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, - data_); + image_->data(0).data()); shaderProgram_.setUniformValue(textureUniformY_, 0); shaderProgram_.setUniformValue(textureUniformBayerFirstRed_, firstRed_); @@ -714,7 +710,7 @@ void ViewFinderGL::paintGL() << "create fragment shader failed."; } - if (data_) { + if (image_) { glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/src/qcam/viewfinder_gl.h b/src/qcam/viewfinder_gl.h index 7cd8ef3316b9..72a60ecb9159 100644 --- a/src/qcam/viewfinder_gl.h +++ b/src/qcam/viewfinder_gl.h @@ -67,7 +67,7 @@ private: libcamera::PixelFormat format_; QSize size_; unsigned int stride_; - unsigned char *data_; + Image *image_; /* Shaders */ QOpenGLShaderProgram shaderProgram_;