Received: by 10.223.176.5 with SMTP id f5csp1093758wra; Tue, 6 Feb 2018 12:31:14 -0800 (PST) X-Google-Smtp-Source: AH8x226MhYhfEl3gOof0d/f5tgu8iD7PPIc7tjTAxPylmvImZd7d+yJUudoM+JyyoRDQ0vGdSCVy X-Received: by 10.99.110.7 with SMTP id j7mr1462490pgc.156.1517949074220; Tue, 06 Feb 2018 12:31:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517949074; cv=none; d=google.com; s=arc-20160816; b=Wa60BRdwxcBUDN2d2K05cwY80S0NukTS1fMPy0pSTZbpaP1xQYhXPVqGYcyvztbYvj sIbCTkuTRU9JXMt5M98utqzzk6OrqpyLHbaj3AYCtccaqecEclX51SCuUE2XnBqMr3+g T2/i//3SxqJcI/hwoS7ySHcb8l8Kr12K+R3ti6XBjzyiDvMT6ieOpJC3xbluD18BVcCj QFmDxD4jUiqEeXLJFtyRGHiqH7lsejNaUUxhT6G24kPgIm64R8pyxPhCgxQ5ya3EX0g6 RUyQKbu8gRfYgYsOXe9KuzPD1iNptqe3wfyBplCyPYO/VukDdMlVWxfsE1z8bSdMNhy4 PJZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=j/iciJnvaX36/pfriZxnvwOilZ0a5Bq8HT7mcWwUaEc=; b=GjXhaMqOA7aI4uz8y9wMDXWlfLgBs9U9WE74btTi/qSjzlwA0Je5A3LVPdqz4EMEt4 nXxsvXeqAwihGnwBpvnf7Y5TwitzzqDrH6RwMDDDp2nR8ImVbX//HgP4ZIBZ0wBMlZwL vULEKc8AhdZPulc8SC4FI83wCF9cId04FQb/54iG2utRlEbBGgKDEjg+xQJNBjRj/CS/ 8WNZlh8qc0+vXa5DFhQ7Z6Ogjy0Wnd8Ewf6cKEdkrPeIGRUO5FYbCC3Ihh1YV/HTunBa 0ZxSYD668fHIfRPfwLOu+eWNz3+OUq7gC5QWOSDDkrX8BLTIX41GH72fF/DA6J5LrsMI 3h6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gateworks-com.20150623.gappssmtp.com header.s=20150623 header.b=rriX9zN1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n26si5526309pge.266.2018.02.06.12.31.00; Tue, 06 Feb 2018 12:31:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gateworks-com.20150623.gappssmtp.com header.s=20150623 header.b=rriX9zN1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753355AbeBFU2O (ORCPT + 99 others); Tue, 6 Feb 2018 15:28:14 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:40978 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752832AbeBFU2L (ORCPT ); Tue, 6 Feb 2018 15:28:11 -0500 Received: by mail-pg0-f66.google.com with SMTP id 141so1560398pgd.8 for ; Tue, 06 Feb 2018 12:28:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gateworks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=j/iciJnvaX36/pfriZxnvwOilZ0a5Bq8HT7mcWwUaEc=; b=rriX9zN1xF7HUvn71IFs1n1vNk8AVAFIHqlN5XfJGy/5uN8FC5qUtPulhga1fkLwNy zQlAFFF7qrL95ENyQVryi+8bC8IZqUtrIzCCZmy20pV3HF5pCbf/mMxXbama7pLBVWuf dps9/kHenZDkOtlJKhT2pZNYtFk0LnjgccK4aT7XiPBkF3SzfpRuQHeE/kKBNynu+Qk7 G99WEGG0mMLG5/Y8fFG4JdX1dbRdBGG0rYSv0YXG5zB5BSimFiChS1X4P9IvS9DEiu+D 3A2IN5TSpYW6m/8G3PzcJKO90So6zyg1AXR18yIokckO4h1WgR0i4wRYNlaR2+AtsvvX n/3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=j/iciJnvaX36/pfriZxnvwOilZ0a5Bq8HT7mcWwUaEc=; b=LHZw/a1xfRMWumazcKtcgw3YIijLfn+j5kRIr38FTKLp00+Sd6KYkYWpvvYzYzJxOf D955UhFhDHndautkBhuuQD4F6hQW2ZIOdLe5lTHlVsx8ShPz87wmbx1uTYmaxavsby+l l2Va/+R67C+qrIa3jStmkqZWurwwX5v3ZarqnfHSojfthcPb9ZNjwNzQowgbVsKPIkIj 3kfLL6F1mm2m7csHk5o3n0llz74ggEnnplE7bAkQntSj1ONJX9bew1tu++aRMC4rapMR rLFB/nCWIP1rLEYKDV2stwpfNqwwRpcy2OLEy19HJOOeqIx4DTAchS8elaX4oV7uopS6 NodQ== X-Gm-Message-State: APf1xPBbnFtpPFDsSrteLgdXLRdxLP7PmcgEDcDzkzaz++VjrVvzdxyK +RF3U4060LEN7Zn6/SYVMl9d5Q== X-Received: by 10.98.198.2 with SMTP id m2mr3576222pfg.113.1517948890940; Tue, 06 Feb 2018 12:28:10 -0800 (PST) Received: from tharvey.pdc.gateworks.com (68-189-91-139.static.snlo.ca.charter.com. [68.189.91.139]) by smtp.gmail.com with ESMTPSA id m9sm22943512pff.59.2018.02.06.12.28.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Feb 2018 12:28:10 -0800 (PST) From: Tim Harvey To: linux-media@vger.kernel.org, alsa-devel@alsa-project.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, shawnguo@kernel.org, Steve Longerbeam , Philipp Zabel , Hans Verkuil , Mauro Carvalho Chehab , Hans Verkuil , Hans Verkuil Subject: [PATCH v8 1/7] v4l2-dv-timings: add v4l2_hdmi_colorimetry() Date: Tue, 6 Feb 2018 12:27:48 -0800 Message-Id: <1517948874-21681-2-git-send-email-tharvey@gateworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517948874-21681-1-git-send-email-tharvey@gateworks.com> References: <1517948874-21681-1-git-send-email-tharvey@gateworks.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans Verkuil Add the v4l2_hdmi_colorimetry() function so we have a single function that determines the colorspace, YCbCr encoding, quantization range and transfer function from the InfoFrame data. Signed-off-by: Hans Verkuil Signed-off-by: Tim Harvey --- drivers/media/v4l2-core/v4l2-dv-timings.c | 141 ++++++++++++++++++++++++++++++ include/media/v4l2-dv-timings.h | 21 +++++ 2 files changed, 162 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-dv-timings.c b/drivers/media/v4l2-core/v4l2-dv-timings.c index 930f9c5..0182d3d 100644 --- a/drivers/media/v4l2-core/v4l2-dv-timings.c +++ b/drivers/media/v4l2-core/v4l2-dv-timings.c @@ -27,6 +27,7 @@ #include #include #include +#include MODULE_AUTHOR("Hans Verkuil"); MODULE_DESCRIPTION("V4L2 DV Timings Helper Functions"); @@ -814,3 +815,143 @@ struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait) return aspect; } EXPORT_SYMBOL_GPL(v4l2_calc_aspect_ratio); + +/** v4l2_hdmi_rx_colorimetry - determine HDMI colorimetry information + * based on various InfoFrames. + * @avi - the AVI InfoFrame + * @hdmi - the HDMI Vendor InfoFrame, may be NULL + * @height - the frame height + * + * Determines the HDMI colorimetry information, i.e. how the HDMI + * pixel color data should be interpreted. + * + * Note that some of the newer features (DCI-P3, HDR) are not yet + * implemented: the hdmi.h header needs to be updated to the HDMI 2.0 + * and CTA-861-G standards. + */ +struct v4l2_hdmi_colorimetry +v4l2_hdmi_rx_colorimetry(const struct hdmi_avi_infoframe *avi, + const struct hdmi_vendor_infoframe *hdmi, + unsigned int height) +{ + struct v4l2_hdmi_colorimetry c = { + V4L2_COLORSPACE_SRGB, + V4L2_YCBCR_ENC_DEFAULT, + V4L2_QUANTIZATION_FULL_RANGE, + V4L2_XFER_FUNC_SRGB + }; + bool is_ce = avi->video_code || (hdmi && hdmi->vic); + bool is_sdtv = height <= 576; + bool default_is_lim_range_rgb = avi->video_code > 1; + + switch (avi->colorspace) { + case HDMI_COLORSPACE_RGB: + /* RGB pixel encoding */ + switch (avi->colorimetry) { + case HDMI_COLORIMETRY_EXTENDED: + switch (avi->extended_colorimetry) { + case HDMI_EXTENDED_COLORIMETRY_ADOBE_RGB: + c.colorspace = V4L2_COLORSPACE_ADOBERGB; + c.xfer_func = V4L2_XFER_FUNC_ADOBERGB; + break; + case HDMI_EXTENDED_COLORIMETRY_BT2020: + c.colorspace = V4L2_COLORSPACE_BT2020; + c.xfer_func = V4L2_XFER_FUNC_709; + break; + default: + break; + } + break; + default: + break; + } + switch (avi->quantization_range) { + case HDMI_QUANTIZATION_RANGE_LIMITED: + c.quantization = V4L2_QUANTIZATION_LIM_RANGE; + break; + case HDMI_QUANTIZATION_RANGE_FULL: + break; + default: + if (default_is_lim_range_rgb) + c.quantization = V4L2_QUANTIZATION_LIM_RANGE; + break; + } + break; + + default: + /* YCbCr pixel encoding */ + c.quantization = V4L2_QUANTIZATION_LIM_RANGE; + switch (avi->colorimetry) { + case HDMI_COLORIMETRY_NONE: + if (!is_ce) + break; + if (is_sdtv) { + c.colorspace = V4L2_COLORSPACE_SMPTE170M; + c.ycbcr_enc = V4L2_YCBCR_ENC_601; + } else { + c.colorspace = V4L2_COLORSPACE_REC709; + c.ycbcr_enc = V4L2_YCBCR_ENC_709; + } + c.xfer_func = V4L2_XFER_FUNC_709; + break; + case HDMI_COLORIMETRY_ITU_601: + c.colorspace = V4L2_COLORSPACE_SMPTE170M; + c.ycbcr_enc = V4L2_YCBCR_ENC_601; + c.xfer_func = V4L2_XFER_FUNC_709; + break; + case HDMI_COLORIMETRY_ITU_709: + c.colorspace = V4L2_COLORSPACE_REC709; + c.ycbcr_enc = V4L2_YCBCR_ENC_709; + c.xfer_func = V4L2_XFER_FUNC_709; + break; + case HDMI_COLORIMETRY_EXTENDED: + switch (avi->extended_colorimetry) { + case HDMI_EXTENDED_COLORIMETRY_XV_YCC_601: + c.colorspace = V4L2_COLORSPACE_REC709; + c.ycbcr_enc = V4L2_YCBCR_ENC_XV709; + c.xfer_func = V4L2_XFER_FUNC_709; + break; + case HDMI_EXTENDED_COLORIMETRY_XV_YCC_709: + c.colorspace = V4L2_COLORSPACE_REC709; + c.ycbcr_enc = V4L2_YCBCR_ENC_XV601; + c.xfer_func = V4L2_XFER_FUNC_709; + break; + case HDMI_EXTENDED_COLORIMETRY_S_YCC_601: + c.colorspace = V4L2_COLORSPACE_SRGB; + c.ycbcr_enc = V4L2_YCBCR_ENC_601; + c.xfer_func = V4L2_XFER_FUNC_SRGB; + break; + case HDMI_EXTENDED_COLORIMETRY_ADOBE_YCC_601: + c.colorspace = V4L2_COLORSPACE_ADOBERGB; + c.ycbcr_enc = V4L2_YCBCR_ENC_601; + c.xfer_func = V4L2_XFER_FUNC_ADOBERGB; + break; + case HDMI_EXTENDED_COLORIMETRY_BT2020: + c.colorspace = V4L2_COLORSPACE_BT2020; + c.ycbcr_enc = V4L2_YCBCR_ENC_BT2020; + c.xfer_func = V4L2_XFER_FUNC_709; + break; + case HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM: + c.colorspace = V4L2_COLORSPACE_BT2020; + c.ycbcr_enc = V4L2_YCBCR_ENC_BT2020_CONST_LUM; + c.xfer_func = V4L2_XFER_FUNC_709; + break; + default: /* fall back to ITU_709 */ + c.colorspace = V4L2_COLORSPACE_REC709; + c.ycbcr_enc = V4L2_YCBCR_ENC_709; + c.xfer_func = V4L2_XFER_FUNC_709; + break; + } + break; + default: + break; + } + /* + * YCC Quantization Range signaling is more-or-less broken, + * let's just ignore this. + */ + break; + } + return c; +} +EXPORT_SYMBOL_GPL(v4l2_hdmi_rx_colorimetry); diff --git a/include/media/v4l2-dv-timings.h b/include/media/v4l2-dv-timings.h index 61a1889..835aef7 100644 --- a/include/media/v4l2-dv-timings.h +++ b/include/media/v4l2-dv-timings.h @@ -223,5 +223,26 @@ static inline bool can_reduce_fps(struct v4l2_bt_timings *bt) return false; } +/** + * struct v4l2_hdmi_rx_colorimetry - describes the HDMI colorimetry information + * @colorspace: enum v4l2_colorspace, the colorspace + * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding + * @quantization: enum v4l2_quantization, colorspace quantization + * @xfer_func: enum v4l2_xfer_func, colorspace transfer function + */ +struct v4l2_hdmi_colorimetry { + enum v4l2_colorspace colorspace; + enum v4l2_ycbcr_encoding ycbcr_enc; + enum v4l2_quantization quantization; + enum v4l2_xfer_func xfer_func; +}; + +struct hdmi_avi_infoframe; +struct hdmi_vendor_infoframe; + +struct v4l2_hdmi_colorimetry +v4l2_hdmi_rx_colorimetry(const struct hdmi_avi_infoframe *avi, + const struct hdmi_vendor_infoframe *hdmi, + unsigned int height); #endif -- 2.7.4