aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2015-03-14 07:01:50 -0400
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2015-04-02 20:08:30 -0400
commit02aa769d9fa12d51213e7b1db34bb9b200a967a3 (patch)
tree7dbc6f67bedacaa6bf63cbab84368bb817cc5a8a /drivers/media
parent87c674e24362cf0f8d5b70d2e20f6160045fd753 (diff)
[media] vivid: add support for 8-bit Bayer formats
Add support for: PIX_FMT_SBGGR8, SGBRG8, SGRBG8 and SRGGB8. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/platform/vivid/vivid-tpg.c57
-rw-r--r--drivers/media/platform/vivid/vivid-tpg.h17
-rw-r--r--drivers/media/platform/vivid/vivid-vid-common.c32
3 files changed, 97 insertions, 9 deletions
diff --git a/drivers/media/platform/vivid/vivid-tpg.c b/drivers/media/platform/vivid/vivid-tpg.c
index 7079460deb61..9656e4dbd5e7 100644
--- a/drivers/media/platform/vivid/vivid-tpg.c
+++ b/drivers/media/platform/vivid/vivid-tpg.c
@@ -181,6 +181,7 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
181 tpg->planes = 1; 181 tpg->planes = 1;
182 tpg->buffers = 1; 182 tpg->buffers = 1;
183 tpg->recalc_colors = true; 183 tpg->recalc_colors = true;
184 tpg->interleaved = false;
184 tpg->vdownsampling[0] = 1; 185 tpg->vdownsampling[0] = 1;
185 tpg->hdownsampling[0] = 1; 186 tpg->hdownsampling[0] = 1;
186 tpg->hmask[0] = ~0; 187 tpg->hmask[0] = ~0;
@@ -188,6 +189,15 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
188 tpg->hmask[2] = ~0; 189 tpg->hmask[2] = ~0;
189 190
190 switch (fourcc) { 191 switch (fourcc) {
192 case V4L2_PIX_FMT_SBGGR8:
193 case V4L2_PIX_FMT_SGBRG8:
194 case V4L2_PIX_FMT_SGRBG8:
195 case V4L2_PIX_FMT_SRGGB8:
196 tpg->interleaved = true;
197 tpg->vdownsampling[1] = 1;
198 tpg->hdownsampling[1] = 1;
199 tpg->planes = 2;
200 /* fall through */
191 case V4L2_PIX_FMT_RGB332: 201 case V4L2_PIX_FMT_RGB332:
192 case V4L2_PIX_FMT_RGB565: 202 case V4L2_PIX_FMT_RGB565:
193 case V4L2_PIX_FMT_RGB565X: 203 case V4L2_PIX_FMT_RGB565X:
@@ -326,13 +336,14 @@ bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
326 case V4L2_PIX_FMT_NV21: 336 case V4L2_PIX_FMT_NV21:
327 case V4L2_PIX_FMT_NV12M: 337 case V4L2_PIX_FMT_NV12M:
328 case V4L2_PIX_FMT_NV21M: 338 case V4L2_PIX_FMT_NV21M:
329 tpg->twopixelsize[0] = 2;
330 tpg->twopixelsize[1] = 2;
331 break;
332 case V4L2_PIX_FMT_NV16: 339 case V4L2_PIX_FMT_NV16:
333 case V4L2_PIX_FMT_NV61: 340 case V4L2_PIX_FMT_NV61:
334 case V4L2_PIX_FMT_NV16M: 341 case V4L2_PIX_FMT_NV16M:
335 case V4L2_PIX_FMT_NV61M: 342 case V4L2_PIX_FMT_NV61M:
343 case V4L2_PIX_FMT_SBGGR8:
344 case V4L2_PIX_FMT_SGBRG8:
345 case V4L2_PIX_FMT_SGRBG8:
346 case V4L2_PIX_FMT_SRGGB8:
336 tpg->twopixelsize[0] = 2; 347 tpg->twopixelsize[0] = 2;
337 tpg->twopixelsize[1] = 2; 348 tpg->twopixelsize[1] = 2;
338 break; 349 break;
@@ -1011,6 +1022,35 @@ static void gen_twopix(struct tpg_data *tpg,
1011 buf[0][offset + 2] = r_y; 1022 buf[0][offset + 2] = r_y;
1012 buf[0][offset + 3] = alpha; 1023 buf[0][offset + 3] = alpha;
1013 break; 1024 break;
1025 case V4L2_PIX_FMT_SBGGR8:
1026 buf[0][offset] = odd ? g_u : b_v;
1027 buf[1][offset] = odd ? r_y : g_u;
1028 break;
1029 case V4L2_PIX_FMT_SGBRG8:
1030 buf[0][offset] = odd ? b_v : g_u;
1031 buf[1][offset] = odd ? g_u : r_y;
1032 break;
1033 case V4L2_PIX_FMT_SGRBG8:
1034 buf[0][offset] = odd ? r_y : g_u;
1035 buf[1][offset] = odd ? g_u : b_v;
1036 break;
1037 case V4L2_PIX_FMT_SRGGB8:
1038 buf[0][offset] = odd ? g_u : r_y;
1039 buf[1][offset] = odd ? b_v : g_u;
1040 break;
1041 }
1042}
1043
1044unsigned tpg_g_interleaved_plane(const struct tpg_data *tpg, unsigned buf_line)
1045{
1046 switch (tpg->fourcc) {
1047 case V4L2_PIX_FMT_SBGGR8:
1048 case V4L2_PIX_FMT_SGBRG8:
1049 case V4L2_PIX_FMT_SGRBG8:
1050 case V4L2_PIX_FMT_SRGGB8:
1051 return buf_line & 1;
1052 default:
1053 return 0;
1014 } 1054 }
1015} 1055}
1016 1056
@@ -1614,6 +1654,8 @@ void tpg_calc_text_basep(struct tpg_data *tpg,
1614 basep[p][1] += h * stride / 2; 1654 basep[p][1] += h * stride / 2;
1615 else if (tpg->field == V4L2_FIELD_SEQ_BT) 1655 else if (tpg->field == V4L2_FIELD_SEQ_BT)
1616 basep[p][0] += h * stride / 2; 1656 basep[p][0] += h * stride / 2;
1657 if (p == 0 && tpg->interleaved)
1658 tpg_calc_text_basep(tpg, basep, 1, vbuf);
1617} 1659}
1618 1660
1619static int tpg_pattern_avg(const struct tpg_data *tpg, 1661static int tpg_pattern_avg(const struct tpg_data *tpg,
@@ -1990,6 +2032,13 @@ void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std,
1990 src_y++; 2032 src_y++;
1991 } 2033 }
1992 2034
2035 /*
2036 * For line-interleaved formats determine the 'plane'
2037 * based on the buffer line.
2038 */
2039 if (tpg_g_interleaved(tpg))
2040 p = tpg_g_interleaved_plane(tpg, buf_line);
2041
1993 if (tpg->vdownsampling[p] > 1) { 2042 if (tpg->vdownsampling[p] > 1) {
1994 /* 2043 /*
1995 * When doing vertical downsampling the field setting 2044 * When doing vertical downsampling the field setting
@@ -2036,7 +2085,7 @@ void tpg_fillbuffer(struct tpg_data *tpg, v4l2_std_id std, unsigned p, u8 *vbuf)
2036 return; 2085 return;
2037 } 2086 }
2038 2087
2039 for (i = 0; i < tpg->planes; i++) { 2088 for (i = 0; i < tpg_g_planes(tpg); i++) {
2040 tpg_fill_plane_buffer(tpg, std, i, vbuf + offset); 2089 tpg_fill_plane_buffer(tpg, std, i, vbuf + offset);
2041 offset += tpg_calc_plane_size(tpg, i); 2090 offset += tpg_calc_plane_size(tpg, i);
2042 } 2091 }
diff --git a/drivers/media/platform/vivid/vivid-tpg.h b/drivers/media/platform/vivid/vivid-tpg.h
index 82ce9bfa8604..a50cd2e2535b 100644
--- a/drivers/media/platform/vivid/vivid-tpg.h
+++ b/drivers/media/platform/vivid/vivid-tpg.h
@@ -140,6 +140,7 @@ struct tpg_data {
140 unsigned real_rgb_range; 140 unsigned real_rgb_range;
141 unsigned buffers; 141 unsigned buffers;
142 unsigned planes; 142 unsigned planes;
143 bool interleaved;
143 u8 vdownsampling[TPG_MAX_PLANES]; 144 u8 vdownsampling[TPG_MAX_PLANES];
144 u8 hdownsampling[TPG_MAX_PLANES]; 145 u8 hdownsampling[TPG_MAX_PLANES];
145 /* 146 /*
@@ -197,6 +198,7 @@ void tpg_gen_text(const struct tpg_data *tpg,
197 u8 *basep[TPG_MAX_PLANES][2], int y, int x, char *text); 198 u8 *basep[TPG_MAX_PLANES][2], int y, int x, char *text);
198void tpg_calc_text_basep(struct tpg_data *tpg, 199void tpg_calc_text_basep(struct tpg_data *tpg,
199 u8 *basep[TPG_MAX_PLANES][2], unsigned p, u8 *vbuf); 200 u8 *basep[TPG_MAX_PLANES][2], unsigned p, u8 *vbuf);
201unsigned tpg_g_interleaved_plane(const struct tpg_data *tpg, unsigned buf_line);
200void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std, 202void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std,
201 unsigned p, u8 *vbuf); 203 unsigned p, u8 *vbuf);
202void tpg_fillbuffer(struct tpg_data *tpg, v4l2_std_id std, 204void tpg_fillbuffer(struct tpg_data *tpg, v4l2_std_id std,
@@ -346,7 +348,12 @@ static inline unsigned tpg_g_buffers(const struct tpg_data *tpg)
346 348
347static inline unsigned tpg_g_planes(const struct tpg_data *tpg) 349static inline unsigned tpg_g_planes(const struct tpg_data *tpg)
348{ 350{
349 return tpg->planes; 351 return tpg->interleaved ? 1 : tpg->planes;
352}
353
354static inline bool tpg_g_interleaved(const struct tpg_data *tpg)
355{
356 return tpg->interleaved;
350} 357}
351 358
352static inline unsigned tpg_g_twopixelsize(const struct tpg_data *tpg, unsigned plane) 359static inline unsigned tpg_g_twopixelsize(const struct tpg_data *tpg, unsigned plane)
@@ -386,7 +393,7 @@ static inline void tpg_s_bytesperline(struct tpg_data *tpg, unsigned plane, unsi
386 return; 393 return;
387 } 394 }
388 395
389 for (p = 0; p < tpg->planes; p++) { 396 for (p = 0; p < tpg_g_planes(tpg); p++) {
390 unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0]; 397 unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0];
391 398
392 tpg->bytesperline[p] = plane_w / tpg->hdownsampling[p]; 399 tpg->bytesperline[p] = plane_w / tpg->hdownsampling[p];
@@ -401,7 +408,7 @@ static inline unsigned tpg_g_line_width(const struct tpg_data *tpg, unsigned pla
401 408
402 if (tpg->buffers > 1) 409 if (tpg->buffers > 1)
403 return tpg_g_bytesperline(tpg, plane); 410 return tpg_g_bytesperline(tpg, plane);
404 for (p = 0; p < tpg->planes; p++) { 411 for (p = 0; p < tpg_g_planes(tpg); p++) {
405 unsigned plane_w = tpg_g_bytesperline(tpg, p); 412 unsigned plane_w = tpg_g_bytesperline(tpg, p);
406 413
407 w += plane_w / tpg->vdownsampling[p]; 414 w += plane_w / tpg->vdownsampling[p];
@@ -417,7 +424,7 @@ static inline unsigned tpg_calc_line_width(const struct tpg_data *tpg,
417 424
418 if (tpg->buffers > 1) 425 if (tpg->buffers > 1)
419 return bpl; 426 return bpl;
420 for (p = 0; p < tpg->planes; p++) { 427 for (p = 0; p < tpg_g_planes(tpg); p++) {
421 unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0]; 428 unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0];
422 429
423 plane_w /= tpg->hdownsampling[p]; 430 plane_w /= tpg->hdownsampling[p];
@@ -428,7 +435,7 @@ static inline unsigned tpg_calc_line_width(const struct tpg_data *tpg,
428 435
429static inline unsigned tpg_calc_plane_size(const struct tpg_data *tpg, unsigned plane) 436static inline unsigned tpg_calc_plane_size(const struct tpg_data *tpg, unsigned plane)
430{ 437{
431 if (plane >= tpg->planes) 438 if (plane >= tpg_g_planes(tpg))
432 return 0; 439 return 0;
433 440
434 return tpg_g_bytesperline(tpg, plane) * tpg->buf_height / 441 return tpg_g_bytesperline(tpg, plane) * tpg->buf_height /
diff --git a/drivers/media/platform/vivid/vivid-vid-common.c b/drivers/media/platform/vivid/vivid-vid-common.c
index 8f0910da2bc4..283b2e861b79 100644
--- a/drivers/media/platform/vivid/vivid-vid-common.c
+++ b/drivers/media/platform/vivid/vivid-vid-common.c
@@ -384,6 +384,38 @@ struct vivid_fmt vivid_formats[] = {
384 .alpha_mask = 0xff000000, 384 .alpha_mask = 0xff000000,
385 }, 385 },
386 { 386 {
387 .name = "Bayer BG/GR",
388 .fourcc = V4L2_PIX_FMT_SBGGR8, /* Bayer BG/GR */
389 .vdownsampling = { 1 },
390 .bit_depth = { 8 },
391 .planes = 1,
392 .buffers = 1,
393 },
394 {
395 .name = "Bayer GB/RG",
396 .fourcc = V4L2_PIX_FMT_SGBRG8, /* Bayer GB/RG */
397 .vdownsampling = { 1 },
398 .bit_depth = { 8 },
399 .planes = 1,
400 .buffers = 1,
401 },
402 {
403 .name = "Bayer GR/BG",
404 .fourcc = V4L2_PIX_FMT_SGRBG8, /* Bayer GR/BG */
405 .vdownsampling = { 1 },
406 .bit_depth = { 8 },
407 .planes = 1,
408 .buffers = 1,
409 },
410 {
411 .name = "Bayer RG/GB",
412 .fourcc = V4L2_PIX_FMT_SRGGB8, /* Bayer RG/GB */
413 .vdownsampling = { 1 },
414 .bit_depth = { 8 },
415 .planes = 1,
416 .buffers = 1,
417 },
418 {
387 .name = "4:2:2, biplanar, YUV", 419 .name = "4:2:2, biplanar, YUV",
388 .fourcc = V4L2_PIX_FMT_NV16M, 420 .fourcc = V4L2_PIX_FMT_NV16M,
389 .vdownsampling = { 1, 1 }, 421 .vdownsampling = { 1, 1 },