From patchwork Thu Aug 18 14:33:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 9288275 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E1629607FF for ; Thu, 18 Aug 2016 14:35:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D20302929C for ; Thu, 18 Aug 2016 14:35:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C68D6292A4; Thu, 18 Aug 2016 14:35:54 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 70A2C2929C for ; Thu, 18 Aug 2016 14:35:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1947283AbcHROfv (ORCPT ); Thu, 18 Aug 2016 10:35:51 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:36596 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1768303AbcHROfq (ORCPT ); Thu, 18 Aug 2016 10:35:46 -0400 Received: by mail-lf0-f65.google.com with SMTP id 33so1865960lfw.3; Thu, 18 Aug 2016 07:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3QcdM3+kyigVd2kYaJv5OiWn+nC/bvwJXyhHKW8yfYQ=; b=V5JCh5Jr9ybyoKqtIJVJZvvF53JGmjfYBUJHXT1XD/vHUvfanyip/6ePr8r75hH5Ro uzcSmJsiPcZykYfpSRLv4K5FgbgPTbnzo/Vbw1Auytxmlo/anuTqpbBGE5CqTQ/xyu1C oKzB1drI7Sh/CoIAQj6XeUKQw4FKT4DqCFeZiEaoVuXefD7wuwHSPSNcCUf2V8vpIfiq UaYct4ziGW0+4OrGYNBUBnl/lgTvygRCqF1TJQHDDwLgzLfl1lk3BvbkSIk2HdW87G7j 4TehguzEBHinLu/zzC3VUC65nZpYsAKEULCGfHidvzH8elowXYEiez3SelVmPD2Qewbh 5Tjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3QcdM3+kyigVd2kYaJv5OiWn+nC/bvwJXyhHKW8yfYQ=; b=F3mlWlj61bWE+ieoiIvbL2o/NWSS5EglRdQ+0XDzxAAwgHIihCW9CgpbziWR45kAL+ Vv1ocqFfrUBRIExHYN+3bs3Y5Fnl25SSrC5uWBLfQLRZv21qvrwJRHjoGRR+mM2n8Y5W Uye1N2YNL1k0pcW8lqhKDKj1EArTJonhShXFNWZ0YjhxGLGuBFp1XlQlA/mTl06hK/GN PlLGnCMi237iu3GR6Vvgrz1MiU4FEYCZP9POd9S3SqsjWQCx+kU1udVOddgY4AtSX/XU TvwuxvQei621QeBuHxAWdkhPjj/JcPqh0UofdaiezLctQgQa7ac3XlCNUF3q4JSDeKav 0dAw== X-Gm-Message-State: AEkoouv+tF3oX/chBCn8QSb9rXm5eX9M1BBpXpxf66wUKErVFpyqu5xdI4btsFyy5pTMFg== X-Received: by 10.25.210.80 with SMTP id j77mr735808lfg.139.1471530832875; Thu, 18 Aug 2016 07:33:52 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id p21sm389218lfp.4.2016.08.18.07.33.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Aug 2016 07:33:51 -0700 (PDT) From: Ricardo Ribalda Delgado To: Mauro Carvalho Chehab , Hans Verkuil , Markus Heiser , Laurent Pinchart , Helen Mae Koike Fornazier , Antti Palosaari , Philipp Zabel , Shuah Khan , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Cc: Ricardo Ribalda Delgado Subject: [PATCH v5 08/12] [media] vivid: Fix YUV555 and YUV565 handling Date: Thu, 18 Aug 2016 16:33:34 +0200 Message-Id: <1471530818-7928-9-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1471530818-7928-1-git-send-email-ricardo.ribalda@gmail.com> References: <1471530818-7928-1-git-send-email-ricardo.ribalda@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 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 --- 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 920c8495f3dd..7364ced09abc 100644 --- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c @@ -795,6 +795,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 ycbcr_valid = false; if (k == TPG_COLOR_TEXTBG) { col = tpg_get_textbg_color(tpg); @@ -871,7 +873,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 */ @@ -888,13 +889,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_YCBCR) { - 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_YCBCR) + ycbcr_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; @@ -915,9 +913,8 @@ static void precalculate_color(struct tpg_data *tpg, int k) case TGP_COLOR_ENC_YCBCR: { /* Convert to YCbCr */ - int y, cb, cr; - - color_to_ycbcr(tpg, r, g, b, &y, &cb, &cr); + if (!ycbcr_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);