linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 00/12] Add HSV format
@ 2016-07-18 12:42 Ricardo Ribalda Delgado
  2016-07-18 12:42 ` [PATCH v4 01/12] [media] videodev2.h Add HSV formats Ricardo Ribalda Delgado
                   ` (11 more replies)
  0 siblings, 12 replies; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 12:42 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media
  Cc: Ricardo Ribalda Delgado

HSV formats are extremely useful for image segmentation. This set of
patches makes v4l2 aware of this kind of formats.

Vivid changes have been divided to ease the reviewing process.

We are working on patches for Gstreamer and OpenCV that will make use
of these formats.

We still need to decide if and how we will support HUE range 0-255


Changelog:
v4:  
Suggested by Hans Verkuil <hverkuil@xs4all.nl> and
- Rename YUV to YCBCR
- Fix numerical error

Suggested by Hans Verkuil <hverkuil@xs4all.nl> and
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-Implement hsv_encoding for supporting 0-255 range


v3:  
-Fix wrong handling of some YUV formats when brightness != 128

Suggested by Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-Remove unneeded empty lines on .rst file
Thanks!

Suggested by Hans Verkuil <hverkuil@xs4all.nl>
-Rebase over master and docs-next
-Introduce TPG_COLOR_ENC_LUMA for gray formats
-CodeStyle
Thanks!

v2:
Suggested by Mauro Carvalho Chehab <mchehab@osg.samsung.com>,
-Rebase on top of docs-next (port documentation to .rst)

Ricardo Ribalda Delgado (12):
  [media] videodev2.h Add HSV formats
  [media] Documentation: Add HSV format
  [media] Documentation: Add Ricardo Ribalda
  [media] vivid: Code refactor for color encoding
  [media] vivid: Add support for HSV formats
  [media] vivid: Rename variable
  [media] vivid: Introduce TPG_COLOR_ENC_LUMA
  [media] vivid: Fix YUV555 and YUV565 handling
  [media] vivid: Local optimization
  [media] videodev2.h Add HSV encoding
  [media] Documentation: Add HSV encodings
  [media] vivid: Add support for HSV encoding

 Documentation/media/uapi/v4l/hsv-formats.rst       |  19 +
 Documentation/media/uapi/v4l/pixfmt-002.rst        |  12 +-
 Documentation/media/uapi/v4l/pixfmt-003.rst        |  14 +-
 Documentation/media/uapi/v4l/pixfmt-006.rst        |  38 ++
 Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst | 159 ++++++++
 Documentation/media/uapi/v4l/pixfmt.rst            |   1 +
 Documentation/media/uapi/v4l/v4l2.rst              |   9 +
 Documentation/media/videodev2.h.rst.exceptions     |   4 +
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c      | 408 ++++++++++++++-------
 drivers/media/platform/vivid/vivid-core.h          |   3 +-
 drivers/media/platform/vivid/vivid-ctrls.c         |  25 ++
 drivers/media/platform/vivid/vivid-vid-cap.c       |  17 +-
 drivers/media/platform/vivid/vivid-vid-common.c    |  68 ++--
 drivers/media/platform/vivid/vivid-vid-out.c       |   1 +
 drivers/media/v4l2-core/v4l2-ioctl.c               |   2 +
 include/media/v4l2-tpg.h                           |  24 +-
 include/uapi/linux/videodev2.h                     |  25 +-
 17 files changed, 652 insertions(+), 177 deletions(-)
 create mode 100644 Documentation/media/uapi/v4l/hsv-formats.rst
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst

-- 
2.8.1

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v4 01/12] [media] videodev2.h Add HSV formats
  2016-07-18 12:42 [PATCH v4 00/12] Add HSV format Ricardo Ribalda Delgado
@ 2016-07-18 12:42 ` Ricardo Ribalda Delgado
  2016-07-18 12:42 ` [PATCH v4 02/12] [media] Documentation: Add HSV format Ricardo Ribalda Delgado
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 12:42 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media
  Cc: Ricardo Ribalda Delgado

These formats store the color information of the image
in a geometrical representation. The colors are mapped into a
cylinder, where the angle is the HUE, the height is the VALUE
and the distance to the center is the SATURATION. This is a very
useful format for image segmentation algorithms.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++
 include/uapi/linux/videodev2.h       | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index f899bf1c5fc0..54670cd59212 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1238,6 +1238,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 	case V4L2_PIX_FMT_TM6000:	descr = "A/V + VBI Mux Packet"; break;
 	case V4L2_PIX_FMT_CIT_YYVYUY:	descr = "GSPCA CIT YYVYUY"; break;
 	case V4L2_PIX_FMT_KONICA420:	descr = "GSPCA KONICA420"; break;
+	case V4L2_PIX_FMT_HSV24:	descr = "24-bit HSV 8-8-8"; break;
+	case V4L2_PIX_FMT_HSV32:	descr = "32-bit XHSV 8-8-8-8"; break;
 	case V4L2_SDR_FMT_CU8:		descr = "Complex U8"; break;
 	case V4L2_SDR_FMT_CU16LE:	descr = "Complex U16LE"; break;
 	case V4L2_SDR_FMT_CS8:		descr = "Complex S8"; break;
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 724f43e69d03..c7fb760386cf 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -580,6 +580,10 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_SRGGB12 v4l2_fourcc('R', 'G', '1', '2') /* 12  RGRG.. GBGB.. */
 #define V4L2_PIX_FMT_SBGGR16 v4l2_fourcc('B', 'Y', 'R', '2') /* 16  BGBG.. GRGR.. */
 
+/* HSV formats */
+#define V4L2_PIX_FMT_HSV24 v4l2_fourcc('H', 'S', 'V', '3')
+#define V4L2_PIX_FMT_HSV32 v4l2_fourcc('H', 'S', 'V', '4')
+
 /* compressed formats */
 #define V4L2_PIX_FMT_MJPEG    v4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG   */
 #define V4L2_PIX_FMT_JPEG     v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG     */
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v4 02/12] [media] Documentation: Add HSV format
  2016-07-18 12:42 [PATCH v4 00/12] Add HSV format Ricardo Ribalda Delgado
  2016-07-18 12:42 ` [PATCH v4 01/12] [media] videodev2.h Add HSV formats Ricardo Ribalda Delgado
@ 2016-07-18 12:42 ` Ricardo Ribalda Delgado
  2016-07-18 12:42 ` [PATCH v4 03/12] [media] Documentation: Add Ricardo Ribalda Ricardo Ribalda Delgado
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 12:42 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media
  Cc: Ricardo Ribalda Delgado

Describe the HSV formats

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 Documentation/media/uapi/v4l/hsv-formats.rst       |  19 +++
 Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst | 158 +++++++++++++++++++++
 Documentation/media/uapi/v4l/pixfmt.rst            |   1 +
 Documentation/media/uapi/v4l/v4l2.rst              |   5 +
 4 files changed, 183 insertions(+)
 create mode 100644 Documentation/media/uapi/v4l/hsv-formats.rst
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst

diff --git a/Documentation/media/uapi/v4l/hsv-formats.rst b/Documentation/media/uapi/v4l/hsv-formats.rst
new file mode 100644
index 000000000000..f0f2615eaa95
--- /dev/null
+++ b/Documentation/media/uapi/v4l/hsv-formats.rst
@@ -0,0 +1,19 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _hsv-formats:
+
+***********
+HSV Formats
+***********
+
+These formats store the color information of the image
+in a geometrical representation. The colors are mapped into a
+cylinder, where the angle is the HUE, the height is the VALUE
+and the distance to the center is the SATURATION. This is a very
+useful format for image segmentation algorithms.
+
+
+.. toctree::
+    :maxdepth: 1
+
+    pixfmt-packed-hsv
diff --git a/Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst b/Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst
new file mode 100644
index 000000000000..60ac821e309d
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst
@@ -0,0 +1,158 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _packed-hsv:
+
+******************
+Packed HSV formats
+******************
+
+*man Packed HSV formats(2)*
+
+Packed HSV formats
+
+
+Description
+===========
+
+The *hue* (h) is measured in degrees, one LSB represents two degrees.
+The *saturation* (s) and the *value* (v) are measured in percentage of the
+cylinder: 0 being the smallest value and 255 the maximum.
+
+
+The values are packed in 24 or 32 bit formats.
+
+
+.. flat-table:: Packed HSV Image Formats
+    :header-rows:  2
+    :stub-columns: 0
+
+    -  .. row 1
+
+       -  Identifier
+       -  Code
+       -
+       -  :cspan:`7` Byte 0 in memory
+       -
+       -  :cspan:`7` Byte 1
+       -
+       -  :cspan:`7` Byte 2
+       -
+       -  :cspan:`7` Byte 3
+
+    -  .. row 2
+
+       -
+       -
+       -  Bit
+       -  7
+       -  6
+       -  5
+       -  4
+       -  3
+       -  2
+       -  1
+       -  0
+       -
+       -  7
+       -  6
+       -  5
+       -  4
+       -  3
+       -  2
+       -  1
+       -  0
+       -
+       -  7
+       -  6
+       -  5
+       -  4
+       -  3
+       -  2
+       -  1
+       -  0
+       -
+       -  7
+       -  6
+       -  5
+       -  4
+       -  3
+       -  2
+       -  1
+       -  0
+
+    -  .. _V4L2-PIX-FMT-HSV32:
+
+       -  ``V4L2_PIX_FMT_HSV32``
+       -  'HSV4'
+       -
+       -  -
+       -  -
+       -  -
+       -  -
+       -  -
+       -  -
+       -  -
+       -  -
+       -
+       -  h\ :sub:`7`
+       -  h\ :sub:`6`
+       -  h\ :sub:`5`
+       -  h\ :sub:`4`
+       -  h\ :sub:`3`
+       -  h\ :sub:`2`
+       -  h\ :sub:`1`
+       -  h\ :sub:`0`
+       -
+       -  s\ :sub:`7`
+       -  s\ :sub:`6`
+       -  s\ :sub:`5`
+       -  s\ :sub:`4`
+       -  s\ :sub:`3`
+       -  s\ :sub:`2`
+       -  s\ :sub:`1`
+       -  s\ :sub:`0`
+       -
+       -  v\ :sub:`7`
+       -  v\ :sub:`6`
+       -  v\ :sub:`5`
+       -  v\ :sub:`4`
+       -  v\ :sub:`3`
+       -  v\ :sub:`2`
+       -  v\ :sub:`1`
+       -  v\ :sub:`0`
+
+    -  .. _V4L2-PIX-FMT-HSV24:
+
+       -  ``V4L2_PIX_FMT_HSV24``
+       -  'HSV3'
+       -
+       -  h\ :sub:`7`
+       -  h\ :sub:`6`
+       -  h\ :sub:`5`
+       -  h\ :sub:`4`
+       -  h\ :sub:`3`
+       -  h\ :sub:`2`
+       -  h\ :sub:`1`
+       -  h\ :sub:`0`
+       -
+       -  s\ :sub:`7`
+       -  s\ :sub:`6`
+       -  s\ :sub:`5`
+       -  s\ :sub:`4`
+       -  s\ :sub:`3`
+       -  s\ :sub:`2`
+       -  s\ :sub:`1`
+       -  s\ :sub:`0`
+       -
+       -  v\ :sub:`7`
+       -  v\ :sub:`6`
+       -  v\ :sub:`5`
+       -  v\ :sub:`4`
+       -  v\ :sub:`3`
+       -  v\ :sub:`2`
+       -  v\ :sub:`1`
+       -  v\ :sub:`0`
+       -
+       -
+
+Bit 7 is the most significant bit.
diff --git a/Documentation/media/uapi/v4l/pixfmt.rst b/Documentation/media/uapi/v4l/pixfmt.rst
index 81222a99f7ce..1d2270422345 100644
--- a/Documentation/media/uapi/v4l/pixfmt.rst
+++ b/Documentation/media/uapi/v4l/pixfmt.rst
@@ -29,6 +29,7 @@ see also :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>`.)
     pixfmt-indexed
     pixfmt-rgb
     yuv-formats
+    hsv-formats
     depth-formats
     pixfmt-013
     sdr-formats
diff --git a/Documentation/media/uapi/v4l/v4l2.rst b/Documentation/media/uapi/v4l/v4l2.rst
index c0859ebc88ee..6d23bc987f51 100644
--- a/Documentation/media/uapi/v4l/v4l2.rst
+++ b/Documentation/media/uapi/v4l/v4l2.rst
@@ -85,6 +85,11 @@ part can be used and distributed without restrictions.
 Revision History
 ****************
 
+:revision: 4.8 / 2016-07-15 (*rr*)
+
+Introduce HSV formats.
+
+
 :revision: 4.5 / 2015-10-29 (*rr*)
 
 Extend VIDIOC_G_EXT_CTRLS;. Replace ctrl_class with a new union with
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v4 03/12] [media] Documentation: Add Ricardo Ribalda
  2016-07-18 12:42 [PATCH v4 00/12] Add HSV format Ricardo Ribalda Delgado
  2016-07-18 12:42 ` [PATCH v4 01/12] [media] videodev2.h Add HSV formats Ricardo Ribalda Delgado
  2016-07-18 12:42 ` [PATCH v4 02/12] [media] Documentation: Add HSV format Ricardo Ribalda Delgado
