Show a patch.

GET /api/patches/13702/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 13702,
    "url": "https://patchwork.libcamera.org/api/patches/13702/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13702/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20210906230436.17106-6-laurent.pinchart@ideasonboard.com>",
    "date": "2021-09-06T23:04:36",
    "name": "[libcamera-devel,v1,5/5] qcam: viewfinder_gl: Support configurable stride in shaders",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "7c1ff158d5636ef1351412024879dced7f29e207",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/13702/mbox/",
    "series": [
        {
            "id": 2483,
            "url": "https://patchwork.libcamera.org/api/series/2483/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2483",
            "date": "2021-09-06T23:04:32",
            "name": "qcam: Fix stride handling",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2483/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13702/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13702/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 3E671C3242\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Sep 2021 23:05:06 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 96D8669182;\n\tTue,  7 Sep 2021 01:05:03 +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 B84B169167\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 01:04:59 +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 5A2FE993\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 01:04:59 +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=\"qfJdZHCV\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1630969499;\n\tbh=qA/QDTXbRNCgEiMTWj43du7RQ3xu+VWaAzJ3TzR7K+c=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=qfJdZHCV/UYmk0NW29ns9XP+4ZBC70CYW11DaeLhwHqJGW3YdAzMIyC7Pq0sI1QoQ\n\tKX/Nw9cIbj20+3p4zGCMmDXh6VTrydaC0IBR9UEvL9D++r2bPsj+7ffnJBO0LJh/Sb\n\tepfe9XYHGsx1zdT707Xwti3XaN1t6aa30YMkoq7I=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue,  7 Sep 2021 02:04:36 +0300",
        "Message-Id": "<20210906230436.17106-6-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.32.0",
        "In-Reply-To": "<20210906230436.17106-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20210906230436.17106-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v1 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",
        "v1",
        "5/5"
    ]
}