Re: uvcvideo: IR camera lights only every second frame

2018-11-01 Thread Ricardo Ribalda Delgado
Hi
On Tue, Oct 30, 2018 at 4:49 PM Kieran Bingham
 wrote:
>
> Hi Jiri,
>
> On 30/10/2018 14:36, Jiri Slaby wrote:
> > Hi,
> >
> > I have a Dell Lattitude 7280 with two webcams. The standard one works
> > fine (/dev/video0). The other one is an IR camera (/dev/video1). The
> > camera proper works fine and produces 340x374 frames. But there is an IR
> > led supposed to light the object. The video is 30fps, but the LED seems
> > to emit light only on half of the frames, i.e. on every second frame (15
> > fps). This makes the video blink a lot. The two consecutive frames look
> > like:
> > https://www.fi.muni.cz/~xslaby/sklad/mpv-shot0002.jpg
> > https://www.fi.muni.cz/~xslaby/sklad/mpv-shot0003.jpg
> >
> > Do you have any ideas what to check/test?
>
> I have an HP Spectre with IR camera, and it also 'flashes' alternate frames.
>
> I assumed this was something to do with controlling the lighting for
> face recognition some how.

I think Kieran is right here. A very common way of detecting what is
close to the camera is using NIR LEDs due to how directional they are.

The algorithm is more or less:

You have a camera with a NIR filter (the rbg camera) and a camera without.

You alternate the NIR LEDs and substract both images. The results are
the object on the front.

You use that information to get what is in on the front of the RGB
camera (unaffected by the NIR leds).

Around 10 years ago we were using this approach for segmentation of
body parts. It worked like a charm for getting biometrical parameters
and detect gestures

https://repositorio.uam.es/bitstream/handle/10486/664236/biometric_morales_LNCS_2009_ps.pdf?sequence=3=y

Cheers!

>
> I'm fairly sure we don't control the 'IR flash' from the UVC.
>
> I wonder if there is a control parameter for the IR led in the
> extension-units?
>
> --
> Regards
>
> Kieran
>
>
>
> > $ v4l2-ctl  --all -d /dev/video2
> > Driver Info (not using libv4l2):
> > Driver name   : uvcvideo
> > Card type : Integrated_Webcam_HD: Integrate
> > Bus info  : usb-:00:14.0-5
> > Driver version: 4.18.15
> > Capabilities  : 0x84A1
> > Video Capture
> > Metadata Capture
> > Streaming
> > Extended Pix Format
> > Device Capabilities
> > Device Caps   : 0x0421
> > Video Capture
> > Streaming
> > Extended Pix Format
> > Priority: 2
> > Video input : 0 (Camera 11: ok)
> > Format Video Capture:
> > Width/Height  : 340/374
> > Pixel Format  : 'YUYV'
> > Field : None
> > Bytes per Line: 680
> > Size Image: 254320
> > Colorspace: sRGB
> > Transfer Function : Default (maps to sRGB)
> > YCbCr/HSV Encoding: Default (maps to ITU-R 601)
> > Quantization  : Default (maps to Limited Range)
> > Flags :
> > Crop Capability Video Capture:
> > Bounds  : Left 0, Top 0, Width 340, Height 374
> > Default : Left 0, Top 0, Width 340, Height 374
> > Pixel Aspect: 1/1
> > Selection: crop_default, Left 0, Top 0, Width 340, Height 374
> > Selection: crop_bounds, Left 0, Top 0, Width 340, Height 374
> > Streaming Parameters Video Capture:
> > Capabilities : timeperframe
> > Frames per second: 30.000 (30/1)
> > Read buffers : 0
> >
> >
> >
> >
> >
> > $ lsusb -vs 1:3
> > Bus 001 Device 003: ID 0bda:5691 Realtek Semiconductor Corp.
> > Device Descriptor:
> >   bLength18
> >   bDescriptorType 1
> >   bcdUSB   2.00
> >   bDeviceClass  239 Miscellaneous Device
> >   bDeviceSubClass 2
> >   bDeviceProtocol 1 Interface Association
> >   bMaxPacketSize064
> >   idVendor   0x0bda Realtek Semiconductor Corp.
> >   idProduct  0x5691
> >   bcdDevice   60.12
> >   iManufacturer   3 CNFGE16N5214300025C2
> >   iProduct1 Integrated_Webcam_HD
> >   iSerial 2 0001
> >   bNumConfigurations  1
> >   Configuration Descriptor:
> > bLength 9
> > bDescriptorType 2
> > wTotalLength 1041
> > bNumInterfaces  4
> > bConfigurationValue 1
> > iConfiguration  4 USB Camera
> > bmAttributes 0x80
> >   (Bus Powered)
> > MaxPower  500mA
> > ** UNRECOGNIZED:  28 ff 42 49 53 54 00 01 06 06 10 00 00 00 00 00 01
> > 07 f4 01 02 08 f4 01 03 09 f4 01 04 0a f4 01 05 0b f4 01 06 0c e8 03
> > Interface Association:
> >   bLength 8
> >   bDescriptorType11
> >   bFirstInterface 0
> >   bInterfaceCount 2
> >   bFunctionClass 14 Video
> >   bFunctionSubClass   3 Video Interface Collection
> >   bFunctionProtocol   0
> >   iFunction

[PATCH v3 1/2] [media] imx214: device tree binding

2018-10-02 Thread Ricardo Ribalda Delgado
Document bindings for imx214 camera sensor

Cc: devicet...@vger.kernel.org
Signed-off-by: Ricardo Ribalda Delgado 
---
Changelog from v2:
Laurent Pinchart:

-Spell checks
-Remove frequency
-Identation
-Data lanes order

Thanks!

 .../devicetree/bindings/media/i2c/imx214.txt  | 52 +++
 1 file changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/imx214.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/imx214.txt 
b/Documentation/devicetree/bindings/media/i2c/imx214.txt
new file mode 100644
index ..bf3cac731eca
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/imx214.txt
@@ -0,0 +1,52 @@
+* Sony 1/3.06-Inch 13.13Mp CMOS Digital Image Sensor
+
+The Sony imx214 is a 1/3.06-inch CMOS active pixel digital image sensor with
+an active array size of 4224H x 3200V. It is programmable through an I2C
+interface. The I2C address can be configured to to 0x1a or 0x10, depending on
+how the hardware is wired.
+Image data is sent through MIPI CSI-2, which is configured as 4 lanes
+at 1440 Mbps.
+
+
+Required Properties:
+- compatible: value should be "sony,imx214" for imx214 sensor
+- reg: I2C bus address of the device
+- enable-gpios: GPIO descriptor for the enable pin.
+- vdddo-supply: Chip digital IO regulator (1.8V).
+- vdda-supply: Chip analog regulator (2.7V).
+- vddd-supply: Chip digital core regulator (1.12V).
+- clocks = Reference to the xclk clock.
+- clock-names = Clock name, e.g. "xclk".
+- clock-frequency = Frequency of the xclk clock. (Currently the
+   driver only supports <2400>).
+
+Optional Properties:
+- flash-leds: See ../video-interfaces.txt
+- lens-focus: See ../video-interfaces.txt
+
+The imx274 device node should contain one 'port' child node with
+an 'endpoint' subnode. For further reading on port node refer to
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+   camera_rear@1a {
+   compatible = "sony,imx214";
+   reg = <0x1a>;
+   vdddo-supply = <_lvs1>;
+   vddd-supply = <_vddd_1v12>;
+   vdda-supply = <_l17>;
+   lens-focus = <>;
+   enable-gpios = < 25 GPIO_ACTIVE_HIGH>;
+   clocks = < CAMSS_MCLK0_CLK>;
+   clock-names = "xclk";
+   clock-frequency = <2400>;
+   port {
+   imx214_ep: endpoint {
+   clock-lanes = <0>;
+   data-lanes = <1 2 3 4>;
+   link-frequencies = /bits/ 64 <48000>;
+   remote-endpoint = <_ep>;
+   };
+   };
+   };
-- 
2.19.0



[PATCH] media: smiapp: Remove unused loop

2018-09-26 Thread Ricardo Ribalda Delgado
The loop seemed to be made to calculate max, but max is not used in that
function.

Signed-off-by: Ricardo Ribalda Delgado 
---
 drivers/media/i2c/smiapp/smiapp-core.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/media/i2c/smiapp/smiapp-core.c 
b/drivers/media/i2c/smiapp/smiapp-core.c
index 99f3b295ae3c..bccbf4c841d6 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -624,7 +624,7 @@ static int smiapp_init_late_controls(struct smiapp_sensor 
*sensor)
 {
unsigned long *valid_link_freqs = >valid_link_freqs[
sensor->csi_format->compressed - sensor->compressed_min_bpp];
-   unsigned int max, i;
+   unsigned int i;
 
for (i = 0; i < ARRAY_SIZE(sensor->test_data); i++) {
int max_value = (1 << sensor->csi_format->width) - 1;
@@ -635,8 +635,6 @@ static int smiapp_init_late_controls(struct smiapp_sensor 
*sensor)
0, max_value, 1, max_value);
}
 
-   for (max = 0; sensor->hwcfg->op_sys_clock[max + 1]; max++);
-
sensor->link_freq = v4l2_ctrl_new_int_menu(
>src->ctrl_handler, _ctrl_ops,
V4L2_CID_LINK_FREQ, __fls(*valid_link_freqs),
-- 
2.19.0



Power Management and lens-focus

2018-09-21 Thread Ricardo Ribalda Delgado
Hello

I have started using the lens-focus property:

ad5820: dac@0c {
compatible = "adi,ad5820";
reg = <0x0c>;
VANA-supply = <_l23>;
enable-gpios = < 26 GPIO_ACTIVE_HIGH>;
};

camera_rear@60 {
lens-focus = <>;
};

I was testing my device using the following setup: qv4l2 grabbing
images and yavta changing the focus controls.

Unfortunately, this does not work (or does not work as I expected):
The ad5820 is powered off until it is open() (even during streamon),
so when yavta finished setting the control and closed the device the
focus was back to its original position :S.

Apparently, this has not been an issue before because usually there is
a close loop program constantly setting up the focus and not closing
the device.

Shouldn't we poweron the focus when the pipeline is running?

Regards!



-- 
Ricardo Ribalda


[PATCH v2] libv4l: Add support for BAYER10P format conversion

2018-09-21 Thread Ricardo Ribalda Delgado
Add support for 10 bit packet Bayer formats:
-V4L2_PIX_FMT_SBGGR10P
-V4L2_PIX_FMT_SGBRG10P
-V4L2_PIX_FMT_SGRBG10P
-V4L2_PIX_FMT_SRGGB10P

These formats pack the 2 LSBs for every 4 pixels in an indeppendent
byte.

Signed-off-by: Ricardo Ribalda Delgado 
---
 lib/libv4lconvert/bayer.c  | 21 
 lib/libv4lconvert/libv4lconvert-priv.h |  4 +++
 lib/libv4lconvert/libv4lconvert.c  | 35 ++
 3 files changed, 60 insertions(+)

diff --git a/lib/libv4lconvert/bayer.c b/lib/libv4lconvert/bayer.c
index 4b70ddd9..11af6543 100644
--- a/lib/libv4lconvert/bayer.c
+++ b/lib/libv4lconvert/bayer.c
@@ -631,3 +631,24 @@ void v4lconvert_bayer_to_yuv420(const unsigned char 
*bayer, unsigned char *yuv,
v4lconvert_border_bayer_line_to_y(bayer + stride, bayer, ydst, width,
!start_with_green, !blue_line);
 }
+
+void v4lconvert_bayer10p_to_bayer8(unsigned char *bayer10p,
+   unsigned char *bayer8, int width, int height)
+{
+   unsigned long i;
+   unsigned long len = width * height;
+
+   for (i = 0; i < len ; i += 4) {
+   /*
+* Do not use a second loop, hoping that
+* a clever compiler with understand the
+* pattern and will optimize it.
+*/
+   bayer8[0] = bayer10p[0];
+   bayer8[1] = bayer10p[1];
+   bayer8[2] = bayer10p[2];
+   bayer8[3] = bayer10p[3];
+   bayer10p += 5;
+   bayer8 += 4;
+   }
+}
diff --git a/lib/libv4lconvert/libv4lconvert-priv.h 
b/lib/libv4lconvert/libv4lconvert-priv.h
index 9a467e10..3020a39e 100644
--- a/lib/libv4lconvert/libv4lconvert-priv.h
+++ b/lib/libv4lconvert/libv4lconvert-priv.h
@@ -264,6 +264,10 @@ void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,
 void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv,
int width, int height, const unsigned int stride, unsigned int 
src_pixfmt, int yvu);
 
+
+void v4lconvert_bayer10p_to_bayer8(unsigned char *bayer10p,
+   unsigned char *bayer8, int width, int height);
+
 void v4lconvert_hm12_to_rgb24(const unsigned char *src,
unsigned char *dst, int width, int height);
 