@ 2016-07-18 12:42 ` Ricardo Ribalda Delgado
  2016-07-18 12:42 ` [PATCH v4 04/12] [media] vivid: Code refactor for color encoding Ricardo Ribalda Delgado
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 12:42 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media
  Cc: Ricardo Ribalda Delgado

My initials were on the Changelog, but there was no link to my name.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 Documentation/media/uapi/v4l/v4l2.rst | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/media/uapi/v4l/v4l2.rst b/Documentation/media/uapi/v4l/v4l2.rst
index 6d23bc987f51..330674a0f553 100644
--- a/Documentation/media/uapi/v4l/v4l2.rst
+++ b/Documentation/media/uapi/v4l/v4l2.rst
@@ -64,6 +64,10 @@ Authors, in alphabetical order:
 
   - SDR API.
 
+- Ribalda, Ricardo
+
+  - Introduce HSV formats and other minor changes.
+
 - Rubli, Martin
 
   - Designed and documented the VIDIOC_ENUM_FRAMESIZES and VIDIOC_ENUM_FRAMEINTERVALS ioctls.
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v4 04/12] [media] vivid: Code refactor for color encoding
  2016-07-18 12:42 [PATCH v4 00/12] Add HSV format Ricardo Ribalda Delgado
                   ` (2 preceding siblings ...)
  2016-07-18 12:42 ` [PATCH v4 03/12] [media] Documentation: Add Ricardo Ribalda Ricardo Ribalda Delgado
@ 2016-07-18 12:42 ` Ricardo Ribalda Delgado
  2016-07-18 12:42 ` [PATCH v4 05/12] [media] vivid: Add support for HSV formats Ricardo Ribalda Delgado
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 12:42 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media
  Cc: Ricardo Ribalda Delgado

Replace is_yuv with color_enc Which can be used by other
color encodings such us HSV.

This change should ease the review of the following patches.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c   | 49 +++++++++++++++--------
 drivers/media/platform/vivid/vivid-core.h       |  2 +-
 drivers/media/platform/vivid/vivid-vid-common.c | 52 ++++++++++++-------------
 include/media/v4l2-tpg.h                        |  7 +++-
 4 files changed, 66 insertions(+), 44 deletions(-)

diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
index 3ec3cebe62b9..4d0c9ab408da 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -237,13 +237,13 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
 	case V4L2_PIX_FMT_GREY:
 	case V4L2_PIX_FMT_Y16:
 	case V4L2_PIX_FMT_Y16_BE:
-		tpg->is_yuv = false;
+		tpg->color_enc = TGP_COLOR_ENC_RGB;
 		break;
 	case V4L2_PIX_FMT_YUV444:
 	case V4L2_PIX_FMT_YUV555:
 	case V4L2_PIX_FMT_YUV565:
 	case V4L2_PIX_FMT_YUV32:
-		tpg->is_yuv = true;
+		tpg->color_enc = TGP_COLOR_ENC_YCBCR;
 		break;
 	case V4L2_PIX_FMT_YUV420M:
 	case V4L2_PIX_FMT_YVU420M:
@@ -256,7 +256,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
 		tpg->hdownsampling[1] = 2;
 		tpg->hdownsampling[2] = 2;
 		tpg->planes = 3;
-		tpg->is_yuv = true;
+		tpg->color_enc = TGP_COLOR_ENC_YCBCR;
 		break;
 	case V4L2_PIX_FMT_YUV422M:
 	case V4L2_PIX_FMT_YVU422M:
@@ -268,7 +268,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
 		tpg->hdownsampling[1] = 2;
 		tpg->hdownsampling[2] = 2;
 		tpg->planes = 3;
-		tpg->is_yuv = true;
+		tpg->color_enc = TGP_COLOR_ENC_YCBCR;
 		break;
 	case V4L2_PIX_FMT_NV16M:
 	case V4L2_PIX_FMT_NV61M:
@@ -280,7 +280,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
 		tpg->hdownsampling[1] = 1;
 		tpg->hmask[1] = ~1;
 		tpg->planes = 2;
-		tpg->is_yuv = true;
+		tpg->color_enc = TGP_COLOR_ENC_YCBCR;
 		break;
 	case V4L2_PIX_FMT_NV12M:
 	case V4L2_PIX_FMT_NV21M:
@@ -292,7 +292,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
 		tpg->hdownsampling[1] = 1;
 		tpg->hmask[1] = ~1;
 		tpg->planes = 2;
-		tpg->is_yuv = true;
+		tpg->color_enc = TGP_COLOR_ENC_YCBCR;
 		break;
 	case V4L2_PIX_FMT_YUV444M:
 	case V4L2_PIX_FMT_YVU444M:
@@ -302,21 +302,21 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
 		tpg->vdownsampling[2] = 1;
 		tpg->hdownsampling[1] = 1;
 		tpg->hdownsampling[2] = 1;
-		tpg->is_yuv = true;
+		tpg->color_enc = TGP_COLOR_ENC_YCBCR;
 		break;
 	case V4L2_PIX_FMT_NV24:
 	case V4L2_PIX_FMT_NV42:
 		tpg->vdownsampling[1] = 1;
 		tpg->hdownsampling[1] = 1;
 		tpg->planes = 2;
-		tpg->is_yuv = true;
+		tpg->color_enc = TGP_COLOR_ENC_YCBCR;
 		break;
 	case V4L2_PIX_FMT_YUYV:
 	case V4L2_PIX_FMT_UYVY:
 	case V4L2_PIX_FMT_YVYU:
 	case V4L2_PIX_FMT_VYUY:
 		tpg->hmask[0] = ~1;
-		tpg->is_yuv = true;
+		tpg->color_enc = TGP_COLOR_ENC_YCBCR;
 		break;
 	default:
 		return false;
