Lines Matching +full:y +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0-only
3 * v4l2-tpg-core.c - Test Pattern Generator
12 #include <media/tpg/v4l2-tpg.h>
54 * Sine table: sin[0] = 127 * sin(-180 degrees)
59 0, -4, -7, -11, -13, -18, -20, -22, -26, -29, -33, -35, -37, -41, -43, -48,
60 -50, -52, -56, -58, -62, -63, -65, -69, -71, -75, -76, -78, -82, -83, -87, -88,
61 -90, -93, -94, -97, -99, -101, -103, -104, -107, -108, -110, -111, -112, -114, -115, -117,
62 -118, -119, -120, -121, -122, -123, -123, -124, -125, -125, -126, -126, -127, -127, -127, -127,
63 -127, -127, -127, -127, -126, -126, -125, -125, -124, -124, -123, -122, -121, -120, -119, -118,
64 -117, -116, -114, -113, -111, -110, -109, -107, -105, -103, -101, -100, -97, -96, -93, -91,
65 -90, -87, -85, -82, -80, -76, -75, -73, -69, -67, -63, -62, -60, -56, -54, -50,
66 -48, -46, -41, -39, -35, -33, -31, -26, -24, -20, -18, -15, -11, -9, -4, -2,
92 tpg->scaled_width = tpg->src_width = w; in tpg_init()
93 tpg->src_height = tpg->buf_height = h; in tpg_init()
94 tpg->crop.width = tpg->compose.width = w; in tpg_init()
95 tpg->crop.height = tpg->compose.height = h; in tpg_init()
96 tpg->recalc_colors = true; in tpg_init()
97 tpg->recalc_square_border = true; in tpg_init()
98 tpg->brightness = 128; in tpg_init()
99 tpg->contrast = 128; in tpg_init()
100 tpg->saturation = 128; in tpg_init()
101 tpg->hue = 0; in tpg_init()
102 tpg->mv_hor_mode = TPG_MOVE_NONE; in tpg_init()
103 tpg->mv_vert_mode = TPG_MOVE_NONE; in tpg_init()
104 tpg->field = V4L2_FIELD_NONE; in tpg_init()
106 tpg->colorspace = V4L2_COLORSPACE_SRGB; in tpg_init()
107 tpg->perc_fill = 100; in tpg_init()
108 tpg->hsv_enc = V4L2_HSV_ENC_180; in tpg_init()
117 tpg->max_line_width = max_w; in tpg_alloc()
122 tpg->lines[pat][plane] = in tpg_alloc()
124 if (!tpg->lines[pat][plane]) in tpg_alloc()
125 return -ENOMEM; in tpg_alloc()
128 tpg->downsampled_lines[pat][plane] = in tpg_alloc()
130 if (!tpg->downsampled_lines[pat][plane]) in tpg_alloc()
131 return -ENOMEM; in tpg_alloc()
137 tpg->contrast_line[plane] = in tpg_alloc()
139 if (!tpg->contrast_line[plane]) in tpg_alloc()
140 return -ENOMEM; in tpg_alloc()
141 tpg->black_line[plane] = in tpg_alloc()
143 if (!tpg->black_line[plane]) in tpg_alloc()
144 return -ENOMEM; in tpg_alloc()
145 tpg->random_line[plane] = in tpg_alloc()
147 if (!tpg->random_line[plane]) in tpg_alloc()
148 return -ENOMEM; in tpg_alloc()
161 vfree(tpg->lines[pat][plane]); in tpg_free()
162 tpg->lines[pat][plane] = NULL; in tpg_free()
165 vfree(tpg->downsampled_lines[pat][plane]); in tpg_free()
166 tpg->downsampled_lines[pat][plane] = NULL; in tpg_free()
169 vfree(tpg->contrast_line[plane]); in tpg_free()
170 vfree(tpg->black_line[plane]); in tpg_free()
171 vfree(tpg->random_line[plane]); in tpg_free()
172 tpg->contrast_line[plane] = NULL; in tpg_free()
173 tpg->black_line[plane] = NULL; in tpg_free()
174 tpg->random_line[plane] = NULL; in tpg_free()
181 tpg->fourcc = fourcc; in tpg_s_fourcc()
182 tpg->planes = 1; in tpg_s_fourcc()
183 tpg->buffers = 1; in tpg_s_fourcc()
184 tpg->recalc_colors = true; in tpg_s_fourcc()
185 tpg->interleaved = false; in tpg_s_fourcc()
186 tpg->vdownsampling[0] = 1; in tpg_s_fourcc()
187 tpg->hdownsampling[0] = 1; in tpg_s_fourcc()
188 tpg->hmask[0] = ~0; in tpg_s_fourcc()
189 tpg->hmask[1] = ~0; in tpg_s_fourcc()
190 tpg->hmask[2] = ~0; in tpg_s_fourcc()
209 tpg->interleaved = true; in tpg_s_fourcc()
210 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
211 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
212 tpg->planes = 2; in tpg_s_fourcc()
251 tpg->color_enc = TGP_COLOR_ENC_RGB; in tpg_s_fourcc()
259 tpg->color_enc = TGP_COLOR_ENC_LUMA; in tpg_s_fourcc()
271 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
275 tpg->buffers = 3; in tpg_s_fourcc()
279 tpg->vdownsampling[1] = 2; in tpg_s_fourcc()
280 tpg->vdownsampling[2] = 2; in tpg_s_fourcc()
281 tpg->hdownsampling[1] = 2; in tpg_s_fourcc()
282 tpg->hdownsampling[2] = 2; in tpg_s_fourcc()
283 tpg->planes = 3; in tpg_s_fourcc()
284 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
288 tpg->buffers = 3; in tpg_s_fourcc()
291 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
292 tpg->vdownsampling[2] = 1; in tpg_s_fourcc()
293 tpg->hdownsampling[1] = 2; in tpg_s_fourcc()
294 tpg->hdownsampling[2] = 2; in tpg_s_fourcc()
295 tpg->planes = 3; in tpg_s_fourcc()
296 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
300 tpg->buffers = 2; in tpg_s_fourcc()
304 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
305 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
306 tpg->hmask[1] = ~1; in tpg_s_fourcc()
307 tpg->planes = 2; in tpg_s_fourcc()
308 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
312 tpg->buffers = 2; in tpg_s_fourcc()
316 tpg->vdownsampling[1] = 2; in tpg_s_fourcc()
317 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
318 tpg->hmask[1] = ~1; in tpg_s_fourcc()
319 tpg->planes = 2; in tpg_s_fourcc()
320 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
324 tpg->buffers = 3; in tpg_s_fourcc()
325 tpg->planes = 3; in tpg_s_fourcc()
326 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
327 tpg->vdownsampling[2] = 1; in tpg_s_fourcc()
328 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
329 tpg->hdownsampling[2] = 1; in tpg_s_fourcc()
330 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
334 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
335 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
336 tpg->planes = 2; in tpg_s_fourcc()
337 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
343 tpg->hmask[0] = ~1; in tpg_s_fourcc()
344 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
348 tpg->color_enc = TGP_COLOR_ENC_HSV; in tpg_s_fourcc()
357 tpg->twopixelsize[0] = 2; in tpg_s_fourcc()
394 tpg->twopixelsize[0] = 2 * 2; in tpg_s_fourcc()
399 tpg->twopixelsize[0] = 2 * 3; in tpg_s_fourcc()
420 tpg->twopixelsize[0] = 2 * 4; in tpg_s_fourcc()
434 tpg->twopixelsize[0] = 2; in tpg_s_fourcc()
435 tpg->twopixelsize[1] = 2; in tpg_s_fourcc()
449 tpg->twopixelsize[0] = 4; in tpg_s_fourcc()
450 tpg->twopixelsize[1] = 4; in tpg_s_fourcc()
461 tpg->twopixelsize[0] = 2; in tpg_s_fourcc()
462 tpg->twopixelsize[1] = 2; in tpg_s_fourcc()
463 tpg->twopixelsize[2] = 2; in tpg_s_fourcc()
467 tpg->twopixelsize[0] = 2; in tpg_s_fourcc()
468 tpg->twopixelsize[1] = 4; in tpg_s_fourcc()
478 tpg->crop = *crop; in tpg_s_crop_compose()
479 tpg->compose = *compose; in tpg_s_crop_compose()
480 tpg->scaled_width = (tpg->src_width * tpg->compose.width + in tpg_s_crop_compose()
481 tpg->crop.width - 1) / tpg->crop.width; in tpg_s_crop_compose()
482 tpg->scaled_width &= ~1; in tpg_s_crop_compose()
483 if (tpg->scaled_width > tpg->max_line_width) in tpg_s_crop_compose()
484 tpg->scaled_width = tpg->max_line_width; in tpg_s_crop_compose()
485 if (tpg->scaled_width < 2) in tpg_s_crop_compose()
486 tpg->scaled_width = 2; in tpg_s_crop_compose()
487 tpg->recalc_lines = true; in tpg_s_crop_compose()
496 tpg->src_width = width; in tpg_reset_source()
497 tpg->src_height = height; in tpg_reset_source()
498 tpg->field = field; in tpg_reset_source()
499 tpg->buf_height = height; in tpg_reset_source()
501 tpg->buf_height /= 2; in tpg_reset_source()
502 tpg->scaled_width = width; in tpg_reset_source()
503 tpg->crop.top = tpg->crop.left = 0; in tpg_reset_source()
504 tpg->crop.width = width; in tpg_reset_source()
505 tpg->crop.height = height; in tpg_reset_source()
506 tpg->compose.top = tpg->compose.left = 0; in tpg_reset_source()
507 tpg->compose.width = width; in tpg_reset_source()
508 tpg->compose.height = tpg->buf_height; in tpg_reset_source()
509 for (p = 0; p < tpg->planes; p++) in tpg_reset_source()
510 tpg->bytesperline[p] = (width * tpg->twopixelsize[p]) / in tpg_reset_source()
511 (2 * tpg->hdownsampling[p]); in tpg_reset_source()
512 tpg->recalc_square_border = true; in tpg_reset_source()
518 switch (tpg->pattern) { in tpg_get_textbg_color()
530 switch (tpg->pattern) { in tpg_get_textfg_color()
576 diff_rgb = max_rgb - min_rgb; in color_to_hsv()
586 third_size = (tpg->real_hsv_enc == V4L2_HSV_ENC_180) ? 60 : 85; in color_to_hsv()
590 aux = g - b; in color_to_hsv()
593 aux = b - r; in color_to_hsv()
596 aux = r - g; in color_to_hsv()
606 if (tpg->real_hsv_enc == V4L2_HSV_ENC_180) { in color_to_hsv()
610 aux -= 180; in color_to_hsv()
619 int y_offset, int *y, int *cb, int *cr) in rgb2ycbcr() argument
621 *y = ((m[0][0] * r + m[0][1] * g + m[0][2] * b) >> 16) + (y_offset << 4); in rgb2ycbcr()
627 int *y, int *cb, int *cr) in color_to_ycbcr() argument
633 { COEFF(-0.1687, 224), COEFF(-0.3313, 224), COEFF(0.5, 224) }, in color_to_ycbcr()
634 { COEFF(0.5, 224), COEFF(-0.4187, 224), COEFF(-0.0813, 224) }, in color_to_ycbcr()
638 { COEFF(-0.1687, 255), COEFF(-0.3313, 255), COEFF(0.5, 255) }, in color_to_ycbcr()
639 { COEFF(0.5, 255), COEFF(-0.4187, 255), COEFF(-0.0813, 255) }, in color_to_ycbcr()
643 { COEFF(-0.1146, 224), COEFF(-0.3854, 224), COEFF(0.5, 224) }, in color_to_ycbcr()
644 { COEFF(0.5, 224), COEFF(-0.4542, 224), COEFF(-0.0458, 224) }, in color_to_ycbcr()
648 { COEFF(-0.1146, 255), COEFF(-0.3854, 255), COEFF(0.5, 255) }, in color_to_ycbcr()
649 { COEFF(0.5, 255), COEFF(-0.4542, 255), COEFF(-0.0458, 255) }, in color_to_ycbcr()
653 { COEFF(-0.116, 224), COEFF(-0.384, 224), COEFF(0.5, 224) }, in color_to_ycbcr()
654 { COEFF(0.5, 224), COEFF(-0.445, 224), COEFF(-0.055, 224) }, in color_to_ycbcr()
658 { COEFF(-0.116, 255), COEFF(-0.384, 255), COEFF(0.5, 255) }, in color_to_ycbcr()
659 { COEFF(0.5, 255), COEFF(-0.445, 255), COEFF(-0.055, 255) }, in color_to_ycbcr()
663 { COEFF(-0.1396, 224), COEFF(-0.3604, 224), COEFF(0.5, 224) }, in color_to_ycbcr()
664 { COEFF(0.5, 224), COEFF(-0.4598, 224), COEFF(-0.0402, 224) }, in color_to_ycbcr()
668 { COEFF(-0.1396, 255), COEFF(-0.3604, 255), COEFF(0.5, 255) }, in color_to_ycbcr()
669 { COEFF(0.5, 255), COEFF(-0.4598, 255), COEFF(-0.0402, 255) }, in color_to_ycbcr()
680 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE; in color_to_ycbcr()
684 switch (tpg->real_ycbcr_enc) { in color_to_ycbcr()
686 rgb2ycbcr(full ? bt601_full : bt601, r, g, b, y_offset, y, cb, cr); in color_to_ycbcr()
690 * Y'CbCr encoding. */ in color_to_ycbcr()
691 rgb2ycbcr(bt601, r, g, b, 16, y, cb, cr); in color_to_ycbcr()
695 * Y'CbCr encoding. */ in color_to_ycbcr()
696 rgb2ycbcr(rec709, r, g, b, 16, y, cb, cr); in color_to_ycbcr()
699 rgb2ycbcr(full ? bt2020_full : bt2020, r, g, b, y_offset, y, cb, cr); in color_to_ycbcr()
706 *y = full ? yc : (yc * 219) / 255 + (16 << 4); in color_to_ycbcr()
708 *cb = (((b - yc) * (full ? bt2020c_full[0] : bt2020c[0])) >> 16) + (128 << 4); in color_to_ycbcr()
710 *cb = (((b - yc) * (full ? bt2020c_full[1] : bt2020c[1])) >> 16) + (128 << 4); in color_to_ycbcr()
712 *cr = (((r - yc) * (full ? bt2020c_full[2] : bt2020c[2])) >> 16) + (128 << 4); in color_to_ycbcr()
714 *cr = (((r - yc) * (full ? bt2020c_full[3] : bt2020c[3])) >> 16) + (128 << 4); in color_to_ycbcr()
717 rgb2ycbcr(full ? smpte240m_full : smpte240m, r, g, b, y_offset, y, cb, cr); in color_to_ycbcr()
721 rgb2ycbcr(full ? rec709_full : rec709, r, g, b, y_offset, y, cb, cr); in color_to_ycbcr()
726 static void ycbcr2rgb(const int m[3][3], int y, int cb, int cr, in ycbcr2rgb() argument
729 y -= y_offset << 4; in ycbcr2rgb()
730 cb -= 128 << 4; in ycbcr2rgb()
731 cr -= 128 << 4; in ycbcr2rgb()
732 *r = m[0][0] * y + m[0][1] * cb + m[0][2] * cr; in ycbcr2rgb()
733 *g = m[1][0] * y + m[1][1] * cb + m[1][2] * cr; in ycbcr2rgb()
734 *b = m[2][0] * y + m[2][1] * cb + m[2][2] * cr; in ycbcr2rgb()
740 static void ycbcr_to_color(struct tpg_data *tpg, int y, int cb, int cr, in ycbcr_to_color() argument
747 { COEFF(1, 219), COEFF(-0.3441, 224), COEFF(-0.7141, 224) }, in ycbcr_to_color()
752 { COEFF(1, 255), COEFF(-0.3441, 255), COEFF(-0.7141, 255) }, in ycbcr_to_color()
757 { COEFF(1, 219), COEFF(-0.1873, 224), COEFF(-0.4681, 224) }, in ycbcr_to_color()
762 { COEFF(1, 255), COEFF(-0.1873, 255), COEFF(-0.4681, 255) }, in ycbcr_to_color()
767 { COEFF(1, 219), COEFF(-0.2253, 224), COEFF(-0.4767, 224) }, in ycbcr_to_color()
772 { COEFF(1, 255), COEFF(-0.2253, 255), COEFF(-0.4767, 255) }, in ycbcr_to_color()
777 { COEFF(1, 219), COEFF(-0.1646, 224), COEFF(-0.5714, 224) }, in ycbcr_to_color()
782 { COEFF(1, 255), COEFF(-0.1646, 255), COEFF(-0.5714, 255) }, in ycbcr_to_color()
794 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE; in ycbcr_to_color()
799 switch (tpg->real_ycbcr_enc) { in ycbcr_to_color()
801 ycbcr2rgb(full ? bt601_full : bt601, y, cb, cr, y_offset, r, g, b); in ycbcr_to_color()
805 * Y'CbCr encoding. */ in ycbcr_to_color()
806 ycbcr2rgb(bt601, y, cb, cr, 16, r, g, b); in ycbcr_to_color()
810 * Y'CbCr encoding. */ in ycbcr_to_color()
811 ycbcr2rgb(rec709, y, cb, cr, 16, r, g, b); in ycbcr_to_color()
814 ycbcr2rgb(full ? bt2020_full : bt2020, y, cb, cr, y_offset, r, g, b); in ycbcr_to_color()
817 y -= full ? 0 : 16 << 4; in ycbcr_to_color()
818 cb -= 128 << 4; in ycbcr_to_color()
819 cr -= 128 << 4; in ycbcr_to_color()
822 *b = y_fac * y + (full ? bt2020c_full[0] : bt2020c[0]) * cb; in ycbcr_to_color()
824 *b = y_fac * y + (full ? bt2020c_full[1] : bt2020c[1]) * cb; in ycbcr_to_color()
827 *r = y_fac * y + (full ? bt2020c_full[2] : bt2020c[2]) * cr; in ycbcr_to_color()
829 *r = y_fac * y + (full ? bt2020c_full[3] : bt2020c[3]) * cr; in ycbcr_to_color()
833 lin_y = rec709_to_linear((y * 255) / (full ? 255 : 219)); in ycbcr_to_color()
835 lin_g = COEFF(1.0 / 0.6780, 255) * lin_y - in ycbcr_to_color()
836 COEFF(0.2627 / 0.6780, 255) * lin_r - in ycbcr_to_color()
841 ycbcr2rgb(full ? smpte240m_full : smpte240m, y, cb, cr, y_offset, r, g, b); in ycbcr_to_color()
845 ycbcr2rgb(full ? rec709_full : rec709, y, cb, cr, y_offset, r, g, b); in ycbcr_to_color()
857 int y, cb, cr; in precalculate_color() local
872 } else if (tpg->pattern == TPG_PAT_NOISE) { in precalculate_color()
875 r = g = b = tpg->qual_offset + get_random_u32_below(196); in precalculate_color()
877 r = g = b = k - TPG_COLOR_RAMP; in precalculate_color()
880 if (tpg->pattern == TPG_PAT_CSC_COLORBAR && col <= TPG_COLOR_CSC_BLACK) { in precalculate_color()
881 r = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].r; in precalculate_color()
882 g = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].g; in precalculate_color()
883 b = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].b; in precalculate_color()
890 if (tpg->qual == TPG_QUAL_GRAY || in precalculate_color()
891 tpg->color_enc == TGP_COLOR_ENC_LUMA) { in precalculate_color()
902 * Remember that r, g and b are still in the 0 - 0xff0 range. in precalculate_color()
904 if (tpg->real_rgb_range == V4L2_DV_RGB_RANGE_LIMITED && in precalculate_color()
905 tpg->rgb_range == V4L2_DV_RGB_RANGE_FULL && in precalculate_color()
906 tpg->color_enc == TGP_COLOR_ENC_RGB) { in precalculate_color()
915 } else if (tpg->real_rgb_range != V4L2_DV_RGB_RANGE_LIMITED && in precalculate_color()
916 tpg->rgb_range == V4L2_DV_RGB_RANGE_LIMITED && in precalculate_color()
917 tpg->color_enc == TGP_COLOR_ENC_RGB) { in precalculate_color()
926 r = (r - (16 << 4)) * 255 / 219; in precalculate_color()
927 g = (g - (16 << 4)) * 255 / 219; in precalculate_color()
928 b = (b - (16 << 4)) * 255 / 219; in precalculate_color()
931 if ((tpg->brightness != 128 || tpg->contrast != 128 || in precalculate_color()
932 tpg->saturation != 128 || tpg->hue) && in precalculate_color()
933 tpg->color_enc != TGP_COLOR_ENC_LUMA) { in precalculate_color()
939 color_to_ycbcr(tpg, r, g, b, &y, &cb, &cr); in precalculate_color()
941 y = (16 << 4) + ((y - (16 << 4)) * tpg->contrast) / 128; in precalculate_color()
942 y += (tpg->brightness << 4) - (128 << 4); in precalculate_color()
944 cb -= 128 << 4; in precalculate_color()
945 cr -= 128 << 4; in precalculate_color()
946 tmp_cb = (cb * cos(128 + tpg->hue)) / 127 + (cr * sin[128 + tpg->hue]) / 127; in precalculate_color()
947 tmp_cr = (cr * cos(128 + tpg->hue)) / 127 - (cb * sin[128 + tpg->hue]) / 127; in precalculate_color()
949 cb = (128 << 4) + (tmp_cb * tpg->contrast * tpg->saturation) / (128 * 128); in precalculate_color()
950 cr = (128 << 4) + (tmp_cr * tpg->contrast * tpg->saturation) / (128 * 128); in precalculate_color()
951 if (tpg->color_enc == TGP_COLOR_ENC_YCBCR) in precalculate_color()
954 ycbcr_to_color(tpg, y, cb, cr, &r, &g, &b); in precalculate_color()
955 } else if ((tpg->brightness != 128 || tpg->contrast != 128) && in precalculate_color()
956 tpg->color_enc == TGP_COLOR_ENC_LUMA) { in precalculate_color()
957 r = (16 << 4) + ((r - (16 << 4)) * tpg->contrast) / 128; in precalculate_color()
958 r += (tpg->brightness << 4) - (128 << 4); in precalculate_color()
961 switch (tpg->color_enc) { in precalculate_color()
967 tpg->colors[k][0] = h; in precalculate_color()
968 tpg->colors[k][1] = s; in precalculate_color()
969 tpg->colors[k][2] = v; in precalculate_color()
976 color_to_ycbcr(tpg, r, g, b, &y, &cb, &cr); in precalculate_color()
978 y >>= 4; in precalculate_color()
983 * and B' values outside the range [0-1]. So do not clamp in precalculate_color()
986 if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE && in precalculate_color()
987 tpg->real_ycbcr_enc != V4L2_YCBCR_ENC_XV601 && in precalculate_color()
988 tpg->real_ycbcr_enc != V4L2_YCBCR_ENC_XV709) { in precalculate_color()
989 y = clamp(y, 16, 235); in precalculate_color()
993 y = clamp(y, 1, 254); in precalculate_color()
997 switch (tpg->fourcc) { in precalculate_color()
999 y >>= 4; in precalculate_color()
1004 y >>= 3; in precalculate_color()
1009 y >>= 3; in precalculate_color()
1014 tpg->colors[k][0] = y; in precalculate_color()
1015 tpg->colors[k][1] = cb; in precalculate_color()
1016 tpg->colors[k][2] = cr; in precalculate_color()
1021 tpg->colors[k][0] = r >> 4; in precalculate_color()
1026 if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) { in precalculate_color()
1031 switch (tpg->fourcc) { in precalculate_color()
1084 tpg->colors[k][0] = r; in precalculate_color()
1085 tpg->colors[k][1] = g; in precalculate_color()
1086 tpg->colors[k][2] = b; in precalculate_color()
1104 unsigned offset = odd * tpg->twopixelsize[0] / 2; in gen_twopix() local
1105 u8 alpha = tpg->alpha_component; in gen_twopix()
1108 if (tpg->alpha_red_only && color != TPG_COLOR_CSC_RED && in gen_twopix()
1114 r_y_h = tpg->colors[color][0]; /* R or precalculated Y, H */ in gen_twopix()
1115 g_u_s = tpg->colors[color][1]; /* G or precalculated U, V */ in gen_twopix()
1116 b_v = tpg->colors[color][2]; /* B or precalculated V */ in gen_twopix()
1118 switch (tpg->fourcc) { in gen_twopix()
1120 buf[0][offset] = r_y_h; in gen_twopix()
1123 buf[0][offset] = (r_y_h << 2) & 0xff; in gen_twopix()
1124 buf[0][offset+1] = r_y_h >> 6; in gen_twopix()
1127 buf[0][offset] = (r_y_h << 4) & 0xff; in gen_twopix()
1128 buf[0][offset+1] = r_y_h >> 4; in gen_twopix()
1138 buf[0][offset] = r_y_h == 0xff ? r_y_h : 0; in gen_twopix()
1139 buf[0][offset+1] = r_y_h; in gen_twopix()
1143 buf[0][offset] = r_y_h; in gen_twopix()
1144 buf[0][offset+1] = r_y_h == 0xff ? r_y_h : 0; in gen_twopix()
1150 buf[0][offset] = r_y_h; in gen_twopix()
1164 buf[0][offset] = r_y_h; in gen_twopix()
1180 buf[0][offset] = r_y_h; in gen_twopix()
1193 buf[0][offset] = r_y_h; in gen_twopix()
1204 buf[0][offset] = r_y_h; in gen_twopix()
1205 buf[1][offset] = g_u_s; in gen_twopix()
1206 buf[2][offset] = b_v; in gen_twopix()
1210 buf[0][offset] = r_y_h; in gen_twopix()
1211 buf[1][offset] = b_v; in gen_twopix()
1212 buf[2][offset] = g_u_s; in gen_twopix()
1216 buf[0][offset] = r_y_h; in gen_twopix()
1217 buf[1][2 * offset] = g_u_s; in gen_twopix()
1218 buf[1][(2 * offset + 1) % 8] = b_v; in gen_twopix()
1222 buf[0][offset] = r_y_h; in gen_twopix()
1223 buf[1][2 * offset] = b_v; in gen_twopix()
1224 buf[1][(2 * offset + 1) % 8] = g_u_s; in gen_twopix()
1228 buf[0][offset] = r_y_h; in gen_twopix()
1238 buf[0][offset + 1] = r_y_h; in gen_twopix()
1248 buf[0][offset] = r_y_h; in gen_twopix()
1258 buf[0][offset + 1] = r_y_h; in gen_twopix()
1268 buf[0][offset] = (r_y_h << 5) | (g_u_s << 2) | b_v; in gen_twopix()
1272 buf[0][offset] = (g_u_s << 5) | b_v; in gen_twopix()
1273 buf[0][offset + 1] = (r_y_h << 3) | (g_u_s >> 3); in gen_twopix()
1276 buf[0][offset] = (r_y_h << 3) | (g_u_s >> 3); in gen_twopix()
1277 buf[0][offset + 1] = (g_u_s << 5) | b_v; in gen_twopix()
1285 buf[0][offset] = (g_u_s << 4) | b_v; in gen_twopix()
1286 buf[0][offset + 1] = (alpha & 0xf0) | r_y_h; in gen_twopix()
1292 buf[0][offset] = (b_v << 4) | (alpha >> 4); in gen_twopix()
1293 buf[0][offset + 1] = (r_y_h << 4) | g_u_s; in gen_twopix()
1299 buf[0][offset] = (g_u_s << 4) | r_y_h; in gen_twopix()
1300 buf[0][offset + 1] = (alpha & 0xf0) | b_v; in gen_twopix()
1306 buf[0][offset] = (r_y_h << 4) | (alpha >> 4); in gen_twopix()
1307 buf[0][offset + 1] = (b_v << 4) | g_u_s; in gen_twopix()
1315 buf[0][offset] = (g_u_s << 5) | b_v; in gen_twopix()
1316 buf[0][offset + 1] = (alpha & 0x80) | (r_y_h << 2) in gen_twopix()
1323 buf[0][offset] = (g_u_s << 6) | (b_v << 1) | in gen_twopix()
1325 buf[0][offset + 1] = (r_y_h << 3) | (g_u_s >> 2); in gen_twopix()
1331 buf[0][offset] = (g_u_s << 5) | r_y_h; in gen_twopix()
1332 buf[0][offset + 1] = (alpha & 0x80) | (b_v << 2) in gen_twopix()
1339 buf[0][offset] = (g_u_s << 6) | (r_y_h << 1) | in gen_twopix()
1341 buf[0][offset + 1] = (b_v << 3) | (g_u_s >> 2); in gen_twopix()
1348 buf[0][offset] = (alpha & 0x80) | (r_y_h << 2) | (g_u_s >> 3); in gen_twopix()
1349 buf[0][offset + 1] = (g_u_s << 5) | b_v; in gen_twopix()
1353 buf[0][offset] = r_y_h; in gen_twopix()
1354 buf[0][offset + 1] = g_u_s; in gen_twopix()
1355 buf[0][offset + 2] = b_v; in gen_twopix()
1358 buf[0][offset] = b_v; in gen_twopix()
1359 buf[0][offset + 1] = g_u_s; in gen_twopix()
1360 buf[0][offset + 2] = r_y_h; in gen_twopix()
1363 buf[0][offset] = (b_v << 2) | (g_u_s >> 4); in gen_twopix()
1364 buf[0][offset + 1] = (g_u_s << 4) | (r_y_h >> 2); in gen_twopix()
1365 buf[0][offset + 2] = r_y_h << 6; in gen_twopix()
1366 buf[0][offset + 3] = 0; in gen_twopix()
1377 buf[0][offset] = alpha; in gen_twopix()
1378 buf[0][offset + 1] = r_y_h; in gen_twopix()
1379 buf[0][offset + 2] = g_u_s; in gen_twopix()
1380 buf[0][offset + 3] = b_v; in gen_twopix()
1388 buf[0][offset] = r_y_h; in gen_twopix()
1389 buf[0][offset + 1] = g_u_s; in gen_twopix()
1390 buf[0][offset + 2] = b_v; in gen_twopix()
1391 buf[0][offset + 3] = alpha; in gen_twopix()
1400 buf[0][offset] = b_v; in gen_twopix()
1401 buf[0][offset + 1] = g_u_s; in gen_twopix()
1402 buf[0][offset + 2] = r_y_h; in gen_twopix()
1403 buf[0][offset + 3] = alpha; in gen_twopix()
1409 buf[0][offset] = alpha; in gen_twopix()
1410 buf[0][offset + 1] = b_v; in gen_twopix()
1411 buf[0][offset + 2] = g_u_s; in gen_twopix()
1412 buf[0][offset + 3] = r_y_h; in gen_twopix()
1415 buf[0][offset] = odd ? g_u_s : b_v; in gen_twopix()
1416 buf[1][offset] = odd ? r_y_h : g_u_s; in gen_twopix()
1419 buf[0][offset] = odd ? b_v : g_u_s; in gen_twopix()
1420 buf[1][offset] = odd ? g_u_s : r_y_h; in gen_twopix()
1423 buf[0][offset] = odd ? r_y_h : g_u_s; in gen_twopix()
1424 buf[1][offset] = odd ? g_u_s : b_v; in gen_twopix()
1427 buf[0][offset] = odd ? g_u_s : r_y_h; in gen_twopix()
1428 buf[1][offset] = odd ? b_v : g_u_s; in gen_twopix()
1431 buf[0][offset] = odd ? g_u_s << 2 : b_v << 2; in gen_twopix()
1432 buf[0][offset + 1] = odd ? g_u_s >> 6 : b_v >> 6; in gen_twopix()
1433 buf[1][offset] = odd ? r_y_h << 2 : g_u_s << 2; in gen_twopix()
1434 buf[1][offset + 1] = odd ? r_y_h >> 6 : g_u_s >> 6; in gen_twopix()
1435 buf[0][offset] |= (buf[0][offset] >> 2) & 3; in gen_twopix()
1436 buf[1][offset] |= (buf[1][offset] >> 2) & 3; in gen_twopix()
1439 buf[0][offset] = odd ? b_v << 2 : g_u_s << 2; in gen_twopix()
1440 buf[0][offset + 1] = odd ? b_v >> 6 : g_u_s >> 6; in gen_twopix()
1441 buf[1][offset] = odd ? g_u_s << 2 : r_y_h << 2; in gen_twopix()
1442 buf[1][offset + 1] = odd ? g_u_s >> 6 : r_y_h >> 6; in gen_twopix()
1443 buf[0][offset] |= (buf[0][offset] >> 2) & 3; in gen_twopix()
1444 buf[1][offset] |= (buf[1][offset] >> 2) & 3; in gen_twopix()
1447 buf[0][offset] = odd ? r_y_h << 2 : g_u_s << 2; in gen_twopix()
1448 buf[0][offset + 1] = odd ? r_y_h >> 6 : g_u_s >> 6; in gen_twopix()
1449 buf[1][offset] = odd ? g_u_s << 2 : b_v << 2; in gen_twopix()
1450 buf[1][offset + 1] = odd ? g_u_s >> 6 : b_v >> 6; in gen_twopix()
1451 buf[0][offset] |= (buf[0][offset] >> 2) & 3; in gen_twopix()
1452 buf[1][offset] |= (buf[1][offset] >> 2) & 3; in gen_twopix()
1455 buf[0][offset] = odd ? g_u_s << 2 : r_y_h << 2; in gen_twopix()
1456 buf[0][offset + 1] = odd ? g_u_s >> 6 : r_y_h >> 6; in gen_twopix()
1457 buf[1][offset] = odd ? b_v << 2 : g_u_s << 2; in gen_twopix()
1458 buf[1][offset + 1] = odd ? b_v >> 6 : g_u_s >> 6; in gen_twopix()
1459 buf[0][offset] |= (buf[0][offset] >> 2) & 3; in gen_twopix()
1460 buf[1][offset] |= (buf[1][offset] >> 2) & 3; in gen_twopix()
1463 buf[0][offset] = odd ? g_u_s << 4 : b_v << 4; in gen_twopix()
1464 buf[0][offset + 1] = odd ? g_u_s >> 4 : b_v >> 4; in gen_twopix()
1465 buf[1][offset] = odd ? r_y_h << 4 : g_u_s << 4; in gen_twopix()
1466 buf[1][offset + 1] = odd ? r_y_h >> 4 : g_u_s >> 4; in gen_twopix()
1467 buf[0][offset] |= (buf[0][offset] >> 4) & 0xf; in gen_twopix()
1468 buf[1][offset] |= (buf[1][offset] >> 4) & 0xf; in gen_twopix()
1471 buf[0][offset] = odd ? b_v << 4 : g_u_s << 4; in gen_twopix()
1472 buf[0][offset + 1] = odd ? b_v >> 4 : g_u_s >> 4; in gen_twopix()
1473 buf[1][offset] = odd ? g_u_s << 4 : r_y_h << 4; in gen_twopix()
1474 buf[1][offset + 1] = odd ? g_u_s >> 4 : r_y_h >> 4; in gen_twopix()
1475 buf[0][offset] |= (buf[0][offset] >> 4) & 0xf; in gen_twopix()
1476 buf[1][offset] |= (buf[1][offset] >> 4) & 0xf; in gen_twopix()
1479 buf[0][offset] = odd ? r_y_h << 4 : g_u_s << 4; in gen_twopix()
1480 buf[0][offset + 1] = odd ? r_y_h >> 4 : g_u_s >> 4; in gen_twopix()
1481 buf[1][offset] = odd ? g_u_s << 4 : b_v << 4; in gen_twopix()
1482 buf[1][offset + 1] = odd ? g_u_s >> 4 : b_v >> 4; in gen_twopix()
1483 buf[0][offset] |= (buf[0][offset] >> 4) & 0xf; in gen_twopix()
1484 buf[1][offset] |= (buf[1][offset] >> 4) & 0xf; in gen_twopix()
1487 buf[0][offset] = odd ? g_u_s << 4 : r_y_h << 4; in gen_twopix()
1488 buf[0][offset + 1] = odd ? g_u_s >> 4 : r_y_h >> 4; in gen_twopix()
1489 buf[1][offset] = odd ? b_v << 4 : g_u_s << 4; in gen_twopix()
1490 buf[1][offset + 1] = odd ? b_v >> 4 : g_u_s >> 4; in gen_twopix()
1491 buf[0][offset] |= (buf[0][offset] >> 4) & 0xf; in gen_twopix()
1492 buf[1][offset] |= (buf[1][offset] >> 4) & 0xf; in gen_twopix()
1495 buf[0][offset] = buf[0][offset + 1] = odd ? g_u_s : b_v; in gen_twopix()
1496 buf[1][offset] = buf[1][offset + 1] = odd ? r_y_h : g_u_s; in gen_twopix()
1499 buf[0][offset] = buf[0][offset + 1] = odd ? b_v : g_u_s; in gen_twopix()
1500 buf[1][offset] = buf[1][offset + 1] = odd ? g_u_s : r_y_h; in gen_twopix()
1503 buf[0][offset] = buf[0][offset + 1] = odd ? r_y_h : g_u_s; in gen_twopix()
1504 buf[1][offset] = buf[1][offset + 1] = odd ? g_u_s : b_v; in gen_twopix()
1507 buf[0][offset] = buf[0][offset + 1] = odd ? g_u_s : r_y_h; in gen_twopix()
1508 buf[1][offset] = buf[1][offset + 1] = odd ? b_v : g_u_s; in gen_twopix()
1515 switch (tpg->fourcc) { in tpg_g_interleaved_plane()
1542 switch (tpg->pattern) { in tpg_get_pat_lines()
1564 switch (tpg->pattern) { in tpg_get_pat_line()
1576 return (line * 8) / tpg->src_height; in tpg_get_pat_line()
1578 return line == tpg->src_height / 2; in tpg_get_pat_line()
1580 return (line + 1) / 2 == tpg->src_height / 4; in tpg_get_pat_line()
1582 return (line + 10) / 20 == tpg->src_height / 40; in tpg_get_pat_line()
1590 * Note: x is in the range 0 to 2 * tpg->src_width.
1595 /* Maximum number of bars are TPG_COLOR_MAX - otherwise, the input print code in tpg_get_color()
1598 /* Standard ITU-R 75% color bar sequence */ in tpg_get_color()
1603 /* Standard ITU-R 100% color bar sequence */ in tpg_get_color()
1615 switch (tpg->pattern) { in tpg_get_color()
1619 return bars[tpg->pattern][((x * 8) / tpg->src_width) % 8]; in tpg_get_color()
1621 return bars[1][(pat_line + (x * 8) / tpg->src_width) % 8]; in tpg_get_color()
1654 if (pat_line || (x % tpg->src_width) == tpg->src_width / 2) in tpg_get_color()
1658 if (pat_line || ((x % tpg->src_width) + 1) / 2 == tpg->src_width / 4) in tpg_get_color()
1662 if (pat_line || ((x % tpg->src_width) + 10) / 20 == tpg->src_width / 40) in tpg_get_color()
1666 return TPG_COLOR_RAMP + ((x % tpg->src_width) * 256) / tpg->src_width; in tpg_get_color()
1680 unsigned w = tpg->src_width; in tpg_calculate_square_border()
1681 unsigned h = tpg->src_height; in tpg_calculate_square_border()
1685 if (((w - sq_w) / 2) & 1) in tpg_calculate_square_border()
1688 tpg->square.width = sq_w; in tpg_calculate_square_border()
1689 if (tpg->vid_aspect == TPG_VIDEO_ASPECT_16X9_ANAMORPHIC) { in tpg_calculate_square_border()
1692 if (((w - ana_sq_w) / 2) & 1) in tpg_calculate_square_border()
1694 tpg->square.width = ana_sq_w; in tpg_calculate_square_border()
1696 tpg->square.left = (w - tpg->square.width) / 2; in tpg_calculate_square_border()
1697 if (tpg->pix_aspect == TPG_PIXEL_ASPECT_NTSC) in tpg_calculate_square_border()
1699 else if (tpg->pix_aspect == TPG_PIXEL_ASPECT_PAL) in tpg_calculate_square_border()
1701 tpg->square.height = sq_h; in tpg_calculate_square_border()
1702 tpg->square.top = (h - sq_h) / 2; in tpg_calculate_square_border()
1703 tpg->border.left = 0; in tpg_calculate_square_border()
1704 tpg->border.width = w; in tpg_calculate_square_border()
1705 tpg->border.top = 0; in tpg_calculate_square_border()
1706 tpg->border.height = h; in tpg_calculate_square_border()
1707 switch (tpg->vid_aspect) { in tpg_calculate_square_border()
1709 if (tpg->pix_aspect) in tpg_calculate_square_border()
1712 tpg->border.width = ((4 * h) / 3) & ~1; in tpg_calculate_square_border()
1713 if (((w - tpg->border.width) / 2) & ~1) in tpg_calculate_square_border()
1714 tpg->border.width -= 2; in tpg_calculate_square_border()
1715 tpg->border.left = (w - tpg->border.width) / 2; in tpg_calculate_square_border()
1718 tpg->border.height = ((3 * w) / 4) & ~1; in tpg_calculate_square_border()
1719 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1722 if (tpg->pix_aspect) { in tpg_calculate_square_border()
1723 tpg->border.height = tpg->pix_aspect == TPG_PIXEL_ASPECT_NTSC ? 420 : 506; in tpg_calculate_square_border()
1724 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1728 tpg->border.width = ((14 * h) / 9) & ~1; in tpg_calculate_square_border()
1729 if (((w - tpg->border.width) / 2) & ~1) in tpg_calculate_square_border()
1730 tpg->border.width -= 2; in tpg_calculate_square_border()
1731 tpg->border.left = (w - tpg->border.width) / 2; in tpg_calculate_square_border()
1734 tpg->border.height = ((9 * w) / 14) & ~1; in tpg_calculate_square_border()
1735 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1738 if (tpg->pix_aspect) { in tpg_calculate_square_border()
1739 tpg->border.height = tpg->pix_aspect == TPG_PIXEL_ASPECT_NTSC ? 368 : 442; in tpg_calculate_square_border()
1740 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1744 tpg->border.width = ((16 * h) / 9) & ~1; in tpg_calculate_square_border()
1745 if (((w - tpg->border.width) / 2) & ~1) in tpg_calculate_square_border()
1746 tpg->border.width -= 2; in tpg_calculate_square_border()
1747 tpg->border.left = (w - tpg->border.width) / 2; in tpg_calculate_square_border()
1750 tpg->border.height = ((9 * w) / 16) & ~1; in tpg_calculate_square_border()
1751 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1766 switch (tpg->pattern) { in tpg_precalculate_line()
1780 unsigned int_part = tpg->src_width / tpg->scaled_width; in tpg_precalculate_line()
1781 unsigned fract_part = tpg->src_width % tpg->scaled_width; in tpg_precalculate_line()
1785 for (x = 0; x < tpg->scaled_width * 2; x += 2) { in tpg_precalculate_line()
1789 real_x = tpg->hflip ? tpg->src_width * 2 - real_x - 2 : real_x; in tpg_precalculate_line()
1794 if (error >= tpg->scaled_width) { in tpg_precalculate_line()
1795 error -= tpg->scaled_width; in tpg_precalculate_line()
1800 real_x = tpg->hflip ? tpg->src_width * 2 - real_x - 2 : real_x; in tpg_precalculate_line()
1805 if (error >= tpg->scaled_width) { in tpg_precalculate_line()
1806 error -= tpg->scaled_width; in tpg_precalculate_line()
1810 gen_twopix(tpg, pix, tpg->hflip ? color2 : color1, 0); in tpg_precalculate_line()
1811 gen_twopix(tpg, pix, tpg->hflip ? color1 : color2, 1); in tpg_precalculate_line()
1812 for (p = 0; p < tpg->planes; p++) { in tpg_precalculate_line()
1813 unsigned twopixsize = tpg->twopixelsize[p]; in tpg_precalculate_line()
1814 unsigned hdiv = tpg->hdownsampling[p]; in tpg_precalculate_line()
1815 u8 *pos = tpg->lines[pat][p] + tpg_hdiv(tpg, p, x); in tpg_precalculate_line()
1822 if (tpg->vdownsampling[tpg->planes - 1] > 1) { in tpg_precalculate_line()
1828 for (p = 1; p < tpg->planes; p++) { in tpg_precalculate_line()
1829 unsigned w = tpg_hdiv(tpg, p, tpg->scaled_width * 2); in tpg_precalculate_line()
1830 u8 *pos1 = tpg->lines[pat][p]; in tpg_precalculate_line()
1831 u8 *pos2 = tpg->lines[next_pat][p]; in tpg_precalculate_line()
1832 u8 *dest = tpg->downsampled_lines[pat][p]; in tpg_precalculate_line()
1842 for (p = 0; p < tpg->planes; p++) { in tpg_precalculate_line()
1843 unsigned twopixsize = tpg->twopixelsize[p]; in tpg_precalculate_line()
1844 u8 *pos = tpg->contrast_line[p]; in tpg_precalculate_line()
1846 for (x = 0; x < tpg->scaled_width; x += 2, pos += twopixsize) in tpg_precalculate_line()
1852 for (p = 0; p < tpg->planes; p++) { in tpg_precalculate_line()
1853 unsigned twopixsize = tpg->twopixelsize[p]; in tpg_precalculate_line()
1854 u8 *pos = tpg->black_line[p]; in tpg_precalculate_line()
1856 for (x = 0; x < tpg->scaled_width; x += 2, pos += twopixsize) in tpg_precalculate_line()
1860 for (x = 0; x < tpg->scaled_width * 2; x += 2) { in tpg_precalculate_line()
1863 for (p = 0; p < tpg->planes; p++) { in tpg_precalculate_line()
1864 unsigned twopixsize = tpg->twopixelsize[p]; in tpg_precalculate_line()
1865 u8 *pos = tpg->random_line[p] + x * twopixsize / 2; in tpg_precalculate_line()
1871 gen_twopix(tpg, tpg->textbg, TPG_COLOR_TEXTBG, 0); in tpg_precalculate_line()
1872 gen_twopix(tpg, tpg->textbg, TPG_COLOR_TEXTBG, 1); in tpg_precalculate_line()
1873 gen_twopix(tpg, tpg->textfg, TPG_COLOR_TEXTFG, 0); in tpg_precalculate_line()
1874 gen_twopix(tpg, tpg->textfg, TPG_COLOR_TEXTFG, 1); in tpg_precalculate_line()
1881 unsigned vdiv = tpg->vdownsampling[p]; \
1882 unsigned hdiv = tpg->hdownsampling[p]; \
1886 memcpy(&fg, tpg->textfg[p], sizeof(PIXTYPE)); \
1887 memcpy(&bg, tpg->textbg[p], sizeof(PIXTYPE)); \
1890 int l = tpg->vflip ? 15 - line : line; \
1892 ((y * step + l) / (vdiv * div)) * tpg->bytesperline[p] + \
1899 if (hdiv == 2 && tpg->hflip) { \
1909 } else if (tpg->hflip) { \
1929 pos += (tpg->hflip ? -8 : 8) / (int)hdiv; \
1936 int y, int x, const char *text, unsigned len) in tpg_print_str_2() argument
1943 int y, int x, const char *text, unsigned len) in tpg_print_str_4() argument
1950 int y, int x, const char *text, unsigned len) in tpg_print_str_6() argument
1957 int y, int x, const char *text, unsigned len) in tpg_print_str_8() argument
1963 int y, int x, const char *text) in tpg_gen_text() argument
1965 unsigned step = V4L2_FIELD_HAS_T_OR_B(tpg->field) ? 2 : 1; in tpg_gen_text()
1977 if (y + 16 >= tpg->compose.height || x + 8 >= tpg->compose.width) in tpg_gen_text()
1980 if (len > (tpg->compose.width - x) / 8) in tpg_gen_text()
1981 len = (tpg->compose.width - x) / 8; in tpg_gen_text()
1982 if (tpg->vflip) in tpg_gen_text()
1983 y = tpg->compose.height - y - 16; in tpg_gen_text()
1984 if (tpg->hflip) in tpg_gen_text()
1985 x = tpg->compose.width - x - 8; in tpg_gen_text()
1986 y += tpg->compose.top; in tpg_gen_text()
1987 x += tpg->compose.left; in tpg_gen_text()
1988 if (tpg->field == V4L2_FIELD_BOTTOM) in tpg_gen_text()
1990 else if (tpg->field == V4L2_FIELD_SEQ_TB || tpg->field == V4L2_FIELD_SEQ_BT) in tpg_gen_text()
1993 for (p = 0; p < tpg->planes; p++) { in tpg_gen_text()
1995 switch (tpg->twopixelsize[p]) { in tpg_gen_text()
1997 tpg_print_str_2(tpg, basep, p, first, div, step, y, x, in tpg_gen_text()
2001 tpg_print_str_4(tpg, basep, p, first, div, step, y, x, in tpg_gen_text()
2005 tpg_print_str_6(tpg, basep, p, first, div, step, y, x, in tpg_gen_text()
2009 tpg_print_str_8(tpg, basep, p, first, div, step, y, x, in tpg_gen_text()
2019 switch (tpg->pattern) { in tpg_g_color_order()
2043 int factor = tpg->mv_hor_mode > TPG_MOVE_NONE ? -1 : 1; in tpg_update_mv_step()
2045 if (tpg->hflip) in tpg_update_mv_step()
2046 factor = -factor; in tpg_update_mv_step()
2047 switch (tpg->mv_hor_mode) { in tpg_update_mv_step()
2050 tpg->mv_hor_step = ((tpg->src_width + 319) / 320) * 4; in tpg_update_mv_step()
2054 tpg->mv_hor_step = ((tpg->src_width + 639) / 640) * 4; in tpg_update_mv_step()
2058 tpg->mv_hor_step = 2; in tpg_update_mv_step()
2061 tpg->mv_hor_step = 0; in tpg_update_mv_step()
2065 tpg->mv_hor_step = tpg->src_width - tpg->mv_hor_step; in tpg_update_mv_step()
2067 factor = tpg->mv_vert_mode > TPG_MOVE_NONE ? -1 : 1; in tpg_update_mv_step()
2068 switch (tpg->mv_vert_mode) { in tpg_update_mv_step()
2071 tpg->mv_vert_step = ((tpg->src_width + 319) / 320) * 4; in tpg_update_mv_step()
2075 tpg->mv_vert_step = ((tpg->src_width + 639) / 640) * 4; in tpg_update_mv_step()
2079 tpg->mv_vert_step = 1; in tpg_update_mv_step()
2082 tpg->mv_vert_step = 0; in tpg_update_mv_step()
2086 tpg->mv_vert_step = tpg->src_height - tpg->mv_vert_step; in tpg_update_mv_step()
2096 return tpg->crop.top + src_y * 2; in tpg_calc_frameline()
2098 return tpg->crop.top + src_y * 2 + 1; in tpg_calc_frameline()
2100 return src_y + tpg->crop.top; in tpg_calc_frameline()
2108 static unsigned tpg_calc_buffer_line(const struct tpg_data *tpg, unsigned y, in tpg_calc_buffer_line() argument
2111 y += tpg->compose.top; in tpg_calc_buffer_line()
2114 if (y & 1) in tpg_calc_buffer_line()
2115 return tpg->buf_height / 2 + y / 2; in tpg_calc_buffer_line()
2116 return y / 2; in tpg_calc_buffer_line()
2118 if (y & 1) in tpg_calc_buffer_line()
2119 return y / 2; in tpg_calc_buffer_line()
2120 return tpg->buf_height / 2 + y / 2; in tpg_calc_buffer_line()
2122 return y; in tpg_calc_buffer_line()
2128 if (tpg->recalc_colors) { in tpg_recalc()
2129 tpg->recalc_colors = false; in tpg_recalc()
2130 tpg->recalc_lines = true; in tpg_recalc()
2131 tpg->real_xfer_func = tpg->xfer_func; in tpg_recalc()
2132 tpg->real_ycbcr_enc = tpg->ycbcr_enc; in tpg_recalc()
2133 tpg->real_hsv_enc = tpg->hsv_enc; in tpg_recalc()
2134 tpg->real_quantization = tpg->quantization; in tpg_recalc()
2136 if (tpg->xfer_func == V4L2_XFER_FUNC_DEFAULT) in tpg_recalc()
2137 tpg->real_xfer_func = in tpg_recalc()
2138 V4L2_MAP_XFER_FUNC_DEFAULT(tpg->colorspace); in tpg_recalc()
2140 if (tpg->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) in tpg_recalc()
2141 tpg->real_ycbcr_enc = in tpg_recalc()
2142 V4L2_MAP_YCBCR_ENC_DEFAULT(tpg->colorspace); in tpg_recalc()
2144 if (tpg->quantization == V4L2_QUANTIZATION_DEFAULT) in tpg_recalc()
2145 tpg->real_quantization = in tpg_recalc()
2147 tpg->color_enc != TGP_COLOR_ENC_YCBCR, in tpg_recalc()
2148 tpg->colorspace, tpg->real_ycbcr_enc); in tpg_recalc()
2152 if (tpg->recalc_square_border) { in tpg_recalc()
2153 tpg->recalc_square_border = false; in tpg_recalc()
2156 if (tpg->recalc_lines) { in tpg_recalc()
2157 tpg->recalc_lines = false; in tpg_recalc()
2165 unsigned stride = tpg->bytesperline[p]; in tpg_calc_text_basep()
2166 unsigned h = tpg->buf_height; in tpg_calc_text_basep()
2172 h /= tpg->vdownsampling[p]; in tpg_calc_text_basep()
2173 if (tpg->field == V4L2_FIELD_SEQ_TB) in tpg_calc_text_basep()
2175 else if (tpg->field == V4L2_FIELD_SEQ_BT) in tpg_calc_text_basep()
2177 if (p == 0 && tpg->interleaved) in tpg_calc_text_basep()
2191 return -1; in tpg_pattern_avg()
2201 return "Y'CbCr"; in tpg_color_enc_str()
2214 tpg->src_width, tpg->src_height, in tpg_log_status()
2215 tpg_color_enc_str(tpg->color_enc)); in tpg_log_status()
2216 pr_info("tpg field: %u\n", tpg->field); in tpg_log_status()
2217 pr_info("tpg crop: %ux%u@%dx%d\n", tpg->crop.width, tpg->crop.height, in tpg_log_status()
2218 tpg->crop.left, tpg->crop.top); in tpg_log_status()
2219 pr_info("tpg compose: %ux%u@%dx%d\n", tpg->compose.width, tpg->compose.height, in tpg_log_status()
2220 tpg->compose.left, tpg->compose.top); in tpg_log_status()
2221 pr_info("tpg colorspace: %d\n", tpg->colorspace); in tpg_log_status()
2222 pr_info("tpg transfer function: %d/%d\n", tpg->xfer_func, tpg->real_xfer_func); in tpg_log_status()
2223 if (tpg->color_enc == TGP_COLOR_ENC_HSV) in tpg_log_status()
2225 tpg->hsv_enc, tpg->real_hsv_enc); in tpg_log_status()
2226 else if (tpg->color_enc == TGP_COLOR_ENC_YCBCR) in tpg_log_status()
2227 pr_info("tpg Y'CbCr encoding: %d/%d\n", in tpg_log_status()
2228 tpg->ycbcr_enc, tpg->real_ycbcr_enc); in tpg_log_status()
2229 pr_info("tpg quantization: %d/%d\n", tpg->quantization, tpg->real_quantization); in tpg_log_status()
2230 pr_info("tpg RGB range: %d/%d\n", tpg->rgb_range, tpg->real_rgb_range); in tpg_log_status()
2266 params->mv_hor_old = in tpg_fill_params_pattern()
2267 tpg_hscale_div(tpg, p, tpg->mv_hor_count % tpg->src_width); in tpg_fill_params_pattern()
2268 params->mv_hor_new = in tpg_fill_params_pattern()
2269 tpg_hscale_div(tpg, p, (tpg->mv_hor_count + tpg->mv_hor_step) % in tpg_fill_params_pattern()
2270 tpg->src_width); in tpg_fill_params_pattern()
2271 params->mv_vert_old = tpg->mv_vert_count % tpg->src_height; in tpg_fill_params_pattern()
2272 params->mv_vert_new = in tpg_fill_params_pattern()
2273 (tpg->mv_vert_count + tpg->mv_vert_step) % tpg->src_height; in tpg_fill_params_pattern()
2281 unsigned right_pillar_start = params->img_width; in tpg_fill_params_extras()
2283 params->wss_width = tpg->crop.left < tpg->src_width / 2 ? in tpg_fill_params_extras()
2284 tpg->src_width / 2 - tpg->crop.left : 0; in tpg_fill_params_extras()
2285 if (params->wss_width > tpg->crop.width) in tpg_fill_params_extras()
2286 params->wss_width = tpg->crop.width; in tpg_fill_params_extras()
2287 params->wss_width = tpg_hscale_div(tpg, p, params->wss_width); in tpg_fill_params_extras()
2288 params->wss_random_offset = in tpg_fill_params_extras()
2289 params->twopixsize * get_random_u32_below(tpg->src_width / 2); in tpg_fill_params_extras()
2291 if (tpg->crop.left < tpg->border.left) { in tpg_fill_params_extras()
2292 left_pillar_width = tpg->border.left - tpg->crop.left; in tpg_fill_params_extras()
2293 if (left_pillar_width > tpg->crop.width) in tpg_fill_params_extras()
2294 left_pillar_width = tpg->crop.width; in tpg_fill_params_extras()
2297 params->left_pillar_width = left_pillar_width; in tpg_fill_params_extras()
2299 if (tpg->crop.left + tpg->crop.width > in tpg_fill_params_extras()
2300 tpg->border.left + tpg->border.width) { in tpg_fill_params_extras()
2302 tpg->border.left + tpg->border.width - tpg->crop.left; in tpg_fill_params_extras()
2305 if (right_pillar_start > params->img_width) in tpg_fill_params_extras()
2306 right_pillar_start = params->img_width; in tpg_fill_params_extras()
2308 params->right_pillar_start = right_pillar_start; in tpg_fill_params_extras()
2310 params->sav_eav_f = tpg->field == in tpg_fill_params_extras()
2311 (params->is_60hz ? V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM); in tpg_fill_params_extras()
2318 unsigned twopixsize = params->twopixsize; in tpg_fill_plane_extras()
2319 unsigned img_width = params->img_width; in tpg_fill_plane_extras()
2320 unsigned frame_line = params->frame_line; in tpg_fill_plane_extras()
2321 const struct v4l2_rect *sq = &tpg->square; in tpg_fill_plane_extras()
2322 const struct v4l2_rect *b = &tpg->border; in tpg_fill_plane_extras()
2323 const struct v4l2_rect *c = &tpg->crop; in tpg_fill_plane_extras()
2325 if (params->is_tv && !params->is_60hz && in tpg_fill_plane_extras()
2326 frame_line == 0 && params->wss_width) { in tpg_fill_plane_extras()
2331 u8 *wss = tpg->random_line[p] + params->wss_random_offset; in tpg_fill_plane_extras()
2333 memcpy(vbuf, wss, params->wss_width); in tpg_fill_plane_extras()
2336 if (tpg->show_border && frame_line >= b->top && in tpg_fill_plane_extras()
2337 frame_line < b->top + b->height) { in tpg_fill_plane_extras()
2338 unsigned bottom = b->top + b->height - 1; in tpg_fill_plane_extras()
2339 unsigned left = params->left_pillar_width; in tpg_fill_plane_extras()
2340 unsigned right = params->right_pillar_start; in tpg_fill_plane_extras()
2342 if (frame_line == b->top || frame_line == b->top + 1 || in tpg_fill_plane_extras()
2343 frame_line == bottom || frame_line == bottom - 1) { in tpg_fill_plane_extras()
2344 memcpy(vbuf + left, tpg->contrast_line[p], in tpg_fill_plane_extras()
2345 right - left); in tpg_fill_plane_extras()
2347 if (b->left >= c->left && in tpg_fill_plane_extras()
2348 b->left < c->left + c->width) in tpg_fill_plane_extras()
2350 tpg->contrast_line[p], twopixsize); in tpg_fill_plane_extras()
2351 if (b->left + b->width > c->left && in tpg_fill_plane_extras()
2352 b->left + b->width <= c->left + c->width) in tpg_fill_plane_extras()
2353 memcpy(vbuf + right - twopixsize, in tpg_fill_plane_extras()
2354 tpg->contrast_line[p], twopixsize); in tpg_fill_plane_extras()
2357 if (tpg->qual != TPG_QUAL_NOISE && frame_line >= b->top && in tpg_fill_plane_extras()
2358 frame_line < b->top + b->height) { in tpg_fill_plane_extras()
2359 memcpy(vbuf, tpg->black_line[p], params->left_pillar_width); in tpg_fill_plane_extras()
2360 memcpy(vbuf + params->right_pillar_start, tpg->black_line[p], in tpg_fill_plane_extras()
2361 img_width - params->right_pillar_start); in tpg_fill_plane_extras()
2363 if (tpg->show_square && frame_line >= sq->top && in tpg_fill_plane_extras()
2364 frame_line < sq->top + sq->height && in tpg_fill_plane_extras()
2365 sq->left < c->left + c->width && in tpg_fill_plane_extras()
2366 sq->left + sq->width >= c->left) { in tpg_fill_plane_extras()
2367 unsigned left = sq->left; in tpg_fill_plane_extras()
2368 unsigned width = sq->width; in tpg_fill_plane_extras()
2370 if (c->left > left) { in tpg_fill_plane_extras()
2371 width -= c->left - left; in tpg_fill_plane_extras()
2372 left = c->left; in tpg_fill_plane_extras()
2374 if (c->left + c->width < left + width) in tpg_fill_plane_extras()
2375 width -= left + width - c->left - c->width; in tpg_fill_plane_extras()
2376 left -= c->left; in tpg_fill_plane_extras()
2379 memcpy(vbuf + left, tpg->contrast_line[p], width); in tpg_fill_plane_extras()
2381 if (tpg->insert_sav) { in tpg_fill_plane_extras()
2382 unsigned offset = tpg_hdiv(tpg, p, tpg->compose.width / 3); in tpg_fill_plane_extras() local
2383 u8 *p = vbuf + offset; in tpg_fill_plane_extras()
2389 p[3] = 0x80 | (params->sav_eav_f << 6) | in tpg_fill_plane_extras()
2392 ((hact ^ params->sav_eav_f) << 2) | in tpg_fill_plane_extras()
2393 ((params->sav_eav_f ^ vact) << 1) | in tpg_fill_plane_extras()
2394 (hact ^ vact ^ params->sav_eav_f); in tpg_fill_plane_extras()
2396 if (tpg->insert_eav) { in tpg_fill_plane_extras()
2397 unsigned offset = tpg_hdiv(tpg, p, tpg->compose.width * 2 / 3); in tpg_fill_plane_extras() local
2398 u8 *p = vbuf + offset; in tpg_fill_plane_extras()
2404 p[3] = 0x80 | (params->sav_eav_f << 6) | in tpg_fill_plane_extras()
2407 ((hact ^ params->sav_eav_f) << 2) | in tpg_fill_plane_extras()
2408 ((params->sav_eav_f ^ vact) << 1) | in tpg_fill_plane_extras()
2409 (hact ^ vact ^ params->sav_eav_f); in tpg_fill_plane_extras()
2411 if (tpg->insert_hdmi_video_guard_band) { in tpg_fill_plane_extras()
2414 switch (tpg->fourcc) { in tpg_fill_plane_extras()
2455 unsigned twopixsize = params->twopixsize; in tpg_fill_plane_pattern()
2456 unsigned img_width = params->img_width; in tpg_fill_plane_pattern()
2457 unsigned mv_hor_old = params->mv_hor_old; in tpg_fill_plane_pattern()
2458 unsigned mv_hor_new = params->mv_hor_new; in tpg_fill_plane_pattern()
2459 unsigned mv_vert_old = params->mv_vert_old; in tpg_fill_plane_pattern()
2460 unsigned mv_vert_new = params->mv_vert_new; in tpg_fill_plane_pattern()
2461 unsigned frame_line = params->frame_line; in tpg_fill_plane_pattern()
2462 unsigned frame_line_next = params->frame_line_next; in tpg_fill_plane_pattern()
2463 unsigned line_offset = tpg_hscale_div(tpg, p, tpg->crop.left); in tpg_fill_plane_pattern()
2475 if (h >= params->hmax) { in tpg_fill_plane_pattern()
2476 if (params->hmax == tpg->compose.height) in tpg_fill_plane_pattern()
2478 if (!tpg->perc_fill_blank) in tpg_fill_plane_pattern()
2483 if (tpg->vflip) { in tpg_fill_plane_pattern()
2484 frame_line = tpg->src_height - frame_line - 1; in tpg_fill_plane_pattern()
2485 frame_line_next = tpg->src_height - frame_line_next - 1; in tpg_fill_plane_pattern()
2489 linestart_older = tpg->contrast_line[p]; in tpg_fill_plane_pattern()
2490 linestart_newer = tpg->contrast_line[p]; in tpg_fill_plane_pattern()
2491 } else if (tpg->qual != TPG_QUAL_NOISE && in tpg_fill_plane_pattern()
2492 (frame_line < tpg->border.top || in tpg_fill_plane_pattern()
2493 frame_line >= tpg->border.top + tpg->border.height)) { in tpg_fill_plane_pattern()
2494 linestart_older = tpg->black_line[p]; in tpg_fill_plane_pattern()
2495 linestart_newer = tpg->black_line[p]; in tpg_fill_plane_pattern()
2496 } else if (tpg->pattern == TPG_PAT_NOISE || tpg->qual == TPG_QUAL_NOISE) { in tpg_fill_plane_pattern()
2497 linestart_older = tpg->random_line[p] + in tpg_fill_plane_pattern()
2498 twopixsize * get_random_u32_below(tpg->src_width / 2); in tpg_fill_plane_pattern()
2499 linestart_newer = tpg->random_line[p] + in tpg_fill_plane_pattern()
2500 twopixsize * get_random_u32_below(tpg->src_width / 2); in tpg_fill_plane_pattern()
2503 (frame_line + mv_vert_old) % tpg->src_height; in tpg_fill_plane_pattern()
2505 (frame_line + mv_vert_new) % tpg->src_height; in tpg_fill_plane_pattern()
2511 linestart_older = tpg->lines[pat_line_old][p] + mv_hor_old; in tpg_fill_plane_pattern()
2512 linestart_newer = tpg->lines[pat_line_new][p] + mv_hor_new; in tpg_fill_plane_pattern()
2514 if (tpg->vdownsampling[p] > 1 && frame_line != frame_line_next) { in tpg_fill_plane_pattern()
2522 (frame_line_next + mv_vert_old) % tpg->src_height); in tpg_fill_plane_pattern()
2524 (frame_line_next + mv_vert_new) % tpg->src_height); in tpg_fill_plane_pattern()
2526 switch (tpg->field) { in tpg_fill_plane_pattern()
2533 linestart_older = tpg->downsampled_lines[avg_pat][p] + mv_hor_old; in tpg_fill_plane_pattern()
2543 linestart_older = tpg->downsampled_lines[avg_pat][p] + in tpg_fill_plane_pattern()
2547 linestart_newer = tpg->downsampled_lines[avg_pat][p] + in tpg_fill_plane_pattern()
2555 if (tpg->field_alternate) { in tpg_fill_plane_pattern()
2557 } else if (params->is_60hz) { in tpg_fill_plane_pattern()
2565 switch (tpg->field) { in tpg_fill_plane_pattern()
2598 unsigned factor = V4L2_FIELD_HAS_T_OR_B(tpg->field) ? 2 : 1; in tpg_fill_plane_buffer()
2601 unsigned int_part = (tpg->crop.height / factor) / tpg->compose.height; in tpg_fill_plane_buffer()
2602 unsigned fract_part = (tpg->crop.height / factor) % tpg->compose.height; in tpg_fill_plane_buffer()
2611 params.twopixsize = tpg->twopixelsize[p]; in tpg_fill_plane_buffer()
2612 params.img_width = tpg_hdiv(tpg, p, tpg->compose.width); in tpg_fill_plane_buffer()
2613 params.stride = tpg->bytesperline[p]; in tpg_fill_plane_buffer()
2614 params.hmax = (tpg->compose.height * tpg->perc_fill) / 100; in tpg_fill_plane_buffer()
2619 vbuf += tpg_hdiv(tpg, p, tpg->compose.left); in tpg_fill_plane_buffer()
2621 for (h = 0; h < tpg->compose.height; h++) { in tpg_fill_plane_buffer()
2624 params.frame_line = tpg_calc_frameline(tpg, src_y, tpg->field); in tpg_fill_plane_buffer()
2626 buf_line = tpg_calc_buffer_line(tpg, h, tpg->field); in tpg_fill_plane_buffer()
2629 if (error >= tpg->compose.height) { in tpg_fill_plane_buffer()
2630 error -= tpg->compose.height; in tpg_fill_plane_buffer()
2635 * For line-interleaved formats determine the 'plane' in tpg_fill_plane_buffer()
2641 if (tpg->vdownsampling[p] > 1) { in tpg_fill_plane_buffer()
2650 if (tpg->field == V4L2_FIELD_SEQ_BT || in tpg_fill_plane_buffer()
2651 tpg->field == V4L2_FIELD_SEQ_TB) { in tpg_fill_plane_buffer()
2657 if (error + fract_part >= tpg->compose.height) in tpg_fill_plane_buffer()
2660 tpg_calc_frameline(tpg, next_src_y, tpg->field); in tpg_fill_plane_buffer()
2665 tpg_calc_frameline(tpg, src_y, tpg->field); in tpg_fill_plane_buffer()
2668 buf_line /= tpg->vdownsampling[p]; in tpg_fill_plane_buffer()
2680 unsigned offset = 0; in tpg_fillbuffer() local
2683 if (tpg->buffers > 1) { in tpg_fillbuffer()
2689 tpg_fill_plane_buffer(tpg, std, i, vbuf + offset); in tpg_fillbuffer()
2690 offset += tpg_calc_plane_size(tpg, i); in tpg_fillbuffer()