diff --git a/lib/libv4lconvert/libv4lconvert.c 
b/lib/libv4lconvert/libv4lconvert.c
index d666bd97..b3dbf5a0 100644
--- a/lib/libv4lconvert/libv4lconvert.c
+++ b/lib/libv4lconvert/libv4lconvert.c
@@ -133,6 +133,10 @@ static const struct v4lconvert_pixfmt 
supported_src_pixfmts[] = {
{ V4L2_PIX_FMT_SRGGB8,   8,  8,  8, 0 },
{ V4L2_PIX_FMT_STV0680,  8,  8,  8, 1 },
{ V4L2_PIX_FMT_SGRBG10, 16,  8,  8, 1 },
+   { V4L2_PIX_FMT_SBGGR10P,10,  8,  8, 1 },
+   { V4L2_PIX_FMT_SGBRG10P,10,  8,  8, 1 },
+   { V4L2_PIX_FMT_SGRBG10P,10,  8,  8, 1 },
+   { V4L2_PIX_FMT_SRGGB10P,10,  8,  8, 1 },
/* compressed bayer */
{ V4L2_PIX_FMT_SPCA561,  0,  9,  9, 1 },
{ V4L2_PIX_FMT_SN9C10X,  0,  9,  9, 1 },
@@ -687,6 +691,10 @@ static int v4lconvert_processing_needs_double_conversion(
case V4L2_PIX_FMT_SGBRG8:
case V4L2_PIX_FMT_SGRBG8:
case V4L2_PIX_FMT_SRGGB8:
+   case V4L2_PIX_FMT_SBGGR10P:
+   case V4L2_PIX_FMT_SGBRG10P:
+   case V4L2_PIX_FMT_SGRBG10P:
+   case V4L2_PIX_FMT_SRGGB10P:
case V4L2_PIX_FMT_STV0680:
return 0;
}
@@ -979,6 +987,33 @@ static int v4lconvert_convert_pixfmt(struct 
v4lconvert_data *data,
}
 
/* Raw bayer formats */
+   case V4L2_PIX_FMT_SBGGR10P:
+   case V4L2_PIX_FMT_SGBRG10P:
+   case V4L2_PIX_FMT_SGRBG10P:
+   case V4L2_PIX_FMT_SRGGB10P:
+   if (src_size < ((width * height * 10)/8)) {
+   V4LCONVERT_ERR("short raw bayer10 data frame\n");
+   errno = EPIPE;
+   result = -1;
+   }
+   switch (src_pix_fmt) {
+   case V4L2_PIX_FMT_SBGGR10P:
+   src_pix_fmt = V4L2_PIX_FMT_SBGGR8;
+   break;
+   case V4L2_PIX_FMT_SGBRG10P:
+   src_pix_fmt = V4L2_PIX_FMT_SGBRG8;
+   break;
+   case V4L2_PIX_FMT_SGRBG10P:
+   src_pix_fmt = V4L2_PIX_FMT_SGRBG8;
+   break;
+   case V4L2_PIX_FMT_SRGGB10P:
+   src_pix_fmt = V4L2_PIX_FMT_SRGGB8;
+   break;
+   }
+   v4lconvert_bayer10p_to_bayer8(src, src, width, height);
+   bytesperline = width;
+
+   /* Fall-through*/
case V4L2_PIX_FMT_SBGGR8:
case V4L2_PIX_FMT_SGBRG8:
case V4L2_PIX_FMT_SGRBG8:
-- 
2.18.0



Re: [PATCH] libv4l: Add support for BAYER10P format conversion

2018-09-21 Thread Ricardo Ribalda Delgado
Hi Hans

On Fri, Sep 21, 2018 at 9:38 AM Hans de Goede  wrote:
>
> Hi,
>
> On 20-09-18 22:04, Ricardo Ribalda Delgado wrote:
> > Add support for 10 bit packet Bayer formats:
> > -V4L2_PIX_FMT_SBGGR10P
> > -V4L2_PIX_FMT_SGBRG10P
> > -V4L2_PIX_FMT_SGRBG10P
> > -V4L2_PIX_FMT_SRGGB10P
> >
> > These formats pack the 2 LSBs for every 4 pixels in an indeppendent
> > byte.
> >
> > Signed-off-by: Ricardo Ribalda Delgado 
> > ---
> >   lib/libv4lconvert/bayer.c  | 15 +++
> >   lib/libv4lconvert/libv4lconvert-priv.h |  4 +++
> >   lib/libv4lconvert/libv4lconvert.c  | 35 ++
> >   3 files changed, 54 insertions(+)
> >
> > diff --git a/lib/libv4lconvert/bayer.c b/lib/libv4lconvert/bayer.c
> > index 4b70ddd9..d7d488f9 100644
> > --- a/lib/libv4lconvert/bayer.c
> > +++ b/lib/libv4lconvert/bayer.c
> > @@ -631,3 +631,18 @@ void v4lconvert_bayer_to_yuv420(const unsigned char 
> > *bayer, unsigned char *yuv,
> >   v4lconvert_border_bayer_line_to_y(bayer + stride, bayer, ydst, width,
> >   !start_with_green, !blue_line);
> >   }
> > +
> > +void v4lconvert_bayer10p_to_bayer8(unsigned char *bayer10p,
> > + unsigned char *bayer8, int width, int height)
> > +{
> > + long i, len = width * height;
> > + uint32_t *src, *dst;
> > +
> > + src = (uint32_t *)bayer10p;
> > + dst = (uint32_t *)bayer8;
> > + for (i = 0; i < len ; i += 4) {
> > + *dst = *src;
> > + dst++;
> > + src = (uint32_t *)(((uint8_t *)src) + 5);
>
> This will lead to unaligned 32 bit integer accesses which will terminate
> the program with an illegal instruction on pretty much all architectures
> except for x86.

I see your point, but I am actually using this code on ARM64 with no issues.

I will change it.

>
> You will need to copy the 4 components 1 by 1 so that you only
> use byte accesses.
>
> Also you seem to simply be throwing away the extra 2 bits, although
> that will work I wonder if that is the best we can do?

Those are the LSB. If the user want the extra resolution has to use
the bayer mode.

>
> Regards,
>
> Hans
>
>
>
> > + }
> > +}
>
>
>
> > diff --git a/lib/libv4lconvert/libv4lconvert-priv.h 
> > b/lib/libv4lconvert/libv4lconvert-priv.h
> > index 9a467e10..3020a39e 100644
> > --- a/lib/libv4lconvert/libv4lconvert-priv.h
> > +++ b/lib/libv4lconvert/libv4lconvert-priv.h
> > @@ -264,6 +264,10 @@ void v4lconvert_bayer_to_bgr24(const unsigned char 
> > *bayer,
> >   void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char 
> > *yuv,
> >   int width, int height, const unsigned int stride, unsigned 
> > int src_pixfmt, int yvu);
> >
> > +
> > +void v4lconvert_bayer10p_to_bayer8(unsigned char *bayer10p,
> > + unsigned char *bayer8, int width, int height);
> > +
> >   void v4lconvert_hm12_to_rgb24(const unsigned char *src,
> >   unsigned char *dst, int width, int height);
> >
> > diff --git a/lib/libv4lconvert/libv4lconvert.c 
> > b/lib/libv4lconvert/libv4lconvert.c
> > index d666bd97..b3dbf5a0 100644
> > --- a/lib/libv4lconvert/libv4lconvert.c
> > +++ b/lib/libv4lconvert/libv4lconvert.c
> > @@ -133,6 +133,10 @@ static const struct v4lconvert_pixfmt 
> > supported_src_pixfmts[] = {
> >   { V4L2_PIX_FMT_SRGGB8,   8,  8,  8, 0 },
> >   { V4L2_PIX_FMT_STV0680,  8,  8,  8, 1 },
> >   { V4L2_PIX_FMT_SGRBG10, 16,  8,  8, 1 },
> > + { V4L2_PIX_FMT_SBGGR10P,10,  8,  8, 1 },
> > + { V4L2_PIX_FMT_SGBRG10P,10,  8,  8, 1 },
> > + { V4L2_PIX_FMT_SGRBG10P,10,  8,  8, 1 },
> > + { V4L2_PIX_FMT_SRGGB10P,10,  8,  8, 1 },
> >   /* compressed bayer */
> >   { V4L2_PIX_FMT_SPCA561,  0,  9,  9, 1 },
> >   { V4L2_PIX_FMT_SN9C10X,  0,  9,  9, 1 },
> > @@ -687,6 +691,10 @@ static int 
> > v4lconvert_processing_needs_double_conversion(
> >   case V4L2_PIX_FMT_SGBRG8:
> >   case V4L2_PIX_FMT_SGRBG8:
> >   case V4L2_PIX_FMT_SRGGB8:
> > + case V4L2_PIX_FMT_SBGGR10P:
> > + case V4L2_PIX_FMT_SGBRG10P:
> > + case V4L2_PIX_FMT_SGRBG10P:
> > + case V4L2_PIX_FMT_SRGGB10P:
> >   case V4L2_PIX_FMT_STV0680:
> >   return 0;
> >   }
> 

Re: [PATCH v5] media: imx208: Add imx208 camera sensor driver

2018-09-20 Thread Ricardo Ribalda Delgado
HI
On Thu, Sep 20, 2018 at 11:13 PM Laurent Pinchart
 wrote:
>
> Hi Sakari,
>
> On Thursday, 20 September 2018 23:56:59 EEST Sakari Ailus wrote:
> > On Thu, Sep 20, 2018 at 05:51:55PM +0900, Tomasz Figa wrote:
> > > On Wed, Aug 8, 2018 at 4:08 PM Ping-chung Chen wrote:
> > > [snip]
> > >
> > > > +
> > > > +/* Digital gain control */
> > > > +#define IMX208_REG_GR_DIGITAL_GAIN 0x020e
> > > > +#define IMX208_REG_R_DIGITAL_GAIN  0x0210
> > > > +#define IMX208_REG_B_DIGITAL_GAIN  0x0212
> > > > +#define IMX208_REG_GB_DIGITAL_GAIN 0x0214
> > > > +#define IMX208_DGTL_GAIN_MIN   0
> > > > +#define IMX208_DGTL_GAIN_MAX   4096
> > > > +#define IMX208_DGTL_GAIN_DEFAULT   0x100
> > > > +#define IMX208_DGTL_GAIN_STEP   1
> > > > +
> > >
> > > [snip]
> > >
> > > > +/* Initialize control handlers */
> > > > +static int imx208_init_controls(struct imx208 *imx208)
> > > > +{
> > >
> > > [snip]
> > >
> > > > +   v4l2_ctrl_new_std(ctrl_hdlr, _ctrl_ops,
> > > > V4L2_CID_DIGITAL_GAIN, + IMX208_DGTL_GAIN_MIN,
> > > > IMX208_DGTL_GAIN_MAX, + IMX208_DGTL_GAIN_STEP,
> > > > + IMX208_DGTL_GAIN_DEFAULT);
> > >
> > > We have a problem here. The sensor supports only a discrete range of
> > > values here - {1, 2, 4, 8, 16} (multiplied by 256, since the value is
> > > fixed point). This makes it possible for the userspace to set values
> > > that are not allowed by the sensor specification and also leaves no
> > > way to enumerate the supported values.
> > >
> > > I can see two solutions here:
> > >
> > > 1) Define the control range from 0 to 4 and treat it as an exponent of
> > > 2, so that the value for the sensor becomes (1 << val) * 256.
> > > (Suggested by Sakari offline.)
> > >
> > > This approach has the problem of losing the original unit (and scale)
> > > of the value.
> >
> > I'd like to add that this is not a property of the proposed solution.
> >
> > Rather, the above needs to be accompanied by additional information
> > provided through VIDIOC_QUERY_EXT_CTRL, i.e. the unit, prefix as well as
> > other information such as whether the control is linear or exponential (as
> > in this case).
> >
> > > 2) Use an integer menu control, which reports only the supported
> > > discrete values - {1, 2, 4, 8, 16}.
> > >
> > > With this approach, userspace can enumerate the real gain values, but
> > > we would either need to introduce a new control (e.g.
> > > V4L2_CID_DIGITAL_GAIN_DISCRETE) or abuse the specification and
> > > register V4L2_CID_DIGITAL_GAIN as an integer menu.
> >
> > New controls in V4L2 are, for the most part, created when there's something
> > new to control. The documentation of some controls (similar to e.g. gain)
> > documents a unit as well as a prefix but that's the case only because
> > there's been no way to tell the unit or prefix otherwise in the API.
> >
> > An exception to this are EXPOSURE and EXPOSURE_ABSOLUTE. I'm not entirely
> > sure how they came to be though. An accident is a possibility as far as I
> > see.
>
> If I remember correctly I introduced the absolute variant for the UVC driver
> (even though git blame points to Brandon Philips). I don't really remember why
> though.
>
> > Controls that have a documented unit use that unit --- as long as that's
> > the unit used by the hardware. If it's not, it tends to be that another
> > unit is used but the user space has currently no way of knowing this. And
> > the digital gain control is no exception to this.
> >
> > So if we want to improve the user space's ability to be informed how the
> > control values reflect to device configuration, we do need to provide more
> > information to the user space. One way to do that would be through
> > VIDIOC_QUERY_EXT_CTRL. The IOCTL struct has plenty of reserved fields ---
> > just for purposes such as this one.
>
> I don't think we can come up with a good way to expose arbitrary mathematical
> formulas through an ioctl. In my opinion the question is how far we want to
> go, how precise we need to be.
>
> > > Any opinions or better ideas?

My 0.02 DKK.  On a similar situation, where userspace was running a
close loop calibration:

We have implemented two extra control: eposure_next exposure_pre that
tell us which one is the next value. Perhaps we could embebed such
functionality in QUERY_EXT_CTRL.

Cheers


>
> --
> Regards,
>
> Laurent Pinchart
>
>
>


-- 
Ricardo Ribalda


ad5820: Sorry for the invalid v3

2018-09-20 Thread Ricardo Ribalda Delgado
HI

Sorry, I did not check the produced files before sending them with git
send-email.  It has been a long day. Please ignore v3 and use v4.

I will write 100 times:  I will check my patches before sending them
to the mailing list

Cheers

-- 
Ricardo Ribalda


[PATCH] libv4l: Add support for BAYER10P format conversion

2018-09-20 Thread Ricardo Ribalda Delgado
Add support for 10 bit packet Bayer formats:
-V4L2_PIX_FMT_SBGGR10P
-V4L2_PIX_FMT_SGBRG10P
-V4L2_PIX_FMT_SGRBG10P
-V4L2_PIX_FMT_SRGGB10P

These formats pack the 2 LSBs for every 4 pixels in an indeppendent
byte.

Signed-off-by: Ricardo Ribalda Delgado 
---
 lib/libv4lconvert/bayer.c  | 15 +++
 lib/libv4lconvert/libv4lconvert-priv.h |  4 +++
 lib/libv4lconvert/libv4lconvert.c  | 35 ++
 3 files changed, 54 insertions(+)

diff --git a/lib/libv4lconvert/bayer.c b/lib/libv4lconvert/bayer.c
index 4b70ddd9..d7d488f9 100644
--- a/lib/libv4lconvert/bayer.c
+++ b/lib/libv4lconvert/bayer.c
@@ -631,3 +631,18 @@ void v4lconvert_bayer_to_yuv420(const unsigned char 
*bayer, unsigned char *yuv,
v4lconvert_border_bayer_line_to_y(bayer + stride, bayer, ydst, width,
!start_with_green, !blue_line);
 }
+
+void v4lconvert_bayer10p_to_bayer8(unsigned char *bayer10p,
+   unsigned char *bayer8, int width, int height)
+{
+   long i, len = width * height;
+   uint32_t *src, *dst;
+
+   src = (uint32_t *)bayer10p;
+   dst = (uint32_t *)bayer8;
+   for (i = 0; i < len ; i += 4) {
+   *dst = *src;
+   dst++;
+   src = (uint32_t *)(((uint8_t *)src) + 5);
+   }
+}
diff --git a/lib/libv4lconvert/libv4lconvert-priv.h 
b/lib/libv4lconvert/libv4lconvert-priv.h
index 9a467e10..3020a39e 100644
--- a/lib/libv4lconvert/libv4lconvert-priv.h
+++ b/lib/libv4lconvert/libv4lconvert-priv.h
@@ -264,6 +264,10 @@ void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,
 void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv,
int width, int height, const unsigned int stride, unsigned int 
src_pixfmt, int yvu);
 
+
+void v4lconvert_bayer10p_to_bayer8(unsigned char *bayer10p,
+   unsigned char *bayer8, int width, int height);
+
 void v4lconvert_hm12_to_rgb24(const unsigned char *src,
unsigned char *dst, int width, int height);
 
diff --git a/lib/libv4lconvert/libv4lconvert.c 
b/lib/libv4lconvert/libv4lconvert.c
index d666bd97..b3dbf5a0 100644
--- a/lib/libv4lconvert/libv4lconvert.c
+++ b/lib/libv4lconvert/libv4lconvert.c
@@ -133,6 +133,10 @@ static const struct v4lconvert_pixfmt 
supported_src_pixfmts[] = {
{ V4L2_PIX_FMT_SRGGB8,   8,  8,  8, 0 },
{ V4L2_PIX_FMT_STV0680,  8,  8,  8, 1 },
{ V4L2_PIX_FMT_SGRBG10, 16,  8,  8, 1 },
+   { V4L2_PIX_FMT_SBGGR10P,10,  8,  8, 1 },
+   { V4L2_PIX_FMT_SGBRG10P,10,  8,  8, 1 },
+   { V4L2_PIX_FMT_SGRBG10P,10,  8,  8, 1 },
+   { V4L2_PIX_FMT_SRGGB10P,10,  8,  8, 1 },
/* compressed bayer */
{ V4L2_PIX_FMT_SPCA561,  0,  9,  9, 1 },
{ V4L2_PIX_FMT_SN9C10X,  0,  9,  9, 1 },
@@ -687,6 +691,10 @@ static int v4lconvert_processing_needs_double_conversion(
case V4L2_PIX_FMT_SGBRG8:
case V4L2_PIX_FMT_SGRBG8:
case V4L2_PIX_FMT_SRGGB8:
+   case V4L2_PIX_FMT_SBGGR10P:
+   case V4L2_PIX_FMT_SGBRG10P:
+   case V4L2_PIX_FMT_SGRBG10P:
+   case V4L2_PIX_FMT_SRGGB10P:
case V4L2_PIX_FMT_STV0680:
return 0;
}
@@ -979,6 +987,33 @@ static int v4lconvert_convert_pixfmt(struct 
v4lconvert_data *data,
}
 
/* Raw bayer formats */
+   case V4L2_PIX_FMT_SBGGR10P:
+   case V4L2_PIX_FMT_SGBRG10P:
+   case V4L2_PIX_FMT_SGRBG10P:
+   case V4L2_PIX_FMT_SRGGB10P:
+   if (src_size < ((width * height * 10)/8)) {
+   V4LCONVERT_ERR("short raw bayer10 data frame\n");
+   errno = EPIPE;
+   result = -1;
+   }
+   switch (src_pix_fmt) {
+   case V4L2_PIX_FMT_SBGGR10P:
+   src_pix_fmt = V4L2_PIX_FMT_SBGGR8;
+   break;
+   case V4L2_PIX_FMT_SGBRG10P:
+   src_pix_fmt = V4L2_PIX_FMT_SGBRG8;
+   break;
+   case V4L2_PIX_FMT_SGRBG10P:
+   src_pix_fmt = V4L2_PIX_FMT_SGRBG8;
+   break;
+   case V4L2_PIX_FMT_SRGGB10P:
+   src_pix_fmt = V4L2_PIX_FMT_SRGGB8;
+   break;
+   }
+   v4lconvert_bayer10p_to_bayer8(src, src, width, height);
+   bytesperline = width;
+
+   /* Fall-through*/
case V4L2_PIX_FMT_SBGGR8:
case V4L2_PIX_FMT_SGBRG8:
case V4L2_PIX_FMT_SGRBG8:
-- 
2.18.0



[RFP] Media Summit: Save/Restore controls from MTD

2018-09-14 Thread Ricardo Ribalda Delgado
Industrial/Scientific sensors usually come with very extensive
calibration information such as: per column gain, list of dead/pixels,
temperature sensor offset... etc

We are saving that information on an flash device that is located by the sensor.

I would like some minutes (15 max) to show you how we are integrating
that calibration flash with v4l2-ctrl. And if this feature is useful
for someone else and upstream it.

Thanks!

-- 
Ricardo Ribalda


[PATCH v2] media: v4l2-ctrl: Fix flags field on Control events

2017-10-17 Thread Ricardo Ribalda Delgado
VIDIOC_DQEVENT and VIDIOC_QUERY_EXT_CTRL should give the same output for
the control flags field.

This patch creates a new function user_flags(), that calculates the user
exported flags value (which is different than the kernel internal flags
structure). This function is then used by all the code that exports the
internal flags to userspace.

Reported-by: Dimitrios Katsaros <patcherw...@gmail.com>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
Attention: Maybe we want to cc stable.

v2: Suggested-by Hans Verkuil <hverk...@xs4all.nl>
 -Define struct v4l2_ctrl as const
 drivers/media/v4l2-core/v4l2-ctrls.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c 
b/drivers/media/v4l2-core/v4l2-ctrls.c
index 4e53a8654690..c230bd5c6558 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -1227,6 +1227,16 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum 
v4l2_ctrl_type *type,
 }
 EXPORT_SYMBOL(v4l2_ctrl_fill);
 