@@ -777,7 +777,8 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 	 * Remember that r, g and b are still in the 0 - 0xff0 range.
 	 */
 	if (tpg->real_rgb_range == V4L2_DV_RGB_RANGE_LIMITED &&
-	    tpg->rgb_range == V4L2_DV_RGB_RANGE_FULL && !tpg->is_yuv) {
+	    tpg->rgb_range == V4L2_DV_RGB_RANGE_FULL &&
+	    tpg->color_enc == TGP_COLOR_ENC_RGB) {
 		/*
 		 * Convert from full range (which is what r, g and b are)
 		 * to limited range (which is the 'real' RGB range), which
@@ -787,7 +788,9 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 		g = (g * 219) / 255 + (16 << 4);
 		b = (b * 219) / 255 + (16 << 4);
 	} else if (tpg->real_rgb_range != V4L2_DV_RGB_RANGE_LIMITED &&
-		   tpg->rgb_range == V4L2_DV_RGB_RANGE_LIMITED && !tpg->is_yuv) {
+		   tpg->rgb_range == V4L2_DV_RGB_RANGE_LIMITED &&
+		   tpg->color_enc == TGP_COLOR_ENC_RGB) {
+
 		/*
 		 * Clamp r, g and b to the limited range and convert to full
 		 * range since that's what we deliver.
@@ -820,7 +823,7 @@ 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->is_yuv) {
+		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);
@@ -829,7 +832,7 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 		ycbcr_to_color(tpg, y, cb, cr, &r, &g, &b);
 	}
 
-	if (tpg->is_yuv) {
+	if (tpg->color_enc == TGP_COLOR_ENC_YCBCR) {
 		/* Convert to YCbCr */
 		int y, cb, cr;
 
@@ -1842,7 +1845,8 @@ static void tpg_recalc(struct tpg_data *tpg)
 
 		if (tpg->quantization == V4L2_QUANTIZATION_DEFAULT)
 			tpg->real_quantization =
-				V4L2_MAP_QUANTIZATION_DEFAULT(!tpg->is_yuv,
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+					tpg->color_enc != TGP_COLOR_ENC_YCBCR,
 					tpg->colorspace, tpg->real_ycbcr_enc);
 
 		tpg_precalculate_colors(tpg);
@@ -1889,11 +1893,24 @@ static int tpg_pattern_avg(const struct tpg_data *tpg,
 	return -1;
 }
 
+static const char *tpg_color_enc_str(enum tgp_color_enc
+						 color_enc)
+{
+	switch (color_enc) {
+	case TGP_COLOR_ENC_YCBCR:
+		return "Y'CbCr";
+	case TGP_COLOR_ENC_RGB:
+	default:
+		return "R'G'B";
+
+	}
+}
+
 void tpg_log_status(struct tpg_data *tpg)
 {
 	pr_info("tpg source WxH: %ux%u (%s)\n",
-			tpg->src_width, tpg->src_height,
-			tpg->is_yuv ? "YCbCr" : "RGB");
+		tpg->src_width, tpg->src_height,
+		tpg_color_enc_str(tpg->color_enc));
 	pr_info("tpg field: %u\n", tpg->field);
 	pr_info("tpg crop: %ux%u@%dx%d\n", tpg->crop.width, tpg->crop.height,
 			tpg->crop.left, tpg->crop.top);
diff --git a/drivers/media/platform/vivid/vivid-core.h b/drivers/media/platform/vivid/vivid-core.h
index a7daa40d0a49..b59b49456d45 100644
--- a/drivers/media/platform/vivid/vivid-core.h
+++ b/drivers/media/platform/vivid/vivid-core.h
@@ -80,7 +80,7 @@ extern unsigned vivid_debug;
 
 struct vivid_fmt {
 	u32	fourcc;          /* v4l2 format id */
-	bool	is_yuv;
+	enum	tgp_color_enc color_enc;
 	bool	can_do_overlay;
 	u8	vdownsampling[TPG_MAX_PLANES];
 	u32	alpha_mask;
diff --git a/drivers/media/platform/vivid/vivid-vid-common.c b/drivers/media/platform/vivid/vivid-vid-common.c
index fcda3ae4e6b0..f4c35ba5f070 100644
--- a/drivers/media/platform/vivid/vivid-vid-common.c
+++ b/drivers/media/platform/vivid/vivid-vid-common.c
@@ -48,7 +48,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_YUYV,
 		.vdownsampling = { 1 },
 		.bit_depth = { 16 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 1,
 		.buffers = 1,
 		.data_offset = { PLANE0_DATA_OFFSET },
@@ -57,7 +57,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_UYVY,
 		.vdownsampling = { 1 },
 		.bit_depth = { 16 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 1,
 		.buffers = 1,
 	},
@@ -65,7 +65,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_YVYU,
 		.vdownsampling = { 1 },
 		.bit_depth = { 16 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 1,
 		.buffers = 1,
 	},
@@ -73,7 +73,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_VYUY,
 		.vdownsampling = { 1 },
 		.bit_depth = { 16 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 1,
 		.buffers = 1,
 	},
@@ -81,7 +81,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_YUV422P,
 		.vdownsampling = { 1, 1, 1 },
 		.bit_depth = { 8, 4, 4 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 3,
 		.buffers = 1,
 	},
@@ -89,7 +89,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_YUV420,
 		.vdownsampling = { 1, 2, 2 },
 		.bit_depth = { 8, 4, 4 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 3,
 		.buffers = 1,
 	},
@@ -97,7 +97,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_YVU420,
 		.vdownsampling = { 1, 2, 2 },
 		.bit_depth = { 8, 4, 4 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 3,
 		.buffers = 1,
 	},
@@ -105,7 +105,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_NV12,
 		.vdownsampling = { 1, 2 },
 		.bit_depth = { 8, 8 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 2,
 		.buffers = 1,
 	},
@@ -113,7 +113,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_NV21,
 		.vdownsampling = { 1, 2 },
 		.bit_depth = { 8, 8 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 2,
 		.buffers = 1,
 	},
@@ -121,7 +121,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_NV16,
 		.vdownsampling = { 1, 1 },
 		.bit_depth = { 8, 8 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 2,
 		.buffers = 1,
 	},
@@ -129,7 +129,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_NV61,
 		.vdownsampling = { 1, 1 },
 		.bit_depth = { 8, 8 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 2,
 		.buffers = 1,
 	},
@@ -137,7 +137,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_NV24,
 		.vdownsampling = { 1, 1 },
 		.bit_depth = { 8, 16 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 2,
 		.buffers = 1,
 	},
@@ -145,7 +145,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_NV42,
 		.vdownsampling = { 1, 1 },
 		.bit_depth = { 8, 16 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 2,
 		.buffers = 1,
 	},
@@ -184,7 +184,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_GREY,
 		.vdownsampling = { 1 },
 		.bit_depth = { 8 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 1,
 		.buffers = 1,
 	},
@@ -192,7 +192,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_Y16,
 		.vdownsampling = { 1 },
 		.bit_depth = { 16 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 1,
 		.buffers = 1,
 	},
@@ -200,7 +200,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_Y16_BE,
 		.vdownsampling = { 1 },
 		.bit_depth = { 16 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 1,
 		.buffers = 1,
 	},
@@ -452,7 +452,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_NV16M,
 		.vdownsampling = { 1, 1 },
 		.bit_depth = { 8, 8 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 2,
 		.buffers = 2,
 		.data_offset = { PLANE0_DATA_OFFSET, 0 },
@@ -461,7 +461,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_NV61M,
 		.vdownsampling = { 1, 1 },
 		.bit_depth = { 8, 8 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 2,
 		.buffers = 2,
 		.data_offset = { 0, PLANE0_DATA_OFFSET },
@@ -470,7 +470,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_YUV420M,
 		.vdownsampling = { 1, 2, 2 },
 		.bit_depth = { 8, 4, 4 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 3,
 		.buffers = 3,
 	},
@@ -478,7 +478,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_YVU420M,
 		.vdownsampling = { 1, 2, 2 },
 		.bit_depth = { 8, 4, 4 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 3,
 		.buffers = 3,
 	},
@@ -486,7 +486,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_NV12M,
 		.vdownsampling = { 1, 2 },
 		.bit_depth = { 8, 8 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 2,
 		.buffers = 2,
 	},
@@ -494,7 +494,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_NV21M,
 		.vdownsampling = { 1, 2 },
 		.bit_depth = { 8, 8 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 2,
 		.buffers = 2,
 	},
@@ -502,7 +502,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_YUV422M,
 		.vdownsampling = { 1, 1, 1 },
 		.bit_depth = { 8, 4, 4 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 3,
 		.buffers = 3,
 	},
@@ -510,7 +510,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_YVU422M,
 		.vdownsampling = { 1, 1, 1 },
 		.bit_depth = { 8, 4, 4 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 3,
 		.buffers = 3,
 	},
@@ -518,7 +518,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_YUV444M,
 		.vdownsampling = { 1, 1, 1 },
 		.bit_depth = { 8, 8, 8 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 3,
 		.buffers = 3,
 	},
@@ -526,7 +526,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_YVU444M,
 		.vdownsampling = { 1, 1, 1 },
 		.bit_depth = { 8, 8, 8 },
-		.is_yuv   = true,
+		.color_enc = TGP_COLOR_ENC_YCBCR,
 		.planes   = 3,
 		.buffers = 3,
 	},
diff --git a/include/media/v4l2-tpg.h b/include/media/v4l2-tpg.h
index 329bebfa930c..b4cb8f34cd87 100644
--- a/include/media/v4l2-tpg.h
+++ b/include/media/v4l2-tpg.h
@@ -87,6 +87,11 @@ enum tpg_move_mode {
 	TPG_MOVE_POS_FAST,
 };
 
+enum tgp_color_enc {
+	TGP_COLOR_ENC_RGB,
+	TGP_COLOR_ENC_YCBCR,
+};
+
 extern const char * const tpg_aspect_strings[];
 
 #define TPG_MAX_PLANES 3
@@ -119,7 +124,7 @@ struct tpg_data {
 	u8				saturation;
 	s16				hue;
 	u32				fourcc;
-	bool				is_yuv;
+	enum tgp_color_enc		color_enc;
 	u32				colorspace;
 	u32				xfer_func;
 	u32				ycbcr_enc;
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v4 05/12] [media] vivid: Add support for HSV formats
  2016-07-18 12:42 [PATCH v4 00/12] Add HSV format Ricardo Ribalda Delgado
                   ` (3 preceding siblings ...)
  2016-07-18 12:42 ` [PATCH v4 04/12] [media] vivid: Code refactor for color encoding Ricardo Ribalda Delgado
@ 2016-07-18 12:42 ` Ricardo Ribalda Delgado
  2016-07-18 12:42 ` [PATCH v4 06/12] [media] vivid: Rename variable Ricardo Ribalda Delgado
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 12:42 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media
  Cc: Ricardo Ribalda Delgado

This patch adds support for V4L2_PIX_FMT_HSV24 and V4L2_PIX_FMT_HSV32.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c   | 93 +++++++++++++++++++++++--
 drivers/media/platform/vivid/vivid-vid-common.c | 14 ++++
 include/media/v4l2-tpg.h                        |  1 +
 3 files changed, 104 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 4d0c9ab408da..ec8f887a84e5 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_enc = TGP_COLOR_ENC_YCBCR;
 		break;
+	case V4L2_PIX_FMT_HSV24:
+	case V4L2_PIX_FMT_HSV32:
+		tpg->color_enc = TGP_COLOR_ENC_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:
@@ -490,6 +496,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;
+
+	/* Value */
+	max_rgb = max3(r, g, b);
+	*v = max_rgb;
+	if (!max_rgb) {
+		*h = 0;
+		*s = 0;
+		return;
+	}
+
+	/* Saturation */
+	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;
+	}
+
+	/* Hue */
+	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 Hue */
+	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)
 {
@@ -832,7 +896,19 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 		ycbcr_to_color(tpg, y, cb, cr, &r, &g, &b);
 	}
 
-	if (tpg->color_enc == TGP_COLOR_ENC_YCBCR) {
+	switch (tpg->color_enc) {
+	case TGP_COLOR_ENC_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_ENC_YCBCR:
+	{
 		/* Convert to YCbCr */
 		int y, cb, cr;
 
@@ -866,7 +942,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_ENC_RGB:
+	{
 		if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) {
 			r = (r * 219) / 255 + (16 << 4);
 			g = (g * 219) / 255 + (16 << 4);
@@ -916,6 +995,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;
+	}
 	}
 }
 
@@ -941,8 +1022,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) {
@@ -1124,6 +1205,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;
@@ -1141,6 +1223,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:
@@ -1897,6 +1980,8 @@ static const char *tpg_color_enc_str(enum tgp_color_enc
 						 color_enc)
 {
 	switch (color_enc) {
+	case TGP_COLOR_ENC_HSV:
+		return "HSV";
 	case TGP_COLOR_ENC_YCBCR:
 		return "Y'CbCr";
 	case TGP_COLOR_ENC_RGB:
diff --git a/drivers/media/platform/vivid/vivid-vid-common.c b/drivers/media/platform/vivid/vivid-vid-common.c
index f4c35ba5f070..20822b5111b3 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 b4cb8f34cd87..4a40f9b79053 100644
--- a/include/media/v4l2-tpg.h
+++ b/include/media/v4l2-tpg.h
@@ -90,6 +90,7 @@ enum tpg_move_mode {
 enum tgp_color_enc {
 	TGP_COLOR_ENC_RGB,
 	TGP_COLOR_ENC_YCBCR,
+	TGP_COLOR_ENC_HSV,
 };
 
 extern const char * const tpg_aspect_strings[];
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v4 06/12] [media] vivid: Rename variable
  2016-07-18 12:42 [PATCH v4 00/12] Add HSV format Ricardo Ribalda Delgado
                   ` (4 preceding siblings ...)
  2016-07-18 12:42 ` [PATCH v4 05/12] [media] vivid: Add support for HSV formats Ricardo Ribalda Delgado
@ 2016-07-18 12:42 ` Ricardo Ribalda Delgado
  2016-07-18 12:42 ` [PATCH v4 07/12] [media] vivid: Introduce TPG_COLOR_ENC_LUMA Ricardo Ribalda Delgado
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 12:42 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media
  Cc: Ricardo Ribalda Delgado

r_y and g_u now also contain the H and V components on the HSV formats.
Rename the variables to reflect this.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 209 +++++++++++++-------------
 1 file changed, 105 insertions(+), 104 deletions(-)

diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
index ec8f887a84e5..da77cdd4f2e5 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -1014,7 +1014,7 @@ static void gen_twopix(struct tpg_data *tpg,
 {
 	unsigned offset = odd * tpg->twopixelsize[0] / 2;
 	u8 alpha = tpg->alpha_component;
-	u8 r_y, g_u, b_v;
+	u8 r_y_h, g_u_s, b_v;
 
 	if (tpg->alpha_red_only && color != TPG_COLOR_CSC_RED &&
 				   color != TPG_COLOR_100_RED &&
@@ -1022,161 +1022,161 @@ 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, H */
-	g_u = tpg->colors[color][1]; /* G or precalculated U, V */
+	r_y_h = tpg->colors[color][0]; /* R or precalculated Y, H */
+	g_u_s = tpg->colors[color][1]; /* G or precalculated U, V */
 	b_v = tpg->colors[color][2]; /* B or precalculated V */
 
 	switch (tpg->fourcc) {
 	case V4L2_PIX_FMT_GREY:
-		buf[0][offset] = r_y;
+		buf[0][offset] = r_y_h;
 		break;
 	case V4L2_PIX_FMT_Y16:
 		/*
-		 * Ideally both bytes should be set to r_y, but then you won't
+		 * Ideally both bytes should be set to r_y_h, but then you won't
 		 * be able to detect endian problems. So keep it 0 except for
-		 * the corner case where r_y is 0xff so white really will be
+		 * the corner case where r_y_h is 0xff so white really will be
 		 * white (0xffff).
 		 */
-		buf[0][offset] = r_y == 0xff ? r_y : 0;
-		buf[0][offset+1] = r_y;
+		buf[0][offset] = r_y_h == 0xff ? r_y_h : 0;
+		buf[0][offset+1] = r_y_h;
 		break;
 	case V4L2_PIX_FMT_Y16_BE:
 		/* See comment for V4L2_PIX_FMT_Y16 above */
-		buf[0][offset] = r_y;
-		buf[0][offset+1] = r_y == 0xff ? r_y : 0;
+		buf[0][offset] = r_y_h;
+		buf[0][offset+1] = r_y_h == 0xff ? r_y_h : 0;
 		break;
 	case V4L2_PIX_FMT_YUV422M:
 	case V4L2_PIX_FMT_YUV422P:
 	case V4L2_PIX_FMT_YUV420:
 	case V4L2_PIX_FMT_YUV420M:
-		buf[0][offset] = r_y;
+		buf[0][offset] = r_y_h;
 		if (odd) {
-			buf[1][0] = (buf[1][0] + g_u) / 2;
+			buf[1][0] = (buf[1][0] + g_u_s) / 2;
 			buf[2][0] = (buf[2][0] + b_v) / 2;
 			buf[1][1] = buf[1][0];
 			buf[2][1] = buf[2][0];
 			break;
 		}
-		buf[1][0] = g_u;
+		buf[1][0] = g_u_s;
 		buf[2][0] = b_v;
 		break;
 	case V4L2_PIX_FMT_YVU422M:
 	case V4L2_PIX_FMT_YVU420:
 	case V4L2_PIX_FMT_YVU420M:
-		buf[0][offset] = r_y;
+		buf[0][offset] = r_y_h;
 		if (odd) {
 			buf[1][0] = (buf[1][0] + b_v) / 2;
-			buf[2][0] = (buf[2][0] + g_u) / 2;
+			buf[2][0] = (buf[2][0] + g_u_s) / 2;
 			buf[1][1] = buf[1][0];
 			buf[2][1] = buf[2][0];
 			break;
 		}
 		buf[1][0] = b_v;
-		buf[2][0] = g_u;
+		buf[2][0] = g_u_s;
 		break;
 
 	case V4L2_PIX_FMT_NV12:
 	case V4L2_PIX_FMT_NV12M:
 	case V4L2_PIX_FMT_NV16:
 	case V4L2_PIX_FMT_NV16M:
-		buf[0][offset] = r_y;
+		buf[0][offset] = r_y_h;
 		if (odd) {
-			buf[1][0] = (buf[1][0] + g_u) / 2;
+			buf[1][0] = (buf[1][0] + g_u_s) / 2;
 			buf[1][1] = (buf[1][1] + b_v) / 2;
 			break;
 		}
-		buf[1][0] = g_u;
+		buf[1][0] = g_u_s;
 		buf[1][1] = b_v;
 		break;
 	case V4L2_PIX_FMT_NV21:
 	case V4L2_PIX_FMT_NV21M:
 	case V4L2_PIX_FMT_NV61:
 	case V4L2_PIX_FMT_NV61M:
-		buf[0][offset] = r_y;
+		buf[0][offset] = r_y_h;
 		if (odd) {
 			buf[1][0] = (buf[1][0] + b_v) / 2;
-			buf[1][1] = (buf[1][1] + g_u) / 2;
+			buf[1][1] = (buf[1][1] + g_u_s) / 2;
 			break;
 		}
 		buf[1][0] = b_v;
-		buf[1][1] = g_u;
+		buf[1][1] = g_u_s;
 		break;
 
 	case V4L2_PIX_FMT_YUV444M:
-		buf[0][offset] = r_y;
-		buf[1][offset] = g_u;
+		buf[0][offset] = r_y_h;
+		buf[1][offset] = g_u_s;
 		buf[2][offset] = b_v;
 		break;
 
 	case V4L2_PIX_FMT_YVU444M:
-		buf[0][offset] = r_y;
+		buf[0][offset] = r_y_h;
 		buf[1][offset] = b_v;
-		buf[2][offset] = g_u;
+		buf[2][offset] = g_u_s;
 		break;
 
 	case V4L2_PIX_FMT_NV24:
-		buf[0][offset] = r_y;
-		buf[1][2 * offset] = g_u;
+		buf[0][offset] = r_y_h;
+		buf[1][2 * offset] = g_u_s;
 		buf[1][2 * offset + 1] = b_v;
 		break;
 
 	case V4L2_PIX_FMT_NV42:
-		buf[0][offset] = r_y;
+		buf[0][offset] = r_y_h;
 		buf[1][2 * offset] = b_v;
-		buf[1][2 * offset + 1] = g_u;
+		buf[1][2 * offset + 1] = g_u_s;
 		break;
 
 	case V4L2_PIX_FMT_YUYV:
-		buf[0][offset] = r_y;
+		buf[0][offset] = r_y_h;
 		if (odd) {
-			buf[0][1] = (buf[0][1] + g_u) / 2;
+			buf[0][1] = (buf[0][1] + g_u_s) / 2;
 			buf[0][3] = (buf[0][3] + b_v) / 2;
 			break;
 		}
-		buf[0][1] = g_u;
+		buf[0][1] = g_u_s;
 		buf[0][3] = b_v;
 		break;
 	case V4L2_PIX_FMT_UYVY:
-		buf[0][offset + 1] = r_y;
+		buf[0][offset + 1] = r_y_h;
 		if (odd) {
-			buf[0][0] = (buf[0][0] + g_u) / 2;
+			buf[0][0] = (buf[0][0] + g_u_s) / 2;
 			buf[0][2] = (buf[0][2] + b_v) / 2;
 			break;
 		}
-		buf[0][0] = g_u;
+		buf[0][0] = g_u_s;
 		buf[0][2] = b_v;
 		break;
 	case V4L2_PIX_FMT_YVYU:
-		buf[0][offset] = r_y;
+		buf[0][offset] = r_y_h;
 		if (odd) {
 			buf[0][1] = (buf[0][1] + b_v) / 2;
-			buf[0][3] = (buf[0][3] + g_u) / 2;
+			buf[0][3] = (buf[0][3] + g_u_s) / 2;
 			break;
 		}
 		buf[0][1] = b_v;
-		buf[0][3] = g_u;
+		buf[0][3] = g_u_s;
 		break;
 	case V4L2_PIX_FMT_VYUY:
-		buf[0][offset + 1] = r_y;
+		buf[0][offset + 1] = r_y_h;
 		if (odd) {
 			buf[0][0] = (buf[0][0] + b_v) / 2;
-			buf[0][2] = (buf[0][2] + g_u) / 2;
+			buf[0][2] = (buf[0][2] + g_u_s) / 2;
 			break;
 		}
 		buf[0][0] = b_v;
-		buf[0][2] = g_u;
+		buf[0][2] = g_u_s;
 		break;
 	case V4L2_PIX_FMT_RGB332:
-		buf[0][offset] = (r_y << 5) | (g_u << 2) | b_v;
+		buf[0][offset] = (r_y_h << 5) | (g_u_s << 2) | b_v;
 		break;
 	case V4L2_PIX_FMT_YUV565:
 	case V4L2_PIX_FMT_RGB565:
-		buf[0][offset] = (g_u << 5) | b_v;
-		buf[0][offset + 1] = (r_y << 3) | (g_u >> 3);
+		buf[0][offset] = (g_u_s << 5) | b_v;
+		buf[0][offset + 1] = (r_y_h << 3) | (g_u_s >> 3);
 		break;
 	case V4L2_PIX_FMT_RGB565X:
-		buf[0][offset] = (r_y << 3) | (g_u >> 3);
-		buf[0][offset + 1] = (g_u << 5) | b_v;
+		buf[0][offset] = (r_y_h << 3) | (g_u_s >> 3);
+		buf[0][offset + 1] = (g_u_s << 5) | b_v;
 		break;
 	case V4L2_PIX_FMT_RGB444:
 	case V4L2_PIX_FMT_XRGB444:
@@ -1184,8 +1184,8 @@ static void gen_twopix(struct tpg_data *tpg,
 		/* fall through */
 	case V4L2_PIX_FMT_YUV444:
 	case V4L2_PIX_FMT_ARGB444:
-		buf[0][offset] = (g_u << 4) | b_v;
-		buf[0][offset + 1] = (alpha & 0xf0) | r_y;
+		buf[0][offset] = (g_u_s << 4) | b_v;
+		buf[0][offset + 1] = (alpha & 0xf0) | r_y_h;
 		break;
 	case V4L2_PIX_FMT_RGB555:
 	case V4L2_PIX_FMT_XRGB555:
@@ -1193,32 +1193,33 @@ static void gen_twopix(struct tpg_data *tpg,
 		/* fall through */
 	case V4L2_PIX_FMT_YUV555:
 	case V4L2_PIX_FMT_ARGB555:
-		buf[0][offset] = (g_u << 5) | b_v;
-		buf[0][offset + 1] = (alpha & 0x80) | (r_y << 2) | (g_u >> 3);
+		buf[0][offset] = (g_u_s << 5) | b_v;
+		buf[0][offset + 1] = (alpha & 0x80) | (r_y_h << 2)
+						    | (g_u_s >> 3);
 		break;
 	case V4L2_PIX_FMT_RGB555X:
 	case V4L2_PIX_FMT_XRGB555X:
 		alpha = 0;
 		/* fall through */
 	case V4L2_PIX_FMT_ARGB555X:
-		buf[0][offset] = (alpha & 0x80) | (r_y << 2) | (g_u >> 3);
-		buf[0][offset + 1] = (g_u << 5) | b_v;
+		buf[0][offset] = (alpha & 0x80) | (r_y_h << 2) | (g_u_s >> 3);
+		buf[0][offset + 1] = (g_u_s << 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] = r_y_h;
+		buf[0][offset + 1] = g_u_s;
 		buf[0][offset + 2] = b_v;
 		break;
 	case V4L2_PIX_FMT_BGR24:
 		buf[0][offset] = b_v;
-		buf[0][offset + 1] = g_u;
-		buf[0][offset + 2] = r_y;
+		buf[0][offset + 1] = g_u_s;
+		buf[0][offset + 2] = r_y_h;
 		break;
 	case V4L2_PIX_FMT_BGR666:
-		buf[0][offset] = (b_v << 2) | (g_u >> 4);
-		buf[0][offset + 1] = (g_u << 4) | (r_y >> 2);
-		buf[0][offset + 2] = r_y << 6;
+		buf[0][offset] = (b_v << 2) | (g_u_s >> 4);
+		buf[0][offset + 1] = (g_u_s << 4) | (r_y_h >> 2);
+		buf[0][offset + 2] = r_y_h << 6;
 		buf[0][offset + 3] = 0;
 		break;
 	case V4L2_PIX_FMT_RGB32:
@@ -1229,8 +1230,8 @@ static void gen_twopix(struct tpg_data *tpg,
 	case V4L2_PIX_FMT_YUV32:
 	case V4L2_PIX_FMT_ARGB32:
 		buf[0][offset] = alpha;
-		buf[0][offset + 1] = r_y;
-		buf[0][offset + 2] = g_u;
+		buf[0][offset + 1] = r_y_h;
+		buf[0][offset + 2] = g_u_s;
 		buf[0][offset + 3] = b_v;
 		break;
 	case V4L2_PIX_FMT_BGR32:
@@ -1239,87 +1240,87 @@ static void gen_twopix(struct tpg_data *tpg,
 		/* fall through */
 	case V4L2_PIX_FMT_ABGR32:
 		buf[0][offset] = b_v;
-		buf[0][offset + 1] = g_u;
-		buf[0][offset + 2] = r_y;
+		buf[0][offset + 1] = g_u_s;
+		buf[0][offset + 2] = r_y_h;
 		buf[0][offset + 3] = alpha;
 		break;
 	case V4L2_PIX_FMT_SBGGR8:
-		buf[0][offset] = odd ? g_u : b_v;
-		buf[1][offset] = odd ? r_y : g_u;
+		buf[0][offset] = odd ? g_u_s : b_v;
+		buf[1][offset] = odd ? r_y_h : g_u_s;
 		break;
 	case V4L2_PIX_FMT_SGBRG8:
-		buf[0][offset] = odd ? b_v : g_u;
-		buf[1][offset] = odd ? g_u : r_y;
+		buf[0][offset] = odd ? b_v : g_u_s;
+		buf[1][offset] = odd ? g_u_s : r_y_h;
 		break;
 	case V4L2_PIX_FMT_SGRBG8:
-		buf[0][offset] = odd ? r_y : g_u;
-		buf[1][offset] = odd ? g_u : b_v;
+		buf[0][offset] = odd ? r_y_h : g_u_s;
+		buf[1][offset] = odd ? g_u_s : b_v;
 		break;
 	case V4L2_PIX_FMT_SRGGB8:
-		buf[0][offset] = odd ? g_u : r_y;
-		buf[1][offset] = odd ? b_v : g_u;
+		buf[0][offset] = odd ? g_u_s : r_y_h;
+		buf[1][offset] = odd ? b_v : g_u_s;
 		break;
 	case V4L2_PIX_FMT_SBGGR10:
-		buf[0][offset] = odd ? g_u << 2 : b_v << 2;
-		buf[0][offset + 1] = odd ? g_u >> 6 : b_v >> 6;
-		buf[1][offset] = odd ? r_y << 2 : g_u << 2;
-		buf[1][offset + 1] = odd ? r_y >> 6 : g_u >> 6;
+		buf[0][offset] = odd ? g_u_s << 2 : b_v << 2;
+		buf[0][offset + 1] = odd ? g_u_s >> 6 : b_v >> 6;
+		buf[1][offset] = odd ? r_y_h << 2 : g_u_s << 2;
+		buf[1][offset + 1] = odd ? r_y_h >> 6 : g_u_s >> 6;
 		buf[0][offset] |= (buf[0][offset] >> 2) & 3;
 		buf[1][offset] |= (buf[1][offset] >> 2) & 3;
 		break;
 	case V4L2_PIX_FMT_SGBRG10:
-		buf[0][offset] = odd ? b_v << 2 : g_u << 2;
-		buf[0][offset + 1] = odd ? b_v >> 6 : g_u >> 6;
-		buf[1][offset] = odd ? g_u << 2 : r_y << 2;
-		buf[1][offset + 1] = odd ? g_u >> 6 : r_y >> 6;
+		buf[0][offset] = odd ? b_v << 2 : g_u_s << 2;
+		buf[0][offset + 1] = odd ? b_v >> 6 : g_u_s >> 6;
+		buf[1][offset] = odd ? g_u_s << 2 : r_y_h << 2;
+		buf[1][offset + 1] = odd ? g_u_s >> 6 : r_y_h >> 6;
 		buf[0][offset] |= (buf[0][offset] >> 2) & 3;
 		buf[1][offset] |= (buf[1][offset] >> 2) & 3;
 		break;
 	case V4L2_PIX_FMT_SGRBG10:
-		buf[0][offset] = odd ? r_y << 2 : g_u << 2;
-		buf[0][offset + 1] = odd ? r_y >> 6 : g_u >> 6;
-		buf[1][offset] = odd ? g_u << 2 : b_v << 2;
-		buf[1][offset + 1] = odd ? g_u >> 6 : b_v >> 6;
+		buf[0][offset] = odd ? r_y_h << 2 : g_u_s << 2;
+		buf[0][offset + 1] = odd ? r_y_h >> 6 : g_u_s >> 6;
+		buf[1][offset] = odd ? g_u_s << 2 : b_v << 2;
+		buf[1][offset + 1] = odd ? g_u_s >> 6 : b_v >> 6;
 		buf[0][offset] |= (buf[0][offset] >> 2) & 3;
 		buf[1][offset] |= (buf[1][offset] >> 2) & 3;
 		break;
 	case V4L2_PIX_FMT_SRGGB10:
-		buf[0][offset] = odd ? g_u << 2 : r_y << 2;
-		buf[0][offset + 1] = odd ? g_u >> 6 : r_y >> 6;
-		buf[1][offset] = odd ? b_v << 2 : g_u << 2;
-		buf[1][offset + 1] = odd ? b_v >> 6 : g_u >> 6;
+		buf[0][offset] = odd ? g_u_s << 2 : r_y_h << 2;
+		buf[0][offset + 1] = odd ? g_u_s >> 6 : r_y_h >> 6;
+		buf[1][offset] = odd ? b_v << 2 : g_u_s << 2;
+		buf[1][offset + 1] = odd ? b_v >> 6 : g_u_s >> 6;
 		buf[0][offset] |= (buf[0][offset] >> 2) & 3;
 		buf[1][offset] |= (buf[1][offset] >> 2) & 3;
 		break;
 	case V4L2_PIX_FMT_SBGGR12:
-		buf[0][offset] = odd ? g_u << 4 : b_v << 4;
-		buf[0][offset + 1] = odd ? g_u >> 4 : b_v >> 4;
-		buf[1][offset] = odd ? r_y << 4 : g_u << 4;
-		buf[1][offset + 1] = odd ? r_y >> 4 : g_u >> 4;
+		buf[0][offset] = odd ? g_u_s << 4 : b_v << 4;
+		buf[0][offset + 1] = odd ? g_u_s >> 4 : b_v >> 4;
+		buf[1][offset] = odd ? r_y_h << 4 : g_u_s << 4;
+		buf[1][offset + 1] = odd ? r_y_h >> 4 : g_u_s >> 4;
 		buf[0][offset] |= (buf[0][offset] >> 4) & 0xf;
 		buf[1][offset] |= (buf[1][offset] >> 4) & 0xf;
 		break;
 	case V4L2_PIX_FMT_SGBRG12:
-		buf[0][offset] = odd ? b_v << 4 : g_u << 4;
-		buf[0][offset + 1] = odd ? b_v >> 4 : g_u >> 4;
-		buf[1][offset] = odd ? g_u << 4 : r_y << 4;
-		buf[1][offset + 1] = odd ? g_u >> 4 : r_y >> 4;
+		buf[0][offset] = odd ? b_v << 4 : g_u_s << 4;
+		buf[0][offset + 1] = odd ? b_v >> 4 : g_u_s >> 4;
+		buf[1][offset] = odd ? g_u_s << 4 : r_y_h << 4;
+		buf[1][offset + 1] = odd ? g_u_s >> 4 : r_y_h >> 4;
 		buf[0][offset] |= (buf[0][offset] >> 4) & 0xf;
 		buf[1][offset] |= (buf[1][offset] >> 4) & 0xf;
 		break;
 	case V4L2_PIX_FMT_SGRBG12:
-		buf[0][offset] = odd ? r_y << 4 : g_u << 4;
-		buf[0][offset + 1] = odd ? r_y >> 4 : g_u >> 4;
-		buf[1][offset] = odd ? g_u << 4 : b_v << 4;
-		buf[1][offset + 1] = odd ? g_u >> 4 : b_v >> 4;
+		buf[0][offset] = odd ? r_y_h << 4 : g_u_s << 4;
+		buf[0][offset + 1] = odd ? r_y_h >> 4 : g_u_s >> 4;
+		buf[1][offset] = odd ? g_u_s << 4 : b_v << 4;
+		buf[1][offset + 1] = odd ? g_u_s >> 4 : b_v >> 4;
 		buf[0][offset] |= (buf[0][offset] >> 4) & 0xf;
 		buf[1][offset] |= (buf[1][offset] >> 4) & 0xf;
 		break;
 	case V4L2_PIX_FMT_SRGGB12:
-		buf[0][offset] = odd ? g_u << 4 : r_y << 4;
-		buf[0][offset + 1] = odd ? g_u >> 4 : r_y >> 4;
-		buf[1][offset] = odd ? b_v << 4 : g_u << 4;
-		buf[1][offset + 1] = odd ? b_v >> 4 : g_u >> 4;
+		buf[0][offset] = odd ? g_u_s << 4 : r_y_h << 4;
+		buf[0][offset + 1] = odd ? g_u_s >> 4 : r_y_h >> 4;
+		buf[1][offset] = odd ? b_v << 4 : g_u_s << 4;
+		buf[1][offset + 1] = odd ? b_v >> 4 : g_u_s >> 4;
 		buf[0][offset] |= (buf[0][offset] >> 4) & 0xf;
 		buf[1][offset] |= (buf[1][offset] >> 4) & 0xf;
 		break;
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v4 07/12] [media] vivid: Introduce TPG_COLOR_ENC_LUMA
  2016-07-18 12:42 [PATCH v4 00/12] Add HSV format Ricardo Ribalda Delgado
                   ` (5 preceding siblings ...)
  2016-07-18 12:42 ` [PATCH v4 06/12] [media] vivid: Rename variable Ricardo Ribalda Delgado
@ 2016-07-18 12:42 ` Ricardo Ribalda Delgado
  2016-07-18 12:42 ` [PATCH v4 08/12] [media] vivid: Fix YUV555 and YUV565 handling Ricardo Ribalda Delgado
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 12:42 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media
  Cc: Ricardo Ribalda Delgado

Simplifies handling of Gray formats.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c   | 26 +++++++++++++++++++------
 drivers/media/platform/vivid/vivid-vid-common.c |  6 +++---
 include/media/v4l2-tpg.h                        |  1 +
 3 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
index da77cdd4f2e5..41cc402ddeef 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -234,10 +234,12 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
 	case V4L2_PIX_FMT_XBGR32:
 	case V4L2_PIX_FMT_ARGB32:
 	case V4L2_PIX_FMT_ABGR32:
+		tpg->color_enc = TGP_COLOR_ENC_RGB;
+		break;
 	case V4L2_PIX_FMT_GREY:
 	case V4L2_PIX_FMT_Y16:
 	case V4L2_PIX_FMT_Y16_BE:
-		tpg->color_enc = TGP_COLOR_ENC_RGB;
+		tpg->color_enc = TGP_COLOR_ENC_LUMA;
 		break;
 	case V4L2_PIX_FMT_YUV444:
 	case V4L2_PIX_FMT_YUV555:
@@ -825,9 +827,9 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 		g <<= 4;
 		b <<= 4;
 	}
-	if (tpg->qual == TPG_QUAL_GRAY || tpg->fourcc == V4L2_PIX_FMT_GREY ||
-	    tpg->fourcc == V4L2_PIX_FMT_Y16 ||
-	    tpg->fourcc == V4L2_PIX_FMT_Y16_BE) {
+
+	if (tpg->qual == TPG_QUAL_GRAY ||
+	    tpg->color_enc ==  TGP_COLOR_ENC_LUMA) {
 		/* Rec. 709 Luma function */
 		/* (0.2126, 0.7152, 0.0722) * (255 * 256) */
 		r = g = b = (13879 * r + 46688 * g + 4713 * b) >> 16;
@@ -867,8 +869,9 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 		b = (b - (16 << 4)) * 255 / 219;
 	}
 
-	if (tpg->brightness != 128 || tpg->contrast != 128 ||
-	    tpg->saturation != 128 || tpg->hue) {
+	if ((tpg->brightness != 128 || tpg->contrast != 128 ||
+	     tpg->saturation != 128 || tpg->hue) &&
+	    tpg->color_enc != TGP_COLOR_ENC_LUMA) {
 		/* Implement these operations */
 		int y, cb, cr;
 		int tmp_cb, tmp_cr;
@@ -894,6 +897,10 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 			return;
 		}
 		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;
+		r += (tpg->brightness << 4) - (128 << 4);
 	}
 
 	switch (tpg->color_enc) {
@@ -944,6 +951,11 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 		tpg->colors[k][2] = cr;
 		break;
 	}
+	case TGP_COLOR_ENC_LUMA:
+	{
+		tpg->colors[k][0] = r >> 4;
+		break;
+	}
 	case TGP_COLOR_ENC_RGB:
 	{
 		if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) {
@@ -1985,6 +1997,8 @@ static const char *tpg_color_enc_str(enum tgp_color_enc
 		return "HSV";
 	case TGP_COLOR_ENC_YCBCR:
 		return "Y'CbCr";
+	case TGP_COLOR_ENC_LUMA:
+		return "Luma";
 	case TGP_COLOR_ENC_RGB:
 	default:
 		return "R'G'B";
diff --git a/drivers/media/platform/vivid/vivid-vid-common.c b/drivers/media/platform/vivid/vivid-vid-common.c
index 20822b5111b3..e0df44151461 100644
--- a/drivers/media/platform/vivid/vivid-vid-common.c
+++ b/drivers/media/platform/vivid/vivid-vid-common.c
@@ -184,7 +184,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_GREY,
 		.vdownsampling = { 1 },
 		.bit_depth = { 8 },
-		.color_enc = TGP_COLOR_ENC_YCBCR,
+		.color_enc = TGP_COLOR_ENC_LUMA,
 		.planes   = 1,
 		.buffers = 1,
 	},
@@ -192,7 +192,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_Y16,
 		.vdownsampling = { 1 },
 		.bit_depth = { 16 },
-		.color_enc = TGP_COLOR_ENC_YCBCR,
+		.color_enc = TGP_COLOR_ENC_LUMA,
 		.planes   = 1,
 		.buffers = 1,
 	},
@@ -200,7 +200,7 @@ struct vivid_fmt vivid_formats[] = {
 		.fourcc   = V4L2_PIX_FMT_Y16_BE,
 		.vdownsampling = { 1 },
 		.bit_depth = { 16 },
-		.color_enc = TGP_COLOR_ENC_YCBCR,
+		.color_enc = TGP_COLOR_ENC_LUMA,
 		.planes   = 1,
 		.buffers = 1,
 	},
diff --git a/include/media/v4l2-tpg.h b/include/media/v4l2-tpg.h
index 4a40f9b79053..8abed92317e8 100644
--- a/include/media/v4l2-tpg.h
+++ b/include/media/v4l2-tpg.h
@@ -91,6 +91,7 @@ enum tgp_color_enc {
 	TGP_COLOR_ENC_RGB,
 	TGP_COLOR_ENC_YCBCR,
 	TGP_COLOR_ENC_HSV,
+	TGP_COLOR_ENC_LUMA,
 };
 
 extern const char * const tpg_aspect_strings[];
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v4 08/12] [media] vivid: Fix YUV555 and YUV565 handling
  2016-07-18 12:42 [PATCH v4 00/12] Add HSV format Ricardo Ribalda Delgado
                   ` (6 preceding siblings ...)
  2016-07-18 12:42 ` [PATCH v4 07/12] [media] vivid: Introduce TPG_COLOR_ENC_LUMA Ricardo Ribalda Delgado
@ 2016-07-18 12:42 ` Ricardo Ribalda Delgado
  2016-07-18 12:42 ` [PATCH v4 09/12] [media] vivid: Local optimization Ricardo Ribalda Delgado
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 12:42 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media
  Cc: Ricardo Ribalda Delgado

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 <ricardo.ribalda@gmail.com>
---
 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);
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v4 09/12] [media] vivid: Local optimization
  2016-07-18 12:42 [PATCH v4 00/12] Add HSV format Ricardo Ribalda Delgado
                   ` (7 preceding siblings ...)
  2016-07-18 12:42 ` [PATCH v4 08/12] [media] vivid: Fix YUV555 and YUV565 handling Ricardo Ribalda Delgado
@ 2016-07-18 12:42 ` Ricardo Ribalda Delgado
  2016-07-18 13:13   ` Philipp Zabel
  2016-07-18 12:42 ` [PATCH v4 10/12] [media] videodev2.h Add HSV encoding Ricardo Ribalda Delgado
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 12:42 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media
  Cc: Ricardo Ribalda Delgado

Avoid duplicated data shifts when possible.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
index a26172575e56..7f284c591f25 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -919,13 +919,14 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 			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);
-			cb = clamp(cb, 16 << 4, 240 << 4);
-			cr = clamp(cr, 16 << 4, 240 << 4);
+			y = clamp(y >> 4, 16, 235);
+			cb = clamp(cb >> 4, 16, 240);
+			cr = clamp(cr >> 4, 16, 240);
+		} else {
+			y = clamp(y >> 4, 1, 254);
+			cb = clamp(cb >> 4, 1, 254);
+			cr = clamp(cr >> 4, 1, 254);
 		}
-		y = clamp(y >> 4, 1, 254);
-		cb = clamp(cb >> 4, 1, 254);
-		cr = clamp(cr >> 4, 1, 254);
 		switch (tpg->fourcc) {
 		case V4L2_PIX_FMT_YUV444:
 			y >>= 4;
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v4 10/12] [media] videodev2.h Add HSV encoding
  2016-07-18 12:42 [PATCH v4 00/12] Add HSV format Ricardo Ribalda Delgado
                   ` (8 preceding siblings ...)
  2016-07-18 12:42 ` [PATCH v4 09/12] [media] vivid: Local optimization Ricardo Ribalda Delgado
@ 2016-07-18 12:42 ` Ricardo Ribalda Delgado
  2016-08-12 13:56   ` Hans Verkuil
  2016-07-18 12:42 ` [PATCH v4 11/12] [media] Documentation: Add HSV encodings Ricardo Ribalda Delgado
  2016-07-18 12:42 ` [PATCH v4 12/12] [media] vivid: Add support for HSV encoding Ricardo Ribalda Delgado
  11 siblings, 1 reply; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 12:42 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media
  Cc: Ricardo Ribalda Delgado

Some hardware maps the Hue between 0 and 255 instead of 0-179. Support
this format with a new field hsv_enc.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 include/uapi/linux/videodev2.h | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index c7fb760386cf..49edc462ca8e 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -330,6 +330,15 @@ enum v4l2_ycbcr_encoding {
 	V4L2_YCBCR_ENC_SMPTE240M      = 8,
 };
 
+enum v4l2_hsv_encoding {
+
+	/* Hue mapped to 0 - 179 */
+	V4L2_HSV_ENC_180		= 16,
+
+	/* Hue mapped to 0-255 */
+	V4L2_HSV_ENC_256		= 17,
+};
+
 /*
  * Determine how YCBCR_ENC_DEFAULT should map to a proper Y'CbCr encoding.
  * This depends on the colorspace.
@@ -455,7 +464,12 @@ struct v4l2_pix_format {
 	__u32			colorspace;	/* enum v4l2_colorspace */
 	__u32			priv;		/* private data, depends on pixelformat */
 	__u32			flags;		/* format flags (V4L2_PIX_FMT_FLAG_*) */
-	__u32			ycbcr_enc;	/* enum v4l2_ycbcr_encoding */
+	union {
+		/* enum v4l2_ycbcr_encoding */
+		__u32			ycbcr_enc;
+		/* enum v4l2_hsv_encoding */
+		__u32			hsv_enc;
+	};
 	__u32			quantization;	/* enum v4l2_quantization */
 	__u32			xfer_func;	/* enum v4l2_xfer_func */
 };
@@ -1988,7 +2002,10 @@ struct v4l2_pix_format_mplane {
 	struct v4l2_plane_pix_format	plane_fmt[VIDEO_MAX_PLANES];
 	__u8				num_planes;
 	__u8				flags;
-	__u8				ycbcr_enc;
+	 union {
+		__u8				ycbcr_enc;
+		__u8				hsv_enc;
+	};
 	__u8				quantization;
 	__u8				xfer_func;
 	__u8				reserved[7];
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v4 11/12] [media] Documentation: Add HSV encodings
  2016-07-18 12:42 [PATCH v4 00/12] Add HSV format Ricardo Ribalda Delgado
                   ` (9 preceding siblings ...)
  2016-07-18 12:42 ` [PATCH v4 10/12] [media] videodev2.h Add HSV encoding Ricardo Ribalda Delgado
@ 2016-07-18 12:42 ` Ricardo Ribalda Delgado
  2016-08-12 13:51   ` Hans Verkuil
  2016-07-18 12:42 ` [PATCH v4 12/12] [media] vivid: Add support for HSV encoding Ricardo Ribalda Delgado
  11 siblings, 1 reply; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 12:42 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media
  Cc: Ricardo Ribalda Delgado

Describe the hsv_enc field and its use.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 Documentation/media/uapi/v4l/pixfmt-002.rst        | 12 ++++++-
 Documentation/media/uapi/v4l/pixfmt-003.rst        | 14 ++++++--
 Documentation/media/uapi/v4l/pixfmt-006.rst        | 38 ++++++++++++++++++++++
 Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst |  3 +-
 Documentation/media/videodev2.h.rst.exceptions     |  4 +++
 5 files changed, 67 insertions(+), 4 deletions(-)

diff --git a/Documentation/media/uapi/v4l/pixfmt-002.rst b/Documentation/media/uapi/v4l/pixfmt-002.rst
index fae9b2d40a85..9a59e87b590f 100644
--- a/Documentation/media/uapi/v4l/pixfmt-002.rst
+++ b/Documentation/media/uapi/v4l/pixfmt-002.rst
@@ -177,6 +177,16 @@ Single-planar format structure
 
     -  .. row 13
 
+       -  enum :ref:`v4l2_hsv_encoding <v4l2-hsv-encoding>`
+
+       -  ``hsv_enc``
+
+       -  This information supplements the ``colorspace`` and must be set by
+	  the driver for capture streams and by the application for output
+	  streams, see :ref:`colorspaces`.
+
+    -  .. row 14
+
        -  enum :ref:`v4l2_quantization <v4l2-quantization>`
 
        -  ``quantization``
@@ -185,7 +195,7 @@ Single-planar format structure
 	  the driver for capture streams and by the application for output
 	  streams, see :ref:`colorspaces`.
 
-    -  .. row 14
+    -  .. row 15
 
        -  enum :ref:`v4l2_xfer_func <v4l2-xfer-func>`
 
diff --git a/Documentation/media/uapi/v4l/pixfmt-003.rst b/Documentation/media/uapi/v4l/pixfmt-003.rst
index 25c54872fbe1..f212d1feaaa0 100644
--- a/Documentation/media/uapi/v4l/pixfmt-003.rst
+++ b/Documentation/media/uapi/v4l/pixfmt-003.rst
@@ -138,6 +138,16 @@ describing all planes of that format.
 
     -  .. row 10
 
+       -  enum :ref:`v4l2_hsv_encoding <v4l2-hsv-encoding>`
+
+       -  ``hsv_enc``
+
+       -  This information supplements the ``colorspace`` and must be set by
+	  the driver for capture streams and by the application for output
+	  streams, see :ref:`colorspaces`.
+
+    -  .. row 11
+
        -  enum :ref:`v4l2_quantization <v4l2-quantization>`
 
        -  ``quantization``
@@ -146,7 +156,7 @@ describing all planes of that format.
 	  the driver for capture streams and by the application for output
 	  streams, see :ref:`colorspaces`.
 
-    -  .. row 11
+    -  .. row 12
 
        -  enum :ref:`v4l2_xfer_func <v4l2-xfer-func>`
 
@@ -156,7 +166,7 @@ describing all planes of that format.
 	  the driver for capture streams and by the application for output
 	  streams, see :ref:`colorspaces`.
 
-    -  .. row 12
+    -  .. row 13
 
        -  __u8
 
diff --git a/Documentation/media/uapi/v4l/pixfmt-006.rst b/Documentation/media/uapi/v4l/pixfmt-006.rst
index 987b9a8a9eb4..ef7518077e8a 100644
--- a/Documentation/media/uapi/v4l/pixfmt-006.rst
+++ b/Documentation/media/uapi/v4l/pixfmt-006.rst
@@ -19,6 +19,15 @@ colorspace field of struct :ref:`v4l2_pix_format <v4l2-pix-format>`
 or struct :ref:`v4l2_pix_format_mplane <v4l2-pix-format-mplane>`
 needs to be filled in.
 
+.. _hsv-colorspace:
+
+On :ref:`HSV formats <hsv-formats>` the *Hue* is defined as the angle on
+the cylindrical color representation. Usually this angle is measured in
+degrees, i.e. 0-360. When we map this angle value into 8 bits, there are
+two basic ways to do it: Divide the angular value by 2 (0-179), or use the
+whole range, 0-255, dividing the angular value by 1.41. The
+`v4l2_hsv_encoding <v4l2-hsv-encoding>` field specify which encoding is used.
+
 .. note:: The default R'G'B' quantization is full range for all
    colorspaces except for BT.2020 which uses limited range R'G'B'
    quantization.
@@ -286,3 +295,32 @@ needs to be filled in.
        -  Use the limited range quantization encoding. I.e. the range [0…1]
 	  is mapped to [16…235]. Cb and Cr are mapped from [-0.5…0.5] to
 	  [16…240].
+
+
+
+.. _v4l2-hsv-encoding:
+
+.. flat-table:: V4L2 HSV Encodings
+    :header-rows:  1
+    :stub-columns: 0
+
+
+    -  .. row 1
+
+       -  Identifier
+
+       -  Details
+
+    -  .. row 2
+
+       -  ``V4L2_HSV_ENC_180``
+
+       -  For the Hue, each LSB is two degrees.
+
+    -  .. row 3
+
+       -  ``V4L2_HSV_ENC_256``
+
+       -  For the Hue, the 360 degrees are mapped into 8 bits, i.e. each
+          LSB is roughtly 1.41 degrees.
+
diff --git a/Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst b/Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst
index 60ac821e309d..c0239fd2c216 100644
--- a/Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst
+++ b/Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst
@@ -14,7 +14,8 @@ Packed HSV formats
 Description
 ===========
 
-The *hue* (h) is measured in degrees, one LSB represents two degrees.
+The *hue* (h) is measured in degrees, the equivalence between degrees and LSBs
+depends on the hsv-encoding used, see :ref:`colorspaces`.
 The *saturation* (s) and the *value* (v) are measured in percentage of the
 cylinder: 0 being the smallest value and 255 the maximum.
 
diff --git a/Documentation/media/videodev2.h.rst.exceptions b/Documentation/media/videodev2.h.rst.exceptions
index 9bb9a6cc39d8..b47fef566d5f 100644
--- a/Documentation/media/videodev2.h.rst.exceptions
+++ b/Documentation/media/videodev2.h.rst.exceptions
@@ -87,6 +87,10 @@ replace symbol V4L2_YCBCR_ENC_XV601 v4l2-ycbcr-encoding
 replace symbol V4L2_YCBCR_ENC_XV709 v4l2-ycbcr-encoding
 replace symbol V4L2_YCBCR_ENC_SMPTE240M v4l2-ycbcr-encoding
 
+# Documented enum v4l2_hsv_encoding
+replace symbol V4L2_HSV_ENC_180 v4l2-hsv-encoding
+replace symbol V4L2_HSV_ENC_256 v4l2-hsv-encoding
+
 # Documented enum v4l2_quantization
 replace symbol V4L2_QUANTIZATION_DEFAULT v4l2-quantization
 replace symbol V4L2_QUANTIZATION_FULL_RANGE v4l2-quantization
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v4 12/12] [media] vivid: Add support for HSV encoding
  2016-07-18 12:42 [PATCH v4 00/12] Add HSV format Ricardo Ribalda Delgado
                   ` (10 preceding siblings ...)
  2016-07-18 12:42 ` [PATCH v4 11/12] [media] Documentation: Add HSV encodings Ricardo Ribalda Delgado
@ 2016-07-18 12:42 ` Ricardo Ribalda Delgado
  11 siblings, 0 replies; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 12:42 UTC (permalink / raw)
  To: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media
  Cc: Ricardo Ribalda Delgado

Support HSV encoding. Most of the logic is replicated from ycbcr_enc.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c   | 25 +++++++++++++++++--------
 drivers/media/platform/vivid/vivid-core.h       |  1 +
 drivers/media/platform/vivid/vivid-ctrls.c      | 25 +++++++++++++++++++++++++
 drivers/media/platform/vivid/vivid-vid-cap.c    | 17 +++++++++++++++--
 drivers/media/platform/vivid/vivid-vid-common.c |  2 ++
 drivers/media/platform/vivid/vivid-vid-out.c    |  1 +
 include/media/v4l2-tpg.h                        | 15 +++++++++++++++
 7 files changed, 76 insertions(+), 10 deletions(-)

diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
index 7f284c591f25..2341d8ee2601 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -504,6 +504,7 @@ static void color_to_hsv(struct tpg_data *tpg, int r, int g, int b,
 	int max_rgb, min_rgb, diff_rgb;
 	int aux;
 	int third;
+	int third_size;
 
 	r >>= 4;
 	g >>= 4;
@@ -530,30 +531,36 @@ static void color_to_hsv(struct tpg_data *tpg, int r, int g, int b,
 		return;
 	}
 
+	third_size = (tpg->real_hsv_enc == V4L2_HSV_ENC_180) ? 60 : 85;
+
 	/* Hue */
 	if (max_rgb == r) {
 		aux =  g - b;
 		third = 0;
 	} else if (max_rgb == g) {
 		aux =  b - r;
-		third = 60;
+		third = third_size;
 	} else {
 		aux =  r - g;
-		third = 120;
+		third = third_size * 2;
 	}
 
-	aux *= 30;
+	aux *= third_size / 2;
 	aux += diff_rgb / 2;
 	aux /= diff_rgb;
 	aux += third;
 
 	/* Clamp Hue */
-	if (aux < 0)
-		aux += 180;
-	else if (aux > 180)
-		aux -= 180;
-	*h = aux;
+	if (tpg->real_hsv_enc == V4L2_HSV_ENC_180) {
+		if (aux < 0)
+			aux += 180;
+		else if (aux > 180)
+			aux -= 180;
+	} else {
+		aux = aux & 0xff;
+	}
 
+	*h = aux;
 }
 
 static void rgb2ycbcr(const int m[3][3], int r, int g, int b,
@@ -1927,6 +1934,7 @@ static void tpg_recalc(struct tpg_data *tpg)
 		tpg->recalc_lines = true;
 		tpg->real_xfer_func = tpg->xfer_func;
 		tpg->real_ycbcr_enc = tpg->ycbcr_enc;
+		tpg->real_hsv_enc = tpg->hsv_enc;
 		tpg->real_quantization = tpg->quantization;
 
 		if (tpg->xfer_func == V4L2_XFER_FUNC_DEFAULT)
@@ -2017,6 +2025,7 @@ void tpg_log_status(struct tpg_data *tpg)
 	pr_info("tpg colorspace: %d\n", tpg->colorspace);
 	pr_info("tpg transfer function: %d/%d\n", tpg->xfer_func, tpg->real_xfer_func);
 	pr_info("tpg Y'CbCr encoding: %d/%d\n", tpg->ycbcr_enc, tpg->real_ycbcr_enc);
+	pr_info("tpg HSV encoding: %d/%d\n", tpg->hsv_enc, tpg->real_hsv_enc);
 	pr_info("tpg quantization: %d/%d\n", tpg->quantization, tpg->real_quantization);
 	pr_info("tpg RGB range: %d/%d\n", tpg->rgb_range, tpg->real_rgb_range);
 }
diff --git a/drivers/media/platform/vivid/vivid-core.h b/drivers/media/platform/vivid/vivid-core.h
index b59b49456d45..5cdf95bdc4d1 100644
--- a/drivers/media/platform/vivid/vivid-core.h
+++ b/drivers/media/platform/vivid/vivid-core.h
@@ -346,6 +346,7 @@ struct vivid_dev {
 	struct v4l2_dv_timings		dv_timings_out;
 	u32				colorspace_out;
 	u32				ycbcr_enc_out;
+	u32				hsv_enc_out;
 	u32				quantization_out;
 	u32				xfer_func_out;
 	u32				service_set_out;
diff --git a/drivers/media/platform/vivid/vivid-ctrls.c b/drivers/media/platform/vivid/vivid-ctrls.c
index b98089c95ef5..2e1c0b6d6842 100644
--- a/drivers/media/platform/vivid/vivid-ctrls.c
+++ b/drivers/media/platform/vivid/vivid-ctrls.c
@@ -79,6 +79,7 @@
 #define VIVID_CID_MAX_EDID_BLOCKS	(VIVID_CID_VIVID_BASE + 40)
 #define VIVID_CID_PERCENTAGE_FILL	(VIVID_CID_VIVID_BASE + 41)
 #define VIVID_CID_REDUCED_FPS		(VIVID_CID_VIVID_BASE + 42)
+#define VIVID_CID_HSV_ENC		(VIVID_CID_VIVID_BASE + 43)
 
 #define VIVID_CID_STD_SIGNAL_MODE	(VIVID_CID_VIVID_BASE + 60)
 #define VIVID_CID_STANDARD		(VIVID_CID_VIVID_BASE + 61)
@@ -378,6 +379,14 @@ static int vivid_vid_cap_s_ctrl(struct v4l2_ctrl *ctrl)
 		vivid_send_source_change(dev, HDMI);
 		vivid_send_source_change(dev, WEBCAM);
 		break;
+	case VIVID_CID_HSV_ENC:
+		tpg_s_hsv_enc(&dev->tpg, ctrl->val ? V4L2_HSV_ENC_256 :
+						     V4L2_HSV_ENC_180);
+		vivid_send_source_change(dev, TV);
+		vivid_send_source_change(dev, SVID);
+		vivid_send_source_change(dev, HDMI);
+		vivid_send_source_change(dev, WEBCAM);
+		break;
 	case VIVID_CID_QUANTIZATION:
 		tpg_s_quantization(&dev->tpg, ctrl->val);
 		vivid_send_source_change(dev, TV);
@@ -777,6 +786,21 @@ static const struct v4l2_ctrl_config vivid_ctrl_ycbcr_enc = {
 	.qmenu = vivid_ctrl_ycbcr_enc_strings,
 };
 
+static const char * const vivid_ctrl_hsv_enc_strings[] = {
+	"Hue 0-179",
+	"Hue 0-256",
+	NULL,
+};
+
+static const struct v4l2_ctrl_config vivid_ctrl_hsv_enc = {
+	.ops = &vivid_vid_cap_ctrl_ops,
+	.id = VIVID_CID_HSV_ENC,
+	.name = "HSV Encoding",
+	.type = V4L2_CTRL_TYPE_MENU,
+	.max = ARRAY_SIZE(vivid_ctrl_hsv_enc_strings) - 2,
+	.qmenu = vivid_ctrl_hsv_enc_strings,
+};
+
 static const char * const vivid_ctrl_quantization_strings[] = {
 	"Default",
 	"Full Range",
@@ -1453,6 +1477,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 			&vivid_ctrl_colorspace, NULL);
 		v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_xfer_func, NULL);
 		v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_ycbcr_enc, NULL);
+		v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_hsv_enc, NULL);
 		v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_quantization, NULL);
 		v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_alpha_mode, NULL);
 	}
diff --git a/drivers/media/platform/vivid/vivid-vid-cap.c b/drivers/media/platform/vivid/vivid-vid-cap.c
index d404a7ce33a4..fbe1cc8b8a95 100644
--- a/drivers/media/platform/vivid/vivid-vid-cap.c
+++ b/drivers/media/platform/vivid/vivid-vid-cap.c
@@ -510,6 +510,13 @@ static unsigned vivid_ycbcr_enc_cap(struct vivid_dev *dev)
 	return dev->ycbcr_enc_out;
 }
 
+static unsigned int vivid_hsv_enc_cap(struct vivid_dev *dev)
+{
+	if (!dev->loop_video || vivid_is_webcam(dev) || vivid_is_tv_cap(dev))
+		return tpg_g_hsv_enc(&dev->tpg);
+	return dev->hsv_enc_out;
+}
+
 static unsigned vivid_quantization_cap(struct vivid_dev *dev)
 {
 	if (!dev->loop_video || vivid_is_webcam(dev) || vivid_is_tv_cap(dev))
@@ -530,7 +537,10 @@ int vivid_g_fmt_vid_cap(struct file *file, void *priv,
 	mp->pixelformat  = dev->fmt_cap->fourcc;
 	mp->colorspace   = vivid_colorspace_cap(dev);
 	mp->xfer_func    = vivid_xfer_func_cap(dev);
-	mp->ycbcr_enc    = vivid_ycbcr_enc_cap(dev);
+	if (dev->fmt_cap->color_enc == TGP_COLOR_ENC_HSV)
+		mp->hsv_enc    = vivid_hsv_enc_cap(dev);
+	else
+		mp->ycbcr_enc    = vivid_ycbcr_enc_cap(dev);
 	mp->quantization = vivid_quantization_cap(dev);
 	mp->num_planes = dev->fmt_cap->buffers;
 	for (p = 0; p < mp->num_planes; p++) {
@@ -618,7 +628,10 @@ int vivid_try_fmt_vid_cap(struct file *file, void *priv,
 		memset(pfmt[p].reserved, 0, sizeof(pfmt[p].reserved));
 	}
 	mp->colorspace = vivid_colorspace_cap(dev);
-	mp->ycbcr_enc = vivid_ycbcr_enc_cap(dev);
+	if (fmt->color_enc == TGP_COLOR_ENC_HSV)
+		mp->hsv_enc = vivid_hsv_enc_cap(dev);
+	else
+		mp->ycbcr_enc = vivid_ycbcr_enc_cap(dev);
 	mp->xfer_func = vivid_xfer_func_cap(dev);
 	mp->quantization = vivid_quantization_cap(dev);
 	memset(mp->reserved, 0, sizeof(mp->reserved));
diff --git a/drivers/media/platform/vivid/vivid-vid-common.c b/drivers/media/platform/vivid/vivid-vid-common.c
index e0df44151461..3d003fb913ed 100644
--- a/drivers/media/platform/vivid/vivid-vid-common.c
+++ b/drivers/media/platform/vivid/vivid-vid-common.c
@@ -630,6 +630,7 @@ void fmt_sp2mp(const struct v4l2_format *sp_fmt, struct v4l2_format *mp_fmt)
 	mp->field = pix->field;
 	mp->colorspace = pix->colorspace;
 	mp->xfer_func = pix->xfer_func;
+	/* Also copies hsv_enc */
 	mp->ycbcr_enc = pix->ycbcr_enc;
 	mp->quantization = pix->quantization;
 	mp->num_planes = 1;
@@ -659,6 +660,7 @@ int fmt_sp2mp_func(struct file *file, void *priv,
 	pix->field = mp->field;
 	pix->colorspace = mp->colorspace;
 	pix->xfer_func = mp->xfer_func;
+	/* Also copies hsv_enc */
 	pix->ycbcr_enc = mp->ycbcr_enc;
 	pix->quantization = mp->quantization;
 	pix->sizeimage = ppix->sizeimage;
diff --git a/drivers/media/platform/vivid/vivid-vid-out.c b/drivers/media/platform/vivid/vivid-vid-out.c
index dd609eea4753..7ba52ee98371 100644
--- a/drivers/media/platform/vivid/vivid-vid-out.c
+++ b/drivers/media/platform/vivid/vivid-vid-out.c
@@ -256,6 +256,7 @@ void vivid_update_format_out(struct vivid_dev *dev)
 	}
 	dev->xfer_func_out = V4L2_XFER_FUNC_DEFAULT;
 	dev->ycbcr_enc_out = V4L2_YCBCR_ENC_DEFAULT;
+	dev->hsv_enc_out = V4L2_HSV_ENC_180;
 	dev->quantization_out = V4L2_QUANTIZATION_DEFAULT;
 	dev->compose_out = dev->sink_rect;
 	dev->compose_bounds_out = dev->sink_rect;
diff --git a/include/media/v4l2-tpg.h b/include/media/v4l2-tpg.h
index 8abed92317e8..13e49d85cae3 100644
--- a/include/media/v4l2-tpg.h
+++ b/include/media/v4l2-tpg.h
@@ -130,6 +130,7 @@ struct tpg_data {
 	u32				colorspace;
 	u32				xfer_func;
 	u32				ycbcr_enc;
+	u32				hsv_enc;
 	/*
 	 * Stores the actual transfer function, i.e. will never be
 	 * V4L2_XFER_FUNC_DEFAULT.
@@ -139,6 +140,7 @@ struct tpg_data {
 	 * Stores the actual Y'CbCr encoding, i.e. will never be
 	 * V4L2_YCBCR_ENC_DEFAULT.
 	 */
+	u32				real_hsv_enc;
 	u32				real_ycbcr_enc;
 	u32				quantization;
 	/*
@@ -341,6 +343,19 @@ static inline u32 tpg_g_ycbcr_enc(const struct tpg_data *tpg)
 	return tpg->ycbcr_enc;
 }
 
+static inline void tpg_s_hsv_enc(struct tpg_data *tpg, u32 hsv_enc)
+{
+	if (tpg->hsv_enc == hsv_enc)
+		return;
+	tpg->hsv_enc = hsv_enc;
+	tpg->recalc_colors = true;
+}
+
+static inline u32 tpg_g_hsv_enc(const struct tpg_data *tpg)
+{
+	return tpg->hsv_enc;
+}
+
 static inline void tpg_s_xfer_func(struct tpg_data *tpg, u32 xfer_func)
 {
 	if (tpg->xfer_func == xfer_func)
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v4 09/12] [media] vivid: Local optimization
  2016-07-18 12:42 ` [PATCH v4 09/12] [media] vivid: Local optimization Ricardo Ribalda Delgado
@ 2016-07-18 13:13   ` Philipp Zabel
  2016-07-18 13:21     ` Ricardo Ribalda Delgado
  0 siblings, 1 reply; 19+ messages in thread
From: Philipp Zabel @ 2016-07-18 13:13 UTC (permalink / raw)
  To: Ricardo Ribalda Delgado
  Cc: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Shuah Khan, linux-doc, linux-kernel,
	linux-media

Hi Ricardo,

Am Montag, den 18.07.2016, 14:42 +0200 schrieb Ricardo Ribalda Delgado:
> Avoid duplicated data shifts when possible.
> 
> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> ---
>  drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
> index a26172575e56..7f284c591f25 100644
> --- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
> +++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
> @@ -919,13 +919,14 @@ static void precalculate_color(struct tpg_data *tpg, int k)
>  			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);
> -			cb = clamp(cb, 16 << 4, 240 << 4);
> -			cr = clamp(cr, 16 << 4, 240 << 4);
> +			y = clamp(y >> 4, 16, 235);
> +			cb = clamp(cb >> 4, 16, 240);
> +			cr = clamp(cr >> 4, 16, 240);

Since the constant expressions are evaluated at compile time, you are
not actually removing shifts. The code generated for precalculate_color
by gcc 5.4 even grows by one asr instruction with this patch.

> +		} else {
> +			y = clamp(y >> 4, 1, 254);
> +			cb = clamp(cb >> 4, 1, 254);
> +			cr = clamp(cr >> 4, 1, 254);
>  		}
> -		y = clamp(y >> 4, 1, 254);
> -		cb = clamp(cb >> 4, 1, 254);
> -		cr = clamp(cr >> 4, 1, 254);
>  		switch (tpg->fourcc) {
>  		case V4L2_PIX_FMT_YUV444:
>  			y >>= 4;

regards
Philipp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4 09/12] [media] vivid: Local optimization
  2016-07-18 13:13   ` Philipp Zabel
@ 2016-07-18 13:21     ` Ricardo Ribalda Delgado
  2016-07-18 14:16       ` Philipp Zabel
  0 siblings, 1 reply; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 13:21 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Shuah Khan, linux-doc, LKML, linux-media

Hi Philipp

On Mon, Jul 18, 2016 at 3:13 PM, Philipp Zabel <p.zabel@pengutronix.de> wrote:
> Since the constant expressions are evaluated at compile time, you are
> not actually removing shifts. The code generated for precalculate_color
> by gcc 5.4 even grows by one asr instruction with this patch.
>

I dont think that I follow you completely here. The original code was

if (a)
   y= clamp(y, 16<<4, 235<<4)

y = clamp(y>>4, 1, 254)


And now is

if (a)
   y= clamp(y >>4, 16, 235)
else
    y = clamp(y, 1, 254)


On the previous case, when a was true there was 2 clamp operations.
Now it is only one.


Best regards!

-- 
Ricardo Ribalda

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4 09/12] [media] vivid: Local optimization
  2016-07-18 13:21     ` Ricardo Ribalda Delgado
@ 2016-07-18 14:16       ` Philipp Zabel
  2016-07-18 19:41         ` Ricardo Ribalda Delgado
  0 siblings, 1 reply; 19+ messages in thread
From: Philipp Zabel @ 2016-07-18 14:16 UTC (permalink / raw)
  To: Ricardo Ribalda Delgado
  Cc: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Shuah Khan, linux-doc, LKML, linux-media

Hi Ricardo,

Am Montag, den 18.07.2016, 15:21 +0200 schrieb Ricardo Ribalda Delgado:
> Hi Philipp
> 
> On Mon, Jul 18, 2016 at 3:13 PM, Philipp Zabel <p.zabel@pengutronix.de> wrote:
> > Since the constant expressions are evaluated at compile time, you are
> > not actually removing shifts. The code generated for precalculate_color
> > by gcc 5.4 even grows by one asr instruction with this patch.
> >
> 
> I dont think that I follow you completely here. The original code was

Sorry, I forgot to mention I compiled both versions for ARMv7-A, saw
that object size increased, had a look the diff between objdump -d
outputs and noticed an additional shift instruction. I have not checked
this for x86_64.

> if (a)
>    y= clamp(y, 16<<4, 235<<4)
> 
> y = clamp(y>>4, 1, 254)
>
> And now is
> 
> if (a)
>    y= clamp(y >>4, 16, 235)
> else
>     y = clamp(y, 1, 254)
     y = clamp(y >>4, 1, 254)

> On the previous case, when a was true there was 2 clamp operations.
> Now it is only one.

Yes. And now there's two shift operations (overall, still just one in
each conditional path).

It seems in my case the compiler was not clever enough to move all the
right shifts out of the conditional paths, so I ended up with one more
than before. You are right that in the limited range path the second
clamps are now avoided though. Basically, feel free to disregard my
comment.

I had the best looking result with this variant, btw:

	y >>= 4;
	cb >>= 4;
	cr >>= 4;
	if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) {
		y = clamp(y, 16, 235);
		cb = clamp(cb, 16, 240);
		cr = clamp(cr, 16, 240);
	} else {
		y = clamp(y, 1, 254);
		cb = clamp(cb, 1, 254);
		cr = clamp(cr, 1, 254);
	}

regards
Philipp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4 09/12] [media] vivid: Local optimization
  2016-07-18 14:16       ` Philipp Zabel
@ 2016-07-18 19:41         ` Ricardo Ribalda Delgado
  0 siblings, 0 replies; 19+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-07-18 19:41 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Jonathan Corbet, Mauro Carvalho Chehab, Hans Verkuil,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Shuah Khan, linux-doc, LKML, linux-media

Hi Philipp:

On Mon, Jul 18, 2016 at 4:16 PM, Philipp Zabel <p.zabel@pengutronix.de> wrote:

> I had the best looking result with this variant, btw:
>
>         y >>= 4;
>         cb >>= 4;
>         cr >>= 4;
>         if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) {
>                 y = clamp(y, 16, 235);
>                 cb = clamp(cb, 16, 240);
>                 cr = clamp(cr, 16, 240);
>         } else {
>                 y = clamp(y, 1, 254);
>                 cb = clamp(cb, 1, 254);
>                 cr = clamp(cr, 1, 254);
>         }

I like this variant much better than mine. I have applied to my local
tree. So it will be what I post on v5

Thanks for you comments :)


btw: it is scary what the compiler optimizations are capable of doing these days


-- 
Ricardo Ribalda

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4 11/12] [media] Documentation: Add HSV encodings
  2016-07-18 12:42 ` [PATCH v4 11/12] [media] Documentation: Add HSV encodings Ricardo Ribalda Delgado
@ 2016-08-12 13:51   ` Hans Verkuil
  0 siblings, 0 replies; 19+ messages in thread
