From patchwork Mon Jul 18 12:42:12 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: 9234529 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 9F44A6075D for ; Mon, 18 Jul 2016 12:44:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 916EC205AD for ; Mon, 18 Jul 2016 12:44:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 854BF26538; Mon, 18 Jul 2016 12:44:00 +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 2CCC5205AD for ; Mon, 18 Jul 2016 12:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751737AbcGRMn5 (ORCPT ); Mon, 18 Jul 2016 08:43:57 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:36852 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751451AbcGRMmd (ORCPT ); Mon, 18 Jul 2016 08:42:33 -0400 Received: by mail-lf0-f65.google.com with SMTP id 33so11236840lfw.3; Mon, 18 Jul 2016 05:42:32 -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=daGTgZW9jGK/gbQq9XLHin//HYbA8z1t+KQQX75ovPk=; b=S2nuAilqjNRxVGXN8/uOO1XZWzVE06kl0WQsNFnsrRklGcjf29x9QkE9NkTTrzK+ec N3kfhgiH/6xhNr67/1GV/b8gkH1AxA36RkVdVB3laJzjhvYp9Iw8Jy43kobgvuWBI2/H HuAQGayowPm9lsOugI1Fn9i5yrW1SGypf7ckFCyfAz/QVPj7amaajnCdDxH7NF1N1S35 enZaoqX3WvDXJ+f4iqp4WwWG+NhBbChMeo8exTtYFANh7bt9NzEB3XSKXtIHilqODjiy JGFo/F3tAisYDFM/jjCAupMWIjit/dR8tFB/u9jZCGEVBt10YjbSd+ZfXfaevggH1rMr Fv3w== 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=daGTgZW9jGK/gbQq9XLHin//HYbA8z1t+KQQX75ovPk=; b=PS1BnJkG4PyG3v/fMDEduGIJKX1+9IhkmqFAKCFINwLIXLS6xsAe5iR7UZ8M5GVWX1 +4AVGm2zwj2FYbSEYTq4iCYrjCI1tuKxe6DnkRNt6I96oXyYKk/sONaY/ceQrT2zhjGb pZoI7Y4v2qQA1ICHJlGaeLkFkchaR6jUnXwrBePOjYmT9utNW3uMwFtW7bV8qj35oynm n9uiEzycJ3ZYkIQCxZpPiiCVMCOSFJmKcCkFeUWMWs5lG+3X9F3zp0ww5Mc7w62qeBAX CupRnmK3mRnfWO4QjkfNpNorfVtqjOM61Bj1A+a6subSkCq1zE2oBGSBl6AFzdR+5Tih Jpqw== X-Gm-Message-State: ALyK8tIHri2K9pKCxkX41uzo98oH2St1vDttTV5mnP4WBvWa5cSdKCwZhalCY2wluVX+0Q== X-Received: by 10.46.9.22 with SMTP id 22mr15062891ljj.63.1468845751529; Mon, 18 Jul 2016 05:42:31 -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 205sm4571672ljj.47.2016.07.18.05.42.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jul 2016 05:42:30 -0700 (PDT) From: Ricardo Ribalda Delgado To: Jonathan Corbet , Mauro Carvalho Chehab , Hans Verkuil , Markus Heiser , Laurent Pinchart , Helen Mae Koike Fornazier , Antti Palosaari , Philipp Zabel , Shuah Khan , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Cc: Ricardo Ribalda Delgado Subject: [PATCH v4 08/12] [media] vivid: Fix YUV555 and YUV565 handling Date: Mon, 18 Jul 2016 14:42:12 +0200 Message-Id: <1468845736-19651-9-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1468845736-19651-1-git-send-email-ricardo.ribalda@gmail.com> References: <1468845736-19651-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 41cc402ddeef..a26172575e56 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 ycbcr_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_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; @@ -917,9 +915,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);