+static u32 user_flags(const struct v4l2_ctrl *ctrl)
+{
+   u32 flags = ctrl->flags;
+
+   if (ctrl->is_ptr)
+   flags |= V4L2_CTRL_FLAG_HAS_PAYLOAD;
+
+   return flags;
+}
+
 static void fill_event(struct v4l2_event *ev, struct v4l2_ctrl *ctrl, u32 
changes)
 {
memset(ev->reserved, 0, sizeof(ev->reserved));
@@ -1234,7 +1244,7 @@ static void fill_event(struct v4l2_event *ev, struct 
v4l2_ctrl *ctrl, u32 change
ev->id = ctrl->id;
ev->u.ctrl.changes = changes;
ev->u.ctrl.type = ctrl->type;
-   ev->u.ctrl.flags = ctrl->flags;
+   ev->u.ctrl.flags = user_flags(ctrl);
if (ctrl->is_ptr)
ev->u.ctrl.value64 = 0;
else
@@ -2577,10 +2587,8 @@ int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, 
struct v4l2_query_ext_ctr
else
qc->id = ctrl->id;
strlcpy(qc->name, ctrl->name, sizeof(qc->name));
-   qc->flags = ctrl->flags;
+   qc->flags = user_flags(ctrl);
qc->type = ctrl->type;
-   if (ctrl->is_ptr)
-   qc->flags |= V4L2_CTRL_FLAG_HAS_PAYLOAD;
qc->elem_size = ctrl->elem_size;
qc->elems = ctrl->elems;
qc->nr_of_dims = ctrl->nr_of_dims;
-- 
2.13.2



[PATCH] media: v4l2-ctrl: Fix flags field on Control events

2017-10-17 Thread Ricardo Ribalda Delgado
VIDIOC_DQEVENT and VIDIOC_QUERY_EXT_CTRL should give the same output for
the control flags field.

This patch creates a new function user_flags(), that calculates the user
exported flags value (which is different than the kernel internal flags
structure). This function is then used by all the code that exports the
internal flags to userspace.

Reported-by: Dimitrios Katsaros <patcherw...@gmail.com>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---

Maybe we should cc stable on this one.

 drivers/media/v4l2-core/v4l2-ctrls.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c 
b/drivers/media/v4l2-core/v4l2-ctrls.c
index 4e53a8654690..751cf5746f90 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -1227,6 +1227,16 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum 
v4l2_ctrl_type *type,
 }
 EXPORT_SYMBOL(v4l2_ctrl_fill);
 
+static u32 user_flags(struct v4l2_ctrl *ctrl)
+{
+   u32 flags = ctrl->flags;
+
+   if (ctrl->is_ptr)
+   flags |= V4L2_CTRL_FLAG_HAS_PAYLOAD;
+
+   return flags;
+}
+
 static void fill_event(struct v4l2_event *ev, struct v4l2_ctrl *ctrl, u32 
changes)
 {
memset(ev->reserved, 0, sizeof(ev->reserved));
@@ -1234,7 +1244,7 @@ static void fill_event(struct v4l2_event *ev, struct 
v4l2_ctrl *ctrl, u32 change
ev->id = ctrl->id;
ev->u.ctrl.changes = changes;
ev->u.ctrl.type = ctrl->type;
-   ev->u.ctrl.flags = ctrl->flags;
+   ev->u.ctrl.flags = user_flags(ctrl);
if (ctrl->is_ptr)
ev->u.ctrl.value64 = 0;
else
@@ -2577,10 +2587,8 @@ int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, 
struct v4l2_query_ext_ctr
else
qc->id = ctrl->id;
strlcpy(qc->name, ctrl->name, sizeof(qc->name));
-   qc->flags = ctrl->flags;
+   qc->flags = user_flags(ctrl);
qc->type = ctrl->type;
-   if (ctrl->is_ptr)
-   qc->flags |= V4L2_CTRL_FLAG_HAS_PAYLOAD;
qc->elem_size = ctrl->elem_size;
qc->elems = ctrl->elems;
qc->nr_of_dims = ctrl->nr_of_dims;
-- 
2.14.2



[PATCH v2] v4l-ioctl: Fix typo on v4l_print_frmsizeenum

2017-09-13 Thread Ricardo Ribalda Delgado
max_width and max_height are swap with step_width and step_height.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---

Since that this bug has been here for ever. I do not know if we should
notify stable or not

I have also cut the lines to respect the 80 char limit

v2: Suggested by Laurent Pinchart <laurent.pinch...@ideasonboard.com>
-Fix indentation

 drivers/media/v4l2-core/v4l2-ioctl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index b60a6b0841d1..0292f327467d 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -730,9 +730,9 @@ static void v4l_print_frmsizeenum(const void *arg, bool 
write_only)
break;
case V4L2_FRMSIZE_TYPE_STEPWISE:
pr_cont(", min=%ux%u, max=%ux%u, step=%ux%u\n",
-   p->stepwise.min_width,  p->stepwise.min_height,
-   p->stepwise.step_width, p->stepwise.step_height,
-   p->stepwise.max_width,  p->stepwise.max_height);
+ p->stepwise.min_width, p->stepwise.min_height,
+ p->stepwise.max_width, p->stepwise.max_height,
+ p->stepwise.step_width, p->stepwise.step_height);
break;
case V4L2_FRMSIZE_TYPE_CONTINUOUS:
/* fall through */
-- 
2.14.1



[PATCH] v4l-ioctl: Fix typo on v4l_print_frmsizeenum

2017-09-08 Thread Ricardo Ribalda Delgado
max_width and max_height are swap with step_width and step_height.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---

Since that this bug has been here for ever. I do not know if we should
notify stable or not

I have also cut the lines to respect the 80 char limit

 drivers/media/v4l2-core/v4l2-ioctl.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index b60a6b0841d1..79614992ee21 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -730,9 +730,12 @@ static void v4l_print_frmsizeenum(const void *arg, bool 
write_only)
break;
case V4L2_FRMSIZE_TYPE_STEPWISE:
pr_cont(", min=%ux%u, max=%ux%u, step=%ux%u\n",
-   p->stepwise.min_width,  p->stepwise.min_height,
-   p->stepwise.step_width, p->stepwise.step_height,
-   p->stepwise.max_width,  p->stepwise.max_height);
+   p->stepwise.min_width,
+   p->stepwise.min_height,
+   p->stepwise.max_width,
+   p->stepwise.max_height,
+   p->stepwise.step_width,
+   p->stepwise.step_height);
break;
case V4L2_FRMSIZE_TYPE_CONTINUOUS:
/* fall through */
-- 
2.14.1



Re: [ANN] Call for topics for the media mini-summit on Friday Oct 27 in Prague

2017-09-05 Thread Ricardo Ribalda Delgado
Hi Hans

On Fri, Sep 1, 2017 at 11:46 AM, Hans Verkuil  wrote:
>
>
> Also, if you plan to attend, please let me know. It is open for all, but it is
> nice if we know beforehand who we can expect.
>

I plan to attend. I do not have any specific topic right now, but as
the date gets closer I might add something.

See you in Prague.
Thanks


[PATCH] v4l2-ctl: Show HSV encodings names

2016-11-15 Thread Ricardo Ribalda Delgado
Add HSV encoding names to v4l2-ctl. I.e.

Format Video Capture:
Width/Height  : 640/360
Pixel Format  : 'HSV3'
Field : None
Bytes per Line: 1920
Size Image: 691200
Colorspace: sRGB
Transfer Function : Default
YCbCr/HSV Encoding: Hue 0 - 179
Quantization  : Default
Flags :

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 utils/v4l2-ctl/v4l2-ctl.cpp | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/utils/v4l2-ctl/v4l2-ctl.cpp b/utils/v4l2-ctl/v4l2-ctl.cpp
index 8a2b3e6d186e..fe398233e28c 100644
--- a/utils/v4l2-ctl/v4l2-ctl.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl.cpp
@@ -451,6 +451,10 @@ static std::string ycbcr_enc2s(int val)
return "BT.2020 Constant Luminance";
case V4L2_YCBCR_ENC_SMPTE240M:
return "SMPTE 240M";
+   case V4L2_HSV_ENC_180:
+   return "Hue 0 - 179";
+   case V4L2_HSV_ENC_256:
+   return "Hue 0 - 255";
default:
return "Unknown (" + num2s(val) + ")";
}
@@ -532,7 +536,7 @@ void printfmt(const struct v4l2_format )
printf("\tSize Image: %u\n", vfmt.fmt.pix.sizeimage);
printf("\tColorspace: %s\n", 
colorspace2s(vfmt.fmt.pix.colorspace).c_str());
printf("\tTransfer Function : %s\n", 
xfer_func2s(vfmt.fmt.pix.xfer_func).c_str());
-   printf("\tYCbCr Encoding: %s\n", 
ycbcr_enc2s(vfmt.fmt.pix.ycbcr_enc).c_str());
+   printf("\tYCbCr/HSV Encoding: %s\n", 
ycbcr_enc2s(vfmt.fmt.pix.ycbcr_enc).c_str());
printf("\tQuantization  : %s\n", 
quantization2s(vfmt.fmt.pix.quantization).c_str());
if (vfmt.fmt.pix.priv == V4L2_PIX_FMT_PRIV_MAGIC)
printf("\tFlags : %s\n", 
pixflags2s(vfmt.fmt.pix.flags).c_str());
-- 
2.10.2

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] qv4l2: Support for HSV encodings

2016-11-15 Thread Ricardo Ribalda Delgado
Support set/get and override of HSV encodings.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 utils/qv4l2/general-tab.cpp | 4 +++-
 utils/qv4l2/qv4l2.cpp   | 5 -
 utils/qv4l2/tpg-tab.cpp | 4 +++-
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/utils/qv4l2/general-tab.cpp b/utils/qv4l2/general-tab.cpp
index c74847935194..0d98d6569c49 100644
--- a/utils/qv4l2/general-tab.cpp
+++ b/utils/qv4l2/general-tab.cpp
@@ -780,8 +780,10 @@ void GeneralTab::formatSection(v4l2_fmtdesc fmt)
m_ycbcrEnc->addItem("BT.2020", QVariant(V4L2_YCBCR_ENC_BT2020));
m_ycbcrEnc->addItem("BT.2020 Constant Luminance", 
QVariant(V4L2_YCBCR_ENC_BT2020_CONST_LUM));
m_ycbcrEnc->addItem("SMPTE 240M", 
QVariant(V4L2_YCBCR_ENC_SMPTE240M));
+   m_ycbcrEnc->addItem("Hue 0 - 179", QVariant(V4L2_HSV_ENC_180));
+   m_ycbcrEnc->addItem("Hue 0 - 255", QVariant(V4L2_HSV_ENC_256));
 
-   addLabel("Y'CbCr Encoding");
+   addLabel("Y'CbCr / HSV Encoding");
addWidget(m_ycbcrEnc);
connect(m_ycbcrEnc, SIGNAL(activated(int)), 
SLOT(ycbcrEncChanged(int)));
 
diff --git a/utils/qv4l2/qv4l2.cpp b/utils/qv4l2/qv4l2.cpp
index 4f0a52d96d39..a093fbf48913 100644
--- a/utils/qv4l2/qv4l2.cpp
+++ b/utils/qv4l2/qv4l2.cpp
@@ -213,7 +213,7 @@ ApplicationWindow::ApplicationWindow() :
connect(grp, SIGNAL(triggered(QAction *)), this, 
SLOT(overrideXferFuncChanged(QAction *)));
 
m_overrideYCbCrEnc = -1;
-   menu = new QMenu("Override Y'CbCr Encoding");
+   menu = new QMenu("Override Y'CbCr / HSV Encoding");
m_overrideYCbCrEncMenu = menu;
grp = new QActionGroup(menu);
addSubMenuItem(grp, menu, "No Override", -1)->setChecked(true);
@@ -224,6 +224,9 @@ ApplicationWindow::ApplicationWindow() :
addSubMenuItem(grp, menu, "BT.2020", V4L2_YCBCR_ENC_BT2020);
addSubMenuItem(grp, menu, "BT.2020 Constant Luminance", 
V4L2_YCBCR_ENC_BT2020_CONST_LUM);
addSubMenuItem(grp, menu, "SMPTE 240M", V4L2_YCBCR_ENC_SMPTE240M);
+   addSubMenuItem(grp, menu, "Hue 0 - 179", V4L2_HSV_ENC_180);
+   addSubMenuItem(grp, menu, "Hue 0 - 255", V4L2_HSV_ENC_256);
+
connect(grp, SIGNAL(triggered(QAction *)), this, 
SLOT(overrideYCbCrEncChanged(QAction *)));
 
m_overrideQuantization = -1;
diff --git a/utils/qv4l2/tpg-tab.cpp b/utils/qv4l2/tpg-tab.cpp
index 386509de986b..e234b7dbfa1c 100644
--- a/utils/qv4l2/tpg-tab.cpp
+++ b/utils/qv4l2/tpg-tab.cpp
@@ -177,7 +177,7 @@ void ApplicationWindow::addTpgTab(int m_winWidth)
addWidget(grid, m_tpgXferFunc);
connect(m_tpgXferFunc, SIGNAL(activated(int)), 
SLOT(tpgXferFuncChanged()));
 
-   addLabel(grid, "Y'CbCr Encoding");
+   addLabel(grid, "Y'CbCr / HSV Encoding");
m_tpgYCbCrEnc = new QComboBox(w);
m_tpgYCbCrEnc->addItem("Use Format", QVariant(V4L2_YCBCR_ENC_DEFAULT));
m_tpgYCbCrEnc->addItem("ITU-R 601", QVariant(V4L2_YCBCR_ENC_601));
@@ -187,6 +187,8 @@ void ApplicationWindow::addTpgTab(int m_winWidth)
m_tpgYCbCrEnc->addItem("BT.2020", QVariant(V4L2_YCBCR_ENC_BT2020));
m_tpgYCbCrEnc->addItem("BT.2020 Constant Luminance", 
QVariant(V4L2_YCBCR_ENC_BT2020_CONST_LUM));
m_tpgYCbCrEnc->addItem("SMPTE 240M", 
QVariant(V4L2_YCBCR_ENC_SMPTE240M));
+   m_tpgYCbCrEnc->addItem("Hue 0 - 179", QVariant(V4L2_HSV_ENC_180));
+   m_tpgYCbCrEnc->addItem("Hue 0 - 255", QVariant(V4L2_HSV_ENC_256));
addWidget(grid, m_tpgYCbCrEnc);
connect(m_tpgYCbCrEnc, SIGNAL(activated(int)), 
SLOT(tpgColorspaceChanged()));
 
-- 
2.10.2

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] v4l2-tpg: Init hv_enc field with a valid value

2016-11-15 Thread Ricardo Ribalda Delgado
Zero is not a valid value for hsv_enc. Set the field to a valid
initial value.

This is not a problem for vivid, because it sets the field to 180 via
tpg_s_hsv_enc() on the control initialization, but it might be a source
of errors for other drivers that use this code.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c 
b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
index 28d7b072d867..e47b46e2d26c 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -117,6 +117,7 @@ void tpg_init(struct tpg_data *tpg, unsigned w, unsigned h)
tpg_s_fourcc(tpg, V4L2_PIX_FMT_RGB24);
tpg->colorspace = V4L2_COLORSPACE_SRGB;
tpg->perc_fill = 100;
+   tpg->hsv_enc = V4L2_HSV_ENC_180;
 }
 EXPORT_SYMBOL_GPL(tpg_init);
 
-- 
2.10.2

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] vivid: Set color_enc on HSV formats

2016-11-15 Thread Ricardo Ribalda Delgado
HSV formats were missing the color encoding, which leads to an invalid
ycbcr_enc value during get_fmt and try_fmt.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/platform/vivid/vivid-vid-common.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/vivid/vivid-vid-common.c 
b/drivers/media/platform/vivid/vivid-vid-common.c
index 3d003fb913ed..5fc010f6ce67 100644
--- a/drivers/media/platform/vivid/vivid-vid-common.c
+++ b/drivers/media/platform/vivid/vivid-vid-common.c
@@ -447,6 +447,7 @@ struct vivid_fmt vivid_formats[] = {
},
{
.fourcc   = V4L2_PIX_FMT_HSV24, /* HSV 24bits */
+   .color_enc = TGP_COLOR_ENC_HSV,
.vdownsampling = { 1 },
.bit_depth = { 24 },
.planes   = 1,
@@ -454,6 +455,7 @@ struct vivid_fmt vivid_formats[] = {
},
{
.fourcc   = V4L2_PIX_FMT_HSV32, /* HSV 32bits */
+   .color_enc = TGP_COLOR_ENC_HSV,
.vdownsampling = { 1 },
.bit_depth = { 32 },
.planes   = 1,
-- 
2.10.2

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] qv4l: support for HSV formats via OpenGL.

2016-11-15 Thread Ricardo Ribalda Delgado
Support for HSV32 and HSV24.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 utils/qv4l2/capture-win-gl.cpp | 32 +++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/utils/qv4l2/capture-win-gl.cpp b/utils/qv4l2/capture-win-gl.cpp
index af1909c936c5..df10d6863402 100644
--- a/utils/qv4l2/capture-win-gl.cpp
+++ b/utils/qv4l2/capture-win-gl.cpp
@@ -185,6 +185,8 @@ void CaptureWinGLEngine::setColorspace(unsigned colorspace, 
unsigned xfer_func,
case V4L2_PIX_FMT_YUV555:
case V4L2_PIX_FMT_YUV565:
case V4L2_PIX_FMT_YUV32:
+   case V4L2_PIX_FMT_HSV24:
+   case V4L2_PIX_FMT_HSV32:
is_rgb = false;
break;
}
@@ -396,6 +398,8 @@ bool CaptureWinGLEngine::hasNativeFormat(__u32 format)
V4L2_PIX_FMT_GREY,
V4L2_PIX_FMT_Y16,
V4L2_PIX_FMT_Y16_BE,
+   V4L2_PIX_FMT_HSV24,
+   V4L2_PIX_FMT_HSV32,
0
};
 
@@ -505,6 +509,8 @@ void CaptureWinGLEngine::changeShader()
case V4L2_PIX_FMT_GREY:
case V4L2_PIX_FMT_Y16:
case V4L2_PIX_FMT_Y16_BE:
+   case V4L2_PIX_FMT_HSV24:
+   case V4L2_PIX_FMT_HSV32:
default:
shader_RGB(m_frameFormat);
break;
@@ -647,6 +653,8 @@ void CaptureWinGLEngine::paintGL()
case V4L2_PIX_FMT_XBGR32:
case V4L2_PIX_FMT_ARGB32:
case V4L2_PIX_FMT_ABGR32:
+   case V4L2_PIX_FMT_HSV24:
+   case V4L2_PIX_FMT_HSV32:
default:
render_RGB(m_frameFormat);
break;
@@ -1537,7 +1545,9 @@ void CaptureWinGLEngine::shader_RGB(__u32 format)
  format == V4L2_PIX_FMT_BGR666 ||
  format == V4L2_PIX_FMT_GREY ||
  format == V4L2_PIX_FMT_Y16 ||
- format == V4L2_PIX_FMT_Y16_BE;
+ format == V4L2_PIX_FMT_Y16_BE ||
+ format == V4L2_PIX_FMT_HSV24 ||
+ format == V4L2_PIX_FMT_HSV32;
GLint internalFmt = manualTransform ? GL_RGBA8 : GL_SRGB8_ALPHA8;
 
