blob: 181dcbe777f396b6fd1235a9ec8cd7e79af576a4 [file] [log] [blame]
Hans Verkuilab15d242018-02-07 09:05:46 -05001/* SPDX-License-Identifier: GPL-2.0-only */
Hans Verkuil63881df2014-08-25 08:02:14 -03002/*
Helen Mae Koike Fornaziere07d46e2016-04-08 17:28:58 -03003 * v4l2-tpg.h - Test Pattern Generator
Hans Verkuil63881df2014-08-25 08:02:14 -03004 *
5 * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
Hans Verkuil63881df2014-08-25 08:02:14 -03006 */
7
Helen Mae Koike Fornaziere07d46e2016-04-08 17:28:58 -03008#ifndef _V4L2_TPG_H_
9#define _V4L2_TPG_H_
Hans Verkuil63881df2014-08-25 08:02:14 -030010
Hans Verkuil63881df2014-08-25 08:02:14 -030011#include <linux/types.h>
12#include <linux/errno.h>
13#include <linux/random.h>
14#include <linux/slab.h>
Hans Verkuil5754d0d2014-09-03 04:29:00 -030015#include <linux/vmalloc.h>
Hans Verkuil63881df2014-08-25 08:02:14 -030016#include <linux/videodev2.h>
Hans Verkuil63881df2014-08-25 08:02:14 -030017
Mauro Carvalho Chehabb29fd562017-10-09 06:10:28 -040018struct tpg_rbg_color8 {
Mauro Carvalho Chehab1beb6232017-10-09 06:02:25 -040019 unsigned char r, g, b;
20};
21
Mauro Carvalho Chehabb29fd562017-10-09 06:10:28 -040022struct tpg_rbg_color16 {
Mauro Carvalho Chehab43feabd2017-10-09 06:20:48 -040023 __u16 r, g, b;
Mauro Carvalho Chehab1beb6232017-10-09 06:02:25 -040024};
25
26enum tpg_color {
27 TPG_COLOR_CSC_WHITE,
28 TPG_COLOR_CSC_YELLOW,
29 TPG_COLOR_CSC_CYAN,
30 TPG_COLOR_CSC_GREEN,
31 TPG_COLOR_CSC_MAGENTA,
32 TPG_COLOR_CSC_RED,
33 TPG_COLOR_CSC_BLUE,
34 TPG_COLOR_CSC_BLACK,
35 TPG_COLOR_75_YELLOW,
36 TPG_COLOR_75_CYAN,
37 TPG_COLOR_75_GREEN,
38 TPG_COLOR_75_MAGENTA,
39 TPG_COLOR_75_RED,
40 TPG_COLOR_75_BLUE,
41 TPG_COLOR_100_WHITE,
42 TPG_COLOR_100_YELLOW,
43 TPG_COLOR_100_CYAN,
44 TPG_COLOR_100_GREEN,
45 TPG_COLOR_100_MAGENTA,
46 TPG_COLOR_100_RED,
47 TPG_COLOR_100_BLUE,
48 TPG_COLOR_100_BLACK,
49 TPG_COLOR_TEXTFG,
50 TPG_COLOR_TEXTBG,
51 TPG_COLOR_RANDOM,
52 TPG_COLOR_RAMP,
53 TPG_COLOR_MAX = TPG_COLOR_RAMP + 256
54};
55
Mauro Carvalho Chehabb29fd562017-10-09 06:10:28 -040056extern const struct tpg_rbg_color8 tpg_colors[TPG_COLOR_MAX];
Mauro Carvalho Chehab1beb6232017-10-09 06:02:25 -040057extern const unsigned short tpg_rec709_to_linear[255 * 16 + 1];
58extern const unsigned short tpg_linear_to_rec709[255 * 16 + 1];
Mauro Carvalho Chehabb29fd562017-10-09 06:10:28 -040059extern const struct tpg_rbg_color16 tpg_csc_colors[V4L2_COLORSPACE_DCI_P3 + 1]
Mauro Carvalho Chehab1beb6232017-10-09 06:02:25 -040060 [V4L2_XFER_FUNC_SMPTE2084 + 1]
61 [TPG_COLOR_CSC_BLACK + 1];
Hans Verkuil63881df2014-08-25 08:02:14 -030062enum tpg_pattern {
63 TPG_PAT_75_COLORBAR,
64 TPG_PAT_100_COLORBAR,
65 TPG_PAT_CSC_COLORBAR,
66 TPG_PAT_100_HCOLORBAR,
67 TPG_PAT_100_COLORSQUARES,
68 TPG_PAT_BLACK,
69 TPG_PAT_WHITE,
70 TPG_PAT_RED,
71 TPG_PAT_GREEN,
72 TPG_PAT_BLUE,
73 TPG_PAT_CHECKERS_16X16,
Hans Verkuil1a05d312015-03-07 12:49:57 -030074 TPG_PAT_CHECKERS_2X2,
Hans Verkuil63881df2014-08-25 08:02:14 -030075 TPG_PAT_CHECKERS_1X1,
Hans Verkuil1a05d312015-03-07 12:49:57 -030076 TPG_PAT_COLOR_CHECKERS_2X2,
77 TPG_PAT_COLOR_CHECKERS_1X1,
Hans Verkuil63881df2014-08-25 08:02:14 -030078 TPG_PAT_ALTERNATING_HLINES,
79 TPG_PAT_ALTERNATING_VLINES,
80 TPG_PAT_CROSS_1_PIXEL,
81 TPG_PAT_CROSS_2_PIXELS,
82 TPG_PAT_CROSS_10_PIXELS,
83 TPG_PAT_GRAY_RAMP,
84
85 /* Must be the last pattern */
86 TPG_PAT_NOISE,
87};
88
89extern const char * const tpg_pattern_strings[];
90
91enum tpg_quality {
92 TPG_QUAL_COLOR,
93 TPG_QUAL_GRAY,
94 TPG_QUAL_NOISE
95};
96
97enum tpg_video_aspect {
98 TPG_VIDEO_ASPECT_IMAGE,
99 TPG_VIDEO_ASPECT_4X3,
100 TPG_VIDEO_ASPECT_14X9_CENTRE,
101 TPG_VIDEO_ASPECT_16X9_CENTRE,
102 TPG_VIDEO_ASPECT_16X9_ANAMORPHIC,
103};
104
105enum tpg_pixel_aspect {
106 TPG_PIXEL_ASPECT_SQUARE,
107 TPG_PIXEL_ASPECT_NTSC,
108 TPG_PIXEL_ASPECT_PAL,
109};
110
111enum tpg_move_mode {
112 TPG_MOVE_NEG_FAST,
113 TPG_MOVE_NEG,
114 TPG_MOVE_NEG_SLOW,
115 TPG_MOVE_NONE,
116 TPG_MOVE_POS_SLOW,
117 TPG_MOVE_POS,
118 TPG_MOVE_POS_FAST,
119};
120
Ricardo Ribalda Delgado646895e2016-07-15 06:09:47 -0300121enum tgp_color_enc {
122 TGP_COLOR_ENC_RGB,
123 TGP_COLOR_ENC_YCBCR,
Ricardo Ribalda Delgado54fb1532016-07-15 10:20:08 -0300124 TGP_COLOR_ENC_HSV,
Ricardo Ribalda Delgadoca2b32d2016-07-16 05:58:09 -0300125 TGP_COLOR_ENC_LUMA,
Ricardo Ribalda Delgado646895e2016-07-15 06:09:47 -0300126};
127
Hans Verkuil63881df2014-08-25 08:02:14 -0300128extern const char * const tpg_aspect_strings[];
129
Hans Verkuilba01f672015-03-07 13:57:27 -0300130#define TPG_MAX_PLANES 3
Hans Verkuil63881df2014-08-25 08:02:14 -0300131#define TPG_MAX_PAT_LINES 8
132
133struct tpg_data {
134 /* Source frame size */
135 unsigned src_width, src_height;
136 /* Buffer height */
137 unsigned buf_height;
138 /* Scaled output frame size */
139 unsigned scaled_width;
140 u32 field;
Hans Verkuil43047f62015-03-07 12:38:42 -0300141 bool field_alternate;
Hans Verkuil63881df2014-08-25 08:02:14 -0300142 /* crop coordinates are frame-based */
143 struct v4l2_rect crop;
144 /* compose coordinates are format-based */
145 struct v4l2_rect compose;
146 /* border and square coordinates are frame-based */
147 struct v4l2_rect border;
148 struct v4l2_rect square;
149
150 /* Color-related fields */
151 enum tpg_quality qual;
152 unsigned qual_offset;
153 u8 alpha_component;
154 bool alpha_red_only;
155 u8 brightness;
156 u8 contrast;
157 u8 saturation;
158 s16 hue;
159 u32 fourcc;
Ricardo Ribalda Delgado646895e2016-07-15 06:09:47 -0300160 enum tgp_color_enc color_enc;
Hans Verkuil63881df2014-08-25 08:02:14 -0300161 u32 colorspace;
Hans Verkuilca5316d2015-04-28 09:41:37 -0300162 u32 xfer_func;
Hans Verkuil481b97a2014-11-17 10:14:32 -0300163 u32 ycbcr_enc;
Ricardo Ribalda Delgado429175e2016-07-18 09:16:15 -0300164 u32 hsv_enc;
Hans Verkuil481b97a2014-11-17 10:14:32 -0300165 /*
Hans Verkuilca5316d2015-04-28 09:41:37 -0300166 * Stores the actual transfer function, i.e. will never be
167 * V4L2_XFER_FUNC_DEFAULT.
168 */
169 u32 real_xfer_func;
170 /*
Hans Verkuil481b97a2014-11-17 10:14:32 -0300171 * Stores the actual Y'CbCr encoding, i.e. will never be
172 * V4L2_YCBCR_ENC_DEFAULT.
173 */
Ricardo Ribalda Delgado429175e2016-07-18 09:16:15 -0300174 u32 real_hsv_enc;
Hans Verkuil481b97a2014-11-17 10:14:32 -0300175 u32 real_ycbcr_enc;
176 u32 quantization;
177 /*
178 * Stores the actual quantization, i.e. will never be
179 * V4L2_QUANTIZATION_DEFAULT.
180 */
181 u32 real_quantization;
Hans Verkuil63881df2014-08-25 08:02:14 -0300182 enum tpg_video_aspect vid_aspect;
183 enum tpg_pixel_aspect pix_aspect;
184 unsigned rgb_range;
185 unsigned real_rgb_range;
Hans Verkuil06d1f0c2015-03-07 13:01:53 -0300186 unsigned buffers;
Hans Verkuil63881df2014-08-25 08:02:14 -0300187 unsigned planes;
Hans Verkuil02aa7692015-03-14 08:01:50 -0300188 bool interleaved;
Hans Verkuilba01f672015-03-07 13:57:27 -0300189 u8 vdownsampling[TPG_MAX_PLANES];
190 u8 hdownsampling[TPG_MAX_PLANES];
Hans Verkuil9991def2015-03-08 05:53:10 -0300191 /*
192 * horizontal positions must be ANDed with this value to enforce
193 * correct boundaries for packed YUYV values.
194 */
195 unsigned hmask[TPG_MAX_PLANES];
Hans Verkuil63881df2014-08-25 08:02:14 -0300196 /* Used to store the colors in native format, either RGB or YUV */
197 u8 colors[TPG_COLOR_MAX][3];
198 u8 textfg[TPG_MAX_PLANES][8], textbg[TPG_MAX_PLANES][8];
199 /* size in bytes for two pixels in each plane */
200 unsigned twopixelsize[TPG_MAX_PLANES];
201 unsigned bytesperline[TPG_MAX_PLANES];
202
203 /* Configuration */
204 enum tpg_pattern pattern;
205 bool hflip;
206 bool vflip;
207 unsigned perc_fill;
208 bool perc_fill_blank;
209 bool show_border;
210 bool show_square;
211 bool insert_sav;
212 bool insert_eav;
213
214 /* Test pattern movement */
215 enum tpg_move_mode mv_hor_mode;
216 int mv_hor_count;
217 int mv_hor_step;
218 enum tpg_move_mode mv_vert_mode;
219 int mv_vert_count;
220 int mv_vert_step;
221
222 bool recalc_colors;
223 bool recalc_lines;
224 bool recalc_square_border;
225
226 /* Used to store TPG_MAX_PAT_LINES lines, each with up to two planes */
227 unsigned max_line_width;
228 u8 *lines[TPG_MAX_PAT_LINES][TPG_MAX_PLANES];
Hans Verkuil5d7c5392015-03-07 14:06:43 -0300229 u8 *downsampled_lines[TPG_MAX_PAT_LINES][TPG_MAX_PLANES];
Hans Verkuil63881df2014-08-25 08:02:14 -0300230 u8 *random_line[TPG_MAX_PLANES];
231 u8 *contrast_line[TPG_MAX_PLANES];
232 u8 *black_line[TPG_MAX_PLANES];
233};
234
235void tpg_init(struct tpg_data *tpg, unsigned w, unsigned h);
236int tpg_alloc(struct tpg_data *tpg, unsigned max_w);
237void tpg_free(struct tpg_data *tpg);
238void tpg_reset_source(struct tpg_data *tpg, unsigned width, unsigned height,
239 u32 field);
Hans Verkuil84b76d72015-04-24 11:16:22 -0300240void tpg_log_status(struct tpg_data *tpg);
Hans Verkuil63881df2014-08-25 08:02:14 -0300241
242void tpg_set_font(const u8 *f);
Hans Verkuildfff0482015-03-09 11:04:02 -0300243void tpg_gen_text(const struct tpg_data *tpg,
Kaaira Gupta9dc75e72020-07-05 15:53:04 +0200244 u8 *basep[TPG_MAX_PLANES][2], int y, int x, const char *text);
Hans Verkuil63881df2014-08-25 08:02:14 -0300245void tpg_calc_text_basep(struct tpg_data *tpg,
246 u8 *basep[TPG_MAX_PLANES][2], unsigned p, u8 *vbuf);
Hans Verkuil02aa7692015-03-14 08:01:50 -0300247unsigned tpg_g_interleaved_plane(const struct tpg_data *tpg, unsigned buf_line);
Hans Verkuildfff0482015-03-09 11:04:02 -0300248void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std,
249 unsigned p, u8 *vbuf);
250void tpg_fillbuffer(struct tpg_data *tpg, v4l2_std_id std,
251 unsigned p, u8 *vbuf);
Hans Verkuil63881df2014-08-25 08:02:14 -0300252bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc);
253void tpg_s_crop_compose(struct tpg_data *tpg, const struct v4l2_rect *crop,
254 const struct v4l2_rect *compose);
Kaaira Gupta7a785082020-07-05 15:53:05 +0200255const char *tpg_g_color_order(const struct tpg_data *tpg);
Hans Verkuil63881df2014-08-25 08:02:14 -0300256
257static inline void tpg_s_pattern(struct tpg_data *tpg, enum tpg_pattern pattern)
258{
259 if (tpg->pattern == pattern)
260 return;
261 tpg->pattern = pattern;
262 tpg->recalc_colors = true;
263}
264
265static inline void tpg_s_quality(struct tpg_data *tpg,
266 enum tpg_quality qual, unsigned qual_offset)
267{
268 if (tpg->qual == qual && tpg->qual_offset == qual_offset)
269 return;
270 tpg->qual = qual;
271 tpg->qual_offset = qual_offset;
272 tpg->recalc_colors = true;
273}
274
275static inline enum tpg_quality tpg_g_quality(const struct tpg_data *tpg)
276{
277 return tpg->qual;
278}
279
280static inline void tpg_s_alpha_component(struct tpg_data *tpg,
281 u8 alpha_component)
282{
283 if (tpg->alpha_component == alpha_component)
284 return;
285 tpg->alpha_component = alpha_component;
286 tpg->recalc_colors = true;
287}
288
289static inline void tpg_s_alpha_mode(struct tpg_data *tpg,
290 bool red_only)
291{
292 if (tpg->alpha_red_only == red_only)
293 return;
294 tpg->alpha_red_only = red_only;
295 tpg->recalc_colors = true;
296}
297
298static inline void tpg_s_brightness(struct tpg_data *tpg,
299 u8 brightness)
300{
301 if (tpg->brightness == brightness)
302 return;
303 tpg->brightness = brightness;
304 tpg->recalc_colors = true;
305}
306
307static inline void tpg_s_contrast(struct tpg_data *tpg,
308 u8 contrast)
309{
310 if (tpg->contrast == contrast)
311 return;
312 tpg->contrast = contrast;
313 tpg->recalc_colors = true;
314}
315
316static inline void tpg_s_saturation(struct tpg_data *tpg,
317 u8 saturation)
318{
319 if (tpg->saturation == saturation)
320 return;
321 tpg->saturation = saturation;
322 tpg->recalc_colors = true;
323}
324
325static inline void tpg_s_hue(struct tpg_data *tpg,
326 s16 hue)
327{
Peilin Ye45c20442020-08-21 17:13:43 +0200328 hue = clamp_t(s16, hue, -128, 128);
Hans Verkuil63881df2014-08-25 08:02:14 -0300329 if (tpg->hue == hue)
330 return;
331 tpg->hue = hue;
332 tpg->recalc_colors = true;
333}
334
335static inline void tpg_s_rgb_range(struct tpg_data *tpg,
336 unsigned rgb_range)
337{
338 if (tpg->rgb_range == rgb_range)
339 return;
340 tpg->rgb_range = rgb_range;
341 tpg->recalc_colors = true;
342}
343
344static inline void tpg_s_real_rgb_range(struct tpg_data *tpg,
345 unsigned rgb_range)
346{
347 if (tpg->real_rgb_range == rgb_range)
348 return;
349 tpg->real_rgb_range = rgb_range;
350 tpg->recalc_colors = true;
351}
352
353static inline void tpg_s_colorspace(struct tpg_data *tpg, u32 colorspace)
354{
355 if (tpg->colorspace == colorspace)
356 return;
357 tpg->colorspace = colorspace;
358 tpg->recalc_colors = true;
359}
360
361static inline u32 tpg_g_colorspace(const struct tpg_data *tpg)
362{
363 return tpg->colorspace;
364}
365
Hans Verkuil481b97a2014-11-17 10:14:32 -0300366static inline void tpg_s_ycbcr_enc(struct tpg_data *tpg, u32 ycbcr_enc)
367{
368 if (tpg->ycbcr_enc == ycbcr_enc)
369 return;
370 tpg->ycbcr_enc = ycbcr_enc;
371 tpg->recalc_colors = true;
372}
373
374static inline u32 tpg_g_ycbcr_enc(const struct tpg_data *tpg)
375{
376 return tpg->ycbcr_enc;
377}
378
Ricardo Ribalda Delgado429175e2016-07-18 09:16:15 -0300379static inline void tpg_s_hsv_enc(struct tpg_data *tpg, u32 hsv_enc)
380{
381 if (tpg->hsv_enc == hsv_enc)
382 return;
383 tpg->hsv_enc = hsv_enc;
384 tpg->recalc_colors = true;
385}
386
387static inline u32 tpg_g_hsv_enc(const struct tpg_data *tpg)
388{
389 return tpg->hsv_enc;
390}
391
Hans Verkuilca5316d2015-04-28 09:41:37 -0300392static inline void tpg_s_xfer_func(struct tpg_data *tpg, u32 xfer_func)
393{
394 if (tpg->xfer_func == xfer_func)
395 return;
396 tpg->xfer_func = xfer_func;
397 tpg->recalc_colors = true;
398}
399
400static inline u32 tpg_g_xfer_func(const struct tpg_data *tpg)
401{
402 return tpg->xfer_func;
403}
404
Hans Verkuil481b97a2014-11-17 10:14:32 -0300405static inline void tpg_s_quantization(struct tpg_data *tpg, u32 quantization)
406{
407 if (tpg->quantization == quantization)
408 return;
409 tpg->quantization = quantization;
410 tpg->recalc_colors = true;
411}
412
413static inline u32 tpg_g_quantization(const struct tpg_data *tpg)
414{
415 return tpg->quantization;
416}
417
Hans Verkuil06d1f0c2015-03-07 13:01:53 -0300418static inline unsigned tpg_g_buffers(const struct tpg_data *tpg)
419{
420 return tpg->buffers;
421}
422
Hans Verkuil63881df2014-08-25 08:02:14 -0300423static inline unsigned tpg_g_planes(const struct tpg_data *tpg)
424{
Hans Verkuil02aa7692015-03-14 08:01:50 -0300425 return tpg->interleaved ? 1 : tpg->planes;
426}
427
428static inline bool tpg_g_interleaved(const struct tpg_data *tpg)
429{
430 return tpg->interleaved;
Hans Verkuil63881df2014-08-25 08:02:14 -0300431}
432
433static inline unsigned tpg_g_twopixelsize(const struct tpg_data *tpg, unsigned plane)
434{
435 return tpg->twopixelsize[plane];
436}
437
Hans Verkuil9991def2015-03-08 05:53:10 -0300438static inline unsigned tpg_hdiv(const struct tpg_data *tpg,
439 unsigned plane, unsigned x)
440{
441 return ((x / tpg->hdownsampling[plane]) & tpg->hmask[plane]) *
442 tpg->twopixelsize[plane] / 2;
443}
444
445static inline unsigned tpg_hscale(const struct tpg_data *tpg, unsigned x)
446{
447 return (x * tpg->scaled_width) / tpg->src_width;
448}
449
450static inline unsigned tpg_hscale_div(const struct tpg_data *tpg,
451 unsigned plane, unsigned x)
452{
453 return tpg_hdiv(tpg, plane, tpg_hscale(tpg, x));
454}
455
Hans Verkuil63881df2014-08-25 08:02:14 -0300456static inline unsigned tpg_g_bytesperline(const struct tpg_data *tpg, unsigned plane)
457{
458 return tpg->bytesperline[plane];
459}
460
461static inline void tpg_s_bytesperline(struct tpg_data *tpg, unsigned plane, unsigned bpl)
462{
Hans Verkuil4db22042015-03-07 13:39:01 -0300463 unsigned p;
464
465 if (tpg->buffers > 1) {
466 tpg->bytesperline[plane] = bpl;
467 return;
468 }
469
Hans Verkuil02aa7692015-03-14 08:01:50 -0300470 for (p = 0; p < tpg_g_planes(tpg); p++) {
Hans Verkuil4db22042015-03-07 13:39:01 -0300471 unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0];
472
Hans Verkuilba01f672015-03-07 13:57:27 -0300473 tpg->bytesperline[p] = plane_w / tpg->hdownsampling[p];
Hans Verkuil4db22042015-03-07 13:39:01 -0300474 }
Hans Verkuil3541e342016-01-22 13:13:25 -0200475 if (tpg_g_interleaved(tpg))
476 tpg->bytesperline[1] = tpg->bytesperline[0];
Hans Verkuil4db22042015-03-07 13:39:01 -0300477}
478
Hans Verkuilba01f672015-03-07 13:57:27 -0300479
Hans Verkuil4db22042015-03-07 13:39:01 -0300480static inline unsigned tpg_g_line_width(const struct tpg_data *tpg, unsigned plane)
481{
482 unsigned w = 0;
483 unsigned p;
484
485 if (tpg->buffers > 1)
486 return tpg_g_bytesperline(tpg, plane);
Hans Verkuil02aa7692015-03-14 08:01:50 -0300487 for (p = 0; p < tpg_g_planes(tpg); p++) {
Hans Verkuil4db22042015-03-07 13:39:01 -0300488 unsigned plane_w = tpg_g_bytesperline(tpg, p);
489
Hans Verkuilba01f672015-03-07 13:57:27 -0300490 w += plane_w / tpg->vdownsampling[p];
Hans Verkuil4db22042015-03-07 13:39:01 -0300491 }
492 return w;
493}
494
495static inline unsigned tpg_calc_line_width(const struct tpg_data *tpg,
496 unsigned plane, unsigned bpl)
497{
498 unsigned w = 0;
499 unsigned p;
500
501 if (tpg->buffers > 1)
502 return bpl;
Hans Verkuil02aa7692015-03-14 08:01:50 -0300503 for (p = 0; p < tpg_g_planes(tpg); p++) {
Hans Verkuil4db22042015-03-07 13:39:01 -0300504 unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0];
505
Hans Verkuilba01f672015-03-07 13:57:27 -0300506 plane_w /= tpg->hdownsampling[p];
507 w += plane_w / tpg->vdownsampling[p];
Hans Verkuil4db22042015-03-07 13:39:01 -0300508 }
509 return w;
510}
511
512static inline unsigned tpg_calc_plane_size(const struct tpg_data *tpg, unsigned plane)
513{
Hans Verkuil02aa7692015-03-14 08:01:50 -0300514 if (plane >= tpg_g_planes(tpg))
Hans Verkuil4db22042015-03-07 13:39:01 -0300515 return 0;
516
Hans Verkuilba01f672015-03-07 13:57:27 -0300517 return tpg_g_bytesperline(tpg, plane) * tpg->buf_height /
518 tpg->vdownsampling[plane];
Hans Verkuil63881df2014-08-25 08:02:14 -0300519}
520
521static inline void tpg_s_buf_height(struct tpg_data *tpg, unsigned h)
522{
523 tpg->buf_height = h;
524}
525
Hans Verkuil43047f62015-03-07 12:38:42 -0300526static inline void tpg_s_field(struct tpg_data *tpg, unsigned field, bool alternate)
Hans Verkuil63881df2014-08-25 08:02:14 -0300527{
528 tpg->field = field;
Hans Verkuil43047f62015-03-07 12:38:42 -0300529 tpg->field_alternate = alternate;
Hans Verkuil63881df2014-08-25 08:02:14 -0300530}
531
532static inline void tpg_s_perc_fill(struct tpg_data *tpg,
533 unsigned perc_fill)
534{
535 tpg->perc_fill = perc_fill;
536}
537
538static inline unsigned tpg_g_perc_fill(const struct tpg_data *tpg)
539{
540 return tpg->perc_fill;
541}
542
543static inline void tpg_s_perc_fill_blank(struct tpg_data *tpg,
544 bool perc_fill_blank)
545{
546 tpg->perc_fill_blank = perc_fill_blank;
547}
548
549static inline void tpg_s_video_aspect(struct tpg_data *tpg,
550 enum tpg_video_aspect vid_aspect)
551{
552 if (tpg->vid_aspect == vid_aspect)
553 return;
554 tpg->vid_aspect = vid_aspect;
555 tpg->recalc_square_border = true;
556}
557
558static inline enum tpg_video_aspect tpg_g_video_aspect(const struct tpg_data *tpg)
559{
560 return tpg->vid_aspect;
561}
562
563static inline void tpg_s_pixel_aspect(struct tpg_data *tpg,
564 enum tpg_pixel_aspect pix_aspect)
565{
566 if (tpg->pix_aspect == pix_aspect)
567 return;
568 tpg->pix_aspect = pix_aspect;
569 tpg->recalc_square_border = true;
570}
571
572static inline void tpg_s_show_border(struct tpg_data *tpg,
573 bool show_border)
574{
575 tpg->show_border = show_border;
576}
577
578static inline void tpg_s_show_square(struct tpg_data *tpg,
579 bool show_square)
580{
581 tpg->show_square = show_square;
582}
583
584static inline void tpg_s_insert_sav(struct tpg_data *tpg, bool insert_sav)
585{
586 tpg->insert_sav = insert_sav;
587}
588
589static inline void tpg_s_insert_eav(struct tpg_data *tpg, bool insert_eav)
590{
591 tpg->insert_eav = insert_eav;
592}
593
594void tpg_update_mv_step(struct tpg_data *tpg);
595
596static inline void tpg_s_mv_hor_mode(struct tpg_data *tpg,
597 enum tpg_move_mode mv_hor_mode)
598{
599 tpg->mv_hor_mode = mv_hor_mode;
600 tpg_update_mv_step(tpg);
601}
602
603static inline void tpg_s_mv_vert_mode(struct tpg_data *tpg,
604 enum tpg_move_mode mv_vert_mode)
605{
606 tpg->mv_vert_mode = mv_vert_mode;
607 tpg_update_mv_step(tpg);
608}
609
610static inline void tpg_init_mv_count(struct tpg_data *tpg)
611{
612 tpg->mv_hor_count = tpg->mv_vert_count = 0;
613}
614
615static inline void tpg_update_mv_count(struct tpg_data *tpg, bool frame_is_field)
616{
617 tpg->mv_hor_count += tpg->mv_hor_step * (frame_is_field ? 1 : 2);
618 tpg->mv_vert_count += tpg->mv_vert_step * (frame_is_field ? 1 : 2);
619}
620
621static inline void tpg_s_hflip(struct tpg_data *tpg, bool hflip)
622{
623 if (tpg->hflip == hflip)
624 return;
625 tpg->hflip = hflip;
626 tpg_update_mv_step(tpg);
627 tpg->recalc_lines = true;
628}
629
630static inline bool tpg_g_hflip(const struct tpg_data *tpg)
631{
632 return tpg->hflip;
633}
634
635static inline void tpg_s_vflip(struct tpg_data *tpg, bool vflip)
636{
637 tpg->vflip = vflip;
638}
639
640static inline bool tpg_g_vflip(const struct tpg_data *tpg)
641{
642 return tpg->vflip;
643}
644
645static inline bool tpg_pattern_is_static(const struct tpg_data *tpg)
646{
647 return tpg->pattern != TPG_PAT_NOISE &&
648 tpg->mv_hor_mode == TPG_MOVE_NONE &&
649 tpg->mv_vert_mode == TPG_MOVE_NONE;
650}
651
652#endif