From patchwork Tue Jun 22 13:46:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12693 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 0E88EC321B for ; Tue, 22 Jun 2021 13:47:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BE09A68935; Tue, 22 Jun 2021 15:47:29 +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="X3PO4JM2"; dkim-atps=neutral Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BD61060292 for ; Tue, 22 Jun 2021 15:47:28 +0200 (CEST) Received: by mail-lj1-x235.google.com with SMTP id c11so30228354ljd.6 for ; Tue, 22 Jun 2021 06:47:28 -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=BAvEJ84VEQWmiF5nH6jedi2+7DTSJ/Dd6CWNQQoblKM=; b=X3PO4JM2ieRIyhbE0kk68dp4O3+0MBEuGA71zGBS9Yo8n832lueq0FH5MtywGgEzXS QK9RQ4Vj+50vwziry/AOSSNTHHdCtG5/GOUWMTgX4EyyicjnCQfWXRPq/hxfFki4jL0F JEHDeRgsMiCQDPw5mc8pSZUPX+3T+XXRwUSE5EZRBlpb3IFjCc+b34SZMnu+7lL81Da1 I8HOYfxZAI7//Umdr4NrA9kfGZD6mKB06tJJf6oBPasVaZ9TGjeSl3X6qK+UOesEHVx4 RMFPeUDzTJyxs3Az8SkZZdsOkqiZi1YsVAv3w31Ao4QuTbgqS4fqHMV+5CIY/LPhD2zp 5KhA== 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=BAvEJ84VEQWmiF5nH6jedi2+7DTSJ/Dd6CWNQQoblKM=; b=QVh/UcpzfWGrB4cZ9WZOQ4eiXSYxmTYXvQa3dR87FErgXpcmZE75nBubbmDjmnnBfb OvQxLxoiUxv6SUXtFxhpk9YoEM159zBIgkNkU1mL07cqVp3fcyey1zrXZ0JJ1m6/ox88 RoP8gBG5NrJFWzbix2GKdpWHUql3OlSqo0UBPzH6lAWOS6FStcG8yfXvW7Jf7cynJXIA EwVUG+GmO3ZcjcEOmwdhpnM3mm2rX9q3NTchyS3CqE52gYoDc/SAU5gsVQnMNRs5RUAh NVVOMAPVrZSblUflFLlkx90ibHmqaleFkfoFaoyaBmQTcQrNFz71DemIw0chUshKMzh5 H3yg== X-Gm-Message-State: AOAM53034YZZy/nFM26ts2sXM3O++SwAXjiiT2RjvIIlj5Pp3yHxwH5H FjnuQZj/xPUt+IZlFMpv5EthQyPDezaA7Q== X-Google-Smtp-Source: ABdhPJxAbZw1aNb+1fAB4omI6YzAS/lzn+PwtJXjFM/ujDT5Si40ivI7P6WXqJTvkod8qhbHO3D28Q== X-Received: by 2002:a2e:a612:: with SMTP id v18mr3389208ljp.358.1624369648247; Tue, 22 Jun 2021 06:47:28 -0700 (PDT) Received: from localhost.localdomain ([85.249.44.185]) by smtp.googlemail.com with ESMTPSA id b19sm163125ljo.37.2021.06.22.06.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Jun 2021 06:47:27 -0700 (PDT) From: Andrey Konovalov To: libcamera-devel@lists.libcamera.org, laurent.pinchart@ideasonboard.com Date: Tue, 22 Jun 2021 16:46:52 +0300 Message-Id: <20210622134652.1279260-10-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] [RFC PATCH v5 9/9] qcam: viewfinder_gl: bayer_8.frag: compute the coordinates manually 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" Use the identity vertex shader, and compute the coordinates in the fragment shader without using the hardware interpolator. The texture coordinates passed to the fragment shader are ajusted to point to the nearest pixel in the image. This prevents artifacts when the image is scaled from the frame resolution to the window size. Signed-off-by: Andrey Konovalov --- src/qcam/assets/shader/bayer_8.frag | 38 ++++++++++++++++++++++++++--- src/qcam/viewfinder_gl.cpp | 4 --- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/qcam/assets/shader/bayer_8.frag b/src/qcam/assets/shader/bayer_8.frag index 4ece44ab..be23913b 100644 --- a/src/qcam/assets/shader/bayer_8.frag +++ b/src/qcam/assets/shader/bayer_8.frag @@ -10,21 +10,51 @@ 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. + +Modified by Linaro Ltd to integrate it into libcamera, and to +fix the artifacts due to pixel coordinates interpolation. Copyright (C) 2021, Linaro */ //Pixel Shader +varying vec2 textureOut; + +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 tex_bayer_first_red; + /** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/ uniform sampler2D tex_y; -varying vec4 center; -varying vec4 yCoord; -varying vec4 xCoord; void main(void) { #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r + /** .xy = Pixel being sampled in the fragment shader on the range [0, 1] + .zw = ...on the range [0, sourceSize], offset by firstRed */ + vec4 center; + + /** center.x + (-2/w, -1/w, 1/w, 2/w); These are the x-positions */ + /** of the adjacent pixels.*/ + vec4 xCoord; + + /** center.y + (-2/h, -1/h, 1/h, 2/h); These are the y-positions */ + /** of the adjacent pixels.*/ + vec4 yCoord; + + /* Align the center coordinates to the nearest pixel */ + center.zw = floor(textureOut * tex_size); + center.xy = center.zw * tex_step; + center.zw += tex_bayer_first_red; + + 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); + float C = texture2D(tex_y, center.xy).r; // ( 0, 0) const vec4 kC = vec4( 4.0, 6.0, 5.0, 5.0) / 8.0; diff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp index e7c8620c..a5b1bfbe 100644 --- a/src/qcam/viewfinder_gl.cpp +++ b/src/qcam/viewfinder_gl.cpp @@ -231,28 +231,24 @@ bool ViewFinderGL::selectFormat(const libcamera::PixelFormat &format) 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;