switch (format) {
@@ -1588,6 +1598,7 @@ void CaptureWinGLEngine::shader_RGB(__u32 format)
/* fall-through */
case V4L2_PIX_FMT_RGB32:
case V4L2_PIX_FMT_XRGB32:
+   case V4L2_PIX_FMT_HSV32:
glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, m_frameWidth, 
m_frameHeight, 0,
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, NULL);
break;
@@ -1610,6 +1621,7 @@ void CaptureWinGLEngine::shader_RGB(__u32 format)
break;
case V4L2_PIX_FMT_RGB24:
case V4L2_PIX_FMT_BGR24:
+   case V4L2_PIX_FMT_HSV24:
default:
glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, m_frameWidth, 
m_frameHeight, 0,
GL_RGB, GL_UNSIGNED_BYTE, NULL);
@@ -1657,6 +1669,22 @@ void CaptureWinGLEngine::shader_RGB(__u32 format)
"   float g = r;"
"   float b = r;";
break;
+   case V4L2_PIX_FMT_HSV24:
+   case V4L2_PIX_FMT_HSV32:
+   /* From http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl 
*/
+   if (m_ycbcr_enc == V4L2_HSV_ENC_256)
+   codeHead += "   float hue = color.r;";
+   else
+   codeHead += "   float hue = (color.r * 256.0) / 180.0;";
+
+   codeHead += "   vec3 c = vec3(hue, color.g, color.b);"
+   "   vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);"
+   "   vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - 
K.www);"
+   "   vec3 ret = c.z * mix(K.xxx, clamp(p - K.xxx, 
0.0, 1.0), c.y);"
+   "   float r = ret.x;"
+   "   float g = ret.y;"
+   "   float b = ret.z;";
+   break;
default:
codeHead += "   float r = color.r;"
"   float g = color.g;"
@@ -1759,6 +1787,7 @@ void CaptureWinGLEngine::render_RGB(__u32 format)
case V4L2_PIX_FMT_RGB32:
case V4L2_PIX_FMT_XRGB32:
case V4L2_PIX_FMT_ARGB32:
+   case V4L2_PIX_FMT_HSV32:
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, 
m_frameHeight,
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, m_frameData);
break;
@@ -1771,6 +1800,7 @@ void CaptureWinGLEngine::render_RGB(__u32 format)
break;
case V4L2_PIX_FMT_RGB24:
case V4L2_PIX_FMT_BGR24:
+   case V4L2_PIX_FMT_HSV24:
default:
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, 
m_frameHei

[PATCH 1/3] libv4lconvert: Add support for V4L2_PIX_FMT_{HSV24, HSV32}

2016-11-15 Thread Ricardo Ribalda Delgado
HSV32 and HSV24 are single plane interleaved Hue Saturation Value
formats.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 lib/libv4lconvert/libv4lconvert-priv.h |  3 ++
 lib/libv4lconvert/libv4lconvert.c  | 62 +++
 lib/libv4lconvert/rgbyuv.c | 77 ++
 3 files changed, 142 insertions(+)

diff --git a/lib/libv4lconvert/libv4lconvert-priv.h 
b/lib/libv4lconvert/libv4lconvert-priv.h
index 1740efc94456..e23893475a6e 100644
--- a/lib/libv4lconvert/libv4lconvert-priv.h
+++ b/lib/libv4lconvert/libv4lconvert-priv.h
@@ -271,6 +271,9 @@ void v4lconvert_hm12_to_bgr24(const unsigned char *src,
 void v4lconvert_hm12_to_yuv420(const unsigned char *src,
unsigned char *dst, int width, int height, int yvu);
 
+void v4lconvert_hsv_to_rgb24(const unsigned char *src, unsigned char *dest,
+   int width, int height, int bgr, int Xin, unsigned char hsv_enc);
+
 void v4lconvert_rotate90(unsigned char *src, unsigned char *dest,
struct v4l2_format *fmt);
 
diff --git a/lib/libv4lconvert/libv4lconvert.c 
b/lib/libv4lconvert/libv4lconvert.c
index d3d89362d3ca..da718918b030 100644
--- a/lib/libv4lconvert/libv4lconvert.c
+++ b/lib/libv4lconvert/libv4lconvert.c
@@ -142,6 +142,9 @@ static const struct v4lconvert_pixfmt 
supported_src_pixfmts[] = {
{ V4L2_PIX_FMT_Y10BPACK,10, 20, 20, 0 },
{ V4L2_PIX_FMT_Y16, 16, 20, 20, 0 },
{ V4L2_PIX_FMT_Y16_BE,  16, 20, 20, 0 },
+   /* hsv formats */
+   { V4L2_PIX_FMT_HSV32,   32,  5,  4, 0 },
+   { V4L2_PIX_FMT_HSV24,   24,  5,  4, 0 },
 };
 
 static const struct v4lconvert_pixfmt supported_dst_pixfmts[] = {
@@ -1327,6 +1330,65 @@ static int v4lconvert_convert_pixfmt(struct 
v4lconvert_data *data,
break;
}
break;
+   case V4L2_PIX_FMT_HSV24:
+   if (src_size < (width * height * 3)) {
+   V4LCONVERT_ERR("short hsv24 data frame\n");
+   errno = EPIPE;
+   result = -1;
+   }
+   switch (dest_pix_fmt) {
+   case V4L2_PIX_FMT_RGB24:
+   v4lconvert_hsv_to_rgb24(src, dest, width, height, 0,
+   24, fmt->fmt.pix.hsv_enc);
+   break;
+   case V4L2_PIX_FMT_BGR24:
+   v4lconvert_hsv_to_rgb24(src, dest, width, height, 1,
+   24, fmt->fmt.pix.hsv_enc);
+   break;
+   case V4L2_PIX_FMT_YUV420:
+   v4lconvert_hsv_to_rgb24(src, dest, width, height, 0,
+   24, fmt->fmt.pix.hsv_enc);
+   v4lconvert_rgb24_to_yuv420(src, dest, fmt, 0, 0, 3);
+   break;
+   case V4L2_PIX_FMT_YVU420:
+   v4lconvert_hsv_to_rgb24(src, dest, width, height, 0,
+   24, fmt->fmt.pix.hsv_enc);
+   v4lconvert_rgb24_to_yuv420(src, dest, fmt, 0, 1, 3);
+   break;
+   }
+
+   break;
+
+   case V4L2_PIX_FMT_HSV32:
+   if (src_size < (width * height * 4)) {
+   V4LCONVERT_ERR("short hsv32 data frame\n");
+   errno = EPIPE;
+   result = -1;
+   }
+   switch (dest_pix_fmt) {
+   case V4L2_PIX_FMT_RGB24:
+   v4lconvert_hsv_to_rgb24(src, dest, width, height, 0,
+   32, fmt->fmt.pix.hsv_enc);
+   break;
+   case V4L2_PIX_FMT_BGR24:
+   v4lconvert_hsv_to_rgb24(src, dest, width, height, 1,
+   32, fmt->fmt.pix.hsv_enc);
+   break;
+   case V4L2_PIX_FMT_YUV420:
+   v4lconvert_hsv_to_rgb24(src, dest, width, height, 0,
+   32, fmt->fmt.pix.hsv_enc);
+   v4lconvert_rgb24_to_yuv420(src, dest, fmt, 0, 0, 3);
+   break;
+   case V4L2_PIX_FMT_YVU420:
+   v4lconvert_hsv_to_rgb24(src, dest, width, height, 0,
+   32, fmt->fmt.pix.hsv_enc);
+   v4lconvert_rgb24_to_yuv420(src, dest, fmt, 0, 1, 3);
+   break;
+   }
+
+   break;
+
+
 
default:
V4LCONVERT_ERR("Unknown src format in conversion\n");
diff --git a/lib/libv4lconvert/rgbyuv.c b/lib/libv4lconvert/rgbyuv.c
index a0f825

[GIT PULL] HSV formats v2

2016-10-17 Thread Ricardo Ribalda Delgado
Hi Mauro,

These is the last PULL request rebased to your last master thanks to Laurent :)


These patches add support for HSV.

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.

This pull request contains [PATCH v5 00/12] Add HSV format, plus the
following chanes:

-It has been rebased to media/master
-Laurent patch to add support for vsp1
-Hans Ack-by
-Documentation now make use of tabularcolumn (latex)

Please pull:

The following changes since commit 11a1e0ed7908f04c896e69d0eb65e478c12f8519:

  [media] dvb-usb: warn if return value for USB read/write routines is
not checked (2016-10-14 12:52:31 -0300)

are available in the git repository at:

  https://github.com/ribalda/linux.git vivid-hsv-v7

for you to fetch changes up to 7cb9d88402c4f674887af165e1425f1fd347583f:

  v4l: vsp1: Add support for capture and output in HSV formats
(2016-10-17 23:20:10 +0200)


Laurent Pinchart (1):
  v4l: vsp1: Add support for capture and output in HSV formats

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

 Documentation/media/uapi/v4l/hsv-formats.rst   |  19 +
 Documentation/media/uapi/v4l/pixfmt-002.rst|   5 +
 Documentation/media/uapi/v4l/pixfmt-003.rst|   5 +
 Documentation/media/uapi/v4l/pixfmt-006.rst|  31 +-
 Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst | 157 
 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  | 411 ++---
 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/platform/vsp1/vsp1_pipe.c|   8 +
 drivers/media/platform/vsp1/vsp1_rwpf.c|   2 +
 drivers/media/platform/vsp1/vsp1_video.c   |   5 +
 drivers/media/v4l2-core/v4l2-ioctl.c   |   2 +
 include/media/v4l2-tpg.h   |  24 +-
 include/uapi/linux/videodev2.h |  36 +-
 20 files changed, 653 insertions(+), 180 deletions(-)
 create mode 100644 Documentation/media/uapi/v4l/hsv-formats.rst
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst

-- 
Ricardo Ribalda
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[GIT PULL] HSV formats

2016-09-07 Thread Ricardo Ribalda Delgado
Hi Mauro,


These patches add support for HSV.

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.

This pull request contains [PATCH v5 00/12] Add HSV format, plus the
following chanes:

-It has been rebased to media/master
-Laurent patch to add support for vsp1
-Hans Ack-by
-Documentation now make use of tabularcolumn (latex)

This is my first pull request :)

Please pull


The following changes since commit 036bbb8213ecca49799217f30497dc0484178e53:

  [media] cobalt: update EDID (2016-09-06 16:46:39 -0300)

are available in the git repository at:

  https://github.com/ribalda/linux.git vivid-hsv-v6

for you to fetch changes up to 1242d7e43b9053cd649ac5ec81aad8597e88ab46:

  [media] vsp1: Add support for capture and output in HSV formats
(2016-09-07 10:41:52 +0200)


Laurent Pinchart (1):
  [media] vsp1: Add support for capture and output in HSV formats

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|  43 ++-
 Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst | 164
+++
 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  | 411
---
 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/platform/vsp1/vsp1_pipe.c|   8 ++
 drivers/media/platform/vsp1/vsp1_rwpf.c|   2 +
 drivers/media/platform/vsp1/vsp1_video.c   |   5 +
 drivers/media/v4l2-core/v4l2-ioctl.c   |   2 +
 include/media/v4l2-tpg.h   |  24 +++-
 include/uapi/linux/videodev2.h |  36 +-
 20 files changed, 685 insertions(+), 183 deletions(-)
 create mode 100644 Documentation/media/uapi/v4l/hsv-formats.rst
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst


-- 
Ricardo Ribalda
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] v4l: vsp1: Add support for capture and output in HSV formats

2016-09-07 Thread Ricardo Ribalda Delgado
Hi Laurent,

On Wed, Sep 7, 2016 at 9:09 AM, Laurent Pinchart
<laurent.pinch...@ideasonboard.com> wrote:
>>
>> Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
>
> Do you mean Acked-by ?

Acked-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>

Ups, my bad


>
> Feel free to take the patch in your tree to get it merged along with the HSV
> series.


I do not really have a tree, I have a github account that is it.

Let me ask Hans on the irc how to procede from here.

I really appreciate your help!

-- 
Ricardo Ribalda
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] v4l: vsp1: Add support for capture and output in HSV formats

2016-09-07 Thread Ricardo Ribalda Delgado
Hi Laurent

Thank you very much!

On Wed, Sep 7, 2016 at 2:14 AM, Laurent Pinchart
<laurent.pinchart+rene...@ideasonboard.com> wrote:
> Support both the HSV24 and HSV32 formats. From a hardware point of view
> pretend the formats are RGB, the RPF and WPF will just pass the data
> through without performing any processing.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5_2 10/12] [media] videodev2.h Add HSV encoding

2016-08-22 Thread 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.riba...@gmail.com>
---

v5_2: s/s_rgb_or_yuv/s_rgb_or_hsv/
Thanks Hans!!
 include/uapi/linux/videodev2.h | 32 +++-
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 58ed8aedc196..baa874d91299 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -335,6 +335,19 @@ enum v4l2_ycbcr_encoding {
 };
 
 /*
+ * enum v4l2_hsv_encoding values should not collide with the ones from
+ * enum v4l2_ycbcr_encoding.
+ */
+enum v4l2_hsv_encoding {
+
+   /* Hue mapped to 0 - 179 */
+   V4L2_HSV_ENC_180= 128,
+
+   /* Hue mapped to 0-255 */
+   V4L2_HSV_ENC_256= 129,
+};
+
+/*
  * Determine how YCBCR_ENC_DEFAULT should map to a proper Y'CbCr encoding.
  * This depends on the colorspace.
  */
@@ -362,9 +375,10 @@ enum v4l2_quantization {
  * This depends on whether the image is RGB or not, the colorspace and the
  * Y'CbCr encoding.
  */
-#define V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb, colsp, ycbcr_enc) \
-   (((is_rgb) && (colsp) == V4L2_COLORSPACE_BT2020) ? 
V4L2_QUANTIZATION_LIM_RANGE : \
-(((is_rgb) || (ycbcr_enc) == V4L2_YCBCR_ENC_XV601 || \
+#define V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb_or_hsv, colsp, ycbcr_enc) \
+   (((is_rgb_or_hsv) && (colsp) == V4L2_COLORSPACE_BT2020) ? \
+V4L2_QUANTIZATION_LIM_RANGE : \
+(((is_rgb_or_hsv) || (ycbcr_enc) == V4L2_YCBCR_ENC_XV601 || \
  (ycbcr_enc) == V4L2_YCBCR_ENC_XV709 || (colsp) == 
V4L2_COLORSPACE_JPEG) || \
  (colsp) == V4L2_COLORSPACE_ADOBERGB || (colsp) == 
V4L2_COLORSPACE_SRGB ? \
 V4L2_QUANTIZATION_FULL_RANGE : V4L2_QUANTIZATION_LIM_RANGE))
@@ -460,7 +474,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 */
 };
@@ -1993,7 +2012,10 @@ struct v4l2_pix_format_mplane {
struct v4l2_plane_pix_formatplane_fmt[VIDEO_MAX_PLANES];
__u8num_planes;
__u8flags;
-   __u8ycbcr_enc;
+union {
+   __u8ycbcr_enc;
+   __u8hsv_enc;
+   };
__u8quantization;
__u8xfer_func;
__u8reserved[7];
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 10/12] [media] videodev2.h Add HSV encoding

2016-08-22 Thread Ricardo Ribalda Delgado
Hello Hans:

>
> That should be is_rgb_or_hsv.

Sorry about that! I am resending v5_2 with only that patch fixed

>
> All other patches look OK.

Thanks

>
> It would be useful though if you could rebase on top of 
> https://git.linuxtv.org/hverkuil/media_tree.git/log/?h=sycc.
> I have a pull request outstanding for that tree, and it will conflict with 
> this patch.

It should be already be rebased over that branch:

ricardo@neopili:~/curro/linux-upstream$ git rebase hans/sycc
Current branch vivid-hsv-v5 is up to date.


Best regards!
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 08/12] [media] vivid: Fix YUV555 and YUV565 handling

2016-08-18 Thread 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.riba...@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 920c8495f3dd..7364ced09abc 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -795,6 +795,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);
@@ -871,7 +873,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 */
@@ -888,13 +889,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, , , );
+   if (tpg->color_enc == TGP_COLOR_ENC_YCBCR)
+   ycbcr_valid = true;
+   else
+   ycbcr_to_color(tpg, y, cb, cr, , , );
} else if ((tpg->brightness != 128 || tpg->contrast != 128) &&
   tpg->color_enc == TGP_COLOR_ENC_LUMA) {
r = (16 << 4) + ((r - (16 << 4)) * tpg->contrast) / 128;
@@ -915,9 +913,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, , , );
+   if (!ycbcr_valid)
+   color_to_ycbcr(tpg, r, g, b, , , );
 
if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) {
y = clamp(y, 16 << 4, 235 << 4);
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 04/12] [media] vivid: Code refactor for color encoding

2016-08-18 Thread 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.riba...@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 1684810cab83..c4153307bfc5 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;
@@ -775,7 +775,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
@@ -785,7 +786,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 &&
+

[PATCH v5 06/12] [media] vivid: Rename variable

2016-08-18 Thread 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.riba...@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 67e0aaf067b7..0aeabe92ff32 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -1012,7 +1012,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 &&
@@ -1020,161 +1020,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 (0x).
 */
-   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;
+ 

[PATCH v5 07/12] [media] vivid: Introduce TPG_COLOR_ENC_LUMA

2016-08-18 Thread Ricardo Ribalda Delgado
Simplifies handling of Gray formats.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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 0aeabe92ff32..920c8495f3dd 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:
@@ -823,9 +825,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;
@@ -865,8 +867,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;
@@ -892,6 +895,10 @@ static void precalculate_color(struct tpg_data *tpg, int k)
return;
}
ycbcr_to_color(tpg, y, cb, cr, , , );
+   } 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) {
@@ -942,6 +949,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) {
@@ -1983,6 +1995,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,
   

[PATCH v5 05/12] [media] vivid: Add support for HSV formats

2016-08-18 Thread Ricardo Ribalda Delgado
This patch adds support for V4L2_PIX_FMT_HSV24 and V4L2_PIX_FMT_HSV32.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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 c4153307bfc5..67e0aaf067b7 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)
 {
@@ -830,7 +894,19 @@ static void precalculate_color(struct tpg_data *tpg, int k)
ycbcr_to_color(tpg, y, cb, cr, , , );
}
 
-   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, , , );
+   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;
 
@@ -864,7 +940,10 @@ static void precalculate_color(struct tpg_data *tpg, int k)
tpg->colors[k][0] = y;
tpg->colors[k][1] = cb;
tpg->colors[k][2] = cr;
-   } else {
+   break;
+   }
+   case TGP_COLOR_ENC_RGB:
+   {
if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) {
r = (r * 219) / 255 + (16 << 4);
g = (g * 219) / 255 + (16 << 4);
@@ -914,6 +993,8 @@ static void precalculate_color(struct tpg_data *tpg, int k)
tpg->colors[k][0] = r;
tpg->colors[k][1] = g;
tpg->colors[k][2] = b;
+   break;
+   }
}
 }
 
