Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2051005imj; Fri, 8 Feb 2019 11:42:15 -0800 (PST) X-Google-Smtp-Source: AHgI3IblPNgmqHxQ87HXmU8irK6BX1nbaaibtIR2iI9pfASOMF62adlrIOQPIjlyF/XMujoC5k09 X-Received: by 2002:a17:902:6502:: with SMTP id b2mr24071845plk.44.1549654935117; Fri, 08 Feb 2019 11:42:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549654935; cv=none; d=google.com; s=arc-20160816; b=tsXGs2O437vvM7TumRFbhR4kzgPOcRuk//tuBGcNFUeZHPf1gRb8Cy6CpXEqTIcrET 2B4APDRaoInqTmmuewuvYzhzmRobVUh2f0kVgq/mwQzA3UVqpL2B7ospFGD6urncdlsg WNUogQknA+E3ogGhrV5WulKZaEy+KiFDC0WJQJlKB5YQG+Po2pdu60sM5kFrizMfHdTn RuyrA7s9vgxFfi1KOp2JNAn5IOcrbfaNyityDoX5TR0nUQy28jGFDitGR7KQq9wy6/0q O8zJbHSV0rSv0jZIR75L1T2te3uXbHiYSrIh9+GXfpHtj9zUFSWLzNpdkNlIuKlvOBUP 8e5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=J0HyZi80ABUFbqHV8+o+6rZvaWNkoNVSHUnqIA+2qVE=; b=bhTxTtiaLFcOh9AMrlPiDTB+IzdaC/7eAqJ19qU1sxwOzWSC8ScNDOpExyoCb454nn rHxrIMStPjQg4KN3H/q3SSPemgm9RY/DLWKuD8rHLSv3YZnWE0JgW3dJKIQ3IkKM7vqh Z6JvL3pAxGswZRIfjqh26mcVVtFUsRca9wBg8RzlRNkxYec8JFh6i1HmwDRSJhyrsE4e jLtvydt2d9q2xcwbC5kKP3Etc/AcAZZRMbv+w0L99NOaJ8ADQBsyRjYlmGjdZ8dk8oeR XAO3yZS7WV3QY0Ddz2hs2JuQwY5lbV/1YjfZNKX5dOJ+4LhPhukdS9ImcZOhhgOo5Wbe 41Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=khhcTPNV; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h22si2882067pgv.198.2019.02.08.11.41.40; Fri, 08 Feb 2019 11:42:15 -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=@gmail.com header.s=20161025 header.b=khhcTPNV; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727251AbfBHTPH (ORCPT + 99 others); Fri, 8 Feb 2019 14:15:07 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55256 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726858AbfBHTPH (ORCPT ); Fri, 8 Feb 2019 14:15:07 -0500 Received: by mail-wm1-f65.google.com with SMTP id a62so4971896wmh.4; Fri, 08 Feb 2019 11:15:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=J0HyZi80ABUFbqHV8+o+6rZvaWNkoNVSHUnqIA+2qVE=; b=khhcTPNVJpdVQ70c4d/NcnwRUZqhH8nzRoLDzmDEUmwbSJ5Nu71Zyy99HzyCAy5Vbv pfHUxCnXjw1EIR2eN4J5F0d+6izdZ7jb6dHiJH7P/OyRZGW3twCqAxGF+S3V1v3dWlbv aLtu1sgv+yHBiudE0SFwcg4WcQcoEmpRLzUiD989ybS7ZxwgwIPOFdt5JfbDbeFUpa96 rpemUF3eFXEKNx5EMUjftjgbOAfhPzpeHZQeUAcn9kkxtk/AN8oadLxBI1SJ6UnKSFix dLBZbK1Kh2XgQMx2vGitwPq/1Bd1PFAKcj9nPgbqooNBaSKeHnpfvi72XA13PKUFzxHv oJGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=J0HyZi80ABUFbqHV8+o+6rZvaWNkoNVSHUnqIA+2qVE=; b=Qx2vElG5npXYX32Uzpxj9PSa4QfDKG/jCElg91wNDx4e9rIAnrqfq7KQBwWgGzkK7k UAybhBCeYsJokOq1978rMC/8b1Y+4jiMZW18AUrA+cl4Hz7LYLZwf1RKDo7mZFwuIoUc /C0FG7JpYD+ZOyfDozSaHRUQ/9fQKBlKvpfwtcsFsHrVvsnwal1d+Rixxj1o9SZOZFwK pCt+/6DrUtQ3UDO94EXmr5LWVKvb1GRNqzjTH7o7QemHQoXwhWGZ+1vISgvcoOevKK0F ghvwd9RbfaBpp3SObdMNwp0Bdynw/L3MMcEVn00BujOGDh3SIp5mH6o976/B4oBa1EpV vbTA== X-Gm-Message-State: AHQUAuZJ9/g1rfSID5toeCVw0wBplIBbMYDZ8I0MdJbbt+oimgA3LZNn wG5sl/tRrhxgL6nyZW2sX5iiiQIE X-Received: by 2002:a1c:eb1a:: with SMTP id j26mr18663wmh.127.1549653303202; Fri, 08 Feb 2019 11:15:03 -0800 (PST) Received: from [172.30.89.46] (sjewanfw1-nat.mentorg.com. [139.181.7.34]) by smtp.gmail.com with ESMTPSA id h133sm6311145wmd.8.2019.02.08.11.15.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Feb 2019 11:15:02 -0800 (PST) Subject: Re: [PATCH 2/3] gpu: ipu-v3: ipu-ic: Add support for BT.709 encoding To: Tim Harvey 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" References: <20190203194744.11546-1-slongerbeam@gmail.com> <20190203194744.11546-3-slongerbeam@gmail.com> From: Steve Longerbeam Message-ID: Date: Fri, 8 Feb 2019 11:14:58 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/8/19 8:24 AM, Tim Harvey wrote: > 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: Thanks for reporting Tim I rather keep the check for supported encoding, and instead get rid of "Unsupported color space conversion" error, because that is the YUV->YUV case which can be allowed using the identity matrix. Steve > > 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