Patch Detail
Show a patch.
GET /api/1.1/patches/13708/?format=api
{ "id": 13708, "url": "https://patchwork.libcamera.org/api/1.1/patches/13708/?format=api", "web_url": "https://patchwork.libcamera.org/patch/13708/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210907002044.7319-6-laurent.pinchart@ideasonboard.com>", "date": "2021-09-07T00:20:44", "name": "[libcamera-devel,v2,5/5] qcam: viewfinder_gl: Support configurable stride in shaders", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "7c1ff158d5636ef1351412024879dced7f29e207", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/13708/mbox/", "series": [ { "id": 2484, "url": "https://patchwork.libcamera.org/api/1.1/series/2484/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2484", "date": "2021-09-07T00:20:39", "name": "qcam: Fix stride handling", "version": 2, "mbox": "https://patchwork.libcamera.org/series/2484/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/13708/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/13708/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A2018BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 7 Sep 2021 00:21:16 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1210469180;\n\tTue, 7 Sep 2021 02:21:13 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DC62260253\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 7 Sep 2021 02:21:08 +0200 (CEST)", "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 873C1993\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 7 Sep 2021 02:21:08 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"o+YsCFwZ\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1630974068;\n\tbh=qA/QDTXbRNCgEiMTWj43du7RQ3xu+VWaAzJ3TzR7K+c=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=o+YsCFwZ99KpJXjPqJbukLVsG5vHcaZitWUsRwSobeFFjj5cAYCIKLy4Wiqq1Gshm\n\t3/spGQygDuRaY/hFWzn/ZjK9kKGRDFnk+qXdgJKsRh1bWQ1lW92Q7bpaigndKJhMA1\n\tzQD6d9dFRUzPFu7bXKYIMfnNPmyIyyR3isfwNUwQ=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 7 Sep 2021 03:20:44 +0300", "Message-Id": "<20210907002044.7319-6-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.32.0", "In-Reply-To": "<20210907002044.7319-1-laurent.pinchart@ideasonboard.com>", "References": "<20210907002044.7319-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 5/5] qcam: viewfinder_gl: Support\n\tconfigurable stride in shaders", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The RGB and YUV conversion doesn't take the stride into account, neither\nwhen creating the textures, nor when sampling them. Fix it by using the\nstride as the texture width, and multiplying the x coordinate in the\nvertex shaders by a factor to only sample the active portion of the\nimage.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/qcam/assets/shader/identity.vert | 4 ++-\n src/qcam/viewfinder_gl.cpp | 54 ++++++++++++++++++++++------\n src/qcam/viewfinder_gl.h | 1 +\n 3 files changed, 47 insertions(+), 12 deletions(-)", "diff": "diff --git a/src/qcam/assets/shader/identity.vert b/src/qcam/assets/shader/identity.vert\nindex 6d6f7551017e..12c41377cfe7 100644\n--- a/src/qcam/assets/shader/identity.vert\n+++ b/src/qcam/assets/shader/identity.vert\n@@ -9,8 +9,10 @@ attribute vec4 vertexIn;\n attribute vec2 textureIn;\n varying vec2 textureOut;\n \n+uniform float stride_factor;\n+\n void main(void)\n {\n \tgl_Position = vertexIn;\n-\ttextureOut = textureIn;\n+\ttextureOut = vec2(textureIn.x * stride_factor, textureIn.y);\n }\ndiff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp\nindex aeb1ea02d2d5..3ae8b03accb5 100644\n--- a/src/qcam/viewfinder_gl.cpp\n+++ b/src/qcam/viewfinder_gl.cpp\n@@ -395,6 +395,7 @@ bool ViewFinderGL::createFragmentShader()\n \ttextureUniformV_ = shaderProgram_.uniformLocation(\"tex_v\");\n \ttextureUniformStep_ = shaderProgram_.uniformLocation(\"tex_step\");\n \ttextureUniformSize_ = shaderProgram_.uniformLocation(\"tex_size\");\n+\ttextureUniformStrideFactor_ = shaderProgram_.uniformLocation(\"stride_factor\");\n \ttextureUniformBayerFirstRed_ = shaderProgram_.uniformLocation(\"tex_bayer_first_red\");\n \n \t/* Create the textures. */\n@@ -464,6 +465,9 @@ void ViewFinderGL::initializeGL()\n \n void ViewFinderGL::doRender()\n {\n+\t/* Stride of the first plane, in pixels. */\n+\tunsigned int stridePixels;\n+\n \tswitch (format_) {\n \tcase libcamera::formats::NV12:\n \tcase libcamera::formats::NV21:\n@@ -477,7 +481,7 @@ void ViewFinderGL::doRender()\n \t\tglTexImage2D(GL_TEXTURE_2D,\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n-\t\t\t size_.width(),\n+\t\t\t stride_,\n \t\t\t size_.height(),\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n@@ -491,13 +495,15 @@ void ViewFinderGL::doRender()\n \t\tglTexImage2D(GL_TEXTURE_2D,\n \t\t\t 0,\n \t\t\t GL_LUMINANCE_ALPHA,\n-\t\t\t size_.width() / horzSubSample_,\n+\t\t\t stride_ / horzSubSample_,\n \t\t\t size_.height() / vertSubSample_,\n \t\t\t 0,\n \t\t\t GL_LUMINANCE_ALPHA,\n \t\t\t GL_UNSIGNED_BYTE,\n \t\t\t image_->data(1).data());\n \t\tshaderProgram_.setUniformValue(textureUniformU_, 1);\n+\n+\t\tstridePixels = stride_;\n \t\tbreak;\n \n \tcase libcamera::formats::YUV420:\n@@ -507,7 +513,7 @@ void ViewFinderGL::doRender()\n \t\tglTexImage2D(GL_TEXTURE_2D,\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n-\t\t\t size_.width(),\n+\t\t\t stride_,\n \t\t\t size_.height(),\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n@@ -521,7 +527,7 @@ void ViewFinderGL::doRender()\n \t\tglTexImage2D(GL_TEXTURE_2D,\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n-\t\t\t size_.width() / horzSubSample_,\n+\t\t\t stride_ / horzSubSample_,\n \t\t\t size_.height() / vertSubSample_,\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n@@ -535,13 +541,15 @@ void ViewFinderGL::doRender()\n \t\tglTexImage2D(GL_TEXTURE_2D,\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n-\t\t\t size_.width() / horzSubSample_,\n+\t\t\t stride_ / horzSubSample_,\n \t\t\t size_.height() / vertSubSample_,\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n \t\t\t GL_UNSIGNED_BYTE,\n \t\t\t image_->data(2).data());\n \t\tshaderProgram_.setUniformValue(textureUniformV_, 2);\n+\n+\t\tstridePixels = stride_;\n \t\tbreak;\n \n \tcase libcamera::formats::YVU420:\n@@ -551,7 +559,7 @@ void ViewFinderGL::doRender()\n \t\tglTexImage2D(GL_TEXTURE_2D,\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n-\t\t\t size_.width(),\n+\t\t\t stride_,\n \t\t\t size_.height(),\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n@@ -565,7 +573,7 @@ void ViewFinderGL::doRender()\n \t\tglTexImage2D(GL_TEXTURE_2D,\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n-\t\t\t size_.width() / horzSubSample_,\n+\t\t\t stride_ / horzSubSample_,\n \t\t\t size_.height() / vertSubSample_,\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n@@ -579,13 +587,15 @@ void ViewFinderGL::doRender()\n \t\tglTexImage2D(GL_TEXTURE_2D,\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n-\t\t\t size_.width() / horzSubSample_,\n+\t\t\t stride_ / horzSubSample_,\n \t\t\t size_.height() / vertSubSample_,\n \t\t\t 0,\n \t\t\t GL_LUMINANCE,\n \t\t\t GL_UNSIGNED_BYTE,\n \t\t\t image_->data(2).data());\n \t\tshaderProgram_.setUniformValue(textureUniformU_, 1);\n+\n+\t\tstridePixels = stride_;\n \t\tbreak;\n \n \tcase libcamera::formats::UYVY:\n@@ -602,7 +612,7 @@ void ViewFinderGL::doRender()\n \t\tglTexImage2D(GL_TEXTURE_2D,\n \t\t\t 0,\n \t\t\t GL_RGBA,\n-\t\t\t size_.width() / 2,\n+\t\t\t stride_ / 4,\n \t\t\t size_.height(),\n \t\t\t 0,\n \t\t\t GL_RGBA,\n@@ -619,6 +629,8 @@ void ViewFinderGL::doRender()\n \t\tshaderProgram_.setUniformValue(textureUniformStep_,\n \t\t\t\t\t 1.0f / (size_.width() / 2 - 1),\n \t\t\t\t\t 1.0f /* not used */);\n+\n+\t\tstridePixels = stride_ / 2;\n \t\tbreak;\n \n \tcase libcamera::formats::ABGR8888:\n@@ -630,13 +642,15 @@ void ViewFinderGL::doRender()\n \t\tglTexImage2D(GL_TEXTURE_2D,\n \t\t\t 0,\n \t\t\t GL_RGBA,\n-\t\t\t size_.width(),\n+\t\t\t stride_ / 4,\n \t\t\t size_.height(),\n \t\t\t 0,\n \t\t\t GL_RGBA,\n \t\t\t GL_UNSIGNED_BYTE,\n \t\t\t image_->data(0).data());\n \t\tshaderProgram_.setUniformValue(textureUniformY_, 0);\n+\n+\t\tstridePixels = stride_ / 4;\n \t\tbreak;\n \n \tcase libcamera::formats::BGR888:\n@@ -646,13 +660,15 @@ void ViewFinderGL::doRender()\n \t\tglTexImage2D(GL_TEXTURE_2D,\n \t\t\t 0,\n \t\t\t GL_RGB,\n-\t\t\t size_.width(),\n+\t\t\t stride_ / 3,\n \t\t\t size_.height(),\n \t\t\t 0,\n \t\t\t GL_RGB,\n \t\t\t GL_UNSIGNED_BYTE,\n \t\t\t image_->data(0).data());\n \t\tshaderProgram_.setUniformValue(textureUniformY_, 0);\n+\n+\t\tstridePixels = stride_ / 3;\n \t\tbreak;\n \n \tcase libcamera::formats::SBGGR8:\n@@ -692,11 +708,27 @@ void ViewFinderGL::doRender()\n \t\tshaderProgram_.setUniformValue(textureUniformStep_,\n \t\t\t\t\t 1.0f / (stride_ - 1),\n \t\t\t\t\t 1.0f / (size_.height() - 1));\n+\n+\t\t/*\n+\t\t * The stride is already taken into account in the shaders, set\n+\t\t * the generic stride factor to 1.0.\n+\t\t */\n+\t\tstridePixels = size_.width();\n \t\tbreak;\n \n \tdefault:\n+\t\tstridePixels = size_.width();\n \t\tbreak;\n \t};\n+\n+\t/*\n+\t * Compute the stride factor for the vertex shader, to map the\n+\t * horizontal texture coordinate range [0.0, 1.0] to the active portion\n+\t * of the image.\n+\t */\n+\tshaderProgram_.setUniformValue(textureUniformStrideFactor_,\n+\t\t\t\t static_cast<float>(size_.width() - 1) /\n+\t\t\t\t (stridePixels - 1));\n }\n \n void ViewFinderGL::paintGL()\ndiff --git a/src/qcam/viewfinder_gl.h b/src/qcam/viewfinder_gl.h\nindex 2b2b1e86035a..37b1ddd04b1d 100644\n--- a/src/qcam/viewfinder_gl.h\n+++ b/src/qcam/viewfinder_gl.h\n@@ -97,6 +97,7 @@ private:\n \n \t/* Raw Bayer texture parameters */\n \tGLuint textureUniformSize_;\n+\tGLuint textureUniformStrideFactor_;\n \tGLuint textureUniformBayerFirstRed_;\n \tQPointF firstRed_;\n \n", "prefixes": [ "libcamera-devel", "v2", "5/5" ] }