1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * v4l2-tpg.h - Test Pattern Generator
4 *
5 * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
6 */
7
8 #ifndef _V4L2_TPG_H_
9 #define _V4L2_TPG_H_
10
11 #include <linux/videodev2.h>
12
13 #include <stdbool.h>
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <string.h>
17 #include <errno.h>
18
19 typedef __u32 u32;
20 typedef __u16 u16;
21 typedef __s16 s16;
22 typedef __u8 u8;
23 typedef __s8 s8;
24
25 #ifndef __packed
26 #define __packed __attribute__((packed))
27 #endif
28 #define pr_info printf
29 #define noinline
30
31 #define tpg_min(a,b) ((a) < (b) ? (a) : (b))
32 #define tpg_max(a,b) ((a) > (b) ? (a) : (b))
33 #define min3(x, y, z) tpg_min((typeof(x))tpg_min(x, y), z)
34 #define max3(x, y, z) tpg_max((typeof(x))tpg_max(x, y), z)
35 #define array_size(a, b) ((a) * (b))
36 #define array3_size(a, b, c) ((a) * (b) * (c))
37
vfree(void * p)38 static inline void vfree(void *p)
39 {
40 free(p);
41 }
42
vzalloc(unsigned long size)43 static inline void *vzalloc(unsigned long size)
44 {
45 return calloc(1, size);
46 }
47
48 #define clamp(val, min, max) ({ \
49 typeof(val) __val = (val); \
50 typeof(min) __min = (min); \
51 typeof(max) __max = (max); \
52 (void) (&__val == &__min); \
53 (void) (&__val == &__max); \
54 __val = __val < __min ? __min: __val; \
55 __val > __max ? __max: __val; })
56
57 #define clamp_t(type, val, min, max) clamp((type)val, (type)min, (type)max)
58
get_random_u32_below(u32 ep_ro)59 static inline u32 get_random_u32_below(u32 ep_ro)
60 {
61 return rand() % ep_ro;
62 }
63
get_random_u8(void)64 static inline u32 get_random_u8(void)
65 {
66 return get_random_u32_below(256);
67 }
68
69
70 struct tpg_rbg_color8 {
71 unsigned char r, g, b;
72 };
73
74 struct tpg_rbg_color16 {
75 __u16 r, g, b;
76 };
77
78 enum tpg_color {
79 TPG_COLOR_CSC_WHITE,
80 TPG_COLOR_CSC_YELLOW,
81 TPG_COLOR_CSC_CYAN,
82 TPG_COLOR_CSC_GREEN,
83 TPG_COLOR_CSC_MAGENTA,
84 TPG_COLOR_CSC_RED,
85 TPG_COLOR_CSC_BLUE,
86 TPG_COLOR_CSC_BLACK,
87 TPG_COLOR_75_YELLOW,
88 TPG_COLOR_75_CYAN,
89 TPG_COLOR_75_GREEN,
90 TPG_COLOR_75_MAGENTA,
91 TPG_COLOR_75_RED,
92 TPG_COLOR_75_BLUE,
93 TPG_COLOR_100_WHITE,
94 TPG_COLOR_100_YELLOW,
95 TPG_COLOR_100_CYAN,
96 TPG_COLOR_100_GREEN,
97 TPG_COLOR_100_MAGENTA,
98 TPG_COLOR_100_RED,
99 TPG_COLOR_100_BLUE,
100 TPG_COLOR_100_BLACK,
101 TPG_COLOR_TEXTFG,
102 TPG_COLOR_TEXTBG,
103 TPG_COLOR_RANDOM,
104 TPG_COLOR_RAMP,
105 TPG_COLOR_MAX = TPG_COLOR_RAMP + 256
106 };
107
108 extern const struct tpg_rbg_color8 tpg_colors[TPG_COLOR_MAX];
109 extern const unsigned short tpg_rec709_to_linear[255 * 16 + 1];
110 extern const unsigned short tpg_linear_to_rec709[255 * 16 + 1];
111 extern const struct tpg_rbg_color16 tpg_csc_colors[V4L2_COLORSPACE_DCI_P3 + 1]
112 [V4L2_XFER_FUNC_SMPTE2084 + 1]
113 [TPG_COLOR_CSC_BLACK + 1];
114 enum tpg_pattern {
115 TPG_PAT_75_COLORBAR,
116 TPG_PAT_100_COLORBAR,
117 TPG_PAT_CSC_COLORBAR,
118 TPG_PAT_100_HCOLORBAR,
119 TPG_PAT_100_COLORSQUARES,
120 TPG_PAT_BLACK,
121 TPG_PAT_WHITE,
122 TPG_PAT_RED,
123 TPG_PAT_GREEN,
124 TPG_PAT_BLUE,
125 TPG_PAT_CHECKERS_16X16,
126 TPG_PAT_CHECKERS_2X2,
127 TPG_PAT_CHECKERS_1X1,
128 TPG_PAT_COLOR_CHECKERS_2X2,
129 TPG_PAT_COLOR_CHECKERS_1X1,
130 TPG_PAT_ALTERNATING_HLINES,
131 TPG_PAT_ALTERNATING_VLINES,
132 TPG_PAT_CROSS_1_PIXEL,
133 TPG_PAT_CROSS_2_PIXELS,
134 TPG_PAT_CROSS_10_PIXELS,
135 TPG_PAT_GRAY_RAMP,
136
137 /* Must be the last pattern */
138 TPG_PAT_NOISE,
139 };
140
141 extern const char * const tpg_pattern_strings[];
142
143 enum tpg_quality {
144 TPG_QUAL_COLOR,
145 TPG_QUAL_GRAY,
146 TPG_QUAL_NOISE
147 };
148
149 enum tpg_video_aspect {
150 TPG_VIDEO_ASPECT_IMAGE,
151 TPG_VIDEO_ASPECT_4X3,
152 TPG_VIDEO_ASPECT_14X9_CENTRE,
153 TPG_VIDEO_ASPECT_16X9_CENTRE,
154 TPG_VIDEO_ASPECT_16X9_ANAMORPHIC,
155 };
156
157 enum tpg_pixel_aspect {
158 TPG_PIXEL_ASPECT_SQUARE,
159 TPG_PIXEL_ASPECT_NTSC,
160 TPG_PIXEL_ASPECT_PAL,
161 };
162
163 enum tpg_move_mode {
164 TPG_MOVE_NEG_FAST,
165 TPG_MOVE_NEG,
166 TPG_MOVE_NEG_SLOW,
167 TPG_MOVE_NONE,
168 TPG_MOVE_POS_SLOW,
169 TPG_MOVE_POS,
170 TPG_MOVE_POS_FAST,
171 };
172
173 enum tgp_color_enc {
174 TGP_COLOR_ENC_RGB,
175 TGP_COLOR_ENC_YCBCR,
176 TGP_COLOR_ENC_HSV,
177 TGP_COLOR_ENC_LUMA,
178 };
179
180 extern const char * const tpg_aspect_strings[];
181
182 #define TPG_MAX_PLANES 3
183 #define TPG_MAX_PAT_LINES 8
184
185 struct tpg_data {
186 /* Source frame size */
187 unsigned src_width, src_height;
188 /* Buffer height */
189 unsigned buf_height;
190 /* Scaled output frame size */
191 unsigned scaled_width;
192 u32 field;
193 bool field_alternate;
194 /* crop coordinates are frame-based */
195 struct v4l2_rect crop;
196 /* compose coordinates are format-based */
197 struct v4l2_rect compose;
198 /* border and square coordinates are frame-based */
199 struct v4l2_rect border;
200 struct v4l2_rect square;
201
202 /* Color-related fields */
203 enum tpg_quality qual;
204 unsigned qual_offset;
205 u8 alpha_component;
206 bool alpha_red_only;
207 u8 brightness;
208 u8 contrast;
209 u8 saturation;
210 s16 hue;
211 u32 fourcc;
212 enum tgp_color_enc color_enc;
213 u32 colorspace;
214 u32 xfer_func;
215 u32 ycbcr_enc;
216 u32 hsv_enc;
217 /*
218 * Stores the actual transfer function, i.e. will never be
219 * V4L2_XFER_FUNC_DEFAULT.
220 */
221 u32 real_xfer_func;
222 /*
223 * Stores the actual Y'CbCr encoding, i.e. will never be
224 * V4L2_YCBCR_ENC_DEFAULT.
225 */
226 u32 real_hsv_enc;
227 u32 real_ycbcr_enc;
228 u32 quantization;
229 /*
230 * Stores the actual quantization, i.e. will never be
231 * V4L2_QUANTIZATION_DEFAULT.
232 */
233 u32 real_quantization;
234 enum tpg_video_aspect vid_aspect;
235 enum tpg_pixel_aspect pix_aspect;
236 unsigned rgb_range;
237 unsigned real_rgb_range;
238 unsigned buffers;
239 unsigned planes;
240 bool interleaved;
241 u8 vdownsampling[TPG_MAX_PLANES];
242 u8 hdownsampling[TPG_MAX_PLANES];
243 /*
244 * horizontal positions must be ANDed with this value to enforce
245 * correct boundaries for packed YUYV values.
246 */
247 unsigned hmask[TPG_MAX_PLANES];
248 /* Used to store the colors in native format, either RGB or YUV */
249 u8 colors[TPG_COLOR_MAX][3];
250 u8 textfg[TPG_MAX_PLANES][8], textbg[TPG_MAX_PLANES][8];
251 /* size in bytes for two pixels in each plane */
252 unsigned twopixelsize[TPG_MAX_PLANES];
253 unsigned bytesperline[TPG_MAX_PLANES];
254
255 /* Configuration */
256 enum tpg_pattern pattern;
257 bool hflip;
258 bool vflip;
259 unsigned perc_fill;
260 bool perc_fill_blank;
261 bool show_border;
262 bool show_square;
263 bool insert_sav;
264 bool insert_eav;
265 bool insert_hdmi_video_guard_band;
266
267 /* Test pattern movement */
268 enum tpg_move_mode mv_hor_mode;
269 int mv_hor_count;
270 int mv_hor_step;
271 enum tpg_move_mode mv_vert_mode;
272 int mv_vert_count;
273 int mv_vert_step;
274
275 bool recalc_colors;
276 bool recalc_lines;
277 bool recalc_square_border;
278
279 /* Used to store TPG_MAX_PAT_LINES lines, each with up to two planes */
280 unsigned max_line_width;
281 u8 *lines[TPG_MAX_PAT_LINES][TPG_MAX_PLANES];
282 u8 *downsampled_lines[TPG_MAX_PAT_LINES][TPG_MAX_PLANES];
283 u8 *random_line[TPG_MAX_PLANES];
284 u8 *contrast_line[TPG_MAX_PLANES];
285 u8 *black_line[TPG_MAX_PLANES];
286 };
287
288 void tpg_init(struct tpg_data *tpg, unsigned w, unsigned h);
289 int tpg_alloc(struct tpg_data *tpg, unsigned max_w);
290 void tpg_free(struct tpg_data *tpg);
291 void tpg_reset_source(struct tpg_data *tpg, unsigned width, unsigned height,
292 u32 field);
293 void tpg_log_status(struct tpg_data *tpg);
294
295 void tpg_set_font(const u8 *f);
296 void tpg_gen_text(const struct tpg_data *tpg,
297 u8 *basep[TPG_MAX_PLANES][2], int y, int x, const char *text);
298 void tpg_calc_text_basep(struct tpg_data *tpg,
299 u8 *basep[TPG_MAX_PLANES][2], unsigned p, u8 *vbuf);
300 unsigned tpg_g_interleaved_plane(const struct tpg_data *tpg, unsigned buf_line);
301 void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std,
302 unsigned p, u8 *vbuf);
303 void tpg_fillbuffer(struct tpg_data *tpg, v4l2_std_id std,
304 unsigned p, u8 *vbuf);
305 bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc);
306 void tpg_s_crop_compose(struct tpg_data *tpg, const struct v4l2_rect *crop,
307 const struct v4l2_rect *compose);
308 const char *tpg_g_color_order(const struct tpg_data *tpg);
309
tpg_s_pattern(struct tpg_data * tpg,enum tpg_pattern pattern)310 static inline void tpg_s_pattern(struct tpg_data *tpg, enum tpg_pattern pattern)
311 {
312 if (tpg->pattern == pattern)
313 return;
314 tpg->pattern = pattern;
315 tpg->recalc_colors = true;
316 }
317
tpg_s_quality(struct tpg_data * tpg,enum tpg_quality qual,unsigned qual_offset)318 static inline void tpg_s_quality(struct tpg_data *tpg,
319 enum tpg_quality qual, unsigned qual_offset)
320 {
321 if (tpg->qual == qual && tpg->qual_offset == qual_offset)
322 return;
323 tpg->qual = qual;
324 tpg->qual_offset = qual_offset;
325 tpg->recalc_colors = true;
326 }
327
tpg_g_quality(const struct tpg_data * tpg)328 static inline enum tpg_quality tpg_g_quality(const struct tpg_data *tpg)
329 {
330 return tpg->qual;
331 }
332
tpg_s_alpha_component(struct tpg_data * tpg,u8 alpha_component)333 static inline void tpg_s_alpha_component(struct tpg_data *tpg,
334 u8 alpha_component)
335 {
336 if (tpg->alpha_component == alpha_component)
337 return;
338 tpg->alpha_component = alpha_component;
339 tpg->recalc_colors = true;
340 }
341
tpg_s_alpha_mode(struct tpg_data * tpg,bool red_only)342 static inline void tpg_s_alpha_mode(struct tpg_data *tpg,
343 bool red_only)
344 {
345 if (tpg->alpha_red_only == red_only)
346 return;
347 tpg->alpha_red_only = red_only;
348 tpg->recalc_colors = true;
349 }
350
tpg_s_brightness(struct tpg_data * tpg,u8 brightness)351 static inline void tpg_s_brightness(struct tpg_data *tpg,
352 u8 brightness)
353 {
354 if (tpg->brightness == brightness)
355 return;
356 tpg->brightness = brightness;
357 tpg->recalc_colors = true;
358 }
359
tpg_s_contrast(struct tpg_data * tpg,u8 contrast)360 static inline void tpg_s_contrast(struct tpg_data *tpg,
361 u8 contrast)
362 {
363 if (tpg->contrast == contrast)
364 return;
365 tpg->contrast = contrast;
366 tpg->recalc_colors = true;
367 }
368
tpg_s_saturation(struct tpg_data * tpg,u8 saturation)369 static inline void tpg_s_saturation(struct tpg_data *tpg,
370 u8 saturation)
371 {
372 if (tpg->saturation == saturation)
373 return;
374 tpg->saturation = saturation;
375 tpg->recalc_colors = true;
376 }
377
tpg_s_hue(struct tpg_data * tpg,s16 hue)378 static inline void tpg_s_hue(struct tpg_data *tpg,
379 s16 hue)
380 {
381 hue = clamp_t(s16, hue, -128, 128);
382 if (tpg->hue == hue)
383 return;
384 tpg->hue = hue;
385 tpg->recalc_colors = true;
386 }
387
tpg_s_rgb_range(struct tpg_data * tpg,unsigned rgb_range)388 static inline void tpg_s_rgb_range(struct tpg_data *tpg,
389 unsigned rgb_range)
390 {
391 if (tpg->rgb_range == rgb_range)
392 return;
393 tpg->rgb_range = rgb_range;
394 tpg->recalc_colors = true;
395 }
396
tpg_s_real_rgb_range(struct tpg_data * tpg,unsigned rgb_range)397 static inline void tpg_s_real_rgb_range(struct tpg_data *tpg,
398 unsigned rgb_range)
399 {
400 if (tpg->real_rgb_range == rgb_range)
401 return;
402 tpg->real_rgb_range = rgb_range;
403 tpg->recalc_colors = true;
404 }
405
tpg_s_colorspace(struct tpg_data * tpg,u32 colorspace)406 static inline void tpg_s_colorspace(struct tpg_data *tpg, u32 colorspace)
407 {
408 if (tpg->colorspace == colorspace)
409 return;
410 tpg->colorspace = colorspace;
411 tpg->recalc_colors = true;
412 }
413
tpg_g_colorspace(const struct tpg_data * tpg)414 static inline u32 tpg_g_colorspace(const struct tpg_data *tpg)
415 {
416 return tpg->colorspace;
417 }
418
tpg_s_ycbcr_enc(struct tpg_data * tpg,u32 ycbcr_enc)419 static inline void tpg_s_ycbcr_enc(struct tpg_data *tpg, u32 ycbcr_enc)
420 {
421 if (tpg->ycbcr_enc == ycbcr_enc)
422 return;
423 tpg->ycbcr_enc = ycbcr_enc;
424 tpg->recalc_colors = true;
425 }
426
tpg_g_ycbcr_enc(const struct tpg_data * tpg)427 static inline u32 tpg_g_ycbcr_enc(const struct tpg_data *tpg)
428 {
429 return tpg->ycbcr_enc;
430 }
431
tpg_s_hsv_enc(struct tpg_data * tpg,u32 hsv_enc)432 static inline void tpg_s_hsv_enc(struct tpg_data *tpg, u32 hsv_enc)
433 {
434 if (tpg->hsv_enc == hsv_enc)
435 return;
436 tpg->hsv_enc = hsv_enc;
437 tpg->recalc_colors = true;
438 }
439
tpg_g_hsv_enc(const struct tpg_data * tpg)440 static inline u32 tpg_g_hsv_enc(const struct tpg_data *tpg)
441 {
442 return tpg->hsv_enc;
443 }
444
tpg_s_xfer_func(struct tpg_data * tpg,u32 xfer_func)445 static inline void tpg_s_xfer_func(struct tpg_data *tpg, u32 xfer_func)
446 {
447 if (tpg->xfer_func == xfer_func)
448 return;
449 tpg->xfer_func = xfer_func;
450 tpg->recalc_colors = true;
451 }
452
tpg_g_xfer_func(const struct tpg_data * tpg)453 static inline u32 tpg_g_xfer_func(const struct tpg_data *tpg)
454 {
455 return tpg->xfer_func;
456 }
457
tpg_s_quantization(struct tpg_data * tpg,u32 quantization)458 static inline void tpg_s_quantization(struct tpg_data *tpg, u32 quantization)
459 {
460 if (tpg->quantization == quantization)
461 return;
462 tpg->quantization = quantization;
463 tpg->recalc_colors = true;
464 }
465
tpg_g_quantization(const struct tpg_data * tpg)466 static inline u32 tpg_g_quantization(const struct tpg_data *tpg)
467 {
468 return tpg->quantization;
469 }
470
tpg_g_buffers(const struct tpg_data * tpg)471 static inline unsigned tpg_g_buffers(const struct tpg_data *tpg)
472 {
473 return tpg->buffers;
474 }
475
tpg_g_planes(const struct tpg_data * tpg)476 static inline unsigned tpg_g_planes(const struct tpg_data *tpg)
477 {
478 return tpg->interleaved ? 1 : tpg->planes;
479 }
480
tpg_g_interleaved(const struct tpg_data * tpg)481 static inline bool tpg_g_interleaved(const struct tpg_data *tpg)
482 {
483 return tpg->interleaved;
484 }
485
tpg_g_twopixelsize(const struct tpg_data * tpg,unsigned plane)486 static inline unsigned tpg_g_twopixelsize(const struct tpg_data *tpg, unsigned plane)
487 {
488 return tpg->twopixelsize[plane];
489 }
490
tpg_hdiv(const struct tpg_data * tpg,unsigned plane,unsigned x)491 static inline unsigned tpg_hdiv(const struct tpg_data *tpg,
492 unsigned plane, unsigned x)
493 {
494 return ((x / tpg->hdownsampling[plane]) & tpg->hmask[plane]) *
495 tpg->twopixelsize[plane] / 2;
496 }
497
tpg_hscale(const struct tpg_data * tpg,unsigned x)498 static inline unsigned tpg_hscale(const struct tpg_data *tpg, unsigned x)
499 {
500 return (x * tpg->scaled_width) / tpg->src_width;
501 }
502
tpg_hscale_div(const struct tpg_data * tpg,unsigned plane,unsigned x)503 static inline unsigned tpg_hscale_div(const struct tpg_data *tpg,
504 unsigned plane, unsigned x)
505 {
506 return tpg_hdiv(tpg, plane, tpg_hscale(tpg, x));
507 }
508
tpg_g_bytesperline(const struct tpg_data * tpg,unsigned plane)509 static inline unsigned tpg_g_bytesperline(const struct tpg_data *tpg, unsigned plane)
510 {
511 return tpg->bytesperline[plane];
512 }
513
tpg_s_bytesperline(struct tpg_data * tpg,unsigned plane,unsigned bpl)514 static inline void tpg_s_bytesperline(struct tpg_data *tpg, unsigned plane, unsigned bpl)
515 {
516 unsigned p;
517
518 if (tpg->buffers > 1) {
519 tpg->bytesperline[plane] = bpl;
520 return;
521 }
522
523 for (p = 0; p < tpg_g_planes(tpg); p++) {
524 unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0];
525
526 tpg->bytesperline[p] = plane_w / tpg->hdownsampling[p];
527 }
528 if (tpg_g_interleaved(tpg))
529 tpg->bytesperline[1] = tpg->bytesperline[0];
530 }
531
532
tpg_g_line_width(const struct tpg_data * tpg,unsigned plane)533 static inline unsigned tpg_g_line_width(const struct tpg_data *tpg, unsigned plane)
534 {
535 unsigned w = 0;
536 unsigned p;
537
538 if (tpg->buffers > 1)
539 return tpg_g_bytesperline(tpg, plane);
540 for (p = 0; p < tpg_g_planes(tpg); p++) {
541 unsigned plane_w = tpg_g_bytesperline(tpg, p);
542
543 w += plane_w / tpg->vdownsampling[p];
544 }
545 return w;
546 }
547
tpg_calc_line_width(const struct tpg_data * tpg,unsigned plane,unsigned bpl)548 static inline unsigned tpg_calc_line_width(const struct tpg_data *tpg,
549 unsigned plane, unsigned bpl)
550 {
551 unsigned w = 0;
552 unsigned p;
553
554 if (tpg->buffers > 1)
555 return bpl;
556 for (p = 0; p < tpg_g_planes(tpg); p++) {
557 unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0];
558
559 plane_w /= tpg->hdownsampling[p];
560 w += plane_w / tpg->vdownsampling[p];
561 }
562 return w;
563 }
564
tpg_calc_plane_size(const struct tpg_data * tpg,unsigned plane)565 static inline unsigned tpg_calc_plane_size(const struct tpg_data *tpg, unsigned plane)
566 {
567 if (plane >= tpg_g_planes(tpg))
568 return 0;
569
570 return tpg_g_bytesperline(tpg, plane) * tpg->buf_height /
571 tpg->vdownsampling[plane];
572 }
573
tpg_s_buf_height(struct tpg_data * tpg,unsigned h)574 static inline void tpg_s_buf_height(struct tpg_data *tpg, unsigned h)
575 {
576 tpg->buf_height = h;
577 }
578
tpg_s_field(struct tpg_data * tpg,unsigned field,bool alternate)579 static inline void tpg_s_field(struct tpg_data *tpg, unsigned field, bool alternate)
580 {
581 tpg->field = field;
582 tpg->field_alternate = alternate;
583 }
584
tpg_s_perc_fill(struct tpg_data * tpg,unsigned perc_fill)585 static inline void tpg_s_perc_fill(struct tpg_data *tpg,
586 unsigned perc_fill)
587 {
588 tpg->perc_fill = perc_fill;
589 }
590
tpg_g_perc_fill(const struct tpg_data * tpg)591 static inline unsigned tpg_g_perc_fill(const struct tpg_data *tpg)
592 {
593 return tpg->perc_fill;
594 }
595
tpg_s_perc_fill_blank(struct tpg_data * tpg,bool perc_fill_blank)596 static inline void tpg_s_perc_fill_blank(struct tpg_data *tpg,
597 bool perc_fill_blank)
598 {
599 tpg->perc_fill_blank = perc_fill_blank;
600 }
601
tpg_s_video_aspect(struct tpg_data * tpg,enum tpg_video_aspect vid_aspect)602 static inline void tpg_s_video_aspect(struct tpg_data *tpg,
603 enum tpg_video_aspect vid_aspect)
604 {
605 if (tpg->vid_aspect == vid_aspect)
606 return;
607 tpg->vid_aspect = vid_aspect;
608 tpg->recalc_square_border = true;
609 }
610
tpg_g_video_aspect(const struct tpg_data * tpg)611 static inline enum tpg_video_aspect tpg_g_video_aspect(const struct tpg_data *tpg)
612 {
613 return tpg->vid_aspect;
614 }
615
tpg_s_pixel_aspect(struct tpg_data * tpg,enum tpg_pixel_aspect pix_aspect)616 static inline void tpg_s_pixel_aspect(struct tpg_data *tpg,
617 enum tpg_pixel_aspect pix_aspect)
618 {
619 if (tpg->pix_aspect == pix_aspect)
620 return;
621 tpg->pix_aspect = pix_aspect;
622 tpg->recalc_square_border = true;
623 }
624
tpg_s_show_border(struct tpg_data * tpg,bool show_border)625 static inline void tpg_s_show_border(struct tpg_data *tpg,
626 bool show_border)
627 {
628 tpg->show_border = show_border;
629 }
630
tpg_s_show_square(struct tpg_data * tpg,bool show_square)631 static inline void tpg_s_show_square(struct tpg_data *tpg,
632 bool show_square)
633 {
634 tpg->show_square = show_square;
635 }
636
tpg_s_insert_sav(struct tpg_data * tpg,bool insert_sav)637 static inline void tpg_s_insert_sav(struct tpg_data *tpg, bool insert_sav)
638 {
639 tpg->insert_sav = insert_sav;
640 }
641
tpg_s_insert_eav(struct tpg_data * tpg,bool insert_eav)642 static inline void tpg_s_insert_eav(struct tpg_data *tpg, bool insert_eav)
643 {
644 tpg->insert_eav = insert_eav;
645 }
646
647 /*
648 * This inserts 4 pixels of the RGB color 0xab55ab at the left hand side of the
649 * image. This is only done for 3 or 4 byte RGB pixel formats. This pixel value
650 * equals the Video Guard Band value as defined by HDMI (see section 5.2.2.1
651 * in the HDMI 1.3 Specification) that preceeds the first actual pixel. If the
652 * HDMI receiver doesn't handle this correctly, then it might keep skipping
653 * these Video Guard Band patterns and end up with a shorter video line. So this
654 * is a nice pattern to test with.
655 */
tpg_s_insert_hdmi_video_guard_band(struct tpg_data * tpg,bool insert_hdmi_video_guard_band)656 static inline void tpg_s_insert_hdmi_video_guard_band(struct tpg_data *tpg,
657 bool insert_hdmi_video_guard_band)
658 {
659 tpg->insert_hdmi_video_guard_band = insert_hdmi_video_guard_band;
660 }
661
662 void tpg_update_mv_step(struct tpg_data *tpg);
663
tpg_s_mv_hor_mode(struct tpg_data * tpg,enum tpg_move_mode mv_hor_mode)664 static inline void tpg_s_mv_hor_mode(struct tpg_data *tpg,
665 enum tpg_move_mode mv_hor_mode)
666 {
667 tpg->mv_hor_mode = mv_hor_mode;
668 tpg_update_mv_step(tpg);
669 }
670
tpg_s_mv_vert_mode(struct tpg_data * tpg,enum tpg_move_mode mv_vert_mode)671 static inline void tpg_s_mv_vert_mode(struct tpg_data *tpg,
672 enum tpg_move_mode mv_vert_mode)
673 {
674 tpg->mv_vert_mode = mv_vert_mode;
675 tpg_update_mv_step(tpg);
676 }
677
tpg_init_mv_count(struct tpg_data * tpg)678 static inline void tpg_init_mv_count(struct tpg_data *tpg)
679 {
680 tpg->mv_hor_count = tpg->mv_vert_count = 0;
681 }
682
tpg_update_mv_count(struct tpg_data * tpg,bool frame_is_field)683 static inline void tpg_update_mv_count(struct tpg_data *tpg, bool frame_is_field)
684 {
685 tpg->mv_hor_count += tpg->mv_hor_step * (frame_is_field ? 1 : 2);
686 tpg->mv_vert_count += tpg->mv_vert_step * (frame_is_field ? 1 : 2);
687 }
688
tpg_s_hflip(struct tpg_data * tpg,bool hflip)689 static inline void tpg_s_hflip(struct tpg_data *tpg, bool hflip)
690 {
691 if (tpg->hflip == hflip)
692 return;
693 tpg->hflip = hflip;
694 tpg_update_mv_step(tpg);
695 tpg->recalc_lines = true;
696 }
697
tpg_g_hflip(const struct tpg_data * tpg)698 static inline bool tpg_g_hflip(const struct tpg_data *tpg)
699 {
700 return tpg->hflip;
701 }
702
tpg_s_vflip(struct tpg_data * tpg,bool vflip)703 static inline void tpg_s_vflip(struct tpg_data *tpg, bool vflip)
704 {
705 tpg->vflip = vflip;
706 }
707
tpg_g_vflip(const struct tpg_data * tpg)708 static inline bool tpg_g_vflip(const struct tpg_data *tpg)
709 {
710 return tpg->vflip;
711 }
712
tpg_pattern_is_static(const struct tpg_data * tpg)713 static inline bool tpg_pattern_is_static(const struct tpg_data *tpg)
714 {
715 return tpg->pattern != TPG_PAT_NOISE &&
716 tpg->mv_hor_mode == TPG_MOVE_NONE &&
717 tpg->mv_vert_mode == TPG_MOVE_NONE;
718 }
719
720 #endif
721