]>
Commit | Line | Data |
---|---|---|
63881df9 HV |
1 | /* |
2 | * vivid-tpg.h - Test Pattern Generator | |
3 | * | |
4 | * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved. | |
5 | * | |
6 | * This program is free software; you may redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; version 2 of the License. | |
9 | * | |
10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
11 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
12 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
13 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
14 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
15 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
16 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
17 | * SOFTWARE. | |
18 | */ | |
19 | ||
20 | #ifndef _VIVID_TPG_H_ | |
21 | #define _VIVID_TPG_H_ | |
22 | ||
23 | #include <linux/version.h> | |
24 | #include <linux/types.h> | |
25 | #include <linux/errno.h> | |
26 | #include <linux/random.h> | |
27 | #include <linux/slab.h> | |
28 | #include <linux/videodev2.h> | |
29 | ||
30 | #include "vivid-tpg-colors.h" | |
31 | ||
32 | enum tpg_pattern { | |
33 | TPG_PAT_75_COLORBAR, | |
34 | TPG_PAT_100_COLORBAR, | |
35 | TPG_PAT_CSC_COLORBAR, | |
36 | TPG_PAT_100_HCOLORBAR, | |
37 | TPG_PAT_100_COLORSQUARES, | |
38 | TPG_PAT_BLACK, | |
39 | TPG_PAT_WHITE, | |
40 | TPG_PAT_RED, | |
41 | TPG_PAT_GREEN, | |
42 | TPG_PAT_BLUE, | |
43 | TPG_PAT_CHECKERS_16X16, | |
44 | TPG_PAT_CHECKERS_1X1, | |
45 | TPG_PAT_ALTERNATING_HLINES, | |
46 | TPG_PAT_ALTERNATING_VLINES, | |
47 | TPG_PAT_CROSS_1_PIXEL, | |
48 | TPG_PAT_CROSS_2_PIXELS, | |
49 | TPG_PAT_CROSS_10_PIXELS, | |
50 | TPG_PAT_GRAY_RAMP, | |
51 | ||
52 | /* Must be the last pattern */ | |
53 | TPG_PAT_NOISE, | |
54 | }; | |
55 | ||
56 | extern const char * const tpg_pattern_strings[]; | |
57 | ||
58 | enum tpg_quality { | |
59 | TPG_QUAL_COLOR, | |
60 | TPG_QUAL_GRAY, | |
61 | TPG_QUAL_NOISE | |
62 | }; | |
63 | ||
64 | enum tpg_video_aspect { | |
65 | TPG_VIDEO_ASPECT_IMAGE, | |
66 | TPG_VIDEO_ASPECT_4X3, | |
67 | TPG_VIDEO_ASPECT_14X9_CENTRE, | |
68 | TPG_VIDEO_ASPECT_16X9_CENTRE, | |
69 | TPG_VIDEO_ASPECT_16X9_ANAMORPHIC, | |
70 | }; | |
71 | ||
72 | enum tpg_pixel_aspect { | |
73 | TPG_PIXEL_ASPECT_SQUARE, | |
74 | TPG_PIXEL_ASPECT_NTSC, | |
75 | TPG_PIXEL_ASPECT_PAL, | |
76 | }; | |
77 | ||
78 | enum tpg_move_mode { | |
79 | TPG_MOVE_NEG_FAST, | |
80 | TPG_MOVE_NEG, | |
81 | TPG_MOVE_NEG_SLOW, | |
82 | TPG_MOVE_NONE, | |
83 | TPG_MOVE_POS_SLOW, | |
84 | TPG_MOVE_POS, | |
85 | TPG_MOVE_POS_FAST, | |
86 | }; | |
87 | ||
88 | extern const char * const tpg_aspect_strings[]; | |
89 | ||
90 | #define TPG_MAX_PLANES 2 | |
91 | #define TPG_MAX_PAT_LINES 8 | |
92 | ||
93 | struct tpg_data { | |
94 | /* Source frame size */ | |
95 | unsigned src_width, src_height; | |
96 | /* Buffer height */ | |
97 | unsigned buf_height; | |
98 | /* Scaled output frame size */ | |
99 | unsigned scaled_width; | |
100 | u32 field; | |
101 | /* crop coordinates are frame-based */ | |
102 | struct v4l2_rect crop; | |
103 | /* compose coordinates are format-based */ | |
104 | struct v4l2_rect compose; | |
105 | /* border and square coordinates are frame-based */ | |
106 | struct v4l2_rect border; | |
107 | struct v4l2_rect square; | |
108 | ||
109 | /* Color-related fields */ | |
110 | enum tpg_quality qual; | |
111 | unsigned qual_offset; | |
112 | u8 alpha_component; | |
113 | bool alpha_red_only; | |
114 | u8 brightness; | |
115 | u8 contrast; | |
116 | u8 saturation; | |
117 | s16 hue; | |
118 | u32 fourcc; | |
119 | bool is_yuv; | |
120 | u32 colorspace; | |
121 | enum tpg_video_aspect vid_aspect; | |
122 | enum tpg_pixel_aspect pix_aspect; | |
123 | unsigned rgb_range; | |
124 | unsigned real_rgb_range; | |
125 | unsigned planes; | |
126 | /* Used to store the colors in native format, either RGB or YUV */ | |
127 | u8 colors[TPG_COLOR_MAX][3]; | |
128 | u8 textfg[TPG_MAX_PLANES][8], textbg[TPG_MAX_PLANES][8]; | |
129 | /* size in bytes for two pixels in each plane */ | |
130 | unsigned twopixelsize[TPG_MAX_PLANES]; | |
131 | unsigned bytesperline[TPG_MAX_PLANES]; | |
132 | ||
133 | /* Configuration */ | |
134 | enum tpg_pattern pattern; | |
135 | bool hflip; | |
136 | bool vflip; | |
137 | unsigned perc_fill; | |
138 | bool perc_fill_blank; | |
139 | bool show_border; | |
140 | bool show_square; | |
141 | bool insert_sav; | |
142 | bool insert_eav; | |
143 | ||
144 | /* Test pattern movement */ | |
145 | enum tpg_move_mode mv_hor_mode; | |
146 | int mv_hor_count; | |
147 | int mv_hor_step; | |
148 | enum tpg_move_mode mv_vert_mode; | |
149 | int mv_vert_count; | |
150 | int mv_vert_step; | |
151 | ||
152 | bool recalc_colors; | |
153 | bool recalc_lines; | |
154 | bool recalc_square_border; | |
155 | ||
156 | /* Used to store TPG_MAX_PAT_LINES lines, each with up to two planes */ | |
157 | unsigned max_line_width; | |
158 | u8 *lines[TPG_MAX_PAT_LINES][TPG_MAX_PLANES]; | |
159 | u8 *random_line[TPG_MAX_PLANES]; | |
160 | u8 *contrast_line[TPG_MAX_PLANES]; | |
161 | u8 *black_line[TPG_MAX_PLANES]; | |
162 | }; | |
163 | ||
164 | void tpg_init(struct tpg_data *tpg, unsigned w, unsigned h); | |
165 | int tpg_alloc(struct tpg_data *tpg, unsigned max_w); | |
166 | void tpg_free(struct tpg_data *tpg); | |
167 | void tpg_reset_source(struct tpg_data *tpg, unsigned width, unsigned height, | |
168 | u32 field); | |
169 | ||
170 | void tpg_set_font(const u8 *f); | |
171 | void tpg_gen_text(struct tpg_data *tpg, | |
172 | u8 *basep[TPG_MAX_PLANES][2], int y, int x, char *text); | |
173 | void tpg_calc_text_basep(struct tpg_data *tpg, | |
174 | u8 *basep[TPG_MAX_PLANES][2], unsigned p, u8 *vbuf); | |
175 | void tpg_fillbuffer(struct tpg_data *tpg, v4l2_std_id std, unsigned p, u8 *vbuf); | |
176 | bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc); | |
177 | void tpg_s_crop_compose(struct tpg_data *tpg, const struct v4l2_rect *crop, | |
178 | const struct v4l2_rect *compose); | |
179 | ||
180 | static inline void tpg_s_pattern(struct tpg_data *tpg, enum tpg_pattern pattern) | |
181 | { | |
182 | if (tpg->pattern == pattern) | |
183 | return; | |
184 | tpg->pattern = pattern; | |
185 | tpg->recalc_colors = true; | |
186 | } | |
187 | ||
188 | static inline void tpg_s_quality(struct tpg_data *tpg, | |
189 | enum tpg_quality qual, unsigned qual_offset) | |
190 | { | |
191 | if (tpg->qual == qual && tpg->qual_offset == qual_offset) | |
192 | return; | |
193 | tpg->qual = qual; | |
194 | tpg->qual_offset = qual_offset; | |
195 | tpg->recalc_colors = true; | |
196 | } | |
197 | ||
198 | static inline enum tpg_quality tpg_g_quality(const struct tpg_data *tpg) | |
199 | { | |
200 | return tpg->qual; | |
201 | } | |
202 | ||
203 | static inline void tpg_s_alpha_component(struct tpg_data *tpg, | |
204 | u8 alpha_component) | |
205 | { | |
206 | if (tpg->alpha_component == alpha_component) | |
207 | return; | |
208 | tpg->alpha_component = alpha_component; | |
209 | tpg->recalc_colors = true; | |
210 | } | |
211 | ||
212 | static inline void tpg_s_alpha_mode(struct tpg_data *tpg, | |
213 | bool red_only) | |
214 | { | |
215 | if (tpg->alpha_red_only == red_only) | |
216 | return; | |
217 | tpg->alpha_red_only = red_only; | |
218 | tpg->recalc_colors = true; | |
219 | } | |
220 | ||
221 | static inline void tpg_s_brightness(struct tpg_data *tpg, | |
222 | u8 brightness) | |
223 | { | |
224 | if (tpg->brightness == brightness) | |
225 | return; | |
226 | tpg->brightness = brightness; | |
227 | tpg->recalc_colors = true; | |
228 | } | |
229 | ||
230 | static inline void tpg_s_contrast(struct tpg_data *tpg, | |
231 | u8 contrast) | |
232 | { | |
233 | if (tpg->contrast == contrast) | |
234 | return; | |
235 | tpg->contrast = contrast; | |
236 | tpg->recalc_colors = true; | |
237 | } | |
238 | ||
239 | static inline void tpg_s_saturation(struct tpg_data *tpg, | |
240 | u8 saturation) | |
241 | { | |
242 | if (tpg->saturation == saturation) | |
243 | return; | |
244 | tpg->saturation = saturation; | |
245 | tpg->recalc_colors = true; | |
246 | } | |
247 | ||
248 | static inline void tpg_s_hue(struct tpg_data *tpg, | |
249 | s16 hue) | |
250 | { | |
251 | if (tpg->hue == hue) | |
252 | return; | |
253 | tpg->hue = hue; | |
254 | tpg->recalc_colors = true; | |
255 | } | |
256 | ||
257 | static inline void tpg_s_rgb_range(struct tpg_data *tpg, | |
258 | unsigned rgb_range) | |
259 | { | |
260 | if (tpg->rgb_range == rgb_range) | |
261 | return; | |
262 | tpg->rgb_range = rgb_range; | |
263 | tpg->recalc_colors = true; | |
264 | } | |
265 | ||
266 | static inline void tpg_s_real_rgb_range(struct tpg_data *tpg, | |
267 | unsigned rgb_range) | |
268 | { | |
269 | if (tpg->real_rgb_range == rgb_range) | |
270 | return; | |
271 | tpg->real_rgb_range = rgb_range; | |
272 | tpg->recalc_colors = true; | |
273 | } | |
274 | ||
275 | static inline void tpg_s_colorspace(struct tpg_data *tpg, u32 colorspace) | |
276 | { | |
277 | if (tpg->colorspace == colorspace) | |
278 | return; | |
279 | tpg->colorspace = colorspace; | |
280 | tpg->recalc_colors = true; | |
281 | } | |
282 | ||
283 | static inline u32 tpg_g_colorspace(const struct tpg_data *tpg) | |
284 | { | |
285 | return tpg->colorspace; | |
286 | } | |
287 | ||
288 | static inline unsigned tpg_g_planes(const struct tpg_data *tpg) | |
289 | { | |
290 | return tpg->planes; | |
291 | } | |
292 | ||
293 | static inline unsigned tpg_g_twopixelsize(const struct tpg_data *tpg, unsigned plane) | |
294 | { | |
295 | return tpg->twopixelsize[plane]; | |
296 | } | |
297 | ||
298 | static inline unsigned tpg_g_bytesperline(const struct tpg_data *tpg, unsigned plane) | |
299 | { | |
300 | return tpg->bytesperline[plane]; | |
301 | } | |
302 | ||
303 | static inline void tpg_s_bytesperline(struct tpg_data *tpg, unsigned plane, unsigned bpl) | |
304 | { | |
305 | tpg->bytesperline[plane] = bpl; | |
306 | } | |
307 | ||
308 | static inline void tpg_s_buf_height(struct tpg_data *tpg, unsigned h) | |
309 | { | |
310 | tpg->buf_height = h; | |
311 | } | |
312 | ||
313 | static inline void tpg_s_field(struct tpg_data *tpg, unsigned field) | |
314 | { | |
315 | tpg->field = field; | |
316 | } | |
317 | ||
318 | static inline void tpg_s_perc_fill(struct tpg_data *tpg, | |
319 | unsigned perc_fill) | |
320 | { | |
321 | tpg->perc_fill = perc_fill; | |
322 | } | |
323 | ||
324 | static inline unsigned tpg_g_perc_fill(const struct tpg_data *tpg) | |
325 | { | |
326 | return tpg->perc_fill; | |
327 | } | |
328 | ||
329 | static inline void tpg_s_perc_fill_blank(struct tpg_data *tpg, | |
330 | bool perc_fill_blank) | |
331 | { | |
332 | tpg->perc_fill_blank = perc_fill_blank; | |
333 | } | |
334 | ||
335 | static inline void tpg_s_video_aspect(struct tpg_data *tpg, | |
336 | enum tpg_video_aspect vid_aspect) | |
337 | { | |
338 | if (tpg->vid_aspect == vid_aspect) | |
339 | return; | |
340 | tpg->vid_aspect = vid_aspect; | |
341 | tpg->recalc_square_border = true; | |
342 | } | |
343 | ||
344 | static inline enum tpg_video_aspect tpg_g_video_aspect(const struct tpg_data *tpg) | |
345 | { | |
346 | return tpg->vid_aspect; | |
347 | } | |
348 | ||
349 | static inline void tpg_s_pixel_aspect(struct tpg_data *tpg, | |
350 | enum tpg_pixel_aspect pix_aspect) | |
351 | { | |
352 | if (tpg->pix_aspect == pix_aspect) | |
353 | return; | |
354 | tpg->pix_aspect = pix_aspect; | |
355 | tpg->recalc_square_border = true; | |
356 | } | |
357 | ||
358 | static inline void tpg_s_show_border(struct tpg_data *tpg, | |
359 | bool show_border) | |
360 | { | |
361 | tpg->show_border = show_border; | |
362 | } | |
363 | ||
364 | static inline void tpg_s_show_square(struct tpg_data *tpg, | |
365 | bool show_square) | |
366 | { | |
367 | tpg->show_square = show_square; | |
368 | } | |
369 | ||
370 | static inline void tpg_s_insert_sav(struct tpg_data *tpg, bool insert_sav) | |
371 | { | |
372 | tpg->insert_sav = insert_sav; | |
373 | } | |
374 | ||
375 | static inline void tpg_s_insert_eav(struct tpg_data *tpg, bool insert_eav) | |
376 | { | |
377 | tpg->insert_eav = insert_eav; | |
378 | } | |
379 | ||
380 | void tpg_update_mv_step(struct tpg_data *tpg); | |
381 | ||
382 | static inline void tpg_s_mv_hor_mode(struct tpg_data *tpg, | |
383 | enum tpg_move_mode mv_hor_mode) | |
384 | { | |
385 | tpg->mv_hor_mode = mv_hor_mode; | |
386 | tpg_update_mv_step(tpg); | |
387 | } | |
388 | ||
389 | static inline void tpg_s_mv_vert_mode(struct tpg_data *tpg, | |
390 | enum tpg_move_mode mv_vert_mode) | |
391 | { | |
392 | tpg->mv_vert_mode = mv_vert_mode; | |
393 | tpg_update_mv_step(tpg); | |
394 | } | |
395 | ||
396 | static inline void tpg_init_mv_count(struct tpg_data *tpg) | |
397 | { | |
398 | tpg->mv_hor_count = tpg->mv_vert_count = 0; | |
399 | } | |
400 | ||
401 | static inline void tpg_update_mv_count(struct tpg_data *tpg, bool frame_is_field) | |
402 | { | |
403 | tpg->mv_hor_count += tpg->mv_hor_step * (frame_is_field ? 1 : 2); | |
404 | tpg->mv_vert_count += tpg->mv_vert_step * (frame_is_field ? 1 : 2); | |
405 | } | |
406 | ||
407 | static inline void tpg_s_hflip(struct tpg_data *tpg, bool hflip) | |
408 | { | |
409 | if (tpg->hflip == hflip) | |
410 | return; | |
411 | tpg->hflip = hflip; | |
412 | tpg_update_mv_step(tpg); | |
413 | tpg->recalc_lines = true; | |
414 | } | |
415 | ||
416 | static inline bool tpg_g_hflip(const struct tpg_data *tpg) | |
417 | { | |
418 | return tpg->hflip; | |
419 | } | |
420 | ||
421 | static inline void tpg_s_vflip(struct tpg_data *tpg, bool vflip) | |
422 | { | |
423 | tpg->vflip = vflip; | |
424 | } | |
425 | ||
426 | static inline bool tpg_g_vflip(const struct tpg_data *tpg) | |
427 | { | |
428 | return tpg->vflip; | |
429 | } | |
430 | ||
431 | static inline bool tpg_pattern_is_static(const struct tpg_data *tpg) | |
432 | { | |
433 | return tpg->pattern != TPG_PAT_NOISE && | |
434 | tpg->mv_hor_mode == TPG_MOVE_NONE && | |
435 | tpg->mv_vert_mode == TPG_MOVE_NONE; | |
436 | } | |
437 | ||
438 | #endif |