Lines Matching refs:tpg

97 void tpg_init(struct tpg_data *tpg, unsigned w, unsigned h)  in tpg_init()  argument
99 memset(tpg, 0, sizeof(*tpg)); in tpg_init()
100 tpg->scaled_width = tpg->src_width = w; in tpg_init()
101 tpg->src_height = tpg->buf_height = h; in tpg_init()
102 tpg->crop.width = tpg->compose.width = w; in tpg_init()
103 tpg->crop.height = tpg->compose.height = h; in tpg_init()
104 tpg->recalc_colors = true; in tpg_init()
105 tpg->recalc_square_border = true; in tpg_init()
106 tpg->brightness = 128; in tpg_init()
107 tpg->contrast = 128; in tpg_init()
108 tpg->saturation = 128; in tpg_init()
109 tpg->hue = 0; in tpg_init()
110 tpg->mv_hor_mode = TPG_MOVE_NONE; in tpg_init()
111 tpg->mv_vert_mode = TPG_MOVE_NONE; in tpg_init()
112 tpg->field = V4L2_FIELD_NONE; in tpg_init()
113 tpg_s_fourcc(tpg, V4L2_PIX_FMT_RGB24); in tpg_init()
114 tpg->colorspace = V4L2_COLORSPACE_SRGB; in tpg_init()
115 tpg->perc_fill = 100; in tpg_init()
118 int tpg_alloc(struct tpg_data *tpg, unsigned max_w) in tpg_alloc() argument
123 tpg->max_line_width = max_w; in tpg_alloc()
128 tpg->lines[pat][plane] = vzalloc(max_w * 2 * pixelsz); in tpg_alloc()
129 if (!tpg->lines[pat][plane]) in tpg_alloc()
133 tpg->downsampled_lines[pat][plane] = vzalloc(max_w * 2 * pixelsz); in tpg_alloc()
134 if (!tpg->downsampled_lines[pat][plane]) in tpg_alloc()
141 tpg->contrast_line[plane] = vzalloc(max_w * pixelsz); in tpg_alloc()
142 if (!tpg->contrast_line[plane]) in tpg_alloc()
144 tpg->black_line[plane] = vzalloc(max_w * pixelsz); in tpg_alloc()
145 if (!tpg->black_line[plane]) in tpg_alloc()
147 tpg->random_line[plane] = vzalloc(max_w * 2 * pixelsz); in tpg_alloc()
148 if (!tpg->random_line[plane]) in tpg_alloc()
154 void tpg_free(struct tpg_data *tpg) in tpg_free() argument
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()
178 bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc) in tpg_s_fourcc() argument
180 tpg->fourcc = fourcc; in tpg_s_fourcc()
181 tpg->planes = 1; in tpg_s_fourcc()
182 tpg->buffers = 1; in tpg_s_fourcc()
183 tpg->recalc_colors = true; in tpg_s_fourcc()
184 tpg->interleaved = false; in tpg_s_fourcc()
185 tpg->vdownsampling[0] = 1; in tpg_s_fourcc()
186 tpg->hdownsampling[0] = 1; in tpg_s_fourcc()
187 tpg->hmask[0] = ~0; in tpg_s_fourcc()
188 tpg->hmask[1] = ~0; in tpg_s_fourcc()
189 tpg->hmask[2] = ~0; in tpg_s_fourcc()
204 tpg->interleaved = true; in tpg_s_fourcc()
205 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
206 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
207 tpg->planes = 2; in tpg_s_fourcc()
233 tpg->is_yuv = false; in tpg_s_fourcc()
239 tpg->is_yuv = true; in tpg_s_fourcc()
243 tpg->buffers = 3; in tpg_s_fourcc()
247 tpg->vdownsampling[1] = 2; in tpg_s_fourcc()
248 tpg->vdownsampling[2] = 2; in tpg_s_fourcc()
249 tpg->hdownsampling[1] = 2; in tpg_s_fourcc()
250 tpg->hdownsampling[2] = 2; in tpg_s_fourcc()
251 tpg->planes = 3; in tpg_s_fourcc()
252 tpg->is_yuv = true; in tpg_s_fourcc()
255 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
256 tpg->vdownsampling[2] = 1; in tpg_s_fourcc()
257 tpg->hdownsampling[1] = 2; in tpg_s_fourcc()
258 tpg->hdownsampling[2] = 2; in tpg_s_fourcc()
259 tpg->planes = 3; in tpg_s_fourcc()
260 tpg->is_yuv = true; in tpg_s_fourcc()
264 tpg->buffers = 2; in tpg_s_fourcc()
268 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
269 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
270 tpg->hmask[1] = ~1; in tpg_s_fourcc()
271 tpg->planes = 2; in tpg_s_fourcc()
272 tpg->is_yuv = true; in tpg_s_fourcc()
276 tpg->buffers = 2; in tpg_s_fourcc()
280 tpg->vdownsampling[1] = 2; in tpg_s_fourcc()
281 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
282 tpg->hmask[1] = ~1; in tpg_s_fourcc()
283 tpg->planes = 2; in tpg_s_fourcc()
284 tpg->is_yuv = true; in tpg_s_fourcc()
288 tpg->vdownsampling[1] = 1; in tpg_s_fourcc()
289 tpg->hdownsampling[1] = 1; in tpg_s_fourcc()
290 tpg->planes = 2; in tpg_s_fourcc()
291 tpg->is_yuv = true; in tpg_s_fourcc()
297 tpg->hmask[0] = ~1; in tpg_s_fourcc()
298 tpg->is_yuv = true; in tpg_s_fourcc()
307 tpg->twopixelsize[0] = 2; in tpg_s_fourcc()
329 tpg->twopixelsize[0] = 2 * 2; in tpg_s_fourcc()
333 tpg->twopixelsize[0] = 2 * 3; in tpg_s_fourcc()
343 tpg->twopixelsize[0] = 2 * 4; in tpg_s_fourcc()
357 tpg->twopixelsize[0] = 2; in tpg_s_fourcc()
358 tpg->twopixelsize[1] = 2; in tpg_s_fourcc()
368 tpg->twopixelsize[0] = 4; in tpg_s_fourcc()
369 tpg->twopixelsize[1] = 4; in tpg_s_fourcc()
376 tpg->twopixelsize[0] = 2; in tpg_s_fourcc()
377 tpg->twopixelsize[1] = 2; in tpg_s_fourcc()
378 tpg->twopixelsize[2] = 2; in tpg_s_fourcc()
382 tpg->twopixelsize[0] = 2; in tpg_s_fourcc()
383 tpg->twopixelsize[1] = 4; in tpg_s_fourcc()
389 void tpg_s_crop_compose(struct tpg_data *tpg, const struct v4l2_rect *crop, in tpg_s_crop_compose() argument
392 tpg->crop = *crop; in tpg_s_crop_compose()
393 tpg->compose = *compose; in tpg_s_crop_compose()
394 tpg->scaled_width = (tpg->src_width * tpg->compose.width + in tpg_s_crop_compose()
395 tpg->crop.width - 1) / tpg->crop.width; in tpg_s_crop_compose()
396 tpg->scaled_width &= ~1; in tpg_s_crop_compose()
397 if (tpg->scaled_width > tpg->max_line_width) in tpg_s_crop_compose()
398 tpg->scaled_width = tpg->max_line_width; in tpg_s_crop_compose()
399 if (tpg->scaled_width < 2) in tpg_s_crop_compose()
400 tpg->scaled_width = 2; in tpg_s_crop_compose()
401 tpg->recalc_lines = true; in tpg_s_crop_compose()
404 void tpg_reset_source(struct tpg_data *tpg, unsigned width, unsigned height, in tpg_reset_source() argument
409 tpg->src_width = width; in tpg_reset_source()
410 tpg->src_height = height; in tpg_reset_source()
411 tpg->field = field; in tpg_reset_source()
412 tpg->buf_height = height; in tpg_reset_source()
414 tpg->buf_height /= 2; in tpg_reset_source()
415 tpg->scaled_width = width; in tpg_reset_source()
416 tpg->crop.top = tpg->crop.left = 0; in tpg_reset_source()
417 tpg->crop.width = width; in tpg_reset_source()
418 tpg->crop.height = height; in tpg_reset_source()
419 tpg->compose.top = tpg->compose.left = 0; in tpg_reset_source()
420 tpg->compose.width = width; in tpg_reset_source()
421 tpg->compose.height = tpg->buf_height; in tpg_reset_source()
422 for (p = 0; p < tpg->planes; p++) in tpg_reset_source()
423 tpg->bytesperline[p] = (width * tpg->twopixelsize[p]) / in tpg_reset_source()
424 (2 * tpg->hdownsampling[p]); in tpg_reset_source()
425 tpg->recalc_square_border = true; in tpg_reset_source()
428 static enum tpg_color tpg_get_textbg_color(struct tpg_data *tpg) in tpg_get_textbg_color() argument
430 switch (tpg->pattern) { in tpg_get_textbg_color()
440 static enum tpg_color tpg_get_textfg_color(struct tpg_data *tpg) in tpg_get_textfg_color() argument
442 switch (tpg->pattern) { in tpg_get_textfg_color()
473 static void color_to_ycbcr(struct tpg_data *tpg, int r, int g, int b, in color_to_ycbcr() argument
527 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE; in color_to_ycbcr()
531 switch (tpg->real_ycbcr_enc) { in color_to_ycbcr()
588 static void ycbcr_to_color(struct tpg_data *tpg, int y, int cb, int cr, in ycbcr_to_color() argument
642 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE; in ycbcr_to_color()
647 switch (tpg->real_ycbcr_enc) { in ycbcr_to_color()
700 static void precalculate_color(struct tpg_data *tpg, int k) in precalculate_color() argument
708 col = tpg_get_textbg_color(tpg); in precalculate_color()
714 col = tpg_get_textfg_color(tpg); in precalculate_color()
719 } else if (tpg->pattern == TPG_PAT_NOISE) { in precalculate_color()
722 r = g = b = tpg->qual_offset + prandom_u32_max(196); in precalculate_color()
727 if (tpg->pattern == TPG_PAT_CSC_COLORBAR && col <= TPG_COLOR_CSC_BLACK) { in precalculate_color()
728 r = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].r; in precalculate_color()
729 g = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].g; in precalculate_color()
730 b = tpg_csc_colors[tpg->colorspace][tpg->real_xfer_func][col].b; in precalculate_color()
736 if (tpg->qual == TPG_QUAL_GRAY || tpg->fourcc == V4L2_PIX_FMT_GREY || in precalculate_color()
737 tpg->fourcc == V4L2_PIX_FMT_Y16 || in precalculate_color()
738 tpg->fourcc == V4L2_PIX_FMT_Y16_BE) { in precalculate_color()
751 if (tpg->real_rgb_range == V4L2_DV_RGB_RANGE_LIMITED && in precalculate_color()
752 tpg->rgb_range == V4L2_DV_RGB_RANGE_FULL) { in precalculate_color()
761 } else if (tpg->real_rgb_range != V4L2_DV_RGB_RANGE_LIMITED && in precalculate_color()
762 tpg->rgb_range == V4L2_DV_RGB_RANGE_LIMITED) { in precalculate_color()
775 if (tpg->brightness != 128 || tpg->contrast != 128 || in precalculate_color()
776 tpg->saturation != 128 || tpg->hue) { in precalculate_color()
783 color_to_ycbcr(tpg, r, g, b, &y, &cb, &cr); in precalculate_color()
785 y = (16 << 4) + ((y - (16 << 4)) * tpg->contrast) / 128; in precalculate_color()
786 y += (tpg->brightness << 4) - (128 << 4); in precalculate_color()
790 tmp_cb = (cb * cos(128 + tpg->hue)) / 127 + (cr * sin[128 + tpg->hue]) / 127; in precalculate_color()
791 tmp_cr = (cr * cos(128 + tpg->hue)) / 127 - (cb * sin[128 + tpg->hue]) / 127; in precalculate_color()
793 cb = (128 << 4) + (tmp_cb * tpg->contrast * tpg->saturation) / (128 * 128); in precalculate_color()
794 cr = (128 << 4) + (tmp_cr * tpg->contrast * tpg->saturation) / (128 * 128); in precalculate_color()
795 if (tpg->is_yuv) { in precalculate_color()
796 tpg->colors[k][0] = clamp(y >> 4, 1, 254); in precalculate_color()
797 tpg->colors[k][1] = clamp(cb >> 4, 1, 254); in precalculate_color()
798 tpg->colors[k][2] = clamp(cr >> 4, 1, 254); in precalculate_color()
801 ycbcr_to_color(tpg, y, cb, cr, &r, &g, &b); in precalculate_color()
804 if (tpg->is_yuv) { in precalculate_color()
808 color_to_ycbcr(tpg, r, g, b, &y, &cb, &cr); in precalculate_color()
810 if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) { in precalculate_color()
818 switch (tpg->fourcc) { in precalculate_color()
835 tpg->colors[k][0] = y; in precalculate_color()
836 tpg->colors[k][1] = cb; in precalculate_color()
837 tpg->colors[k][2] = cr; in precalculate_color()
839 if (tpg->real_quantization == V4L2_QUANTIZATION_LIM_RANGE) { in precalculate_color()
844 switch (tpg->fourcc) { in precalculate_color()
885 tpg->colors[k][0] = r; in precalculate_color()
886 tpg->colors[k][1] = g; in precalculate_color()
887 tpg->colors[k][2] = b; in precalculate_color()
891 static void tpg_precalculate_colors(struct tpg_data *tpg) in tpg_precalculate_colors() argument
896 precalculate_color(tpg, k); in tpg_precalculate_colors()
900 static void gen_twopix(struct tpg_data *tpg, in gen_twopix() argument
903 unsigned offset = odd * tpg->twopixelsize[0] / 2; in gen_twopix()
904 u8 alpha = tpg->alpha_component; in gen_twopix()
907 if (tpg->alpha_red_only && color != TPG_COLOR_CSC_RED && in gen_twopix()
912 precalculate_color(tpg, color); in gen_twopix()
913 r_y = tpg->colors[color][0]; /* R or precalculated Y */ in gen_twopix()
914 g_u = tpg->colors[color][1]; /* G or precalculated U */ in gen_twopix()
915 b_v = tpg->colors[color][2]; /* B or precalculated V */ in gen_twopix()
917 switch (tpg->fourcc) { in gen_twopix()
1201 unsigned tpg_g_interleaved_plane(const struct tpg_data *tpg, unsigned buf_line) in tpg_g_interleaved_plane() argument
1203 switch (tpg->fourcc) { in tpg_g_interleaved_plane()
1223 static unsigned tpg_get_pat_lines(const struct tpg_data *tpg) in tpg_get_pat_lines() argument
1225 switch (tpg->pattern) { in tpg_get_pat_lines()
1245 static unsigned tpg_get_pat_line(const struct tpg_data *tpg, unsigned line) in tpg_get_pat_line() argument
1247 switch (tpg->pattern) { in tpg_get_pat_line()
1259 return (line * 8) / tpg->src_height; in tpg_get_pat_line()
1261 return line == tpg->src_height / 2; in tpg_get_pat_line()
1263 return (line + 1) / 2 == tpg->src_height / 4; in tpg_get_pat_line()
1265 return (line + 10) / 20 == tpg->src_height / 40; in tpg_get_pat_line()
1275 static enum tpg_color tpg_get_color(const struct tpg_data *tpg, in tpg_get_color() argument
1298 switch (tpg->pattern) { in tpg_get_color()
1302 return bars[tpg->pattern][((x * 8) / tpg->src_width) % 8]; in tpg_get_color()
1304 return bars[1][(pat_line + (x * 8) / tpg->src_width) % 8]; in tpg_get_color()
1337 if (pat_line || (x % tpg->src_width) == tpg->src_width / 2) in tpg_get_color()
1341 if (pat_line || ((x % tpg->src_width) + 1) / 2 == tpg->src_width / 4) in tpg_get_color()
1345 if (pat_line || ((x % tpg->src_width) + 10) / 20 == tpg->src_width / 40) in tpg_get_color()
1349 return TPG_COLOR_RAMP + ((x % tpg->src_width) * 256) / tpg->src_width; in tpg_get_color()
1361 static void tpg_calculate_square_border(struct tpg_data *tpg) in tpg_calculate_square_border() argument
1363 unsigned w = tpg->src_width; in tpg_calculate_square_border()
1364 unsigned h = tpg->src_height; in tpg_calculate_square_border()
1371 tpg->square.width = sq_w; in tpg_calculate_square_border()
1372 if (tpg->vid_aspect == TPG_VIDEO_ASPECT_16X9_ANAMORPHIC) { in tpg_calculate_square_border()
1377 tpg->square.width = ana_sq_w; in tpg_calculate_square_border()
1379 tpg->square.left = (w - tpg->square.width) / 2; in tpg_calculate_square_border()
1380 if (tpg->pix_aspect == TPG_PIXEL_ASPECT_NTSC) in tpg_calculate_square_border()
1382 else if (tpg->pix_aspect == TPG_PIXEL_ASPECT_PAL) in tpg_calculate_square_border()
1384 tpg->square.height = sq_h; in tpg_calculate_square_border()
1385 tpg->square.top = (h - sq_h) / 2; in tpg_calculate_square_border()
1386 tpg->border.left = 0; in tpg_calculate_square_border()
1387 tpg->border.width = w; in tpg_calculate_square_border()
1388 tpg->border.top = 0; in tpg_calculate_square_border()
1389 tpg->border.height = h; in tpg_calculate_square_border()
1390 switch (tpg->vid_aspect) { in tpg_calculate_square_border()
1392 if (tpg->pix_aspect) in tpg_calculate_square_border()
1395 tpg->border.width = ((4 * h) / 3) & ~1; in tpg_calculate_square_border()
1396 if (((w - tpg->border.width) / 2) & ~1) in tpg_calculate_square_border()
1397 tpg->border.width -= 2; in tpg_calculate_square_border()
1398 tpg->border.left = (w - tpg->border.width) / 2; in tpg_calculate_square_border()
1401 tpg->border.height = ((3 * w) / 4) & ~1; in tpg_calculate_square_border()
1402 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1405 if (tpg->pix_aspect) { in tpg_calculate_square_border()
1406 tpg->border.height = tpg->pix_aspect == TPG_PIXEL_ASPECT_NTSC ? 420 : 506; in tpg_calculate_square_border()
1407 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1411 tpg->border.width = ((14 * h) / 9) & ~1; in tpg_calculate_square_border()
1412 if (((w - tpg->border.width) / 2) & ~1) in tpg_calculate_square_border()
1413 tpg->border.width -= 2; in tpg_calculate_square_border()
1414 tpg->border.left = (w - tpg->border.width) / 2; in tpg_calculate_square_border()
1417 tpg->border.height = ((9 * w) / 14) & ~1; in tpg_calculate_square_border()
1418 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1421 if (tpg->pix_aspect) { in tpg_calculate_square_border()
1422 tpg->border.height = tpg->pix_aspect == TPG_PIXEL_ASPECT_NTSC ? 368 : 442; in tpg_calculate_square_border()
1423 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1427 tpg->border.width = ((16 * h) / 9) & ~1; in tpg_calculate_square_border()
1428 if (((w - tpg->border.width) / 2) & ~1) in tpg_calculate_square_border()
1429 tpg->border.width -= 2; in tpg_calculate_square_border()
1430 tpg->border.left = (w - tpg->border.width) / 2; in tpg_calculate_square_border()
1433 tpg->border.height = ((9 * w) / 16) & ~1; in tpg_calculate_square_border()
1434 tpg->border.top = (h - tpg->border.height) / 2; in tpg_calculate_square_border()
1441 static void tpg_precalculate_line(struct tpg_data *tpg) in tpg_precalculate_line() argument
1449 switch (tpg->pattern) { in tpg_precalculate_line()
1461 for (pat = 0; pat < tpg_get_pat_lines(tpg); pat++) { in tpg_precalculate_line()
1463 unsigned int_part = tpg->src_width / tpg->scaled_width; in tpg_precalculate_line()
1464 unsigned fract_part = tpg->src_width % tpg->scaled_width; in tpg_precalculate_line()
1468 for (x = 0; x < tpg->scaled_width * 2; x += 2) { in tpg_precalculate_line()
1472 real_x = tpg->hflip ? tpg->src_width * 2 - real_x - 2 : real_x; in tpg_precalculate_line()
1473 color1 = tpg_get_color(tpg, pat, real_x); in tpg_precalculate_line()
1477 if (error >= tpg->scaled_width) { in tpg_precalculate_line()
1478 error -= tpg->scaled_width; in tpg_precalculate_line()
1483 real_x = tpg->hflip ? tpg->src_width * 2 - real_x - 2 : real_x; in tpg_precalculate_line()
1484 color2 = tpg_get_color(tpg, pat, real_x); in tpg_precalculate_line()
1488 if (error >= tpg->scaled_width) { in tpg_precalculate_line()
1489 error -= tpg->scaled_width; in tpg_precalculate_line()
1493 gen_twopix(tpg, pix, tpg->hflip ? color2 : color1, 0); in tpg_precalculate_line()
1494 gen_twopix(tpg, pix, tpg->hflip ? color1 : color2, 1); in tpg_precalculate_line()
1495 for (p = 0; p < tpg->planes; p++) { in tpg_precalculate_line()
1496 unsigned twopixsize = tpg->twopixelsize[p]; in tpg_precalculate_line()
1497 unsigned hdiv = tpg->hdownsampling[p]; in tpg_precalculate_line()
1498 u8 *pos = tpg->lines[pat][p] + tpg_hdiv(tpg, p, x); in tpg_precalculate_line()
1505 if (tpg->vdownsampling[tpg->planes - 1] > 1) { in tpg_precalculate_line()
1506 unsigned pat_lines = tpg_get_pat_lines(tpg); in tpg_precalculate_line()
1511 for (p = 1; p < tpg->planes; p++) { in tpg_precalculate_line()
1512 unsigned w = tpg_hdiv(tpg, p, tpg->scaled_width * 2); in tpg_precalculate_line()
1513 u8 *pos1 = tpg->lines[pat][p]; in tpg_precalculate_line()
1514 u8 *pos2 = tpg->lines[next_pat][p]; in tpg_precalculate_line()
1515 u8 *dest = tpg->downsampled_lines[pat][p]; in tpg_precalculate_line()
1523 gen_twopix(tpg, pix, contrast, 0); in tpg_precalculate_line()
1524 gen_twopix(tpg, pix, contrast, 1); in tpg_precalculate_line()
1525 for (p = 0; p < tpg->planes; p++) { in tpg_precalculate_line()
1526 unsigned twopixsize = tpg->twopixelsize[p]; in tpg_precalculate_line()
1527 u8 *pos = tpg->contrast_line[p]; in tpg_precalculate_line()
1529 for (x = 0; x < tpg->scaled_width; x += 2, pos += twopixsize) in tpg_precalculate_line()
1533 gen_twopix(tpg, pix, TPG_COLOR_100_BLACK, 0); in tpg_precalculate_line()
1534 gen_twopix(tpg, pix, TPG_COLOR_100_BLACK, 1); in tpg_precalculate_line()
1535 for (p = 0; p < tpg->planes; p++) { in tpg_precalculate_line()
1536 unsigned twopixsize = tpg->twopixelsize[p]; in tpg_precalculate_line()
1537 u8 *pos = tpg->black_line[p]; in tpg_precalculate_line()
1539 for (x = 0; x < tpg->scaled_width; x += 2, pos += twopixsize) in tpg_precalculate_line()
1543 for (x = 0; x < tpg->scaled_width * 2; x += 2) { in tpg_precalculate_line()
1544 gen_twopix(tpg, pix, TPG_COLOR_RANDOM, 0); in tpg_precalculate_line()
1545 gen_twopix(tpg, pix, TPG_COLOR_RANDOM, 1); in tpg_precalculate_line()
1546 for (p = 0; p < tpg->planes; p++) { in tpg_precalculate_line()
1547 unsigned twopixsize = tpg->twopixelsize[p]; in tpg_precalculate_line()
1548 u8 *pos = tpg->random_line[p] + x * twopixsize / 2; in tpg_precalculate_line()
1554 gen_twopix(tpg, tpg->textbg, TPG_COLOR_TEXTBG, 0); in tpg_precalculate_line()
1555 gen_twopix(tpg, tpg->textbg, TPG_COLOR_TEXTBG, 1); in tpg_precalculate_line()
1556 gen_twopix(tpg, tpg->textfg, TPG_COLOR_TEXTFG, 0); in tpg_precalculate_line()
1557 gen_twopix(tpg, tpg->textfg, TPG_COLOR_TEXTFG, 1); in tpg_precalculate_line()
1564 unsigned vdiv = tpg->vdownsampling[p]; \
1565 unsigned hdiv = tpg->hdownsampling[p]; \
1569 memcpy(&fg, tpg->textfg[p], sizeof(PIXTYPE)); \
1570 memcpy(&bg, tpg->textbg[p], sizeof(PIXTYPE)); \
1573 int l = tpg->vflip ? 15 - line : line; \
1575 ((y * step + l) / (vdiv * div)) * tpg->bytesperline[p] + \
1582 if (hdiv == 2 && tpg->hflip) { \
1592 } else if (tpg->hflip) { \
1612 pos += (tpg->hflip ? -8 : 8) / hdiv; \
1617 static noinline void tpg_print_str_2(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2], in tpg_print_str_2() argument
1624 static noinline void tpg_print_str_4(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2], in tpg_print_str_4() argument
1631 static noinline void tpg_print_str_6(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2], in tpg_print_str_6() argument
1638 static noinline void tpg_print_str_8(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2], in tpg_print_str_8() argument
1645 void tpg_gen_text(const struct tpg_data *tpg, u8 *basep[TPG_MAX_PLANES][2], in tpg_gen_text() argument
1648 unsigned step = V4L2_FIELD_HAS_T_OR_B(tpg->field) ? 2 : 1; in tpg_gen_text()
1658 if (y + 16 >= tpg->compose.height || x + 8 >= tpg->compose.width) in tpg_gen_text()
1661 if (len > (tpg->compose.width - x) / 8) in tpg_gen_text()
1662 len = (tpg->compose.width - x) / 8; in tpg_gen_text()
1663 if (tpg->vflip) in tpg_gen_text()
1664 y = tpg->compose.height - y - 16; in tpg_gen_text()
1665 if (tpg->hflip) in tpg_gen_text()
1666 x = tpg->compose.width - x - 8; in tpg_gen_text()
1667 y += tpg->compose.top; in tpg_gen_text()
1668 x += tpg->compose.left; in tpg_gen_text()
1669 if (tpg->field == V4L2_FIELD_BOTTOM) in tpg_gen_text()
1671 else if (tpg->field == V4L2_FIELD_SEQ_TB || tpg->field == V4L2_FIELD_SEQ_BT) in tpg_gen_text()
1674 for (p = 0; p < tpg->planes; p++) { in tpg_gen_text()
1676 switch (tpg->twopixelsize[p]) { in tpg_gen_text()
1678 tpg_print_str_2(tpg, basep, p, first, div, step, y, x, in tpg_gen_text()
1682 tpg_print_str_4(tpg, basep, p, first, div, step, y, x, in tpg_gen_text()
1686 tpg_print_str_6(tpg, basep, p, first, div, step, y, x, in tpg_gen_text()
1690 tpg_print_str_8(tpg, basep, p, first, div, step, y, x, in tpg_gen_text()
1697 void tpg_update_mv_step(struct tpg_data *tpg) in tpg_update_mv_step() argument
1699 int factor = tpg->mv_hor_mode > TPG_MOVE_NONE ? -1 : 1; in tpg_update_mv_step()
1701 if (tpg->hflip) in tpg_update_mv_step()
1703 switch (tpg->mv_hor_mode) { in tpg_update_mv_step()
1706 tpg->mv_hor_step = ((tpg->src_width + 319) / 320) * 4; in tpg_update_mv_step()
1710 tpg->mv_hor_step = ((tpg->src_width + 639) / 640) * 4; in tpg_update_mv_step()
1714 tpg->mv_hor_step = 2; in tpg_update_mv_step()
1717 tpg->mv_hor_step = 0; in tpg_update_mv_step()
1721 tpg->mv_hor_step = tpg->src_width - tpg->mv_hor_step; in tpg_update_mv_step()
1723 factor = tpg->mv_vert_mode > TPG_MOVE_NONE ? -1 : 1; in tpg_update_mv_step()
1724 switch (tpg->mv_vert_mode) { in tpg_update_mv_step()
1727 tpg->mv_vert_step = ((tpg->src_width + 319) / 320) * 4; in tpg_update_mv_step()
1731 tpg->mv_vert_step = ((tpg->src_width + 639) / 640) * 4; in tpg_update_mv_step()
1735 tpg->mv_vert_step = 1; in tpg_update_mv_step()
1738 tpg->mv_vert_step = 0; in tpg_update_mv_step()
1742 tpg->mv_vert_step = tpg->src_height - tpg->mv_vert_step; in tpg_update_mv_step()
1746 static unsigned tpg_calc_frameline(const struct tpg_data *tpg, unsigned src_y, in tpg_calc_frameline() argument
1751 return tpg->crop.top + src_y * 2; in tpg_calc_frameline()
1753 return tpg->crop.top + src_y * 2 + 1; in tpg_calc_frameline()
1755 return src_y + tpg->crop.top; in tpg_calc_frameline()
1763 static unsigned tpg_calc_buffer_line(const struct tpg_data *tpg, unsigned y, in tpg_calc_buffer_line() argument
1766 y += tpg->compose.top; in tpg_calc_buffer_line()
1770 return tpg->buf_height / 2 + y / 2; in tpg_calc_buffer_line()
1775 return tpg->buf_height / 2 + y / 2; in tpg_calc_buffer_line()
1781 static void tpg_recalc(struct tpg_data *tpg) in tpg_recalc() argument
1783 if (tpg->recalc_colors) { in tpg_recalc()
1784 tpg->recalc_colors = false; in tpg_recalc()
1785 tpg->recalc_lines = true; in tpg_recalc()
1786 tpg->real_xfer_func = tpg->xfer_func; in tpg_recalc()
1787 tpg->real_ycbcr_enc = tpg->ycbcr_enc; in tpg_recalc()
1788 tpg->real_quantization = tpg->quantization; in tpg_recalc()
1790 if (tpg->xfer_func == V4L2_XFER_FUNC_DEFAULT) in tpg_recalc()
1791 tpg->real_xfer_func = in tpg_recalc()
1792 V4L2_MAP_XFER_FUNC_DEFAULT(tpg->colorspace); in tpg_recalc()
1794 if (tpg->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) in tpg_recalc()
1795 tpg->real_ycbcr_enc = in tpg_recalc()
1796 V4L2_MAP_YCBCR_ENC_DEFAULT(tpg->colorspace); in tpg_recalc()
1798 if (tpg->quantization == V4L2_QUANTIZATION_DEFAULT) in tpg_recalc()
1799 tpg->real_quantization = in tpg_recalc()
1800 V4L2_MAP_QUANTIZATION_DEFAULT(!tpg->is_yuv, in tpg_recalc()
1801 tpg->colorspace, tpg->real_ycbcr_enc); in tpg_recalc()
1803 tpg_precalculate_colors(tpg); in tpg_recalc()
1805 if (tpg->recalc_square_border) { in tpg_recalc()
1806 tpg->recalc_square_border = false; in tpg_recalc()
1807 tpg_calculate_square_border(tpg); in tpg_recalc()
1809 if (tpg->recalc_lines) { in tpg_recalc()
1810 tpg->recalc_lines = false; in tpg_recalc()
1811 tpg_precalculate_line(tpg); in tpg_recalc()
1815 void tpg_calc_text_basep(struct tpg_data *tpg, in tpg_calc_text_basep() argument
1818 unsigned stride = tpg->bytesperline[p]; in tpg_calc_text_basep()
1819 unsigned h = tpg->buf_height; in tpg_calc_text_basep()
1821 tpg_recalc(tpg); in tpg_calc_text_basep()
1825 h /= tpg->vdownsampling[p]; in tpg_calc_text_basep()
1826 if (tpg->field == V4L2_FIELD_SEQ_TB) in tpg_calc_text_basep()
1828 else if (tpg->field == V4L2_FIELD_SEQ_BT) in tpg_calc_text_basep()
1830 if (p == 0 && tpg->interleaved) in tpg_calc_text_basep()
1831 tpg_calc_text_basep(tpg, basep, 1, vbuf); in tpg_calc_text_basep()
1834 static int tpg_pattern_avg(const struct tpg_data *tpg, in tpg_pattern_avg() argument
1837 unsigned pat_lines = tpg_get_pat_lines(tpg); in tpg_pattern_avg()
1846 void tpg_log_status(struct tpg_data *tpg) in tpg_log_status() argument
1849 tpg->src_width, tpg->src_height, in tpg_log_status()
1850 tpg->is_yuv ? "YCbCr" : "RGB"); in tpg_log_status()
1851 pr_info("tpg field: %u\n", tpg->field); in tpg_log_status()
1852 pr_info("tpg crop: %ux%u@%dx%d\n", tpg->crop.width, tpg->crop.height, in tpg_log_status()
1853 tpg->crop.left, tpg->crop.top); in tpg_log_status()
1854 pr_info("tpg compose: %ux%u@%dx%d\n", tpg->compose.width, tpg->compose.height, in tpg_log_status()
1855 tpg->compose.left, tpg->compose.top); in tpg_log_status()
1856 pr_info("tpg colorspace: %d\n", tpg->colorspace); in tpg_log_status()
1857 pr_info("tpg transfer function: %d/%d\n", tpg->xfer_func, tpg->real_xfer_func); in tpg_log_status()
1858 pr_info("tpg Y'CbCr encoding: %d/%d\n", tpg->ycbcr_enc, tpg->real_ycbcr_enc); in tpg_log_status()
1859 pr_info("tpg quantization: %d/%d\n", tpg->quantization, tpg->real_quantization); in tpg_log_status()
1860 pr_info("tpg RGB range: %d/%d\n", tpg->rgb_range, tpg->real_rgb_range); in tpg_log_status()
1892 static void tpg_fill_params_pattern(const struct tpg_data *tpg, unsigned p, in tpg_fill_params_pattern() argument
1896 tpg_hscale_div(tpg, p, tpg->mv_hor_count % tpg->src_width); in tpg_fill_params_pattern()
1898 tpg_hscale_div(tpg, p, (tpg->mv_hor_count + tpg->mv_hor_step) % in tpg_fill_params_pattern()
1899 tpg->src_width); in tpg_fill_params_pattern()
1900 params->mv_vert_old = tpg->mv_vert_count % tpg->src_height; in tpg_fill_params_pattern()
1902 (tpg->mv_vert_count + tpg->mv_vert_step) % tpg->src_height; in tpg_fill_params_pattern()
1905 static void tpg_fill_params_extras(const struct tpg_data *tpg, in tpg_fill_params_extras() argument
1912 params->wss_width = tpg->crop.left < tpg->src_width / 2 ? in tpg_fill_params_extras()
1913 tpg->src_width / 2 - tpg->crop.left : 0; in tpg_fill_params_extras()
1914 if (params->wss_width > tpg->crop.width) in tpg_fill_params_extras()
1915 params->wss_width = tpg->crop.width; in tpg_fill_params_extras()
1916 params->wss_width = tpg_hscale_div(tpg, p, params->wss_width); in tpg_fill_params_extras()
1918 params->twopixsize * prandom_u32_max(tpg->src_width / 2); in tpg_fill_params_extras()
1920 if (tpg->crop.left < tpg->border.left) { in tpg_fill_params_extras()
1921 left_pillar_width = tpg->border.left - tpg->crop.left; in tpg_fill_params_extras()
1922 if (left_pillar_width > tpg->crop.width) in tpg_fill_params_extras()
1923 left_pillar_width = tpg->crop.width; in tpg_fill_params_extras()
1924 left_pillar_width = tpg_hscale_div(tpg, p, left_pillar_width); in tpg_fill_params_extras()
1928 if (tpg->crop.left + tpg->crop.width > in tpg_fill_params_extras()
1929 tpg->border.left + tpg->border.width) { in tpg_fill_params_extras()
1931 tpg->border.left + tpg->border.width - tpg->crop.left; in tpg_fill_params_extras()
1933 tpg_hscale_div(tpg, p, right_pillar_start); in tpg_fill_params_extras()
1939 params->sav_eav_f = tpg->field == in tpg_fill_params_extras()
1943 static void tpg_fill_plane_extras(const struct tpg_data *tpg, in tpg_fill_plane_extras() argument
1950 const struct v4l2_rect *sq = &tpg->square; in tpg_fill_plane_extras()
1951 const struct v4l2_rect *b = &tpg->border; in tpg_fill_plane_extras()
1952 const struct v4l2_rect *c = &tpg->crop; in tpg_fill_plane_extras()
1960 u8 *wss = tpg->random_line[p] + params->wss_random_offset; in tpg_fill_plane_extras()
1965 if (tpg->show_border && frame_line >= b->top && in tpg_fill_plane_extras()
1973 memcpy(vbuf + left, tpg->contrast_line[p], in tpg_fill_plane_extras()
1979 tpg->contrast_line[p], twopixsize); in tpg_fill_plane_extras()
1983 tpg->contrast_line[p], twopixsize); in tpg_fill_plane_extras()
1986 if (tpg->qual != TPG_QUAL_NOISE && frame_line >= b->top && in tpg_fill_plane_extras()
1988 memcpy(vbuf, tpg->black_line[p], params->left_pillar_width); in tpg_fill_plane_extras()
1989 memcpy(vbuf + params->right_pillar_start, tpg->black_line[p], in tpg_fill_plane_extras()
1992 if (tpg->show_square && frame_line >= sq->top && in tpg_fill_plane_extras()
2006 left = tpg_hscale_div(tpg, p, left); in tpg_fill_plane_extras()
2007 width = tpg_hscale_div(tpg, p, width); in tpg_fill_plane_extras()
2008 memcpy(vbuf + left, tpg->contrast_line[p], width); in tpg_fill_plane_extras()
2010 if (tpg->insert_sav) { in tpg_fill_plane_extras()
2011 unsigned offset = tpg_hdiv(tpg, p, tpg->compose.width / 3); in tpg_fill_plane_extras()
2025 if (tpg->insert_eav) { in tpg_fill_plane_extras()
2026 unsigned offset = tpg_hdiv(tpg, p, tpg->compose.width * 2 / 3); in tpg_fill_plane_extras()
2042 static void tpg_fill_plane_pattern(const struct tpg_data *tpg, in tpg_fill_plane_pattern() argument
2054 unsigned line_offset = tpg_hscale_div(tpg, p, tpg->crop.left); in tpg_fill_plane_pattern()
2067 if (params->hmax == tpg->compose.height) in tpg_fill_plane_pattern()
2069 if (!tpg->perc_fill_blank) in tpg_fill_plane_pattern()
2074 if (tpg->vflip) { in tpg_fill_plane_pattern()
2075 frame_line = tpg->src_height - frame_line - 1; in tpg_fill_plane_pattern()
2076 frame_line_next = tpg->src_height - frame_line_next - 1; in tpg_fill_plane_pattern()
2080 linestart_older = tpg->contrast_line[p]; in tpg_fill_plane_pattern()
2081 linestart_newer = tpg->contrast_line[p]; in tpg_fill_plane_pattern()
2082 } else if (tpg->qual != TPG_QUAL_NOISE && in tpg_fill_plane_pattern()
2083 (frame_line < tpg->border.top || in tpg_fill_plane_pattern()
2084 frame_line >= tpg->border.top + tpg->border.height)) { in tpg_fill_plane_pattern()
2085 linestart_older = tpg->black_line[p]; in tpg_fill_plane_pattern()
2086 linestart_newer = tpg->black_line[p]; in tpg_fill_plane_pattern()
2087 } else if (tpg->pattern == TPG_PAT_NOISE || tpg->qual == TPG_QUAL_NOISE) { in tpg_fill_plane_pattern()
2088 linestart_older = tpg->random_line[p] + in tpg_fill_plane_pattern()
2089 twopixsize * prandom_u32_max(tpg->src_width / 2); in tpg_fill_plane_pattern()
2090 linestart_newer = tpg->random_line[p] + in tpg_fill_plane_pattern()
2091 twopixsize * prandom_u32_max(tpg->src_width / 2); in tpg_fill_plane_pattern()
2094 (frame_line + mv_vert_old) % tpg->src_height; in tpg_fill_plane_pattern()
2096 (frame_line + mv_vert_new) % tpg->src_height; in tpg_fill_plane_pattern()
2100 pat_line_old = tpg_get_pat_line(tpg, frame_line_old); in tpg_fill_plane_pattern()
2101 pat_line_new = tpg_get_pat_line(tpg, frame_line_new); in tpg_fill_plane_pattern()
2102 linestart_older = tpg->lines[pat_line_old][p] + mv_hor_old; in tpg_fill_plane_pattern()
2103 linestart_newer = tpg->lines[pat_line_new][p] + mv_hor_new; in tpg_fill_plane_pattern()
2105 if (tpg->vdownsampling[p] > 1 && frame_line != frame_line_next) { in tpg_fill_plane_pattern()
2112 pat_line_next_old = tpg_get_pat_line(tpg, in tpg_fill_plane_pattern()
2113 (frame_line_next + mv_vert_old) % tpg->src_height); in tpg_fill_plane_pattern()
2114 pat_line_next_new = tpg_get_pat_line(tpg, in tpg_fill_plane_pattern()
2115 (frame_line_next + mv_vert_new) % tpg->src_height); in tpg_fill_plane_pattern()
2117 switch (tpg->field) { in tpg_fill_plane_pattern()
2121 avg_pat = tpg_pattern_avg(tpg, pat_line_old, pat_line_new); in tpg_fill_plane_pattern()
2124 linestart_older = tpg->downsampled_lines[avg_pat][p] + mv_hor_old; in tpg_fill_plane_pattern()
2132 avg_pat = tpg_pattern_avg(tpg, pat_line_old, pat_line_next_old); in tpg_fill_plane_pattern()
2134 linestart_older = tpg->downsampled_lines[avg_pat][p] + in tpg_fill_plane_pattern()
2136 avg_pat = tpg_pattern_avg(tpg, pat_line_new, pat_line_next_new); in tpg_fill_plane_pattern()
2138 linestart_newer = tpg->downsampled_lines[avg_pat][p] + in tpg_fill_plane_pattern()
2146 if (tpg->field_alternate) { in tpg_fill_plane_pattern()
2156 switch (tpg->field) { in tpg_fill_plane_pattern()
2185 void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std, in tpg_fill_plane_buffer() argument
2189 unsigned factor = V4L2_FIELD_HAS_T_OR_B(tpg->field) ? 2 : 1; in tpg_fill_plane_buffer()
2192 unsigned int_part = (tpg->crop.height / factor) / tpg->compose.height; in tpg_fill_plane_buffer()
2193 unsigned fract_part = (tpg->crop.height / factor) % tpg->compose.height; in tpg_fill_plane_buffer()
2198 tpg_recalc(tpg); in tpg_fill_plane_buffer()
2202 params.twopixsize = tpg->twopixelsize[p]; in tpg_fill_plane_buffer()
2203 params.img_width = tpg_hdiv(tpg, p, tpg->compose.width); in tpg_fill_plane_buffer()
2204 params.stride = tpg->bytesperline[p]; in tpg_fill_plane_buffer()
2205 params.hmax = (tpg->compose.height * tpg->perc_fill) / 100; in tpg_fill_plane_buffer()
2207 tpg_fill_params_pattern(tpg, p, &params); in tpg_fill_plane_buffer()
2208 tpg_fill_params_extras(tpg, p, &params); in tpg_fill_plane_buffer()
2210 vbuf += tpg_hdiv(tpg, p, tpg->compose.left); in tpg_fill_plane_buffer()
2212 for (h = 0; h < tpg->compose.height; h++) { in tpg_fill_plane_buffer()
2215 params.frame_line = tpg_calc_frameline(tpg, src_y, tpg->field); in tpg_fill_plane_buffer()
2217 buf_line = tpg_calc_buffer_line(tpg, h, tpg->field); in tpg_fill_plane_buffer()
2220 if (error >= tpg->compose.height) { in tpg_fill_plane_buffer()
2221 error -= tpg->compose.height; in tpg_fill_plane_buffer()
2229 if (tpg_g_interleaved(tpg)) in tpg_fill_plane_buffer()
2230 p = tpg_g_interleaved_plane(tpg, buf_line); in tpg_fill_plane_buffer()
2232 if (tpg->vdownsampling[p] > 1) { in tpg_fill_plane_buffer()
2241 if (tpg->field == V4L2_FIELD_SEQ_BT || in tpg_fill_plane_buffer()
2242 tpg->field == V4L2_FIELD_SEQ_TB) { in tpg_fill_plane_buffer()
2248 if (error + fract_part >= tpg->compose.height) in tpg_fill_plane_buffer()
2251 tpg_calc_frameline(tpg, next_src_y, tpg->field); in tpg_fill_plane_buffer()
2256 tpg_calc_frameline(tpg, src_y, tpg->field); in tpg_fill_plane_buffer()
2259 buf_line /= tpg->vdownsampling[p]; in tpg_fill_plane_buffer()
2261 tpg_fill_plane_pattern(tpg, &params, p, h, in tpg_fill_plane_buffer()
2263 tpg_fill_plane_extras(tpg, &params, p, h, in tpg_fill_plane_buffer()
2268 void tpg_fillbuffer(struct tpg_data *tpg, v4l2_std_id std, unsigned p, u8 *vbuf) in tpg_fillbuffer() argument
2273 if (tpg->buffers > 1) { in tpg_fillbuffer()
2274 tpg_fill_plane_buffer(tpg, std, p, vbuf); in tpg_fillbuffer()
2278 for (i = 0; i < tpg_g_planes(tpg); i++) { in tpg_fillbuffer()
2279 tpg_fill_plane_buffer(tpg, std, i, vbuf + offset); in tpg_fillbuffer()
2280 offset += tpg_calc_plane_size(tpg, i); in tpg_fillbuffer()