Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1856483imj; Fri, 8 Feb 2019 08:26:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IZcojauj/U+ftWlVavA7d0+2Zs4gW39zFIK1ScZOmkBl+zNZNtJRWGxwwSmUMr6FpGU0NXS X-Received: by 2002:a17:902:b615:: with SMTP id b21mr17856018pls.338.1549643173115; Fri, 08 Feb 2019 08:26:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549643173; cv=none; d=google.com; s=arc-20160816; b=CeaYDZGSMP/iB06B2jd9mpHe0tK+ZpMVCEE+eDYBV2VbN7K4fAavH1iDXjvxX/yAjx e3hek6Y43d8xCKVT/EOSY8l5YDWSk56QcAowBT8LZ1OHKUSqOq2hbffdw5vyosJr/kbf QwcfR2JSg+vNBc+6rhLbzmcTNu2Dl2f25b79HBYrh+EWcMKgoUAwgX/1NlV0lyzzLjMD b7H/ED7J+YRw2ZpQKbbbs/b0qAMCVJOX4ReEeK1/kUF3m9CsxhO1cznwq8VeJaoTrD4N P75k/kuA8nxDYh2s8jqzyCAyAQbcEY3b66DLwRBR+G+kUxgToX+Bn+b6HiCH0RoLPgVJ eE/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=gRB9eVUyeN72O+6cZqkUBflHLrbFQcOWtsgfTHQ9lJ0=; b=ma9drATpJzLpQaky5Du2tqE9MPUGLSRwFq2sxKucTDTSbWvR10xMLzLIMyqBxSF/EH mysB+F7bbFFmXLv2hMfFps6pHl0S+pi7mJUXfEKu8xPIXWKFRsyQke8N92NJZav+b8Fh fYTuJNSPcA+QQ10cy1qPImcdcNj03yAAS3A1YEx0/rV62nLUBF3//J7kBsSGcSb3Ye1A uUTrEJ/UaUU70NXNjuZA5c6fne+9X5jlb1O2Z6q83T0H1/Jh9zIWNPVu3w7qBE1l5Gse bscCVyNqdx/pet+cumMP58RQt2M1gpmQYm7Z565yVAPTGpzLPbZy1c6T4GtQIGL2SMNJ b0Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gateworks-com.20150623.gappssmtp.com header.s=20150623 header.b=0+QEHfOw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n13si2787464pfh.66.2019.02.08.08.25.56; Fri, 08 Feb 2019 08:26:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gateworks-com.20150623.gappssmtp.com header.s=20150623 header.b=0+QEHfOw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727951AbfBHQYu (ORCPT + 99 others); Fri, 8 Feb 2019 11:24:50 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40821 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727203AbfBHQYr (ORCPT ); Fri, 8 Feb 2019 11:24:47 -0500 Received: by mail-wr1-f68.google.com with SMTP id q1so4195924wrp.7 for ; Fri, 08 Feb 2019 08:24:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gateworks-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gRB9eVUyeN72O+6cZqkUBflHLrbFQcOWtsgfTHQ9lJ0=; b=0+QEHfOw+quX515EYGZoTt2MgPppdtjvA3dOT+q0N53tg9h0qI/LeVn2teGDWGjPVv g54ijHe0yZbQ0SRrNeI4hqAWsCTlMd2AG2/eErPfe5HAYQ1FNCgkFJYSfdDekpdDYzEe OpIbTyhhIMd9Df3hHf84GIzZWAnGMFmdXXfRz13xdHHlMqsxX1z2gK0dJRNSajupgUzo ZBdjGt15N4BQqW5KJ75tj4Rk8fUqGA4ZiyO55pasyYbjKXJS/1UFrx2uRkw0PWGEX/yi +fFiEv15JCoz39LZ/BYCmpH2XH6if0hFoHt1Hc0tyN12G/jjJLVTmw8MXUW+Mzezdx9r lfFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gRB9eVUyeN72O+6cZqkUBflHLrbFQcOWtsgfTHQ9lJ0=; b=WYILTij4XtHdmZShqUyNUFzEnD2gV5OvshvtEDFBVgz98rm+l0jJW60tzXGxt4dlhT 5yrJx88tygR/x1WVN2zu2tdutoQYOtc61UIStz/hgPy8eXgUQl9wOqNqVR99Spo4mQOi xyu2/eBH9Mfalu2KsyBvd26lgGBUQs/uzb2AHcBbrRwTLoVCSLZmsPF2RlNIIqrUoPw8 px4KcHpokVAe4LE+FLRzpYs6gELdpdSDomHWXGmE4anAvrfGN5SH2hbTAyYRoe4MtiCs hbZJvbymmYI3oLQi17TBfeyPt4X1kqxkGEzrZZUzNg/nFbbahgjKuv/b0+VqCzkzQPec wdkg== X-Gm-Message-State: AHQUAuZVFpYoNKPRlIZwHCuXY2kq7fAZdNZyKrsaetsxelMAHqhjfGZH FSz2JVEpav+Sq2V+pFw6xLV5fM5wYX83aWjCXsq+kw== X-Received: by 2002:a5d:690d:: with SMTP id t13mr1113412wru.135.1549643085429; Fri, 08 Feb 2019 08:24:45 -0800 (PST) MIME-Version: 1.0 References: <20190203194744.11546-1-slongerbeam@gmail.com> <20190203194744.11546-3-slongerbeam@gmail.com> In-Reply-To: <20190203194744.11546-3-slongerbeam@gmail.com> From: Tim Harvey Date: Fri, 8 Feb 2019 08:24:34 -0800 Message-ID: Subject: Re: [PATCH 2/3] gpu: ipu-v3: ipu-ic: Add support for BT.709 encoding To: Steve Longerbeam Cc: linux-media , Philipp Zabel , Mauro Carvalho Chehab , Greg Kroah-Hartman , Bartlomiej Zolnierkiewicz , "open list:DRM DRIVERS FOR FREESCALE IMX" , open list , "open list:STAGING SUBSYSTEM" , "open list:FRAMEBUFFER LAYER" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 3, 2019 at 11:48 AM Steve Longerbeam wrote: > > 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 > --- > drivers/gpu/ipu-v3/ipu-ic.c | 67 ++++++++++++++++++--- > 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, 67 insertions(+), 10 deletions(-) > > diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c > index 35ae86ff0585..63362b4fff81 100644 > --- a/drivers/gpu/ipu-v3/ipu-ic.c > +++ b/drivers/gpu/ipu-v3/ipu-ic.c > @@ -199,6 +199,23 @@ static const struct ic_csc_params ic_csc_rgb2ycbcr_bt601 = { > .scale = 1, > }; > > +/* > + * 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, > +}; > + > /* transparent RGB->RGB matrix for graphics combining */ > static const struct ic_csc_params ic_csc_rgb2rgb = { > .coeff = { > @@ -226,12 +243,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]; > @@ -241,10 +277,24 @@ 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: > + dev_err(priv->ipu->dev, "Unsupported YCbCr encoding\n"); > + return -EINVAL; > + } > + Steve, This will fail for RGB to RGB with 'Unsupported YCbCr encoding. We need to account for the RGB->RGB case. How about something like: 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; + const struct ic_csc_params *params = NULL; u32 __iomem *base; const u16 (*c)[3]; const u16 *a; @@ -241,13 +276,18 @@ 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) - params = &ic_csc_ycbcr2rgb_bt601; - else if (inf == IPUV3_COLORSPACE_RGB && outf == IPUV3_COLORSPACE_YUV) - params = &ic_csc_rgb2ycbcr_bt601; + if (inf == IPUV3_COLORSPACE_YUV && outf == IPUV3_COLORSPACE_RGB) { + params = (encoding == V4L2_YCBCR_ENC_601) ? + &ic_csc_ycbcr2rgb_bt601 : &ic_csc_ycbcr2rgb_bt709; + } + else if (inf == IPUV3_COLORSPACE_RGB && outf == IPUV3_COLORSPACE_YUV) { + params = (encoding == V4L2_YCBCR_ENC_601) ? + &ic_csc_rgb2ycbcr_bt601 : &ic_csc_rgb2ycbcr_bt709; + } else if (inf == IPUV3_COLORSPACE_RGB && outf == IPUV3_COLORSPACE_RGB) params = &ic_csc_rgb2rgb; - else { + + if (!params) { dev_err(priv->ipu->dev, "Unsupported color space conversion\n"); return -EINVAL; } Tim