2 * vivid-tpg.h - Test Pattern Generator
4 * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
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.
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
23 #include <linux/types.h>
24 #include <linux/errno.h>
25 #include <linux/random.h>
26 #include <linux/slab.h>
27 #include <linux/vmalloc.h>
28 #include <linux/videodev2.h>
30 #include "vivid-tpg-colors.h"
36 TPG_PAT_100_HCOLORBAR
,
37 TPG_PAT_100_COLORSQUARES
,
43 TPG_PAT_CHECKERS_16X16
,
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
,
52 /* Must be the last pattern */
56 extern const char * const tpg_pattern_strings
[];
64 enum tpg_video_aspect
{
65 TPG_VIDEO_ASPECT_IMAGE
,
67 TPG_VIDEO_ASPECT_14X9_CENTRE
,
68 TPG_VIDEO_ASPECT_16X9_CENTRE
,
69 TPG_VIDEO_ASPECT_16X9_ANAMORPHIC
,
72 enum tpg_pixel_aspect
{
73 TPG_PIXEL_ASPECT_SQUARE
,
74 TPG_PIXEL_ASPECT_NTSC
,
88 extern const char * const tpg_aspect_strings
[];
90 #define TPG_MAX_PLANES 2
91 #define TPG_MAX_PAT_LINES 8
94 /* Source frame size */
95 unsigned src_width
, src_height
;
98 /* Scaled output frame size */
99 unsigned scaled_width
;
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
;
109 /* Color-related fields */
110 enum tpg_quality qual
;
111 unsigned qual_offset
;
123 * Stores the actual Y'CbCr encoding, i.e. will never be
124 * V4L2_YCBCR_ENC_DEFAULT.
129 * Stores the actual quantization, i.e. will never be
130 * V4L2_QUANTIZATION_DEFAULT.
132 u32 real_quantization
;
133 enum tpg_video_aspect vid_aspect
;
134 enum tpg_pixel_aspect pix_aspect
;
136 unsigned real_rgb_range
;
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
];
146 enum tpg_pattern pattern
;
150 bool perc_fill_blank
;
156 /* Test pattern movement */
157 enum tpg_move_mode mv_hor_mode
;
160 enum tpg_move_mode mv_vert_mode
;
166 bool recalc_square_border
;
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
];
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
,
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
);
192 static inline void tpg_s_pattern(struct tpg_data
*tpg
, enum tpg_pattern pattern
)
194 if (tpg
->pattern
== pattern
)
196 tpg
->pattern
= pattern
;
197 tpg
->recalc_colors
= true;
200 static inline void tpg_s_quality(struct tpg_data
*tpg
,
201 enum tpg_quality qual
, unsigned qual_offset
)
203 if (tpg
->qual
== qual
&& tpg
->qual_offset
== qual_offset
)
206 tpg
->qual_offset
= qual_offset
;
207 tpg
->recalc_colors
= true;
210 static inline enum tpg_quality
tpg_g_quality(const struct tpg_data
*tpg
)
215 static inline void tpg_s_alpha_component(struct tpg_data
*tpg
,
218 if (tpg
->alpha_component
== alpha_component
)
220 tpg
->alpha_component
= alpha_component
;
221 tpg
->recalc_colors
= true;
224 static inline void tpg_s_alpha_mode(struct tpg_data
*tpg
,
227 if (tpg
->alpha_red_only
== red_only
)
229 tpg
->alpha_red_only
= red_only
;
230 tpg
->recalc_colors
= true;
233 static inline void tpg_s_brightness(struct tpg_data
*tpg
,
236 if (tpg
->brightness
== brightness
)
238 tpg
->brightness
= brightness
;
239 tpg
->recalc_colors
= true;
242 static inline void tpg_s_contrast(struct tpg_data
*tpg
,
245 if (tpg
->contrast
== contrast
)
247 tpg
->contrast
= contrast
;
248 tpg
->recalc_colors
= true;
251 static inline void tpg_s_saturation(struct tpg_data
*tpg
,
254 if (tpg
->saturation
== saturation
)
256 tpg
->saturation
= saturation
;
257 tpg
->recalc_colors
= true;
260 static inline void tpg_s_hue(struct tpg_data
*tpg
,
266 tpg
->recalc_colors
= true;
269 static inline void tpg_s_rgb_range(struct tpg_data
*tpg
,
272 if (tpg
->rgb_range
== rgb_range
)
274 tpg
->rgb_range
= rgb_range
;
275 tpg
->recalc_colors
= true;
278 static inline void tpg_s_real_rgb_range(struct tpg_data
*tpg
,
281 if (tpg
->real_rgb_range
== rgb_range
)
283 tpg
->real_rgb_range
= rgb_range
;
284 tpg
->recalc_colors
= true;
287 static inline void tpg_s_colorspace(struct tpg_data
*tpg
, u32 colorspace
)
289 if (tpg
->colorspace
== colorspace
)
291 tpg
->colorspace
= colorspace
;
292 tpg
->recalc_colors
= true;
295 static inline u32
tpg_g_colorspace(const struct tpg_data
*tpg
)
297 return tpg
->colorspace
;
300 static inline void tpg_s_ycbcr_enc(struct tpg_data
*tpg
, u32 ycbcr_enc
)
302 if (tpg
->ycbcr_enc
== ycbcr_enc
)
304 tpg
->ycbcr_enc
= ycbcr_enc
;
305 tpg
->recalc_colors
= true;
308 static inline u32
tpg_g_ycbcr_enc(const struct tpg_data
*tpg
)
310 return tpg
->ycbcr_enc
;
313 static inline void tpg_s_quantization(struct tpg_data
*tpg
, u32 quantization
)
315 if (tpg
->quantization
== quantization
)
317 tpg
->quantization
= quantization
;
318 tpg
->recalc_colors
= true;
321 static inline u32
tpg_g_quantization(const struct tpg_data
*tpg
)
323 return tpg
->quantization
;
326 static inline unsigned tpg_g_planes(const struct tpg_data
*tpg
)
331 static inline unsigned tpg_g_twopixelsize(const struct tpg_data
*tpg
, unsigned plane
)
333 return tpg
->twopixelsize
[plane
];
336 static inline unsigned tpg_g_bytesperline(const struct tpg_data
*tpg
, unsigned plane
)
338 return tpg
->bytesperline
[plane
];
341 static inline void tpg_s_bytesperline(struct tpg_data
*tpg
, unsigned plane
, unsigned bpl
)
343 tpg
->bytesperline
[plane
] = bpl
;
346 static inline void tpg_s_buf_height(struct tpg_data
*tpg
, unsigned h
)
351 static inline void tpg_s_field(struct tpg_data
*tpg
, unsigned field
)
356 static inline void tpg_s_perc_fill(struct tpg_data
*tpg
,
359 tpg
->perc_fill
= perc_fill
;
362 static inline unsigned tpg_g_perc_fill(const struct tpg_data
*tpg
)
364 return tpg
->perc_fill
;
367 static inline void tpg_s_perc_fill_blank(struct tpg_data
*tpg
,
368 bool perc_fill_blank
)
370 tpg
->perc_fill_blank
= perc_fill_blank
;
373 static inline void tpg_s_video_aspect(struct tpg_data
*tpg
,
374 enum tpg_video_aspect vid_aspect
)
376 if (tpg
->vid_aspect
== vid_aspect
)
378 tpg
->vid_aspect
= vid_aspect
;
379 tpg
->recalc_square_border
= true;
382 static inline enum tpg_video_aspect
tpg_g_video_aspect(const struct tpg_data
*tpg
)
384 return tpg
->vid_aspect
;
387 static inline void tpg_s_pixel_aspect(struct tpg_data
*tpg
,
388 enum tpg_pixel_aspect pix_aspect
)
390 if (tpg
->pix_aspect
== pix_aspect
)
392 tpg
->pix_aspect
= pix_aspect
;
393 tpg
->recalc_square_border
= true;
396 static inline void tpg_s_show_border(struct tpg_data
*tpg
,
399 tpg
->show_border
= show_border
;
402 static inline void tpg_s_show_square(struct tpg_data
*tpg
,
405 tpg
->show_square
= show_square
;
408 static inline void tpg_s_insert_sav(struct tpg_data
*tpg
, bool insert_sav
)
410 tpg
->insert_sav
= insert_sav
;
413 static inline void tpg_s_insert_eav(struct tpg_data
*tpg
, bool insert_eav
)
415 tpg
->insert_eav
= insert_eav
;
418 void tpg_update_mv_step(struct tpg_data
*tpg
);
420 static inline void tpg_s_mv_hor_mode(struct tpg_data
*tpg
,
421 enum tpg_move_mode mv_hor_mode
)
423 tpg
->mv_hor_mode
= mv_hor_mode
;
424 tpg_update_mv_step(tpg
);
427 static inline void tpg_s_mv_vert_mode(struct tpg_data
*tpg
,
428 enum tpg_move_mode mv_vert_mode
)
430 tpg
->mv_vert_mode
= mv_vert_mode
;
431 tpg_update_mv_step(tpg
);
434 static inline void tpg_init_mv_count(struct tpg_data
*tpg
)
436 tpg
->mv_hor_count
= tpg
->mv_vert_count
= 0;
439 static inline void tpg_update_mv_count(struct tpg_data
*tpg
, bool frame_is_field
)
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);
445 static inline void tpg_s_hflip(struct tpg_data
*tpg
, bool hflip
)
447 if (tpg
->hflip
== hflip
)
450 tpg_update_mv_step(tpg
);
451 tpg
->recalc_lines
= true;
454 static inline bool tpg_g_hflip(const struct tpg_data
*tpg
)
459 static inline void tpg_s_vflip(struct tpg_data
*tpg
, bool vflip
)
464 static inline bool tpg_g_vflip(const struct tpg_data
*tpg
)
469 static inline bool tpg_pattern_is_static(const struct tpg_data
*tpg
)
471 return tpg
->pattern
!= TPG_PAT_NOISE
&&
472 tpg
->mv_hor_mode
== TPG_MOVE_NONE
&&
473 tpg
->mv_vert_mode
== TPG_MOVE_NONE
;