{"id":17116,"url":"https://patchwork.libcamera.org/api/1.1/patches/17116/?format=json","web_url":"https://patchwork.libcamera.org/patch/17116/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220814160747.52093-1-kunalagarwal1072002@gmail.com>","date":"2022-08-14T16:07:42","name":"[libcamera-devel,v3,1/6] pipeline: simple: shader: Shaders for debayering","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"3613b8480b5d739102d6068d3626778a65f408c4","submitter":{"id":116,"url":"https://patchwork.libcamera.org/api/1.1/people/116/?format=json","name":"Kunal Agarwal","email":"kunalagarwal1072002@gmail.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17116/mbox/","series":[{"id":3414,"url":"https://patchwork.libcamera.org/api/1.1/series/3414/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3414","date":"2022-08-14T16:07:42","name":"[libcamera-devel,v3,1/6] pipeline: simple: shader: Shaders for debayering","version":3,"mbox":"https://patchwork.libcamera.org/series/3414/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17116/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17116/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 D3F7DC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 14 Aug 2022 16:08:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 24D0B61FC1;\n\tSun, 14 Aug 2022 18:08:11 +0200 (CEST)","from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com\n\t[IPv6:2607:f8b0:4864:20::1034])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E26F361FBA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 14 Aug 2022 18:08:09 +0200 (CEST)","by mail-pj1-x1034.google.com with SMTP id\n\tw11-20020a17090a380b00b001f73f75a1feso12545050pjb.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 14 Aug 2022 09:08:09 -0700 (PDT)","from pop-os.localdomain ([115.96.217.20])\n\tby smtp.googlemail.com with ESMTPSA id\n\tj6-20020a170902da8600b001709aea1516sm5576653plx.276.2022.08.14.09.08.05\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSun, 14 Aug 2022 09:08:07 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660493291;\n\tbh=CFCCm3qhsYlV/cSMq0SuqhAn9aXHQPSameYXDa/7Guk=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=fTzog0ciAyB8GsjO/bAwQt4e0BiVqDSKoJaMr1QuLmzxoAB2Cl1+Wc0qfAd53iCwC\n\tnDyn9vQ/EoG7BRTQHz6ikc0ojWKbJdgyvFMZu6fv1HGZREOXXLQCvn6n/CPrSlqCaS\n\t447GVgmyK97yNDFtU/raRUw6E0FLWNUoEVrcZ8H3Qanr2nLk0ribt9Xf0aqd9NF0Vt\n\twQr6I8dv0LSswNwnmzEfXu9bBJc0409v3/AsdeiKEJpaGC1kqT4pjsetJKpr9vnGrv\n\tkshNwdRKmovvbIJV/pF3oFhDGAHwXgMyokcxZpsAOjvUX3MQpLeOANx9YNbkzFyM90\n\t6hkZvblriL5Eg==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:from:to:cc;\n\tbh=Mv2/OGgWITkybWi8yKAUa6aKvJhjxQYpPZCXqcbgkr0=;\n\tb=eScTQl+wmZU+rKw5uN/VVhMtZhdq8HZ6yeSR+fksErP7NXZw504IUzBiqSdmphH/W/\n\tr2Bvbrdf6undZNg4dyvQuCkcRdsprdi3EMq5n3VWg2t2pjtp8hda8qMDjIwyh3M0Clt7\n\tgIY5rSvHwtCtkZoiT6ECBVHqaYHy6ie9qdjwdW4I6FZfQ/qn+FVRXv9HYu+bJmA6jW8A\n\tOc3N/9cE623DnL/+Ij69Yfvq061WXykSRq8ouLNuIg0b5rqwq6Np0UqmHnXliOKyezOh\n\tZM///cXiIIc7Mf61JQI2N0mK738AJf6FfsRu6IvwSxsGegxRB2jhJs2sUrnEWDwHe1SJ\n\tnVTw=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"eScTQl+w\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:x-gm-message-state:from:to:cc;\n\tbh=Mv2/OGgWITkybWi8yKAUa6aKvJhjxQYpPZCXqcbgkr0=;\n\tb=WgbHy+IXBYWVuxmtPaqTdPgCa9TaNNwDdKfl4ukHSWGIaajVEIem9tAzDaFxJmnxVk\n\tL8uSL67iQXp81izViRPQy6XrLZHHXEjs8tPYl8SlGkccHNKHAO0Ke9gaZ1Kl7zQ/bG1i\n\tUU9Q+YXXTVD+ehSZvOG5iB4ohjOFHky+CTV68z7diNrj4M1Y1Rw4H8mq0EJdFgSs4rGy\n\tsWjzdgU35hm9/YgwZQHOHNOPDnWpGsOTck45AlYSWAjDTMG3lUAhWPPfbfMdmsQwsM4r\n\tdJtYF4xADrgUQJE064USIJVtvTSbM8s9OdiRTykTFxOpmvtT3p/GKHgDIUvUj2fRafm5\n\tqiCA==","X-Gm-Message-State":"ACgBeo2oHsKN0dZZgzuYeueE9u75BgOIkogWtFvJoEXyI0vb9AomfgxT\n\tHUgHZpxqAyvIvrsf9c+sfawyzumwjsE=","X-Google-Smtp-Source":"AA6agR7P4Fzas4Gqq8cKMB8swQyW0DGru32OGlG/tRU0ooyoQjuIfc6peaKGrUL1edZ4Z1W9oWKb7g==","X-Received":"by 2002:a17:902:820d:b0:16e:c853:ddd1 with SMTP id\n\tx13-20020a170902820d00b0016ec853ddd1mr13097273pln.31.1660493287725; \n\tSun, 14 Aug 2022 09:08:07 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Sun, 14 Aug 2022 21:37:42 +0530","Message-Id":"<20220814160747.52093-1-kunalagarwal1072002@gmail.com>","X-Mailer":"git-send-email 2.25.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 1/6] pipeline: simple: shader: Shaders\n\tfor debayering","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>","From":"Kunal Agarwal via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Kunal Agarwal <kunalagarwal1072002@gmail.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Default and Bayer shaders which performs debayering on\nraw input data\n\nSigned-off-by: Kunal Agarwal <kunalagarwal1072002@gmail.com>\n---\n .../pipeline/simple/shader/bayer_8.frag       | 107 ++++++++++++++++++\n .../pipeline/simple/shader/bayer_8.vert       |  51 +++++++++\n .../pipeline/simple/shader/default.frag       |  16 +++\n .../pipeline/simple/shader/default.vert       |  23 ++++\n 4 files changed, 197 insertions(+)\n create mode 100644 src/libcamera/pipeline/simple/shader/bayer_8.frag\n create mode 100644 src/libcamera/pipeline/simple/shader/bayer_8.vert\n create mode 100644 src/libcamera/pipeline/simple/shader/default.frag\n create mode 100644 src/libcamera/pipeline/simple/shader/default.vert","diff":"diff --git a/src/libcamera/pipeline/simple/shader/bayer_8.frag b/src/libcamera/pipeline/simple/shader/bayer_8.frag\nnew file mode 100644\nindex 00000000..7e35ca88\n--- /dev/null\n+++ b/src/libcamera/pipeline/simple/shader/bayer_8.frag\n@@ -0,0 +1,107 @@\n+/* SPDX-License-Identifier: BSD-2-Clause */\n+/*\n+From http://jgt.akpeters.com/papers/McGuire08/\n+\n+Efficient, High-Quality Bayer Demosaic Filtering on GPUs\n+\n+Morgan McGuire\n+\n+This paper appears in issue Volume 13, Number 4.\n+---------------------------------------------------------\n+Copyright (c) 2008, Morgan McGuire. All rights reserved.\n+\n+Modified by Linaro Ltd to integrate it into libcamera.\n+Copyright (C) 2021, Linaro\n+*/\n+\n+//Pixel Shader\n+#ifdef GL_ES\n+precision mediump float;\n+#endif\n+\n+/** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/\n+uniform sampler2D       tex_y;\n+varying vec4            center;\n+varying vec4            yCoord;\n+varying vec4            xCoord;\n+\n+void main(void) {\n+    #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r\n+\n+    float C = texture2D(tex_y, center.xy).r; // ( 0, 0)\n+    const vec4 kC = vec4( 4.0,  6.0,  5.0,  5.0) / 8.0;\n+\n+    // Determine which of four types of pixels we are on.\n+    vec2 alternate = mod(floor(center.zw), 2.0);\n+\n+    vec4 Dvec = vec4(\n+        fetch(xCoord[1], yCoord[1]),  // (-1,-1)\n+        fetch(xCoord[1], yCoord[2]),  // (-1, 1)\n+        fetch(xCoord[2], yCoord[1]),  // ( 1,-1)\n+        fetch(xCoord[2], yCoord[2])); // ( 1, 1)\n+\n+    vec4 PATTERN = (kC.xyz * C).xyzz;\n+\n+    // Can also be a dot product with (1,1,1,1) on hardware where that is\n+    // specially optimized.\n+    // Equivalent to: D = Dvec[0] + Dvec[1] + Dvec[2] + Dvec[3];\n+    Dvec.xy += Dvec.zw;\n+    Dvec.x  += Dvec.y;\n+\n+    vec4 value = vec4(\n+        fetch(center.x, yCoord[0]),   // ( 0,-2)\n+        fetch(center.x, yCoord[1]),   // ( 0,-1)\n+        fetch(xCoord[0], center.y),   // (-2, 0)\n+        fetch(xCoord[1], center.y));  // (-1, 0)\n+\n+    vec4 temp = vec4(\n+        fetch(center.x, yCoord[3]),   // ( 0, 2)\n+        fetch(center.x, yCoord[2]),   // ( 0, 1)\n+        fetch(xCoord[3], center.y),   // ( 2, 0)\n+        fetch(xCoord[2], center.y));  // ( 1, 0)\n+\n+    // Even the simplest compilers should be able to constant-fold these to\n+    // avoid the division.\n+    // Note that on scalar processors these constants force computation of some\n+    // identical products twice.\n+    const vec4 kA = vec4(-1.0, -1.5,  0.5, -1.0) / 8.0;\n+    const vec4 kB = vec4( 2.0,  0.0,  0.0,  4.0) / 8.0;\n+    const vec4 kD = vec4( 0.0,  2.0, -1.0, -1.0) / 8.0;\n+\n+    // Conserve constant registers and take advantage of free swizzle on load\n+    #define kE (kA.xywz)\n+    #define kF (kB.xywz)\n+\n+    value += temp;\n+\n+    // There are five filter patterns (identity, cross, checker,\n+    // theta, phi).  Precompute the terms from all of them and then\n+    // use swizzles to assign to color channels.\n+    //\n+    // Channel   Matches\n+    //   x       cross   (e.g., EE G)\n+    //   y       checker (e.g., EE B)\n+    //   z       theta   (e.g., EO R)\n+    //   w       phi     (e.g., EO R)\n+    #define A (value[0])\n+    #define B (value[1])\n+    #define D (Dvec.x)\n+    #define E (value[2])\n+    #define F (value[3])\n+\n+    // Avoid zero elements. On a scalar processor this saves two MADDs\n+    // and it has no effect on a vector processor.\n+    PATTERN.yzw += (kD.yz * D).xyy;\n+\n+    PATTERN += (kA.xyz * A).xyzx + (kE.xyw * E).xyxz;\n+    PATTERN.xw  += kB.xw * B;\n+    PATTERN.xz  += kF.xz * F;\n+\n+    gl_FragColor.rgb = (alternate.y == 0.0) ?\n+        ((alternate.x == 0.0) ?\n+            vec3(C, PATTERN.xy) :\n+            vec3(PATTERN.z, C, PATTERN.w)) :\n+        ((alternate.x == 0.0) ?\n+            vec3(PATTERN.w, C, PATTERN.z) :\n+            vec3(PATTERN.yx, C));\n+}\ndiff --git a/src/libcamera/pipeline/simple/shader/bayer_8.vert b/src/libcamera/pipeline/simple/shader/bayer_8.vert\nnew file mode 100644\nindex 00000000..3695a5e9\n--- /dev/null\n+++ b/src/libcamera/pipeline/simple/shader/bayer_8.vert\n@@ -0,0 +1,51 @@\n+/* SPDX-License-Identifier: BSD-2-Clause */\n+/*\n+From http://jgt.akpeters.com/papers/McGuire08/\n+\n+Efficient, High-Quality Bayer Demosaic Filtering on GPUs\n+\n+Morgan McGuire\n+\n+This paper appears in issue Volume 13, Number 4.\n+---------------------------------------------------------\n+Copyright (c) 2008, Morgan McGuire. All rights reserved.\n+\n+Modified by Linaro Ltd to integrate it into libcamera.\n+Copyright (C) 2021, Linaro\n+*/\n+\n+//Vertex Shader\n+\n+attribute vec4 vertexIn;\n+attribute vec2 textureIn;\n+\n+uniform vec2 tex_size;\t/* The texture size in pixels */\n+uniform vec2 tex_step;\n+\n+/** Pixel position of the first red pixel in the */\n+/**  Bayer pattern.  [{0,1}, {0, 1}]*/\n+uniform vec2            tex_bayer_first_red;\n+\n+/** .xy = Pixel being sampled in the fragment shader on the range [0, 1]\n+    .zw = ...on the range [0, sourceSize], offset by firstRed */\n+varying vec4            center;\n+\n+/** center.x + (-2/w, -1/w, 1/w, 2/w); These are the x-positions */\n+/** of the adjacent pixels.*/\n+varying vec4            xCoord;\n+\n+/** center.y + (-2/h, -1/h, 1/h, 2/h); These are the y-positions */\n+/** of the adjacent pixels.*/\n+varying vec4            yCoord;\n+\n+void main(void) {\n+    center.xy = textureIn;\n+    center.zw = textureIn * tex_size + tex_bayer_first_red;\n+\n+    xCoord = center.x + vec4(-2.0 * tex_step.x,\n+                             -tex_step.x, tex_step.x, 2.0 * tex_step.x);\n+    yCoord = center.y + vec4(-2.0 * tex_step.y,\n+                              -tex_step.y, tex_step.y, 2.0 * tex_step.y);\n+\n+    gl_Position = vertexIn;\n+}\ndiff --git a/src/libcamera/pipeline/simple/shader/default.frag b/src/libcamera/pipeline/simple/shader/default.frag\nnew file mode 100644\nindex 00000000..5899f8fc\n--- /dev/null\n+++ b/src/libcamera/pipeline/simple/shader/default.frag\n@@ -0,0 +1,16 @@\n+#version 310 es\n+precision mediump float;\n+// Outputs colors in RGBA\n+out vec4 FragColor;\n+\n+//Inputs color from the Vertex Shader\n+in vec3 color;\n+// Inputs the texture coordinates from the Vertex Shader\n+in vec2 texCoord;\n+\n+uniform sampler2D tex0;\n+\n+void main()\n+{\n+   FragColor = texture(tex0,texCoord);\n+}\ndiff --git a/src/libcamera/pipeline/simple/shader/default.vert b/src/libcamera/pipeline/simple/shader/default.vert\nnew file mode 100644\nindex 00000000..1a24284b\n--- /dev/null\n+++ b/src/libcamera/pipeline/simple/shader/default.vert\n@@ -0,0 +1,23 @@\n+#version 310 es\n+precision mediump float;\n+//Positions/Coordinates\n+layout (location = 0) in vec3 aPos;\n+//Colors\n+layout (location = 1) in vec3 aColor;\n+// Texture Coordinates\n+layout (location = 2) in vec2 aTex;\n+\n+//Outputs the color for the Fragment Shader\n+out vec3 color;\n+// Outputs the texture coordinates to the fragment shader\n+out vec2 texCoord;\n+\n+\n+void main()\n+{\n+   gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n+   //Assigns the color from the vertex Data to \"color\"\n+   color = aColor;\n+   // Assigns the texture coordinates from the Vertex Data to \"texCoord\"\n+\ttexCoord = aTex;\n+}\n\\ No newline at end of file\n","prefixes":["libcamera-devel","v3","1/6"]}