[{"id":19746,"web_url":"https://patchwork.libcamera.org/comment/19746/","msgid":"<e4590578-8b95-2a27-fc67-153b94e05d29@ideasonboard.com>","date":"2021-09-21T15:38:08","subject":"Re: [libcamera-devel] [PATCH v2 5/5] qcam: viewfinder_gl: Support\n\tconfigurable stride in shaders","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"On 07/09/2021 01:20, Laurent Pinchart wrote:\n> The RGB and YUV conversion doesn't take the stride into account, neither\n> when creating the textures, nor when sampling them. Fix it by using the\n> stride as the texture width, and multiplying the x coordinate in the\n> vertex shaders by a factor to only sample the active portion of the\n> image.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nA somewhat not-particularly-confident, but no disagreement:\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\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(-)\n> \n> diff --git a/src/qcam/assets/shader/identity.vert b/src/qcam/assets/shader/identity.vert\n> index 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>  }\n> diff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp\n> index 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()\n> diff --git a/src/qcam/viewfinder_gl.h b/src/qcam/viewfinder_gl.h\n> index 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>","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 B952DBF01C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 21 Sep 2021 15:38:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0735569188;\n\tTue, 21 Sep 2021 17:38: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 F016760247\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 21 Sep 2021 17:38:11 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 644A82BA;\n\tTue, 21 Sep 2021 17:38:11 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"tDZSJnS7\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1632238691;\n\tbh=OZKhKoK5dCej9hzFM5Fq1EMGXmWD/4mfbN9qf++6nEg=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=tDZSJnS7O/OKgiFNSlrI4Zj795iNIiFavDvgjWhVjo+LH4bUWrqg3xceqDXrk4U0E\n\t40DRRFtnbelIJeFE1sPC79nR2J3jxt1TofzDCTuCZBKD8X27UQsmB6v507upVjQDjg\n\txcJ6MuWntWmbm2lBkyCOtRnm5uCpg1yRE3DkQ2M8=","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20210907002044.7319-1-laurent.pinchart@ideasonboard.com>\n\t<20210907002044.7319-6-laurent.pinchart@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<e4590578-8b95-2a27-fc67-153b94e05d29@ideasonboard.com>","Date":"Tue, 21 Sep 2021 16:38:08 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.11.0","MIME-Version":"1.0","In-Reply-To":"<20210907002044.7319-6-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"7bit","Subject":"Re: [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>"}},{"id":19777,"web_url":"https://patchwork.libcamera.org/comment/19777/","msgid":"<20210922081015.GK4382@pyrite.rasen.tech>","date":"2021-09-22T08:10:15","subject":"Re: [libcamera-devel] [PATCH v2 5/5] qcam: viewfinder_gl: Support\n\tconfigurable stride in shaders","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Hi Laurent,\n\nOn Tue, Sep 07, 2021 at 03:20:44AM +0300, Laurent Pinchart wrote:\n> The RGB and YUV conversion doesn't take the stride into account, neither\n> when creating the textures, nor when sampling them. Fix it by using the\n> stride as the texture width, and multiplying the x coordinate in the\n> vertex shaders by a factor to only sample the active portion of the\n> image.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\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(-)\n> \n> diff --git a/src/qcam/assets/shader/identity.vert b/src/qcam/assets/shader/identity.vert\n> index 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>  }\n> diff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp\n> index 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()\n> diff --git a/src/qcam/viewfinder_gl.h b/src/qcam/viewfinder_gl.h\n> index 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> -- \n> Regards,\n> \n> Laurent Pinchart\n>","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 BA9C1BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 22 Sep 2021 08:10:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 04A436918C;\n\tWed, 22 Sep 2021 10:10:25 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6D600687DD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Sep 2021 10:10:23 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E479AF1;\n\tWed, 22 Sep 2021 10:10:21 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"kPo5lOvT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1632298223;\n\tbh=GtEWZHTGC1Uo2CG+SxFfPoHRR34oTW1giWAScfcnPws=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=kPo5lOvT8mssSzT2KKEC9xKCdd0PVIEOs+FVUHwCF3LZRuofMc1ahy/8naj8nOksK\n\tjbBPA1lXRg/X/JDcPxZy9N7YOSnGJQOKwVChQeerXko8TmMInwy2OwAG5aKnUnagBy\n\tFfmxcMPRzVEqt6ni2iKK1sSRjV44E2LXczBDUoH8=","Date":"Wed, 22 Sep 2021 17:10:15 +0900","From":"paul.elder@ideasonboard.com","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20210922081015.GK4382@pyrite.rasen.tech>","References":"<20210907002044.7319-1-laurent.pinchart@ideasonboard.com>\n\t<20210907002044.7319-6-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20210907002044.7319-6-laurent.pinchart@ideasonboard.com>","Subject":"Re: [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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]