From patchwork Wed Feb 20 00:05:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10820925 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 83E141575 for ; Wed, 20 Feb 2019 00:06:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DA582D247 for ; Wed, 20 Feb 2019 00:06:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61F412D278; Wed, 20 Feb 2019 00:06:20 +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=-6.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_RP_RNBL 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 16ED82D247 for ; Wed, 20 Feb 2019 00:06:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729543AbfBTAFf (ORCPT ); Tue, 19 Feb 2019 19:05:35 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:40909 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726405AbfBTAFe (ORCPT ); Tue, 19 Feb 2019 19:05:34 -0500 Received: by mail-pf1-f194.google.com with SMTP id h1so10981373pfo.7; Tue, 19 Feb 2019 16:05:34 -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=Sbop/e2Y1jW2dASCMBf3SX8kr8ytrYOuWO0KO4p5Y/M=; b=awsYZ+lpu8xpjZ0QqBcaD51aVK7F7YRTRHD1hYTvjjTDaVoo9zNrlXBNTIMQBbk8TG blCPC9Aykfl9Rkcs3rLq3xrqS3NpHlEiSOlhaDnfu+arZjwjiHaWwRQfaLSAIZcO7hPA RFrdM5EKrIBDZHUBdhDWEI11uvzAEhe3RlC5AH7NM25cTELpjIY8Avidr8T3UhhJNKKD bjVvw0/8T0x+bw0ZAFgtEM6PDf1Dp0oBfXQ2SipzYaPrPTvqezmpcPI8zF4NbL8gFcRn YdUljtjEhXfb4pobQbST58+0v0nPD+fjY8uHGsRWeOrNEbwilwewYOABDV6pn99dtOIJ PSJA== 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=Sbop/e2Y1jW2dASCMBf3SX8kr8ytrYOuWO0KO4p5Y/M=; b=JY7D4+MvYqIwRB+XJ5N79qjrQlYnyVycbVSMLIUPZ3LCN0Ox58k1RjrL7erQKW12Er BTiu16txxuAmu6Eutx9DgWB3mpgfhufeleqOQ0FL612NVKRb0pcKcyJJPGrBjcS9G3zC T6IodASfnGrJGRvLWUO7vrPCvwPs8pC/1hrco8DXcYTKLlXL7xHMonQwoIDLB7qybVyN 4EnZkdxQElnOK5aJCS2VUKN+uqXGgWbNso22KXR6YC5FXYE+3bC60+oZvTR3btB+aBuq XRvBQUYK+GsEKU+fpapSjKmNM954cx8TF6gwI3qSBgnhqxfJWUcUXJa0Pnp8GdYOraqw Fv9g== X-Gm-Message-State: AHQUAub6g8F38eTK1l194nXc+/udJmjDRcTR0lWXaJZu74NZK8pBxxsF qTR/9H+4mu1/KoB81vJDXImTopm6 X-Google-Smtp-Source: AHgI3IYXY9TZTFL2nYPclx5+lCtf3/cSq9cseTN9WoRBl4PPyxTm+J5ETyea/r7mqOE616DWZHljDQ== X-Received: by 2002:a62:1706:: with SMTP id 6mr31503936pfx.28.1550621133399; Tue, 19 Feb 2019 16:05:33 -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 f14sm19159083pgv.23.2019.02.19.16.05.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 16:05:32 -0800 (PST) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Tim Harvey , Steve Longerbeam , stable@vger.kernel.org, Philipp Zabel , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS FOR FREESCALE IMX), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5 1/7] gpu: ipu-v3: ipu-ic: Fix saturation bit offset in TPMEM Date: Tue, 19 Feb 2019 16:05:15 -0800 Message-Id: <20190220000521.31130-2-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220000521.31130-1-slongerbeam@gmail.com> References: <20190220000521.31130-1-slongerbeam@gmail.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 The saturation bit was being set at bit 9 in the second 32-bit word of the TPMEM CSC. This isn't correct, the saturation bit is bit 42, which is bit 10 of the second word. Fixes: 1aa8ea0d2bd5d ("gpu: ipu-v3: Add Image Converter unit") Signed-off-by: Steve Longerbeam Cc: stable@vger.kernel.org --- drivers/gpu/ipu-v3/ipu-ic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c index 594c3cbc8291..18816ccf600e 100644 --- a/drivers/gpu/ipu-v3/ipu-ic.c +++ b/drivers/gpu/ipu-v3/ipu-ic.c @@ -257,7 +257,7 @@ static int init_csc(struct ipu_ic *ic, writel(param, base++); param = ((a[0] & 0x1fe0) >> 5) | (params->scale << 8) | - (params->sat << 9); + (params->sat << 10); writel(param, base++); param = ((a[1] & 0x1f) << 27) | ((c[0][1] & 0x1ff) << 18) | From patchwork Wed Feb 20 00:05:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10820923 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 815FA1575 for ; Wed, 20 Feb 2019 00:06:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AF532D247 for ; Wed, 20 Feb 2019 00:06:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F0FC2D278; Wed, 20 Feb 2019 00:06:17 +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=-6.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_RP_RNBL 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 CCB162D247 for ; Wed, 20 Feb 2019 00:06:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726405AbfBTAFg (ORCPT ); Tue, 19 Feb 2019 19:05:36 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41281 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729908AbfBTAFg (ORCPT ); Tue, 19 Feb 2019 19:05:36 -0500 Received: by mail-pf1-f194.google.com with SMTP id d25so2634849pfn.8; Tue, 19 Feb 2019 16:05:35 -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=PkbTgyhRaMGFHjnDfnhQ8iJ0W1fozZfXO5YRJxGME50=; b=Qj5l7UYCR0ZCmazb57JpBmCZ/vssQ8UQ/eRhR4usyJeofdvqnJHBDrhfwR5j/sLpnu 7RQEnidk1ixVToxNrs875Djk0nS4DO1v1ZTp9arKQ7Zl36skDpfpBRYQrdZgGakviZeW aMS4ErHV1ujmXpcMAJhiKYzOil/GahpHipZ0t+pliBe55vDIXRMxE5VfYKxvzuVE++06 mmws866GC+nRsPBBHvsuLvNJfvFVA9B3jpG94xh7b3L/0PpizFn2yQaIbRYrQ+IJY/f6 TE8x9CGicdqCaGYBFpuO9IQW/a4MxZHcnaZHMtWAC8c0HrPZaJQHjiR2ndWgdaBDoIpj uQhQ== 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=PkbTgyhRaMGFHjnDfnhQ8iJ0W1fozZfXO5YRJxGME50=; b=f5n0cDpybhHcW1Eb9gLqXoGeX+NLCHBJQQ2rpasvt1hvZAznbmosbs/U9ZdonG75yl BBzsUVb/R0k7GQGAkE/SuXBP5vZNsrLTN/NwG2tC33yckflTvtSW4PFLv4ZFVBO3PbQZ ZIBKLDttzY56OpawvfDGxZhmsvQjCgGw2CXHWdDmUB2U1/oUvScAjTbzvMepjqzeYsm1 HwcJeHbn+5SO0NORh7KmG+H2ViyaXeBHjeVj8nO8+oll+K9x7h7ng0P7vPgCfwhkpqy4 P2w4YGIjlyUuGh0n05axHXY4KKC6lwa8UdxWWM0o0yuyIEe1TBloRIM+GR+sYcdEjnsw ikxA== X-Gm-Message-State: AHQUAuYlGtDxWmiz3Zjym/9+MguLBsTEAS0v3Bx018iOT0dSYc5mrwUg X4RS+5KhEYJLlEMJmeeoDoYnqPkQ X-Google-Smtp-Source: AHgI3IZ5aGYXc12QPDpdRAxavdyQK85yst3keKlf38lBWnkaQFditnD/HqLuBAFwXgsEQaV96ZpWmw== X-Received: by 2002:a63:4d4f:: with SMTP id n15mr26481764pgl.327.1550621134828; Tue, 19 Feb 2019 16:05:34 -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 f14sm19159083pgv.23.2019.02.19.16.05.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 16:05:34 -0800 (PST) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Tim Harvey , Steve Longerbeam , stable@vger.kernel.org, Philipp Zabel , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS FOR FREESCALE IMX), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5 2/7] gpu: ipu-v3: ipu-ic: Fix BT.601 coefficients Date: Tue, 19 Feb 2019 16:05:16 -0800 Message-Id: <20190220000521.31130-3-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220000521.31130-1-slongerbeam@gmail.com> References: <20190220000521.31130-1-slongerbeam@gmail.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 The ycbcr2rgb and inverse rgb2ycbcr tables define the BT.601 Y'CbCr encoding coefficients. The rgb2ycbcr table specifically describes the BT.601 encoding from full range RGB to full range YUV. Add table comments to make this more clear. The ycbcr2rgb inverse table describes encoding YUV limited range to RGB full range. To be consistent with the rgb2ycbcr table, convert this to YUV full range to RGB full range, and adjust/expand on the comments. The ic_csc_rgb2rgb table is just an identity matrix, so rename to ic_encode_identity. Fixes: 1aa8ea0d2bd5d ("gpu: ipu-v3: Add Image Converter unit") Suggested-by: Philipp Zabel Signed-off-by: Steve Longerbeam Cc: stable@vger.kernel.org --- drivers/gpu/ipu-v3/ipu-ic.c | 63 ++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c index 18816ccf600e..71a0409093e6 100644 --- a/drivers/gpu/ipu-v3/ipu-ic.c +++ b/drivers/gpu/ipu-v3/ipu-ic.c @@ -175,7 +175,7 @@ static inline void ipu_ic_write(struct ipu_ic *ic, u32 value, unsigned offset) writel(value, ic->priv->base + offset); } -struct ic_csc_params { +struct ic_encode_coeff { s16 coeff[3][3]; /* signed 9-bit integer coefficients */ s16 offset[3]; /* signed 11+2-bit fixed point offset */ u8 scale:2; /* scale coefficients * 2^(scale-1) */ @@ -183,22 +183,27 @@ struct ic_csc_params { }; /* - * Y = R * .299 + G * .587 + B * .114; - * U = R * -.169 + G * -.332 + B * .500 + 128.; - * V = R * .500 + G * -.419 + B * -.0813 + 128.; + * BT.601 encoding from RGB full range to YUV full range: + * + * Y = .2990 * R + .5870 * G + .1140 * B + * U = -.1687 * R - .3313 * G + .5000 * B + 128 + * V = .5000 * R - .4187 * G - .0813 * B + 128 */ -static const struct ic_csc_params ic_csc_rgb2ycbcr = { +static const struct ic_encode_coeff ic_encode_rgb2ycbcr_601 = { .coeff = { - { 77, 150, 29 }, - { 469, 427, 128 }, + { 76, 150, 29 }, + { 469, 428, 128 }, { 128, 405, 491 }, }, .offset = { 0, 512, 512 }, .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_encode_coeff ic_encode_identity = { .coeff = { { 128, 0, 0 }, { 0, 128, 0 }, @@ -208,17 +213,25 @@ static const struct ic_csc_params ic_csc_rgb2rgb = { }; /* - * 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); + * Inverse BT.601 encoding from YUV full range to RGB full range: + * + * R = 1. * Y + 0 * (Cb - 128) + 1.4020 * (Cr - 128) + * G = 1. * Y - .3442 * (Cb - 128) - 0.7142 * (Cr - 128) + * B = 1. * Y + 1.7720 * (Cb - 128) + 0 * (Cr - 128) + * + * equivalently (factoring out the offsets): + * + * R = 1. * Y + 0 * Cb + 1.4020 * Cr - 179.456 + * G = 1. * Y - .3442 * Cb - 0.7142 * Cr + 135.475 + * B = 1. * Y + 1.7720 * Cb + 0 * Cr - 226.816 */ -static const struct ic_csc_params ic_csc_ycbcr2rgb = { +static const struct ic_encode_coeff ic_encode_ycbcr2rgb_601 = { .coeff = { - { 149, 0, 204 }, - { 149, 462, 408 }, - { 149, 255, 0 }, + { 128, 0, 179 }, + { 128, 468, 421 }, + { 128, 226, 0 }, }, - .offset = { -446, 266, -554 }, + .offset = { -359, 271, -454 }, .scale = 2, }; @@ -228,7 +241,7 @@ static int init_csc(struct ipu_ic *ic, int csc_index) { struct ipu_ic_priv *priv = ic->priv; - const struct ic_csc_params *params; + const struct ic_encode_coeff *coeff; u32 __iomem *base; const u16 (*c)[3]; const u16 *a; @@ -238,26 +251,26 @@ 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; + coeff = &ic_encode_ycbcr2rgb_601; else if (inf == IPUV3_COLORSPACE_RGB && outf == IPUV3_COLORSPACE_YUV) - params = &ic_csc_rgb2ycbcr; + coeff = &ic_encode_rgb2ycbcr_601; else if (inf == IPUV3_COLORSPACE_RGB && outf == IPUV3_COLORSPACE_RGB) - params = &ic_csc_rgb2rgb; + coeff = &ic_encode_identity; else { dev_err(priv->ipu->dev, "Unsupported color space conversion\n"); return -EINVAL; } /* Cast to unsigned */ - c = (const u16 (*)[3])params->coeff; - a = (const u16 *)params->offset; + c = (const u16 (*)[3])coeff->coeff; + a = (const u16 *)coeff->offset; param = ((a[0] & 0x1f) << 27) | ((c[0][0] & 0x1ff) << 18) | ((c[1][1] & 0x1ff) << 9) | (c[2][2] & 0x1ff); writel(param, base++); - param = ((a[0] & 0x1fe0) >> 5) | (params->scale << 8) | - (params->sat << 10); + param = ((a[0] & 0x1fe0) >> 5) | (coeff->scale << 8) | + (coeff->sat << 10); writel(param, base++); param = ((a[1] & 0x1f) << 27) | ((c[0][1] & 0x1ff) << 18) | From patchwork Wed Feb 20 00:05:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10820915 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 266016CB for ; Wed, 20 Feb 2019 00:06:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EAED2D247 for ; Wed, 20 Feb 2019 00:06:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02C9C2D278; Wed, 20 Feb 2019 00:06:03 +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=-6.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_RP_RNBL 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 D17482D247 for ; Wed, 20 Feb 2019 00:06:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730118AbfBTAFl (ORCPT ); Tue, 19 Feb 2019 19:05:41 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:37741 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730054AbfBTAFi (ORCPT ); Tue, 19 Feb 2019 19:05:38 -0500 Received: by mail-pf1-f193.google.com with SMTP id s22so10994898pfh.4; Tue, 19 Feb 2019 16:05:37 -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=4muVVZQyIcLgGrth7Qy2InTRh/fMnpCHYAHULwqqIF0=; b=Rk143/fOn2mb+lJZjswSI2td31aWq93Mrib149wphL10KCrXmMAGMF/0m/DOVh9Xjg 6wpVuK1HL5liZmiHphjRNRK1Xr6XKyZoYQjw0nL92S0GRTUgXYvpiM/PCscG3JDp/6q7 qxHq+qtoLUwY/fMKV5PvWCJXVOfOhVSGyh+d1wZ89Qg/7c7QYGSgxvOt+0E4Ggecst9N vzJ6RwtVjCpVtvV42Idgh6wrVkHtxJ+sY6vI0Tsk0l/GqTIDXks58vI6SLylZz+MAFNU hSdwL4kr2l0aYEXnTNsEfC7iQztQIln0MdnHCZJil6jdsH3CZkLwKEmbhfKRoGJg7Kez VMpA== 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=4muVVZQyIcLgGrth7Qy2InTRh/fMnpCHYAHULwqqIF0=; b=Y8rwY5sfk+yFYwq7xhl817v4d4SdLNJ79Xh+nXHHYtQ95SSxKCbHNm8ugfkxDFXfIW evjMLgzCk/mB9CSjMp2VDhYPz1xEQZi0QLQu8d9w8/GFuSRMwkDe/QcTaezvGJEup57/ LcRB53uvOddZRFohiC92Ek3wgUJf4iMH23hko23waAz1FyNs0I2THCBVut8rCO7A1sL0 ViMhW1OWM3YfvuQNPptJDoCSd4OkBOujlKTZ3CbWAUrwGc5QvUFJxkTbH12AUxW5Fo5t /x2IlMFlz3dfCEkiBLmW3wmJusyftOt4OlhkNNIE82gBn3I+dOaG9INuJbTHxplyeTKA sW0g== X-Gm-Message-State: AHQUAuZF93OxqX9o2OCaAOa5waUYe3YAF7JyIcpCPA9kcP6Py/ekdXh6 2EDYsNRCdsKsslojfsUnEUXDorb5 X-Google-Smtp-Source: AHgI3IaqfyYUPDxbKDhfj4oYK1OA8ioC2qCk5v8rz0tjFutME0QSIksFwE5GzpmwXSYflsc+V30epg== X-Received: by 2002:a63:5207:: with SMTP id g7mr26715348pgb.253.1550621136869; Tue, 19 Feb 2019 16:05: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 f14sm19159083pgv.23.2019.02.19.16.05.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 16:05:36 -0800 (PST) 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 v5 3/7] gpu: ipu-v3: ipu-ic: Fully describe colorspace conversions Date: Tue, 19 Feb 2019 16:05:17 -0800 Message-Id: <20190220000521.31130-4-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220000521.31130-1-slongerbeam@gmail.com> References: <20190220000521.31130-1-slongerbeam@gmail.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 Only providing the input and output RGB/YUV space to the IC task init functions is not sufficient. To fully characterize a colorspace conversion, the colorspace (chromaticities), Y'CbCr encoding standard, and quantization also need to be specified. Define a 'struct ipu_ic_colorspace' that includes all the above, and pass the input and output ipu_ic_colorspace to the IC task init functions. This allows to actually enforce the fact that the IC: - can only encode to/from YUV full range (follow-up patch will remove this restriction). - can only encode to/from RGB full range. - can only encode using BT.601 standard (follow-up patch will add Rec.709 encoding support). - cannot convert colorspaces from input to output, the input and output colorspace chromaticities must be the same. Signed-off-by: Steve Longerbeam --- drivers/gpu/ipu-v3/ipu-ic.c | 101 ++++++++++++-------- drivers/gpu/ipu-v3/ipu-image-convert.c | 27 ++++-- drivers/staging/media/imx/imx-ic-prpencvf.c | 22 +++-- include/video/imx-ipu-v3.h | 37 +++++-- 4 files changed, 127 insertions(+), 60 deletions(-) diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c index 71a0409093e6..02043f23f411 100644 --- a/drivers/gpu/ipu-v3/ipu-ic.c +++ b/drivers/gpu/ipu-v3/ipu-ic.c @@ -146,8 +146,10 @@ struct ipu_ic { const struct ic_task_regoffs *reg; const struct ic_task_bitfields *bit; - enum ipu_color_space in_cs, g_in_cs; - enum ipu_color_space out_cs; + struct ipu_ic_colorspace in_cs; + struct ipu_ic_colorspace g_in_cs; + struct ipu_ic_colorspace out_cs; + bool graphics; bool rotation; bool in_use; @@ -236,8 +238,8 @@ static const struct ic_encode_coeff ic_encode_ycbcr2rgb_601 = { }; static int init_csc(struct ipu_ic *ic, - enum ipu_color_space inf, - enum ipu_color_space outf, + const struct ipu_ic_colorspace *in, + const struct ipu_ic_colorspace *out, int csc_index) { struct ipu_ic_priv *priv = ic->priv; @@ -247,19 +249,41 @@ static int init_csc(struct ipu_ic *ic, const u16 *a; u32 param; + if (in->colorspace != out->colorspace) { + dev_err(priv->ipu->dev, "Cannot convert colorspaces\n"); + return -ENOTSUPP; + } + + if (out->enc != V4L2_YCBCR_ENC_601) { + dev_err(priv->ipu->dev, "Only BT.601 encoding supported\n"); + return -ENOTSUPP; + } + + if ((in->cs == IPUV3_COLORSPACE_YUV && + in->quant != V4L2_QUANTIZATION_FULL_RANGE) || + (out->cs == IPUV3_COLORSPACE_YUV && + out->quant != V4L2_QUANTIZATION_FULL_RANGE)) { + dev_err(priv->ipu->dev, "Limited range YUV not supported\n"); + return -ENOTSUPP; + } + + if ((in->cs == IPUV3_COLORSPACE_RGB && + in->quant != V4L2_QUANTIZATION_FULL_RANGE) || + (out->cs == IPUV3_COLORSPACE_RGB && + out->quant != V4L2_QUANTIZATION_FULL_RANGE)) { + dev_err(priv->ipu->dev, "Limited range RGB not supported\n"); + return -ENOTSUPP; + } + base = (u32 __iomem *) (priv->tpmem_base + ic->reg->tpmem_csc[csc_index]); - if (inf == IPUV3_COLORSPACE_YUV && outf == IPUV3_COLORSPACE_RGB) + if (in->cs == out->cs) + coeff = &ic_encode_identity; + else if (in->cs == IPUV3_COLORSPACE_YUV) coeff = &ic_encode_ycbcr2rgb_601; - else if (inf == IPUV3_COLORSPACE_RGB && outf == IPUV3_COLORSPACE_YUV) + else coeff = &ic_encode_rgb2ycbcr_601; - else if (inf == IPUV3_COLORSPACE_RGB && outf == IPUV3_COLORSPACE_RGB) - coeff = &ic_encode_identity; - else { - dev_err(priv->ipu->dev, "Unsupported color space conversion\n"); - return -EINVAL; - } /* Cast to unsigned */ c = (const u16 (*)[3])coeff->coeff; @@ -357,14 +381,14 @@ void ipu_ic_task_enable(struct ipu_ic *ic) if (ic->rotation) ic_conf |= ic->bit->ic_conf_rot_en; - if (ic->in_cs != ic->out_cs) + if (ic->in_cs.cs != ic->out_cs.cs) ic_conf |= ic->bit->ic_conf_csc1_en; if (ic->graphics) { ic_conf |= ic->bit->ic_conf_cmb_en; ic_conf |= ic->bit->ic_conf_csc1_en; - if (ic->g_in_cs != ic->out_cs) + if (ic->g_in_cs.cs != ic->out_cs.cs) ic_conf |= ic->bit->ic_conf_csc2_en; } @@ -399,7 +423,7 @@ void ipu_ic_task_disable(struct ipu_ic *ic) EXPORT_SYMBOL_GPL(ipu_ic_task_disable); int ipu_ic_task_graphics_init(struct ipu_ic *ic, - enum ipu_color_space in_g_cs, + const struct ipu_ic_colorspace *g_in_cs, bool galpha_en, u32 galpha, bool colorkey_en, u32 colorkey) { @@ -416,20 +440,25 @@ int ipu_ic_task_graphics_init(struct ipu_ic *ic, ic_conf = ipu_ic_read(ic, IC_CONF); if (!(ic_conf & ic->bit->ic_conf_csc1_en)) { + struct ipu_ic_colorspace rgb_cs; + + ipu_ic_fill_colorspace(&rgb_cs, + V4L2_COLORSPACE_SRGB, + V4L2_YCBCR_ENC_601, + V4L2_QUANTIZATION_FULL_RANGE, + IPUV3_COLORSPACE_RGB); + /* need transparent CSC1 conversion */ - ret = init_csc(ic, IPUV3_COLORSPACE_RGB, - IPUV3_COLORSPACE_RGB, 0); + ret = init_csc(ic, &rgb_cs, &rgb_cs, 0); if (ret) goto unlock; } - ic->g_in_cs = in_g_cs; + ic->g_in_cs = *g_in_cs; - if (ic->g_in_cs != ic->out_cs) { - ret = init_csc(ic, ic->g_in_cs, ic->out_cs, 1); - if (ret) - goto unlock; - } + ret = init_csc(ic, &ic->g_in_cs, &ic->out_cs, 1); + if (ret) + goto unlock; if (galpha_en) { ic_conf |= IC_CONF_IC_GLB_LOC_A; @@ -456,10 +485,10 @@ int ipu_ic_task_graphics_init(struct ipu_ic *ic, EXPORT_SYMBOL_GPL(ipu_ic_task_graphics_init); int ipu_ic_task_init_rsc(struct ipu_ic *ic, + const struct ipu_ic_colorspace *in_cs, + const struct ipu_ic_colorspace *out_cs, int in_width, int in_height, int out_width, int out_height, - enum ipu_color_space in_cs, - enum ipu_color_space out_cs, u32 rsc) { struct ipu_ic_priv *priv = ic->priv; @@ -491,28 +520,24 @@ int ipu_ic_task_init_rsc(struct ipu_ic *ic, ipu_ic_write(ic, rsc, ic->reg->rsc); /* Setup color space conversion */ - ic->in_cs = in_cs; - ic->out_cs = out_cs; + ic->in_cs = *in_cs; + ic->out_cs = *out_cs; - if (ic->in_cs != ic->out_cs) { - ret = init_csc(ic, ic->in_cs, ic->out_cs, 0); - if (ret) - goto unlock; - } + ret = init_csc(ic, &ic->in_cs, &ic->out_cs, 0); -unlock: spin_unlock_irqrestore(&priv->lock, flags); return ret; } int ipu_ic_task_init(struct ipu_ic *ic, + const struct ipu_ic_colorspace *in_cs, + const struct ipu_ic_colorspace *out_cs, int in_width, int in_height, - int out_width, int out_height, - enum ipu_color_space in_cs, - enum ipu_color_space out_cs) + int out_width, int out_height) { - return ipu_ic_task_init_rsc(ic, in_width, in_height, out_width, - out_height, in_cs, out_cs, 0); + return ipu_ic_task_init_rsc(ic, in_cs, out_cs, + in_width, in_height, + out_width, out_height, 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..ccbc8f4d95d7 100644 --- a/drivers/gpu/ipu-v3/ipu-image-convert.c +++ b/drivers/gpu/ipu-v3/ipu-image-convert.c @@ -1317,7 +1317,7 @@ static int convert_start(struct ipu_image_convert_run *run, unsigned int tile) struct ipu_image_convert_priv *priv = chan->priv; struct ipu_image_convert_image *s_image = &ctx->in; struct ipu_image_convert_image *d_image = &ctx->out; - enum ipu_color_space src_cs, dest_cs; + struct ipu_ic_colorspace src_cs, dest_cs; unsigned int dst_tile = ctx->out_tile_map[tile]; unsigned int dest_width, dest_height; unsigned int col, row; @@ -1327,8 +1327,16 @@ static int convert_start(struct ipu_image_convert_run *run, unsigned int tile) dev_dbg(priv->ipu->dev, "%s: task %u: starting ctx %p run %p tile %u -> %u\n", __func__, chan->ic_task, ctx, run, tile, dst_tile); - src_cs = ipu_pixelformat_to_colorspace(s_image->fmt->fourcc); - dest_cs = ipu_pixelformat_to_colorspace(d_image->fmt->fourcc); + ipu_ic_fill_colorspace(&src_cs, + s_image->base.pix.colorspace, + s_image->base.pix.ycbcr_enc, + s_image->base.pix.quantization, + ipu_pixelformat_to_colorspace(s_image->fmt->fourcc)); + ipu_ic_fill_colorspace(&dest_cs, + d_image->base.pix.colorspace, + d_image->base.pix.ycbcr_enc, + d_image->base.pix.quantization, + ipu_pixelformat_to_colorspace(d_image->fmt->fourcc)); if (ipu_rot_mode_is_irt(ctx->rot_mode)) { /* swap width/height for resizer */ @@ -1352,13 +1360,12 @@ static int convert_start(struct ipu_image_convert_run *run, unsigned int tile) s_image->tile[tile].height, dest_width, dest_height, rsc); /* setup the IC resizer and CSC */ - ret = ipu_ic_task_init_rsc(chan->ic, - s_image->tile[tile].width, - s_image->tile[tile].height, - dest_width, - dest_height, - src_cs, dest_cs, - rsc); + ret = ipu_ic_task_init_rsc(chan->ic, &src_cs, &dest_cs, + s_image->tile[tile].width, + s_image->tile[tile].height, + dest_width, + dest_height, + rsc); if (ret) { dev_err(priv->ipu->dev, "ipu_ic_task_init failed, %d\n", ret); return ret; diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c b/drivers/staging/media/imx/imx-ic-prpencvf.c index 5c8e6ad8c025..10f2c7684727 100644 --- a/drivers/staging/media/imx/imx-ic-prpencvf.c +++ b/drivers/staging/media/imx/imx-ic-prpencvf.c @@ -458,6 +458,7 @@ static int prp_setup_rotation(struct prp_priv *priv) struct imx_media_video_dev *vdev = priv->vdev; struct imx_ic_priv *ic_priv = priv->ic_priv; const struct imx_media_pixfmt *outcc, *incc; + struct ipu_ic_colorspace in_cs, out_cs; struct v4l2_mbus_framefmt *infmt; struct v4l2_pix_format *outfmt; dma_addr_t phys[2]; @@ -468,6 +469,11 @@ static int prp_setup_rotation(struct prp_priv *priv) incc = priv->cc[PRPENCVF_SINK_PAD]; outcc = vdev->cc; + ipu_ic_fill_colorspace(&in_cs, infmt->colorspace, infmt->ycbcr_enc, + infmt->quantization, incc->cs); + ipu_ic_fill_colorspace(&out_cs, outfmt->colorspace, outfmt->ycbcr_enc, + outfmt->quantization, outcc->cs); + ret = imx_media_alloc_dma_buf(priv->md, &priv->rot_buf[0], outfmt->sizeimage); if (ret) { @@ -481,10 +487,9 @@ static int prp_setup_rotation(struct prp_priv *priv) goto free_rot0; } - ret = ipu_ic_task_init(priv->ic, + ret = ipu_ic_task_init(priv->ic, &in_cs, &out_cs, infmt->width, infmt->height, - outfmt->height, outfmt->width, - incc->cs, outcc->cs); + outfmt->height, outfmt->width); if (ret) { v4l2_err(&ic_priv->sd, "ipu_ic_task_init failed, %d\n", ret); goto free_rot1; @@ -574,6 +579,7 @@ static int prp_setup_norotation(struct prp_priv *priv) struct imx_media_video_dev *vdev = priv->vdev; struct imx_ic_priv *ic_priv = priv->ic_priv; const struct imx_media_pixfmt *outcc, *incc; + struct ipu_ic_colorspace in_cs, out_cs; struct v4l2_mbus_framefmt *infmt; struct v4l2_pix_format *outfmt; dma_addr_t phys[2]; @@ -584,10 +590,14 @@ static int prp_setup_norotation(struct prp_priv *priv) incc = priv->cc[PRPENCVF_SINK_PAD]; outcc = vdev->cc; - ret = ipu_ic_task_init(priv->ic, + ipu_ic_fill_colorspace(&in_cs, infmt->colorspace, infmt->ycbcr_enc, + infmt->quantization, incc->cs); + ipu_ic_fill_colorspace(&out_cs, outfmt->colorspace, outfmt->ycbcr_enc, + outfmt->quantization, outcc->cs); + + ret = ipu_ic_task_init(priv->ic, &in_cs, &out_cs, infmt->width, infmt->height, - outfmt->width, outfmt->height, - incc->cs, outcc->cs); + outfmt->width, outfmt->height); 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..498f4ffc1819 100644 --- a/include/video/imx-ipu-v3.h +++ b/include/video/imx-ipu-v3.h @@ -386,20 +386,45 @@ enum ipu_ic_task { IC_NUM_TASKS, }; +/* + * The parameters that describe a colorspace according to the + * Image Converter: colorspace (chromaticities), Y'CbCr encoding, + * quantization, and "colorspace" (RGB or YUV). + */ +struct ipu_ic_colorspace { + enum v4l2_colorspace colorspace; + enum v4l2_ycbcr_encoding enc; + enum v4l2_quantization quant; + enum ipu_color_space cs; +}; + +static inline void +ipu_ic_fill_colorspace(struct ipu_ic_colorspace *ic_cs, + enum v4l2_colorspace colorspace, + enum v4l2_ycbcr_encoding enc, + enum v4l2_quantization quant, + enum ipu_color_space cs) +{ + ic_cs->colorspace = colorspace; + ic_cs->enc = enc; + ic_cs->quant = quant; + ic_cs->cs = cs; +} + struct ipu_ic; int ipu_ic_task_init(struct ipu_ic *ic, + const struct ipu_ic_colorspace *in_cs, + const struct ipu_ic_colorspace *out_cs, int in_width, int in_height, - int out_width, int out_height, - enum ipu_color_space in_cs, - enum ipu_color_space out_cs); + int out_width, int out_height); int ipu_ic_task_init_rsc(struct ipu_ic *ic, + const struct ipu_ic_colorspace *in_cs, + const struct ipu_ic_colorspace *out_cs, int in_width, int in_height, int out_width, int out_height, - enum ipu_color_space in_cs, - enum ipu_color_space out_cs, u32 rsc); int ipu_ic_task_graphics_init(struct ipu_ic *ic, - enum ipu_color_space in_g_cs, + const struct ipu_ic_colorspace *g_in_cs, bool galpha_en, u32 galpha, bool colorkey_en, u32 colorkey); void ipu_ic_task_enable(struct ipu_ic *ic); From patchwork Wed Feb 20 00:05:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10820919 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 6F3471575 for ; Wed, 20 Feb 2019 00:06:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AC712D247 for ; Wed, 20 Feb 2019 00:06:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F1C62D2E5; Wed, 20 Feb 2019 00:06:12 +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=-6.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_RP_RNBL 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 BBC882D247 for ; Wed, 20 Feb 2019 00:06:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730103AbfBTAFl (ORCPT ); Tue, 19 Feb 2019 19:05:41 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:38857 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730062AbfBTAFk (ORCPT ); Tue, 19 Feb 2019 19:05:40 -0500 Received: by mail-pl1-f194.google.com with SMTP id e5so11225915plb.5; Tue, 19 Feb 2019 16:05:39 -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=YMJ6Z/OI+JwxOvQ/XgxaTgw9XsPGx3EOUms81JPt9UA=; b=iveaGDogIOgbGfnhozf96pLKX2ZZKTeoy5C6+l/I3uCjGR+qkmQDoSXLK6F3+pSwPB 2Y8BOyJLVcEOb2QGUTc2jmE8mL9v99zuYNNo4j2PDT8rj1HSdJl8A+Rvkw+1wTOM4QY4 4R0t9ugIHa6fbMUcLUH/tg+JZ47woGure0PxUyld8ZM3UNsI3dKSvxzc0xy9oI9eqjIz mx83Iohq2hAY2dp6apj5QsuuuQnhPNTpFMW4dGvWYKKcT9e/J3D4rpDtqMmQpm2NQoy7 FF6CsZk0jVbKvTTA6Otk6H2c8b2nitrI61P98b7Cm3SIfJ+GANdgrM/TgY90fnv59xU+ w66w== 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=YMJ6Z/OI+JwxOvQ/XgxaTgw9XsPGx3EOUms81JPt9UA=; b=j9xlsdFI07V1QGI9KcPxHO7NQXVA31W3VsDkAsKkDN4hE/LPAJ85QmweI6OAjcr94t bV6fdN/xGPPssTmSRn2CFvg2Q2zCtPpNjuEXtqS2oFLcG0ZwM5pR7lx8FYNPx/6yFC+L xYM1Z+YbzsKKUFupXhdBIHKqj3Ec644S76pTJRYeT2hJmc27kBz8BDOGk/LIR+EX2Nv6 qmN1/bT8ZWLu4xYCsW4uWaTxYE2U9hFWQJOuDn4ub4rKSiAsmbEXSJm8BYRtq5mWG2qx yzys6kvfEZ9wGQgQmYlyHMoBoesErtYRyeLjU0G7vwDuDmdf0MTGbQgVf2v6THx9RNHc 9PWw== X-Gm-Message-State: AHQUAubs1NoTGiYItZG/UKuFkmnpW2hk/rcnkm5uhFLBuhDbeEVilyLm cQIv00Mczh5Ob35EJ0xrjIxx8BKt X-Google-Smtp-Source: AHgI3IYHzz//jCFUJhXPyHiKH5eiMCkyatxt0LFpOuFJ0DXLcfDJzeCvYQTMHeUtx262coMUB8Xo9g== X-Received: by 2002:a17:902:780a:: with SMTP id p10mr34399164pll.54.1550621138398; Tue, 19 Feb 2019 16:05:38 -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 f14sm19159083pgv.23.2019.02.19.16.05.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 16:05:37 -0800 (PST) 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 v5 4/7] gpu: ipu-v3: ipu-ic: Add support for Rec.709 encoding Date: Tue, 19 Feb 2019 16:05:18 -0800 Message-Id: <20190220000521.31130-5-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220000521.31130-1-slongerbeam@gmail.com> References: <20190220000521.31130-1-slongerbeam@gmail.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 Add support for Rec.709 encoding and inverse encoding. The determination of the CSC coefficients based on the input/output colorspace parameters are moved to a new function calc_csc_coeffs(). Reported-by: Tim Harvey Signed-off-by: Steve Longerbeam --- Changes in v5: - moved API changes to a previous patch. - moved CSC coeff calc to new function calc_csc_coeffs(). Changes in v4: - fix compile error. Chnges in v3: - none. 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 | 120 ++++++++++++++++++++++++++++-------- 1 file changed, 94 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c index 02043f23f411..012ea2239e97 100644 --- a/drivers/gpu/ipu-v3/ipu-ic.c +++ b/drivers/gpu/ipu-v3/ipu-ic.c @@ -214,6 +214,23 @@ static const struct ic_encode_coeff ic_encode_identity = { .scale = 2, }; +/* + * REC.709 encoding from RGB full range to YUV full range: + * + * Y = .2126 * R + .7152 * G + .0722 * B + * U = -.1146 * R - .3854 * G + .5000 * B + 128 + * V = .5000 * R - .4542 * G - .0458 * B + 128 + */ +static const struct ic_encode_coeff ic_encode_rgb2ycbcr_709 = { + .coeff = { + { 54, 183, 19 }, + { 483, 413, 128 }, + { 128, 396, 500 }, + }, + .offset = { 0, 512, 512 }, + .scale = 1, +}; + /* * Inverse BT.601 encoding from YUV full range to RGB full range: * @@ -237,28 +254,42 @@ static const struct ic_encode_coeff ic_encode_ycbcr2rgb_601 = { .scale = 2, }; -static int init_csc(struct ipu_ic *ic, - const struct ipu_ic_colorspace *in, - const struct ipu_ic_colorspace *out, - int csc_index) +/* + * Inverse REC.709 encoding from YUV full range to RGB full range: + * + * R = 1. * Y + 0 * (Cb - 128) + 1.5748 * (Cr - 128) + * G = 1. * Y - .1873 * (Cb - 128) - .4681 * (Cr - 128) + * B = 1. * Y + 1.8556 * (Cb - 128) + 0 * (Cr - 128) + * + * equivalently (factoring out the offsets): + * + * R = 1. * Y + 0 * Cb + 1.5748 * Cr - 201.574 + * G = 1. * Y - .1873 * Cb - .4681 * Cr + 83.891 + * B = 1. * Y + 1.8556 * Cb + 0 * Cr - 237.517 + */ +static const struct ic_encode_coeff ic_encode_ycbcr2rgb_709 = { + .coeff = { + { 128, 0, 202 }, + { 128, 488, 452 }, + { 128, 238, 0 }, + }, + .offset = { -403, 168, -475 }, + .scale = 2, +}; + +static int calc_csc_coeffs(struct ipu_ic_priv *priv, + struct ic_encode_coeff *coeff_out, + const struct ipu_ic_colorspace *in, + const struct ipu_ic_colorspace *out) { - struct ipu_ic_priv *priv = ic->priv; - const struct ic_encode_coeff *coeff; - u32 __iomem *base; - const u16 (*c)[3]; - const u16 *a; - u32 param; + const struct ic_encode_coeff *encode_coeff; + bool inverse_encode; if (in->colorspace != out->colorspace) { dev_err(priv->ipu->dev, "Cannot convert colorspaces\n"); return -ENOTSUPP; } - if (out->enc != V4L2_YCBCR_ENC_601) { - dev_err(priv->ipu->dev, "Only BT.601 encoding supported\n"); - return -ENOTSUPP; - } - if ((in->cs == IPUV3_COLORSPACE_YUV && in->quant != V4L2_QUANTIZATION_FULL_RANGE) || (out->cs == IPUV3_COLORSPACE_YUV && @@ -275,26 +306,63 @@ static int init_csc(struct ipu_ic *ic, return -ENOTSUPP; } + if (in->cs == out->cs) { + *coeff_out = ic_encode_identity; + + return 0; + } + + inverse_encode = (in->cs == IPUV3_COLORSPACE_YUV); + + switch (out->enc) { + case V4L2_YCBCR_ENC_601: + encode_coeff = inverse_encode ? + &ic_encode_ycbcr2rgb_601 : &ic_encode_rgb2ycbcr_601; + break; + case V4L2_YCBCR_ENC_709: + encode_coeff = inverse_encode ? + &ic_encode_ycbcr2rgb_709 : &ic_encode_rgb2ycbcr_709; + break; + default: + dev_err(priv->ipu->dev, "Unsupported YCbCr encoding\n"); + return -ENOTSUPP; + } + + *coeff_out = *encode_coeff; + + return 0; +} + +static int init_csc(struct ipu_ic *ic, + const struct ipu_ic_colorspace *in, + const struct ipu_ic_colorspace *out, + int csc_index) +{ + struct ipu_ic_priv *priv = ic->priv; + struct ic_encode_coeff coeff; + u32 __iomem *base; + const u16 (*c)[3]; + const u16 *a; + u32 param; + int ret; + + ret = calc_csc_coeffs(priv, &coeff, in, out); + if (ret) + return ret; + base = (u32 __iomem *) (priv->tpmem_base + ic->reg->tpmem_csc[csc_index]); - if (in->cs == out->cs) - coeff = &ic_encode_identity; - else if (in->cs == IPUV3_COLORSPACE_YUV) - coeff = &ic_encode_ycbcr2rgb_601; - else - coeff = &ic_encode_rgb2ycbcr_601; - /* Cast to unsigned */ - c = (const u16 (*)[3])coeff->coeff; - a = (const u16 *)coeff->offset; + c = (const u16 (*)[3])coeff.coeff; + a = (const u16 *)coeff.offset; param = ((a[0] & 0x1f) << 27) | ((c[0][0] & 0x1ff) << 18) | ((c[1][1] & 0x1ff) << 9) | (c[2][2] & 0x1ff); writel(param, base++); - param = ((a[0] & 0x1fe0) >> 5) | (coeff->scale << 8) | - (coeff->sat << 10); + param = ((a[0] & 0x1fe0) >> 5) | (coeff.scale << 8) | + (coeff.sat << 10); writel(param, base++); param = ((a[1] & 0x1f) << 27) | ((c[0][1] & 0x1ff) << 18) | From patchwork Wed Feb 20 00:05:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10820917 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 EEEA91575 for ; Wed, 20 Feb 2019 00:06:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D91822D247 for ; Wed, 20 Feb 2019 00:06:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD6162D278; Wed, 20 Feb 2019 00:06:09 +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=-6.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_RP_RNBL 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 05DB42D247 for ; Wed, 20 Feb 2019 00:06:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730240AbfBTAGC (ORCPT ); Tue, 19 Feb 2019 19:06:02 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:34306 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728164AbfBTAFm (ORCPT ); Tue, 19 Feb 2019 19:05:42 -0500 Received: by mail-pg1-f193.google.com with SMTP id i130so10917867pgd.1; Tue, 19 Feb 2019 16:05: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=sgbC6WisCelZOgDnEPuGaK5syAx8/FPS1ZXA5k/W8ZI=; b=eWWJ5Tflxd2ffqEEEWvkmdE5riY4AM25Y04L+MKO7P12m2xlz6PoxjM0Uyp2jb1rab BzAJcGEQ209X5ncYlMk3Rs57wPgtMwO57eND8A2Wr0oDUlf4cBeL0eGwtiEscMMfEOXF LO7XB5ii8Q0caAda80TFSuQ/t57VWYxi01NZtQODGNXB1ygVlAs3p71vQrPCxcyZ8i7K QyBDLMM/W9SIO5lsxYYzil+mBg76RTZtKDocCnEqNx3dKngwEbHXAMtR2Qd09WqcECbR FWvvcABaMqECl9YMEuZAvwBMuHdYrQNuNzAEOHq/wXK000rep/0TshbfpXX+x9RV3Phc 1p0A== 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=sgbC6WisCelZOgDnEPuGaK5syAx8/FPS1ZXA5k/W8ZI=; b=Oc26p0ctVLNDI4F917uiAmNuJDtZdCZf5FYki7ZnVzev6cC7qkpIHzSDgHvwCN9SHP LIQO6PZII8OK3fxHvRihQDKQqIVwoA+Mi6/CQYn4duOLUdJ8XUEng0ztI74r102YhRgy h1XJAuiwqrw/yYBaNeL+sqGRxL72kLxtOM8qQ5Kt7fQh9zp1huFYgCyDKhK01oLVJZSY gLyE6R9JZp5z65tkfUp0MB6laPJV1iUoQg83wfn3rtn9vuUZnvyeaH5OECOKuamS7yUV YBOrVbaPm2ujDvjGIr+P79R57eWNmvLaonb4ECFnb3tabVbirC9qauiQM0YWqpXZPWat w3Cg== X-Gm-Message-State: AHQUAuZxnMMePkbrWZ2iQFVL2ZarfUFKES/llFXpuBy2P91slL1ZIMLO WcE1tMx17W8eFsaBPn2MGg+55ZW5 X-Google-Smtp-Source: AHgI3IYo7bV0VdCQNeUaAsecxPhLhXYG+4KEPNHn+NZStWynoqAU/6lJh0vt3P1tvIkQmyx6uThv2w== X-Received: by 2002:a63:20e:: with SMTP id 14mr26380684pgc.161.1550621139822; Tue, 19 Feb 2019 16:05: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 f14sm19159083pgv.23.2019.02.19.16.05.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 16:05:39 -0800 (PST) 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 v5 5/7] gpu: ipu-v3: ipu-ic: Add support for limited range encoding Date: Tue, 19 Feb 2019 16:05:19 -0800 Message-Id: <20190220000521.31130-6-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220000521.31130-1-slongerbeam@gmail.com> References: <20190220000521.31130-1-slongerbeam@gmail.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 Add support for the following conversions: - YUV full-range to YUV limited-range - YUV limited-range to YUV full-range - YUV limited-range to RGB full-range - RGB full-range to YUV limited-range The last two conversions require operating on the YUV full-range encoding and inverse encoding coefficients, with the YUV-to-YUV limited<->full coefficients. The formula to convert is M_c = M_a * M_b O_c = M_a * O_b + O_a For calculating the RGB full-range to YUV limited-range coefficients: [M_a, O_a] = YUV full-range to YUV limited-range coefficients. [M_b, O_b] = RGB full-range to YUV full-range coefficients. For calculating the YUV limited-range to RGB full-range coefficients: [M_a, O_a] = YUV full-range to RGB full-range coefficients. [M_b, O_b] = YUV limited-range to YUV full-range coefficients. The calculation of [M_c, O_c] is carried out by the function transform_coeffs(). In the future if RGB limited range encoding is required, the same function can be used. And cascaded to create all combinations of encoding for YUV limited/full range <-> RGB limited/full range, passing the output coefficients from one call as the input for the next. For example, to create YUV full-range to RGB limited-range coefficients: [M_a, O_a] = RGB full-range to RGB limited-range coefficients. [M_b, O_b] = YUV full-range to RGB full-range coefficients. and that output sent as input to create YUV limited-range to RGB limited-range coefficients: [M_a, O_a] = YUV full-range to RGB limited-range coefficients. [M_b, O_b] = YUV limited-range to YUV full-range coefficients. Signed-off-by: Steve Longerbeam --- drivers/gpu/ipu-v3/ipu-ic.c | 281 +++++++++++++++++++++++++++++++++--- 1 file changed, 263 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c index 012ea2239e97..861f43556df4 100644 --- a/drivers/gpu/ipu-v3/ipu-ic.c +++ b/drivers/gpu/ipu-v3/ipu-ic.c @@ -178,10 +178,10 @@ static inline void ipu_ic_write(struct ipu_ic *ic, u32 value, unsigned offset) } struct ic_encode_coeff { - s16 coeff[3][3]; /* signed 9-bit integer coefficients */ - s16 offset[3]; /* signed 11+2-bit fixed point offset */ - u8 scale:2; /* scale coefficients * 2^(scale-1) */ - bool sat:1; /* saturate to (16, 235(Y) / 240(U, V)) */ + int coeff[3][3]; /* signed 9-bit integer coefficients */ + int offset[3]; /* signed 13-bit integer offset */ + int scale; /* scale coefficients * 2^(scale-1) */ + bool sat; /* saturate to (16, 235(Y) / 240(U, V)) */ }; /* @@ -277,6 +277,231 @@ static const struct ic_encode_coeff ic_encode_ycbcr2rgb_709 = { .scale = 2, }; +/* + * YUV full range to YUV limited range: + * + * Y_lim = 0.8588 * Y_full + 16 + * Cb_lim = 0.8784 * (Cb_full - 128) + 128 + * Cr_lim = 0.8784 * (Cr_full - 128) + 128 + */ +static const struct ic_encode_coeff ic_encode_ycbcr_full2lim = { + .coeff = { + { 219, 0, 0 }, + { 0, 224, 0 }, + { 0, 0, 224 }, + }, + .offset = { 64, 62, 62 }, + .scale = 1, +}; + +/* + * YUV limited range to YUV full range: + * + * Y_full = 1.1644 * (Y_lim - 16) + * Cb_full = 1.1384 * (Cb_lim - 128) + 128 + * Cr_full = 1.1384 * (Cr_lim - 128) + 128 + */ +static const struct ic_encode_coeff ic_encode_ycbcr_lim2full = { + .coeff = { + { 149, 0, 0 }, + { 0, 145, 0 }, + { 0, 0, 145 }, + }, + .offset = { -37, -35, -35 }, + .scale = 2, +}; + +/* + * RGB full range to RGB limited range: + * + * R_lim = 0.8588 * R_full + 16 + * G_lim = 0.8588 * G_full + 16 + * B_lim = 0.8588 * B_full + 16 + */ +static const struct ic_encode_coeff +ic_encode_rgb_full2lim __maybe_unused = { + .coeff = { + { 219, 0, 0 }, + { 0, 219, 0 }, + { 0, 0, 219 }, + }, + .offset = { 64, 64, 64 }, + .scale = 1, +}; + +/* + * RGB limited range to RGB full range: + * + * R_full = 1.1644 * (R_lim - 16) + * G_full = 1.1644 * (G_lim - 16) + * B_full = 1.1644 * (B_lim - 16) + */ +static const struct ic_encode_coeff +ic_encode_rgb_lim2full __maybe_unused = { + .coeff = { + { 149, 0, 0 }, + { 0, 149, 0 }, + { 0, 0, 149 }, + }, + .offset = { -37, -37, -37 }, + .scale = 2, +}; + +/* + * Convert a coefficient and scale value in TPMEM register format + * to a signed int times 256 (fix the radix point). The TPMEM register + * coefficient format is a signed 9-bit value (sign bit at bit 8, + * mantissa = coeff * 2 ^ (8 - scale - 1)). + */ +static int coeff_fix(int coeff, int scale) +{ + if (coeff >= 256) + coeff -= 512; + if (scale == 0) + return DIV_ROUND_CLOSEST(coeff, 2); + return coeff << (scale - 1); +} + +/* + * Convert a signed int coefficient times 256 to TPMEM register + * format, given a scale value = TPMEM scale - 1. + */ +static int coeff_normalize(int coeff, int scale) +{ + coeff = DIV_ROUND_CLOSEST(coeff, 1 << scale); + if (coeff < 0) + coeff += 512; + return coeff; +} + +/* + * Convert an offset and scale value in TPMEM register format to a + * signed int times 256 (fix the radix point). The TPMEM register + * offset format is a signed 13-bit value (sign bit at bit 12, + * mantissa = offset * 2 ^ (2 - (scale - 1)). + */ +static int offset_fix(int offset, int scale) +{ + return offset << (8 - (2 - (scale - 1))); +} + +/* + * Convert a signed int offset times 256 to TPMEM register + * format, given a scale value = TPMEM scale - 1. + */ +static int offset_normalize(int off, int scale) +{ + return DIV_ROUND_CLOSEST(off, 1 << (8 - (2 - scale))); +} + +/* + * Find the scale value that fits the given coefficient within + * the 8-bit TPMEM mantissa. + */ +static int get_coeff_scale(int coeff) +{ + int scale = 0; + + while (abs(coeff) >= 256 && scale <= 2) { + coeff = DIV_ROUND_CLOSEST(coeff, 2); + scale++; + } + + return scale; +} + +/* + * The above defined encoding coefficients all encode between + * full-range RGB and full-range YCbCr. + * + * This function calculates a matrix M_c and offset vector O_c, given + * input matrices M_a, M_b and offset vectors O_a, O_b, such that: + * + * M_c = M_a * M_b + * O_c = M_a * O_b + O_a + * + * This operation will transform the full-range coefficients to + * coefficients that encode to or from limited range YCbCr or RGB. + * + * For example, to transform ic_encode_rgb2ycbcr_601 to encode to + * limited-range YCbCr: + * + * [M_a, O_a] = ic_encode_ycbcr_full2lim + * [M_b, O_b] = ic_encode_rgb2ycbcr_601 + * + * To transform the inverse coefficients ic_encode_ycbcr2rgb_601 to + * encode from limited-range YCbCr: + * + * [M_a, O_a] = ic_encode_ycbcr2rgb_601 + * [M_b, O_b] = ic_encode_ycbcr_lim2full + * + * The function can also be used to create RGB limited range + * coefficients, and cascaded to create all combinations of + * encodings between YCbCr limited/full range <-> RGB limited/full + * range. + */ +static void transform_coeffs(struct ic_encode_coeff *out, + const struct ic_encode_coeff *a, + const struct ic_encode_coeff *b) +{ + int c_a, c_b, c_out; + int o_a, o_b, o_out; + int outscale = 0; + int i, j, k; + + for (i = 0; i < 3; i++) { + o_out = 0; + for (j = 0; j < 3; j++) { + int scale; + + /* M_c[i,j] = M_a[i,k] * M_b[k,j] */ + c_out = 0; + for (k = 0; k < 3; k++) { + c_a = coeff_fix(a->coeff[i][k], a->scale); + c_b = coeff_fix(b->coeff[k][j], b->scale); + c_out += c_a * c_b; + } + + c_out = DIV_ROUND_CLOSEST(c_out, 1 << 8); + out->coeff[i][j] = c_out; + + /* + * get scale for this coefficient and update + * final output scale. + */ + scale = get_coeff_scale(c_out); + outscale = max(outscale, scale); + + /* M_a[i,j] * O_b[j] */ + c_a = coeff_fix(a->coeff[i][j], a->scale); + o_b = offset_fix(b->offset[j], b->scale); + o_out += DIV_ROUND_CLOSEST(c_a * o_b, 1 << 8); + } + + /* O_c[i] = (M_a * O_b)[i] + O_a[i] */ + o_a = offset_fix(a->offset[i], a->scale); + o_out += o_a; + + out->offset[i] = o_out; + } + + /* + * normalize output coefficients and offsets to TPMEM + * register format. + */ + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + c_out = out->coeff[i][j]; + out->coeff[i][j] = coeff_normalize(c_out, outscale); + } + + o_out = out->offset[i]; + out->offset[i] = offset_normalize(o_out, outscale); + } + + out->scale = outscale + 1; +} + static int calc_csc_coeffs(struct ipu_ic_priv *priv, struct ic_encode_coeff *coeff_out, const struct ipu_ic_colorspace *in, @@ -290,14 +515,6 @@ static int calc_csc_coeffs(struct ipu_ic_priv *priv, return -ENOTSUPP; } - if ((in->cs == IPUV3_COLORSPACE_YUV && - in->quant != V4L2_QUANTIZATION_FULL_RANGE) || - (out->cs == IPUV3_COLORSPACE_YUV && - out->quant != V4L2_QUANTIZATION_FULL_RANGE)) { - dev_err(priv->ipu->dev, "Limited range YUV not supported\n"); - return -ENOTSUPP; - } - if ((in->cs == IPUV3_COLORSPACE_RGB && in->quant != V4L2_QUANTIZATION_FULL_RANGE) || (out->cs == IPUV3_COLORSPACE_RGB && @@ -307,7 +524,18 @@ static int calc_csc_coeffs(struct ipu_ic_priv *priv, } if (in->cs == out->cs) { - *coeff_out = ic_encode_identity; + if (in->quant == out->quant) { + *coeff_out = ic_encode_identity; + } else if (in->quant == V4L2_QUANTIZATION_FULL_RANGE) { + /* YUV full-range to YUV limited-range */ + *coeff_out = ic_encode_ycbcr_full2lim; + + /* set saturation bit for YUV limited-range output */ + coeff_out->sat = true; + } else { + /* YUV limited-range to YUV full-range */ + *coeff_out = ic_encode_ycbcr_lim2full; + } return 0; } @@ -328,7 +556,24 @@ static int calc_csc_coeffs(struct ipu_ic_priv *priv, return -ENOTSUPP; } - *coeff_out = *encode_coeff; + if (in->quant == out->quant) { + /* + * YUV full-range to RGB full-range, or + * RGB full-range to YUV full-range. + */ + *coeff_out = *encode_coeff; + } else if (inverse_encode) { + /* YUV limited-range to RGB full-range */ + transform_coeffs(coeff_out, encode_coeff, + &ic_encode_ycbcr_lim2full); + } else { + /* RGB full-range to YUV limited-range */ + transform_coeffs(coeff_out, &ic_encode_ycbcr_full2lim, + encode_coeff); + + /* set saturation bit for YUV limited-range output */ + coeff_out->sat = true; + } return 0; } @@ -340,9 +585,9 @@ static int init_csc(struct ipu_ic *ic, { struct ipu_ic_priv *priv = ic->priv; struct ic_encode_coeff coeff; + const unsigned int (*c)[3]; + const unsigned int *a; u32 __iomem *base; - const u16 (*c)[3]; - const u16 *a; u32 param; int ret; @@ -354,8 +599,8 @@ static int init_csc(struct ipu_ic *ic, (priv->tpmem_base + ic->reg->tpmem_csc[csc_index]); /* Cast to unsigned */ - c = (const u16 (*)[3])coeff.coeff; - a = (const u16 *)coeff.offset; + c = (const unsigned int (*)[3])coeff.coeff; + a = (const unsigned int *)coeff.offset; param = ((a[0] & 0x1f) << 27) | ((c[0][0] & 0x1ff) << 18) | ((c[1][1] & 0x1ff) << 9) | (c[2][2] & 0x1ff); From patchwork Wed Feb 20 00:05:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10820913 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 E52411575 for ; Wed, 20 Feb 2019 00:06:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCEAA2D247 for ; Wed, 20 Feb 2019 00:06:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCD152D278; Wed, 20 Feb 2019 00:06: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=-6.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_RP_RNBL 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 E12022D247 for ; Wed, 20 Feb 2019 00:06:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730202AbfBTAFz (ORCPT ); Tue, 19 Feb 2019 19:05:55 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:34118 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730129AbfBTAFm (ORCPT ); Tue, 19 Feb 2019 19:05:42 -0500 Received: by mail-pl1-f196.google.com with SMTP id d15so4081624plr.1; Tue, 19 Feb 2019 16:05:42 -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=MCRXi36yVo7k0lloMC2BZbkExKJ5Vx5y+atdUDoFkhY=; b=Ykiv9GsJnsnhTjlDGshLf+G45bzzUpth0L5sUukXrKZ3WEalKzh0nHjUihEEhx8DNl TW29qRu294ijE+xoJsR6OuvdOyBNHjVuhFSfyXj7Ok+edkRTaeMixAzUDvKRC1uBTmvx DUf3OO3SsmFRAL7mGVjog+GFuDrxDH+UJZzp5M7vtohuGR/5Udl2rJ8bF/hPbxvm1iRZ xUspHS32mFO2sSSKekW9nrczvyGNtN3KP9WrtRsa4EbigJUGuYplziZC1+0logaIvgKO rc1EADDQr3q13HWuE3tCLm6LQvVa1iny/ra/ncFJDtizmgcmZYUyE9ZaFhDuekLWUN3g 3YIg== 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=MCRXi36yVo7k0lloMC2BZbkExKJ5Vx5y+atdUDoFkhY=; b=oGfmSOyEK5QNuGPH/ROcmyA+ED9DQ8BUE6qba/8wgGpYk9tLNmXTZlrZrR3jghYXc/ +S4eI6oEvbo5aawTjjd32XbkpE3uTaIM9Opra2aUpTfOFo19RI8SV90Ewax+INgVZ+lt 6bXFcB5PqqI7sed7lQJzNbVKMf9Mep/39iSrn4FEkK7OZELXAc8Wq0wsyAwH5NDfoHHj jvSNjR25azarWt/q2l5M+YDyhfVLV49UlatVH4s/3sC9afp48sX6pKHwDn+YulV169ql uZ79QDIidu49911z+Ffs6lGKasUYyutbeGDLVJc1rlItSAxKFVRdcZu4VSi66wC4hwg1 K0lw== X-Gm-Message-State: AHQUAubYeQPKxqmTgrrNLI/kcTdaYyw+4RHcC+VAg7D4tQQiuqCYNvvI 1owZX/TM8oU2OOpfacNPaEOAQEtJ X-Google-Smtp-Source: AHgI3IY21KkUfpPobyxHsy4aHMJoxd4QcUoSQSHna70t4H+Zv+urHcJW0oDEPVFf+4xGNXS4TbyPlQ== X-Received: by 2002:a17:902:b60c:: with SMTP id b12mr11826669pls.261.1550621141554; Tue, 19 Feb 2019 16:05: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 f14sm19159083pgv.23.2019.02.19.16.05.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 16:05:40 -0800 (PST) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Tim Harvey , Steve Longerbeam , Philipp Zabel , Mauro Carvalho Chehab , Greg Kroah-Hartman , Rui Miguel Silva , devel@driverdev.osuosl.org (open list:STAGING SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5 6/7] media: imx: Try colorimetry at both sink and source pads Date: Tue, 19 Feb 2019 16:05:20 -0800 Message-Id: <20190220000521.31130-7-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220000521.31130-1-slongerbeam@gmail.com> References: <20190220000521.31130-1-slongerbeam@gmail.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 The colorimetry parameters need to be tested at both sink and source pads. Specifically, for prpencvf, the IC only supports RGB full-range quantization at input and output. Fix this by cleaning up imx_media_fill_default_mbus_fields(), renaming to imx_media_try_colorimetry(), and call it at both sink and source pad try_fmt's. The unrelated check for uninitialized field value is moved out to appropriate places in each subdev try_fmt. Signed-off-by: Steve Longerbeam --- drivers/staging/media/imx/imx-ic-prp.c | 6 +- drivers/staging/media/imx/imx-ic-prpencvf.c | 8 +-- drivers/staging/media/imx/imx-media-csi.c | 19 +++--- drivers/staging/media/imx/imx-media-utils.c | 68 +++++++++++---------- drivers/staging/media/imx/imx-media-vdic.c | 5 +- drivers/staging/media/imx/imx-media.h | 5 +- drivers/staging/media/imx/imx7-media-csi.c | 8 +-- 7 files changed, 62 insertions(+), 57 deletions(-) diff --git a/drivers/staging/media/imx/imx-ic-prp.c b/drivers/staging/media/imx/imx-ic-prp.c index 3d43cdcb4bb9..8010ee706164 100644 --- a/drivers/staging/media/imx/imx-ic-prp.c +++ b/drivers/staging/media/imx/imx-ic-prp.c @@ -197,8 +197,8 @@ static int prp_set_fmt(struct v4l2_subdev *sd, sdformat->format.code = cc->codes[0]; } - imx_media_fill_default_mbus_fields(&sdformat->format, infmt, - true); + if (sdformat->format.field == V4L2_FIELD_ANY) + sdformat->format.field = V4L2_FIELD_NONE; break; case PRP_SRC_PAD_PRPENC: case PRP_SRC_PAD_PRPVF: @@ -207,6 +207,8 @@ static int prp_set_fmt(struct v4l2_subdev *sd, break; } + imx_media_try_colorimetry(&sdformat->format, true); + fmt = __prp_get_fmt(priv, cfg, sdformat->pad, sdformat->which); *fmt = sdformat->format; out: diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c b/drivers/staging/media/imx/imx-ic-prpencvf.c index 10f2c7684727..b1886a4e362e 100644 --- a/drivers/staging/media/imx/imx-ic-prpencvf.c +++ b/drivers/staging/media/imx/imx-ic-prpencvf.c @@ -899,8 +899,6 @@ static void prp_try_fmt(struct prp_priv *priv, /* propagate colorimetry from sink */ sdformat->format.colorspace = infmt->colorspace; sdformat->format.xfer_func = infmt->xfer_func; - sdformat->format.quantization = infmt->quantization; - sdformat->format.ycbcr_enc = infmt->ycbcr_enc; } else { v4l_bound_align_image(&sdformat->format.width, MIN_W_SINK, MAX_W_SINK, W_ALIGN_SINK, @@ -908,9 +906,11 @@ static void prp_try_fmt(struct prp_priv *priv, MIN_H_SINK, MAX_H_SINK, H_ALIGN_SINK, S_ALIGN); - imx_media_fill_default_mbus_fields(&sdformat->format, infmt, - true); + if (sdformat->format.field == V4L2_FIELD_ANY) + sdformat->format.field = V4L2_FIELD_NONE; } + + imx_media_try_colorimetry(&sdformat->format, true); } static int prp_set_fmt(struct v4l2_subdev *sd, diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c index 3b7517348666..cc3e0086b08a 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -1369,9 +1369,15 @@ static void csi_try_field(struct csi_priv *priv, struct v4l2_mbus_framefmt *infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sdformat->which); - /* no restrictions on sink pad field type */ - if (sdformat->pad == CSI_SINK_PAD) + /* + * no restrictions on sink pad field type except must + * be initialized. + */ + if (sdformat->pad == CSI_SINK_PAD) { + if (sdformat->format.field == V4L2_FIELD_ANY) + sdformat->format.field = V4L2_FIELD_NONE; return; + } switch (infmt->field) { case V4L2_FIELD_SEQ_TB: @@ -1449,8 +1455,6 @@ static void csi_try_fmt(struct csi_priv *priv, /* propagate colorimetry from sink */ sdformat->format.colorspace = infmt->colorspace; sdformat->format.xfer_func = infmt->xfer_func; - sdformat->format.quantization = infmt->quantization; - sdformat->format.ycbcr_enc = infmt->ycbcr_enc; break; case CSI_SINK_PAD: @@ -1470,10 +1474,6 @@ static void csi_try_fmt(struct csi_priv *priv, csi_try_field(priv, cfg, sdformat); - imx_media_fill_default_mbus_fields( - &sdformat->format, infmt, - priv->active_output_pad == CSI_SRC_PAD_DIRECT); - /* Reset crop and compose rectangles */ crop->left = 0; crop->top = 0; @@ -1489,6 +1489,9 @@ static void csi_try_fmt(struct csi_priv *priv, break; } + + imx_media_try_colorimetry(&sdformat->format, + priv->active_output_pad == CSI_SRC_PAD_DIRECT); } static int csi_set_fmt(struct v4l2_subdev *sd, diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index 1c63a2765a81..aa7d4be77a7e 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -515,21 +515,19 @@ int imx_media_init_cfg(struct v4l2_subdev *sd, EXPORT_SYMBOL_GPL(imx_media_init_cfg); /* - * Check whether the field and colorimetry parameters in tryfmt are - * uninitialized, and if so fill them with the values from fmt, - * or if tryfmt->colorspace has been initialized, all the default - * colorimetry params can be derived from tryfmt->colorspace. + * Default the colorspace in tryfmt to SRGB if set to an unsupported + * colorspace or not initialized. Then set the remaining colorimetry + * parameters based on the colorspace if they are uninitialized. * * tryfmt->code must be set on entry. * * If this format is destined to be routed through the Image Converter, - * quantization and Y`CbCr encoding must be fixed. The IC expects and - * produces fixed quantization and Y`CbCr encoding at its input and output - * (full range for RGB, limited range for YUV, and V4L2_YCBCR_ENC_601). + * quantization and Y`CbCr encoding must be fixed. The IC supports only + * full-range quantization for RGB at its input and output, and only + * BT.601 Y`CbCr encoding. */ -void imx_media_fill_default_mbus_fields(struct v4l2_mbus_framefmt *tryfmt, - struct v4l2_mbus_framefmt *fmt, - bool ic_route) +void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt, + bool ic_route) { const struct imx_media_pixfmt *cc; bool is_rgb = false; @@ -537,28 +535,41 @@ void imx_media_fill_default_mbus_fields(struct v4l2_mbus_framefmt *tryfmt, cc = imx_media_find_mbus_format(tryfmt->code, CS_SEL_ANY, true); if (!cc) cc = imx_media_find_ipu_format(tryfmt->code, CS_SEL_ANY); - if (cc && cc->cs != IPUV3_COLORSPACE_YUV) + if (cc && cc->cs == IPUV3_COLORSPACE_RGB) is_rgb = true; - /* fill field if necessary */ - if (tryfmt->field == V4L2_FIELD_ANY) - tryfmt->field = fmt->field; + switch (tryfmt->colorspace) { + case V4L2_COLORSPACE_SMPTE170M: + case V4L2_COLORSPACE_REC709: + case V4L2_COLORSPACE_JPEG: + case V4L2_COLORSPACE_SRGB: + case V4L2_COLORSPACE_BT2020: + case V4L2_COLORSPACE_OPRGB: + case V4L2_COLORSPACE_DCI_P3: + case V4L2_COLORSPACE_RAW: + break; + default: + tryfmt->colorspace = V4L2_COLORSPACE_SRGB; + break; + } + + if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT) { + tryfmt->xfer_func = + V4L2_MAP_XFER_FUNC_DEFAULT(tryfmt->colorspace); + } + + if (ic_route) { + if (is_rgb || + tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT) + tryfmt->quantization = V4L2_QUANTIZATION_FULL_RANGE; - /* fill colorimetry if necessary */ - if (tryfmt->colorspace == V4L2_COLORSPACE_DEFAULT) { - tryfmt->colorspace = fmt->colorspace; - tryfmt->xfer_func = fmt->xfer_func; - tryfmt->ycbcr_enc = fmt->ycbcr_enc; - tryfmt->quantization = fmt->quantization; + tryfmt->ycbcr_enc = V4L2_YCBCR_ENC_601; } else { - if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT) { - tryfmt->xfer_func = - V4L2_MAP_XFER_FUNC_DEFAULT(tryfmt->colorspace); - } if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) { tryfmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(tryfmt->colorspace); } + if (tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT) { tryfmt->quantization = V4L2_MAP_QUANTIZATION_DEFAULT( @@ -566,15 +577,8 @@ 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); +EXPORT_SYMBOL_GPL(imx_media_try_colorimetry); int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, struct v4l2_rect *compose, diff --git a/drivers/staging/media/imx/imx-media-vdic.c b/drivers/staging/media/imx/imx-media-vdic.c index 2808662e2597..a285619afa0f 100644 --- a/drivers/staging/media/imx/imx-media-vdic.c +++ b/drivers/staging/media/imx/imx-media-vdic.c @@ -615,14 +615,13 @@ static void vdic_try_fmt(struct vdic_priv *priv, &sdformat->format.height, MIN_H, MAX_H_VDIC, H_ALIGN, S_ALIGN); - imx_media_fill_default_mbus_fields(&sdformat->format, infmt, - true); - /* input must be interlaced! Choose SEQ_TB if not */ if (!V4L2_FIELD_HAS_BOTH(sdformat->format.field)) sdformat->format.field = V4L2_FIELD_SEQ_TB; break; } + + imx_media_try_colorimetry(&sdformat->format, true); } static int vdic_set_fmt(struct v4l2_subdev *sd, diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index ae964c8d5be1..48c8996d394c 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -176,9 +176,8 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, const struct imx_media_pixfmt **cc); int imx_media_init_cfg(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg); -void imx_media_fill_default_mbus_fields(struct v4l2_mbus_framefmt *tryfmt, - struct v4l2_mbus_framefmt *fmt, - bool ic_route); +void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt, + bool ic_route); int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, struct v4l2_rect *compose, const struct v4l2_mbus_framefmt *mbus, diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c index 3fba7c27c0ec..6e626c10a5f1 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -1003,8 +1003,6 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, sdformat->format.colorspace = in_fmt->colorspace; sdformat->format.xfer_func = in_fmt->xfer_func; - sdformat->format.quantization = in_fmt->quantization; - sdformat->format.ycbcr_enc = in_fmt->ycbcr_enc; break; case IMX7_CSI_PAD_SINK: *cc = imx_media_find_mbus_format(sdformat->format.code, @@ -1015,14 +1013,14 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, false); sdformat->format.code = (*cc)->codes[0]; } - - imx_media_fill_default_mbus_fields(&sdformat->format, in_fmt, - false); break; default: return -EINVAL; break; } + + imx_media_try_colorimetry(&sdformat->format, false); + return 0; } From patchwork Wed Feb 20 00:05:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 10820911 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 2C8246CB for ; Wed, 20 Feb 2019 00:05:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16BC32D247 for ; Wed, 20 Feb 2019 00:05:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B0142D278; Wed, 20 Feb 2019 00:05:52 +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=-6.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_RP_RNBL 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 A9F4B2D247 for ; Wed, 20 Feb 2019 00:05:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730167AbfBTAFo (ORCPT ); Tue, 19 Feb 2019 19:05:44 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:40988 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730151AbfBTAFo (ORCPT ); Tue, 19 Feb 2019 19:05:44 -0500 Received: by mail-pl1-f193.google.com with SMTP id y5so5656148plk.8; Tue, 19 Feb 2019 16:05:43 -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=P8PzRIifprMXFLbQqXKcG+mi2gnEr+W/CIJ2rU/DvCo=; b=Upt2BiL1PvcfCiCG7UGwgUAwn+0/gHLWJHGAIlvsiSlaa2+jyGY1V2taOV+6y+h/eW eK1W12cwujjoz81KJhC/hFLSuoPD55DEdzywB4B6dJITl8n1OiXeatJ/r8b+b/4s550X TrAky23eYf1J7yDKHkTjg5GiOcoYFyBpFVpJXFrTjfx3nwsor6//GeoR8bXonp3YPqdP ennKrPlKVUkeqSVvk2i1NiKhP14rH63CiEu7tQHQb9WMbuNbthcZQav3yN7eAfIxqJHS /zYvfWenhmlA1gOhrLuleeKfPGjXyFY7uMjJVLa1Y9XoceulC5NiHZx643AUCFs3oPEW CyZA== 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=P8PzRIifprMXFLbQqXKcG+mi2gnEr+W/CIJ2rU/DvCo=; b=CnFEoHThYsllxyii3k0otyVuFnfdEq7kcglrksB9/W59CBUQ7EAoz6DNg+RaErC5+d N+JP0BY1K+0ZFOq/QnmWEoEOchXfqJrUvj4Oxzw0xrlXU6O8sJSgVPqMETh1CyzJGGX6 XDjOXpI6J9e5o3rN4+NKSv8mCmXBSRiM29qO9Y+TE8YBeSRz8CiyFdxAU1R1NCcrmSuJ nR7PiGR0RCQzc1VJ2R6y2nfJrLq8R0+Q6Qua4sVQBzJ6S/1RhKcXarAj7GraVuNZwu6l SBw6SBbZijSpaQJydoxjpn+nPmDNtt6z4bvMTcr3fvE2wCHw9T2eimpArWe6ck0mei7i kmKQ== X-Gm-Message-State: AHQUAubiXaQM/lsiQK8zJiVGaKPyz2swtg6v6zn2gnPCDcPBVQ03fYFK y0bewtKvdA4dtfe5+Lwo29U0dQ85 X-Google-Smtp-Source: AHgI3IblQ7cwR7BHCD+aTEO7Kh2+LS7B09WpvXzkx28JJcwkc11kxx1xAyvcK+tl8LAbGmLv58aX0g== X-Received: by 2002:a17:902:28e9:: with SMTP id f96mr33736202plb.169.1550621142980; Tue, 19 Feb 2019 16:05:42 -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 f14sm19159083pgv.23.2019.02.19.16.05.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 16:05:42 -0800 (PST) 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 v5 7/7] media: imx: Allow BT.709 encoding for IC routes Date: Tue, 19 Feb 2019 16:05:21 -0800 Message-Id: <20190220000521.31130-8-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220000521.31130-1-slongerbeam@gmail.com> References: <20190220000521.31130-1-slongerbeam@gmail.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 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 v5: - rebased this patch on top of repurposing the function to imx_media_try_colorimetry(). 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index aa7d4be77a7e..12967d6d7e1a 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -524,7 +524,7 @@ EXPORT_SYMBOL_GPL(imx_media_init_cfg); * If this format is destined to be routed through the Image Converter, * quantization and Y`CbCr encoding must be fixed. The IC supports only * full-range quantization for RGB at its input and output, and only - * BT.601 Y`CbCr encoding. + * BT.601 or Rec.709 Y`CbCr encoding. */ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt, bool ic_route) @@ -563,7 +563,9 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt, tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT) tryfmt->quantization = V4L2_QUANTIZATION_FULL_RANGE; - tryfmt->ycbcr_enc = V4L2_YCBCR_ENC_601; + if (tryfmt->ycbcr_enc != V4L2_YCBCR_ENC_601 && + tryfmt->ycbcr_enc != V4L2_YCBCR_ENC_709) + tryfmt->ycbcr_enc = V4L2_YCBCR_ENC_601; } else { if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) { tryfmt->ycbcr_enc =