]>
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 | ||
63881df9 HV |
23 | #include <linux/types.h> |
24 | #include <linux/errno.h> | |
25 | #include <linux/random.h> | |
26 | #include <linux/slab.h> | |
5754d0d5 | 27 | #include <linux/vmalloc.h> |
63881df9 HV |
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; | |
481b97a1 HV |
121 | u32 ycbcr_enc; |
122 | /* | |
123 | * Stores the actual Y'CbCr encoding, i.e. will never be | |
124 | * V4L2_YCBCR_ENC_DEFAULT. | |
125 | */ | |
126 | u32 real_ycbcr_enc; | |
127 | u32 quantization; | |
128 | /* | |
129 | * Stores the actual quantization, i.e. will never be | |
130 | * V4L2_QUANTIZATION_DEFAULT. | |
131 | */ | |
132 | u32 real_quantization; | |
63881df9 HV |
133 | enum tpg_video_aspect vid_aspect; |
134 | enum tpg_pixel_aspect pix_aspect; | |
135 | unsigned rgb_range; | |
136 | unsigned real_rgb_range; | |
137 | unsigned planes; | |
138 | /* Used to store the colors in native format, either RGB or YUV */ | |
139 | u8 colors[TPG_COLOR_MAX][3]; | |
140 | u8 textfg[TPG_MAX_PLANES][8], textbg[TPG_MAX_PLANES][8]; | |
141 | /* size in bytes for two pixels in each plane */ | |
142 | unsigned twopixelsize[TPG_MAX_PLANES]; | |
143 | unsigned bytesperline[TPG_MAX_PLANES]; | |
144 | ||
145 | /* Configuration */ | |
146 | enum tpg_pattern pattern; | |
147 | bool hflip; | |
148 | bool vflip; | |
149 | unsigned perc_fill; | |
150 | bool perc_fill_blank; | |
151 | bool show_border; | |
152 | bool show_square; | |
153 | bool insert_sav; | |
154 | bool insert_eav; | |
155 | ||
156 | /* Test pattern movement */ | |
157 | enum tpg_move_mode mv_hor_mode; | |
158 | int mv_hor_count; | |
159 | int mv_hor_step; | |
160 | enum tpg_move_mode mv_vert_mode; | |
161 | int mv_vert_count; | |
162 | int mv_vert_step; | |
163 | ||
164 | bool recalc_colors; | |
165 | bool recalc_lines; | |
166 | bool recalc_square_border; | |
167 | ||
168 | /* Used to store TPG_MAX_PAT_LINES lines, each with up to two planes */ | |
169 | unsigned max_line_width; | |
170 | u8 *lines[TPG_MAX_PAT_LINES][TPG_MAX_PLANES]; | |
171 | u8 *random_line[TPG_MAX_PLANES]; | |
172 | u8 *contrast_line[TPG_MAX_PLANES]; | |
173 | u8 *black_line[TPG_MAX_PLANES]; | |
174 | }; | |
175 | ||
176 | void tpg_init(struct tpg_data *tpg, unsigned w, unsigned h); | |
177 | int tpg_alloc(struct tpg_data *tpg, unsigned max_w); | |
178 | void tpg_free(struct tpg_data *tpg); | |
179 | void tpg_reset_source(struct tpg_data *tpg, unsigned width, unsigned height, | |
180 | u32 field); | |
181 | ||
182 | void tpg_set_font(const u8 *f); | |
183 | void tpg_gen_text(struct tpg_data *tpg, | |
184 | u8 *basep[TPG_MAX_PLANES][2], int y, int x, char *text); | |
185 | void tpg_calc_text_basep(struct tpg_data *tpg, | |
186 | u8 *basep[TPG_MAX_PLANES][2], unsigned p, u8 *vbuf); | |
187 | void tpg_fillbuffer(struct tpg_data *tpg, v4l2_std_id std, unsigned p, u8 *vbuf); | |
188 | bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc); | |
189 | void tpg_s_crop_compose(struct tpg_data *tpg, const struct v4l2_rect *crop, | |
190 | const struct v4l2_rect *compose); | |
191 | ||
192 | static inline void tpg_s_pattern(struct tpg_data *tpg, enum tpg_pattern pattern) | |
193 | { | |
194 | if (tpg->pattern == pattern) | |
195 | return; | |
196 | tpg->pattern = pattern; | |
197 | tpg->recalc_colors = true; | |
198 | } | |
199 | ||
200 | static inline void tpg_s_quality(struct tpg_data *tpg, | |
201 | enum tpg_quality qual, unsigned qual_offset) | |
202 | { | |
203 | if (tpg->qual == qual && tpg->qual_offset == qual_offset) | |
204 | return; | |
205 | tpg->qual = qual; | |
206 | tpg->qual_offset = qual_offset; | |
207 | tpg->recalc_colors = true; | |
208 | } | |
209 | ||
210 | static inline enum tpg_quality tpg_g_quality(const struct tpg_data *tpg) | |
211 | { | |
212 | return tpg->qual; | |
213 | } | |
214 | ||
215 | static inline void tpg_s_alpha_component(struct tpg_data *tpg, | |
216 | u8 alpha_component) | |
217 | { | |
218 | if (tpg->alpha_component == alpha_component) | |
219 | return; | |
220 | tpg->alpha_component = alpha_component; | |
221 | tpg->recalc_colors = true; | |
222 | } | |
223 | ||
224 | static inline void tpg_s_alpha_mode(struct tpg_data *tpg, | |
225 | bool red_only) | |
226 | { | |
227 | if (tpg->alpha_red_only == red_only) | |
228 | return; | |
229 | tpg->alpha_red_only = red_only; | |
230 | tpg->recalc_colors = true; | |
231 | } | |
232 | ||
233 | static inline void tpg_s_brightness(struct tpg_data *tpg, | |
234 | u8 brightness) | |
235 | { | |
236 | if (tpg->brightness == brightness) | |
237 | return; | |
238 | tpg->brightness = brightness; | |
239 | tpg->recalc_colors = true; | |
240 | } | |
241 | ||
242 | static inline void tpg_s_contrast(struct tpg_data *tpg, | |
243 | u8 contrast) | |
244 | { | |
245 | if (tpg->contrast == contrast) | |
246 | return; | |
247 | tpg->contrast = contrast; | |
248 | tpg->recalc_colors = true; | |
249 | } | |
250 | ||
251 | static inline void tpg_s_saturation(struct tpg_data *tpg, | |
252 | u8 saturation) | |
253 | { | |
254 | if (tpg->saturation == saturation) | |
255 | return; | |
256 | tpg->saturation = saturation; | |
257 | tpg->recalc_colors = true; | |
258 | } | |
259 | ||
260 | static inline void tpg_s_hue(struct tpg_data *tpg, | |
261 | s16 hue) | |
262 | { | |
263 | if (tpg->hue == hue) | |
264 | return; | |
265 | tpg->hue = hue; | |
266 | tpg->recalc_colors = true; | |
267 | } | |
268 | ||
269 | static inline void tpg_s_rgb_range(struct tpg_data *tpg, | |
270 | unsigned rgb_range) | |
271 | { | |
272 | if (tpg->rgb_range == rgb_range) | |
273 | return; | |
274 | tpg->rgb_range = rgb_range; | |
275 | tpg->recalc_colors = true; | |
276 | } | |
277 | ||
278 | static inline void tpg_s_real_rgb_range(struct tpg_data *tpg, | |
279 | unsigned rgb_range) | |
280 | { | |
281 | if (tpg->real_rgb_range == rgb_range) | |
282 | return; | |
283 | tpg->real_rgb_range = rgb_range; | |
284 | tpg->recalc_colors = true; | |
285 | } | |
286 | ||
287 | static inline void tpg_s_colorspace(struct tpg_data *tpg, u32 colorspace) | |
288 | { | |
289 | if (tpg->colorspace == colorspace) | |
290 | return; | |
291 | tpg->colorspace = colorspace; | |
292 | tpg->recalc_colors = true; | |
293 | } | |
294 | ||
295 | static inline u32 tpg_g_colorspace(const struct tpg_data *tpg) | |
296 | { | |
297 | return tpg->colorspace; | |
298 | } | |
299 | ||
481b97a1 HV |
300 | static inline void tpg_s_ycbcr_enc(struct tpg_data *tpg, u32 ycbcr_enc) |
301 | { | |
302 | if (tpg->ycbcr_enc == ycbcr_enc) | |
303 | return; | |
304 | tpg->ycbcr_enc = ycbcr_enc; | |
305 | tpg->recalc_colors = true; | |
306 | } | |
307 | ||
308 | static inline u32 tpg_g_ycbcr_enc(const struct tpg_data *tpg) | |
309 | { | |
310 | return tpg->ycbcr_enc; | |
311 | } | |
312 | ||
313 | static inline void tpg_s_quantization(struct tpg_data *tpg, u32 quantization) | |
314 | { | |
315 | if (tpg->quantization == quantization) | |
316 | return; | |
317 | tpg->quantization = quantization; | |
318 | tpg->recalc_colors = true; | |
319 | } | |
320 | ||
321 | static inline u32 tpg_g_quantization(const struct tpg_data *tpg) | |
322 | { | |
323 | return tpg->quantization; | |
324 | } | |
325 | ||
63881df9 HV |
326 | static inline unsigned tpg_g_planes(const struct tpg_data *tpg) |
327 | { | |
328 | return tpg->planes; | |
329 | } | |
330 | ||
331 | static inline unsigned tpg_g_twopixelsize(const struct tpg_data *tpg, unsigned plane) | |
332 | { | |
333 | return tpg->twopixelsize[plane]; | |
334 | } | |
335 | ||
336 | static inline unsigned tpg_g_bytesperline(const struct tpg_data *tpg, unsigned plane) | |
337 | { | |
338 | return tpg->bytesperline[plane]; | |
339 | } | |
340 | ||
341 | static inline void tpg_s_bytesperline(struct tpg_data *tpg, unsigned plane, unsigned bpl) | |
342 | { | |
343 | tpg->bytesperline[plane] = bpl; | |
344 | } | |
345 | ||
346 | static inline void tpg_s_buf_height(struct tpg_data *tpg, unsigned h) | |
347 | { | |
348 | tpg->buf_height = h; | |
349 | } | |
350 | ||
351 | static inline void tpg_s_field(struct tpg_data *tpg, unsigned field) | |
352 | { | |
353 | tpg->field = field; | |
354 | } | |
355 | ||
356 | static inline void tpg_s_perc_fill(struct tpg_data *tpg, | |
357 | unsigned perc_fill) | |
358 | { | |
359 | tpg->perc_fill = perc_fill; | |
360 | } | |
361 | ||
362 | static inline unsigned tpg_g_perc_fill(const struct tpg_data *tpg) | |
363 | { | |
364 | return tpg->perc_fill; | |
365 | } | |
366 | ||
367 | static inline void tpg_s_perc_fill_blank(struct tpg_data *tpg, | |
368 | bool perc_fill_blank) | |
369 | { | |
370 | tpg->perc_fill_blank = perc_fill_blank; | |
371 | } | |
372 | ||
373 | static inline void tpg_s_video_aspect(struct tpg_data *tpg, | |
374 | enum tpg_video_aspect vid_aspect) | |
375 | { | |
376 | if (tpg->vid_aspect == vid_aspect) | |
377 | return; | |
378 | tpg->vid_aspect = vid_aspect; | |
379 | tpg->recalc_square_border = true; | |
380 | } | |
381 | ||
382 | static inline enum tpg_video_aspect tpg_g_video_aspect(const struct tpg_data *tpg) | |
383 | { | |
384 | return tpg->vid_aspect; | |
385 | } | |
386 | ||
387 | static inline void tpg_s_pixel_aspect(struct tpg_data *tpg, | |
388 | enum tpg_pixel_aspect pix_aspect) | |
389 | { | |
390 | if (tpg->pix_aspect == pix_aspect) | |
391 | return; | |
392 | tpg->pix_aspect = pix_aspect; | |
393 | tpg->recalc_square_border = true; | |
394 | } | |
395 | ||
396 | static inline void tpg_s_show_border(struct tpg_data *tpg, | |
397 | bool show_border) | |
398 | { | |
399 | tpg->show_border = show_border; | |
400 | } | |
401 | ||
402 | static inline void tpg_s_show_square(struct tpg_data *tpg, | |
403 | bool show_square) | |
404 | { | |
405 | tpg->show_square = show_square; | |
406 | } | |
407 | ||
408 | static inline void tpg_s_insert_sav(struct tpg_data *tpg, bool insert_sav) | |
409 | { | |
410 | tpg->insert_sav = insert_sav; | |
411 | } | |
412 | ||
413 | static inline void tpg_s_insert_eav(struct tpg_data *tpg, bool insert_eav) | |
414 | { | |
415 | tpg->insert_eav = insert_eav; | |
416 | } | |
417 | ||
418 | void tpg_update_mv_step(struct tpg_data *tpg); | |
419 | ||
420 | static inline void tpg_s_mv_hor_mode(struct tpg_data *tpg, | |
421 | enum tpg_move_mode mv_hor_mode) | |
422 | { | |
423 | tpg->mv_hor_mode = mv_hor_mode; | |
424 | tpg_update_mv_step(tpg); | |
425 | } | |
426 | ||
427 | static inline void tpg_s_mv_vert_mode(struct tpg_data *tpg, | |
428 | enum tpg_move_mode mv_vert_mode) | |
429 | { | |
430 | tpg->mv_vert_mode = mv_vert_mode; | |
431 | tpg_update_mv_step(tpg); | |
432 | } | |
433 | ||
434 | static inline void tpg_init_mv_count(struct tpg_data *tpg) | |
435 | { | |
436 | tpg->mv_hor_count = tpg->mv_vert_count = 0; | |
437 | } | |
438 | ||
439 | static inline void tpg_update_mv_count(struct tpg_data *tpg, bool frame_is_field) | |
440 | { | |
441 | tpg->mv_hor_count += tpg->mv_hor_step * (frame_is_field ? 1 : 2); | |
442 | tpg->mv_vert_count += tpg->mv_vert_step * (frame_is_field ? 1 : 2); | |
443 | } | |
444 | ||
445 | static inline void tpg_s_hflip(struct tpg_data *tpg, bool hflip) | |
446 | { | |
447 | if (tpg->hflip == hflip) | |
448 | return; | |
449 | tpg->hflip = hflip; | |
450 | tpg_update_mv_step(tpg); | |
451 | tpg->recalc_lines = true; | |
452 | } | |
453 | ||
454 | static inline bool tpg_g_hflip(const struct tpg_data *tpg) | |
455 | { | |
456 | return tpg->hflip; | |
457 | } | |
458 | ||
459 | static inline void tpg_s_vflip(struct tpg_data *tpg, bool vflip) | |
460 | { | |
461 | tpg->vflip = vflip; | |
462 | } | |
463 | ||
464 | static inline bool tpg_g_vflip(const struct tpg_data *tpg) | |
465 | { | |
466 | return tpg->vflip; | |
467 | } | |
468 | ||
469 | static inline bool tpg_pattern_is_static(const struct tpg_data *tpg) | |
470 | { | |
471 | return tpg->pattern != TPG_PAT_NOISE && | |
472 | tpg->mv_hor_mode == TPG_MOVE_NONE && | |
473 | tpg->mv_vert_mode == TPG_MOVE_NONE; | |
474 | } | |
475 | ||
476 | #endif |