@@ -939,8 +1020,8 @@ static void gen_twopix(struct tpg_data *tpg,
alpha = 0;
if (color == TPG_COLOR_RANDOM)
precalculate_color(tpg, color);
-   r_y = tpg->colors[color][0]; /* R or precalculated Y */
-   g_u = tpg->colors[color][1]; /* G or precalculated U */
+   r_y = tpg->colors[color][0]; /* R or precalculated Y, H */
+   g_u = tpg->colors[color][1]; /* G or pr

[PATCH v5 12/12] [media] vivid: Add support for HSV encoding

2016-08-18 Thread Ricardo Ribalda Delgado
Support HSV encoding. Most of the logic is replicated from ycbcr_enc.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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 ed37ae307cac..28d7b072d867 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,
@@ -1928,6 +1935,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)
@@ -2018,6 +2026,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 aceb38d9f7e7..34731f71cc00 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;
+

[PATCH v5 00/12] Add HSV format

2016-08-18 Thread 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:
It is rebased on top of 
https://git.linuxtv.org/hverkuil/media_tree.git/commit/?h=sycc

v5: Suggested-by: Philipp Zabel <p.za...@pengutronix.de>
-Redo "Local optimization for clamp" based on compiler output

Suggested by Hans Verkuil <hverk...@xs4all.nl> and
- Start hsv encoding values at 128
- Fix documentation 
- Change MAP_QUANTIZATION_DEFAULT

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

Suggested by Hans Verkuil <hverk...@xs4all.nl> and
Laurent Pinchart <laurent.pinch...@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.pinch...@ideasonboard.com>
-Remove unneeded empty lines on .rst file
Thanks!

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

v2:
Suggested by Mauro Carvalho Chehab <mche...@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|  41 +-
 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  | 411 ++---
 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 |  36 +-
 17 files changed, 664 insertions(+), 182 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

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 10/12] [media] videodev2.h Add HSV encoding

2016-08-18 Thread 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.riba...@gmail.com>
---
 include/uapi/linux/videodev2.h | 32 +++-
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 58ed8aedc196..71a4c3c13ee0 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -335,6 +335,19 @@ enum v4l2_ycbcr_encoding {
 };
 
 /*
+ * enum v4l2_hsv_encoding values should not collide with the ones from
+ * enum v4l2_ycbcr_encoding.
+ */
+enum v4l2_hsv_encoding {
+
+   /* Hue mapped to 0 - 179 */
+   V4L2_HSV_ENC_180= 128,
+
+   /* Hue mapped to 0-255 */
+   V4L2_HSV_ENC_256= 129,
+};
+
+/*
  * Determine how YCBCR_ENC_DEFAULT should map to a proper Y'CbCr encoding.
  * This depends on the colorspace.
  */
@@ -362,9 +375,10 @@ enum v4l2_quantization {
  * This depends on whether the image is RGB or not, the colorspace and the
  * Y'CbCr encoding.
  */
-#define V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb, colsp, ycbcr_enc) \
-   (((is_rgb) && (colsp) == V4L2_COLORSPACE_BT2020) ? 
V4L2_QUANTIZATION_LIM_RANGE : \
-(((is_rgb) || (ycbcr_enc) == V4L2_YCBCR_ENC_XV601 || \
+#define V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb_or_yuv, colsp, ycbcr_enc) \
+   (((is_rgb_or_yuv) && (colsp) == V4L2_COLORSPACE_BT2020) ? \
+V4L2_QUANTIZATION_LIM_RANGE : \
+(((is_rgb_or_yuv) || (ycbcr_enc) == V4L2_YCBCR_ENC_XV601 || \
  (ycbcr_enc) == V4L2_YCBCR_ENC_XV709 || (colsp) == 
V4L2_COLORSPACE_JPEG) || \
  (colsp) == V4L2_COLORSPACE_ADOBERGB || (colsp) == 
V4L2_COLORSPACE_SRGB ? \
 V4L2_QUANTIZATION_FULL_RANGE : V4L2_QUANTIZATION_LIM_RANGE))
@@ -460,7 +474,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 */
 };
@@ -1993,7 +2012,10 @@ struct v4l2_pix_format_mplane {
struct v4l2_plane_pix_formatplane_fmt[VIDEO_MAX_PLANES];
__u8num_planes;
__u8flags;
-   __u8ycbcr_enc;
+union {
+   __u8ycbcr_enc;
+   __u8hsv_enc;
+   };
__u8quantization;
__u8xfer_func;
__u8reserved[7];
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 02/12] [media] Documentation: Add HSV format

2016-08-18 Thread Ricardo Ribalda Delgado
Describe the HSV formats

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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 ..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 ..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 `.)
 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 5e41a8505301..36c6d0dc3859 100644
--- a/Documentation/media/uapi/v4l/v4l2.rst
+++ b/Documentation/media/uapi/v4l/v4l2.rst
@@ -89,6 +89,11 @@ part can be used and distributed without restrictions.
 Revision H

[PATCH v5 11/12] [media] Documentation: Add HSV encodings

2016-08-18 Thread Ricardo Ribalda Delgado
Describe the hsv_enc field and its use.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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| 41 --
 Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst |  3 +-
 Documentation/media/videodev2.h.rst.exceptions |  4 +++
 5 files changed, 68 insertions(+), 6 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 `
+
+   -  ``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 `
 
-  ``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 `
 
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 `
+
+   -  ``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 `
 
-  ``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 `
 
@@ -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 94271c8a3f68..b95099226e52 100644
--- a/Documentation/media/uapi/v4l/pixfmt-006.rst
+++ b/Documentation/media/uapi/v4l/pixfmt-006.rst
@@ -19,9 +19,18 @@ colorspace field of struct :ref:`v4l2_pix_format 
`
 or struct :ref:`v4l2_pix_format_mplane `
 needs to be filled in.
 
+.. _hsv-colorspace:
+
+On :ref:`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
+:ref:`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.
+   quantization. :ref:`HSV formats ` are always full range.
 
 
 .. _v4l2-colorspace:
@@ -242,6 +251,34 @@ needs to be filled in.
 
 
 
+.. _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 roughly 1.41 degrees.
+
+
+
 .. _v4l2-quantization:
 
 .. flat-table:: V4L2 Quantization Methods
@@ -261,7 +298,7 @@ needs to be filled in.
 
-  Use the default quantization encoding as defined by the
  colorspace. This is always full range for R'G'B' (except for the
- BT.2020 colorspace) and usually limited range for Y'CbCr.
+ BT.2020 colorspace) and HSV. It is usually limited range for Y'CbCr.
 
 -  .. row 3
 
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.
+Th

[PATCH v5 09/12] [media] vivid: Local optimization

2016-08-18 Thread Ricardo Ribalda Delgado
Avoid duplicated clamps when possible.

Suggested-by: Philipp Zabel <p.za...@pengutronix.de>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 16 ++--
 1 file changed, 10 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 7364ced09abc..ed37ae307cac 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -916,14 +916,18 @@ static void precalculate_color(struct tpg_data *tpg, int 
k)
if (!ycbcr_valid)
color_to_ycbcr(tpg, r, g, b, , , );
 
+   y >>= 4;
+   cb >>= 4;
+   cr >>= 4;
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, 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);
}
-   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

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 03/12] [media] Documentation: Add Ricardo Ribalda

2016-08-18 Thread Ricardo Ribalda Delgado
My initials were on the Changelog, but there was no link to my name.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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 36c6d0dc3859..cf4a40ff7e14 100644
--- a/Documentation/media/uapi/v4l/v4l2.rst
+++ b/Documentation/media/uapi/v4l/v4l2.rst
@@ -68,6 +68,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

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 01/12] [media] videodev2.h Add HSV formats

2016-08-18 Thread 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.riba...@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 51a0fa144392..16b211f7212b 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 8c5468cf43e3..58ed8aedc196 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -585,6 +585,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_MJPEGv4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG   
*/
 #define V4L2_PIX_FMT_JPEG v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG 
*/
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0658/1285] Replace numeric parameter like 0444 with macro

2016-08-03 Thread Ricardo Ribalda Delgado
Hi

On Tue, Aug 2, 2016 at 1:34 PM, Baole Ni  wrote:
> thus, I suggest replacing the numeric parameter with the macro.

For what my opinion is worth it... I found more comprehensive the
octal values than the macros, but maybe it is because I am old and
dream in hexadecimal

I do not know if there is a consensus about this, but if there is not
maybe we should have that discussion before sending a 1K patchset.

Regards
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] [media] Documentation: Fix V4L2_CTRL_FLAG_VOLATILE

2016-07-22 Thread Ricardo Ribalda Delgado
V4L2_CTRL_FLAG_VOLATILE behaviour when V4L2_CTRL_FLAG_EXECUTE_ON_WRITE
is set was not properly explained.

Also set some hyperlink to ease the Documentation browsing.

Reported-by: Dimitrios Katsaros <patcherw...@gmail.com>
Credit-to: Hans Verkuil <hansv...@cisco.com>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---

v2: By Hans Verkuil <hansv...@cisco.com>
-Fix some syntax errors

By Mauro Carvalho Chehab <mche...@kernel.org>
-Add hyperlinks

 Documentation/media/uapi/v4l/vidioc-queryctrl.rst | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/Documentation/media/uapi/v4l/vidioc-queryctrl.rst 
b/Documentation/media/uapi/v4l/vidioc-queryctrl.rst
index 8d6e61a7284d..22475f484cb3 100644
--- a/Documentation/media/uapi/v4l/vidioc-queryctrl.rst
+++ b/Documentation/media/uapi/v4l/vidioc-queryctrl.rst
@@ -728,10 +728,12 @@ See also the examples in :ref:`control`.
  case the hardware calculates the gain value based on the lighting
  conditions which can change over time.
 
- .. note:: Setting a new value for a volatile control will have no
-effect and no ``V4L2_EVENT_CTRL_CH_VALUE`` will be sent, unless
-the ``V4L2_CTRL_FLAG_EXECUTE_ON_WRITE`` flag (see below) is
-also set. Otherwise the new value will just be ignored.
+ .. note:: Setting a new value for a volatile control will be ignored
+ unless
+ :ref:`V4L2_CTRL_FLAG_EXECUTE_ON_WRITE `
+ is also set.
+ Setting a new value for a volatile control will *never* trigger a
+ :ref:`V4L2_EVENT_CTRL_CH_VALUE ` event.
 
 -  .. row 9
 
@@ -747,6 +749,7 @@ See also the examples in :ref:`control`.
  payload of the control.
 
 -  .. row 10
+   .. _FLAG_EXECUTE_ON_WRITE:
 
-  ``V4L2_CTRL_FLAG_EXECUTE_ON_WRITE``
 
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] [media] Documentation: Fix V4L2_CTRL_FLAG_VOLATILE

2016-07-22 Thread Ricardo Ribalda Delgado
V4L2_CTRL_FLAG_VOLATILE behaviour when V4L2_CTRL_FLAG_EXECUTE_ON_WRITE
is set was not properly explained.

Reported-by: Dimitrios Katsaros <patcherw...@gmail.com>
Credit-to: Hans Verkuil <hansv...@cisco.com>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 Documentation/media/uapi/v4l/vidioc-queryctrl.rst | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Documentation/media/uapi/v4l/vidioc-queryctrl.rst 
b/Documentation/media/uapi/v4l/vidioc-queryctrl.rst
index 8d6e61a7284d..3a30d6cf70b4 100644
--- a/Documentation/media/uapi/v4l/vidioc-queryctrl.rst
+++ b/Documentation/media/uapi/v4l/vidioc-queryctrl.rst
@@ -728,10 +728,10 @@ See also the examples in :ref:`control`.
  case the hardware calculates the gain value based on the lighting
  conditions which can change over time.
 
- .. note:: Setting a new value for a volatile control will have no
-effect and no ``V4L2_EVENT_CTRL_CH_VALUE`` will be sent, unless
-the ``V4L2_CTRL_FLAG_EXECUTE_ON_WRITE`` flag (see below) is
-also set. Otherwise the new value will just be ignored.
+ .. note:: Setting a new value for a volatile control will be ignored
+ unless `V4L2_CTRL_FLAG_EXECUTE_ON_WRITE`` flag (see below) is 
also set.
+ Setting a new value for a volatile contol will never trigger a
+ ``V4L2_EVENT_CTRL_CH_VALUE`` event.
 
 -  .. row 9
 
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 09/12] [media] vivid: Local optimization

2016-07-18 Thread Ricardo Ribalda Delgado
Hi Philipp:

On Mon, Jul 18, 2016 at 4:16 PM, Philipp Zabel  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
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 09/12] [media] vivid: Local optimization

2016-07-18 Thread Ricardo Ribalda Delgado
Hi Philipp

On Mon, Jul 18, 2016 at 3:13 PM, Philipp Zabel  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
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 01/12] [media] videodev2.h Add HSV formats

2016-07-18 Thread 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.riba...@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_MJPEGv4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG   
*/
 #define V4L2_PIX_FMT_JPEG v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG 
*/
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 04/12] [media] vivid: Code refactor for color encoding

2016-07-18 Thread 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.riba...@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 &&
+

[PATCH v4 00/12] Add HSV format

2016-07-18 Thread 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 <hverk...@xs4all.nl> and
- Rename YUV to YCBCR
- Fix numerical error

Suggested by Hans Verkuil <hverk...@xs4all.nl> and
Laurent Pinchart <laurent.pinch...@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.pinch...@ideasonboard.com>
-Remove unneeded empty lines on .rst file
Thanks!

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

v2:
Suggested by Mauro Carvalho Chehab <mche...@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

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 03/12] [media] Documentation: Add Ricardo Ribalda

2016-07-18 Thread Ricardo Ribalda Delgado
My initials were on the Changelog, but there was no link to my name.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 07/12] [media] vivid: Introduce TPG_COLOR_ENC_LUMA

2016-07-18 Thread Ricardo Ribalda Delgado
Simplifies handling of Gray formats.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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, , , );
+   } 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,
   

[PATCH v4 10/12] [media] videodev2.h Add HSV encoding

2016-07-18 Thread 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.riba...@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_formatplane_fmt[VIDEO_MAX_PLANES];
__u8num_planes;
__u8flags;
-   __u8ycbcr_enc;
+union {
+   __u8ycbcr_enc;
+   __u8hsv_enc;
+   };
__u8quantization;
__u8xfer_func;
__u8reserved[7];
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 05/12] [media] vivid: Add support for HSV formats

2016-07-18 Thread Ricardo Ribalda Delgado
This patch adds support for V4L2_PIX_FMT_HSV24 and V4L2_PIX_FMT_HSV32.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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, , , );
}
 
-   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, , , );
+   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 pr

[PATCH v4 08/12] [media] vivid: Fix YUV555 and YUV565 handling

2016-07-18 Thread 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.riba...@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, , , );
+   if (tpg->color_enc == TGP_COLOR_ENC_YCBCR)
+   ycbcr_valid = true;
+   else
+   ycbcr_to_color(tpg, y, cb, cr, , , );
} 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, , , );
+   if (!ycbcr_valid)
+   color_to_ycbcr(tpg, r, g, b, , , );
 
if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) {
y = clamp(y, 16 << 4, 235 << 4);
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 06/12] [media] vivid: Rename variable

2016-07-18 Thread 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.riba...@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 (0x).
 */
-   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;
+ 

[PATCH v4 02/12] [media] Documentation: Add HSV format

2016-07-18 Thread Ricardo Ribalda Delgado
Describe the HSV formats

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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 ..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 ..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 `.)
 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 H

[PATCH v4 12/12] [media] vivid: Add support for HSV encoding

2016-07-18 Thread Ricardo Ribalda Delgado
Support HSV encoding. Most of the logic is replicated from ycbcr_enc.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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;
+

[PATCH v4 11/12] [media] Documentation: Add HSV encodings

2016-07-18 Thread Ricardo Ribalda Delgado
Describe the hsv_enc field and its use.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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 `
+
+   -  ``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 `
 
-  ``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 `
 
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 `
+
+   -  ``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 `
 
-  ``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 `
 
@@ -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 
`
 or struct :ref:`v4l2_pix_format_mplane `
 needs to be filled in.
 
+.. _hsv-colorspace:
+
+On :ref:`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 ` 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

[PATCH v4 09/12] [media] vivid: Local optimization

2016-07-18 Thread Ricardo Ribalda Delgado
Avoid duplicated data shifts when possible.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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, , , );
 
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

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 8/9] [media] vivid: Fix YUV555 and YUV565 handling

2016-07-18 Thread Ricardo Ribalda Delgado
Hi Hans


On Mon, Jul 18, 2016 at 10:51 AM, Hans Verkuil  wrote:
>> + int y, cb, cr;
>> + bool ycbbr_valid = false;
>
> I guess you mean ycbcr_valid?

Yes, I think the medical term is Saturday dyslexia :)

It is fixed on the next version.

Thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/6] [media] Documentation: Add HSV format

2016-07-16 Thread Ricardo Ribalda Delgado
Hi Hans

On Sat, Jul 16, 2016 at 5:28 PM, Hans Verkuil  wrote:

>
>> +
>> +enum v4l2_rgb_encoding {
>> +   V4L2_RGB_ENC_FULL   = 32,
>> +   V4L2_HSV_ENC_16_235 = 33,
>> +};
>
> No.

I was trying to fit also Laurent special 16-235 RGB format. I will
remove it on future versions.


Can I make this change as 2 new patches on my vivid-hsv patchset?

1) Add hsv_encoding
2) Add support for vivid hsv_encoding


?


Best Regards
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/6] [media] Documentation: Add HSV format

2016-07-16 Thread Ricardo Ribalda Delgado
Hi

On Sat, Jul 16, 2016 at 4:12 PM, Laurent Pinchart
 wrote:

> I'd still like to know about it for my personal information :-)

Maybe it is just a very cheap gamma.

>
>> Anyway, I am inclined to use ycbcr_enc as well.
>
> I'm glad we agree.
>

Are you thinking about something like this:


diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index c7fb760386cf..3e613fba1b20 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -330,6 +330,16 @@ enum v4l2_ycbcr_encoding {
V4L2_YCBCR_ENC_SMPTE240M  = 8,
 };

