From patchwork Fri Jul 15 15:16: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: 9232211 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 B0F1A60865 for ; Fri, 15 Jul 2016 15:17:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F2EF27CCB for ; Fri, 15 Jul 2016 15:17:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93C3C27FA4; Fri, 15 Jul 2016 15:17:50 +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 08D0227F4B for ; Fri, 15 Jul 2016 15:17:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751607AbcGOPRp (ORCPT ); Fri, 15 Jul 2016 11:17:45 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:33946 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751461AbcGOPRJ (ORCPT ); Fri, 15 Jul 2016 11:17:09 -0400 Received: by mail-lf0-f65.google.com with SMTP id l69so2695307lfg.1; Fri, 15 Jul 2016 08:17:08 -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=mcVCoQ1WtCyxJ73027MTYDpv5HGzKmSusvX1JWZ2wFQ=; b=MNBfCz2GL7AioetiweCjx2ozh6Q0NeKttcBsDhZSkueoqjbvAVprH+HYcq+jBjRiXp 7VgyhfgGOH6rarjIJ403v9M6rseFZDx7yCUTvdH1FeghKg/4/Et/p9iCTCNgsOPYnJGz lJ1F4TKgas7VmHgPzIWmjYJIDvwaRATJlmx4F7FWzEDfi+Yex5G4cjC6QXF0MUbdK8NP l2ETjhEerR1YorHdAWcZtyJ2455dM8QrDWW4FpinbOr4hMi36LnMHjhh5Lkln60gVtP9 WT4k0lBq+q9/g0XEeUDanRkdsY5lWio/09idcJVlLgiU2+4JBiB801BVY82IskuoUZnh +TLQ== 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=mcVCoQ1WtCyxJ73027MTYDpv5HGzKmSusvX1JWZ2wFQ=; b=CXAX5AHU6zLCFjyWKnr0Ju5bYLPSckwWeaBg1tXzlePTZtgkU6anFt+TpG/QJmPW54 wiaPiAbCSSRLCMtigV58BzRcIV2kv05iTC5vdUXvdEc7IiQVddOrcKHm4svr8kcajv2a kLKZ4MHhZJGIMy0FFvnbOxxoDghvcb3GGh3qNfR78yIw8l17HYtXZL1Hxr4XbyD3pE6O iMeb3QEcElAPkWTt99mJ8Uir00hMQq0ShWrDTCjFkB1RDRObKPuAoX/7uiA6oKW9xfB8 wnBKslBa79CQrIWLorCs+n0XgPWu+mtyawjXYGroiJkXz+F4p4tH11jw0j/Yg3zON75b DAIg== X-Gm-Message-State: ALyK8tKvAy+dzpGcJjPv0VGKMW5ayO4eg2sbRW95pn2OfGcIS7CrII3KkK4Osj+B89a0Kg== X-Received: by 10.46.5.6 with SMTP id 6mr10411599ljf.66.1468595827325; Fri, 15 Jul 2016 08:17:07 -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 62sm2041745ljj.3.2016.07.15.08.17.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Jul 2016 08:17:05 -0700 (PDT) From: Ricardo Ribalda Delgado To: auro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Antti Palosaari , Guennadi Liakhovetski , Helen Mae Koike Fornazier , Philipp Zabel , Shuah Khan , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Delgado Subject: [PATCH 5/6] [media] vivid: Add support for HSV formats Date: Fri, 15 Jul 2016 17:16:55 +0200 Message-Id: <1468595816-31272-6-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1468595816-31272-1-git-send-email-ricardo.ribalda@gmail.com> References: <1468595816-31272-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 This patch adds support for V4L2_PIX_FMT_HSV24 and V4L2_PIX_FMT_HSV32. Signed-off-by: Ricardo Ribalda Delgado --- drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 94 +++++++++++++++++++++++-- drivers/media/platform/vivid/vivid-vid-common.c | 14 ++++ include/media/v4l2-tpg.h | 1 + 3 files changed, 105 insertions(+), 4 deletions(-) diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c index 3cab77ea92a4..d87a7a6a6b22 100644 --- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c @@ -318,6 +318,10 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc) tpg->hmask[0] = ~1; tpg->color_representation = TGP_COLOR_REPRESENTATION_YUV; break; + case V4L2_PIX_FMT_HSV24: + case V4L2_PIX_FMT_HSV32: + tpg->color_representation = TGP_COLOR_REPRESENTATION_HSV; + break; default: return false; } @@ -351,6 +355,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc) break; case V4L2_PIX_FMT_RGB24: case V4L2_PIX_FMT_BGR24: + case V4L2_PIX_FMT_HSV24: tpg->twopixelsize[0] = 2 * 3; break; case V4L2_PIX_FMT_BGR666: @@ -361,6 +366,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc) case V4L2_PIX_FMT_ARGB32: case V4L2_PIX_FMT_ABGR32: case V4L2_PIX_FMT_YUV32: + case V4L2_PIX_FMT_HSV32: tpg->twopixelsize[0] = 2 * 4; break; case V4L2_PIX_FMT_NV12: @@ -408,6 +414,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc) tpg->twopixelsize[1] = 4; break; } + return true; } EXPORT_SYMBOL_GPL(tpg_s_fourcc); @@ -490,6 +497,64 @@ static inline int linear_to_rec709(int v) return tpg_linear_to_rec709[v]; } +static void color_to_hsv(struct tpg_data *tpg, int r, int g, int b, + int *h, int *s, int *v) +{ + int max_rgb, min_rgb, diff_rgb; + int aux; + int third; + + r >>= 4; + g >>= 4; + b >>= 4; + + /*V*/ + max_rgb = max3(r, g, b); + *v = max_rgb; + if (!max_rgb) { + *h = 0; + *s = 0; + return; + } + + /*S*/ + min_rgb = min3(r, g, b); + diff_rgb = max_rgb - min_rgb; + aux = 255 * diff_rgb; + aux += max_rgb / 2; + aux /= max_rgb; + *s = aux; + if (!aux) { + *h = 0; + return; + } + + /*H*/ + if (max_rgb == r) { + aux = g - b; + third = 0; + } else if (max_rgb == g) { + aux = b - r; + third = 60; + } else { + aux = r - g; + third = 120; + } + + aux *= 30; + aux += diff_rgb / 2; + aux /= diff_rgb; + aux += third; + + /*Clamp H*/ + if (aux < 0) + aux += 180; + else if (aux > 180) + aux -= 180; + *h = aux; + +} + static void rgb2ycbcr(const int m[3][3], int r, int g, int b, int y_offset, int *y, int *cb, int *cr) { @@ -829,7 +894,19 @@ static void precalculate_color(struct tpg_data *tpg, int k) ycbcr_to_color(tpg, y, cb, cr, &r, &g, &b); } - if (tpg->color_representation == TGP_COLOR_REPRESENTATION_YUV) { + switch (tpg->color_representation) { + case TGP_COLOR_REPRESENTATION_HSV: + { + int h, s, v; + + color_to_hsv(tpg, r, g, b, &h, &s, &v); + tpg->colors[k][0] = h; + tpg->colors[k][1] = s; + tpg->colors[k][2] = v; + break; + } + case TGP_COLOR_REPRESENTATION_YUV: + { /* Convert to YCbCr */ int y, cb, cr; @@ -863,7 +940,10 @@ static void precalculate_color(struct tpg_data *tpg, int k) tpg->colors[k][0] = y; tpg->colors[k][1] = cb; tpg->colors[k][2] = cr; - } else { + break; + } + case TGP_COLOR_REPRESENTATION_RGB: + { if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) { r = (r * 219) / 255 + (16 << 4); g = (g * 219) / 255 + (16 << 4); @@ -913,6 +993,8 @@ static void precalculate_color(struct tpg_data *tpg, int k) tpg->colors[k][0] = r; tpg->colors[k][1] = g; tpg->colors[k][2] = b; + break; + } } } @@ -938,8 +1020,8 @@ static void gen_twopix(struct tpg_data *tpg, alpha = 0; if (color == TPG_COLOR_RANDOM) precalculate_color(tpg, color); - r_y = tpg->colors[color][0]; /* R or precalculated Y */ - g_u = tpg->colors[color][1]; /* G or precalculated U */ + r_y = tpg->colors[color][0]; /* R or precalculated Y, H */ + g_u = tpg->colors[color][1]; /* G or precalculated U, V */ b_v = tpg->colors[color][2]; /* B or precalculated V */ switch (tpg->fourcc) { @@ -1121,6 +1203,7 @@ static void gen_twopix(struct tpg_data *tpg, buf[0][offset + 1] = (g_u << 5) | b_v; break; case V4L2_PIX_FMT_RGB24: + case V4L2_PIX_FMT_HSV24: buf[0][offset] = r_y; buf[0][offset + 1] = g_u; buf[0][offset + 2] = b_v; @@ -1138,6 +1221,7 @@ static void gen_twopix(struct tpg_data *tpg, break; case V4L2_PIX_FMT_RGB32: case V4L2_PIX_FMT_XRGB32: + case V4L2_PIX_FMT_HSV32: alpha = 0; /* fall through */ case V4L2_PIX_FMT_YUV32: @@ -1896,6 +1980,8 @@ static const char *tpg_color_representation_str(enum tgp_color_representation { switch (color_representation) { + case TGP_COLOR_REPRESENTATION_HSV: + return "HSV"; case TGP_COLOR_REPRESENTATION_YUV: return "YCbCr"; case TGP_COLOR_REPRESENTATION_RGB: diff --git a/drivers/media/platform/vivid/vivid-vid-common.c b/drivers/media/platform/vivid/vivid-vid-common.c index 314799111cf7..cc985685ed05 100644 --- a/drivers/media/platform/vivid/vivid-vid-common.c +++ b/drivers/media/platform/vivid/vivid-vid-common.c @@ -445,6 +445,20 @@ struct vivid_fmt vivid_formats[] = { .planes = 1, .buffers = 1, }, + { + .fourcc = V4L2_PIX_FMT_HSV24, /* HSV 24bits */ + .vdownsampling = { 1 }, + .bit_depth = { 24 }, + .planes = 1, + .buffers = 1, + }, + { + .fourcc = V4L2_PIX_FMT_HSV32, /* HSV 32bits */ + .vdownsampling = { 1 }, + .bit_depth = { 32 }, + .planes = 1, + .buffers = 1, + }, /* Multiplanar formats */ diff --git a/include/media/v4l2-tpg.h b/include/media/v4l2-tpg.h index 13ea42bb9530..17a257d12941 100644 --- a/include/media/v4l2-tpg.h +++ b/include/media/v4l2-tpg.h @@ -90,6 +90,7 @@ enum tpg_move_mode { enum tgp_color_representation { TGP_COLOR_REPRESENTATION_RGB, TGP_COLOR_REPRESENTATION_YUV, + TGP_COLOR_REPRESENTATION_HSV, }; extern const char * const tpg_aspect_strings[];