From patchwork Tue Nov 3 15:50:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10328 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 DEAB7BDB89 for ; Tue, 3 Nov 2020 15:51:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A76C462C68; Tue, 3 Nov 2020 16:51:24 +0100 (CET) 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="mPsU0xSr"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D343D62C58 for ; Tue, 3 Nov 2020 16:51:21 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4F1C2B9C; Tue, 3 Nov 2020 16:51:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1604418681; bh=JbnoKqKyW6cNdAvP5q3oSVvE+Cx0gakltQfn0ca8qLo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mPsU0xSrHHfOKUg2ZtbE9v72BHbN2Ku8P/4AW9Zu6HqMUAzDhCfnjkD+l3/qJrPNi fkFrIktxe3dAkN4qANEdCRoJecwtOA6cdDkfHQWb11YBPaQIahhMVa28qaGSWpjDiu MzmuAFqvB/OQiviW53wn5G5NaYl7iiBvFuEDbSuk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 3 Nov 2020 17:50:25 +0200 Message-Id: <20201103155025.5948-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201103155025.5948-1-laurent.pinchart@ideasonboard.com> References: <20201103155025.5948-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 7/7] qcam: viewfinder_gl: Add support for RGB formats 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" Add support for 24-bit and 32-bit RGB formats. The fragment samples the texture and reorders the components, using a pattern set through the RGB_PATTERN macro. An alternative to manual reordering in the shader would be to set the texture swizzling mask. This is however not available in OpenGL ES before version 3.0, which we don't mandate at the moment. Only the BGR888 and RGB888 formats have been tested, with the vimc pipeline handler. Signed-off-by: Laurent Pinchart Reviewed-by: Andrey Konovalov Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- src/qcam/assets/shader/RGB.frag | 22 +++++++++ src/qcam/assets/shader/shaders.qrc | 1 + src/qcam/viewfinder_gl.cpp | 71 ++++++++++++++++++++++++++++-- 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 src/qcam/assets/shader/RGB.frag diff --git a/src/qcam/assets/shader/RGB.frag b/src/qcam/assets/shader/RGB.frag new file mode 100644 index 000000000000..4c374ac98095 --- /dev/null +++ b/src/qcam/assets/shader/RGB.frag @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Laurent Pinchart + * + * RGB.frag - Fragment shader code for RGB formats + */ + +#ifdef GL_ES +precision mediump float; +#endif + +varying vec2 textureOut; +uniform sampler2D tex_y; + +void main(void) +{ + vec3 rgb; + + rgb = texture2D(tex_y, textureOut).RGB_PATTERN; + + gl_FragColor = vec4(rgb, 1.0); +} diff --git a/src/qcam/assets/shader/shaders.qrc b/src/qcam/assets/shader/shaders.qrc index 863109146281..8a8f9de1a5fa 100644 --- a/src/qcam/assets/shader/shaders.qrc +++ b/src/qcam/assets/shader/shaders.qrc @@ -1,6 +1,7 @@ + RGB.frag YUV_2_planes.frag YUV_3_planes.frag YUV_packed.frag diff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp index cbc1365500f5..5d9b442e7985 100644 --- a/src/qcam/viewfinder_gl.cpp +++ b/src/qcam/viewfinder_gl.cpp @@ -14,21 +14,28 @@ #include static const QList supportedFormats{ - /* Packed (single plane) */ + /* YUV - packed (single plane) */ libcamera::formats::UYVY, libcamera::formats::VYUY, libcamera::formats::YUYV, libcamera::formats::YVYU, - /* Semi planar (two planes) */ + /* YUV - semi planar (two planes) */ libcamera::formats::NV12, libcamera::formats::NV21, libcamera::formats::NV16, libcamera::formats::NV61, libcamera::formats::NV24, libcamera::formats::NV42, - /* Fully planar (three planes) */ + /* YUV - fully planar (three planes) */ libcamera::formats::YUV420, libcamera::formats::YVU420, + /* RGB */ + libcamera::formats::ABGR8888, + libcamera::formats::ARGB8888, + libcamera::formats::BGRA8888, + libcamera::formats::RGBA8888, + libcamera::formats::BGR888, + libcamera::formats::RGB888, }; ViewFinderGL::ViewFinderGL(QWidget *parent) @@ -172,6 +179,30 @@ bool ViewFinderGL::selectFormat(const libcamera::PixelFormat &format) fragmentShaderDefines_.append("#define YUV_PATTERN_YVYU"); fragmentShaderFile_ = ":YUV_packed.frag"; break; + case libcamera::formats::ABGR8888: + fragmentShaderDefines_.append("#define RGB_PATTERN rgb"); + fragmentShaderFile_ = ":RGB.frag"; + break; + case libcamera::formats::ARGB8888: + fragmentShaderDefines_.append("#define RGB_PATTERN bgr"); + fragmentShaderFile_ = ":RGB.frag"; + break; + case libcamera::formats::BGRA8888: + fragmentShaderDefines_.append("#define RGB_PATTERN gba"); + fragmentShaderFile_ = ":RGB.frag"; + break; + case libcamera::formats::RGBA8888: + fragmentShaderDefines_.append("#define RGB_PATTERN abg"); + fragmentShaderFile_ = ":RGB.frag"; + break; + case libcamera::formats::BGR888: + fragmentShaderDefines_.append("#define RGB_PATTERN rgb"); + fragmentShaderFile_ = ":RGB.frag"; + break; + case libcamera::formats::RGB888: + fragmentShaderDefines_.append("#define RGB_PATTERN bgr"); + fragmentShaderFile_ = ":RGB.frag"; + break; default: ret = false; qWarning() << "[ViewFinderGL]:" @@ -481,6 +512,40 @@ void ViewFinderGL::doRender() 1.0f / (size_.width() / 2 - 1)); break; + case libcamera::formats::ABGR8888: + case libcamera::formats::ARGB8888: + case libcamera::formats::BGRA8888: + case libcamera::formats::RGBA8888: + glActiveTexture(GL_TEXTURE0); + configureTexture(*textures_[0]); + glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGBA, + size_.width(), + size_.height(), + 0, + GL_RGBA, + GL_UNSIGNED_BYTE, + data_); + shaderProgram_.setUniformValue(textureUniformY_, 0); + break; + + case libcamera::formats::BGR888: + case libcamera::formats::RGB888: + glActiveTexture(GL_TEXTURE0); + configureTexture(*textures_[0]); + glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGB, + size_.width(), + size_.height(), + 0, + GL_RGB, + GL_UNSIGNED_BYTE, + data_); + shaderProgram_.setUniformValue(textureUniformY_, 0); + break; + default: break; };