+enum v4l2_hsv_encoding {
+   V4L2_HSV_ENC_180= 16,
+   V4L2_HSV_ENC_256= 17,
+};
+
+enum v4l2_rgb_encoding {
+   V4L2_RGB_ENC_FULL   = 32,
+   V4L2_HSV_ENC_16_235 = 33,
+};
+
 /*
  * Determine how YCBCR_ENC_DEFAULT should map to a proper Y'CbCr encoding.
  * This depends on the colorspace.
@@ -455,7 +465,11 @@ 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 {
+   __u32   ycbcr_enc;  /* enum
v4l2_ycbcr_encoding */
+   __u32   hsv_enc;/* enum
v4l2_hsv_encoding */
+   __u32   rgb_enc;/* enum
v4l2_rgb_encoding */
+   };
__u32   quantization;   /* enum v4l2_quantization */
__u32   xfer_func;  /* enum v4l2_xfer_func */
 };
@@ -1988,7 +2002,11 @@ struct v4l2_pix_format_mplane {
struct v4l2_plane_pix_formatplane_fmt[VIDEO_MAX_PLANES];
__u8num_planes;
__u8flags;
-   __u8ycbcr_enc;
+   union {
+   __u8ycbcr_enc;  /* enum
v4l2_ycbcr_encoding */
+   __u8hsv_enc;/* enum
v4l2_hsv_encoding */
+   __u8rgb_enc;/* enum
v4l2_rgb_encoding */
+   };
__u8quantization;
__u8xfer_func;
__u8reserved[7];

> --


Best regards!

-- 
Ricardo Ribalda
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 9/9] [media] vivid: Local optimization

2016-07-16 Thread Ricardo Ribalda Delgado
Hi

On Sat, Jul 16, 2016 at 12:41 PM, Ricardo Ribalda Delgado
<ricardo.riba...@gmail.com> wrote:

> -   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);
This line is obviously wrong, sorry about that.

I wait for some more comments and add it to v4.

Regards!
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 8/9] [media] vivid: Fix YUV555 and YUV565 handling

2016-07-16 Thread 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.riba...@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 e91bf3cbaab9..1c862465e335 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -797,6 +797,8 @@ static void precalculate_color(struct tpg_data *tpg, int k)
int r = tpg_colors[col].r;
int g = tpg_colors[col].g;
int b = tpg_colors[col].b;
+   int y, cb, cr;
+   bool ycbbr_valid = false;
 
if (k == TPG_COLOR_TEXTBG) {
col = tpg_get_textbg_color(tpg);
@@ -873,7 +875,6 @@ static void precalculate_color(struct tpg_data *tpg, int k)
 tpg->saturation != 128 || tpg->hue) &&
tpg->color_enc != TGP_COLOR_ENC_LUMA) {
/* Implement these operations */
-   int y, cb, cr;
int tmp_cb, tmp_cr;
 
/* First convert to YCbCr */
@@ -890,13 +891,10 @@ static void precalculate_color(struct tpg_data *tpg, int 
k)
 
cb = (128 << 4) + (tmp_cb * tpg->contrast * tpg->saturation) / 
(128 * 128);
cr = (128 << 4) + (tmp_cr * tpg->contrast * tpg->saturation) / 
(128 * 128);
-   if (tpg->color_enc == TGP_COLOR_ENC_YUV) {
-   tpg->colors[k][0] = clamp(y >> 4, 1, 254);
-   tpg->colors[k][1] = clamp(cb >> 4, 1, 254);
-   tpg->colors[k][2] = clamp(cr >> 4, 1, 254);
-   return;
-   }
-   ycbcr_to_color(tpg, y, cb, cr, , , );
+   if (tpg->color_enc == TGP_COLOR_ENC_YUV)
+   ycbbr_valid = true;
+   else
+   ycbcr_to_color(tpg, y, cb, cr, , , );
} else if ((tpg->brightness != 128 || tpg->contrast != 128) &&
   tpg->color_enc == TGP_COLOR_ENC_LUMA) {
r = (16 << 4) + ((r - (16 << 4)) * tpg->contrast) / 128;
@@ -917,9 +915,8 @@ static void precalculate_color(struct tpg_data *tpg, int k)
case TGP_COLOR_ENC_YUV:
{
/* Convert to YCbCr */
-   int y, cb, cr;
-
-   color_to_ycbcr(tpg, r, g, b, , , );
+   if (!ycbbr_valid)
+   color_to_ycbcr(tpg, r, g, b, , , );
 
if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) {
y = clamp(y, 16 << 4, 235 << 4);
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 6/9] [media] vivid: Rename variable

2016-07-16 Thread 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.riba...@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 53e512f5a6b6..ba3fe65ceb98 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 (0x).
 */
-   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;
+ 

[PATCH v3 2/9] [media] Documentation: Add HSV format

2016-07-16 Thread Ricardo Ribalda Delgado
Describe the HSV formats

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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 ..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 ..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 `.)
 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 H

[PATCH v3 9/9] [media] vivid: Local optimization

2016-07-16 Thread Ricardo Ribalda Delgado
Avoid duplicated data shifts when possible.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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 1c862465e335..2c23c458b1a6 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, , , );
 
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

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 3/9] [media] Documentation: Add Ricardo Ribalda

2016-07-16 Thread Ricardo Ribalda Delgado
My initials were on the Changelog, but there was no link to my name.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 0/9] Add HSV format

2016-07-16 Thread 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:
v3:  Fix wrong handling of some YUV formats when brightness != 128

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

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

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

Ricardo Ribalda Delgado (9):
  [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

 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  |   9 +
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c  | 399 +
 drivers/media/platform/vivid/vivid-core.h  |   2 +-
 drivers/media/platform/vivid/vivid-vid-common.c|  66 ++--
 drivers/media/v4l2-core/v4l2-ioctl.c   |   2 +
 include/media/v4l2-tpg.h   |   9 +-
 include/uapi/linux/videodev2.h |   4 +
 10 files changed, 499 insertions(+), 170 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

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 7/9] [media] vivid: Introduce TPG_COLOR_ENC_LUMA

2016-07-16 Thread Ricardo Ribalda Delgado
Simplifies handling of Gray formats.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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 ba3fe65ceb98..e91bf3cbaab9 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, , , );
+   } 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_YUV:
return "YCbCr";
+   case TGP_COLOR_ENC_LUMA:
+   return "Luma";
case TGP_COLOR_ENC_RGB:
default:
return "RGB";
diff --git a/drivers/media/platform/vivid/vivid-vid-common.c 
b/drivers/media/platform/vivid/vivid-vid-common.c
index 869e26ea7cf5..b78bca4c2f16 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_YUV,
+   .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_YUV,
+   .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_YUV,
+   .color_enc = TGP_COLOR_ENC_LUMA,
.planes   = 1,
.buffers = 1,
},
diff -

[PATCH v3 1/9] [media] videodev2.h Add HSV formats

2016-07-16 Thread 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.riba...@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_MJPEGv4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG   
*/
 #define V4L2_PIX_FMT_JPEG v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG 
*/
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 4/9] [media] vivid: code refactor for color encoding

2016-07-16 Thread 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.riba...@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..e8d2bf388597 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_YUV;
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_YUV;
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_YUV;
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_YUV;
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_YUV;
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_YUV;
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_YUV;
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_YUV;
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-

[PATCH v3 5/9] [media] vivid: Add support for HSV formats

2016-07-16 Thread Ricardo Ribalda Delgado
This patch adds support for V4L2_PIX_FMT_HSV24 and V4L2_PIX_FMT_HSV32.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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 e8d2bf388597..53e512f5a6b6 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_YUV;
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, , , );
}
 
-   if (tpg->color_enc == TGP_COLOR_ENC_YUV) {
+   switch (tpg->color_enc) {
+   case TGP_COLOR_ENC_HSV:
+   {
+   int h, s, v;
+
+   color_to_hsv(tpg, r, g, b, , , );
+   tpg->colors[k][0] = h;
+   tpg->colors[k][1] = s;
+   tpg->colors[k][2] = v;
+   break;
+   }
+   case TGP_COLOR_ENC_YUV:
+   {
/* 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 precalcula

Re: [PATCH v2 2/6] [media] Documentation: Add HSV format

2016-07-16 Thread Ricardo Ribalda Delgado
Hi Laurent

It is actually a very good comment. :) In our case we have implemented
the format ourselves in the FPGA and we support both 0-255 and 0-179
Hue ranges.

After some weeks of use, only the 0-179 range is used in userpace. The
reasons for this is mainly that it is the format used by OpenCV
http://docs.opencv.org/3.1.0/de/d25/imgproc_color_conversions.html#color_convert_rgb_hsv=0
, but also because it is very efficient to convert from 0-360 to 0-180
and the lose of color resolution (256/180) does not lead to (human)
perceptible differences.

All that said, I would not mind to implement also the 0-255 range, but
I do not know which API should be the best way to do it. quantization?
it looks nice, but it is not really a quantization... a control? a bit
messy fourcc? seems good...

I am open to anything :), but I am not the right guy for making the
decision. Hans, could you help me?


Thanks!

On Fri, Jul 15, 2016 at 8:11 PM, Laurent Pinchart
<laurent.pinch...@ideasonboard.com> wrote:
> Hi Ricardo,
>
> Thank you for the patch.
>
> On Friday 15 Jul 2016 18:13:15 Ricardo Ribalda Delgado wrote:
>> Describe the HSV formats
>>
>> Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
>> ---
>>  Documentation/media/uapi/v4l/hsv-formats.rst   |  19 ++
>>  Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst | 253 ++
>>  Documentation/media/uapi/v4l/pixfmt.rst|   1 +
>>  Documentation/media/uapi/v4l/v4l2.rst  |   5 +
>>  4 files changed, 278 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 ..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 ..b297aa4f7ba6
>> --- /dev/null
>> +++ b/Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst
>> @@ -0,0 +1,253 @@
>> +.. -*- coding: utf-8; mode: rst -*-
>> +
>> +.. _packed-hsv:
>> +
>> +**
>> +Packed HSV formats
>> +**
>> +
>> +*man Packed HSV formats(2)*
>> +
>> +Packed HSV formats
>> +
>> +
>> +Description
>> +===
>> +
>> +The HUE (h) is meassured in degrees, one LSB represents two degrees.
>
> Is this common ? I have a device that can handle HSV data, I need to check how
> it maps the hue values to binary, but I'm pretty sure they cover the full
> 0-255 range. We would then have to support the two formats. Separate 4CCs are
> an option, but reporting the range separately (possibly through the colorspace
> API) might be better. Any thought on that ?
>
>> +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
>> +
>
> Do we really need all those blank lines ?
>
> [snip]
>
> --
> Regards,
>
> Laurent Pinchart
>



-- 
Ricardo Ribalda
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/6] [media] videodev2.h Add HSV formats

2016-07-15 Thread 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.riba...@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 28e5be2c2eef..4b67ad06efb7 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_MJPEGv4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG   
*/
 #define V4L2_PIX_FMT_JPEG v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG 
*/
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 6/6] [media] vivid: Rename variable

2016-07-15 Thread 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.riba...@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 85b9c1925dd9..dba6656082d8 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -1012,7 +1012,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 &&
@@ -1020,161 +1020,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 (0x).
 */
-   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;
+ 

[PATCH v2 2/6] [media] Documentation: Add HSV format

2016-07-15 Thread Ricardo Ribalda Delgado
Describe the HSV formats

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 Documentation/media/uapi/v4l/hsv-formats.rst   |  19 ++
 Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst | 253 +
 Documentation/media/uapi/v4l/pixfmt.rst|   1 +
 Documentation/media/uapi/v4l/v4l2.rst  |   5 +
 4 files changed, 278 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 ..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 ..b297aa4f7ba6
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst
@@ -0,0 +1,253 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _packed-hsv:
+
+**
+Packed HSV formats
+**
+
+*man Packed HSV formats(2)*
+
+Packed HSV formats
+
+
+Description
+===
+
+The HUE (h) is meassured 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 `.)
 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 

[PATCH v2 5/6] [media] vivid: Add support for HSV formats

2016-07-15 Thread Ricardo Ribalda Delgado
This patch adds support for V4L2_PIX_FMT_HSV24 and V4L2_PIX_FMT_HSV32.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c   | 94 +++--
 drivers/media/platform/vivid/vivid-vid-common.c | 14 
 include/media/v4l2-tpg.h|  1 +
 3 files changed, 105 insertions(+), 4 deletions(-)

diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c 
b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
index acf0e6854832..85b9c1925dd9 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -318,6 +318,10 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
tpg->hmask[0] = ~1;
tpg->color_representation = TGP_COLOR_REPRESENTATION_YUV;
break;
+   case V4L2_PIX_FMT_HSV24:
+   case V4L2_PIX_FMT_HSV32:
+   tpg->color_representation = TGP_COLOR_REPRESENTATION_HSV;
+   break;
default:
return false;
}
@@ -351,6 +355,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
break;
case V4L2_PIX_FMT_RGB24:
case V4L2_PIX_FMT_BGR24:
+   case V4L2_PIX_FMT_HSV24:
tpg->twopixelsize[0] = 2 * 3;
break;
case V4L2_PIX_FMT_BGR666:
@@ -361,6 +366,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
case V4L2_PIX_FMT_ARGB32:
case V4L2_PIX_FMT_ABGR32:
case V4L2_PIX_FMT_YUV32:
+   case V4L2_PIX_FMT_HSV32:
tpg->twopixelsize[0] = 2 * 4;
break;
case V4L2_PIX_FMT_NV12:
@@ -408,6 +414,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
tpg->twopixelsize[1] = 4;
break;
}
+
return true;
 }
 EXPORT_SYMBOL_GPL(tpg_s_fourcc);
@@ -490,6 +497,64 @@ static inline int linear_to_rec709(int v)
return tpg_linear_to_rec709[v];
 }
 
+static void color_to_hsv(struct tpg_data *tpg, int r, int g, int b,
+  int *h, int *s, int *v)
+{
+   int max_rgb, min_rgb, diff_rgb;
+   int aux;
+   int third;
+
+   r >>= 4;
+   g >>= 4;
+   b >>= 4;
+
+   /*V*/
+   max_rgb = max3(r, g, b);
+   *v = max_rgb;
+   if (!max_rgb) {
+   *h = 0;
+   *s = 0;
+   return;
+   }
+
+   /*S*/
+   min_rgb = min3(r, g, b);
+   diff_rgb = max_rgb - min_rgb;
+   aux = 255 * diff_rgb;
+   aux += max_rgb / 2;
+   aux /= max_rgb;
+   *s = aux;
+   if (!aux) {
+   *h = 0;
+   return;
+   }
+
+   /*H*/
+   if (max_rgb == r) {
+   aux =  g - b;
+   third = 0;
+   } else if (max_rgb == g) {
+   aux =  b - r;
+   third = 60;
+   } else {
+   aux =  r - g;
+   third = 120;
+   }
+
+   aux *= 30;
+   aux += diff_rgb / 2;
+   aux /= diff_rgb;
+   aux += third;
+
+   /*Clamp H*/
+   if (aux < 0)
+   aux += 180;
+   else if (aux > 180)
+   aux -= 180;
+   *h = aux;
+
+}
+
 static void rgb2ycbcr(const int m[3][3], int r, int g, int b,
int y_offset, int *y, int *cb, int *cr)
 {
@@ -829,7 +894,19 @@ static void precalculate_color(struct tpg_data *tpg, int k)
ycbcr_to_color(tpg, y, cb, cr, , , );
}
 
-   if (tpg->color_representation == TGP_COLOR_REPRESENTATION_YUV) {
+   switch (tpg->color_representation) {
+   case TGP_COLOR_REPRESENTATION_HSV:
+   {
+   int h, s, v;
+
+   color_to_hsv(tpg, r, g, b, , , );
+   tpg->colors[k][0] = h;
+   tpg->colors[k][1] = s;
+   tpg->colors[k][2] = v;
+   break;
+   }
+   case TGP_COLOR_REPRESENTATION_YUV:
+   {
/* Convert to YCbCr */
int y, cb, cr;
 
@@ -863,7 +940,10 @@ static void precalculate_color(struct tpg_data *tpg, int k)
tpg->colors[k][0] = y;
tpg->colors[k][1] = cb;
tpg->colors[k][2] = cr;
-   } else {
+   break;
+   }
+   case TGP_COLOR_REPRESENTATION_RGB:
+   {
if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) {
r = (r * 219) / 255 + (16 << 4);
g = (g * 219) / 255 + (16 << 4);
@@ -913,6 +993,8 @@ static void precalculate_color(struct tpg_data *tpg, int k)
tpg->colors[k][0] = r;
tpg->colors[k][1] = g;
tpg->colors[k][2] = b;
+   break;
+   }
}
 }
 
@@ -938,8 +1020,8 @@ static void gen_twopix(struct tpg_data *tpg,
alpha = 0;
if (color == TPG_COLOR_RANDOM)

[PATCH v2 4/6] [media] vivid: code refactor for color representation

2016-07-15 Thread Ricardo Ribalda Delgado
Replace is_yuv with color_representation. Which can be used by HSV
formats.

This change should ease the review of the following patches.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c   | 44 ++---
 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, 63 insertions(+), 42 deletions(-)

diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c 
b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
index cf1dadd0be9e..acf0e6854832 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_representation = TGP_COLOR_REPRESENTATION_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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
break;
default:
return false;
@@ -820,7 +820,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_representation == TGP_COLOR_REPRESENTATION_YUV) {
tpg->colors[k][0] = clamp(y >> 4, 1, 254);
tpg->colors[k][1] = clamp(cb >> 4, 1, 254);
tpg->colors[k][2] = clamp(cr >> 4, 1, 254);
@@ -829,7 +829,7 @@ static void precalculate_color(struct tpg_data *tpg, int k)
ycbcr_to_color(tpg, y, cb, cr, , , );
}
 
-   if (tpg->is_yuv) {
+   if (tpg->color_representation == TGP_COLOR_REPRESENTATION_YUV) 

[PATCH v2 0/6] Add HSV format

2016-07-15 Thread 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 in three to ease the reviewing process.

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

Thanks!

Changelog
v2: Suggested by Mauro Carvalho Chehab <mche...@osg.samsung.com>,
-Rebase on top of docs-next (port documentation to .rst)
@mchehab, You were right, there was no conflict after the rebase, Thanks!

Ricardo Ribalda Delgado (6):
  [media] videodev2.h Add HSV formats
  [media] Documentation: Add HSV format
  [media] Documentation: Add Ricardo Ribalda
  [media] vivid: code refactor for color representation
  [media] vivid: Add support for HSV formats
  [media] vivid: Rename variable

 Documentation/media/uapi/v4l/hsv-formats.rst   |  19 ++
 Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst | 253 +++
 Documentation/media/uapi/v4l/pixfmt.rst|   1 +
 Documentation/media/uapi/v4l/v4l2.rst  |   9 +
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c  | 341 ++---
 drivers/media/platform/vivid/vivid-core.h  |   2 +-
 drivers/media/platform/vivid/vivid-vid-common.c|  66 ++--
 drivers/media/v4l2-core/v4l2-ioctl.c   |   2 +
 include/media/v4l2-tpg.h   |   8 +-
 include/uapi/linux/videodev2.h |   4 +
 10 files changed, 558 insertions(+), 147 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

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/6] [media] Documentation: Add Ricardo Ribalda