From: Hans Verkuil @ 2016-08-12 13:51 UTC (permalink / raw)
  To: Ricardo Ribalda Delgado, Jonathan Corbet, Mauro Carvalho Chehab,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media

On 07/18/2016 02:42 PM, Ricardo Ribalda Delgado wrote:
> Describe the hsv_enc field and its use.
> 
> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> ---
>  Documentation/media/uapi/v4l/pixfmt-002.rst        | 12 ++++++-
>  Documentation/media/uapi/v4l/pixfmt-003.rst        | 14 ++++++--
>  Documentation/media/uapi/v4l/pixfmt-006.rst        | 38 ++++++++++++++++++++++
>  Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst |  3 +-
>  Documentation/media/videodev2.h.rst.exceptions     |  4 +++
>  5 files changed, 67 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/media/uapi/v4l/pixfmt-002.rst b/Documentation/media/uapi/v4l/pixfmt-002.rst
> index fae9b2d40a85..9a59e87b590f 100644
> --- a/Documentation/media/uapi/v4l/pixfmt-002.rst
> +++ b/Documentation/media/uapi/v4l/pixfmt-002.rst
> @@ -177,6 +177,16 @@ Single-planar format structure
>  
>      -  .. row 13
>  
> +       -  enum :ref:`v4l2_hsv_encoding <v4l2-hsv-encoding>`
> +
> +       -  ``hsv_enc``
> +
> +       -  This information supplements the ``colorspace`` and must be set by
> +	  the driver for capture streams and by the application for output
> +	  streams, see :ref:`colorspaces`.
> +
> +    -  .. row 14
> +
>         -  enum :ref:`v4l2_quantization <v4l2-quantization>`
>  
>         -  ``quantization``
> @@ -185,7 +195,7 @@ Single-planar format structure
>  	  the driver for capture streams and by the application for output
>  	  streams, see :ref:`colorspaces`.
>  
> -    -  .. row 14
> +    -  .. row 15
>  
>         -  enum :ref:`v4l2_xfer_func <v4l2-xfer-func>`
>  
> diff --git a/Documentation/media/uapi/v4l/pixfmt-003.rst b/Documentation/media/uapi/v4l/pixfmt-003.rst
> index 25c54872fbe1..f212d1feaaa0 100644
> --- a/Documentation/media/uapi/v4l/pixfmt-003.rst
> +++ b/Documentation/media/uapi/v4l/pixfmt-003.rst
> @@ -138,6 +138,16 @@ describing all planes of that format.
>  
>      -  .. row 10
>  
> +       -  enum :ref:`v4l2_hsv_encoding <v4l2-hsv-encoding>`
> +
> +       -  ``hsv_enc``
> +
> +       -  This information supplements the ``colorspace`` and must be set by
> +	  the driver for capture streams and by the application for output
> +	  streams, see :ref:`colorspaces`.
> +
> +    -  .. row 11
> +
>         -  enum :ref:`v4l2_quantization <v4l2-quantization>`
>  
>         -  ``quantization``
> @@ -146,7 +156,7 @@ describing all planes of that format.
>  	  the driver for capture streams and by the application for output
>  	  streams, see :ref:`colorspaces`.
>  
> -    -  .. row 11
> +    -  .. row 12
>  
>         -  enum :ref:`v4l2_xfer_func <v4l2-xfer-func>`
>  
> @@ -156,7 +166,7 @@ describing all planes of that format.
>  	  the driver for capture streams and by the application for output
>  	  streams, see :ref:`colorspaces`.
>  
> -    -  .. row 12
> +    -  .. row 13
>  
>         -  __u8
>  
> diff --git a/Documentation/media/uapi/v4l/pixfmt-006.rst b/Documentation/media/uapi/v4l/pixfmt-006.rst
> index 987b9a8a9eb4..ef7518077e8a 100644
> --- a/Documentation/media/uapi/v4l/pixfmt-006.rst
> +++ b/Documentation/media/uapi/v4l/pixfmt-006.rst
> @@ -19,6 +19,15 @@ colorspace field of struct :ref:`v4l2_pix_format <v4l2-pix-format>`
>  or struct :ref:`v4l2_pix_format_mplane <v4l2-pix-format-mplane>`
>  needs to be filled in.
>  
> +.. _hsv-colorspace:
> +
> +On :ref:`HSV formats <hsv-formats>` the *Hue* is defined as the angle on
> +the cylindrical color representation. Usually this angle is measured in
> +degrees, i.e. 0-360. When we map this angle value into 8 bits, there are
> +two basic ways to do it: Divide the angular value by 2 (0-179), or use the
> +whole range, 0-255, dividing the angular value by 1.41. The
> +`v4l2_hsv_encoding <v4l2-hsv-encoding>` field specify which encoding is used.
> +
>  .. note:: The default R'G'B' quantization is full range for all
>     colorspaces except for BT.2020 which uses limited range R'G'B'
>     quantization.
> @@ -286,3 +295,32 @@ needs to be filled in.
>         -  Use the limited range quantization encoding. I.e. the range [0…1]
>  	  is mapped to [16…235]. Cb and Cr are mapped from [-0.5…0.5] to
>  	  [16…240].
> +
> +
> +
> +.. _v4l2-hsv-encoding:
> +
> +.. flat-table:: V4L2 HSV Encodings
> +    :header-rows:  1
> +    :stub-columns: 0
> +
> +
> +    -  .. row 1
> +
> +       -  Identifier
> +
> +       -  Details
> +
> +    -  .. row 2
> +
> +       -  ``V4L2_HSV_ENC_180``
> +
> +       -  For the Hue, each LSB is two degrees.
> +
> +    -  .. row 3
> +
> +       -  ``V4L2_HSV_ENC_256``
> +
> +       -  For the Hue, the 360 degrees are mapped into 8 bits, i.e. each
> +          LSB is roughtly 1.41 degrees.

