mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
To: Jonathan Corbet <corbet@lwn.net>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil@xs4all.nl>,
	Markus Heiser <markus.heiser@darmarIT.de>,
	Helen Mae Koike Fornazier <helen.koike@collabora.co.uk>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Antti Palosaari <crope@iki.fi>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Shuah Khan <shuahkh@osg.samsung.com>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-media@vger.kernel.org
Cc: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Subject: [PATCH v3 8/9] [media] vivid: Fix YUV555 and YUV565 handling
Date: Sat, 16 Jul 2016 12:41:55 +0200	[thread overview]
Message-ID: <1468665716-10178-9-git-send-email-ricardo.ribalda@gmail.com> (raw)
In-Reply-To: <1468665716-10178-1-git-send-email-ricardo.ribalda@gmail.com>

precalculate_color() had a optimization that avoided duplicated
conversion for YUV formats. This optimization did not take into
consideration YUV444, YUV555, YUV565 or limited range quantization.

This patch keeps the optimization, but fixes the wrong handling.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
index e91bf3cbaab9..1c862465e335 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -797,6 +797,8 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 	int r = tpg_colors[col].r;
 	int g = tpg_colors[col].g;
 	int b = tpg_colors[col].b;
+	int y, cb, cr;
+	bool ycbbr_valid = false;
 
 	if (k == TPG_COLOR_TEXTBG) {
 		col = tpg_get_textbg_color(tpg);
@@ -873,7 +875,6 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 	     tpg->saturation != 128 || tpg->hue) &&
 	    tpg->color_enc != TGP_COLOR_ENC_LUMA) {
 		/* Implement these operations */
-		int y, cb, cr;
 		int tmp_cb, tmp_cr;
 
 		/* First convert to YCbCr */
@@ -890,13 +891,10 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 
 		cb = (128 << 4) + (tmp_cb * tpg->contrast * tpg->saturation) / (128 * 128);
 		cr = (128 << 4) + (tmp_cr * tpg->contrast * tpg->saturation) / (128 * 128);
-		if (tpg->color_enc == TGP_COLOR_ENC_YUV) {
-			tpg->colors[k][0] = clamp(y >> 4, 1, 254);
-			tpg->colors[k][1] = clamp(cb >> 4, 1, 254);
-			tpg->colors[k][2] = clamp(cr >> 4, 1, 254);
-			return;
-		}
-		ycbcr_to_color(tpg, y, cb, cr, &r, &g, &b);
+		if (tpg->color_enc == TGP_COLOR_ENC_YUV)
+			ycbbr_valid = true;
+		else
+			ycbcr_to_color(tpg, y, cb, cr, &r, &g, &b);
 	} else if ((tpg->brightness != 128 || tpg->contrast != 128) &&
 		   tpg->color_enc == TGP_COLOR_ENC_LUMA) {
 		r = (16 << 4) + ((r - (16 << 4)) * tpg->contrast) / 128;
@@ -917,9 +915,8 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 	case TGP_COLOR_ENC_YUV:
 	{
 		/* Convert to YCbCr */
-		int y, cb, cr;
-
-		color_to_ycbcr(tpg, r, g, b, &y, &cb, &cr);
+		if (!ycbbr_valid)
+			color_to_ycbcr(tpg, r, g, b, &y, &cb, &cr);
 
 		if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) {
 			y = clamp(y, 16 << 4, 235 << 4);
-- 
2.8.1

  parent reply	other threads:[~2016-07-16 10:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-16 10:41 [PATCH v3 0/9] Add HSV format Ricardo Ribalda Delgado
2016-07-16 10:41 ` [PATCH v3 1/9] [media] videodev2.h Add HSV formats Ricardo Ribalda Delgado
2016-07-16 10:41 ` [PATCH v3 2/9] [media] Documentation: Add HSV format Ricardo Ribalda Delgado
2016-07-16 10:41 ` [PATCH v3 3/9] [media] Documentation: Add Ricardo Ribalda Ricardo Ribalda Delgado
2016-07-16 10:41 ` [PATCH v3 4/9] [media] vivid: code refactor for color encoding Ricardo Ribalda Delgado
2016-07-18  8:40   ` Hans Verkuil
2016-07-16 10:41 ` [PATCH v3 5/9] [media] vivid: Add support for HSV formats Ricardo Ribalda Delgado
2016-07-16 10:41 ` [PATCH v3 6/9] [media] vivid: Rename variable Ricardo Ribalda Delgado
2016-07-16 10:41 ` [PATCH v3 7/9] [media] vivid: Introduce TPG_COLOR_ENC_LUMA Ricardo Ribalda Delgado
2016-07-16 10:41 ` Ricardo Ribalda Delgado [this message]
2016-07-18  8:51   ` [PATCH v3 8/9] [media] vivid: Fix YUV555 and YUV565 handling Hans Verkuil
2016-07-18  9:03     ` Ricardo Ribalda Delgado
2016-07-16 10:41 ` [PATCH v3 9/9] [media] vivid: Local optimization Ricardo Ribalda Delgado
2016-07-16 10:52   ` Ricardo Ribalda Delgado

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468665716-10178-9-git-send-email-ricardo.ribalda@gmail.com \
    --to=ricardo.ribalda@gmail.com \
    --cc=corbet@lwn.net \
    --cc=crope@iki.fi \
    --cc=helen.koike@collabora.co.uk \
    --cc=hverkuil@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=markus.heiser@darmarIT.de \
    --cc=mchehab@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=shuahkh@osg.samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®