2016-07-15 Thread Ricardo Ribalda Delgado
My initials were on the Changelog, but there was no link to my name.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@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

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/6] [media] Documentation: Add HSV format

2016-07-15 Thread Ricardo Ribalda Delgado
Hi Mauro

On Fri, Jul 15, 2016 at 5:28 PM, Mauro Carvalho Chehab
 wrote:
> Hi Ricardo,
>
> I'm not seeing patch 1.

That is because you blacklisted me :P
https://lkml.org/lkml/2016/7/15/455

I resend it to you right away.


>
> Anyway, please send documentation patches against the rst files. They're
> at the "docs-next" branch and will be merged upstream on this merge window.
>

you are absolutely right, I read about it in lwn. Sorry about that.


How do you prefer it:
- 2 patchset : One on top of media/master with the code changes, and
one on top of docs-next with the doc changes.
or
-1 patchset on top of doc-next and we will figure out later if there
is a merge conflict with media

Thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/6] [media] videodev2.h Add HSV formats

2016-07-15 Thread 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.riba...@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_MJPEGv4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG   
*/
 #define V4L2_PIX_FMT_JPEG v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG 
*/
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/6] [media] vivid: Add support for HSV formats

2016-07-15 Thread Ricardo Ribalda Delgado
This patch adds support for V4L2_PIX_FMT_HSV24 and V4L2_PIX_FMT_HSV32.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c   | 94 +++--
 drivers/media/platform/vivid/vivid-vid-common.c | 14 
 include/media/v4l2-tpg.h|  1 +
 3 files changed, 105 insertions(+), 4 deletions(-)

diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c 
b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
index 3cab77ea92a4..d87a7a6a6b22 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -318,6 +318,10 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
tpg->hmask[0] = ~1;
tpg->color_representation = TGP_COLOR_REPRESENTATION_YUV;
break;
+   case V4L2_PIX_FMT_HSV24:
+   case V4L2_PIX_FMT_HSV32:
+   tpg->color_representation = TGP_COLOR_REPRESENTATION_HSV;
+   break;
default:
return false;
}
@@ -351,6 +355,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
break;
case V4L2_PIX_FMT_RGB24:
case V4L2_PIX_FMT_BGR24:
+   case V4L2_PIX_FMT_HSV24:
tpg->twopixelsize[0] = 2 * 3;
break;
case V4L2_PIX_FMT_BGR666:
@@ -361,6 +366,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
case V4L2_PIX_FMT_ARGB32:
case V4L2_PIX_FMT_ABGR32:
case V4L2_PIX_FMT_YUV32:
+   case V4L2_PIX_FMT_HSV32:
tpg->twopixelsize[0] = 2 * 4;
break;
case V4L2_PIX_FMT_NV12:
@@ -408,6 +414,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
tpg->twopixelsize[1] = 4;
break;
}
+
return true;
 }
 EXPORT_SYMBOL_GPL(tpg_s_fourcc);
@@ -490,6 +497,64 @@ static inline int linear_to_rec709(int v)
return tpg_linear_to_rec709[v];
 }
 
+static void color_to_hsv(struct tpg_data *tpg, int r, int g, int b,
+  int *h, int *s, int *v)
+{
+   int max_rgb, min_rgb, diff_rgb;
+   int aux;
+   int third;
+
+   r >>= 4;
+   g >>= 4;
+   b >>= 4;
+
+   /*V*/
+   max_rgb = max3(r, g, b);
+   *v = max_rgb;
+   if (!max_rgb) {
+   *h = 0;
+   *s = 0;
+   return;
+   }
+
+   /*S*/
+   min_rgb = min3(r, g, b);
+   diff_rgb = max_rgb - min_rgb;
+   aux = 255 * diff_rgb;
+   aux += max_rgb / 2;
+   aux /= max_rgb;
+   *s = aux;
+   if (!aux) {
+   *h = 0;
+   return;
+   }
+
+   /*H*/
+   if (max_rgb == r) {
+   aux =  g - b;
+   third = 0;
+   } else if (max_rgb == g) {
+   aux =  b - r;
+   third = 60;
+   } else {
+   aux =  r - g;
+   third = 120;
+   }
+
+   aux *= 30;
+   aux += diff_rgb / 2;
+   aux /= diff_rgb;
+   aux += third;
+
+   /*Clamp H*/
+   if (aux < 0)
+   aux += 180;
+   else if (aux > 180)
+   aux -= 180;
+   *h = aux;
+
+}
+
 static void rgb2ycbcr(const int m[3][3], int r, int g, int b,
int y_offset, int *y, int *cb, int *cr)
 {
@@ -829,7 +894,19 @@ static void precalculate_color(struct tpg_data *tpg, int k)
ycbcr_to_color(tpg, y, cb, cr, , , );
}
 
-   if (tpg->color_representation == TGP_COLOR_REPRESENTATION_YUV) {
+   switch (tpg->color_representation) {
+   case TGP_COLOR_REPRESENTATION_HSV:
+   {
+   int h, s, v;
+
+   color_to_hsv(tpg, r, g, b, , , );
+   tpg->colors[k][0] = h;
+   tpg->colors[k][1] = s;
+   tpg->colors[k][2] = v;
+   break;
+   }
+   case TGP_COLOR_REPRESENTATION_YUV:
+   {
/* Convert to YCbCr */
int y, cb, cr;
 
@@ -863,7 +940,10 @@ static void precalculate_color(struct tpg_data *tpg, int k)
tpg->colors[k][0] = y;
tpg->colors[k][1] = cb;
tpg->colors[k][2] = cr;
-   } else {
+   break;
+   }
+   case TGP_COLOR_REPRESENTATION_RGB:
+   {
if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) {
r = (r * 219) / 255 + (16 << 4);
g = (g * 219) / 255 + (16 << 4);
@@ -913,6 +993,8 @@ static void precalculate_color(struct tpg_data *tpg, int k)
tpg->colors[k][0] = r;
tpg->colors[k][1] = g;
tpg->colors[k][2] = b;
+   break;
+   }
}
 }
 
@@ -938,8 +1020,8 @@ static void gen_twopix(struct tpg_data *tpg,
alpha = 0;
if (color == TPG_COLOR_RANDOM)

[PATCH 4/6] [media] vivid: code refactor for color representation

2016-07-15 Thread Ricardo Ribalda Delgado
Replace is_yuv with color_representation. Which can be used by HSV
formats.

This change should ease the review of the following patches.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c   | 44 ++---
 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, 63 insertions(+), 42 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..3cab77ea92a4 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_representation = TGP_COLOR_REPRESENTATION_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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
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_representation = TGP_COLOR_REPRESENTATION_YUV;
break;
default:
return false;
@@ -820,7 +820,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_representation == TGP_COLOR_REPRESENTATION_YUV) {
tpg->colors[k][0] = clamp(y >> 4, 1, 254);
tpg->colors[k][1] = clamp(cb >> 4, 1, 254);
tpg->colors[k][2] = clamp(cr >> 4, 1, 254);
@@ -829,7 +829,7 @@ static void precalculate_color(struct tpg_data *tpg, int k)
ycbcr_to_color(tpg, y, cb, cr, , , );
}
 
-   if (tpg->is_yuv) {
+   if (tpg->color_representation == TGP_COLOR_REPRESENTATION_YUV) 

[PATCH 2/6] [media] Documentation: Add HSV format

2016-07-15 Thread Ricardo Ribalda Delgado
Describe the HSV formats.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 .../DocBook/media/v4l/pixfmt-packed-hsv.xml| 195 +
 Documentation/DocBook/media/v4l/pixfmt.xml |  13 ++
 Documentation/DocBook/media/v4l/v4l2.xml   |   8 +
 3 files changed, 216 insertions(+)
 create mode 100644 Documentation/DocBook/media/v4l/pixfmt-packed-hsv.xml

diff --git a/Documentation/DocBook/media/v4l/pixfmt-packed-hsv.xml 
b/Documentation/DocBook/media/v4l/pixfmt-packed-hsv.xml
new file mode 100644
index ..3b41d567e32b
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/pixfmt-packed-hsv.xml
@@ -0,0 +1,195 @@
+
+  
+Packed HSV formats
+
+  
+  
+Packed HSV formats
+Packed HSV formats
+  
+  
+Description
+
+The HUE (h) is meassured in degrees, one LSB represents two
+degrees. The SATURATION (s) and the VALUE (v) are meassured in percentage
+of the cylinder: 0 being the smallest value and 255 the maximum.
+The values are packed in 24 or 32 bit formats. 
+
+
+  Packed YUV Image Formats
+  
+   
+   
+   
+
+   
+   
+   
+   
+   
+   
+   
+   
+
+   
+   
+   
+   
+   
+   
+   
+   
+
+   
+   
+   
+   
+   
+   
+   
+   
+
+   
+   
+   
+   
+   
+   
+   
+   
+
+   
+   
+   
+   
+   
+ 
+   Identifier
+   Code
+   
+   Byte0 in memory
+   Byte1
+   Byte2
+   Byte3
+ 
+ 
+   
+   
+   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
+   'HSV4'
+   
+   -
+   -
+   -
+   -
+   -
+   -
+   -
+   -
+   
+   h7
+   h6
+   h5
+   h4
+   h3
+   h2
+   h1
+   h0
+   
+   s7
+   s6
+   s5
+   s4
+   s3
+   s2
+   s1
+   s0
+   
+   v7
+   v6
+   v5
+   v4
+   v3
+   v2
+   v1
+   v0
+ 
+ 
+   V4L2_PIX_FMT_HSV24
+   'HSV3'
+   
+   h7
+   h6
+   h5
+   h4
+   h3
+   h2
+   h1
+   h0
+   
+   s7
+   s6
+   s5
+   s4
+   s3
+   s2
+   s1
+   s0
+   
+   v7
+   v6
+   v5
+   v4
+   v3
+   v2
+   v1
+   v0
+ 
+   
+  
+
+
+Bit 7 is the most significant bit.
+
+  
+
diff --git a/Documentation/DocBook/media/v4l/pixfmt.xml 
b/Documentation/DocBook/media/v4l/pixfmt.xml
index 5a08aeea4360..7b081a6bdc61 100644
--- a/Documentation/DocBook/media/v4l/pixfmt.xml
+++ b/Documentation/DocBook/media/v4l/pixfmt.xml
@@ -1740,6 +1740,19 @@ extended control 
V4L2_CID_MPEG_STREAM_TYPE, see
 
   
 
+  
+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. 
+
+
+
+  
+
   
 SDR Formats
 
diff --git a/Documentation/DocBook/media/v4l/v4l2.xml 
b/Documentation/DocBook/media/v4l/v4l2.xml
index 42e626d6c936..f38039b7c338 100644
--- a/Documentation/DocBook/media/v4l/v4l2.xml
+++ b/Documentation/DocBook/media/v4l/v4l2.xml
@@ -152,6 +152,14 @@ structs, ioctls) must be noted in more detail in the 
history chapter
 (compat.xml), along with the possible impact on existing drivers and
 applications. -->
   
+   4.8
+   2016-07-15
+   rr
+Introduce HSV formats.
+   
+  
+
+  
4.5
2015-10-29
rr
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/6] Add HSV format

2016-07-15 Thread 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 in three to ease the reviewing process.

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

Thanks!

Ricardo Ribalda Delgado (6):
  [media] videodev2.h Add HSV formats
  [media] Documentation: Add HSV format
  [media] Documentation: Add Ricardo Ribalda as author
  [media] vivid: code refactor for color representation
  [media] vivid: Add support for HSV formats
  [media] vivid: Rename variable

 .../DocBook/media/v4l/pixfmt-packed-hsv.xml| 195 
 Documentation/DocBook/media/v4l/pixfmt.xml |  13 +
 Documentation/DocBook/media/v4l/v4l2.xml   |  19 ++
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c  | 341 ++---
 drivers/media/platform/vivid/vivid-core.h  |   2 +-
 drivers/media/platform/vivid/vivid-vid-common.c|  66 ++--
 drivers/media/v4l2-core/v4l2-ioctl.c   |   2 +
 include/media/v4l2-tpg.h   |   8 +-
 include/uapi/linux/videodev2.h |   4 +
 9 files changed, 503 insertions(+), 147 deletions(-)
 create mode 100644 Documentation/DocBook/media/v4l/pixfmt-packed-hsv.xml

-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 6/6] [media] vivid: Rename variable

2016-07-15 Thread 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.riba...@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 d87a7a6a6b22..1711a9cd20c4 100644
--- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
+++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c
@@ -1012,7 +1012,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 &&
@@ -1020,161 +1020,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 (0x).
 */
-   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;
+ 

[PATCH 3/6] [media] Documentation: Add Ricardo Ribalda as author

2016-07-15 Thread Ricardo Ribalda Delgado
My initials were on the Changelog, but there was no link to my mail.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 Documentation/DocBook/media/v4l/v4l2.xml | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/v4l2.xml 
b/Documentation/DocBook/media/v4l/v4l2.xml
index f38039b7c338..e09839d56113 100644
--- a/Documentation/DocBook/media/v4l/v4l2.xml
+++ b/Documentation/DocBook/media/v4l/v4l2.xml
@@ -117,6 +117,17 @@ Remote Controller chapter.
  

   
+
+  
+   Ricardo
+   Ribalda
+   HSV formats and minor fixes.
+   
+ 
+   ricardo.riba...@gmail.com
+ 
+   
+  
 
 
 
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 2/4] vb2: Merge vb2_internal_dqbuf and vb2_dqbuf

2016-06-20 Thread Ricardo Ribalda Delgado
After all the code refactoring, vb2_internal_dqbuf is only called by
vb2_dqbuf.

Since the function it is very simple, there is no need to have two
functions.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/v4l2-core/videobuf2-v4l2.c | 39 ++--
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c 
b/drivers/media/v4l2-core/videobuf2-v4l2.c
index 6d14df3d615d..7dff2b688a9f 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -621,27 +621,6 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 }
 EXPORT_SYMBOL_GPL(vb2_qbuf);
 
-static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b,
-   bool nonblocking)
-{
-   int ret;
-
-   if (b->type != q->type) {
-   dprintk(1, "invalid buffer type\n");
-   return -EINVAL;
-   }
-
-   ret = vb2_core_dqbuf(q, NULL, b, nonblocking);
-
-   /*
-*  After calling the VIDIOC_DQBUF V4L2_BUF_FLAG_DONE must be
-*  cleared.
-*/
-   b->flags &= ~V4L2_BUF_FLAG_DONE;
-
-   return ret;
-}
-
 /**
  * vb2_dqbuf() - Dequeue a buffer to the userspace
  * @q: videobuf2 queue
@@ -665,11 +644,27 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct 
v4l2_buffer *b,
  */
 int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
 {
+   int ret;
+
if (vb2_fileio_is_active(q)) {
dprintk(1, "file io in progress\n");
return -EBUSY;
}
-   return vb2_internal_dqbuf(q, b, nonblocking);
+
+   if (b->type != q->type) {
+   dprintk(1, "invalid buffer type\n");
+   return -EINVAL;
+   }
+
+   ret = vb2_core_dqbuf(q, NULL, b, nonblocking);
+
+   /*
+*  After calling the VIDIOC_DQBUF V4L2_BUF_FLAG_DONE must be
+*  cleared.
+*/
+   b->flags &= ~V4L2_BUF_FLAG_DONE;
+
+   return ret;
 }
 EXPORT_SYMBOL_GPL(vb2_dqbuf);
 
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 4/4] vb2: Fix comment

2016-06-20 Thread Ricardo Ribalda Delgado
The comment was referencing the wrong function.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/v4l2-core/videobuf2-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 633fc1ab1d7a..ba6ab8b7311f 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1845,7 +1845,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
 * Make sure to call buf_finish for any queued buffers. Normally
 * that's done in dqbuf, but that's not going to happen when we
 * cancel the whole queue. Note: this code belongs here, not in
-* __vb2_dqbuf() since in vb2_internal_dqbuf() there is a critical
+* __vb2_dqbuf() since in vb2_core_dqbuf() there is a critical
 * call to __fill_user_buffer() after buf_finish(). That order can't
 * be changed, so we can't move the buf_finish() to __vb2_dqbuf().
 */
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 1/4] vb2: V4L2_BUF_FLAG_DONE is set after DQBUF

2016-06-20 Thread Ricardo Ribalda Delgado
According to the doc, V4L2_BUF_FLAG_DONE is cleared after DQBUF:

V4L2_BUF_FLAG_DONE 0x0004  ... After calling the VIDIOC_QBUF or
VIDIOC_DQBUF it is always cleared ...

Unfortunately, it seems that videobuf2 keeps it set after DQBUF. This
can be tested with vivid and dev_debug:

[257604.338082] video1: VIDIOC_DQBUF: 71:33:25.00260479 index=3,
type=vid-cap, flags=0x2004, field=none, sequence=163,
memory=userptr, bytesused=460800, offset/userptr=0x344b000,
length=460800

This patch forces FLAG_DONE to 0 after calling DQBUF.

Reported-by: Dimitrios Katsaros <patcherw...@gmail.com>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/v4l2-core/videobuf2-v4l2.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c 
b/drivers/media/v4l2-core/videobuf2-v4l2.c
index 7f366f1b0377..6d14df3d615d 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -633,6 +633,12 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct 
v4l2_buffer *b,
 
ret = vb2_core_dqbuf(q, NULL, b, nonblocking);
 
+   /*
+*  After calling the VIDIOC_DQBUF V4L2_BUF_FLAG_DONE must be
+*  cleared.
+*/
+   b->flags &= ~V4L2_BUF_FLAG_DONE;
+
return ret;
 }
 
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 3/4] vb2: Merge vb2_internal_qbuf and vb2_qbuf

