Commit ca2b32da authored by Ricardo Ribalda Delgado's avatar Ricardo Ribalda Delgado Committed by Mauro Carvalho Chehab

[media] vivid: Introduce TPG_COLOR_ENC_LUMA

Simplifies handling of Gray formats.
Signed-off-by: default avatarRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Acked-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 25e90073
...@@ -234,10 +234,12 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc) ...@@ -234,10 +234,12 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
case V4L2_PIX_FMT_XBGR32: case V4L2_PIX_FMT_XBGR32:
case V4L2_PIX_FMT_ARGB32: case V4L2_PIX_FMT_ARGB32:
case V4L2_PIX_FMT_ABGR32: case V4L2_PIX_FMT_ABGR32:
tpg->color_enc = TGP_COLOR_ENC_RGB;
break;
case V4L2_PIX_FMT_GREY: case V4L2_PIX_FMT_GREY:
case V4L2_PIX_FMT_Y16: case V4L2_PIX_FMT_Y16:
case V4L2_PIX_FMT_Y16_BE: case V4L2_PIX_FMT_Y16_BE:
tpg->color_enc = TGP_COLOR_ENC_RGB; tpg->color_enc = TGP_COLOR_ENC_LUMA;
break; break;
case V4L2_PIX_FMT_YUV444: case V4L2_PIX_FMT_YUV444:
case V4L2_PIX_FMT_YUV555: case V4L2_PIX_FMT_YUV555:
...@@ -823,9 +825,9 @@ static void precalculate_color(struct tpg_data *tpg, int k) ...@@ -823,9 +825,9 @@ static void precalculate_color(struct tpg_data *tpg, int k)
g <<= 4; g <<= 4;
b <<= 4; b <<= 4;
} }
if (tpg->qual == TPG_QUAL_GRAY || tpg->fourcc == V4L2_PIX_FMT_GREY ||
tpg->fourcc == V4L2_PIX_FMT_Y16 || if (tpg->qual == TPG_QUAL_GRAY ||
tpg->fourcc == V4L2_PIX_FMT_Y16_BE) { tpg->color_enc == TGP_COLOR_ENC_LUMA) {
/* Rec. 709 Luma function */ /* Rec. 709 Luma function */
/* (0.2126, 0.7152, 0.0722) * (255 * 256) */ /* (0.2126, 0.7152, 0.0722) * (255 * 256) */
r = g = b = (13879 * r + 46688 * g + 4713 * b) >> 16; r = g = b = (13879 * r + 46688 * g + 4713 * b) >> 16;
...@@ -865,8 +867,9 @@ static void precalculate_color(struct tpg_data *tpg, int k) ...@@ -865,8 +867,9 @@ static void precalculate_color(struct tpg_data *tpg, int k)
b = (b - (16 << 4)) * 255 / 219; b = (b - (16 << 4)) * 255 / 219;
} }
if (tpg->brightness != 128 || tpg->contrast != 128 || if ((tpg->brightness != 128 || tpg->contrast != 128 ||
tpg->saturation != 128 || tpg->hue) { tpg->saturation != 128 || tpg->hue) &&
tpg->color_enc != TGP_COLOR_ENC_LUMA) {
/* Implement these operations */ /* Implement these operations */
int y, cb, cr; int y, cb, cr;
int tmp_cb, tmp_cr; int tmp_cb, tmp_cr;
...@@ -892,6 +895,10 @@ static void precalculate_color(struct tpg_data *tpg, int k) ...@@ -892,6 +895,10 @@ static void precalculate_color(struct tpg_data *tpg, int k)
return; return;
} }
ycbcr_to_color(tpg, y, cb, cr, &r, &g, &b); 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) { switch (tpg->color_enc) {
...@@ -942,6 +949,11 @@ static void precalculate_color(struct tpg_data *tpg, int k) ...@@ -942,6 +949,11 @@ static void precalculate_color(struct tpg_data *tpg, int k)
tpg->colors[k][2] = cr; tpg->colors[k][2] = cr;
break; break;
} }
case TGP_COLOR_ENC_LUMA:
{
tpg->colors[k][0] = r >> 4;
break;
}
case TGP_COLOR_ENC_RGB: case TGP_COLOR_ENC_RGB:
{ {
if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) { if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) {
...@@ -1983,6 +1995,8 @@ static const char *tpg_color_enc_str(enum tgp_color_enc ...@@ -1983,6 +1995,8 @@ static const char *tpg_color_enc_str(enum tgp_color_enc
return "HSV"; return "HSV";
case TGP_COLOR_ENC_YCBCR: case TGP_COLOR_ENC_YCBCR:
return "Y'CbCr"; return "Y'CbCr";
case TGP_COLOR_ENC_LUMA:
return "Luma";
case TGP_COLOR_ENC_RGB: case TGP_COLOR_ENC_RGB:
default: default:
return "R'G'B"; return "R'G'B";
......
...@@ -184,7 +184,7 @@ struct vivid_fmt vivid_formats[] = { ...@@ -184,7 +184,7 @@ struct vivid_fmt vivid_formats[] = {
.fourcc = V4L2_PIX_FMT_GREY, .fourcc = V4L2_PIX_FMT_GREY,
.vdownsampling = { 1 }, .vdownsampling = { 1 },
.bit_depth = { 8 }, .bit_depth = { 8 },
.color_enc = TGP_COLOR_ENC_YCBCR, .color_enc = TGP_COLOR_ENC_LUMA,
.planes = 1, .planes = 1,
.buffers = 1, .buffers = 1,
}, },
...@@ -192,7 +192,7 @@ struct vivid_fmt vivid_formats[] = { ...@@ -192,7 +192,7 @@ struct vivid_fmt vivid_formats[] = {
.fourcc = V4L2_PIX_FMT_Y16, .fourcc = V4L2_PIX_FMT_Y16,
.vdownsampling = { 1 }, .vdownsampling = { 1 },
.bit_depth = { 16 }, .bit_depth = { 16 },
.color_enc = TGP_COLOR_ENC_YCBCR, .color_enc = TGP_COLOR_ENC_LUMA,
.planes = 1, .planes = 1,
.buffers = 1, .buffers = 1,
}, },
...@@ -200,7 +200,7 @@ struct vivid_fmt vivid_formats[] = { ...@@ -200,7 +200,7 @@ struct vivid_fmt vivid_formats[] = {
.fourcc = V4L2_PIX_FMT_Y16_BE, .fourcc = V4L2_PIX_FMT_Y16_BE,
.vdownsampling = { 1 }, .vdownsampling = { 1 },
.bit_depth = { 16 }, .bit_depth = { 16 },
.color_enc = TGP_COLOR_ENC_YCBCR, .color_enc = TGP_COLOR_ENC_LUMA,
.planes = 1, .planes = 1,
.buffers = 1, .buffers = 1,
}, },
......
...@@ -91,6 +91,7 @@ enum tgp_color_enc { ...@@ -91,6 +91,7 @@ enum tgp_color_enc {
TGP_COLOR_ENC_RGB, TGP_COLOR_ENC_RGB,
TGP_COLOR_ENC_YCBCR, TGP_COLOR_ENC_YCBCR,
TGP_COLOR_ENC_HSV, TGP_COLOR_ENC_HSV,
TGP_COLOR_ENC_LUMA,
}; };
extern const char * const tpg_aspect_strings[]; extern const char * const tpg_aspect_strings[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment