From patchwork Sat Jul 16 10:41:55 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: 9233145 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 288D26075E for ; Sat, 16 Jul 2016 10:44:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18D7F264F4 for ; Sat, 16 Jul 2016 10:44:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D66124DA2; Sat, 16 Jul 2016 10:44: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=unavailable 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 B4D2025218 for ; Sat, 16 Jul 2016 10:44:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751801AbcGPKmu (ORCPT ); Sat, 16 Jul 2016 06:42:50 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:36489 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751656AbcGPKmR (ORCPT ); Sat, 16 Jul 2016 06:42:17 -0400 Received: by mail-lf0-f65.google.com with SMTP id 33so8368832lfw.3; Sat, 16 Jul 2016 03:42:16 -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=imTurpotjvVFfvv2VHNvwr8qicmIwXtmxYEsc7jZVIQ=; b=S841/YS0jMcxMxV0ARLBbXbepkU7Z7OzEzwsHiTYJwVBKtAJT7KC2cCYD2jHnOPTPn odWDFhvlnl1WKfAxNjitRqpKxfYzX7lsi0owvN53jyoueBfxKupo9WJoItTZjsW+OlL+ 4rGmB1wR3JkzlVAutRYCjTQJTzdAHHW4uJRn4O5Xng20M7eP55xmK4W9hdVWZxHeZx+H RMXxnHKTAtt6XJs+TuKcCyq6jZpECZizP7e67S8yY9vDqpTizU9eFl9075AMC/Y40R3V R3eGEGwIp9buFk0/1yKDLygM7eXq0xCf5kkC9IK+leCjL1uXsGErMv1kF5gke9mB3Myr ylAQ== 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=imTurpotjvVFfvv2VHNvwr8qicmIwXtmxYEsc7jZVIQ=; b=Lv4WjcqrB5qokZPfC29ogbcAgsRn185SG741h/XecBBbBl5OUKF8sjAcv0qEud4jKe W3scdyQ/QrQlH+IqKMSosbKLCWsTTjTWmi0uOAd81g7A+kVP2EJ4H8LGITvVeY6+Dbbh iWVY5LJZIawm7B34w77ja8ztldNrzstcvPdoZ9pN6NxpPeNaBD9ayWFwBl3dIQql+QTD taub2tbAmyENqJAT+kmO/3AKHBg70kI9X/uaHZBfN0RQZQ79jYPIfcAmcKw4KhQehbAe FIjGti61ZuVG+kgssQ4y8TPw95erTgzAuHHxV+bsE4nw8g5HLu/Muh6UOFfzOS/JLrHc 91Pg== X-Gm-Message-State: ALyK8tL6NAxizsbH214/hmi/LD0UfDAkNa2SV7axEPwy8tpNkJQfJXtOLl9Ht3KGwfO9jw== X-Received: by 10.46.33.154 with SMTP id h26mr11493313lji.39.1468665735669; Sat, 16 Jul 2016 03:42:15 -0700 (PDT) Received: from localhost.localdomain (x1-6-74-44-01-e3-62-1a.cpe.webspeed.dk. [80.167.115.215]) by smtp.gmail.com with ESMTPSA id f22sm1779457lji.13.2016.07.16.03.42.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Jul 2016 03:42:14 -0700 (PDT) From: Ricardo Ribalda Delgado To: Jonathan Corbet , Mauro Carvalho Chehab , Hans Verkuil , Markus Heiser , Helen Mae Koike Fornazier , Laurent Pinchart , 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 v3 8/9] [media] vivid: Fix YUV555 and YUV565 handling Date: Sat, 16 Jul 2016 12:41:55 +0200 Message-Id: <1468665716-10178-9-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1468665716-10178-1-git-send-email-ricardo.ribalda@gmail.com> References: <1468665716-10178-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 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);