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