Lines Matching +full:offset +full:- +full:y

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()
118 tpg->max_line_width = max_w; in tpg_alloc()
123 tpg->lines[pat][plane] = in tpg_alloc()
125 if (!tpg->lines[pat][plane]) { in tpg_alloc()
126 ret = -ENOMEM; in tpg_alloc()
131 tpg->downsampled_lines[pat][plane] = in tpg_alloc()
133 if (!tpg->downsampled_lines[pat][plane]) { in tpg_alloc()
134 ret = -ENOMEM; in tpg_alloc()
142 tpg->contrast_line[plane] = in tpg_alloc()
144 if (!tpg->contrast_line[plane]) { in tpg_alloc()
145 ret = -ENOMEM; in tpg_alloc()
148 tpg->black_line[plane] = in tpg_alloc()
150 if (!tpg->black_line[plane]) { in tpg_alloc()
151 ret = -ENOMEM; in tpg_alloc()
154 tpg->random_line[plane] = in tpg_alloc()
156 if (!tpg->random_line[plane]) { in tpg_alloc()
157 ret = -ENOMEM; in tpg_alloc()
165 vfree(tpg->contrast_line[plane]); in tpg_alloc()
166 vfree(tpg->black_line[plane]); in tpg_alloc()
167 vfree(tpg->random_line[plane]); in tpg_alloc()
168 tpg->contrast_line[plane] = NULL; in tpg_alloc()
169 tpg->black_line[plane] = NULL; in tpg_alloc()
170 tpg->random_line[plane] = NULL; in tpg_alloc()
175 vfree(tpg->lines[pat][plane]); in tpg_alloc()
176 tpg->lines[pat][plane] = NULL; in tpg_alloc()
179 vfree(tpg->downsampled_lines[pat][plane]); in tpg_alloc()
180 tpg->downsampled_lines[pat][plane] = NULL; in tpg_alloc()
193 vfree(tpg->lines[pat][plane]); in tpg_free()
194 tpg->lines[pat][plane] = NULL; in tpg_free()
197 vfree(tpg->downsampled_lines[pat][plane]); in tpg_free()
198 tpg->downsampled_lines[pat][plane] = NULL; in tpg_free()
201 vfree(tpg->contrast_line[plane]); in tpg_free()
202 vfree(tpg->black_line[plane]); in tpg_free()
203 vfree(tpg->random_line[plane]); in tpg_free()
204 tpg->contrast_line[plane] = NULL; in tpg_free()
205 tpg->black_line[plane] = NULL; in tpg_free()
206 tpg->random_line[plane] = NULL; in tpg_free()
213 tpg->fourcc = fourcc; in tpg_s_fourcc()
214 tpg->planes = 1; in tpg_s_fourcc()
215 tpg->buffers = 1; in tpg_s_fourcc()
216 tpg->recalc_colors = true; in tpg_s_fourcc()
217 tpg->interleaved = false; in tpg_s_fourcc()
218 tpg->vdownsampling[0] = 1; in tpg_s_fourcc()
219 tpg->hdownsampling[0] = 1; in tpg_s_fourcc()
220 tpg->hmask[0] = ~0; in tpg_s_fourcc()
221 tpg->hmask[1] = ~0; in tpg_s_fourcc()
222 tpg->hmask[2] = ~0; in tpg_s_fourcc()
241 tpg->interleaved = true; in tpg_s_fourcc()
242 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
243 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
244 tpg->planes = 2; in tpg_s_fourcc()
283 tpg->color_enc = TGP_COLOR_ENC_RGB; in tpg_s_fourcc()
291 tpg->color_enc = TGP_COLOR_ENC_LUMA; in tpg_s_fourcc()
303 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
307 tpg->buffers = 3; in tpg_s_fourcc()
311 tpg->vdownsampling[1] = 2; in tpg_s_fourcc()
312 tpg->vdownsampling[2] = 2; in tpg_s_fourcc()
313 tpg->hdownsampling[1] = 2; in tpg_s_fourcc()
314 tpg->hdownsampling[2] = 2; in tpg_s_fourcc()
315 tpg->planes = 3; in tpg_s_fourcc()
316 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
320 tpg->buffers = 3; in tpg_s_fourcc()
323 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
324 tpg->vdownsampling[2] = 1; in tpg_s_fourcc()
325 tpg->hdownsampling[1] = 2; in tpg_s_fourcc()
326 tpg->hdownsampling[2] = 2; in tpg_s_fourcc()
327 tpg->planes = 3; in tpg_s_fourcc()
328 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
332 tpg->buffers = 2; in tpg_s_fourcc()
336 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
337 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
338 tpg->hmask[1] = ~1; in tpg_s_fourcc()
339 tpg->planes = 2; in tpg_s_fourcc()
340 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
344 tpg->buffers = 2; in tpg_s_fourcc()
348 tpg->vdownsampling[1] = 2; in tpg_s_fourcc()
349 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
350 tpg->hmask[1] = ~1; in tpg_s_fourcc()
351 tpg->planes = 2; in tpg_s_fourcc()
352 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
356 tpg->buffers = 3; in tpg_s_fourcc()
357 tpg->planes = 3; in tpg_s_fourcc()
358 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
359 tpg->vdownsampling[2] = 1; in tpg_s_fourcc()
360 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
361 tpg->hdownsampling[2] = 1; in tpg_s_fourcc()
362 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
366 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
367 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
368 tpg->planes = 2; in tpg_s_fourcc()
369 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
375 tpg->hmask[0] = ~1; in tpg_s_fourcc()
376 tpg->color_enc = TGP_COLOR_ENC_YCBCR; in tpg_s_fourcc()
380 tpg->color_enc = TGP_COLOR_ENC_HSV; in tpg_s_fourcc()
389 tpg->twopixelsize[0] = 2; in tpg_s_fourcc()
426 tpg->twopixelsize[0] = 2 * 2; in tpg_s_fourcc()
431 tpg->twopixelsize[0] = 2 * 3; in tpg_s_fourcc()
452 tpg->twopixelsize[0] = 2 * 4; in tpg_s_fourcc()
466 tpg->twopixelsize[0] = 2; in tpg_s_fourcc()
467 tpg->twopixelsize[1] = 2; in tpg_s_fourcc()
481 tpg->twopixelsize[0] = 4; in tpg_s_fourcc()
482 tpg->twopixelsize[1] = 4; in tpg_s_fourcc()
493 tpg->twopixelsize[0] = 2; in tpg_s_fourcc()
494 tpg->twopixelsize[1] = 2; in tpg_s_fourcc()
495 tpg->twopixelsize[2] = 2; in tpg_s_fourcc()
499 tpg->twopixelsize[0] = 2; in tpg_s_fourcc()
500 tpg->twopixelsize[1] = 4; in tpg_s_fourcc()
510 tpg->crop = *crop; in tpg_s_crop_compose()
511 tpg->compose = *compose; in tpg_s_crop_compose()
512 tpg->scaled_width = (tpg->src_width * tpg->compose.width + in tpg_s_crop_compose()
513 tpg->crop.width - 1) / tpg->crop.width; in tpg_s_crop_compose()
514 tpg->scaled_width &= ~1; in tpg_s_crop_compose()
515 if (tpg->scaled_width > tpg->max_line_width) in tpg_s_crop_compose()
516 tpg->scaled_width = tpg->max_line_width; in tpg_s_crop_compose()
517 if (tpg->scaled_width < 2) in tpg_s_crop_compose()
518 tpg->scaled_width = 2; in tpg_s_crop_compose()
519 tpg->recalc_lines = true; in tpg_s_crop_compose()
528 tpg->src_width = width; in tpg_reset_source()
529 tpg->src_height = height; in tpg_reset_source()
530 tpg->field = field; in tpg_reset_source()
531 tpg->buf_height = height; in tpg_reset_source()
533 tpg->buf_height /= 2; in tpg_reset_source()
534 tpg->scaled_width = width; in tpg_reset_source()
535 tpg->crop.top = tpg->crop.left = 0; in tpg_reset_source()
536 tpg->crop.width = width; in tpg_reset_source()
537 tpg->crop.height = height; in tpg_reset_source()
538 tpg->compose.top = tpg->compose.left = 0; in tpg_reset_source()
539 tpg->compose.width = width; in tpg_reset_source()
540 tpg->compose.height = tpg->buf_height; in tpg_reset_source()
541 for (p = 0; p < tpg->planes; p++) in tpg_reset_source()
542 tpg->bytesperline[p] = (width * tpg->twopixelsize[p]) / in tpg_reset_source()
543 (2 * tpg->hdownsampling[p]); in tpg_reset_source()
544 tpg->recalc_square_border = true; in tpg_reset_source()
550 switch (tpg->pattern) { in tpg_get_textbg_color()
562 switch (tpg->pattern) { in tpg_get_textfg_color()
608 diff_rgb = max_rgb - min_rgb; in color_to_hsv()
618 third_size = (tpg->real_hsv_enc == V4L2_HSV_ENC_180) ? 60 : 85; in color_to_hsv()
622 aux = g - b; in color_to_hsv()
625 aux = b - r; in color_to_hsv()
628 aux = r - g; in color_to_hsv()
638 if (tpg->real_hsv_enc == V4L2_HSV_ENC_180) { in color_to_hsv()
642 aux -= 180; in color_to_hsv()
651 int y_offset, int *y, int *cb, int *cr) in rgb2ycbcr() argument
653 *y = ((m[0][0] * r + m[0][1] * g + m[0][2] * b) >> 16) + (y_offset << 4); in rgb2ycbcr()
659 int *y, int *cb, int *cr) in color_to_ycbcr() argument
665 { COEFF(-0.1687, 224), COEFF(-0.3313, 224), COEFF(0.5, 224) }, in color_to_ycbcr()
666 { COEFF(0.5, 224), COEFF(-0.4187, 224), COEFF(-0.0813, 224) }, in color_to_ycbcr()
670 { COEFF(-0.1687, 255), COEFF(-0.3313, 255), COEFF(0.5, 255) }, in color_to_ycbcr()
671 { COEFF(0.5, 255), COEFF(-0.4187, 255), COEFF(-0.0813, 255) }, in color_to_ycbcr()
675 { COEFF(-0.1146, 224), COEFF(-0.3854, 224), COEFF(0.5, 224) }, in color_to_ycbcr()
676 { COEFF(0.5, 224), COEFF(-0.4542, 224), COEFF(-0.0458, 224) }, in color_to_ycbcr()
680 { COEFF(-0.1146, 255), COEFF(-0.3854, 255), COEFF(0.5, 255) }, in color_to_ycbcr()
681 { COEFF(0.5, 255), COEFF(-0.4542, 255), COEFF(-0.0458, 255) }, in color_to_ycbcr()
685 { COEFF(-0.116, 224), COEFF(-0.384, 224), COEFF(0.5, 224) }, in color_to_ycbcr()
686 { COEFF(0.5, 224), COEFF(-0.445, 224), COEFF(-0.055, 224) }, in color_to_ycbcr()
690 { COEFF(-0.116, 255), COEFF(-0.384, 255), COEFF(0.5, 255) }, in color_to_ycbcr()
691 { COEFF(0.5, 255), COEFF(-0.445, 255), COEFF(-0.055, 255) }, in color_to_ycbcr()
695 { COEFF(-0.1396, 224), COEFF(-0.3604, 224), COEFF(0.5, 224) }, in color_to_ycbcr()
696 { COEFF(0.5, 224), COEFF(-0.4598, 224), COEFF(-0.0402, 224) }, in color_to_ycbcr()
700 { COEFF(-0.1396, 255), COEFF(-0.3604, 255), COEFF(0.5, 255) }, in color_to_ycbcr()
701 { COEFF(0.5, 255), COEFF(-0.4598, 255), COEFF(-0.0402, 255) }, in color_to_ycbcr()
712 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE; in color_to_ycbcr()
716 switch (tpg->real_ycbcr_enc) { in color_to_ycbcr()
718 rgb2ycbcr(full ? bt601_full : bt601, r, g, b, y_offset, y, cb, cr); in color_to_ycbcr()
722 * Y'CbCr encoding. */ in color_to_ycbcr()
723 rgb2ycbcr(bt601, r, g, b, 16, y, cb, cr); in color_to_ycbcr()
727 * Y'CbCr encoding. */ in color_to_ycbcr()
728 rgb2ycbcr(rec709, r, g, b, 16, y, cb, cr); in color_to_ycbcr()
731 rgb2ycbcr(full ? bt2020_full : bt2020, r, g, b, y_offset, y, cb, cr); in color_to_ycbcr()
738 *y = full ? yc : (yc * 219) / 255 + (16 << 4); in color_to_ycbcr()
740 *cb = (((b - yc) * (full ? bt2020c_full[0] : bt2020c[0])) >> 16) + (128 << 4); in color_to_ycbcr()
742 *cb = (((b - yc) * (full ? bt2020c_full[1] : bt2020c[1])) >> 16) + (128 << 4); in color_to_ycbcr()
744 *cr = (((r - yc) * (full ? bt2020c_full[2] : bt2020c[2])) >> 16) + (128 << 4); in color_to_ycbcr()
746 *cr = (((r - yc) * (full ? bt2020c_full[3] : bt2020c[3])) >> 16) + (128 << 4); in color_to_ycbcr()
749 rgb2ycbcr(full ? smpte240m_full : smpte240m, r, g, b, y_offset, y, cb, cr); in color_to_ycbcr()
753 rgb2ycbcr(full ? rec709_full : rec709, r, g, b, y_offset, y, cb, cr); in color_to_ycbcr()
758 static void ycbcr2rgb(const int m[3][3], int y, int cb, int cr, in ycbcr2rgb() argument
761 y -= y_offset << 4; in ycbcr2rgb()
762 cb -= 128 << 4; in ycbcr2rgb()
763 cr -= 128 << 4; in ycbcr2rgb()
764 *r = m[0][0] * y + m[0][1] * cb + m[0][2] * cr; in ycbcr2rgb()
765 *g = m[1][0] * y + m[1][1] * cb + m[1][2] * cr; in ycbcr2rgb()
766 *b = m[2][0] * y + m[2][1] * cb + m[2][2] * cr; in ycbcr2rgb()
772 static void ycbcr_to_color(struct tpg_data *tpg, int y, int cb, int cr, in ycbcr_to_color() argument
779 { COEFF(1, 219), COEFF(-0.3441, 224), COEFF(-0.7141, 224) }, in ycbcr_to_color()
784 { COEFF(1, 255), COEFF(-0.3441, 255), COEFF(-0.7141, 255) }, in ycbcr_to_color()
789 { COEFF(1, 219), COEFF(-0.1873, 224), COEFF(-0.4681, 224) }, in ycbcr_to_color()
794 { COEFF(1, 255), COEFF(-0.1873, 255), COEFF(-0.4681, 255) }, in ycbcr_to_color()
799 { COEFF(1, 219), COEFF(-0.2253, 224), COEFF(-0.4767, 224) }, in ycbcr_to_color()
804 { COEFF(1, 255), COEFF(-0.2253, 255), COEFF(-0.4767, 255) }, in ycbcr_to_color()
809 { COEFF(1, 219), COEFF(-0.1646, 224), COEFF(-0.5714, 224) }, in ycbcr_to_color()
814 { COEFF(1, 255), COEFF(-0.1646, 255), COEFF(-0.5714, 255) }, in ycbcr_to_color()
826 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE; in ycbcr_to_color()
831 switch (tpg->real_ycbcr_enc) { in ycbcr_to_color()
833 ycbcr2rgb(full ? bt601_full : bt601, y, cb, cr, y_offset, r, g, b); in ycbcr_to_color()
837 * Y'CbCr encoding. */ in ycbcr_to_color()
838 ycbcr2rgb(bt601, y, cb, cr, 16, r, g, b); in ycbcr_to_color()
842 * Y'CbCr encoding. */ in ycbcr_to_color()
843 ycbcr2rgb(rec709, y, cb, cr, 16, r, g, b); in ycbcr_to_color()
846 ycbcr2rgb(full ? bt2020_full : bt2020, y, cb, cr, y_offset, r, g, b); in ycbcr_to_color()
849 y -= full ? 0 : 16 << 4; in ycbcr_to_color()
850 cb -= 128 << 4; in ycbcr_to_color()
851 cr -= 128 << 4; in ycbcr_to_color()
854 *b = y_fac * y + (full ? bt2020c_full[0] : bt2020c[0]) * cb; in ycbcr_to_color()
856 *b = y_fac * y + (full ? bt2020c_full[1] : bt2020c[1]) * cb; in ycbcr_to_color()
859 *r = y_fac * y + (full ? bt2020c_full[2] : bt2020c[2]) * cr; in ycbcr_to_color()
861 *r = y_fac * y + (full ? bt2020c_full[3] : bt2020c[3]) * cr; in ycbcr_to_color()
865 lin_y = rec709_to_linear((y * 255) / (full ? 255 : 219)); in ycbcr_to_color()
867 lin_g = COEFF(1.0 / 0.6780, 255) * lin_y - in ycbcr_to_color()
868 COEFF(0.2627 / 0.6780, 255) * lin_r - in ycbcr_to_color()
873 ycbcr2rgb(full ? smpte240m_full : smpte240m, y, cb, cr, y_offset, r, g, b); in ycbcr_to_color()
877 ycbcr2rgb(full ? rec709_full : rec709, y, cb, cr, y_offset, r, g, b); in ycbcr_to_color()
889 int y, cb, cr; in precalculate_color() local
904 } else if (tpg->pattern == TPG_PAT_NOISE) { in precalculate_color()
907 r = g = b = tpg->qual_offset + get_random_u32_below(196); in precalculate_color()
909 r = g = b = k - TPG_COLOR_RAMP; in precalculate_color()
912 if (tpg->pattern == TPG_PAT_CSC_COLORBAR && col <= TPG_COLOR_CSC_BLACK) { in precalculate_color()
913 r = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].r; in precalculate_color()
914 g = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].g; in precalculate_color()
915 b = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].b; in precalculate_color()
922 if (tpg->qual == TPG_QUAL_GRAY || in precalculate_color()
923 tpg->color_enc == TGP_COLOR_ENC_LUMA) { in precalculate_color()
934 * Remember that r, g and b are still in the 0 - 0xff0 range. in precalculate_color()
936 if (tpg->real_rgb_range == V4L2_DV_RGB_RANGE_LIMITED && in precalculate_color()
937 tpg->rgb_range == V4L2_DV_RGB_RANGE_FULL && in precalculate_color()
938 tpg->color_enc == TGP_COLOR_ENC_RGB) { in precalculate_color()
947 } else if (tpg->real_rgb_range != V4L2_DV_RGB_RANGE_LIMITED && in precalculate_color()
948 tpg->rgb_range == V4L2_DV_RGB_RANGE_LIMITED && in precalculate_color()
949 tpg->color_enc == TGP_COLOR_ENC_RGB) { in precalculate_color()
958 r = (r - (16 << 4)) * 255 / 219; in precalculate_color()
959 g = (g - (16 << 4)) * 255 / 219; in precalculate_color()
960 b = (b - (16 << 4)) * 255 / 219; in precalculate_color()
963 if ((tpg->brightness != 128 || tpg->contrast != 128 || in precalculate_color()
964 tpg->saturation != 128 || tpg->hue) && in precalculate_color()
965 tpg->color_enc != TGP_COLOR_ENC_LUMA) { in precalculate_color()
971 color_to_ycbcr(tpg, r, g, b, &y, &cb, &cr); in precalculate_color()
973 y = (16 << 4) + ((y - (16 << 4)) * tpg->contrast) / 128; in precalculate_color()
974 y += (tpg->brightness << 4) - (128 << 4); in precalculate_color()
976 cb -= 128 << 4; in precalculate_color()
977 cr -= 128 << 4; in precalculate_color()
978 tmp_cb = (cb * cos(128 + tpg->hue)) / 127 + (cr * sin[128 + tpg->hue]) / 127; in precalculate_color()
979 tmp_cr = (cr * cos(128 + tpg->hue)) / 127 - (cb * sin[128 + tpg->hue]) / 127; in precalculate_color()
981 cb = (128 << 4) + (tmp_cb * tpg->contrast * tpg->saturation) / (128 * 128); in precalculate_color()
982 cr = (128 << 4) + (tmp_cr * tpg->contrast * tpg->saturation) / (128 * 128); in precalculate_color()
983 if (tpg->color_enc == TGP_COLOR_ENC_YCBCR) in precalculate_color()
986 ycbcr_to_color(tpg, y, cb, cr, &r, &g, &b); in precalculate_color()
987 } else if ((tpg->brightness != 128 || tpg->contrast != 128) && in precalculate_color()
988 tpg->color_enc == TGP_COLOR_ENC_LUMA) { in precalculate_color()
989 r = (16 << 4) + ((r - (16 << 4)) * tpg->contrast) / 128; in precalculate_color()
990 r += (tpg->brightness << 4) - (128 << 4); in precalculate_color()
993 switch (tpg->color_enc) { in precalculate_color()
999 tpg->colors[k][0] = h; in precalculate_color()
1000 tpg->colors[k][1] = s; in precalculate_color()
1001 tpg->colors[k][2] = v; in precalculate_color()
1008 color_to_ycbcr(tpg, r, g, b, &y, &cb, &cr); in precalculate_color()
1010 y >>= 4; in precalculate_color()
1015 * and B' values outside the range [0-1]. So do not clamp in precalculate_color()
1018 if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE && in precalculate_color()
1019 tpg->real_ycbcr_enc != V4L2_YCBCR_ENC_XV601 && in precalculate_color()
1020 tpg->real_ycbcr_enc != V4L2_YCBCR_ENC_XV709) { in precalculate_color()
1021 y = clamp(y, 16, 235); in precalculate_color()
1025 y = clamp(y, 1, 254); in precalculate_color()
1029 switch (tpg->fourcc) { in precalculate_color()
1031 y >>= 4; in precalculate_color()
1036 y >>= 3; in precalculate_color()
1041 y >>= 3; in precalculate_color()
1046 tpg->colors[k][0] = y; in precalculate_color()
1047 tpg->colors[k][1] = cb; in precalculate_color()
1048 tpg->colors[k][2] = cr; in precalculate_color()
1053 tpg->colors[k][0] = r >> 4; in precalculate_color()
1058 if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) { in precalculate_color()
1063 switch (tpg->fourcc) { in precalculate_color()
1116 tpg->colors[k][0] = r; in precalculate_color()
1117 tpg->colors[k][1] = g; in precalculate_color()
1118 tpg->colors[k][2] = b; in precalculate_color()
1136 unsigned offset = odd * tpg->twopixelsize[0] / 2; in gen_twopix() local
1137 u8 alpha = tpg->alpha_component; in gen_twopix()
1140 if (tpg->alpha_red_only && color != TPG_COLOR_CSC_RED && in gen_twopix()
1146 r_y_h = tpg->colors[color][0]; /* R or precalculated Y, H */ in gen_twopix()
1147 g_u_s = tpg->colors[color][1]; /* G or precalculated U, V */ in gen_twopix()
1148 b_v = tpg->colors[color][2]; /* B or precalculated V */ in gen_twopix()
1150 switch (tpg->fourcc) { in gen_twopix()
1152 buf[0][offset] = r_y_h; in gen_twopix()
1155 buf[0][offset] = (r_y_h << 2) & 0xff; in gen_twopix()
1156 buf[0][offset+1] = r_y_h >> 6; in gen_twopix()
1159 buf[0][offset] = (r_y_h << 4) & 0xff; in gen_twopix()
1160 buf[0][offset+1] = r_y_h >> 4; in gen_twopix()
1170 buf[0][offset] = r_y_h == 0xff ? r_y_h : 0; in gen_twopix()
1171 buf[0][offset+1] = r_y_h; in gen_twopix()
1175 buf[0][offset] = r_y_h; in gen_twopix()
1176 buf[0][offset+1] = r_y_h == 0xff ? r_y_h : 0; in gen_twopix()
1182 buf[0][offset] = r_y_h; in gen_twopix()
1196 buf[0][offset] = r_y_h; in gen_twopix()
1212 buf[0][offset] = r_y_h; in gen_twopix()
1225 buf[0][offset] = r_y_h; in gen_twopix()
1236 buf[0][offset] = r_y_h; in gen_twopix()
1237 buf[1][offset] = g_u_s; in gen_twopix()
1238 buf[2][offset] = b_v; in gen_twopix()
1242 buf[0][offset] = r_y_h; in gen_twopix()
1243 buf[1][offset] = b_v; in gen_twopix()
1244 buf[2][offset] = g_u_s; in gen_twopix()
1248 buf[0][offset] = r_y_h; in gen_twopix()
1249 buf[1][2 * offset] = g_u_s; in gen_twopix()
1250 buf[1][(2 * offset + 1) % 8] = b_v; in gen_twopix()
1254 buf[0][offset] = r_y_h; in gen_twopix()
1255 buf[1][2 * offset] = b_v; in gen_twopix()
1256 buf[1][(2 * offset + 1) % 8] = g_u_s; in gen_twopix()
1260 buf[0][offset] = r_y_h; in gen_twopix()
1270 buf[0][offset + 1] = r_y_h; in gen_twopix()
1280 buf[0][offset] = r_y_h; in gen_twopix()
1290 buf[0][offset + 1] = r_y_h; in gen_twopix()
1300 buf[0][offset] = (r_y_h << 5) | (g_u_s << 2) | b_v; in gen_twopix()
1304 buf[0][offset] = (g_u_s << 5) | b_v; in gen_twopix()
1305 buf[0][offset + 1] = (r_y_h << 3) | (g_u_s >> 3); in gen_twopix()
1308 buf[0][offset] = (r_y_h << 3) | (g_u_s >> 3); in gen_twopix()
1309 buf[0][offset + 1] = (g_u_s << 5) | b_v; in gen_twopix()
1317 buf[0][offset] = (g_u_s << 4) | b_v; in gen_twopix()
1318 buf[0][offset + 1] = (alpha & 0xf0) | r_y_h; in gen_twopix()
1324 buf[0][offset] = (b_v << 4) | (alpha >> 4); in gen_twopix()
1325 buf[0][offset + 1] = (r_y_h << 4) | g_u_s; in gen_twopix()
1331 buf[0][offset] = (g_u_s << 4) | r_y_h; in gen_twopix()
1332 buf[0][offset + 1] = (alpha & 0xf0) | b_v; in gen_twopix()
1338 buf[0][offset] = (r_y_h << 4) | (alpha >> 4); in gen_twopix()
1339 buf[0][offset + 1] = (b_v << 4) | g_u_s; in gen_twopix()
1347 buf[0][offset] = (g_u_s << 5) | b_v; in gen_twopix()
1348 buf[0][offset + 1] = (alpha & 0x80) | (r_y_h << 2) in gen_twopix()
1355 buf[0][offset] = (g_u_s << 6) | (b_v << 1) | in gen_twopix()
1357 buf[0][offset + 1] = (r_y_h << 3) | (g_u_s >> 2); in gen_twopix()
1363 buf[0][offset] = (g_u_s << 5) | r_y_h; in gen_twopix()
1364 buf[0][offset + 1] = (alpha & 0x80) | (b_v << 2) in gen_twopix()
1371 buf[0][offset] = (g_u_s << 6) | (r_y_h << 1) | in gen_twopix()
1373 buf[0][offset + 1] = (b_v << 3) | (g_u_s >> 2); in gen_twopix()
1380 buf[0][offset] = (alpha & 0x80) | (r_y_h << 2) | (g_u_s >> 3); in gen_twopix()
1381 buf[0][offset + 1] = (g_u_s << 5) | b_v; in gen_twopix()
1385 buf[0][offset] = r_y_h; in gen_twopix()
1386 buf[0][offset + 1] = g_u_s; in gen_twopix()
1387 buf[0][offset + 2] = b_v; in gen_twopix()
1390 buf[0][offset] = b_v; in gen_twopix()
1391 buf[0][offset + 1] = g_u_s; in gen_twopix()
1392 buf[0][offset + 2] = r_y_h; in gen_twopix()
1395 buf[0][offset] = (b_v << 2) | (g_u_s >> 4); in gen_twopix()
1396 buf[0][offset + 1] = (g_u_s << 4) | (r_y_h >> 2); in gen_twopix()
1397 buf[0][offset + 2] = r_y_h << 6; in gen_twopix()
1398 buf[0][offset + 3] = 0; in gen_twopix()
1409 buf[0][offset] = alpha; in gen_twopix()
1410 buf[0][offset + 1] = r_y_h; in gen_twopix()
1411 buf[0][offset + 2] = g_u_s; in gen_twopix()
1412 buf[0][offset + 3] = b_v; in gen_twopix()
1420 buf[0][offset] = r_y_h; in gen_twopix()
1421 buf[0][offset + 1] = g_u_s; in gen_twopix()
1422 buf[0][offset + 2] = b_v; in gen_twopix()
1423 buf[0][offset + 3] = alpha; in gen_twopix()
1432 buf[0][offset] = b_v; in gen_twopix()
1433 buf[0][offset + 1] = g_u_s; in gen_twopix()
1434 buf[0][offset + 2] = r_y_h; in gen_twopix()
1435 buf[0][offset + 3] = alpha; in gen_twopix()
1441 buf[0][offset] = alpha; in gen_twopix()
1442 buf[0][offset + 1] = b_v; in gen_twopix()
1443 buf[0][offset + 2] = g_u_s; in gen_twopix()
1444 buf[0][offset + 3] = r_y_h; in gen_twopix()
1447 buf[0][offset] = odd ? g_u_s : b_v; in gen_twopix()
1448 buf[1][offset] = odd ? r_y_h : g_u_s; in gen_twopix()
1451 buf[0][offset] = odd ? b_v : g_u_s; in gen_twopix()
1452 buf[1][offset] = odd ? g_u_s : r_y_h; in gen_twopix()
1455 buf[0][offset] = odd ? r_y_h : g_u_s; in gen_twopix()
1456 buf[1][offset] = odd ? g_u_s : b_v; in gen_twopix()
1459 buf[0][offset] = odd ? g_u_s : r_y_h; in gen_twopix()
1460 buf[1][offset] = odd ? b_v : g_u_s; in gen_twopix()
1463 buf[0][offset] = odd ? g_u_s << 2 : b_v << 2; in gen_twopix()
1464 buf[0][offset + 1] = odd ? g_u_s >> 6 : b_v >> 6; in gen_twopix()
1465 buf[1][offset] = odd ? r_y_h << 2 : g_u_s << 2; in gen_twopix()
1466 buf[1][offset + 1] = odd ? r_y_h >> 6 : g_u_s >> 6; in gen_twopix()
1467 buf[0][offset] |= (buf[0][offset] >> 2) & 3; in gen_twopix()
1468 buf[1][offset] |= (buf[1][offset] >> 2) & 3; in gen_twopix()
1471 buf[0][offset] = odd ? b_v << 2 : g_u_s << 2; in gen_twopix()
1472 buf[0][offset + 1] = odd ? b_v >> 6 : g_u_s >> 6; in gen_twopix()
1473 buf[1][offset] = odd ? g_u_s << 2 : r_y_h << 2; in gen_twopix()
1474 buf[1][offset + 1] = odd ? g_u_s >> 6 : r_y_h >> 6; in gen_twopix()
1475 buf[0][offset] |= (buf[0][offset] >> 2) & 3; in gen_twopix()
1476 buf[1][offset] |= (buf[1][offset] >> 2) & 3; in gen_twopix()
1479 buf[0][offset] = odd ? r_y_h << 2 : g_u_s << 2; in gen_twopix()
1480 buf[0][offset + 1] = odd ? r_y_h >> 6 : g_u_s >> 6; in gen_twopix()
1481 buf[1][offset] = odd ? g_u_s << 2 : b_v << 2; in gen_twopix()
1482 buf[1][offset + 1] = odd ? g_u_s >> 6 : b_v >> 6; in gen_twopix()
1483 buf[0][offset] |= (buf[0][offset] >> 2) & 3; in gen_twopix()
1484 buf[1][offset] |= (buf[1][offset] >> 2) & 3; in gen_twopix()
1487 buf[0][offset] = odd ? g_u_s << 2 : r_y_h << 2; in gen_twopix()
1488 buf[0][offset + 1] = odd ? g_u_s >> 6 : r_y_h >> 6; in gen_twopix()
1489 buf[1][offset] = odd ? b_v << 2 : g_u_s << 2; in gen_twopix()
1490 buf[1][offset + 1] = odd ? b_v >> 6 : g_u_s >> 6; in gen_twopix()
1491 buf[0][offset] |= (buf[0][offset] >> 2) & 3; in gen_twopix()
1492 buf[1][offset] |= (buf[1][offset] >> 2) & 3; in gen_twopix()
1495 buf[0][offset] = odd ? g_u_s << 4 : b_v << 4; in gen_twopix()
1496 buf[0][offset + 1] = odd ? g_u_s >> 4 : b_v >> 4; in gen_twopix()
1497 buf[1][offset] = odd ? r_y_h << 4 : g_u_s << 4; in gen_twopix()
1498 buf[1][offset + 1] = odd ? r_y_h >> 4 : g_u_s >> 4; in gen_twopix()
1499 buf[0][offset] |= (buf[0][offset] >> 4) & 0xf; in gen_twopix()
1500 buf[1][offset] |= (buf[1][offset] >> 4) & 0xf; in gen_twopix()
1503 buf[0][offset] = odd ? b_v << 4 : g_u_s << 4; in gen_twopix()
1504 buf[0][offset + 1] = odd ? b_v >> 4 : g_u_s >> 4; in gen_twopix()
1505 buf[1][offset] = odd ? g_u_s << 4 : r_y_h << 4; in gen_twopix()
1506 buf[1][offset + 1] = odd ? g_u_s >> 4 : r_y_h >> 4; in gen_twopix()
1507 buf[0][offset] |= (buf[0][offset] >> 4) & 0xf; in gen_twopix()
1508 buf[1][offset] |= (buf[1][offset] >> 4) & 0xf; in gen_twopix()
1511 buf[0][offset] = odd ? r_y_h << 4 : g_u_s << 4; in gen_twopix()
1512 buf[0][offset + 1] = odd ? r_y_h >> 4 : g_u_s >> 4; in gen_twopix()
1513 buf[1][offset] = odd ? g_u_s << 4 : b_v << 4; in gen_twopix()
1514 buf[1][offset + 1] = odd ? g_u_s >> 4 : b_v >> 4; in gen_twopix()
1515 buf[0][offset] |= (buf[0][offset] >> 4) & 0xf; in gen_twopix()
1516 buf[1][offset] |= (buf[1][offset] >> 4) & 0xf; in gen_twopix()
1519 buf[0][offset] = odd ? g_u_s << 4 : r_y_h << 4; in gen_twopix()
1520 buf[0][offset + 1] = odd ? g_u_s >> 4 : r_y_h >> 4; in gen_twopix()
1521 buf[1][offset] = odd ? b_v << 4 : g_u_s << 4; in gen_twopix()
1522 buf[1][offset + 1] = odd ? b_v >> 4 : g_u_s >> 4; in gen_twopix()
1523 buf[0][offset] |= (buf[0][offset] >> 4) & 0xf; in gen_twopix()
1524 buf[1][offset] |= (buf[1][offset] >> 4) & 0xf; in gen_twopix()
1527 buf[0][offset] = buf[0][offset + 1] = odd ? g_u_s : b_v; in gen_twopix()
1528 buf[1][offset] = buf[1][offset + 1] = odd ? r_y_h : g_u_s; in gen_twopix()
1531 buf[0][offset] = buf[0][offset + 1] = odd ? b_v : g_u_s; in gen_twopix()
1532 buf[1][offset] = buf[1][offset + 1] = odd ? g_u_s : r_y_h; in gen_twopix()
1535 buf[0][offset] = buf[0][offset + 1] = odd ? r_y_h : g_u_s; in gen_twopix()
1536 buf[1][offset] = buf[1][offset + 1] = odd ? g_u_s : b_v; in gen_twopix()
1539 buf[0][offset] = buf[0][offset + 1] = odd ? g_u_s : r_y_h; in gen_twopix()
1540 buf[1][offset] = buf[1][offset + 1] = odd ? b_v : g_u_s; in gen_twopix()
1547 switch (tpg->fourcc) { in tpg_g_interleaved_plane()
1574 switch (tpg->pattern) { in tpg_get_pat_lines()
1596 switch (tpg->pattern) { in tpg_get_pat_line()
1608 return (line * 8) / tpg->src_height; in tpg_get_pat_line()
1610 return line == tpg->src_height / 2; in tpg_get_pat_line()
1612 return (line + 1) / 2 == tpg->src_height / 4; in tpg_get_pat_line()
1614 return (line + 10) / 20 == tpg->src_height / 40; in tpg_get_pat_line()
1622 * Note: x is in the range 0 to 2 * tpg->src_width.
1627 /* Maximum number of bars are TPG_COLOR_MAX - otherwise, the input print code in tpg_get_color()
1630 /* Standard ITU-R 75% color bar sequence */ in tpg_get_color()
1635 /* Standard ITU-R 100% color bar sequence */ in tpg_get_color()
1647 switch (tpg->pattern) { in tpg_get_color()
1651 return bars[tpg->pattern][((x * 8) / tpg->src_width) % 8]; in tpg_get_color()
1653 return bars[1][(pat_line + (x * 8) / tpg->src_width) % 8]; in tpg_get_color()
1686 if (pat_line || (x % tpg->src_width) == tpg->src_width / 2) in tpg_get_color()
1690 if (pat_line || ((x % tpg->src_width) + 1) / 2 == tpg->src_width / 4) in tpg_get_color()
1694 if (pat_line || ((x % tpg->src_width) + 10) / 20 == tpg->src_width / 40) in tpg_get_color()
1698 return TPG_COLOR_RAMP + ((x % tpg->src_width) * 256) / tpg->src_width; in tpg_get_color()
1712 unsigned w = tpg->src_width; in tpg_calculate_square_border()
1713 unsigned h = tpg->src_height; in tpg_calculate_square_border()
1717 if (((w - sq_w) / 2) & 1) in tpg_calculate_square_border()
1720 tpg->square.width = sq_w; in tpg_calculate_square_border()
1721 if (tpg->vid_aspect == TPG_VIDEO_ASPECT_16X9_ANAMORPHIC) { in tpg_calculate_square_border()
1724 if (((w - ana_sq_w) / 2) & 1) in tpg_calculate_square_border()
1726 tpg->square.width = ana_sq_w; in tpg_calculate_square_border()
1728 tpg->square.left = (w - tpg->square.width) / 2; in tpg_calculate_square_border()
1729 if (tpg->pix_aspect == TPG_PIXEL_ASPECT_NTSC) in tpg_calculate_square_border()
1731 else if (tpg->pix_aspect == TPG_PIXEL_ASPECT_PAL) in tpg_calculate_square_border()
1733 tpg->square.height = sq_h; in tpg_calculate_square_border()
1734 tpg->square.top = (h - sq_h) / 2; in tpg_calculate_square_border()
1735 tpg->border.left = 0; in tpg_calculate_square_border()
1736 tpg->border.width = w; in tpg_calculate_square_border()
1737 tpg->border.top = 0; in tpg_calculate_square_border()
1738 tpg->border.height = h; in tpg_calculate_square_border()
1739 switch (tpg->vid_aspect) { in tpg_calculate_square_border()
1741 if (tpg->pix_aspect) in tpg_calculate_square_border()
1744 tpg->border.width = ((4 * h) / 3) & ~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 = ((3 * w) / 4) & ~1; in tpg_calculate_square_border()
1751 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1754 if (tpg->pix_aspect) { in tpg_calculate_square_border()
1755 tpg->border.height = tpg->pix_aspect == TPG_PIXEL_ASPECT_NTSC ? 420 : 506; in tpg_calculate_square_border()
1756 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1760 tpg->border.width = ((14 * h) / 9) & ~1; in tpg_calculate_square_border()
1761 if (((w - tpg->border.width) / 2) & ~1) in tpg_calculate_square_border()
1762 tpg->border.width -= 2; in tpg_calculate_square_border()
1763 tpg->border.left = (w - tpg->border.width) / 2; in tpg_calculate_square_border()
1766 tpg->border.height = ((9 * w) / 14) & ~1; in tpg_calculate_square_border()
1767 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1770 if (tpg->pix_aspect) { in tpg_calculate_square_border()
1771 tpg->border.height = tpg->pix_aspect == TPG_PIXEL_ASPECT_NTSC ? 368 : 442; in tpg_calculate_square_border()
1772 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1776 tpg->border.width = ((16 * h) / 9) & ~1; in tpg_calculate_square_border()
1777 if (((w - tpg->border.width) / 2) & ~1) in tpg_calculate_square_border()
1778 tpg->border.width -= 2; in tpg_calculate_square_border()
1779 tpg->border.left = (w - tpg->border.width) / 2; in tpg_calculate_square_border()
1782 tpg->border.height = ((9 * w) / 16) & ~1; in tpg_calculate_square_border()
1783 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1798 if (WARN_ON_ONCE(!tpg->src_width || !tpg->scaled_width)) in tpg_precalculate_line()
1801 switch (tpg->pattern) { in tpg_precalculate_line()
1815 unsigned int_part = tpg->src_width / tpg->scaled_width; in tpg_precalculate_line()
1816 unsigned fract_part = tpg->src_width % tpg->scaled_width; in tpg_precalculate_line()
1820 for (x = 0; x < tpg->scaled_width * 2; x += 2) { in tpg_precalculate_line()
1824 real_x = tpg->hflip ? tpg->src_width * 2 - real_x - 2 : real_x; in tpg_precalculate_line()
1829 if (error >= tpg->scaled_width) { in tpg_precalculate_line()
1830 error -= tpg->scaled_width; in tpg_precalculate_line()
1835 real_x = tpg->hflip ? tpg->src_width * 2 - real_x - 2 : real_x; in tpg_precalculate_line()
1840 if (error >= tpg->scaled_width) { in tpg_precalculate_line()
1841 error -= tpg->scaled_width; in tpg_precalculate_line()
1845 gen_twopix(tpg, pix, tpg->hflip ? color2 : color1, 0); in tpg_precalculate_line()
1846 gen_twopix(tpg, pix, tpg->hflip ? color1 : color2, 1); in tpg_precalculate_line()
1847 for (p = 0; p < tpg->planes; p++) { in tpg_precalculate_line()
1848 unsigned twopixsize = tpg->twopixelsize[p]; in tpg_precalculate_line()
1849 unsigned hdiv = tpg->hdownsampling[p]; in tpg_precalculate_line()
1850 u8 *pos = tpg->lines[pat][p] + tpg_hdiv(tpg, p, x); in tpg_precalculate_line()
1857 if (tpg->vdownsampling[tpg->planes - 1] > 1) { in tpg_precalculate_line()
1863 for (p = 1; p < tpg->planes; p++) { in tpg_precalculate_line()
1864 unsigned w = tpg_hdiv(tpg, p, tpg->scaled_width * 2); in tpg_precalculate_line()
1865 u8 *pos1 = tpg->lines[pat][p]; in tpg_precalculate_line()
1866 u8 *pos2 = tpg->lines[next_pat][p]; in tpg_precalculate_line()
1867 u8 *dest = tpg->downsampled_lines[pat][p]; in tpg_precalculate_line()
1877 for (p = 0; p < tpg->planes; p++) { in tpg_precalculate_line()
1878 unsigned twopixsize = tpg->twopixelsize[p]; in tpg_precalculate_line()
1879 u8 *pos = tpg->contrast_line[p]; in tpg_precalculate_line()
1881 for (x = 0; x < tpg->scaled_width; x += 2, pos += twopixsize) in tpg_precalculate_line()
1887 for (p = 0; p < tpg->planes; p++) { in tpg_precalculate_line()
1888 unsigned twopixsize = tpg->twopixelsize[p]; in tpg_precalculate_line()
1889 u8 *pos = tpg->black_line[p]; in tpg_precalculate_line()
1891 for (x = 0; x < tpg->scaled_width; x += 2, pos += twopixsize) in tpg_precalculate_line()
1895 for (x = 0; x < tpg->scaled_width * 2; x += 2) { in tpg_precalculate_line()
1898 for (p = 0; p < tpg->planes; p++) { in tpg_precalculate_line()
1899 unsigned twopixsize = tpg->twopixelsize[p]; in tpg_precalculate_line()
1900 u8 *pos = tpg->random_line[p] + x * twopixsize / 2; in tpg_precalculate_line()
1906 gen_twopix(tpg, tpg->textbg, TPG_COLOR_TEXTBG, 0); in tpg_precalculate_line()
1907 gen_twopix(tpg, tpg->textbg, TPG_COLOR_TEXTBG, 1); in tpg_precalculate_line()
1908 gen_twopix(tpg, tpg->textfg, TPG_COLOR_TEXTFG, 0); in tpg_precalculate_line()
1909 gen_twopix(tpg, tpg->textfg, TPG_COLOR_TEXTFG, 1); in tpg_precalculate_line()
1916 unsigned vdiv = tpg->vdownsampling[p]; \
1917 unsigned hdiv = tpg->hdownsampling[p]; \
1921 memcpy(&fg, tpg->textfg[p], sizeof(PIXTYPE)); \
1922 memcpy(&bg, tpg->textbg[p], sizeof(PIXTYPE)); \
1925 int l = tpg->vflip ? 15 - line : line; \
1927 ((y * step + l) / (vdiv * div)) * tpg->bytesperline[p] + \
1934 if (hdiv == 2 && tpg->hflip) { \
1944 } else if (tpg->hflip) { \
1964 pos += (tpg->hflip ? -8 : 8) / (int)hdiv; \
1971 int y, int x, const char *text, unsigned len) in tpg_print_str_2() argument
1978 int y, int x, const char *text, unsigned len) in tpg_print_str_4() argument
1985 int y, int x, const char *text, unsigned len) in tpg_print_str_6() argument
1992 int y, int x, const char *text, unsigned len) in tpg_print_str_8() argument
1998 int y, int x, const char *text) in tpg_gen_text() argument
2000 unsigned step = V4L2_FIELD_HAS_T_OR_B(tpg->field) ? 2 : 1; in tpg_gen_text()
2012 if (y + 16 >= tpg->compose.height || x + 8 >= tpg->compose.width) in tpg_gen_text()
2015 if (len > (tpg->compose.width - x) / 8) in tpg_gen_text()
2016 len = (tpg->compose.width - x) / 8; in tpg_gen_text()
2017 if (tpg->vflip) in tpg_gen_text()
2018 y = tpg->compose.height - y - 16; in tpg_gen_text()
2019 if (tpg->hflip) in tpg_gen_text()
2020 x = tpg->compose.width - x - 8; in tpg_gen_text()
2021 y += tpg->compose.top; in tpg_gen_text()
2022 x += tpg->compose.left; in tpg_gen_text()
2023 if (tpg->field == V4L2_FIELD_BOTTOM) in tpg_gen_text()
2025 else if (tpg->field == V4L2_FIELD_SEQ_TB || tpg->field == V4L2_FIELD_SEQ_BT) in tpg_gen_text()
2028 for (p = 0; p < tpg->planes; p++) { in tpg_gen_text()
2030 switch (tpg->twopixelsize[p]) { in tpg_gen_text()
2032 tpg_print_str_2(tpg, basep, p, first, div, step, y, x, in tpg_gen_text()
2036 tpg_print_str_4(tpg, basep, p, first, div, step, y, x, in tpg_gen_text()
2040 tpg_print_str_6(tpg, basep, p, first, div, step, y, x, in tpg_gen_text()
2044 tpg_print_str_8(tpg, basep, p, first, div, step, y, x, in tpg_gen_text()
2054 switch (tpg->pattern) { in tpg_g_color_order()
2078 int factor = tpg->mv_hor_mode > TPG_MOVE_NONE ? -1 : 1; in tpg_update_mv_step()
2080 if (tpg->hflip) in tpg_update_mv_step()
2081 factor = -factor; in tpg_update_mv_step()
2082 switch (tpg->mv_hor_mode) { in tpg_update_mv_step()
2085 tpg->mv_hor_step = ((tpg->src_width + 319) / 320) * 4; in tpg_update_mv_step()
2089 tpg->mv_hor_step = ((tpg->src_width + 639) / 640) * 4; in tpg_update_mv_step()
2093 tpg->mv_hor_step = 2; in tpg_update_mv_step()
2096 tpg->mv_hor_step = 0; in tpg_update_mv_step()
2100 tpg->mv_hor_step = tpg->src_width - tpg->mv_hor_step; in tpg_update_mv_step()
2102 factor = tpg->mv_vert_mode > TPG_MOVE_NONE ? -1 : 1; in tpg_update_mv_step()
2103 switch (tpg->mv_vert_mode) { in tpg_update_mv_step()
2106 tpg->mv_vert_step = ((tpg->src_width + 319) / 320) * 4; in tpg_update_mv_step()
2110 tpg->mv_vert_step = ((tpg->src_width + 639) / 640) * 4; in tpg_update_mv_step()
2114 tpg->mv_vert_step = 1; in tpg_update_mv_step()
2117 tpg->mv_vert_step = 0; in tpg_update_mv_step()
2121 tpg->mv_vert_step = tpg->src_height - tpg->mv_vert_step; in tpg_update_mv_step()
2131 return tpg->crop.top + src_y * 2; in tpg_calc_frameline()
2133 return tpg->crop.top + src_y * 2 + 1; in tpg_calc_frameline()
2135 return src_y + tpg->crop.top; in tpg_calc_frameline()
2143 static unsigned tpg_calc_buffer_line(const struct tpg_data *tpg, unsigned y, in tpg_calc_buffer_line() argument
2146 y += tpg->compose.top; in tpg_calc_buffer_line()
2149 if (y & 1) in tpg_calc_buffer_line()
2150 return tpg->buf_height / 2 + y / 2; in tpg_calc_buffer_line()
2151 return y / 2; in tpg_calc_buffer_line()
2153 if (y & 1) in tpg_calc_buffer_line()
2154 return y / 2; in tpg_calc_buffer_line()
2155 return tpg->buf_height / 2 + y / 2; in tpg_calc_buffer_line()
2157 return y; in tpg_calc_buffer_line()
2163 if (tpg->recalc_colors) { in tpg_recalc()
2164 tpg->recalc_colors = false; in tpg_recalc()
2165 tpg->recalc_lines = true; in tpg_recalc()
2166 tpg->real_xfer_func = tpg->xfer_func; in tpg_recalc()
2167 tpg->real_ycbcr_enc = tpg->ycbcr_enc; in tpg_recalc()
2168 tpg->real_hsv_enc = tpg->hsv_enc; in tpg_recalc()
2169 tpg->real_quantization = tpg->quantization; in tpg_recalc()
2171 if (tpg->xfer_func == V4L2_XFER_FUNC_DEFAULT) in tpg_recalc()
2172 tpg->real_xfer_func = in tpg_recalc()
2173 V4L2_MAP_XFER_FUNC_DEFAULT(tpg->colorspace); in tpg_recalc()
2175 if (tpg->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) in tpg_recalc()
2176 tpg->real_ycbcr_enc = in tpg_recalc()
2177 V4L2_MAP_YCBCR_ENC_DEFAULT(tpg->colorspace); in tpg_recalc()
2179 if (tpg->quantization == V4L2_QUANTIZATION_DEFAULT) in tpg_recalc()
2180 tpg->real_quantization = in tpg_recalc()
2182 tpg->color_enc != TGP_COLOR_ENC_YCBCR, in tpg_recalc()
2183 tpg->colorspace, tpg->real_ycbcr_enc); in tpg_recalc()
2187 if (tpg->recalc_square_border) { in tpg_recalc()
2188 tpg->recalc_square_border = false; in tpg_recalc()
2191 if (tpg->recalc_lines) { in tpg_recalc()
2192 tpg->recalc_lines = false; in tpg_recalc()
2200 unsigned stride = tpg->bytesperline[p]; in tpg_calc_text_basep()
2201 unsigned h = tpg->buf_height; in tpg_calc_text_basep()
2207 h /= tpg->vdownsampling[p]; in tpg_calc_text_basep()
2208 if (tpg->field == V4L2_FIELD_SEQ_TB) in tpg_calc_text_basep()
2210 else if (tpg->field == V4L2_FIELD_SEQ_BT) in tpg_calc_text_basep()
2212 if (p == 0 && tpg->interleaved) in tpg_calc_text_basep()
2226 return -1; in tpg_pattern_avg()
2236 return "Y'CbCr"; in tpg_color_enc_str()
2249 tpg->src_width, tpg->src_height, in tpg_log_status()
2250 tpg_color_enc_str(tpg->color_enc)); in tpg_log_status()
2251 pr_info("tpg field: %u\n", tpg->field); in tpg_log_status()
2252 pr_info("tpg crop: %ux%u@%dx%d\n", tpg->crop.width, tpg->crop.height, in tpg_log_status()
2253 tpg->crop.left, tpg->crop.top); in tpg_log_status()
2254 pr_info("tpg compose: %ux%u@%dx%d\n", tpg->compose.width, tpg->compose.height, in tpg_log_status()
2255 tpg->compose.left, tpg->compose.top); in tpg_log_status()
2256 pr_info("tpg colorspace: %d\n", tpg->colorspace); in tpg_log_status()
2257 pr_info("tpg transfer function: %d/%d\n", tpg->xfer_func, tpg->real_xfer_func); in tpg_log_status()
2258 if (tpg->color_enc == TGP_COLOR_ENC_HSV) in tpg_log_status()
2260 tpg->hsv_enc, tpg->real_hsv_enc); in tpg_log_status()
2261 else if (tpg->color_enc == TGP_COLOR_ENC_YCBCR) in tpg_log_status()
2262 pr_info("tpg Y'CbCr encoding: %d/%d\n", in tpg_log_status()
2263 tpg->ycbcr_enc, tpg->real_ycbcr_enc); in tpg_log_status()
2264 pr_info("tpg quantization: %d/%d\n", tpg->quantization, tpg->real_quantization); in tpg_log_status()
2265 pr_info("tpg RGB range: %d/%d\n", tpg->rgb_range, tpg->real_rgb_range); in tpg_log_status()
2301 params->mv_hor_old = in tpg_fill_params_pattern()
2302 tpg_hscale_div(tpg, p, tpg->mv_hor_count % tpg->src_width); in tpg_fill_params_pattern()
2303 params->mv_hor_new = in tpg_fill_params_pattern()
2304 tpg_hscale_div(tpg, p, (tpg->mv_hor_count + tpg->mv_hor_step) % in tpg_fill_params_pattern()
2305 tpg->src_width); in tpg_fill_params_pattern()
2306 params->mv_vert_old = tpg->mv_vert_count % tpg->src_height; in tpg_fill_params_pattern()
2307 params->mv_vert_new = in tpg_fill_params_pattern()
2308 (tpg->mv_vert_count + tpg->mv_vert_step) % tpg->src_height; in tpg_fill_params_pattern()
2316 unsigned right_pillar_start = params->img_width; in tpg_fill_params_extras()
2318 params->wss_width = tpg->crop.left < tpg->src_width / 2 ? in tpg_fill_params_extras()
2319 tpg->src_width / 2 - tpg->crop.left : 0; in tpg_fill_params_extras()
2320 if (params->wss_width > tpg->crop.width) in tpg_fill_params_extras()
2321 params->wss_width = tpg->crop.width; in tpg_fill_params_extras()
2322 params->wss_width = tpg_hscale_div(tpg, p, params->wss_width); in tpg_fill_params_extras()
2323 params->wss_random_offset = in tpg_fill_params_extras()
2324 params->twopixsize * get_random_u32_below(tpg->src_width / 2); in tpg_fill_params_extras()
2326 if (tpg->crop.left < tpg->border.left) { in tpg_fill_params_extras()
2327 left_pillar_width = tpg->border.left - tpg->crop.left; in tpg_fill_params_extras()
2328 if (left_pillar_width > tpg->crop.width) in tpg_fill_params_extras()
2329 left_pillar_width = tpg->crop.width; in tpg_fill_params_extras()
2332 params->left_pillar_width = left_pillar_width; in tpg_fill_params_extras()
2334 if (tpg->crop.left + tpg->crop.width > in tpg_fill_params_extras()
2335 tpg->border.left + tpg->border.width) { in tpg_fill_params_extras()
2337 tpg->border.left + tpg->border.width - tpg->crop.left; in tpg_fill_params_extras()
2340 if (right_pillar_start > params->img_width) in tpg_fill_params_extras()
2341 right_pillar_start = params->img_width; in tpg_fill_params_extras()
2343 params->right_pillar_start = right_pillar_start; in tpg_fill_params_extras()
2345 params->sav_eav_f = tpg->field == in tpg_fill_params_extras()
2346 (params->is_60hz ? V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM); in tpg_fill_params_extras()
2353 unsigned twopixsize = params->twopixsize; in tpg_fill_plane_extras()
2354 unsigned img_width = params->img_width; in tpg_fill_plane_extras()
2355 unsigned frame_line = params->frame_line; in tpg_fill_plane_extras()
2356 const struct v4l2_rect *sq = &tpg->square; in tpg_fill_plane_extras()
2357 const struct v4l2_rect *b = &tpg->border; in tpg_fill_plane_extras()
2358 const struct v4l2_rect *c = &tpg->crop; in tpg_fill_plane_extras()
2360 if (params->is_tv && !params->is_60hz && in tpg_fill_plane_extras()
2361 frame_line == 0 && params->wss_width) { in tpg_fill_plane_extras()
2366 u8 *wss = tpg->random_line[p] + params->wss_random_offset; in tpg_fill_plane_extras()
2368 memcpy(vbuf, wss, params->wss_width); in tpg_fill_plane_extras()
2371 if (tpg->show_border && frame_line >= b->top && in tpg_fill_plane_extras()
2372 frame_line < b->top + b->height) { in tpg_fill_plane_extras()
2373 unsigned bottom = b->top + b->height - 1; in tpg_fill_plane_extras()
2374 unsigned left = params->left_pillar_width; in tpg_fill_plane_extras()
2375 unsigned right = params->right_pillar_start; in tpg_fill_plane_extras()
2377 if (frame_line == b->top || frame_line == b->top + 1 || in tpg_fill_plane_extras()
2378 frame_line == bottom || frame_line == bottom - 1) { in tpg_fill_plane_extras()
2379 memcpy(vbuf + left, tpg->contrast_line[p], in tpg_fill_plane_extras()
2380 right - left); in tpg_fill_plane_extras()
2382 if (b->left >= c->left && in tpg_fill_plane_extras()
2383 b->left < c->left + c->width) in tpg_fill_plane_extras()
2385 tpg->contrast_line[p], twopixsize); in tpg_fill_plane_extras()
2386 if (b->left + b->width > c->left && in tpg_fill_plane_extras()
2387 b->left + b->width <= c->left + c->width) in tpg_fill_plane_extras()
2388 memcpy(vbuf + right - twopixsize, in tpg_fill_plane_extras()
2389 tpg->contrast_line[p], twopixsize); in tpg_fill_plane_extras()
2392 if (tpg->qual != TPG_QUAL_NOISE && frame_line >= b->top && in tpg_fill_plane_extras()
2393 frame_line < b->top + b->height) { in tpg_fill_plane_extras()
2394 memcpy(vbuf, tpg->black_line[p], params->left_pillar_width); in tpg_fill_plane_extras()
2395 memcpy(vbuf + params->right_pillar_start, tpg->black_line[p], in tpg_fill_plane_extras()
2396 img_width - params->right_pillar_start); in tpg_fill_plane_extras()
2398 if (tpg->show_square && frame_line >= sq->top && in tpg_fill_plane_extras()
2399 frame_line < sq->top + sq->height && in tpg_fill_plane_extras()
2400 sq->left < c->left + c->width && in tpg_fill_plane_extras()
2401 sq->left + sq->width >= c->left) { in tpg_fill_plane_extras()
2402 unsigned left = sq->left; in tpg_fill_plane_extras()
2403 unsigned width = sq->width; in tpg_fill_plane_extras()
2405 if (c->left > left) { in tpg_fill_plane_extras()
2406 width -= c->left - left; in tpg_fill_plane_extras()
2407 left = c->left; in tpg_fill_plane_extras()
2409 if (c->left + c->width < left + width) in tpg_fill_plane_extras()
2410 width -= left + width - c->left - c->width; in tpg_fill_plane_extras()
2411 left -= c->left; in tpg_fill_plane_extras()
2414 memcpy(vbuf + left, tpg->contrast_line[p], width); in tpg_fill_plane_extras()
2416 if (tpg->insert_sav) { in tpg_fill_plane_extras()
2417 unsigned offset = tpg_hdiv(tpg, p, tpg->compose.width / 3); in tpg_fill_plane_extras() local
2418 u8 *p = vbuf + offset; in tpg_fill_plane_extras()
2424 p[3] = 0x80 | (params->sav_eav_f << 6) | in tpg_fill_plane_extras()
2427 ((hact ^ params->sav_eav_f) << 2) | in tpg_fill_plane_extras()
2428 ((params->sav_eav_f ^ vact) << 1) | in tpg_fill_plane_extras()
2429 (hact ^ vact ^ params->sav_eav_f); in tpg_fill_plane_extras()
2431 if (tpg->insert_eav) { in tpg_fill_plane_extras()
2432 unsigned offset = tpg_hdiv(tpg, p, tpg->compose.width * 2 / 3); in tpg_fill_plane_extras() local
2433 u8 *p = vbuf + offset; in tpg_fill_plane_extras()
2439 p[3] = 0x80 | (params->sav_eav_f << 6) | in tpg_fill_plane_extras()
2442 ((hact ^ params->sav_eav_f) << 2) | in tpg_fill_plane_extras()
2443 ((params->sav_eav_f ^ vact) << 1) | in tpg_fill_plane_extras()
2444 (hact ^ vact ^ params->sav_eav_f); in tpg_fill_plane_extras()
2446 if (tpg->insert_hdmi_video_guard_band) { in tpg_fill_plane_extras()
2449 switch (tpg->fourcc) { in tpg_fill_plane_extras()
2490 unsigned twopixsize = params->twopixsize; in tpg_fill_plane_pattern()
2491 unsigned img_width = params->img_width; in tpg_fill_plane_pattern()
2492 unsigned mv_hor_old = params->mv_hor_old; in tpg_fill_plane_pattern()
2493 unsigned mv_hor_new = params->mv_hor_new; in tpg_fill_plane_pattern()
2494 unsigned mv_vert_old = params->mv_vert_old; in tpg_fill_plane_pattern()
2495 unsigned mv_vert_new = params->mv_vert_new; in tpg_fill_plane_pattern()
2496 unsigned frame_line = params->frame_line; in tpg_fill_plane_pattern()
2497 unsigned frame_line_next = params->frame_line_next; in tpg_fill_plane_pattern()
2498 unsigned line_offset = tpg_hscale_div(tpg, p, tpg->crop.left); in tpg_fill_plane_pattern()
2510 if (h >= params->hmax) { in tpg_fill_plane_pattern()
2511 if (params->hmax == tpg->compose.height) in tpg_fill_plane_pattern()
2513 if (!tpg->perc_fill_blank) in tpg_fill_plane_pattern()
2518 if (tpg->vflip) { in tpg_fill_plane_pattern()
2519 frame_line = tpg->src_height - frame_line - 1; in tpg_fill_plane_pattern()
2520 frame_line_next = tpg->src_height - frame_line_next - 1; in tpg_fill_plane_pattern()
2524 linestart_older = tpg->contrast_line[p]; in tpg_fill_plane_pattern()
2525 linestart_newer = tpg->contrast_line[p]; in tpg_fill_plane_pattern()
2526 } else if (tpg->qual != TPG_QUAL_NOISE && in tpg_fill_plane_pattern()
2527 (frame_line < tpg->border.top || in tpg_fill_plane_pattern()
2528 frame_line >= tpg->border.top + tpg->border.height)) { in tpg_fill_plane_pattern()
2529 linestart_older = tpg->black_line[p]; in tpg_fill_plane_pattern()
2530 linestart_newer = tpg->black_line[p]; in tpg_fill_plane_pattern()
2531 } else if (tpg->pattern == TPG_PAT_NOISE || tpg->qual == TPG_QUAL_NOISE) { in tpg_fill_plane_pattern()
2532 linestart_older = tpg->random_line[p] + in tpg_fill_plane_pattern()
2533 twopixsize * get_random_u32_below(tpg->src_width / 2); in tpg_fill_plane_pattern()
2534 linestart_newer = tpg->random_line[p] + in tpg_fill_plane_pattern()
2535 twopixsize * get_random_u32_below(tpg->src_width / 2); in tpg_fill_plane_pattern()
2538 (frame_line + mv_vert_old) % tpg->src_height; in tpg_fill_plane_pattern()
2540 (frame_line + mv_vert_new) % tpg->src_height; in tpg_fill_plane_pattern()
2546 linestart_older = tpg->lines[pat_line_old][p] + mv_hor_old; in tpg_fill_plane_pattern()
2547 linestart_newer = tpg->lines[pat_line_new][p] + mv_hor_new; in tpg_fill_plane_pattern()
2549 if (tpg->vdownsampling[p] > 1 && frame_line != frame_line_next) { in tpg_fill_plane_pattern()
2557 (frame_line_next + mv_vert_old) % tpg->src_height); in tpg_fill_plane_pattern()
2559 (frame_line_next + mv_vert_new) % tpg->src_height); in tpg_fill_plane_pattern()
2561 switch (tpg->field) { in tpg_fill_plane_pattern()
2568 linestart_older = tpg->downsampled_lines[avg_pat][p] + mv_hor_old; in tpg_fill_plane_pattern()
2578 linestart_older = tpg->downsampled_lines[avg_pat][p] + in tpg_fill_plane_pattern()
2582 linestart_newer = tpg->downsampled_lines[avg_pat][p] + in tpg_fill_plane_pattern()
2590 if (tpg->field_alternate) { in tpg_fill_plane_pattern()
2592 } else if (params->is_60hz) { in tpg_fill_plane_pattern()
2600 switch (tpg->field) { in tpg_fill_plane_pattern()
2633 unsigned factor = V4L2_FIELD_HAS_T_OR_B(tpg->field) ? 2 : 1; in tpg_fill_plane_buffer()
2636 unsigned int_part = (tpg->crop.height / factor) / tpg->compose.height; in tpg_fill_plane_buffer()
2637 unsigned fract_part = (tpg->crop.height / factor) % tpg->compose.height; in tpg_fill_plane_buffer()
2646 params.twopixsize = tpg->twopixelsize[p]; in tpg_fill_plane_buffer()
2647 params.img_width = tpg_hdiv(tpg, p, tpg->compose.width); in tpg_fill_plane_buffer()
2648 params.stride = tpg->bytesperline[p]; in tpg_fill_plane_buffer()
2649 params.hmax = (tpg->compose.height * tpg->perc_fill) / 100; in tpg_fill_plane_buffer()
2654 vbuf += tpg_hdiv(tpg, p, tpg->compose.left); in tpg_fill_plane_buffer()
2656 for (h = 0; h < tpg->compose.height; h++) { in tpg_fill_plane_buffer()
2659 params.frame_line = tpg_calc_frameline(tpg, src_y, tpg->field); in tpg_fill_plane_buffer()
2661 buf_line = tpg_calc_buffer_line(tpg, h, tpg->field); in tpg_fill_plane_buffer()
2664 if (error >= tpg->compose.height) { in tpg_fill_plane_buffer()
2665 error -= tpg->compose.height; in tpg_fill_plane_buffer()
2670 * For line-interleaved formats determine the 'plane' in tpg_fill_plane_buffer()
2676 if (tpg->vdownsampling[p] > 1) { in tpg_fill_plane_buffer()
2685 if (tpg->field == V4L2_FIELD_SEQ_BT || in tpg_fill_plane_buffer()
2686 tpg->field == V4L2_FIELD_SEQ_TB) { in tpg_fill_plane_buffer()
2692 if (error + fract_part >= tpg->compose.height) in tpg_fill_plane_buffer()
2695 tpg_calc_frameline(tpg, next_src_y, tpg->field); in tpg_fill_plane_buffer()
2700 tpg_calc_frameline(tpg, src_y, tpg->field); in tpg_fill_plane_buffer()
2703 buf_line /= tpg->vdownsampling[p]; in tpg_fill_plane_buffer()
2715 unsigned offset = 0; in tpg_fillbuffer() local
2718 if (tpg->buffers > 1) { in tpg_fillbuffer()
2724 tpg_fill_plane_buffer(tpg, std, i, vbuf + offset); in tpg_fillbuffer()
2725 offset += tpg_calc_plane_size(tpg, i); in tpg_fillbuffer()