2016-06-20 Thread Ricardo Ribalda Delgado
After all the code refactoring, vb2_internal_dqbuf is only called by
vb2_dqbuf.

Since the function it is very simple, there is no need to have
two functions.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/v4l2-core/videobuf2-v4l2.c | 14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c 
b/drivers/media/v4l2-core/videobuf2-v4l2.c
index 7dff2b688a9f..9cfbb6e4bc28 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -427,7 +427,7 @@ static int __fill_vb2_buffer(struct vb2_buffer *vb,
if (V4L2_TYPE_IS_OUTPUT(b->type)) {
/*
 * For output buffers mask out the timecode flag:
-* this will be handled later in vb2_internal_qbuf().
+* this will be handled later in vb2_qbuf().
 * The 'field' is valid metadata for this output buffer
 * and so that needs to be copied here.
 */
@@ -586,13 +586,6 @@ int vb2_create_bufs(struct vb2_queue *q, struct 
v4l2_create_buffers *create)
 }
 EXPORT_SYMBOL_GPL(vb2_create_bufs);
 
-static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
-{
-   int ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
-
-   return ret ? ret : vb2_core_qbuf(q, b->index, b);
-}
-
 /**
  * vb2_qbuf() - Queue a buffer from userspace
  * @q: videobuf2 queue
@@ -612,12 +605,15 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct 
v4l2_buffer *b)
  */
 int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
+   int ret;
+
if (vb2_fileio_is_active(q)) {
dprintk(1, "file io in progress\n");
return -EBUSY;
}
 
-   return vb2_internal_qbuf(q, b);
+   ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
+   return ret ? ret : vb2_core_qbuf(q, b->index, b);
 }
 EXPORT_SYMBOL_GPL(vb2_qbuf);
 
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/4] vb2: Merge vb2_internal_dqbuf and vb2_dqbuf

2016-06-20 Thread Ricardo Ribalda Delgado
After all the code refactoring, vb2_internal_dqbuf is only called by
vb2_dqbuf.

Since the function it is very simple, there is no need to have two
functions.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/v4l2-core/videobuf2-v4l2.c | 27 +++
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c 
b/drivers/media/v4l2-core/videobuf2-v4l2.c
index 7f366f1b0377..07d8b409ce05 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -621,21 +621,6 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 }
 EXPORT_SYMBOL_GPL(vb2_qbuf);
 
-static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b,
-   bool nonblocking)
-{
-   int ret;
-
-   if (b->type != q->type) {
-   dprintk(1, "invalid buffer type\n");
-   return -EINVAL;
-   }
-
-   ret = vb2_core_dqbuf(q, NULL, b, nonblocking);
-
-   return ret;
-}
-
 /**
  * vb2_dqbuf() - Dequeue a buffer to the userspace
  * @q: videobuf2 queue
@@ -659,11 +644,21 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct 
v4l2_buffer *b,
  */
 int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
 {
+   int ret;
+
if (vb2_fileio_is_active(q)) {
dprintk(1, "file io in progress\n");
return -EBUSY;
}
-   return vb2_internal_dqbuf(q, b, nonblocking);
+
+   if (b->type != q->type) {
+   dprintk(1, "invalid buffer type\n");
+   return -EINVAL;
+   }
+
+   ret = vb2_core_dqbuf(q, NULL, b, nonblocking);
+
+   return ret;
 }
 EXPORT_SYMBOL_GPL(vb2_dqbuf);
 
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 4/4] vb2: V4L2_BUF_FLAG_DONE is set after DQBUF

2016-06-20 Thread Ricardo Ribalda Delgado
According to the doc, V4L2_BUF_FLAG_DONE is cleared after DQBUF:

V4L2_BUF_FLAG_DONE 0x0004  ... After calling the VIDIOC_QBUF or
VIDIOC_DQBUF it is always cleared ...

Unfortunately, it seems that videobuf2 keeps it set after DQBUF. This
can be tested with vivid and dev_debug:

[257604.338082] video1: VIDIOC_DQBUF: 71:33:25.00260479 index=3,
type=vid-cap, flags=0x2004, field=none, sequence=163,
memory=userptr, bytesused=460800, offset/userptr=0x344b000,
length=460800

This patch forces FLAG_DONE to 0 after calling DQBUF.

Reported-by: Dimitrios Katsaros <patcherw...@gmail.com>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/v4l2-core/videobuf2-v4l2.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c 
b/drivers/media/v4l2-core/videobuf2-v4l2.c
index ba3467468e55..9cfbb6e4bc28 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -654,6 +654,12 @@ int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, 
bool nonblocking)
 
ret = vb2_core_dqbuf(q, NULL, b, nonblocking);
 
+   /*
+*  After calling the VIDIOC_DQBUF V4L2_BUF_FLAG_DONE must be
+*  cleared.
+*/
+   b->flags &= ~V4L2_BUF_FLAG_DONE;
+
return ret;
 }
 EXPORT_SYMBOL_GPL(vb2_dqbuf);
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/4] vb2: Fix comment

2016-06-20 Thread Ricardo Ribalda Delgado
The comment was referencing the wrong function.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/v4l2-core/videobuf2-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 633fc1ab1d7a..ba6ab8b7311f 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1845,7 +1845,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
 * Make sure to call buf_finish for any queued buffers. Normally
 * that's done in dqbuf, but that's not going to happen when we
 * cancel the whole queue. Note: this code belongs here, not in
-* __vb2_dqbuf() since in vb2_internal_dqbuf() there is a critical
+* __vb2_dqbuf() since in vb2_core_dqbuf() there is a critical
 * call to __fill_user_buffer() after buf_finish(). That order can't
 * be changed, so we can't move the buf_finish() to __vb2_dqbuf().
 */
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/4] vb2: Merge vb2_internal_qbuf and vb2_qbuf

2016-06-20 Thread Ricardo Ribalda Delgado
After all the code refactoring, vb2_internal_dqbuf is only called by
vb2_dqbuf.

Since the function it is very simple, there is no need to have
two functions.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/v4l2-core/videobuf2-v4l2.c | 14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c 
b/drivers/media/v4l2-core/videobuf2-v4l2.c
index 07d8b409ce05..ba3467468e55 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -427,7 +427,7 @@ static int __fill_vb2_buffer(struct vb2_buffer *vb,
if (V4L2_TYPE_IS_OUTPUT(b->type)) {
/*
 * For output buffers mask out the timecode flag:
-* this will be handled later in vb2_internal_qbuf().
+* this will be handled later in vb2_qbuf().
 * The 'field' is valid metadata for this output buffer
 * and so that needs to be copied here.
 */
@@ -586,13 +586,6 @@ int vb2_create_bufs(struct vb2_queue *q, struct 
v4l2_create_buffers *create)
 }
 EXPORT_SYMBOL_GPL(vb2_create_bufs);
 
-static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
-{
-   int ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
-
-   return ret ? ret : vb2_core_qbuf(q, b->index, b);
-}
-
 /**
  * vb2_qbuf() - Queue a buffer from userspace
  * @q: videobuf2 queue
@@ -612,12 +605,15 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct 
v4l2_buffer *b)
  */
 int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
+   int ret;
+
if (vb2_fileio_is_active(q)) {
dprintk(1, "file io in progress\n");
return -EBUSY;
}
 
-   return vb2_internal_qbuf(q, b);
+   ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
+   return ret ? ret : vb2_core_qbuf(q, b->index, b);
 }
 EXPORT_SYMBOL_GPL(vb2_qbuf);
 
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] v4l2-compliance: Check V4L2_BUF_FLAG_DONE

2016-06-20 Thread Ricardo Ribalda Delgado
According to the doc, V4L2_BUF_FLAG_DONE is cleared after DQBUF and
QBUF:

V4L2_BUF_FLAG_DONE 0x0004  ... After calling the VIDIOC_QBUF or
VIDIOC_DQBUF it is always cleared ..

This patch implements this check.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---

Hello Hans!

Maybe you do not want to add this check to every dqbuf/qbuf in the code.
Please let me know to make a v2 of this patch.

Thanks!

 utils/v4l2-compliance/v4l2-test-buffers.cpp | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/utils/v4l2-compliance/v4l2-test-buffers.cpp 
b/utils/v4l2-compliance/v4l2-test-buffers.cpp
index 6c5ed5579f12..4d25870942bd 100644
--- a/utils/v4l2-compliance/v4l2-test-buffers.cpp
+++ b/utils/v4l2-compliance/v4l2-test-buffers.cpp
@@ -719,7 +719,9 @@ static int captureBufs(struct node *node, const cv4l_queue 
,
fail_on_test(memcmp(_timecode(), 
_buf.timecode,

sizeof(orig_buf.timecode)));
}
+   fail_on_test(buf.g_flags() & V4L2_BUF_FLAG_DONE);
fail_on_test(buf.qbuf(node));
+   fail_on_test(buf.g_flags() & V4L2_BUF_FLAG_DONE);
if (--count == 0)
break;
}
@@ -746,7 +748,9 @@ static int captureBufs(struct node *node, const cv4l_queue 
,
fail_on_test(memcmp(_timecode(), 
_buf.timecode,

sizeof(orig_buf.timecode)));
}
+   fail_on_test(buf.g_flags() & V4L2_BUF_FLAG_DONE);
fail_on_test(buf.qbuf(node));
+   fail_on_test(buf.g_flags() & V4L2_BUF_FLAG_DONE);
}
if (use_poll)
fcntl(node->g_fd(), F_SETFL, fd_flags);
@@ -778,6 +782,7 @@ static int setupM2M(struct node *node, cv4l_queue )
 
fail_on_test(buf.querybuf(node, i));
fail_on_test(buf.qbuf(node));
+   fail_on_test(buf.g_flags() & V4L2_BUF_FLAG_DONE);
}
if (v4l_type_is_video(q.g_type())) {
cv4l_fmt fmt(q.g_type());
@@ -828,6 +833,7 @@ static int bufferOutputErrorTest(struct node *node, const 
buffer _buf)
}
}
fail_on_test(buf.qbuf(node, false));
+   fail_on_test(buf.g_flags() & V4L2_BUF_FLAG_DONE);
for (unsigned p = 0; p < buf.g_num_planes(); p++) {
fail_on_test(buf.g_bytesused(p) != buf.g_length(p));
fail_on_test(buf.g_data_offset(p));
@@ -864,6 +870,7 @@ static int setupMmap(struct node *node, cv4l_queue )
}
 
fail_on_test(buf.qbuf(node));
+   fail_on_test(buf.g_flags() & V4L2_BUF_FLAG_DONE);
fail_on_test(!buf.qbuf(node));
fail_on_test(!buf.prepare_buf(node));
// Test with invalid buffer index
@@ -926,6 +933,7 @@ int testMmap(struct node *node, unsigned frame_count)
 
fail_on_test(buf.querybuf(node, i));
fail_on_test(buf.qbuf(node));
+   fail_on_test(buf.g_flags() & V4L2_BUF_FLAG_DONE);
}
// calling STREAMOFF...
fail_on_test(node->streamoff(q.g_type()));
@@ -936,6 +944,7 @@ int testMmap(struct node *node, unsigned frame_count)
 
fail_on_test(buf.querybuf(node, i));
fail_on_test(buf.qbuf(node));
+   fail_on_test(buf.g_flags() & V4L2_BUF_FLAG_DONE);
}
// Now request buffers again, freeing the old buffers.
// Good check for whether all the internal vb2 calls are in
@@ -1041,6 +1050,7 @@ static int setupUserPtr(struct node *node, cv4l_queue )
}
 
fail_on_test(buf.qbuf(node));
+   fail_on_test(buf.g_flags() & V4L2_BUF_FLAG_DONE);
fail_on_test(buf.querybuf(node, i));
fail_on_test(buf.check(q, Queued, i));
}
@@ -1142,6 +1152,7 @@ static int setupDmaBuf(struct node *expbuf_node, struct 
node *node,
}
 
fail_on_test(buf.qbuf(node));
+   fail_on_test(buf.g_flags() & V4L2_BUF_FLAG_DONE);
fail_on_test(buf.querybuf(node, i));
fail_on_test(buf.check(q, Queued, i));
}
@@ -1319,6 +1330,7 @@ static int testStreaming(struct node *node, unsigned 
frame_count)
if (alternate)
field ^= 1;
fail_on_test(node->qbuf(buf));
+   fail_on_test(buf.g_flags() & V4L2_BUF_FLAG_DONE);
}
fail_on_test(node->streamon());
 
@@ -1327,10 +1339,12

Re: [PATCH] vb2: V4L2_BUF_FLAG_DONE is set after DQBUF

2016-06-20 Thread Ricardo Ribalda Delgado
Good catch :)

I will prepare the new version. Btw, can I also merge
vb2_internal_dqbuf and vb2_dqbuf in one function? Seems a bit
overkilled that split.

Regarding v42l_compliance... I can take care of that if you dare :)

Best regards!

On Mon, Jun 20, 2016 at 11:53 AM, Hans Verkuil <hverk...@xs4all.nl> wrote:
> On 06/20/2016 11:01 AM, Ricardo Ribalda Delgado wrote:
>> According to the doc, V4L2_BUF_FLAG_DONE is cleared after DQBUF:
>>
>> V4L2_BUF_FLAG_DONE 0x0004  ... After calling the VIDIOC_QBUF or
>> VIDIOC_DQBUF it is always cleared ...
>>
>> Unfortunately, it seems that videobuf2 keeps it set after DQBUF. This
>> can be tested with vivid and dev_debug:
>>
>> [257604.338082] video1: VIDIOC_DQBUF: 71:33:25.00260479 index=3,
>> type=vid-cap, flags=0x2004, field=none, sequence=163,
>> memory=userptr, bytesused=460800, offset/userptr=0x344b000,
>> length=460800
>>
>> This patch changes the order when fill_user_buffer() is called,
>> to follow the documentation.
>>
>> Reported-by: Dimitrios Katsaros <patcherw...@gmail.com>
>> Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
>
> Sorry, this won't work. Calling __vb2_dqbuf will overwrite the state
> VB2_BUF_STATE_ERROR and so the V4L2_BUF_FLAG_ERROR flag will never be
> set. The same is true for the last 'if' in the __fill_v4l2_buffer()
> function.
>
> I think it might be better to keep this code and instead change the
> vb2_internal_dqbuf function to just clear the DONE flag after calling
> vb2_core_dqbuf.
>
> It would be nice to have a v4l2_compliance check for this as well.
>
> Regards,
>
> Hans
>
>> ---
>>  drivers/media/v4l2-core/videobuf2-core.c | 8 
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
>> b/drivers/media/v4l2-core/videobuf2-core.c
>> index 633fc1ab1d7a..63981f28075e 100644
>> --- a/drivers/media/v4l2-core/videobuf2-core.c
>> +++ b/drivers/media/v4l2-core/videobuf2-core.c
>> @@ -1771,10 +1771,6 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int 
>> *pindex, void *pb,
>>   if (pindex)
>>   *pindex = vb->index;
>>
>> - /* Fill buffer information for the userspace */
>> - if (pb)
>> - call_void_bufop(q, fill_user_buffer, vb, pb);
>> -
>>   /* Remove from videobuf queue */
>>   list_del(>queued_entry);
>>   q->queued_count--;
>> @@ -1784,6 +1780,10 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int 
>> *pindex, void *pb,
>>   /* go back to dequeued state */
>>   __vb2_dqbuf(vb);
>>
>> + /* Fill buffer information for the userspace */
>> + if (pb)
>> + call_void_bufop(q, fill_user_buffer, vb, pb);
>> +
>>   dprintk(1, "dqbuf of buffer %d, with state %d\n",
>>   vb->index, vb->state);
>>
>>



-- 
Ricardo Ribalda
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] vb2: V4L2_BUF_FLAG_DONE is set after DQBUF

2016-06-20 Thread Ricardo Ribalda Delgado
According to the doc, V4L2_BUF_FLAG_DONE is cleared after DQBUF:

V4L2_BUF_FLAG_DONE 0x0004  ... After calling the VIDIOC_QBUF or
VIDIOC_DQBUF it is always cleared ...

Unfortunately, it seems that videobuf2 keeps it set after DQBUF. This
can be tested with vivid and dev_debug:

[257604.338082] video1: VIDIOC_DQBUF: 71:33:25.00260479 index=3,
type=vid-cap, flags=0x2004, field=none, sequence=163,
memory=userptr, bytesused=460800, offset/userptr=0x344b000,
length=460800

This patch changes the order when fill_user_buffer() is called,
to follow the documentation.

Reported-by: Dimitrios Katsaros <patcherw...@gmail.com>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.riba...@gmail.com>
---
 drivers/media/v4l2-core/videobuf2-core.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 633fc1ab1d7a..63981f28075e 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1771,10 +1771,6 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int 
*pindex, void *pb,
if (pindex)
*pindex = vb->index;
 
-   /* Fill buffer information for the userspace */
-   if (pb)
-   call_void_bufop(q, fill_user_buffer, vb, pb);
-
/* Remove from videobuf queue */
list_del(>queued_entry);
q->queued_count--;
@@ -1784,6 +1780,10 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int 
*pindex, void *pb,
/* go back to dequeued state */
__vb2_dqbuf(vb);
 
+   /* Fill buffer information for the userspace */
+   if (pb)
+   call_void_bufop(q, fill_user_buffer, vb, pb);
+
dprintk(1, "dqbuf of buffer %d, with state %d\n",
vb->index, vb->state);
 
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RFC: HSV format

2016-05-24 Thread Ricardo Ribalda Delgado
Hi

HSV is a  cylindrical-coordinate representation of a color. It is very
useful for computer vision because the Hue component can be used to
segment a scene.

My plan was to add a format in videodev2.h and then add support for
vivid, libv4l2-convert and qv4l2.

There are also plans to prepare a patch for opencv to use this format
without any software conversion, and also for Gstreamer... but all
these changes depend on the changes on videodev2.h

The question is how open would be the linux-media community for such a
change, considering that there is no real device driver using it in
tree ( Our hardware is currently out of tree_

Today we only have an HSV format on v4l2-mediabus.h
V4L2_MBUS_FROM_MEDIA_BUS_FMT(AHSV_1X32), but no HSV format on
videodev2.h


Thanks!!!



-- 
Ricardo Ribalda
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  1   2   3   4   5   >