Add HSV format
Subsystems (2)
v3 cover Add HSV format
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 <[email protected]> -Remove unneeded empty lines on .rst file
Thanks!
Suggested by Hans Verkuil <[email protected]>
-Rebase over master and docs-next
-Introduce TPG_COLOR_ENC_LUMA for gray formats
-CodeStyle
Thanks!
v2: Suggested by Mauro Carvalho Chehab <[email protected]>, -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
Signature · 1 line
2.8.1
PATCH v3 1/9 videodev2.h Add 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.
--- drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++ include/uapi/linux/videodev2.h | 4 ++++ 2 files changed, 6 insertions(+)
drivers/media/v4l2-core/v4l2-ioctl.c +2 -0
@@ -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 ;
include/uapi/linux/videodev2.h +4 -0
@@ -580,6 +580,10 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_SRGGB12 v4l2_fourcc('R', 'G', '1', '2')/* 12 RGRG.. GBGB.. */ #define V4L2_PIX_FMT_SBGGR16 v4l2_fourcc('B', 'Y', 'R', '2')/* 16 BGBG.. GRGR.. */ +/* HSV formats */ +#define V4L2_PIX_FMT_HSV24 v4l2_fourcc('H', 'S', 'V', '3') +#define V4L2_PIX_FMT_HSV32 v4l2_fourcc('H', 'S', 'V', '4') +/* compressed formats */ #define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M', 'J', 'P', 'G')/* Motion-JPEG */ #define V4L2_PIX_FMT_JPEG v4l2_fourcc('J', 'P', 'E', 'G')/* JFIF JPEG */
Signature · 1 line
2.8.1
PATCH v3 2/9 Documentation: Add HSV format
In reply to Ricardo Ribalda DelgadoDescribe the HSV formats
--- 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
Documentation/media/uapi/v4l/hsv-formats.rst new file +19 -0
@@ -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
Documentation/media/uapi/v4l/pixfmt-packed-hsv.rst new file +158 -0
158 lines not on this page · raw message
Documentation/media/uapi/v4l/pixfmt.rst +1 -0
@@ -29,6 +29,7 @@ see also :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>`.) pixfmt-indexed pixfmt-rgb yuv-formats + hsv-formats depth-formats pixfmt-013 sdr-formats
Documentation/media/uapi/v4l/v4l2.rst +5 -0
@@ -85,6 +85,11 @@ part can be used and distributed without restrictions. Revision History **************** +:revision: 4.8 / 2016-07-15 (*rr*) + +Introduce HSV formats. + + :revision: 4.5 / 2015-10-29 (*rr*) Extend VIDIOC_G_EXT_CTRLS;. Replace ctrl_class with a new union with
Signature · 1 line
2.8.1
PATCH v3 3/9 Documentation: Add Ricardo Ribalda
In reply to Ricardo Ribalda DelgadoMy initials were on the Changelog, but there was no link to my name.
--- Documentation/media/uapi/v4l/v4l2.rst | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/media/uapi/v4l/v4l2.rst +4 -0
@@ -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.
Signature · 1 line
2.8.1
PATCH v3 4/9 vivid: code refactor for color encoding
In reply to Ricardo Ribalda DelgadoReplace 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.
--- 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(-)
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +33 -16
@@ -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->color_enc ==TGP_COLOR_ENC_RGB ) { +/* * Clamp r, g and b to the limited range and convert to full * range since that's what we deliver.
@@ -820,7 +823,7 @@ static void precalculate_color(struct tpg_data *tpg, int k) cb = (128 <<4 ) + (tmp_cb * tpg->contrast * tpg->saturation) / (128 *128 ); cr = (128 <<4 ) + (tmp_cr * tpg->contrast * tpg->saturation) / (128 *128 ); -if (tpg->is_yuv) { +if (tpg->color_enc ==TGP_COLOR_ENC_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 +832,7 @@ static void precalculate_color(struct tpg_data *tpg, int k)ycbcr_to_color (tpg, y, cb, cr, &r, &g, &b); } -if (tpg->is_yuv) { +if (tpg->color_enc ==TGP_COLOR_ENC_YUV ) {/* Convert to YCbCr */ int y, cb, cr;
@@ -1842,7 +1845,8 @@ static void tpg_recalc(struct tpg_data *tpg)if (tpg->quantization ==V4L2_QUANTIZATION_DEFAULT ) tpg->real_quantization = -V4L2_MAP_QUANTIZATION_DEFAULT (!tpg->is_yuv, +V4L2_MAP_QUANTIZATION_DEFAULT ( + tpg->color_enc !=TGP_COLOR_ENC_YUV , tpg->colorspace, tpg->real_ycbcr_enc);tpg_precalculate_colors (tpg);
@@ -1889,11 +1893,24 @@ static int tpg_pattern_avg(const struct tpg_data *tpg,return -1 ; } +static const char *tpg_color_enc_str (enum tgp_color_enc + color_enc) +{ +switch (color_enc) { +case TGP_COLOR_ENC_YUV : +return "YCbCr" ; +case TGP_COLOR_ENC_RGB : +default : +return "RGB" ; + + } +} +void tpg_log_status (struct tpg_data *tpg) {pr_info ("tpg source WxH: %ux%u (%s)\n" , - tpg->src_width, tpg->src_height, - tpg->is_yuv ?"YCbCr" :"RGB" ); + tpg->src_width, tpg->src_height, +tpg_color_enc_str (tpg->color_enc));pr_info ("tpg field: %u\n" , tpg->field);pr_info ("tpg crop: %ux%u@%dx%d\n" , tpg->crop.width, tpg->crop.height, tpg->crop.left, tpg->crop.top);
drivers/media/platform/vivid/vivid-core.h +1 -1
@@ -80,7 +80,7 @@ extern unsigned vivid_debug;struct vivid_fmt {u32 fourcc;/* v4l2 format id */ -bool is_yuv; +enum tgp_color_enc color_enc;bool can_do_overlay;u8 vdownsampling[TPG_MAX_PLANES ];u32 alpha_mask;
drivers/media/platform/vivid/vivid-vid-common.c +26 -26
208 lines not on this page · raw message
include/media/v4l2-tpg.h +6 -1
@@ -87,6 +87,11 @@ enum tpg_move_mode { TPG_MOVE_POS_FAST, }; +enum tgp_color_enc { +TGP_COLOR_ENC_RGB , +TGP_COLOR_ENC_YUV , +}; +extern const char *const tpg_aspect_strings[];#define TPG_MAX_PLANES 3
@@ -119,7 +124,7 @@ struct tpg_data {u8 saturation;s16 hue;u32 fourcc; -bool is_yuv; +enum tgp_color_enc color_enc;u32 colorspace;u32 xfer_func;u32 ycbcr_enc;
Signature · 1 line
2.8.1
PATCH v3 5/9 vivid: Add support for HSV formats
In reply to Ricardo Ribalda DelgadoThis patch adds support for V4L2_PIX_FMT_HSV24 and V4L2_PIX_FMT_HSV32.
--- 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(-)
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +89 -4
@@ -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, &r, &g, &b); } -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, &h, &s, &v); + 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 precalculated U, V */ b_v = tpg->colors[color][2 ];/* B or precalculated V */ switch (tpg->fourcc) {
@@ -1124,6 +1205,7 @@ static void gen_twopix(struct tpg_data *tpg, buf[0 ][offset +1 ] = (g_u <<5 ) | b_v;break ;case V4L2_PIX_FMT_RGB24 : +case V4L2_PIX_FMT_HSV24 : buf[0 ][offset] = r_y; buf[0 ][offset +1 ] = g_u; buf[0 ][offset +2 ] = b_v;
@@ -1141,6 +1223,7 @@ static void gen_twopix(struct tpg_data *tpg,break ;case V4L2_PIX_FMT_RGB32 :case V4L2_PIX_FMT_XRGB32 : +case V4L2_PIX_FMT_HSV32 : alpha =0 ;/* fall through */ case V4L2_PIX_FMT_YUV32 :
@@ -1897,6 +1980,8 @@ static const char *tpg_color_enc_str(enum tgp_color_enc color_enc) {switch (color_enc) { +case TGP_COLOR_ENC_HSV : +return "HSV" ;case TGP_COLOR_ENC_YUV :return "YCbCr" ;case TGP_COLOR_ENC_RGB :
drivers/media/platform/vivid/vivid-vid-common.c +14 -0
@@ -445,6 +445,20 @@ struct vivid_fmt vivid_formats[] = { .planes = 1, .buffers = 1, }, + { + .fourcc = V4L2_PIX_FMT_HSV24, /* HSV 24bits */ + .vdownsampling = { 1 }, + .bit_depth = { 24 }, + .planes = 1, + .buffers = 1, + }, + { + .fourcc = V4L2_PIX_FMT_HSV32, /* HSV 32bits */ + .vdownsampling = { 1 }, + .bit_depth = { 32 }, + .planes = 1, + .buffers = 1, + }, /* Multiplanar formats */
include/media/v4l2-tpg.h +1 -0
@@ -90,6 +90,7 @@ enum tpg_move_mode {enum tgp_color_enc {TGP_COLOR_ENC_RGB ,TGP_COLOR_ENC_YUV , +TGP_COLOR_ENC_HSV , };extern const char *const tpg_aspect_strings[];
Signature · 1 line
2.8.1
PATCH v3 6/9 vivid: Rename variable
In reply to Ricardo Ribalda Delgador_y and g_u now also contain the H and V components on the HSV formats. Rename the variables to reflect this.
--- drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 209 +++++++++++++------------- 1 file changed, 105 insertions(+), 104 deletions(-)
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +105 -104
@@ -1014,7 +1014,7 @@ static void gen_twopix(struct tpg_data *tpg, {unsigned offset = odd * tpg->twopixelsize[0 ] /2 ;u8 alpha = tpg->alpha_component; -u8 r_y, g_u, b_v; +u8 r_y_h, g_u_s, b_v; if (tpg->alpha_red_only && color != TPG_COLOR_CSC_RED && color != TPG_COLOR_100_RED &&
@@ -1022,161 +1022,161 @@ static void gen_twopix(struct tpg_data *tpg, alpha =0 ;if (color ==TPG_COLOR_RANDOM )precalculate_color (tpg, color); - r_y = tpg->colors[color][0 ];/* R or precalculated Y, H */ - g_u = tpg->colors[color][1 ];/* G or precalculated U, V */ + r_y_h = tpg->colors[color][0 ];/* R or precalculated Y, H */ + g_u_s = tpg->colors[color][1 ];/* G or precalculated U, V */ b_v = tpg->colors[color][2 ];/* B or precalculated V */ switch (tpg->fourcc) {case V4L2_PIX_FMT_GREY : - buf[0 ][offset] = r_y; + buf[0 ][offset] = r_y_h;break ;case V4L2_PIX_FMT_Y16 :/* -* Ideally both bytes should be set to r_y, but then you won't +* Ideally both bytes should be set to r_y_h, but then you won't * be able to detect endian problems. So keep it 0 except for -* the corner case where r_y is 0xff so white really will be +* the corner case where r_y_h is 0xff so white really will be * white (0xffff). */ - buf[0 ][offset] = r_y ==0xff ? r_y :0 ; - buf[0 ][offset+1 ] = r_y; + buf[0 ][offset] = r_y_h ==0xff ? r_y_h :0 ; + buf[0 ][offset+1 ] = r_y_h;break ;case V4L2_PIX_FMT_Y16_BE :/* See comment for V4L2_PIX_FMT_Y16 above */ - buf[0 ][offset] = r_y; - buf[0 ][offset+1 ] = r_y ==0xff ? r_y :0 ; + buf[0 ][offset] = r_y_h; + buf[0 ][offset+1 ] = r_y_h ==0xff ? r_y_h :0 ;break ;case V4L2_PIX_FMT_YUV422M :case V4L2_PIX_FMT_YUV422P :case V4L2_PIX_FMT_YUV420 :case V4L2_PIX_FMT_YUV420M : - buf[0 ][offset] = r_y; + buf[0 ][offset] = r_y_h;if (odd) { - buf[1 ][0 ] = (buf[1 ][0 ] + g_u) /2 ; + buf[1 ][0 ] = (buf[1 ][0 ] + g_u_s) /2 ; buf[2 ][0 ] = (buf[2 ][0 ] + b_v) /2 ; buf[1 ][1 ] = buf[1 ][0 ]; buf[2 ][1 ] = buf[2 ][0 ];break ; } - buf[1 ][0 ] = g_u; + buf[1 ][0 ] = g_u_s; buf[2 ][0 ] = b_v;break ;case V4L2_PIX_FMT_YVU422M :case V4L2_PIX_FMT_YVU420 :case V4L2_PIX_FMT_YVU420M : - buf[0 ][offset] = r_y; + buf[0 ][offset] = r_y_h;if (odd) { buf[1 ][0 ] = (buf[1 ][0 ] + b_v) /2 ; - buf[2 ][0 ] = (buf[2 ][0 ] + g_u) /2 ; + buf[2 ][0 ] = (buf[2 ][0 ] + g_u_s) /2 ; buf[1 ][1 ] = buf[1 ][0 ]; buf[2 ][1 ] = buf[2 ][0 ];break ; } buf[1 ][0 ] = b_v; - buf[2 ][0 ] = g_u; + buf[2 ][0 ] = g_u_s;break ;case V4L2_PIX_FMT_NV12 :case V4L2_PIX_FMT_NV12M :case V4L2_PIX_FMT_NV16 :case V4L2_PIX_FMT_NV16M : - buf[0 ][offset] = r_y; + buf[0 ][offset] = r_y_h;if (odd) { - buf[1 ][0 ] = (buf[1 ][0 ] + g_u) /2 ; + buf[1 ][0 ] = (buf[1 ][0 ] + g_u_s) /2 ; buf[1 ][1 ] = (buf[1 ][1 ] + b_v) /2 ;break ; } - buf[1 ][0 ] = g_u; + buf[1 ][0 ] = g_u_s; buf[1 ][1 ] = b_v;break ;case V4L2_PIX_FMT_NV21 :case V4L2_PIX_FMT_NV21M :case V4L2_PIX_FMT_NV61 :case V4L2_PIX_FMT_NV61M : - buf[0 ][offset] = r_y; + buf[0 ][offset] = r_y_h;if (odd) { buf[1 ][0 ] = (buf[1 ][0 ] + b_v) /2 ; - buf[1 ][1 ] = (buf[1 ][1 ] + g_u) /2 ; + buf[1 ][1 ] = (buf[1 ][1 ] + g_u_s) /2 ;break ; } buf[1 ][0 ] = b_v; - buf[1 ][1 ] = g_u; + buf[1 ][1 ] = g_u_s;break ;case V4L2_PIX_FMT_YUV444M : - buf[0 ][offset] = r_y; - buf[1 ][offset] = g_u; + buf[0 ][offset] = r_y_h; + buf[1 ][offset] = g_u_s; buf[2 ][offset] = b_v;break ;case V4L2_PIX_FMT_YVU444M : - buf[0 ][offset] = r_y; + buf[0 ][offset] = r_y_h; buf[1 ][offset] = b_v; - buf[2 ][offset] = g_u; + buf[2 ][offset] = g_u_s;break ;case V4L2_PIX_FMT_NV24 : - buf[0 ][offset] = r_y; - buf[1 ][2 * offset] = g_u; + buf[0 ][offset] = r_y_h; + buf[1 ][2 * offset] = g_u_s; buf[1 ][2 * offset +1 ] = b_v;break ;case V4L2_PIX_FMT_NV42 : - buf[0 ][offset] = r_y; + buf[0 ][offset] = r_y_h; buf[1 ][2 * offset] = b_v; - buf[1 ][2 * offset +1 ] = g_u; + buf[1 ][2 * offset +1 ] = g_u_s;break ;case V4L2_PIX_FMT_YUYV : - buf[0 ][offset] = r_y; + buf[0 ][offset] = r_y_h;if (odd) { - buf[0 ][1 ] = (buf[0 ][1 ] + g_u) /2 ; + buf[0 ][1 ] = (buf[0 ][1 ] + g_u_s) /2 ; buf[0 ][3 ] = (buf[0 ][3 ] + b_v) /2 ;break ; } - buf[0 ][1 ] = g_u; + buf[0 ][1 ] = g_u_s; buf[0 ][3 ] = b_v;break ;case V4L2_PIX_FMT_UYVY : - buf[0 ][offset +1 ] = r_y; + buf[0 ][offset +1 ] = r_y_h;if (odd) { - buf[0 ][0 ] = (buf[0 ][0 ] + g_u) /2 ; + buf[0 ][0 ] = (buf[0 ][0 ] + g_u_s) /2 ; buf[0 ][2 ] = (buf[0 ][2 ] + b_v) /2 ;break ; } - buf[0 ][0 ] = g_u; + buf[0 ][0 ] = g_u_s; buf[0 ][2 ] = b_v;break ;case V4L2_PIX_FMT_YVYU : - buf[0 ][offset] = r_y; + buf[0 ][offset] = r_y_h;if (odd) { buf[0 ][1 ] = (buf[0 ][1 ] + b_v) /2 ; - buf[0 ][3 ] = (buf[0 ][3 ] + g_u) /2 ; + buf[0 ][3 ] = (buf[0 ][3 ] + g_u_s) /2 ;break ; } buf[0 ][1 ] = b_v; - buf[0 ][3 ] = g_u; + buf[0 ][3 ] = g_u_s;break ;case V4L2_PIX_FMT_VYUY : - buf[0 ][offset +1 ] = r_y; + buf[0 ][offset +1 ] = r_y_h;if (odd) { buf[0 ][0 ] = (buf[0 ][0 ] + b_v) /2 ; - buf[0 ][2 ] = (buf[0 ][2 ] + g_u) /2 ; + buf[0 ][2 ] = (buf[0 ][2 ] + g_u_s) /2 ;break ; } buf[0 ][0 ] = b_v; - buf[0 ][2 ] = g_u; + buf[0 ][2 ] = g_u_s;break ;case V4L2_PIX_FMT_RGB332 : - buf[0 ][offset] = (r_y <<5 ) | (g_u <<2 ) | b_v; + buf[0 ][offset] = (r_y_h <<5 ) | (g_u_s <<2 ) | b_v;break ;case V4L2_PIX_FMT_YUV565 :case V4L2_PIX_FMT_RGB565 : - buf[0 ][offset] = (g_u <<5 ) | b_v; - buf[0 ][offset +1 ] = (r_y <<3 ) | (g_u >>3 ); + buf[0 ][offset] = (g_u_s <<5 ) | b_v; + buf[0 ][offset +1 ] = (r_y_h <<3 ) | (g_u_s >>3 );break ;case V4L2_PIX_FMT_RGB565X : - buf[0 ][offset] = (r_y <<3 ) | (g_u >>3 ); - buf[0 ][offset +1 ] = (g_u <<5 ) | b_v; + buf[0 ][offset] = (r_y_h <<3 ) | (g_u_s >>3 ); + buf[0 ][offset +1 ] = (g_u_s <<5 ) | b_v;break ;case V4L2_PIX_FMT_RGB444 :case V4L2_PIX_FMT_XRGB444 :
@@ -1184,8 +1184,8 @@ static void gen_twopix(struct tpg_data *tpg,/* fall through */ case V4L2_PIX_FMT_YUV444 :case V4L2_PIX_FMT_ARGB444 : - buf[0 ][offset] = (g_u <<4 ) | b_v; - buf[0 ][offset +1 ] = (alpha &0xf0 ) | r_y; + buf[0 ][offset] = (g_u_s <<4 ) | b_v; + buf[0 ][offset +1 ] = (alpha &0xf0 ) | r_y_h;break ;case V4L2_PIX_FMT_RGB555 :case V4L2_PIX_FMT_XRGB555 :
@@ -1193,32 +1193,33 @@ static void gen_twopix(struct tpg_data *tpg,/* fall through */ case V4L2_PIX_FMT_YUV555 :case V4L2_PIX_FMT_ARGB555 : - buf[0 ][offset] = (g_u <<5 ) | b_v; - buf[0 ][offset +1 ] = (alpha &0x80 ) | (r_y <<2 ) | (g_u >>3 ); + buf[0 ][offset] = (g_u_s <<5 ) | b_v; + buf[0 ][offset +1 ] = (alpha &0x80 ) | (r_y_h <<2 ) + | (g_u_s >>3 );break ;case V4L2_PIX_FMT_RGB555X :case V4L2_PIX_FMT_XRGB555X : alpha =0 ;/* fall through */ case V4L2_PIX_FMT_ARGB555X : - buf[0 ][offset] = (alpha &0x80 ) | (r_y <<2 ) | (g_u >>3 ); - buf[0 ][offset +1 ] = (g_u <<5 ) | b_v; + buf[0 ][offset] = (alpha &0x80 ) | (r_y_h <<2 ) | (g_u_s >>3 ); + buf[0 ][offset +1 ] = (g_u_s <<5 ) | b_v;break ;case V4L2_PIX_FMT_RGB24 :case V4L2_PIX_FMT_HSV24 : - buf[0 ][offset] = r_y; - buf[0 ][offset +1 ] = g_u; + buf[0 ][offset] = r_y_h; + buf[0 ][offset +1 ] = g_u_s; buf[0 ][offset +2 ] = b_v;break ;case V4L2_PIX_FMT_BGR24 : buf[0 ][offset] = b_v; - buf[0 ][offset +1 ] = g_u; - buf[0 ][offset +2 ] = r_y; + buf[0 ][offset +1 ] = g_u_s; + buf[0 ][offset +2 ] = r_y_h;break ;case V4L2_PIX_FMT_BGR666 : - buf[0 ][offset] = (b_v <<2 ) | (g_u >>4 ); - buf[0 ][offset +1 ] = (g_u <<4 ) | (r_y >>2 ); - buf[0 ][offset +2 ] = r_y <<6 ; + buf[0 ][offset] = (b_v <<2 ) | (g_u_s >>4 ); + buf[0 ][offset +1 ] = (g_u_s <<4 ) | (r_y_h >>2 ); + buf[0 ][offset +2 ] = r_y_h <<6 ; buf[0 ][offset +3 ] =0 ;break ;case V4L2_PIX_FMT_RGB32 :
@@ -1229,8 +1230,8 @@ static void gen_twopix(struct tpg_data *tpg,case V4L2_PIX_FMT_YUV32 :case V4L2_PIX_FMT_ARGB32 : buf[0 ][offset] = alpha; - buf[0 ][offset +1 ] = r_y; - buf[0 ][offset +2 ] = g_u; + buf[0 ][offset +1 ] = r_y_h; + buf[0 ][offset +2 ] = g_u_s; buf[0 ][offset +3 ] = b_v;break ;case V4L2_PIX_FMT_BGR32 :
@@ -1239,87 +1240,87 @@ static void gen_twopix(struct tpg_data *tpg,/* fall through */ case V4L2_PIX_FMT_ABGR32 : buf[0 ][offset] = b_v; - buf[0 ][offset +1 ] = g_u; - buf[0 ][offset +2 ] = r_y; + buf[0 ][offset +1 ] = g_u_s; + buf[0 ][offset +2 ] = r_y_h; buf[0 ][offset +3 ] = alpha;break ;case V4L2_PIX_FMT_SBGGR8 : - buf[0 ][offset] = odd ? g_u : b_v; - buf[1 ][offset] = odd ? r_y : g_u; + buf[0 ][offset] = odd ? g_u_s : b_v; + buf[1 ][offset] = odd ? r_y_h : g_u_s;break ;case V4L2_PIX_FMT_SGBRG8 : - buf[0 ][offset] = odd ? b_v : g_u; - buf[1 ][offset] = odd ? g_u : r_y; + buf[0 ][offset] = odd ? b_v : g_u_s; + buf[1 ][offset] = odd ? g_u_s : r_y_h;break ;case V4L2_PIX_FMT_SGRBG8 : - buf[0 ][offset] = odd ? r_y : g_u; - buf[1 ][offset] = odd ? g_u : b_v; + buf[0 ][offset] = odd ? r_y_h : g_u_s; + buf[1 ][offset] = odd ? g_u_s : b_v;break ;case V4L2_PIX_FMT_SRGGB8 : - buf[0 ][offset] = odd ? g_u : r_y; - buf[1 ][offset] = odd ? b_v : g_u; + buf[0 ][offset] = odd ? g_u_s : r_y_h; + buf[1 ][offset] = odd ? b_v : g_u_s;break ;case V4L2_PIX_FMT_SBGGR10 : - buf[0 ][offset] = odd ? g_u <<2 : b_v <<2 ; - buf[0 ][offset +1 ] = odd ? g_u >>6 : b_v >>6 ; - buf[1 ][offset] = odd ? r_y <<2 : g_u <<2 ; - buf[1 ][offset +1 ] = odd ? r_y >>6 : g_u >>6 ; + buf[0 ][offset] = odd ? g_u_s <<2 : b_v <<2 ; + buf[0 ][offset +1 ] = odd ? g_u_s >>6 : b_v >>6 ; + buf[1 ][offset] = odd ? r_y_h <<2 : g_u_s <<2 ; + buf[1 ][offset +1 ] = odd ? r_y_h >>6 : g_u_s >>6 ; buf[0 ][offset] |= (buf[0 ][offset] >>2 ) &3 ; buf[1 ][offset] |= (buf[1 ][offset] >>2 ) &3 ;break ;case V4L2_PIX_FMT_SGBRG10 : - buf[0 ][offset] = odd ? b_v <<2 : g_u <<2 ; - buf[0 ][offset +1 ] = odd ? b_v >>6 : g_u >>6 ; - buf[1 ][offset] = odd ? g_u <<2 : r_y <<2 ; - buf[1 ][offset +1 ] = odd ? g_u >>6 : r_y >>6 ; + buf[0 ][offset] = odd ? b_v <<2 : g_u_s <<2 ; + buf[0 ][offset +1 ] = odd ? b_v >>6 : g_u_s >>6 ; + buf[1 ][offset] = odd ? g_u_s <<2 : r_y_h <<2 ; + buf[1 ][offset +1 ] = odd ? g_u_s >>6 : r_y_h >>6 ; buf[0 ][offset] |= (buf[0 ][offset] >>2 ) &3 ; buf[1 ][offset] |= (buf[1 ][offset] >>2 ) &3 ;break ;case V4L2_PIX_FMT_SGRBG10 : - buf[0 ][offset] = odd ? r_y <<2 : g_u <<2 ; - buf[0 ][offset +1 ] = odd ? r_y >>6 : g_u >>6 ; - buf[1 ][offset] = odd ? g_u <<2 : b_v <<2 ; - buf[1 ][offset +1 ] = odd ? g_u >>6 : b_v >>6 ; + buf[0 ][offset] = odd ? r_y_h <<2 : g_u_s <<2 ; + buf[0 ][offset +1 ] = odd ? r_y_h >>6 : g_u_s >>6 ; + buf[1 ][offset] = odd ? g_u_s <<2 : b_v <<2 ; + buf[1 ][offset +1 ] = odd ? g_u_s >>6 : b_v >>6 ; buf[0 ][offset] |= (buf[0 ][offset] >>2 ) &3 ; buf[1 ][offset] |= (buf[1 ][offset] >>2 ) &3 ;break ;case V4L2_PIX_FMT_SRGGB10 : - buf[0 ][offset] = odd ? g_u <<2 : r_y <<2 ; - buf[0 ][offset +1 ] = odd ? g_u >>6 : r_y >>6 ; - buf[1 ][offset] = odd ? b_v <<2 : g_u <<2 ; - buf[1 ][offset +1 ] = odd ? b_v >>6 : g_u >>6 ; + buf[0 ][offset] = odd ? g_u_s <<2 : r_y_h <<2 ; + buf[0 ][offset +1 ] = odd ? g_u_s >>6 : r_y_h >>6 ; + buf[1 ][offset] = odd ? b_v <<2 : g_u_s <<2 ; + buf[1 ][offset +1 ] = odd ? b_v >>6 : g_u_s >>6 ; buf[0 ][offset] |= (buf[0 ][offset] >>2 ) &3 ; buf[1 ][offset] |= (buf[1 ][offset] >>2 ) &3 ;break ;case V4L2_PIX_FMT_SBGGR12 : - buf[0 ][offset] = odd ? g_u <<4 : b_v <<4 ; - buf[0 ][offset +1 ] = odd ? g_u >>4 : b_v >>4 ; - buf[1 ][offset] = odd ? r_y <<4 : g_u <<4 ; - buf[1 ][offset +1 ] = odd ? r_y >>4 : g_u >>4 ; + buf[0 ][offset] = odd ? g_u_s <<4 : b_v <<4 ; + buf[0 ][offset +1 ] = odd ? g_u_s >>4 : b_v >>4 ; + buf[1 ][offset] = odd ? r_y_h <<4 : g_u_s <<4 ; + buf[1 ][offset +1 ] = odd ? r_y_h >>4 : g_u_s >>4 ; buf[0 ][offset] |= (buf[0 ][offset] >>4 ) &0xf ; buf[1 ][offset] |= (buf[1 ][offset] >>4 ) &0xf ;break ;case V4L2_PIX_FMT_SGBRG12 : - buf[0 ][offset] = odd ? b_v <<4 : g_u <<4 ; - buf[0 ][offset +1 ] = odd ? b_v >>4 : g_u >>4 ; - buf[1 ][offset] = odd ? g_u <<4 : r_y <<4 ; - buf[1 ][offset +1 ] = odd ? g_u >>4 : r_y >>4 ; + buf[0 ][offset] = odd ? b_v <<4 : g_u_s <<4 ; + buf[0 ][offset +1 ] = odd ? b_v >>4 : g_u_s >>4 ; + buf[1 ][offset] = odd ? g_u_s <<4 : r_y_h <<4 ; + buf[1 ][offset +1 ] = odd ? g_u_s >>4 : r_y_h >>4 ; buf[0 ][offset] |= (buf[0 ][offset] >>4 ) &0xf ; buf[1 ][offset] |= (buf[1 ][offset] >>4 ) &0xf ;break ;case V4L2_PIX_FMT_SGRBG12 : - buf[0 ][offset] = odd ? r_y <<4 : g_u <<4 ; - buf[0 ][offset +1 ] = odd ? r_y >>4 : g_u >>4 ; - buf[1 ][offset] = odd ? g_u <<4 : b_v <<4 ; - buf[1 ][offset +1 ] = odd ? g_u >>4 : b_v >>4 ; + buf[0 ][offset] = odd ? r_y_h <<4 : g_u_s <<4 ; + buf[0 ][offset +1 ] = odd ? r_y_h >>4 : g_u_s >>4 ; + buf[1 ][offset] = odd ? g_u_s <<4 : b_v <<4 ; + buf[1 ][offset +1 ] = odd ? g_u_s >>4 : b_v >>4 ; buf[0 ][offset] |= (buf[0 ][offset] >>4 ) &0xf ; buf[1 ][offset] |= (buf[1 ][offset] >>4 ) &0xf ;break ;case V4L2_PIX_FMT_SRGGB12 : - buf[0 ][offset] = odd ? g_u <<4 : r_y <<4 ; - buf[0 ][offset +1 ] = odd ? g_u >>4 : r_y >>4 ; - buf[1 ][offset] = odd ? b_v <<4 : g_u <<4 ; - buf[1 ][offset +1 ] = odd ? b_v >>4 : g_u >>4 ; + buf[0 ][offset] = odd ? g_u_s <<4 : r_y_h <<4 ; + buf[0 ][offset +1 ] = odd ? g_u_s >>4 : r_y_h >>4 ; + buf[1 ][offset] = odd ? b_v <<4 : g_u_s <<4 ; + buf[1 ][offset +1 ] = odd ? b_v >>4 : g_u_s >>4 ; buf[0 ][offset] |= (buf[0 ][offset] >>4 ) &0xf ; buf[1 ][offset] |= (buf[1 ][offset] >>4 ) &0xf ;break ;
Signature · 1 line
2.8.1
PATCH v3 7/9 vivid: Introduce TPG_COLOR_ENC_LUMA
In reply to Ricardo Ribalda DelgadoSimplifies handling of Gray formats.
--- 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(-)
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +20 -6
@@ -234,10 +234,12 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)case V4L2_PIX_FMT_XBGR32 :case V4L2_PIX_FMT_ARGB32 :case V4L2_PIX_FMT_ABGR32 : + tpg->color_enc =TGP_COLOR_ENC_RGB ; +break ;case V4L2_PIX_FMT_GREY :case V4L2_PIX_FMT_Y16 :case V4L2_PIX_FMT_Y16_BE : - tpg->color_enc =TGP_COLOR_ENC_RGB ; + tpg->color_enc =TGP_COLOR_ENC_LUMA ;break ;case V4L2_PIX_FMT_YUV444 :case V4L2_PIX_FMT_YUV555 :
@@ -825,9 +827,9 @@ static void precalculate_color(struct tpg_data *tpg, int k) g <<=4 ; b <<=4 ; } -if (tpg->qual ==TPG_QUAL_GRAY || tpg->fourcc ==V4L2_PIX_FMT_GREY || - tpg->fourcc ==V4L2_PIX_FMT_Y16 || - tpg->fourcc ==V4L2_PIX_FMT_Y16_BE ) { + +if (tpg->qual ==TPG_QUAL_GRAY || + tpg->color_enc ==TGP_COLOR_ENC_LUMA ) {/* Rec. 709 Luma function */ /* (0.2126, 0.7152, 0.0722) * (255 * 256) */ r = g = b = (13879 * r +46688 * g +4713 * b) >>16 ;
@@ -867,8 +869,9 @@ static void precalculate_color(struct tpg_data *tpg, int k) b = (b - (16 <<4 )) *255 /219 ; } -if (tpg->brightness !=128 || tpg->contrast !=128 || - tpg->saturation !=128 || tpg->hue) { +if ((tpg->brightness !=128 || tpg->contrast !=128 || + tpg->saturation !=128 || tpg->hue) && + tpg->color_enc !=TGP_COLOR_ENC_LUMA ) {/* Implement these operations */ int y, cb, cr;int tmp_cb, tmp_cr;
@@ -894,6 +897,10 @@ static void precalculate_color(struct tpg_data *tpg, int k)return ; }ycbcr_to_color (tpg, y, cb, cr, &r, &g, &b); + }else if ((tpg->brightness !=128 || tpg->contrast !=128 ) && + tpg->color_enc ==TGP_COLOR_ENC_LUMA ) { + r = (16 <<4 ) + ((r - (16 <<4 )) * tpg->contrast) /128 ; + r += (tpg->brightness <<4 ) - (128 <<4 ); }switch (tpg->color_enc) {
@@ -944,6 +951,11 @@ static void precalculate_color(struct tpg_data *tpg, int k) tpg->colors[k][2 ] = cr;break ; } +case TGP_COLOR_ENC_LUMA : + { + tpg->colors[k][0 ] = r >>4 ; +break ; + }case TGP_COLOR_ENC_RGB : {if (tpg->real_quantization ==V4L2_QUANTIZATION_LIM_RANGE ) {
@@ -1985,6 +1997,8 @@ static const char *tpg_color_enc_str(enum tgp_color_encreturn "HSV" ;case TGP_COLOR_ENC_YUV :return "YCbCr" ; +case TGP_COLOR_ENC_LUMA : +return "Luma" ;case TGP_COLOR_ENC_RGB :default :return "RGB" ;
drivers/media/platform/vivid/vivid-vid-common.c +3 -3
@@ -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, },
include/media/v4l2-tpg.h +1 -0
@@ -91,6 +91,7 @@ enum tgp_color_enc {TGP_COLOR_ENC_RGB ,TGP_COLOR_ENC_YUV ,TGP_COLOR_ENC_HSV , + TGP_COLOR_ENC_LUMA, };extern const char *const tpg_aspect_strings[];
Signature · 1 line
2.8.1
PATCH v3 8/9 vivid: Fix YUV555 and YUV565 handling
In reply to Ricardo Ribalda Delgadoprecalculate_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.
--- drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +8 -11
@@ -797,6 +797,8 @@ static void precalculate_color(struct tpg_data *tpg, int k)int r = tpg_colors[col].r;int g = tpg_colors[col].g;int b = tpg_colors[col].b; +int y, cb, cr; +bool ycbbr_valid = false;if (k ==TPG_COLOR_TEXTBG ) { col =tpg_get_textbg_color (tpg);
@@ -873,7 +875,6 @@ static void precalculate_color(struct tpg_data *tpg, int k) tpg->saturation != 128 || tpg->hue) && tpg->color_enc != TGP_COLOR_ENC_LUMA) {/* Implement these operations */ -int y, cb, cr;int tmp_cb, tmp_cr;/* First convert to YCbCr */
@@ -890,13 +891,10 @@ static void precalculate_color(struct tpg_data *tpg, int k) cb = (128 <<4 ) + (tmp_cb * tpg->contrast * tpg->saturation) / (128 *128 ); cr = (128 <<4 ) + (tmp_cr * tpg->contrast * tpg->saturation) / (128 *128 ); -if (tpg->color_enc ==TGP_COLOR_ENC_YUV ) { - tpg->colors[k][0 ] =clamp (y >>4 ,1 ,254 ); - tpg->colors[k][1 ] =clamp (cb >>4 ,1 ,254 ); - tpg->colors[k][2 ] =clamp (cr >>4 ,1 ,254 ); -return ; - } -ycbcr_to_color (tpg, y, cb, cr, &r, &g, &b); +if (tpg->color_enc ==TGP_COLOR_ENC_YUV ) + ycbbr_valid = true; +else +ycbcr_to_color (tpg, y, cb, cr, &r, &g, &b); }else if ((tpg->brightness !=128 || tpg->contrast !=128 ) && tpg->color_enc ==TGP_COLOR_ENC_LUMA ) { r = (16 <<4 ) + ((r - (16 <<4 )) * tpg->contrast) /128 ;
@@ -917,9 +915,8 @@ static void precalculate_color(struct tpg_data *tpg, int k)case TGP_COLOR_ENC_YUV : {/* Convert to YCbCr */ -int y, cb, cr; - -color_to_ycbcr (tpg, r, g, b, &y, &cb, &cr); +if (!ycbbr_valid) +color_to_ycbcr (tpg, r, g, b, &y, &cb, &cr);if (tpg->real_quantization ==V4L2_QUANTIZATION_LIM_RANGE ) { y =clamp (y,16 <<4 ,235 <<4 );
Signature · 1 line
2.8.1
PATCH v3 9/9 vivid: Local optimization
In reply to Ricardo Ribalda DelgadoAvoid duplicated data shifts when possible.
--- drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +7 -6
@@ -919,13 +919,14 @@ static void precalculate_color(struct tpg_data *tpg, int k)color_to_ycbcr (tpg, r, g, b, &y, &cb, &cr);if (tpg->real_quantization ==V4L2_QUANTIZATION_LIM_RANGE ) { - y =clamp (y,16 <<4 ,235 <<4 ); - cb =clamp (cb,16 <<4 ,240 <<4 ); - cr =clamp (cr,16 <<4 ,240 <<4 ); + y =clamp (y >>4 ,16 ,235 ); + cb =clamp (cb >>4 ,16 ,240 ); + cr =clamp (cr >4 ,16 ,240 ); + }else { + y =clamp (y >>4 ,1 ,254 ); + cb =clamp (cb >>4 ,1 ,254 ); + cr =clamp (cr >>4 ,1 ,254 ); } - y =clamp (y >>4 ,1 ,254 ); - cb =clamp (cb >>4 ,1 ,254 ); - cr =clamp (cr >>4 ,1 ,254 );switch (tpg->fourcc) {case V4L2_PIX_FMT_YUV444 : y >>=4 ;
Signature · 1 line
2.8.1
Re: [PATCH v3 9/9] [media] vivid: Local optimization
Hi
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c static void precalculate_color(struct tpg_data *tpg, int k) · line 924
Quoted 4 lines · Ricardo Ribalda Delgado
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +3
-1- 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!
Re: [PATCH v3 4/9] [media] vivid: code refactor for color encoding
In reply to Ricardo Ribalda DelgadoQuoted 18 lines · Ricardo Ribalda Delgado
Replace
is_yuvwithcolor_encWhich 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 <[email protected]>--- 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(-)drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +0
-0
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c static int tpg_pattern_avg(const struct tpg_data *tpg, · line 1901
Quoted 9 lines
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +6
-0@@ -1889,11 +1893,24 @@ static int tpg_pattern_avg(const struct tpg_data *tpg,return -1 ; } +static const char *tpg_color_enc_str (enum tgp_color_enc + color_enc) +{ +switch (color_enc) { +case TGP_COLOR_ENC_YUV : +return "YCbCr" ;
Use "Y'CbCr"
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c static int tpg_pattern_avg(const struct tpg_data *tpg, · line 1904
Quoted 3 lines
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +3
-0+case TGP_COLOR_ENC_RGB : +default : +return "RGB" ;
and "R'G'B'".
That's more precise.
Quoted 19 lines
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +6
-2+ + } +} +void tpg_log_status (struct tpg_data *tpg) {pr_info ("tpg source WxH: %ux%u (%s)\n" , - tpg->src_width, tpg->src_height, - tpg->is_yuv ?"YCbCr" :"RGB" ); + tpg->src_width, tpg->src_height, +tpg_color_enc_str (tpg->color_enc));pr_info ("tpg field: %u\n" , tpg->field);pr_info ("tpg crop: %ux%u@%dx%d\n" , tpg->crop.width, tpg->crop.height, tpg->crop.left, tpg->crop.top);include/media/v4l2-tpg.h +0
-0
include/media/v4l2-tpg.h enum tpg_move_mode { · line 92
Quoted 6 lines
include/media/v4l2-tpg.h +3
-0@@ -87,6 +87,11 @@ enum tpg_move_mode { TPG_MOVE_POS_FAST, }; +enum tgp_color_enc { +TGP_COLOR_ENC_RGB , +TGP_COLOR_ENC_YUV ,
Rename this to YCBCR. It's the technically correct name.
Regards,
Hans
Quoted 15 lines
include/media/v4l2-tpg.h +3
-1+}; +extern const char *const tpg_aspect_strings[];#define TPG_MAX_PLANES 3@@ -119,7 +124,7 @@ struct tpg_data {u8 saturation;s16 hue;u32 fourcc; -bool is_yuv; +enum tgp_color_enc color_enc;u32 colorspace;u32 xfer_func;u32 ycbcr_enc;
Re: [PATCH v3 8/9] [media] vivid: Fix YUV555 and YUV565 handling
In reply to Ricardo Ribalda DelgadoQuoted 16 lines · 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 <[email protected]>--- drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +0
-0
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c static void precalculate_color(struct tpg_data *tpg, int k) · line 801
Quoted 5 lines
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +2
-0@@ -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;
I guess you mean ycbcr_valid?
Regards,
Hans
Quoted 42 lines
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +6
-11if (k ==TPG_COLOR_TEXTBG ) { col =tpg_get_textbg_color (tpg);@@ -873,7 +875,6 @@ static void precalculate_color(struct tpg_data *tpg, int k) tpg->saturation != 128 || tpg->hue) && tpg->color_enc != TGP_COLOR_ENC_LUMA) {/* Implement these operations */ -int y, cb, cr;int tmp_cb, tmp_cr;/* First convert to YCbCr */ @@ -890,13 +891,10 @@ static void precalculate_color(struct tpg_data *tpg, int k) cb = (128 <<4 ) + (tmp_cb * tpg->contrast * tpg->saturation) / (128 *128 ); cr = (128 <<4 ) + (tmp_cr * tpg->contrast * tpg->saturation) / (128 *128 ); -if (tpg->color_enc ==TGP_COLOR_ENC_YUV ) { - tpg->colors[k][0 ] =clamp (y >>4 ,1 ,254 ); - tpg->colors[k][1 ] =clamp (cb >>4 ,1 ,254 ); - tpg->colors[k][2 ] =clamp (cr >>4 ,1 ,254 ); -return ; - } -ycbcr_to_color (tpg, y, cb, cr, &r, &g, &b); +if (tpg->color_enc ==TGP_COLOR_ENC_YUV ) + ycbbr_valid = true; +else +ycbcr_to_color (tpg, y, cb, cr, &r, &g, &b); }else if ((tpg->brightness !=128 || tpg->contrast !=128 ) && tpg->color_enc ==TGP_COLOR_ENC_LUMA ) { r = (16 <<4 ) + ((r - (16 <<4 )) * tpg->contrast) /128 ;@@ -917,9 +915,8 @@ static void precalculate_color(struct tpg_data *tpg, int k)case TGP_COLOR_ENC_YUV : {/* Convert to YCbCr */ -int y, cb, cr; - -color_to_ycbcr (tpg, r, g, b, &y, &cb, &cr); +if (!ycbbr_valid) +color_to_ycbcr (tpg, r, g, b, &y, &cb, &cr);if (tpg->real_quantization ==V4L2_QUANTIZATION_LIM_RANGE ) { y =clamp (y,16 <<4 ,235 <<4 );
Re: [PATCH v3 8/9] [media] vivid: Fix YUV555 and YUV565 handling
Hi Hans
Quoted 4 lines · Hans Verkuil
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c static void precalculate_color(struct tpg_data *tpg, int k) · line 801
Quoted 2 lines
drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +2
-0+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!