From patchwork Tue Jun 22 13:46:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12692 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 73FE5C321B for ; Tue, 22 Jun 2021 13:47:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 352FE68935; Tue, 22 Jun 2021 15:47:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="exkVNZ1t"; dkim-atps=neutral Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EF49668935 for ; Tue, 22 Jun 2021 15:47:23 +0200 (CEST) Received: by mail-lf1-x135.google.com with SMTP id i18so1611625lfl.8 for ; Tue, 22 Jun 2021 06:47:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qlnX/HoUrihRatFwUcg/TBzcFGRWcRTzmu9xMnsm4KA=; b=exkVNZ1tqSnjz7h82YSFROZ8c7KuuC/zW7aBREa01iYLRFz4ROvGRnu3M7MNuovlsy czRjEpdgebE8mHow5r7YOEFov1uLpH6B1SnY7qKgMaRT48hmslKQpf4OtwOsSxE24hTA WBTCjHCHx4TbmDZcj732NNTuidSX5T4LsZYSi7gfVD2enpPtwX1zuDNlvgibFZkLh/4c rBxPmEXhOnLBXDYFxqeLUJz3vLOFN+5++w5ID9q5h1Tu+U5BGWHZJEr6imQ9YlWGWeuU iT1qKKkKRQfhnH6rsLgNms9J+xN8kdhlZ8zl4gxv/wpPjWtDNAs1QKUPhYyp4gDELJpD IBMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qlnX/HoUrihRatFwUcg/TBzcFGRWcRTzmu9xMnsm4KA=; b=sR3vVs4/g0dZKVAV6Q+TAXBmL6reusCEZaKAJE0IxEnEcA8WtbEYn1Wdaa4+qdD3YX DlurJoE8rfjizS2djtTZNBQafbvUeBeYKsE4xzwbJJy41T/2lLMDmZkKpVpmkb1apGpy RFDh4t2YE7g8uBrHj7W96tl37H7tnqDIwTzDcVSwfIe+0CoG+ng8uZZlZm0tE2eIWBAL ZH2/JAQIEsSvVn0XqAK8i/SkqkZXJNgjhS7l+s2kzfvdhoGqxlbdqQeGP9b8X7MOPOOr lWMjpZIufPaIDHkKK/kGznKOqyvUIHx3Xpdxrd2D7b39jS1rhGgZolziNVHbKr9Wbk/2 eNIQ== X-Gm-Message-State: AOAM531Go0L0OrsyKcPETS4sYRQsv9TpxDRnnIaqy8SkoS48CAktY2Ga RHxxrXT9v2x8hlfDr1atrlBQ+7RHgQSNEw== X-Google-Smtp-Source: ABdhPJzqaROaj/7t5CZtK/OisI/L8lAiiypJO+kRym6ZZR5l6/P8fkT6hXS9iz8buzQSWfaPcD/CcA== X-Received: by 2002:ac2:5c0b:: with SMTP id r11mr3101850lfp.655.1624369643374; Tue, 22 Jun 2021 06:47:23 -0700 (PDT) Received: from localhost.localdomain ([85.249.44.185]) by smtp.googlemail.com with ESMTPSA id b19sm163125ljo.37.2021.06.22.06.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Jun 2021 06:47:22 -0700 (PDT) From: Andrey Konovalov To: libcamera-devel@lists.libcamera.org, laurent.pinchart@ideasonboard.com Date: Tue, 22 Jun 2021 16:46:51 +0300 Message-Id: <20210622134652.1279260-9-andrey.konovalov@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210622134652.1279260-1-andrey.konovalov@linaro.org> References: <20210622134652.1279260-1-andrey.konovalov@linaro.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 8/9] qcam: viewfinder_gl: Add support for RAW8 Bayer 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: , Cc: morgan@casual-effects.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This integrates the vertex and the fragment shaders by Morgan McGuire into qcam. Signed-off-by: Andrey Konovalov Reviewed-by: Paul Elder Reviewed-by: Laurent Pinchart --- src/qcam/assets/shader/bayer_8.frag | 9 ++++--- src/qcam/assets/shader/bayer_8.vert | 26 ++++++++++-------- src/qcam/assets/shader/shaders.qrc | 2 ++ src/qcam/viewfinder_gl.cpp | 41 +++++++++++++++++++++++++++-- 4 files changed, 62 insertions(+), 16 deletions(-) diff --git a/src/qcam/assets/shader/bayer_8.frag b/src/qcam/assets/shader/bayer_8.frag index a7d65e1d..4ece44ab 100644 --- a/src/qcam/assets/shader/bayer_8.frag +++ b/src/qcam/assets/shader/bayer_8.frag @@ -9,20 +9,23 @@ Morgan McGuire This paper appears in issue Volume 13, Number 4. --------------------------------------------------------- Copyright (c) 2008, Morgan McGuire. All rights reserved. + +Modified by Linaro Ltd to integrate it into libcamera. +Copyright (C) 2021, Linaro */ //Pixel Shader /** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/ -uniform sampler2D source; +uniform sampler2D tex_y; varying vec4 center; varying vec4 yCoord; varying vec4 xCoord; void main(void) { - #define fetch(x, y) texture2D(source, vec2(x, y)).r + #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r - float C = texture2D(source, center.xy).r; // ( 0, 0) + float C = texture2D(tex_y, center.xy).r; // ( 0, 0) const vec4 kC = vec4( 4.0, 6.0, 5.0, 5.0) / 8.0; // Determine which of four types of pixels we are on. diff --git a/src/qcam/assets/shader/bayer_8.vert b/src/qcam/assets/shader/bayer_8.vert index 347c15f7..3695a5e9 100644 --- a/src/qcam/assets/shader/bayer_8.vert +++ b/src/qcam/assets/shader/bayer_8.vert @@ -9,17 +9,22 @@ Morgan McGuire This paper appears in issue Volume 13, Number 4. --------------------------------------------------------- Copyright (c) 2008, Morgan McGuire. All rights reserved. + +Modified by Linaro Ltd to integrate it into libcamera. +Copyright (C) 2021, Linaro */ //Vertex Shader +attribute vec4 vertexIn; +attribute vec2 textureIn; -/** (w,h,1/w,1/h) */ -uniform vec4 sourceSize; +uniform vec2 tex_size; /* The texture size in pixels */ +uniform vec2 tex_step; /** Pixel position of the first red pixel in the */ /** Bayer pattern. [{0,1}, {0, 1}]*/ -uniform vec2 firstRed; +uniform vec2 tex_bayer_first_red; /** .xy = Pixel being sampled in the fragment shader on the range [0, 1] .zw = ...on the range [0, sourceSize], offset by firstRed */ @@ -34,14 +39,13 @@ varying vec4 xCoord; varying vec4 yCoord; void main(void) { - center.xy = gl_MultiTexCoord0.xy; - center.zw = gl_MultiTexCoord0.xy * sourceSize.xy + firstRed; + center.xy = textureIn; + center.zw = textureIn * tex_size + tex_bayer_first_red; - vec2 invSize = sourceSize.zw; - xCoord = center.x + vec4(-2.0 * invSize.x, - -invSize.x, invSize.x, 2.0 * invSize.x); - yCoord = center.y + vec4(-2.0 * invSize.y, - -invSize.y, invSize.y, 2.0 * invSize.y); + xCoord = center.x + vec4(-2.0 * tex_step.x, + -tex_step.x, tex_step.x, 2.0 * tex_step.x); + yCoord = center.y + vec4(-2.0 * tex_step.y, + -tex_step.y, tex_step.y, 2.0 * tex_step.y); - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + gl_Position = vertexIn; } diff --git a/src/qcam/assets/shader/shaders.qrc b/src/qcam/assets/shader/shaders.qrc index d76d65c5..96c709f9 100644 --- a/src/qcam/assets/shader/shaders.qrc +++ b/src/qcam/assets/shader/shaders.qrc @@ -6,6 +6,8 @@ YUV_3_planes.frag YUV_packed.frag bayer_1x_packed.frag + bayer_8.frag + bayer_8.vert identity.vert diff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp index 6d1d80bd..e7c8620c 100644 --- a/src/qcam/viewfinder_gl.cpp +++ b/src/qcam/viewfinder_gl.cpp @@ -36,6 +36,11 @@ static const QList supportedFormats{ libcamera::formats::RGBA8888, libcamera::formats::BGR888, libcamera::formats::RGB888, + /* Raw Bayer 8-bit */ + libcamera::formats::SBGGR8, + libcamera::formats::SGBRG8, + libcamera::formats::SGRBG8, + libcamera::formats::SRGGB8, /* Raw Bayer 10-bit packed */ libcamera::formats::SBGGR10_CSI2P, libcamera::formats::SGBRG10_CSI2P, @@ -223,6 +228,34 @@ bool ViewFinderGL::selectFormat(const libcamera::PixelFormat &format) fragmentShaderDefines_.append("#define RGB_PATTERN bgr"); fragmentShaderFile_ = ":RGB.frag"; break; + case libcamera::formats::SBGGR8: + firstRed_.setX(1.0); + firstRed_.setY(1.0); + vertexShaderFile_ = ":bayer_8.vert"; + fragmentShaderFile_ = ":bayer_8.frag"; + textureMinMagFilters_ = GL_NEAREST; + break; + case libcamera::formats::SGBRG8: + firstRed_.setX(0.0); + firstRed_.setY(1.0); + vertexShaderFile_ = ":bayer_8.vert"; + fragmentShaderFile_ = ":bayer_8.frag"; + textureMinMagFilters_ = GL_NEAREST; + break; + case libcamera::formats::SGRBG8: + firstRed_.setX(1.0); + firstRed_.setY(0.0); + vertexShaderFile_ = ":bayer_8.vert"; + fragmentShaderFile_ = ":bayer_8.frag"; + textureMinMagFilters_ = GL_NEAREST; + break; + case libcamera::formats::SRGGB8: + firstRed_.setX(0.0); + firstRed_.setY(0.0); + vertexShaderFile_ = ":bayer_8.vert"; + fragmentShaderFile_ = ":bayer_8.frag"; + textureMinMagFilters_ = GL_NEAREST; + break; case libcamera::formats::SBGGR10_CSI2P: firstRed_.setX(1.0); firstRed_.setY(1.0); @@ -627,6 +660,10 @@ void ViewFinderGL::doRender() shaderProgram_.setUniformValue(textureUniformY_, 0); break; + case libcamera::formats::SBGGR8: + case libcamera::formats::SGBRG8: + case libcamera::formats::SGRBG8: + case libcamera::formats::SRGGB8: case libcamera::formats::SBGGR10_CSI2P: case libcamera::formats::SGBRG10_CSI2P: case libcamera::formats::SGRBG10_CSI2P: @@ -636,8 +673,8 @@ void ViewFinderGL::doRender() case libcamera::formats::SGRBG12_CSI2P: case libcamera::formats::SRGGB12_CSI2P: /* - * Packed raw Bayer 10-bit and 12-bit formats are stored in - * GL_RED texture. + * Raw Bayer 8-bit, and packed raw Bayer 10-bit/12-bit formats + * are stored in GL_RED texture. * The texture width is equal to the stride. */ glActiveTexture(GL_TEXTURE0);