Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2405074imj; Mon, 11 Feb 2019 02:13:22 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ0Gb8dvb7cPfFs5SUf1y3EzoUk3wOMgIGKcjbBX03Tsc6lnA0YdNKBXuEyiGLWo0iLz1mm X-Received: by 2002:a17:902:112a:: with SMTP id d39mr36988968pla.66.1549880002155; Mon, 11 Feb 2019 02:13:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549880002; cv=none; d=google.com; s=arc-20160816; b=avBvr/kql5fdW8xMw+8m7SQa++mxmZAgFUzdMqCmKuVFB7+yikB/uEoFQo7n5Ux9lr NePw+w7BITHSJgT1iortww/mcPx+dlo7eewr20xGDznihDtfdsV4jyRoQhEIqQKW+u+I IHZPhpfQ9/+vaHw76Eoo5lFExg7nPQrgWPWd1G1/mNrsHSC/SIIniG78AYcGpK7GdnN2 E36bIjCND2rm9fPnUzDJPh4t9IjV65g/V2J4eddqnmYTqXprDUkWAnodNOvtZdjZc/u6 ABj3td3CP1CYqv8semCrszmn8XkRhuXii04iLIbwQvPPIv2U3fVEOf4EGljEe1y4AmhK 3Ynw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=YFUsfjKOGeeXJrQKpS3rxNlkkk8IZGsk02ndxoULzJY=; b=fugSFEm9wVjzYnZCu0VsRpM7jTAwNxw+93FQuyjVLDJfI9x6dcclRXQdF9SCuBx0Qc 9axGGyXdrkS+woe6SuNf8kR9s/lmM5HUIxdHqMVSWuC8y8mzauOL+bAcZzc/WhG+E7a/ Mk4KQOPk6M+M4LSDnR+/k2TlT3LKBsCzshMRmVARl1CAa3oI4cFGdB5yGjo1OsGLfI8R se6ZxDyqHOca3RdN6ccnPeZdT0ArtkaxirV5gS0gswdbOnB3vMl8P4lXyjhn236f7AlB GQ2Edi6fhT+doeK0o+MP7LF5QCh8gUh1zknq0/BuitRANh/9TSjM08LnuAV+bmYgLftS XtxQ== ARC-Authentication-Results: i=1; mx.google.com; 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 98si2046687pls.205.2019.02.11.02.13.06; Mon, 11 Feb 2019 02:13:22 -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; 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 S1726699AbfBKKMl (ORCPT + 99 others); Mon, 11 Feb 2019 05:12:41 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:40737 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725931AbfBKKMl (ORCPT ); Mon, 11 Feb 2019 05:12:41 -0500 Received: from lupine.hi.pengutronix.de ([2001:67c:670:100:3ad5:47ff:feaf:1a17] helo=lupine) by metis.ext.pengutronix.de with esmtp (Exim 4.89) (envelope-from ) id 1gt8Zm-0000aN-V5; Mon, 11 Feb 2019 11:12:34 +0100 Message-ID: <1549879951.7687.6.camel@pengutronix.de> Subject: Re: [PATCH v4 3/4] gpu: ipu-v3: ipu-ic: Add support for BT.709 encoding From: Philipp Zabel To: Steve Longerbeam , linux-media@vger.kernel.org Cc: Tim Harvey , 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" Date: Mon, 11 Feb 2019 11:12:31 +0100 In-Reply-To: <20190209014748.10427-4-slongerbeam@gmail.com> References: <20190209014748.10427-1-slongerbeam@gmail.com> <20190209014748.10427-4-slongerbeam@gmail.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:3ad5:47ff:feaf:1a17 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2019-02-08 at 17:47 -0800, 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 > --- > 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 | 71 +++++++++++++++++++-- > drivers/gpu/ipu-v3/ipu-image-convert.c | 1 + > drivers/staging/media/imx/imx-ic-prpencvf.c | 4 +- > include/video/imx-ipu-v3.h | 5 +- > 4 files changed, 71 insertions(+), 10 deletions(-) > > diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c > index e459615a49a1..c5f83d7e357f 100644 > --- a/drivers/gpu/ipu-v3/ipu-ic.c > +++ b/drivers/gpu/ipu-v3/ipu-ic.c > @@ -212,6 +212,23 @@ static const struct ic_csc_params ic_csc_identity = { > .scale = 2, > }; > > +/* > + * BT.709 encoding from RGB full range to YUV limited range: > + * > + * Y = R * .2126 + G * .7152 + B * .0722; > + * U = R * -.1146 + G * -.3854 + B * .5000 + 128.; > + * V = R * .5000 + G * -.4542 + B * -.0458 + 128.; This is a conversion to YUV full range. Limited range should be: Y   R * .1826 + G *  .6142 + B *  .0620 + 16; U = R * -.1007 + G * -.3385 + B *  .4392 + 128; V   R * .4392 + G * -.3990 + B * -.0402 + 128; > + */ > +static const struct ic_csc_params ic_csc_rgb2ycbcr_bt709 = { > + .coeff = { > + { 54, 183, 18 }, > + { 483, 413, 128 }, > + { 128, 396, 500 }, > + }, > + .offset = { 0, 512, 512 }, > + .scale = 1, > +}; > + > /* > * Inverse BT.601 encoding from YUV limited range to RGB full range: > * > @@ -229,12 +246,31 @@ static const struct ic_csc_params ic_csc_ycbcr2rgb_bt601 = { > .scale = 2, > }; > > +/* > + * Inverse BT.709 encoding from YUV limited range to RGB full range: > + * > + * R = (1. * (Y - 16)) + (1.5748 * (Cr - 128)); > + * G = (1. * (Y - 16)) - (0.1873 * (Cb - 128)) - (0.4681 * (Cr - 128)); > + * B = (1. * (Y - 16)) + (1.8556 * (Cb - 128); The coefficients look like full range again, conversion from limited range YUV should look like: R = (1.1644 * (Y - 16)) + (1.7927 * (Cr - 128)); G = (1.1644 * (Y - 16)) - (0.2132 * (Cb - 128)) - (0.5329 * (Cr - 128)); B = (1.1644 * (Y - 16)) + (2.1124 * (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, Should we support YUV BT.601 <-> YUV REC.709 conversions? That would require separate encodings for input and output. Also, this might be a good time to think about adding quantization range parameters as well. regards Philipp