From patchwork Fri Feb 8 19:19:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10803655 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D55C31575 for ; Fri, 8 Feb 2019 19:19:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C600C2E183 for ; Fri, 8 Feb 2019 19:19:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA4B42E2BB; Fri, 8 Feb 2019 19:19:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C7EE2E183 for ; Fri, 8 Feb 2019 19:19:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727422AbfBHTTh (ORCPT ); Fri, 8 Feb 2019 14:19:37 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36709 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727417AbfBHTTh (ORCPT ); Fri, 8 Feb 2019 14:19:37 -0500 Received: by mail-pf1-f194.google.com with SMTP id d22so2094969pfo.3; Fri, 08 Feb 2019 11:19:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9JhHL5/aksfCmH9dx827g1mYpbbDSTWhMDYItxweaDE=; b=fwH0P+KH+AnXBQX9gQKdRgiLAPihtgoDmiPzLKxYB0yoWh72BnAUhPSfwDV1SzdG0z Be7p2AYs3KpzTQLzNJagmOBOgUEEQqLmSx4Bhs59FdU3NHh8EDTOArfdPMx2KeZycl8C Qbd2R2ZT/zOPVl5on7uTn5k9l1NU/lLelyyW1DxMomyIj62uu/gpDwoVpbLyoNTlNtkD U9rRuLqRs4/5vACabF1lj9LiKS9UFPD8lOaqg+FJmORXMF0qy2gxcrytLjqR0RvRbaBQ AFFEykW60pR3rxpM8hw1fxVHWEan0lTu0X4CDFwh6tvwA3huSN+pOqDh8v5jALe5pqrx eOsA== 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; bh=9JhHL5/aksfCmH9dx827g1mYpbbDSTWhMDYItxweaDE=; b=oMjHKmjDYYfuVEAy3QKBUJs8TyJ8Bke2TkGnuyg0rp9XYpamSyGaAn0O6PGwhkWxLM DmdnpiJYneNc0KEIvwYgEgbPXfTTwnWnR6dFM8z6C9NsXkWzzbF/0l6/z3pot7C6gXNo TvBzpV6ka3lNVW9VXuT/NwXr6Qab3Jj3JLJbPdjjGsFW3d6A1ozsbNK2l7m2g7SrBYc5 dhkpL2kGflGZOaz/wvHCTtsbjP+2WCux9C/hLi4vQvmozJgz66Q6fpH2WXwjZXUhuelp j6Ds2itHKBl0SLeVSu9ANh45r3XYII6lKN5TEEDbhUQi/GcAD+Xn8+iJrLHyVMd+nlLG Masw== X-Gm-Message-State: AHQUAubyckr1SdQNRwWol/OqnvhhTca1A74/6mlbdSSNAqXnqmVIGhs6 lA5nlrYMzyMxEoYRWd3aVeeejOyc X-Google-Smtp-Source: AHgI3IYN71jIZ/yGMj6QsDbb2Eu4vTRwKJZHUjVca+DC6pD2I+PTR6O/zg3L3m2vTlQubpsHnru5xQ== X-Received: by 2002:a63:fc59:: with SMTP id r25mr6725871pgk.302.1549653576047; Fri, 08 Feb 2019 11:19:36 -0800 (PST) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id o5sm4761817pgm.68.2019.02.08.11.19.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Feb 2019 11:19:35 -0800 (PST) From: Steve Longerbeam X-Google-Original-From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Tim Harvey , Steve Longerbeam , Philipp Zabel , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS FOR FREESCALE IMX), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 1/4] gpu: ipu-v3: ipu-ic: Rename yuv2rgb encoding matrices Date: Fri, 8 Feb 2019 11:19:25 -0800 Message-Id: <20190208191928.13273-2-steve_longerbeam@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190208191928.13273-1-steve_longerbeam@mentor.com> References: <20190208191928.13273-1-steve_longerbeam@mentor.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Steve Longerbeam The ycbcr2rgb and inverse rgb2ycbcr matrices define the BT.601 encoding coefficients, so rename them to indicate that. And add some comments to make clear these are BT.601 coefficients encoding between YUV limited range and RGB full range. The ic_csc_rgb2rgb matrix is just an identity matrix, so rename to ic_csc_identity. No functional changes. Signed-off-by: Steve Longerbeam --- Changes in v2: - rename ic_csc_rgb2rgb matrix to ic_csc_identity. --- drivers/gpu/ipu-v3/ipu-ic.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c index 594c3cbc8291..3ef61f0b509b 100644 --- a/drivers/gpu/ipu-v3/ipu-ic.c +++ b/drivers/gpu/ipu-v3/ipu-ic.c @@ -183,11 +183,13 @@ struct ic_csc_params { }; /* + * BT.601 encoding from RGB full range to YUV limited range: + * * Y = R * .299 + G * .587 + B * .114; * U = R * -.169 + G * -.332 + B * .500 + 128.; * V = R * .500 + G * -.419 + B * -.0813 + 128.; */ -static const struct ic_csc_params ic_csc_rgb2ycbcr = { +static const struct ic_csc_params ic_csc_rgb2ycbcr_bt601 = { .coeff = { { 77, 150, 29 }, { 469, 427, 128 }, @@ -197,8 +199,11 @@ static const struct ic_csc_params ic_csc_rgb2ycbcr = { .scale = 1, }; -/* transparent RGB->RGB matrix for graphics combining */ -static const struct ic_csc_params ic_csc_rgb2rgb = { +/* + * identity matrix, used for transparent RGB->RGB graphics + * combining. + */ +static const struct ic_csc_params ic_csc_identity = { .coeff = { { 128, 0, 0 }, { 0, 128, 0 }, @@ -208,11 +213,13 @@ static const struct ic_csc_params ic_csc_rgb2rgb = { }; /* + * Inverse BT.601 encoding from YUV limited range to RGB full range: + * * R = (1.164 * (Y - 16)) + (1.596 * (Cr - 128)); * G = (1.164 * (Y - 16)) - (0.392 * (Cb - 128)) - (0.813 * (Cr - 128)); * B = (1.164 * (Y - 16)) + (2.017 * (Cb - 128); */ -static const struct ic_csc_params ic_csc_ycbcr2rgb = { +static const struct ic_csc_params ic_csc_ycbcr2rgb_bt601 = { .coeff = { { 149, 0, 204 }, { 149, 462, 408 }, @@ -238,11 +245,11 @@ static int init_csc(struct ipu_ic *ic, (priv->tpmem_base + ic->reg->tpmem_csc[csc_index]); if (inf == IPUV3_COLORSPACE_YUV && outf == IPUV3_COLORSPACE_RGB) - params = &ic_csc_ycbcr2rgb; + params = &ic_csc_ycbcr2rgb_bt601; else if (inf == IPUV3_COLORSPACE_RGB && outf == IPUV3_COLORSPACE_YUV) - params = &ic_csc_rgb2ycbcr; + params = &ic_csc_rgb2ycbcr_bt601; else if (inf == IPUV3_COLORSPACE_RGB && outf == IPUV3_COLORSPACE_RGB) - params = &ic_csc_rgb2rgb; + params = &ic_csc_identity; else { dev_err(priv->ipu->dev, "Unsupported color space conversion\n"); return -EINVAL; From patchwork Fri Feb 8 19:19:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10803663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90B811575 for ; Fri, 8 Feb 2019 19:20:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82D702E8E5 for ; Fri, 8 Feb 2019 19:20:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 768092E96B; Fri, 8 Feb 2019 19:20:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1789B2E8E5 for ; Fri, 8 Feb 2019 19:20:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727476AbfBHTTk (ORCPT ); Fri, 8 Feb 2019 14:19:40 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:45094 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727417AbfBHTTi (ORCPT ); Fri, 8 Feb 2019 14:19:38 -0500 Received: by mail-pf1-f194.google.com with SMTP id j3so2112741pfi.12; Fri, 08 Feb 2019 11:19:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FMVIZC+Ut3hCcGkIAGAKElPF0VEiGdyoGwVPSPpdJa0=; b=Ta7wPGWBkdp/5vb9tEtLtLCG/RIYUlN6J8+HuOmvv5sgi2j6AbY9+7QNBhaGi848vF o+818GtdTGn+h6sJqZooFlM9fkLAhP8iI9hUJvNMldMV5v+SiFgsCN2hTtWlXTPhrKkE CL1vYywI67LlqzgrzlScRDUL++kAvK51xfnG6waV2izi1N2Y+AeKUob/iYtFwxiPVBqU cVGSW9lOLA3zVKEve+qXKmO4oqyZOKlepoXArN0kO9LT48vJlRMtCEOKUJWNvQa2zKex UAdLa5JDlaE2S4qIF6RPmp3JX9ZG7EUDubkKh6eJpgTS9WdGp58TbkYODf85nl5mH7eS STsg== 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; bh=FMVIZC+Ut3hCcGkIAGAKElPF0VEiGdyoGwVPSPpdJa0=; b=H0LrIGcWxnZXuUYNOcnj/vff7L3Q0k3JbqR0ocLoDFJRZlHcAoX+Othm267+Z7RQSP gYPPLRiDLiwKdezTLRYtvjm7d40IVlH1Xe+3CiAUYluH62sffVcOOggV62zJLA7XonaK TCKEvEIjLkMiWS1a9o/N2k2uugWo3pYc6/fzVqvsk6+FS1LdTGhXKvR2QyfkMSFVCTnN /ENdG4o5anbAW09b2kXjfD80qxwdwxMCBvPqXm+t6e3Sbc4CODgrT+2GOa7FbKiyltvC RP+uGvI/e+RYJgiBqSUbR8B6zRQ/vUSVMjJEBYdJUeisiGR25KxXeHtkKZTZim5dXmOA 59kw== X-Gm-Message-State: AHQUAuaTODqrPlP/cH8UdePhR7qzCLWlZu8I49jv/PDlR9VzADTMf7q4 YDEJQCM5lfHk0gRcITJtyEW+wv9K X-Google-Smtp-Source: AHgI3IY2oMmOmQmLij9hkZFlL8X+I4haiIzq8sW0jlH2v71bkIMkH9oajNof8unrgs+p1VFtdGDABQ== X-Received: by 2002:a63:5e43:: with SMTP id s64mr21933216pgb.101.1549653577436; Fri, 08 Feb 2019 11:19:37 -0800 (PST) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id o5sm4761817pgm.68.2019.02.08.11.19.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Feb 2019 11:19:36 -0800 (PST) From: Steve Longerbeam X-Google-Original-From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Tim Harvey , Steve Longerbeam , Philipp Zabel , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS FOR FREESCALE IMX), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 2/4] gpu: ipu-v3: ipu-ic: Simplify selection of encoding matrix Date: Fri, 8 Feb 2019 11:19:26 -0800 Message-Id: <20190208191928.13273-3-steve_longerbeam@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190208191928.13273-1-steve_longerbeam@mentor.com> References: <20190208191928.13273-1-steve_longerbeam@mentor.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Simplify the selection of the Y'CbCr encoding matrices in init_csc(). A side-effect of this change is that init_csc() now allows YUV->YUV using the identity matrix, intead of returning error. Signed-off-by: Steve Longerbeam --- drivers/gpu/ipu-v3/ipu-ic.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c index 3ef61f0b509b..e459615a49a1 100644 --- a/drivers/gpu/ipu-v3/ipu-ic.c +++ b/drivers/gpu/ipu-v3/ipu-ic.c @@ -244,16 +244,12 @@ static int init_csc(struct ipu_ic *ic, base = (u32 __iomem *) (priv->tpmem_base + ic->reg->tpmem_csc[csc_index]); - if (inf == IPUV3_COLORSPACE_YUV && outf == IPUV3_COLORSPACE_RGB) + if (inf == outf) + params = &ic_csc_identity; + else if (inf == IPUV3_COLORSPACE_YUV) params = &ic_csc_ycbcr2rgb_bt601; - else if (inf == IPUV3_COLORSPACE_RGB && outf == IPUV3_COLORSPACE_YUV) + else params = &ic_csc_rgb2ycbcr_bt601; - else if (inf == IPUV3_COLORSPACE_RGB && outf == IPUV3_COLORSPACE_RGB) - params = &ic_csc_identity; - else { - dev_err(priv->ipu->dev, "Unsupported color space conversion\n"); - return -EINVAL; - } /* Cast to unsigned */ c = (const u16 (*)[3])params->coeff; From patchwork Fri Feb 8 19:19:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10803659 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D923613BF for ; Fri, 8 Feb 2019 19:20:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C89CA2E2BB for ; Fri, 8 Feb 2019 19:20:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B90682E2E9; Fri, 8 Feb 2019 19:20:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 977472E2BB for ; Fri, 8 Feb 2019 19:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727605AbfBHTT7 (ORCPT ); Fri, 8 Feb 2019 14:19:59 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:37098 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727480AbfBHTTl (ORCPT ); Fri, 8 Feb 2019 14:19:41 -0500 Received: by mail-pg1-f196.google.com with SMTP id c25so2001927pgb.4; Fri, 08 Feb 2019 11:19:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YabknfUBWKDakYKaYZSCxJoQF69XtL+rIW7dOLCWsyo=; b=GF2uiZ9gJWomLrhnQqchMQV8IyWxd3gcNrVEkdGoxJXrDHmHVGV2A+ylv7KfTBGIz1 PKFR8Od9SHTV4C3/2uZuiR6cip0Khk9N/h9HRsF9SwOihhXq6ew8HUArcgV7KB5zOcBt VhG5Pk3/TD25SGIM4KRE6DD09x2jDHea90ebNudVRARcUDGqb3RQmO0H4NN1cAM0oyL8 jVXOdy2+VWaiaUgbofRu98dQUlE7svyGKClVJHaw2tJjweKm0QbWC8QhASTPZ5J7WHKZ pWnjrclYPZHCoXsjjHSQsp1YdLCWkSfwKobG2pQ4/aolh/5IRVWRiQuSzpT5UgHbugLg MHwA== 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; bh=YabknfUBWKDakYKaYZSCxJoQF69XtL+rIW7dOLCWsyo=; b=AEEgDVtEpaZpbWsCKc/Nkzql83HfxOdu0HwThm0hfJO0uLPjhssTk4OrnfBmbCivKN mamvEK+I54U1TUb1rTgFZ4i+59dKaSicP9PhGv5fHdBiMcR1PWUgrtg3IqwUPbQO7egQ UTweAQ+ZvV7KQisOTExvqvS4223F+hInoodR7wAJYoTadbqqv+aomEUNPBAdruXLQXXl XSee+15tJOaHm3q/ZvMewClGfUb/YPhDHTdIWvzRlUp8rvXyj6O/FGfGCNLmi/7q95+0 ZIr6zBg0dTXCupyJbRh7VXbTdnygK6EDMLUC+xfM76+GISdF1Xy4xJgrjUIyxBkQK4Vi giCg== X-Gm-Message-State: AHQUAubQajblFJOw1SFPTldcQIosMeRQ8Cb4EfJV32Yv5C9WQqsnHST3 zABwOe4KGQvpXVG7QP4/DjwrW82w X-Google-Smtp-Source: AHgI3IbUiivXujc3T5H8n7Tjxcdk/fsBh8tSd0BZj6QnHduBmB1F3NH+IvCSpOOrFPvUG4TauQQ1TA== X-Received: by 2002:a63:2263:: with SMTP id t35mr12013056pgm.69.1549653579354; Fri, 08 Feb 2019 11:19:39 -0800 (PST) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id o5sm4761817pgm.68.2019.02.08.11.19.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Feb 2019 11:19:38 -0800 (PST) From: Steve Longerbeam X-Google-Original-From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Tim Harvey , Steve Longerbeam , Philipp Zabel , Mauro Carvalho Chehab , Greg Kroah-Hartman , Bartlomiej Zolnierkiewicz , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS FOR FREESCALE IMX), linux-kernel@vger.kernel.org (open list), devel@driverdev.osuosl.org (open list:STAGING SUBSYSTEM), linux-fbdev@vger.kernel.org (open list:FRAMEBUFFER LAYER) Subject: [PATCH v2 3/4] gpu: ipu-v3: ipu-ic: Add support for BT.709 encoding Date: Fri, 8 Feb 2019 11:19:27 -0800 Message-Id: <20190208191928.13273-4-steve_longerbeam@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190208191928.13273-1-steve_longerbeam@mentor.com> References: <20190208191928.13273-1-steve_longerbeam@mentor.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Steve Longerbeam Pass v4l2 encoding enum to the ipu_ic task init functions, and add support for the BT.709 encoding and inverse encoding matrices. Reported-by: Tim Harvey Signed-off-by: Steve Longerbeam --- Changes in v2: - only return "Unsupported YCbCr encoding" error if inf != outf, since if inf == outf, the identity matrix can be used. Reported by Tim Harvey. --- drivers/gpu/ipu-v3/ipu-ic.c | 71 +++++++++++++++++++-- drivers/gpu/ipu-v3/ipu-image-convert.c | 1 + drivers/staging/media/imx/imx-ic-prpencvf.c | 4 +- include/video/imx-ipu-v3.h | 5 +- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c index e459615a49a1..0d57ca7ba18e 100644 --- a/drivers/gpu/ipu-v3/ipu-ic.c +++ b/drivers/gpu/ipu-v3/ipu-ic.c @@ -212,6 +212,23 @@ static const struct ic_csc_params ic_csc_identity = { .scale = 2, }; +/* + * BT.709 encoding from RGB full range to YUV limited range: + * + * Y = R * .2126 + G * .7152 + B * .0722; + * U = R * -.1146 + G * -.3854 + B * .5000 + 128.; + * V = R * .5000 + G * -.4542 + B * -.0458 + 128.; + */ +static const struct ic_csc_params ic_csc_rgb2ycbcr_bt709 = { + .coeff = { + { 54, 183, 18 }, + { 483, 413, 128 }, + { 128, 396, 500 }, + }, + .offset = { 0, 512, 512 }, + .scale = 1, +}; + /* * Inverse BT.601 encoding from YUV limited range to RGB full range: * @@ -229,12 +246,31 @@ static const struct ic_csc_params ic_csc_ycbcr2rgb_bt601 = { .scale = 2, }; +/* + * Inverse BT.709 encoding from YUV limited range to RGB full range: + * + * R = (1. * (Y - 16)) + (1.5748 * (Cr - 128)); + * G = (1. * (Y - 16)) - (0.1873 * (Cb - 128)) - (0.4681 * (Cr - 128)); + * B = (1. * (Y - 16)) + (1.8556 * (Cb - 128); + */ +static const struct ic_csc_params ic_csc_ycbcr2rgb_bt709 = { + .coeff = { + { 128, 0, 202 }, + { 128, 488, 452 }, + { 128, 238, 0 }, + }, + .offset = { -435, 136, -507 }, + .scale = 2, +}; + static int init_csc(struct ipu_ic *ic, enum ipu_color_space inf, enum ipu_color_space outf, + enum v4l2_ycbcr_encoding encoding, int csc_index) { struct ipu_ic_priv *priv = ic->priv; + const struct ic_csc_params *params_rgb2yuv, *params_yuv2rgb; const struct ic_csc_params *params; u32 __iomem *base; const u16 (*c)[3]; @@ -244,12 +280,30 @@ static int init_csc(struct ipu_ic *ic, base = (u32 __iomem *) (priv->tpmem_base + ic->reg->tpmem_csc[csc_index]); + switch (encoding) { + case V4L2_YCBCR_ENC_601: + params_rgb2yuv = &ic_csc_rgb2ycbcr_bt601; + params_yuv2rgb = &ic_csc_ycbcr2rgb_bt601; + break; + case V4L2_YCBCR_ENC_709: + params_rgb2yuv = &ic_csc_rgb2ycbcr_bt709; + params_yuv2rgb = &ic_csc_ycbcr2rgb_bt709; + break; + default: + if (inf != outf) { + dev_err(priv->ipu->dev, + "Unsupported YCbCr encoding\n"); + return -EINVAL; + } + break; + } + if (inf == outf) params = &ic_csc_identity; else if (inf == IPUV3_COLORSPACE_YUV) - params = &ic_csc_ycbcr2rgb_bt601; + params = &ic_csc_ycbcr2rgb; else - params = &ic_csc_rgb2ycbcr_bt601; + params = &ic_csc_rgb2ycbcr; /* Cast to unsigned */ c = (const u16 (*)[3])params->coeff; @@ -390,6 +444,7 @@ EXPORT_SYMBOL_GPL(ipu_ic_task_disable); int ipu_ic_task_graphics_init(struct ipu_ic *ic, enum ipu_color_space in_g_cs, + enum v4l2_ycbcr_encoding encoding, bool galpha_en, u32 galpha, bool colorkey_en, u32 colorkey) { @@ -408,7 +463,7 @@ int ipu_ic_task_graphics_init(struct ipu_ic *ic, if (!(ic_conf & ic->bit->ic_conf_csc1_en)) { /* need transparent CSC1 conversion */ ret = init_csc(ic, IPUV3_COLORSPACE_RGB, - IPUV3_COLORSPACE_RGB, 0); + IPUV3_COLORSPACE_RGB, encoding, 0); if (ret) goto unlock; } @@ -416,7 +471,7 @@ int ipu_ic_task_graphics_init(struct ipu_ic *ic, ic->g_in_cs = in_g_cs; if (ic->g_in_cs != ic->out_cs) { - ret = init_csc(ic, ic->g_in_cs, ic->out_cs, 1); + ret = init_csc(ic, ic->g_in_cs, ic->out_cs, encoding, 1); if (ret) goto unlock; } @@ -450,6 +505,7 @@ int ipu_ic_task_init_rsc(struct ipu_ic *ic, int out_width, int out_height, enum ipu_color_space in_cs, enum ipu_color_space out_cs, + enum v4l2_ycbcr_encoding encoding, u32 rsc) { struct ipu_ic_priv *priv = ic->priv; @@ -485,7 +541,7 @@ int ipu_ic_task_init_rsc(struct ipu_ic *ic, ic->out_cs = out_cs; if (ic->in_cs != ic->out_cs) { - ret = init_csc(ic, ic->in_cs, ic->out_cs, 0); + ret = init_csc(ic, ic->in_cs, ic->out_cs, encoding, 0); if (ret) goto unlock; } @@ -499,10 +555,11 @@ int ipu_ic_task_init(struct ipu_ic *ic, int in_width, int in_height, int out_width, int out_height, enum ipu_color_space in_cs, - enum ipu_color_space out_cs) + enum ipu_color_space out_cs, + enum v4l2_ycbcr_encoding encoding) { return ipu_ic_task_init_rsc(ic, in_width, in_height, out_width, - out_height, in_cs, out_cs, 0); + out_height, in_cs, out_cs, encoding, 0); } EXPORT_SYMBOL_GPL(ipu_ic_task_init); diff --git a/drivers/gpu/ipu-v3/ipu-image-convert.c b/drivers/gpu/ipu-v3/ipu-image-convert.c index 13103ab86050..8b37daa99f58 100644 --- a/drivers/gpu/ipu-v3/ipu-image-convert.c +++ b/drivers/gpu/ipu-v3/ipu-image-convert.c @@ -1358,6 +1358,7 @@ static int convert_start(struct ipu_image_convert_run *run, unsigned int tile) dest_width, dest_height, src_cs, dest_cs, + d_image->base.pix.ycbcr_enc, rsc); if (ret) { dev_err(priv->ipu->dev, "ipu_ic_task_init failed, %d\n", ret); diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c b/drivers/staging/media/imx/imx-ic-prpencvf.c index 376b504e8a42..60ecf5809cc1 100644 --- a/drivers/staging/media/imx/imx-ic-prpencvf.c +++ b/drivers/staging/media/imx/imx-ic-prpencvf.c @@ -484,7 +484,7 @@ static int prp_setup_rotation(struct prp_priv *priv) ret = ipu_ic_task_init(priv->ic, infmt->width, infmt->height, outfmt->height, outfmt->width, - incc->cs, outcc->cs); + incc->cs, outcc->cs, outfmt->ycbcr_enc); if (ret) { v4l2_err(&ic_priv->sd, "ipu_ic_task_init failed, %d\n", ret); goto free_rot1; @@ -587,7 +587,7 @@ static int prp_setup_norotation(struct prp_priv *priv) ret = ipu_ic_task_init(priv->ic, infmt->width, infmt->height, outfmt->width, outfmt->height, - incc->cs, outcc->cs); + incc->cs, outcc->cs, outfmt->ycbcr_enc); if (ret) { v4l2_err(&ic_priv->sd, "ipu_ic_task_init failed, %d\n", ret); return ret; diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h index c887f4bee5f8..b19d1e23eece 100644 --- a/include/video/imx-ipu-v3.h +++ b/include/video/imx-ipu-v3.h @@ -391,15 +391,18 @@ int ipu_ic_task_init(struct ipu_ic *ic, int in_width, int in_height, int out_width, int out_height, enum ipu_color_space in_cs, - enum ipu_color_space out_cs); + enum ipu_color_space out_cs, + enum v4l2_ycbcr_encoding encoding); int ipu_ic_task_init_rsc(struct ipu_ic *ic, int in_width, int in_height, int out_width, int out_height, enum ipu_color_space in_cs, enum ipu_color_space out_cs, + enum v4l2_ycbcr_encoding encoding, u32 rsc); int ipu_ic_task_graphics_init(struct ipu_ic *ic, enum ipu_color_space in_g_cs, + enum v4l2_ycbcr_encoding encoding, bool galpha_en, u32 galpha, bool colorkey_en, u32 colorkey); void ipu_ic_task_enable(struct ipu_ic *ic); From patchwork Fri Feb 8 19:19:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10803657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B6B0186D for ; Fri, 8 Feb 2019 19:20:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B64A2E1B3 for ; Fri, 8 Feb 2019 19:20:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D2BF2E2E9; Fri, 8 Feb 2019 19:20:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D8442E1B3 for ; Fri, 8 Feb 2019 19:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727510AbfBHTTm (ORCPT ); Fri, 8 Feb 2019 14:19:42 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42864 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727505AbfBHTTm (ORCPT ); Fri, 8 Feb 2019 14:19:42 -0500 Received: by mail-pf1-f196.google.com with SMTP id n74so872743pfi.9; Fri, 08 Feb 2019 11:19:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=U26YXALvPL/5SPkHyPqlaMA16FEhlCL+u65z44XkYcY=; b=gDAv/yoeqYfokxMgIq2+HeBzDmiHcZrXsGLa/hxzkVA3NSkHASUn4mv+OOpyVMidE2 8Wn1E8KLqYoR0pOH1jrJmm1R0trIxLxEnTZnmKbd5aXS3STPUFCFH9NS+R73fs5vVsH/ TSo4uKh7RR7U74HoEmWfXqXK/Lu+9hidncWANhqp2h45giYJWYNfWqpoLU8Uy4WYg0Zs R6aLYravfJzHACIwQg1IfnUxr3kIkpEwbvP8aBTxC7mLjuGO8n6GuS0nITk6rzldYKjN 8BJFtr6rdzI24Rgzr6VWUHbIG/yTdBqibwQPS9y+FluXfvyRKvwCKB1J2rZgat4qEO7a EXLA== 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; bh=U26YXALvPL/5SPkHyPqlaMA16FEhlCL+u65z44XkYcY=; b=hk5uZC9JNP2nfvfzZ87W9p8UlrV6cxqwaAP9BCPTjNidOyalqUv8SWDBF7Q449yLPo 8mN7IYTo1sKXp04/TWqpiGroj3Cofc+IAiqxDr9ly77bKTYnh7qqBuaZuGqo7gQL4gQq IKAZ3Xse8EnGFPqaFiXPQxHsomL8T5UrXQ31J60dqI2aAvEs/iXCK32S5c7gwzsdmPCD MaCnq4fsv1m+DreaUFyGgAZcO9XXNux4w7QN3F+fgE3DOKnz6R1R4SBelPQCQ7DwVw0q NgxZ/u4ixtewHasNJpJLBm/NGJZmfmMPoiRqOqx/x3Y8hW/DL4vsBjVKfDyjgs46dzO/ EWSw== X-Gm-Message-State: AHQUAuZCDri9zv6rwDSK1WU+BaQWJCzD3Bz7I+IWTJjmCeJGR8Hvp+6W 6Q7GWYZsFUPLSVhso0Y7lUfH+ooh X-Google-Smtp-Source: AHgI3IYM4+lpa75pkDcWL010/7bijkNa7h5oEC1KCaUFtP6DM9mrWS+qtCbKMCXkTw5ox/j1hiQNOg== X-Received: by 2002:a63:b24a:: with SMTP id t10mr21152310pgo.223.1549653581218; Fri, 08 Feb 2019 11:19:41 -0800 (PST) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id o5sm4761817pgm.68.2019.02.08.11.19.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Feb 2019 11:19:40 -0800 (PST) From: Steve Longerbeam X-Google-Original-From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Tim Harvey , Steve Longerbeam , Philipp Zabel , Mauro Carvalho Chehab , Greg Kroah-Hartman , devel@driverdev.osuosl.org (open list:STAGING SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 4/4] media: imx: Allow BT.709 encoding for IC routes Date: Fri, 8 Feb 2019 11:19:28 -0800 Message-Id: <20190208191928.13273-5-steve_longerbeam@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190208191928.13273-1-steve_longerbeam@mentor.com> References: <20190208191928.13273-1-steve_longerbeam@mentor.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Steve Longerbeam The IC now supports BT.709 Y'CbCr encoding, in addition to existing BT.601 encoding, so allow both, for pipelines that route through the IC. Reported-by: Tim Harvey Signed-off-by: Steve Longerbeam --- Changes in v2: - move ic_route check above default colorimetry checks, and fill default colorimetry for ic_route, otherwise it's not possible to set BT.709 encoding for ic routes. --- drivers/staging/media/imx/imx-media-utils.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index 5f110d90a4ef..dde0e47550d7 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -544,6 +544,19 @@ void imx_media_fill_default_mbus_fields(struct v4l2_mbus_framefmt *tryfmt, if (tryfmt->field == V4L2_FIELD_ANY) tryfmt->field = fmt->field; + if (ic_route) { + if (tryfmt->colorspace == V4L2_COLORSPACE_DEFAULT) + tryfmt->colorspace = fmt->colorspace; + + tryfmt->quantization = is_rgb ? + V4L2_QUANTIZATION_FULL_RANGE : + V4L2_QUANTIZATION_LIM_RANGE; + + if (tryfmt->ycbcr_enc != V4L2_YCBCR_ENC_601 && + tryfmt->ycbcr_enc != V4L2_YCBCR_ENC_709) + tryfmt->ycbcr_enc = V4L2_YCBCR_ENC_601; + } + /* fill colorimetry if necessary */ if (tryfmt->colorspace == V4L2_COLORSPACE_DEFAULT) { tryfmt->colorspace = fmt->colorspace; @@ -566,13 +579,6 @@ void imx_media_fill_default_mbus_fields(struct v4l2_mbus_framefmt *tryfmt, tryfmt->ycbcr_enc); } } - - if (ic_route) { - tryfmt->quantization = is_rgb ? - V4L2_QUANTIZATION_FULL_RANGE : - V4L2_QUANTIZATION_LIM_RANGE; - tryfmt->ycbcr_enc = V4L2_YCBCR_ENC_601; - } } EXPORT_SYMBOL_GPL(imx_media_fill_default_mbus_fields);