s/roughtly/roughtly/

> +

It is cleaner if this goes before the quantization list and after the ycbcr encoding.

The quantization description should also be updated: HSV is full range. Limited range
makes no sense for this encoding.

Regards,

	Hans

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4 10/12] [media] videodev2.h Add HSV encoding
  2016-07-18 12:42 ` [PATCH v4 10/12] [media] videodev2.h Add HSV encoding Ricardo Ribalda Delgado
@ 2016-08-12 13:56   ` Hans Verkuil
  0 siblings, 0 replies; 19+ messages in thread
From: Hans Verkuil @ 2016-08-12 13:56 UTC (permalink / raw)
  To: Ricardo Ribalda Delgado, Jonathan Corbet, Mauro Carvalho Chehab,
	Markus Heiser, Laurent Pinchart, Helen Mae Koike Fornazier,
	Antti Palosaari, Philipp Zabel, Shuah Khan, linux-doc,
	linux-kernel, linux-media

On 07/18/2016 02:42 PM, Ricardo Ribalda Delgado wrote:
> Some hardware maps the Hue between 0 and 255 instead of 0-179. Support
> this format with a new field hsv_enc.
> 
> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> ---
>  include/uapi/linux/videodev2.h | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index c7fb760386cf..49edc462ca8e 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -330,6 +330,15 @@ enum v4l2_ycbcr_encoding {
>  	V4L2_YCBCR_ENC_SMPTE240M      = 8,
>  };
>  
> +enum v4l2_hsv_encoding {
> +
> +	/* Hue mapped to 0 - 179 */
> +	V4L2_HSV_ENC_180		= 16,

The value 16 is too low. Start at 128 instead. I expect more ycbcr encodings in the future.
You might want to add a comment to indicate that these hsv_encoding values shouldn't conflict
with the ycbcr_encoding values.

The V4L2_MAP_QUANTIZATION_DEFAULT should also be updated since if it is an hsv encoding,
then the quantization should be full range.

Unfortunately, this will conflict with this pull request:

https://patchwork.linuxtv.org/patch/36348/

It might be better to wait until that is merged.

Regards,

	Hans

> +
> +	/* Hue mapped to 0-255 */
> +	V4L2_HSV_ENC_256		= 17,
> +};
> +
>  /*
>   * Determine how YCBCR_ENC_DEFAULT should map to a proper Y'CbCr encoding.
>   * This depends on the colorspace.
> @@ -455,7 +464,12 @@ struct v4l2_pix_format {
>  	__u32			colorspace;	/* enum v4l2_colorspace */
>  	__u32			priv;		/* private data, depends on pixelformat */
>  	__u32			flags;		/* format flags (V4L2_PIX_FMT_FLAG_*) */
> -	__u32			ycbcr_enc;	/* enum v4l2_ycbcr_encoding */
> +	union {
> +		/* enum v4l2_ycbcr_encoding */
> +		__u32			ycbcr_enc;
> +		/* enum v4l2_hsv_encoding */
> +		__u32			hsv_enc;
> +	};
>  	__u32			quantization;	/* enum v4l2_quantization */
>  	__u32			xfer_func;	/* enum v4l2_xfer_func */
>  };
> @@ -1988,7 +2002,10 @@ struct v4l2_pix_format_mplane {
>  	struct v4l2_plane_pix_format	plane_fmt[VIDEO_MAX_PLANES];
>  	__u8				num_planes;
>  	__u8				flags;
> -	__u8				ycbcr_enc;
> +	 union {
> +		__u8				ycbcr_enc;
> +		__u8				hsv_enc;
> +	};
>  	__u8				quantization;
>  	__u8				xfer_func;
>  	__u8				reserved[7];
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2016-08-12 13:56 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-18 12:42 [PATCH v4 00/12] Add HSV format Ricardo Ribalda Delgado
2016-07-18 12:42 ` [PATCH v4 01/12] [media] videodev2.h Add HSV formats Ricardo Ribalda Delgado
2016-07-18 12:42 ` [PATCH v4 02/12] [media] Documentation: Add HSV format Ricardo Ribalda Delgado
2016-07-18 12:42 ` [PATCH v4 03/12] [media] Documentation: Add Ricardo Ribalda Ricardo Ribalda Delgado
2016-07-18 12:42 ` [PATCH v4 04/12] [media] vivid: Code refactor for color encoding Ricardo Ribalda Delgado
2016-07-18 12:42 ` [PATCH v4 05/12] [media] vivid: Add support for HSV formats Ricardo Ribalda Delgado
2016-07-18 12:42 ` [PATCH v4 06/12] [media] vivid: Rename variable Ricardo Ribalda Delgado
2016-07-18 12:42 ` [PATCH v4 07/12] [media] vivid: Introduce TPG_COLOR_ENC_LUMA Ricardo Ribalda Delgado
2016-07-18 12:42 ` [PATCH v4 08/12] [media] vivid: Fix YUV555 and YUV565 handling Ricardo Ribalda Delgado
2016-07-18 12:42 ` [PATCH v4 09/12] [media] vivid: Local optimization Ricardo Ribalda Delgado
2016-07-18 13:13   ` Philipp Zabel
2016-07-18 13:21     ` Ricardo Ribalda Delgado
2016-07-18 14:16       ` Philipp Zabel
2016-07-18 19:41         ` Ricardo Ribalda Delgado
2016-07-18 12:42 ` [PATCH v4 10/12] [media] videodev2.h Add HSV encoding Ricardo Ribalda Delgado
2016-08-12 13:56   ` Hans Verkuil
2016-07-18 12:42 ` [PATCH v4 11/12] [media] Documentation: Add HSV encodings Ricardo Ribalda Delgado
2016-08-12 13:51   ` Hans Verkuil
2016-07-18 12:42 ` [PATCH v4 12/12] [media] vivid: Add support for HSV encoding Ricardo Ribalda Delgado

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).