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/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/vmalloc.h>
29 #include <linux/videodev2.h>
31 #include "vivid-tpg-colors.h"
37 TPG_PAT_100_HCOLORBAR,
38 TPG_PAT_100_COLORSQUARES,
44 TPG_PAT_CHECKERS_16X16,
46 TPG_PAT_ALTERNATING_HLINES,
47 TPG_PAT_ALTERNATING_VLINES,
48 TPG_PAT_CROSS_1_PIXEL,
49 TPG_PAT_CROSS_2_PIXELS,
50 TPG_PAT_CROSS_10_PIXELS,
53 /* Must be the last pattern */
57 extern const char * const tpg_pattern_strings[];
65 enum tpg_video_aspect {
66 TPG_VIDEO_ASPECT_IMAGE,
68 TPG_VIDEO_ASPECT_14X9_CENTRE,
69 TPG_VIDEO_ASPECT_16X9_CENTRE,
70 TPG_VIDEO_ASPECT_16X9_ANAMORPHIC,
73 enum tpg_pixel_aspect {
74 TPG_PIXEL_ASPECT_SQUARE,
75 TPG_PIXEL_ASPECT_NTSC,
89 extern const char * const tpg_aspect_strings[];
91 #define TPG_MAX_PLANES 2
92 #define TPG_MAX_PAT_LINES 8
95 /* Source frame size */
96 unsigned src_width, src_height;
99 /* Scaled output frame size */
100 unsigned scaled_width;
102 /* crop coordinates are frame-based */
103 struct v4l2_rect crop;
104 /* compose coordinates are format-based */
105 struct v4l2_rect compose;
106 /* border and square coordinates are frame-based */
107 struct v4l2_rect border;
108 struct v4l2_rect square;
110 /* Color-related fields */
111 enum tpg_quality qual;
112 unsigned qual_offset;
124 * Stores the actual Y'CbCr encoding, i.e. will never be
125 * V4L2_YCBCR_ENC_DEFAULT.
130 * Stores the actual quantization, i.e. will never be
131 * V4L2_QUANTIZATION_DEFAULT.
133 u32 real_quantization;
134 enum tpg_video_aspect vid_aspect;
135 enum tpg_pixel_aspect pix_aspect;
137 unsigned real_rgb_range;
139 /* Used to store the colors in native format, either RGB or YUV */
140 u8 colors[TPG_COLOR_MAX][3];
141 u8 textfg[TPG_MAX_PLANES][8], textbg[TPG_MAX_PLANES][8];
142 /* size in bytes for two pixels in each plane */
143 unsigned twopixelsize[TPG_MAX_PLANES];
144 unsigned bytesperline[TPG_MAX_PLANES];
147 enum tpg_pattern pattern;
151 bool perc_fill_blank;
157 /* Test pattern movement */
158 enum tpg_move_mode mv_hor_mode;
161 enum tpg_move_mode mv_vert_mode;
167 bool recalc_square_border;
169 /* Used to store TPG_MAX_PAT_LINES lines, each with up to two planes */
170 unsigned max_line_width;
171 u8 *lines[TPG_MAX_PAT_LINES][TPG_MAX_PLANES];
172 u8 *random_line[TPG_MAX_PLANES];
173 u8 *contrast_line[TPG_MAX_PLANES];
174 u8 *black_line[TPG_MAX_PLANES];
177 void tpg_init(struct tpg_data *tpg, unsigned w, unsigned h);
178 int tpg_alloc(struct tpg_data *tpg, unsigned max_w);
179 void tpg_free(struct tpg_data *tpg);
180 void tpg_reset_source(struct tpg_data *tpg, unsigned width, unsigned height,
183 void tpg_set_font(const u8 *f);
184 void tpg_gen_text(struct tpg_data *tpg,
185 u8 *basep[TPG_MAX_PLANES][2], int y, int x, char *text);
186 void tpg_calc_text_basep(struct tpg_data *tpg,
187 u8 *basep[TPG_MAX_PLANES][2], unsigned p, u8 *vbuf);
188 void tpg_fillbuffer(struct tpg_data *tpg, v4l2_std_id std, unsigned p, u8 *vbuf);
189 bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc);
190 void tpg_s_crop_compose(struct tpg_data *tpg, const struct v4l2_rect *crop,
191 const struct v4l2_rect *compose);
193 static inline void tpg_s_pattern(struct tpg_data *tpg, enum tpg_pattern pattern)
195 if (tpg->pattern == pattern)
197 tpg->pattern = pattern;
198 tpg->recalc_colors = true;
201 static inline void tpg_s_quality(struct tpg_data *tpg,
202 enum tpg_quality qual, unsigned qual_offset)
204 if (tpg->qual == qual && tpg->qual_offset == qual_offset)
207 tpg->qual_offset = qual_offset;
208 tpg->recalc_colors = true;
211 static inline enum tpg_quality tpg_g_quality(const struct tpg_data *tpg)
216 static inline void tpg_s_alpha_component(struct tpg_data *tpg,
219 if (tpg->alpha_component == alpha_component)
221 tpg->alpha_component = alpha_component;
222 tpg->recalc_colors = true;
225 static inline void tpg_s_alpha_mode(struct tpg_data *tpg,
228 if (tpg->alpha_red_only == red_only)
230 tpg->alpha_red_only = red_only;
231 tpg->recalc_colors = true;
234 static inline void tpg_s_brightness(struct tpg_data *tpg,
237 if (tpg->brightness == brightness)
239 tpg->brightness = brightness;
240 tpg->recalc_colors = true;
243 static inline void tpg_s_contrast(struct tpg_data *tpg,
246 if (tpg->contrast == contrast)
248 tpg->contrast = contrast;
249 tpg->recalc_colors = true;
252 static inline void tpg_s_saturation(struct tpg_data *tpg,
255 if (tpg->saturation == saturation)
257 tpg->saturation = saturation;
258 tpg->recalc_colors = true;
261 static inline void tpg_s_hue(struct tpg_data *tpg,
267 tpg->recalc_colors = true;
270 static inline void tpg_s_rgb_range(struct tpg_data *tpg,
273 if (tpg->rgb_range == rgb_range)
275 tpg->rgb_range = rgb_range;
276 tpg->recalc_colors = true;
279 static inline void tpg_s_real_rgb_range(struct tpg_data *tpg,
282 if (tpg->real_rgb_range == rgb_range)
284 tpg->real_rgb_range = rgb_range;
285 tpg->recalc_colors = true;
288 static inline void tpg_s_colorspace(struct tpg_data *tpg, u32 colorspace)
290 if (tpg->colorspace == colorspace)
292 tpg->colorspace = colorspace;
293 tpg->recalc_colors = true;
296 static inline u32 tpg_g_colorspace(const struct tpg_data *tpg)
298 return tpg->colorspace;
301 static inline void tpg_s_ycbcr_enc(struct tpg_data *tpg, u32 ycbcr_enc)
303 if (tpg->ycbcr_enc == ycbcr_enc)
305 tpg->ycbcr_enc = ycbcr_enc;
306 tpg->recalc_colors = true;
309 static inline u32 tpg_g_ycbcr_enc(const struct tpg_data *tpg)
311 return tpg->ycbcr_enc;
314 static inline void tpg_s_quantization(struct tpg_data *tpg, u32 quantization)
316 if (tpg->quantization == quantization)
318 tpg->quantization = quantization;
319 tpg->recalc_colors = true;
322 static inline u32 tpg_g_quantization(const struct tpg_data *tpg)
324 return tpg->quantization;
327 static inline unsigned tpg_g_planes(const struct tpg_data *tpg)
332 static inline unsigned tpg_g_twopixelsize(const struct tpg_data *tpg, unsigned plane)
334 return tpg->twopixelsize[plane];
337 static inline unsigned tpg_g_bytesperline(const struct tpg_data *tpg, unsigned plane)
339 return tpg->bytesperline[plane];
342 static inline void tpg_s_bytesperline(struct tpg_data *tpg, unsigned plane, unsigned bpl)
344 tpg->bytesperline[plane] = bpl;
347 static inline void tpg_s_buf_height(struct tpg_data *tpg, unsigned h)
352 static inline void tpg_s_field(struct tpg_data *tpg, unsigned field)
357 static inline void tpg_s_perc_fill(struct tpg_data *tpg,
360 tpg->perc_fill = perc_fill;
363 static inline unsigned tpg_g_perc_fill(const struct tpg_data *tpg)
365 return tpg->perc_fill;
368 static inline void tpg_s_perc_fill_blank(struct tpg_data *tpg,
369 bool perc_fill_blank)
371 tpg->perc_fill_blank = perc_fill_blank;
374 static inline void tpg_s_video_aspect(struct tpg_data *tpg,
375 enum tpg_video_aspect vid_aspect)
377 if (tpg->vid_aspect == vid_aspect)
379 tpg->vid_aspect = vid_aspect;
380 tpg->recalc_square_border = true;
383 static inline enum tpg_video_aspect tpg_g_video_aspect(const struct tpg_data *tpg)
385 return tpg->vid_aspect;
388 static inline void tpg_s_pixel_aspect(struct tpg_data *tpg,
389 enum tpg_pixel_aspect pix_aspect)
391 if (tpg->pix_aspect == pix_aspect)
393 tpg->pix_aspect = pix_aspect;
394 tpg->recalc_square_border = true;
397 static inline void tpg_s_show_border(struct tpg_data *tpg,
400 tpg->show_border = show_border;
403 static inline void tpg_s_show_square(struct tpg_data *tpg,
406 tpg->show_square = show_square;
409 static inline void tpg_s_insert_sav(struct tpg_data *tpg, bool insert_sav)
411 tpg->insert_sav = insert_sav;
414 static inline void tpg_s_insert_eav(struct tpg_data *tpg, bool insert_eav)
416 tpg->insert_eav = insert_eav;
419 void tpg_update_mv_step(struct tpg_data *tpg);
421 static inline void tpg_s_mv_hor_mode(struct tpg_data *tpg,
422 enum tpg_move_mode mv_hor_mode)
424 tpg->mv_hor_mode = mv_hor_mode;
425 tpg_update_mv_step(tpg);
428 static inline void tpg_s_mv_vert_mode(struct tpg_data *tpg,
429 enum tpg_move_mode mv_vert_mode)
431 tpg->mv_vert_mode = mv_vert_mode;
432 tpg_update_mv_step(tpg);
435 static inline void tpg_init_mv_count(struct tpg_data *tpg)
437 tpg->mv_hor_count = tpg->mv_vert_count = 0;
440 static inline void tpg_update_mv_count(struct tpg_data *tpg, bool frame_is_field)
442 tpg->mv_hor_count += tpg->mv_hor_step * (frame_is_field ? 1 : 2);
443 tpg->mv_vert_count += tpg->mv_vert_step * (frame_is_field ? 1 : 2);
446 static inline void tpg_s_hflip(struct tpg_data *tpg, bool hflip)
448 if (tpg->hflip == hflip)
451 tpg_update_mv_step(tpg);
452 tpg->recalc_lines = true;
455 static inline bool tpg_g_hflip(const struct tpg_data *tpg)
460 static inline void tpg_s_vflip(struct tpg_data *tpg, bool vflip)
465 static inline bool tpg_g_vflip(const struct tpg_data *tpg)
470 static inline bool tpg_pattern_is_static(const struct tpg_data *tpg)
472 return tpg->pattern != TPG_PAT_NOISE &&
473 tpg->mv_hor_mode == TPG_MOVE_NONE &&
474 tpg->mv_vert_mode == TPG_MOVE_NONE;