Lines Matching defs:tpg

3  * v4l2-tpg-core.c - Test Pattern Generator
12 #include <media/tpg/v4l2-tpg.h>
89 void tpg_init(struct tpg_data *tpg, unsigned w, unsigned h)
91 memset(tpg, 0, sizeof(*tpg));
92 tpg->scaled_width = tpg->src_width = w;
93 tpg->src_height = tpg->buf_height = h;
94 tpg->crop.width = tpg->compose.width = w;
95 tpg->crop.height = tpg->compose.height = h;
96 tpg->recalc_colors = true;
97 tpg->recalc_square_border = true;
98 tpg->brightness = 128;
99 tpg->contrast = 128;
100 tpg->saturation = 128;
101 tpg->hue = 0;
102 tpg->mv_hor_mode = TPG_MOVE_NONE;
103 tpg->mv_vert_mode = TPG_MOVE_NONE;
104 tpg->field = V4L2_FIELD_NONE;
105 tpg_s_fourcc(tpg, V4L2_PIX_FMT_RGB24);
106 tpg->colorspace = V4L2_COLORSPACE_SRGB;
107 tpg->perc_fill = 100;
108 tpg->hsv_enc = V4L2_HSV_ENC_180;
112 int tpg_alloc(struct tpg_data *tpg, unsigned max_w)
118 tpg->max_line_width = max_w;
123 tpg->lines[pat][plane] =
125 if (!tpg->lines[pat][plane]) {
131 tpg->downsampled_lines[pat][plane] =
133 if (!tpg->downsampled_lines[pat][plane]) {
142 tpg->contrast_line[plane] =
144 if (!tpg->contrast_line[plane]) {
148 tpg->black_line[plane] =
150 if (!tpg->black_line[plane]) {
154 tpg->random_line[plane] =
156 if (!tpg->random_line[plane]) {
165 vfree(tpg->contrast_line[plane]);
166 vfree(tpg->black_line[plane]);
167 vfree(tpg->random_line[plane]);
168 tpg->contrast_line[plane] = NULL;
169 tpg->black_line[plane] = NULL;
170 tpg->random_line[plane] = NULL;
175 vfree(tpg->lines[pat][plane]);
176 tpg->lines[pat][plane] = NULL;
179 vfree(tpg->downsampled_lines[pat][plane]);
180 tpg->downsampled_lines[pat][plane] = NULL;
186 void tpg_free(struct tpg_data *tpg)
193 vfree(tpg->lines[pat][plane]);
194 tpg->lines[pat][plane] = NULL;
197 vfree(tpg->downsampled_lines[pat][plane]);
198 tpg->downsampled_lines[pat][plane] = NULL;
201 vfree(tpg->contrast_line[plane]);
202 vfree(tpg->black_line[plane]);
203 vfree(tpg->random_line[plane]);
204 tpg->contrast_line[plane] = NULL;
205 tpg->black_line[plane] = NULL;
206 tpg->random_line[plane] = NULL;
211 bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc)
213 tpg->fourcc = fourcc;
214 tpg->planes = 1;
215 tpg->buffers = 1;
216 tpg->recalc_colors = true;
217 tpg->interleaved = false;
218 tpg->vdownsampling[0] = 1;
219 tpg->hdownsampling[0] = 1;
220 tpg->hmask[0] = ~0;
221 tpg->hmask[1] = ~0;
222 tpg->hmask[2] = ~0;
241 tpg->interleaved = true;
242 tpg->vdownsampling[1] = 1;
243 tpg->hdownsampling[1] = 1;
244 tpg->planes = 2;
283 tpg->color_enc = TGP_COLOR_ENC_RGB;
291 tpg->color_enc = TGP_COLOR_ENC_LUMA;
303 tpg->color_enc = TGP_COLOR_ENC_YCBCR;
307 tpg->buffers = 3;
311 tpg->vdownsampling[1] = 2;
312 tpg->vdownsampling[2] = 2;
313 tpg->hdownsampling[1] = 2;
314 tpg->hdownsampling[2] = 2;
315 tpg->planes = 3;
316 tpg->color_enc = TGP_COLOR_ENC_YCBCR;
320 tpg->buffers = 3;
323 tpg->vdownsampling[1] = 1;
324 tpg->vdownsampling[2] = 1;
325 tpg->hdownsampling[1] = 2;
326 tpg->hdownsampling[2] = 2;
327 tpg->planes = 3;
328 tpg->color_enc = TGP_COLOR_ENC_YCBCR;
332 tpg->buffers = 2;
336 tpg->vdownsampling[1] = 1;
337 tpg->hdownsampling[1] = 1;
338 tpg->hmask[1] = ~1;
339 tpg->planes = 2;
340 tpg->color_enc = TGP_COLOR_ENC_YCBCR;
344 tpg->buffers = 2;
348 tpg->vdownsampling[1] = 2;
349 tpg->hdownsampling[1] = 1;
350 tpg->hmask[1] = ~1;
351 tpg->planes = 2;
352 tpg->color_enc = TGP_COLOR_ENC_YCBCR;
356 tpg->buffers = 3;
357 tpg->planes = 3;
358 tpg->vdownsampling[1] = 1;
359 tpg->vdownsampling[2] = 1;
360 tpg->hdownsampling[1] = 1;
361 tpg->hdownsampling[2] = 1;
362 tpg->color_enc = TGP_COLOR_ENC_YCBCR;
366 tpg->vdownsampling[1] = 1;
367 tpg->hdownsampling[1] = 1;
368 tpg->planes = 2;
369 tpg->color_enc = TGP_COLOR_ENC_YCBCR;
375 tpg->hmask[0] = ~1;
376 tpg->color_enc = TGP_COLOR_ENC_YCBCR;
380 tpg->color_enc = TGP_COLOR_ENC_HSV;
389 tpg->twopixelsize[0] = 2;
426 tpg->twopixelsize[0] = 2 * 2;
431 tpg->twopixelsize[0] = 2 * 3;
452 tpg->twopixelsize[0] = 2 * 4;
466 tpg->twopixelsize[0] = 2;
467 tpg->twopixelsize[1] = 2;
481 tpg->twopixelsize[0] = 4;
482 tpg->twopixelsize[1] = 4;
493 tpg->twopixelsize[0] = 2;
494 tpg->twopixelsize[1] = 2;
495 tpg->twopixelsize[2] = 2;
499 tpg->twopixelsize[0] = 2;
500 tpg->twopixelsize[1] = 4;
507 void tpg_s_crop_compose(struct tpg_data *tpg, const struct v4l2_rect *crop,
510 tpg->crop = *crop;
511 tpg->compose = *compose;
512 tpg->scaled_width = (tpg->src_width * tpg->compose.width +
513 tpg->crop.width - 1) / tpg->crop.width;
514 tpg->scaled_width &= ~1;
515 if (tpg->scaled_width > tpg->max_line_width)
516 tpg->scaled_width = tpg->max_line_width;
517 if (tpg->scaled_width < 2)
518 tpg->scaled_width = 2;
519 tpg->recalc_lines = true;
523 void tpg_reset_source(struct tpg_data *tpg, unsigned width, unsigned height,
528 tpg->src_width = width;
529 tpg->src_height = height;
530 tpg->field = field;
531 tpg->buf_height = height;
533 tpg->buf_height /= 2;
534 tpg->scaled_width = width;
535 tpg->crop.top = tpg->crop.left = 0;
536 tpg->crop.width = width;
537 tpg->crop.height = height;
538 tpg->compose.top = tpg->compose.left = 0;
539 tpg->compose.width = width;
540 tpg->compose.height = tpg->buf_height;
541 for (p = 0; p < tpg->planes; p++)
542 tpg->bytesperline[p] = (width * tpg->twopixelsize[p]) /
543 (2 * tpg->hdownsampling[p]);
544 tpg->recalc_square_border = true;
548 static enum tpg_color tpg_get_textbg_color(struct tpg_data *tpg)
550 switch (tpg->pattern) {
560 static enum tpg_color tpg_get_textfg_color(struct tpg_data *tpg)
562 switch (tpg->pattern) {
585 static void color_to_hsv(struct tpg_data *tpg, int r, int g, int b,
618 third_size = (tpg->real_hsv_enc == V4L2_HSV_ENC_180) ? 60 : 85;
638 if (tpg->real_hsv_enc == V4L2_HSV_ENC_180) {
658 static void color_to_ycbcr(struct tpg_data *tpg, int r, int g, int b,
712 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE;
716 switch (tpg->real_ycbcr_enc) {
772 static void ycbcr_to_color(struct tpg_data *tpg, int y, int cb, int cr,
826 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE;
831 switch (tpg->real_ycbcr_enc) {
883 static void precalculate_color(struct tpg_data *tpg, int k)
893 col = tpg_get_textbg_color(tpg);
899 col = tpg_get_textfg_color(tpg);
904 } else if (tpg->pattern == TPG_PAT_NOISE) {
907 r = g = b = tpg->qual_offset + get_random_u32_below(196);
912 if (tpg->pattern == TPG_PAT_CSC_COLORBAR && col <= TPG_COLOR_CSC_BLACK) {
913 r = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].r;
914 g = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].g;
915 b = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].b;
922 if (tpg->qual == TPG_QUAL_GRAY ||
923 tpg->color_enc == TGP_COLOR_ENC_LUMA) {
936 if (tpg->real_rgb_range == V4L2_DV_RGB_RANGE_LIMITED &&
937 tpg->rgb_range == V4L2_DV_RGB_RANGE_FULL &&
938 tpg->color_enc == TGP_COLOR_ENC_RGB) {
947 } else if (tpg->real_rgb_range != V4L2_DV_RGB_RANGE_LIMITED &&
948 tpg->rgb_range == V4L2_DV_RGB_RANGE_LIMITED &&
949 tpg->color_enc == TGP_COLOR_ENC_RGB) {
963 if ((tpg->brightness != 128 || tpg->contrast != 128 ||
964 tpg->saturation != 128 || tpg->hue) &&
965 tpg->color_enc != TGP_COLOR_ENC_LUMA) {
971 color_to_ycbcr(tpg, r, g, b, &y, &cb, &cr);
973 y = (16 << 4) + ((y - (16 << 4)) * tpg->contrast) / 128;
974 y += (tpg->brightness << 4) - (128 << 4);
978 tmp_cb = (cb * cos(128 + tpg->hue)) / 127 + (cr * sin[128 + tpg->hue]) / 127;
979 tmp_cr = (cr * cos(128 + tpg->hue)) / 127 - (cb * sin[128 + tpg->hue]) / 127;
981 cb = (128 << 4) + (tmp_cb * tpg->contrast * tpg->saturation) / (128 * 128);
982 cr = (128 << 4) + (tmp_cr * tpg->contrast * tpg->saturation) / (128 * 128);
983 if (tpg->color_enc == TGP_COLOR_ENC_YCBCR)
986 ycbcr_to_color(tpg, y, cb, cr, &r, &g, &b);
987 } else if ((tpg->brightness != 128 || tpg->contrast != 128) &&
988 tpg->color_enc == TGP_COLOR_ENC_LUMA) {
989 r = (16 << 4) + ((r - (16 << 4)) * tpg->contrast) / 128;
990 r += (tpg->brightness << 4) - (128 << 4);
993 switch (tpg->color_enc) {
998 color_to_hsv(tpg, r, g, b, &h, &s, &v);
999 tpg->colors[k][0] = h;
1000 tpg->colors[k][1] = s;
1001 tpg->colors[k][2] = v;
1008 color_to_ycbcr(tpg, r, g, b, &y, &cb, &cr);
1018 if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE &&
1019 tpg->real_ycbcr_enc != V4L2_YCBCR_ENC_XV601 &&
1020 tpg->real_ycbcr_enc != V4L2_YCBCR_ENC_XV709) {
1029 switch (tpg->fourcc) {
1046 tpg->colors[k][0] = y;
1047 tpg->colors[k][1] = cb;
1048 tpg->colors[k][2] = cr;
1053 tpg->colors[k][0] = r >> 4;
1058 if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) {
1063 switch (tpg->fourcc) {
1116 tpg->colors[k][0] = r;
1117 tpg->colors[k][1] = g;
1118 tpg->colors[k][2] = b;
1124 static void tpg_precalculate_colors(struct tpg_data *tpg)
1129 precalculate_color(tpg, k);
1133 static void gen_twopix(struct tpg_data *tpg,
1136 unsigned offset = odd * tpg->twopixelsize[0] / 2;
1137 u8 alpha = tpg->alpha_component;
1140 if (tpg->alpha_red_only && color != TPG_COLOR_CSC_RED &&
1145 precalculate_color(tpg, color);
1146 r_y_h = tpg->colors[color][0]; /* R or precalculated Y, H */
1147 g_u_s = tpg->colors[color][1]; /* G or precalculated U, V */
1148 b_v = tpg->colors[color][2]; /* B or precalculated V */
1150 switch (tpg->fourcc) {
1545 unsigned tpg_g_interleaved_plane(const struct tpg_data *tpg, unsigned buf_line)
1547 switch (tpg->fourcc) {
1572 static unsigned tpg_get_pat_lines(const struct tpg_data *tpg)
1574 switch (tpg->pattern) {
1594 static unsigned tpg_get_pat_line(const struct tpg_data *tpg, unsigned line)
1596 switch (tpg->pattern) {
1608 return (line * 8) / tpg->src_height;
1610 return line == tpg->src_height / 2;
1612 return (line + 1) / 2 == tpg->src_height / 4;
1614 return (line + 10) / 20 == tpg->src_height / 40;
1622 * Note: x is in the range 0 to 2 * tpg->src_width.
1624 static enum tpg_color tpg_get_color(const struct tpg_data *tpg,
1647 switch (tpg->pattern) {
1651 return bars[tpg->pattern][((x * 8) / tpg->src_width) % 8];
1653 return bars[1][(pat_line + (x * 8) / tpg->src_width) % 8];
1686 if (pat_line || (x % tpg->src_width) == tpg->src_width / 2)
1690 if (pat_line || ((x % tpg->src_width) + 1) / 2 == tpg->src_width / 4)
1694 if (pat_line || ((x % tpg->src_width) + 10) / 20 == tpg->src_width / 40)
1698 return TPG_COLOR_RAMP + ((x % tpg->src_width) * 256) / tpg->src_width;
1710 static void tpg_calculate_square_border(struct tpg_data *tpg)
1712 unsigned w = tpg->src_width;
1713 unsigned h = tpg->src_height;
1720 tpg->square.width = sq_w;
1721 if (tpg->vid_aspect == TPG_VIDEO_ASPECT_16X9_ANAMORPHIC) {
1726 tpg->square.width = ana_sq_w;
1728 tpg->square.left = (w - tpg->square.width) / 2;
1729 if (tpg->pix_aspect == TPG_PIXEL_ASPECT_NTSC)
1731 else if (tpg->pix_aspect == TPG_PIXEL_ASPECT_PAL)
1733 tpg->square.height = sq_h;
1734 tpg->square.top = (h - sq_h) / 2;
1735 tpg->border.left = 0;
1736 tpg->border.width = w;
1737 tpg->border.top = 0;
1738 tpg->border.height = h;
1739 switch (tpg->vid_aspect) {
1741 if (tpg->pix_aspect)
1744 tpg->border.width = ((4 * h) / 3) & ~1;
1745 if (((w - tpg->border.width) / 2) & ~1)
1746 tpg->border.width -= 2;
1747 tpg->border.left = (w - tpg->border.width) / 2;
1750 tpg->border.height = ((3 * w) / 4) & ~1;
1751 tpg->border.top = (h - tpg->border.height) / 2;
1754 if (tpg->pix_aspect) {
1755 tpg->border.height = tpg->pix_aspect == TPG_PIXEL_ASPECT_NTSC ? 420 : 506;
1756 tpg->border.top = (h - tpg->border.height) / 2;
1760 tpg->border.width = ((14 * h) / 9) & ~1;
1761 if (((w - tpg->border.width) / 2) & ~1)
1762 tpg->border.width -= 2;
1763 tpg->border.left = (w - tpg->border.width) / 2;
1766 tpg->border.height = ((9 * w) / 14) & ~1;
1767 tpg->border.top = (h - tpg->border.height) / 2;
1770 if (tpg->pix_aspect) {
1771 tpg->border.height = tpg->pix_aspect == TPG_PIXEL_ASPECT_NTSC ? 368 : 442;
1772 tpg->border.top = (h - tpg->border.height) / 2;
1776 tpg->border.width = ((16 * h) / 9) & ~1;
1777 if (((w - tpg->border.width) / 2) & ~1)
1778 tpg->border.width -= 2;
1779 tpg->border.left = (w - tpg->border.width) / 2;
1782 tpg->border.height = ((9 * w) / 16) & ~1;
1783 tpg->border.top = (h - tpg->border.height) / 2;
1790 static void tpg_precalculate_line(struct tpg_data *tpg)
1798 switch (tpg->pattern) {
1810 for (pat = 0; pat < tpg_get_pat_lines(tpg); pat++) {
1812 unsigned int_part = tpg->src_width / tpg->scaled_width;
1813 unsigned fract_part = tpg->src_width % tpg->scaled_width;
1817 for (x = 0; x < tpg->scaled_width * 2; x += 2) {
1821 real_x = tpg->hflip ? tpg->src_width * 2 - real_x - 2 : real_x;
1822 color1 = tpg_get_color(tpg, pat, real_x);
1826 if (error >= tpg->scaled_width) {
1827 error -= tpg->scaled_width;
1832 real_x = tpg->hflip ? tpg->src_width * 2 - real_x - 2 : real_x;
1833 color2 = tpg_get_color(tpg, pat, real_x);
1837 if (error >= tpg->scaled_width) {
1838 error -= tpg->scaled_width;
1842 gen_twopix(tpg, pix, tpg->hflip ? color2 : color1, 0);
1843 gen_twopix(tpg, pix, tpg->hflip ? color1 : color2, 1);
1844 for (p = 0; p < tpg->planes; p++) {
1845 unsigned twopixsize = tpg->twopixelsize[p];
1846 unsigned hdiv = tpg->hdownsampling[p];
1847 u8 *pos = tpg->lines[pat][p] + tpg_hdiv(tpg, p, x);
1854 if (tpg->vdownsampling[tpg->planes - 1] > 1) {
1855 unsigned pat_lines = tpg_get_pat_lines(tpg);
1860 for (p = 1; p < tpg->planes; p++) {
1861 unsigned w = tpg_hdiv(tpg, p, tpg->scaled_width * 2);
1862 u8 *pos1 = tpg->lines[pat][p];
1863 u8 *pos2 = tpg->lines[next_pat][p];
1864 u8 *dest = tpg->downsampled_lines[pat][p];
1872 gen_twopix(tpg, pix, contrast, 0);
1873 gen_twopix(tpg, pix, contrast, 1);
1874 for (p = 0; p < tpg->planes; p++) {
1875 unsigned twopixsize = tpg->twopixelsize[p];
1876 u8 *pos = tpg->contrast_line[p];
1878 for (x = 0; x < tpg->scaled_width; x += 2, pos += twopixsize)
1882 gen_twopix(tpg, pix, TPG_COLOR_100_BLACK, 0);
1883 gen_twopix(tpg, pix, TPG_COLOR_100_BLACK, 1);
1884 for (p = 0; p < tpg->planes; p++) {
1885 unsigned twopixsize = tpg->twopixelsize[p];
1886 u8 *pos = tpg->black_line[p];
1888 for (x = 0; x < tpg->scaled_width; x += 2, pos += twopixsize)
1892 for (x = 0; x < tpg->scaled_width * 2; x += 2) {
1893 gen_twopix(tpg, pix, TPG_COLOR_RANDOM, 0);
1894 gen_twopix(tpg, pix, TPG_COLOR_RANDOM, 1);
1895 for (p = 0; p < tpg->planes; p++) {
1896 unsigned twopixsize = tpg->twopixelsize[p];
1897 u8 *pos = tpg->random_line[p] + x * twopixsize / 2;
1903 gen_twopix(tpg, tpg->textbg, TPG_COLOR_TEXTBG, 0);
1904 gen_twopix(tpg, tpg->textbg, TPG_COLOR_TEXTBG, 1);
1905 gen_twopix(tpg, tpg->textfg, TPG_COLOR_TEXTFG, 0);
1906 gen_twopix(tpg, tpg->textfg, TPG_COLOR_TEXTFG, 1);
1913 unsigned vdiv = tpg->vdownsampling[p]; \
1914 unsigned hdiv = tpg->hdownsampling[p]; \
1918 memcpy(&fg, tpg->textfg[p], sizeof(PIXTYPE)); \
1919 memcpy(&bg, tpg->textbg[p], sizeof(PIXTYPE)); \
1922 int l = tpg->vflip ? 15 - line : line; \
1924 ((y * step + l) / (vdiv * div)) * tpg->bytesperline[p] + \
1931 if (hdiv == 2 && tpg->hflip) { \
1941 } else if (tpg->hflip) { \
1961 pos += (tpg->hflip ? -8 : 8) / (int)hdiv; \
1966 static noinline void tpg_print_str_2(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2],
1973 static noinline void tpg_print_str_4(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2],
1980 static noinline void tpg_print_str_6(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2],
1987 static noinline void tpg_print_str_8(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2],
1994 void tpg_gen_text(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2],
1997 unsigned step = V4L2_FIELD_HAS_T_OR_B(tpg->field) ? 2 : 1;
2009 if (y + 16 >= tpg->compose.height || x + 8 >= tpg->compose.width)
2012 if (len > (tpg->compose.width - x) / 8)
2013 len = (tpg->compose.width - x) / 8;
2014 if (tpg->vflip)
2015 y = tpg->compose.height - y - 16;
2016 if (tpg->hflip)
2017 x = tpg->compose.width - x - 8;
2018 y += tpg->compose.top;
2019 x += tpg->compose.left;
2020 if (tpg->field == V4L2_FIELD_BOTTOM)
2022 else if (tpg->field == V4L2_FIELD_SEQ_TB || tpg->field == V4L2_FIELD_SEQ_BT)
2025 for (p = 0; p < tpg->planes; p++) {
2027 switch (tpg->twopixelsize[p]) {
2029 tpg_print_str_2(tpg, basep, p, first, div, step, y, x,
2033 tpg_print_str_4(tpg, basep, p, first, div, step, y, x,
2037 tpg_print_str_6(tpg, basep, p, first, div, step, y, x,
2041 tpg_print_str_8(tpg, basep, p, first, div, step, y, x,
2049 const char *tpg_g_color_order(const struct tpg_data *tpg)
2051 switch (tpg->pattern) {
2073 void tpg_update_mv_step(struct tpg_data *tpg)
2075 int factor = tpg->mv_hor_mode > TPG_MOVE_NONE ? -1 : 1;
2077 if (tpg->hflip)
2079 switch (tpg->mv_hor_mode) {
2082 tpg->mv_hor_step = ((tpg->src_width + 319) / 320) * 4;
2086 tpg->mv_hor_step = ((tpg->src_width + 639) / 640) * 4;
2090 tpg->mv_hor_step = 2;
2093 tpg->mv_hor_step = 0;
2097 tpg->mv_hor_step = tpg->src_width - tpg->mv_hor_step;
2099 factor = tpg->mv_vert_mode > TPG_MOVE_NONE ? -1 : 1;
2100 switch (tpg->mv_vert_mode) {
2103 tpg->mv_vert_step = ((tpg->src_width + 319) / 320) * 4;
2107 tpg->mv_vert_step = ((tpg->src_width + 639) / 640) * 4;
2111 tpg->mv_vert_step = 1;
2114 tpg->mv_vert_step = 0;
2118 tpg->mv_vert_step = tpg->src_height - tpg->mv_vert_step;
2123 static unsigned tpg_calc_frameline(const struct tpg_data *tpg, unsigned src_y,
2128 return tpg->crop.top + src_y * 2;
2130 return tpg->crop.top + src_y * 2 + 1;
2132 return src_y + tpg->crop.top;
2140 static unsigned tpg_calc_buffer_line(const struct tpg_data *tpg, unsigned y,
2143 y += tpg->compose.top;
2147 return tpg->buf_height / 2 + y / 2;
2152 return tpg->buf_height / 2 + y / 2;
2158 static void tpg_recalc(struct tpg_data *tpg)
2160 if (tpg->recalc_colors) {
2161 tpg->recalc_colors = false;
2162 tpg->recalc_lines = true;
2163 tpg->real_xfer_func = tpg->xfer_func;
2164 tpg->real_ycbcr_enc = tpg->ycbcr_enc;
2165 tpg->real_hsv_enc = tpg->hsv_enc;
2166 tpg->real_quantization = tpg->quantization;
2168 if (tpg->xfer_func == V4L2_XFER_FUNC_DEFAULT)
2169 tpg->real_xfer_func =
2170 V4L2_MAP_XFER_FUNC_DEFAULT(tpg->colorspace);
2172 if (tpg->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
2173 tpg->real_ycbcr_enc =
2174 V4L2_MAP_YCBCR_ENC_DEFAULT(tpg->colorspace);
2176 if (tpg->quantization == V4L2_QUANTIZATION_DEFAULT)
2177 tpg->real_quantization =
2179 tpg->color_enc != TGP_COLOR_ENC_YCBCR,
2180 tpg->colorspace, tpg->real_ycbcr_enc);
2182 tpg_precalculate_colors(tpg);
2184 if (tpg->recalc_square_border) {
2185 tpg->recalc_square_border = false;
2186 tpg_calculate_square_border(tpg);
2188 if (tpg->recalc_lines) {
2189 tpg->recalc_lines = false;
2190 tpg_precalculate_line(tpg);
2194 void tpg_calc_text_basep(struct tpg_data *tpg,
2197 unsigned stride = tpg->bytesperline[p];
2198 unsigned h = tpg->buf_height;
2200 tpg_recalc(tpg);
2204 h /= tpg->vdownsampling[p];
2205 if (tpg->field == V4L2_FIELD_SEQ_TB)
2207 else if (tpg->field == V4L2_FIELD_SEQ_BT)
2209 if (p == 0 && tpg->interleaved)
2210 tpg_calc_text_basep(tpg, basep, 1, vbuf);
2214 static int tpg_pattern_avg(const struct tpg_data *tpg,
2217 unsigned pat_lines = tpg_get_pat_lines(tpg);
2243 void tpg_log_status(struct tpg_data *tpg)
2245 pr_info("tpg source WxH: %ux%u (%s)\n",
2246 tpg->src_width, tpg->src_height,
2247 tpg_color_enc_str(tpg->color_enc));
2248 pr_info("tpg field: %u\n", tpg->field);
2249 pr_info("tpg crop: %ux%u@%dx%d\n", tpg->crop.width, tpg->crop.height,
2250 tpg->crop.left, tpg->crop.top);
2251 pr_info("tpg compose: %ux%u@%dx%d\n", tpg->compose.width, tpg->compose.height,
2252 tpg->compose.left, tpg->compose.top);
2253 pr_info("tpg colorspace: %d\n", tpg->colorspace);
2254 pr_info("tpg transfer function: %d/%d\n", tpg->xfer_func, tpg->real_xfer_func);
2255 if (tpg->color_enc == TGP_COLOR_ENC_HSV)
2256 pr_info("tpg HSV encoding: %d/%d\n",
2257 tpg->hsv_enc, tpg->real_hsv_enc);
2258 else if (tpg->color_enc == TGP_COLOR_ENC_YCBCR)
2259 pr_info("tpg Y'CbCr encoding: %d/%d\n",
2260 tpg->ycbcr_enc, tpg->real_ycbcr_enc);
2261 pr_info("tpg quantization: %d/%d\n", tpg->quantization, tpg->real_quantization);
2262 pr_info("tpg RGB range: %d/%d\n", tpg->rgb_range, tpg->real_rgb_range);
2295 static void tpg_fill_params_pattern(const struct tpg_data *tpg, unsigned p,
2299 tpg_hscale_div(tpg, p, tpg->mv_hor_count % tpg->src_width);
2301 tpg_hscale_div(tpg, p, (tpg->mv_hor_count + tpg->mv_hor_step) %
2302 tpg->src_width);
2303 params->mv_vert_old = tpg->mv_vert_count % tpg->src_height;
2305 (tpg->mv_vert_count + tpg->mv_vert_step) % tpg->src_height;
2308 static void tpg_fill_params_extras(const struct tpg_data *tpg,
2315 params->wss_width = tpg->crop.left < tpg->src_width / 2 ?
2316 tpg->src_width / 2 - tpg->crop.left : 0;
2317 if (params->wss_width > tpg->crop.width)
2318 params->wss_width = tpg->crop.width;
2319 params->wss_width = tpg_hscale_div(tpg, p, params->wss_width);
2321 params->twopixsize * get_random_u32_below(tpg->src_width / 2);
2323 if (tpg->crop.left < tpg->border.left) {
2324 left_pillar_width = tpg->border.left - tpg->crop.left;
2325 if (left_pillar_width > tpg->crop.width)
2326 left_pillar_width = tpg->crop.width;
2327 left_pillar_width = tpg_hscale_div(tpg, p, left_pillar_width);
2331 if (tpg->crop.left + tpg->crop.width >
2332 tpg->border.left + tpg->border.width) {
2334 tpg->border.left + tpg->border.width - tpg->crop.left;
2336 tpg_hscale_div(tpg, p, right_pillar_start);
2342 params->sav_eav_f = tpg->field ==
2346 static void tpg_fill_plane_extras(const struct tpg_data *tpg,
2353 const struct v4l2_rect *sq = &tpg->square;
2354 const struct v4l2_rect *b = &tpg->border;
2355 const struct v4l2_rect *c = &tpg->crop;
2363 u8 *wss = tpg->random_line[p] + params->wss_random_offset;
2368 if (tpg->show_border && frame_line >= b->top &&
2376 memcpy(vbuf + left, tpg->contrast_line[p],
2382 tpg->contrast_line[p], twopixsize);
2386 tpg->contrast_line[p], twopixsize);
2389 if (tpg->qual != TPG_QUAL_NOISE && frame_line >= b->top &&
2391 memcpy(vbuf, tpg->black_line[p], params->left_pillar_width);
2392 memcpy(vbuf + params->right_pillar_start, tpg->black_line[p],
2395 if (tpg->show_square && frame_line >= sq->top &&
2409 left = tpg_hscale_div(tpg, p, left);
2410 width = tpg_hscale_div(tpg, p, width);
2411 memcpy(vbuf + left, tpg->contrast_line[p], width);
2413 if (tpg->insert_sav) {
2414 unsigned offset = tpg_hdiv(tpg, p, tpg->compose.width / 3);
2428 if (tpg->insert_eav) {
2429 unsigned offset = tpg_hdiv(tpg, p, tpg->compose.width * 2 / 3);
2443 if (tpg->insert_hdmi_video_guard_band) {
2446 switch (tpg->fourcc) {
2483 static void tpg_fill_plane_pattern(const struct tpg_data *tpg,
2495 unsigned line_offset = tpg_hscale_div(tpg, p, tpg->crop.left);
2508 if (params->hmax == tpg->compose.height)
2510 if (!tpg->perc_fill_blank)
2515 if (tpg->vflip) {
2516 frame_line = tpg->src_height - frame_line - 1;
2517 frame_line_next = tpg->src_height - frame_line_next - 1;
2521 linestart_older = tpg->contrast_line[p];
2522 linestart_newer = tpg->contrast_line[p];
2523 } else if (tpg->qual != TPG_QUAL_NOISE &&
2524 (frame_line < tpg->border.top ||
2525 frame_line >= tpg->border.top + tpg->border.height)) {
2526 linestart_older = tpg->black_line[p];
2527 linestart_newer = tpg->black_line[p];
2528 } else if (tpg->pattern == TPG_PAT_NOISE || tpg->qual == TPG_QUAL_NOISE) {
2529 linestart_older = tpg->random_line[p] +
2530 twopixsize * get_random_u32_below(tpg->src_width / 2);
2531 linestart_newer = tpg->random_line[p] +
2532 twopixsize * get_random_u32_below(tpg->src_width / 2);
2535 (frame_line + mv_vert_old) % tpg->src_height;
2537 (frame_line + mv_vert_new) % tpg->src_height;
2541 pat_line_old = tpg_get_pat_line(tpg, frame_line_old);
2542 pat_line_new = tpg_get_pat_line(tpg, frame_line_new);
2543 linestart_older = tpg->lines[pat_line_old][p] + mv_hor_old;
2544 linestart_newer = tpg->lines[pat_line_new][p] + mv_hor_new;
2546 if (tpg->vdownsampling[p] > 1 && frame_line != frame_line_next) {
2553 pat_line_next_old = tpg_get_pat_line(tpg,
2554 (frame_line_next + mv_vert_old) % tpg->src_height);
2555 pat_line_next_new = tpg_get_pat_line(tpg,
2556 (frame_line_next + mv_vert_new) % tpg->src_height);
2558 switch (tpg->field) {
2562 avg_pat = tpg_pattern_avg(tpg, pat_line_old, pat_line_new);
2565 linestart_older = tpg->downsampled_lines[avg_pat][p] + mv_hor_old;
2573 avg_pat = tpg_pattern_avg(tpg, pat_line_old, pat_line_next_old);
2575 linestart_older = tpg->downsampled_lines[avg_pat][p] +
2577 avg_pat = tpg_pattern_avg(tpg, pat_line_new, pat_line_next_new);
2579 linestart_newer = tpg->downsampled_lines[avg_pat][p] +
2587 if (tpg->field_alternate) {
2597 switch (tpg->field) {
2626 void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std,
2630 unsigned factor = V4L2_FIELD_HAS_T_OR_B(tpg->field) ? 2 : 1;
2633 unsigned int_part = (tpg->crop.height / factor) / tpg->compose.height;
2634 unsigned fract_part = (tpg->crop.height / factor) % tpg->compose.height;
2639 tpg_recalc(tpg);
2643 params.twopixsize = tpg->twopixelsize[p];
2644 params.img_width = tpg_hdiv(tpg, p, tpg->compose.width);
2645 params.stride = tpg->bytesperline[p];
2646 params.hmax = (tpg->compose.height * tpg->perc_fill) / 100;
2648 tpg_fill_params_pattern(tpg, p, &params);
2649 tpg_fill_params_extras(tpg, p, &params);
2651 vbuf += tpg_hdiv(tpg, p, tpg->compose.left);
2653 for (h = 0; h < tpg->compose.height; h++) {
2656 params.frame_line = tpg_calc_frameline(tpg, src_y, tpg->field);
2658 buf_line = tpg_calc_buffer_line(tpg, h, tpg->field);
2661 if (error >= tpg->compose.height) {
2662 error -= tpg->compose.height;
2670 if (tpg_g_interleaved(tpg))
2671 p = tpg_g_interleaved_plane(tpg, buf_line);
2673 if (tpg->vdownsampling[p] > 1) {
2682 if (tpg->field == V4L2_FIELD_SEQ_BT ||
2683 tpg->field == V4L2_FIELD_SEQ_TB) {
2689 if (error + fract_part >= tpg->compose.height)
2692 tpg_calc_frameline(tpg, next_src_y, tpg->field);
2697 tpg_calc_frameline(tpg, src_y, tpg->field);
2700 buf_line /= tpg->vdownsampling[p];
2702 tpg_fill_plane_pattern(tpg, &params, p, h,
2704 tpg_fill_plane_extras(tpg, &params, p, h,
2710 void tpg_fillbuffer(struct tpg_data *tpg, v4l2_std_id std, unsigned p, u8 *vbuf)
2715 if (tpg->buffers > 1) {
2716 tpg_fill_plane_buffer(tpg, std, p, vbuf);
2720 for (i = 0; i < tpg_g_planes(tpg); i++) {
2721 tpg_fill_plane_buffer(tpg, std, i, vbuf + offset);
2722 offset += tpg_calc_plane_size(tpg, i);