Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 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 | |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 23 | #include <linux/types.h> |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/random.h> |
| 26 | #include <linux/slab.h> |
Hans Verkuil | 5754d0d | 2014-09-03 04:29:00 -0300 | [diff] [blame] | 27 | #include <linux/vmalloc.h> |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 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, |
Hans Verkuil | 1a05d31 | 2015-03-07 12:49:57 -0300 | [diff] [blame] | 44 | TPG_PAT_CHECKERS_2X2, |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 45 | TPG_PAT_CHECKERS_1X1, |
Hans Verkuil | 1a05d31 | 2015-03-07 12:49:57 -0300 | [diff] [blame] | 46 | TPG_PAT_COLOR_CHECKERS_2X2, |
| 47 | TPG_PAT_COLOR_CHECKERS_1X1, |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 48 | TPG_PAT_ALTERNATING_HLINES, |
| 49 | TPG_PAT_ALTERNATING_VLINES, |
| 50 | TPG_PAT_CROSS_1_PIXEL, |
| 51 | TPG_PAT_CROSS_2_PIXELS, |
| 52 | TPG_PAT_CROSS_10_PIXELS, |
| 53 | TPG_PAT_GRAY_RAMP, |
| 54 | |
| 55 | /* Must be the last pattern */ |
| 56 | TPG_PAT_NOISE, |
| 57 | }; |
| 58 | |
| 59 | extern const char * const tpg_pattern_strings[]; |
| 60 | |
| 61 | enum tpg_quality { |
| 62 | TPG_QUAL_COLOR, |
| 63 | TPG_QUAL_GRAY, |
| 64 | TPG_QUAL_NOISE |
| 65 | }; |
| 66 | |
| 67 | enum tpg_video_aspect { |
| 68 | TPG_VIDEO_ASPECT_IMAGE, |
| 69 | TPG_VIDEO_ASPECT_4X3, |
| 70 | TPG_VIDEO_ASPECT_14X9_CENTRE, |
| 71 | TPG_VIDEO_ASPECT_16X9_CENTRE, |
| 72 | TPG_VIDEO_ASPECT_16X9_ANAMORPHIC, |
| 73 | }; |
| 74 | |
| 75 | enum tpg_pixel_aspect { |
| 76 | TPG_PIXEL_ASPECT_SQUARE, |
| 77 | TPG_PIXEL_ASPECT_NTSC, |
| 78 | TPG_PIXEL_ASPECT_PAL, |
| 79 | }; |
| 80 | |
| 81 | enum tpg_move_mode { |
| 82 | TPG_MOVE_NEG_FAST, |
| 83 | TPG_MOVE_NEG, |
| 84 | TPG_MOVE_NEG_SLOW, |
| 85 | TPG_MOVE_NONE, |
| 86 | TPG_MOVE_POS_SLOW, |
| 87 | TPG_MOVE_POS, |
| 88 | TPG_MOVE_POS_FAST, |
| 89 | }; |
| 90 | |
| 91 | extern const char * const tpg_aspect_strings[]; |
| 92 | |
Hans Verkuil | ba01f67 | 2015-03-07 13:57:27 -0300 | [diff] [blame] | 93 | #define TPG_MAX_PLANES 3 |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 94 | #define TPG_MAX_PAT_LINES 8 |
| 95 | |
| 96 | struct tpg_data { |
| 97 | /* Source frame size */ |
| 98 | unsigned src_width, src_height; |
| 99 | /* Buffer height */ |
| 100 | unsigned buf_height; |
| 101 | /* Scaled output frame size */ |
| 102 | unsigned scaled_width; |
| 103 | u32 field; |
Hans Verkuil | 43047f6 | 2015-03-07 12:38:42 -0300 | [diff] [blame] | 104 | bool field_alternate; |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 105 | /* crop coordinates are frame-based */ |
| 106 | struct v4l2_rect crop; |
| 107 | /* compose coordinates are format-based */ |
| 108 | struct v4l2_rect compose; |
| 109 | /* border and square coordinates are frame-based */ |
| 110 | struct v4l2_rect border; |
| 111 | struct v4l2_rect square; |
| 112 | |
| 113 | /* Color-related fields */ |
| 114 | enum tpg_quality qual; |
| 115 | unsigned qual_offset; |
| 116 | u8 alpha_component; |
| 117 | bool alpha_red_only; |
| 118 | u8 brightness; |
| 119 | u8 contrast; |
| 120 | u8 saturation; |
| 121 | s16 hue; |
| 122 | u32 fourcc; |
| 123 | bool is_yuv; |
| 124 | u32 colorspace; |
Hans Verkuil | 481b97a | 2014-11-17 10:14:32 -0300 | [diff] [blame] | 125 | u32 ycbcr_enc; |
| 126 | /* |
| 127 | * Stores the actual Y'CbCr encoding, i.e. will never be |
| 128 | * V4L2_YCBCR_ENC_DEFAULT. |
| 129 | */ |
| 130 | u32 real_ycbcr_enc; |
| 131 | u32 quantization; |
| 132 | /* |
| 133 | * Stores the actual quantization, i.e. will never be |
| 134 | * V4L2_QUANTIZATION_DEFAULT. |
| 135 | */ |
| 136 | u32 real_quantization; |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 137 | enum tpg_video_aspect vid_aspect; |
| 138 | enum tpg_pixel_aspect pix_aspect; |
| 139 | unsigned rgb_range; |
| 140 | unsigned real_rgb_range; |
Hans Verkuil | 06d1f0c | 2015-03-07 13:01:53 -0300 | [diff] [blame] | 141 | unsigned buffers; |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 142 | unsigned planes; |
Hans Verkuil | 02aa769 | 2015-03-14 08:01:50 -0300 | [diff] [blame] | 143 | bool interleaved; |
Hans Verkuil | ba01f67 | 2015-03-07 13:57:27 -0300 | [diff] [blame] | 144 | u8 vdownsampling[TPG_MAX_PLANES]; |
| 145 | u8 hdownsampling[TPG_MAX_PLANES]; |
Hans Verkuil | 9991def | 2015-03-08 05:53:10 -0300 | [diff] [blame] | 146 | /* |
| 147 | * horizontal positions must be ANDed with this value to enforce |
| 148 | * correct boundaries for packed YUYV values. |
| 149 | */ |
| 150 | unsigned hmask[TPG_MAX_PLANES]; |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 151 | /* Used to store the colors in native format, either RGB or YUV */ |
| 152 | u8 colors[TPG_COLOR_MAX][3]; |
| 153 | u8 textfg[TPG_MAX_PLANES][8], textbg[TPG_MAX_PLANES][8]; |
| 154 | /* size in bytes for two pixels in each plane */ |
| 155 | unsigned twopixelsize[TPG_MAX_PLANES]; |
| 156 | unsigned bytesperline[TPG_MAX_PLANES]; |
| 157 | |
| 158 | /* Configuration */ |
| 159 | enum tpg_pattern pattern; |
| 160 | bool hflip; |
| 161 | bool vflip; |
| 162 | unsigned perc_fill; |
| 163 | bool perc_fill_blank; |
| 164 | bool show_border; |
| 165 | bool show_square; |
| 166 | bool insert_sav; |
| 167 | bool insert_eav; |
| 168 | |
| 169 | /* Test pattern movement */ |
| 170 | enum tpg_move_mode mv_hor_mode; |
| 171 | int mv_hor_count; |
| 172 | int mv_hor_step; |
| 173 | enum tpg_move_mode mv_vert_mode; |
| 174 | int mv_vert_count; |
| 175 | int mv_vert_step; |
| 176 | |
| 177 | bool recalc_colors; |
| 178 | bool recalc_lines; |
| 179 | bool recalc_square_border; |
| 180 | |
| 181 | /* Used to store TPG_MAX_PAT_LINES lines, each with up to two planes */ |
| 182 | unsigned max_line_width; |
| 183 | u8 *lines[TPG_MAX_PAT_LINES][TPG_MAX_PLANES]; |
Hans Verkuil | 5d7c539 | 2015-03-07 14:06:43 -0300 | [diff] [blame] | 184 | u8 *downsampled_lines[TPG_MAX_PAT_LINES][TPG_MAX_PLANES]; |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 185 | u8 *random_line[TPG_MAX_PLANES]; |
| 186 | u8 *contrast_line[TPG_MAX_PLANES]; |
| 187 | u8 *black_line[TPG_MAX_PLANES]; |
| 188 | }; |
| 189 | |
| 190 | void tpg_init(struct tpg_data *tpg, unsigned w, unsigned h); |
| 191 | int tpg_alloc(struct tpg_data *tpg, unsigned max_w); |
| 192 | void tpg_free(struct tpg_data *tpg); |
| 193 | void tpg_reset_source(struct tpg_data *tpg, unsigned width, unsigned height, |
| 194 | u32 field); |
Hans Verkuil | 84b76d7 | 2015-04-24 11:16:22 -0300 | [diff] [blame^] | 195 | void tpg_log_status(struct tpg_data *tpg); |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 196 | |
| 197 | void tpg_set_font(const u8 *f); |
Hans Verkuil | dfff048 | 2015-03-09 11:04:02 -0300 | [diff] [blame] | 198 | void tpg_gen_text(const struct tpg_data *tpg, |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 199 | u8 *basep[TPG_MAX_PLANES][2], int y, int x, char *text); |
| 200 | void tpg_calc_text_basep(struct tpg_data *tpg, |
| 201 | u8 *basep[TPG_MAX_PLANES][2], unsigned p, u8 *vbuf); |
Hans Verkuil | 02aa769 | 2015-03-14 08:01:50 -0300 | [diff] [blame] | 202 | unsigned tpg_g_interleaved_plane(const struct tpg_data *tpg, unsigned buf_line); |
Hans Verkuil | dfff048 | 2015-03-09 11:04:02 -0300 | [diff] [blame] | 203 | void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std, |
| 204 | unsigned p, u8 *vbuf); |
| 205 | void tpg_fillbuffer(struct tpg_data *tpg, v4l2_std_id std, |
| 206 | unsigned p, u8 *vbuf); |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 207 | bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc); |
| 208 | void tpg_s_crop_compose(struct tpg_data *tpg, const struct v4l2_rect *crop, |
| 209 | const struct v4l2_rect *compose); |
| 210 | |
| 211 | static inline void tpg_s_pattern(struct tpg_data *tpg, enum tpg_pattern pattern) |
| 212 | { |
| 213 | if (tpg->pattern == pattern) |
| 214 | return; |
| 215 | tpg->pattern = pattern; |
| 216 | tpg->recalc_colors = true; |
| 217 | } |
| 218 | |
| 219 | static inline void tpg_s_quality(struct tpg_data *tpg, |
| 220 | enum tpg_quality qual, unsigned qual_offset) |
| 221 | { |
| 222 | if (tpg->qual == qual && tpg->qual_offset == qual_offset) |
| 223 | return; |
| 224 | tpg->qual = qual; |
| 225 | tpg->qual_offset = qual_offset; |
| 226 | tpg->recalc_colors = true; |
| 227 | } |
| 228 | |
| 229 | static inline enum tpg_quality tpg_g_quality(const struct tpg_data *tpg) |
| 230 | { |
| 231 | return tpg->qual; |
| 232 | } |
| 233 | |
| 234 | static inline void tpg_s_alpha_component(struct tpg_data *tpg, |
| 235 | u8 alpha_component) |
| 236 | { |
| 237 | if (tpg->alpha_component == alpha_component) |
| 238 | return; |
| 239 | tpg->alpha_component = alpha_component; |
| 240 | tpg->recalc_colors = true; |
| 241 | } |
| 242 | |
| 243 | static inline void tpg_s_alpha_mode(struct tpg_data *tpg, |
| 244 | bool red_only) |
| 245 | { |
| 246 | if (tpg->alpha_red_only == red_only) |
| 247 | return; |
| 248 | tpg->alpha_red_only = red_only; |
| 249 | tpg->recalc_colors = true; |
| 250 | } |
| 251 | |
| 252 | static inline void tpg_s_brightness(struct tpg_data *tpg, |
| 253 | u8 brightness) |
| 254 | { |
| 255 | if (tpg->brightness == brightness) |
| 256 | return; |
| 257 | tpg->brightness = brightness; |
| 258 | tpg->recalc_colors = true; |
| 259 | } |
| 260 | |
| 261 | static inline void tpg_s_contrast(struct tpg_data *tpg, |
| 262 | u8 contrast) |
| 263 | { |
| 264 | if (tpg->contrast == contrast) |
| 265 | return; |
| 266 | tpg->contrast = contrast; |
| 267 | tpg->recalc_colors = true; |
| 268 | } |
| 269 | |
| 270 | static inline void tpg_s_saturation(struct tpg_data *tpg, |
| 271 | u8 saturation) |
| 272 | { |
| 273 | if (tpg->saturation == saturation) |
| 274 | return; |
| 275 | tpg->saturation = saturation; |
| 276 | tpg->recalc_colors = true; |
| 277 | } |
| 278 | |
| 279 | static inline void tpg_s_hue(struct tpg_data *tpg, |
| 280 | s16 hue) |
| 281 | { |
| 282 | if (tpg->hue == hue) |
| 283 | return; |
| 284 | tpg->hue = hue; |
| 285 | tpg->recalc_colors = true; |
| 286 | } |
| 287 | |
| 288 | static inline void tpg_s_rgb_range(struct tpg_data *tpg, |
| 289 | unsigned rgb_range) |
| 290 | { |
| 291 | if (tpg->rgb_range == rgb_range) |
| 292 | return; |
| 293 | tpg->rgb_range = rgb_range; |
| 294 | tpg->recalc_colors = true; |
| 295 | } |
| 296 | |
| 297 | static inline void tpg_s_real_rgb_range(struct tpg_data *tpg, |
| 298 | unsigned rgb_range) |
| 299 | { |
| 300 | if (tpg->real_rgb_range == rgb_range) |
| 301 | return; |
| 302 | tpg->real_rgb_range = rgb_range; |
| 303 | tpg->recalc_colors = true; |
| 304 | } |
| 305 | |
| 306 | static inline void tpg_s_colorspace(struct tpg_data *tpg, u32 colorspace) |
| 307 | { |
| 308 | if (tpg->colorspace == colorspace) |
| 309 | return; |
| 310 | tpg->colorspace = colorspace; |
| 311 | tpg->recalc_colors = true; |
| 312 | } |
| 313 | |
| 314 | static inline u32 tpg_g_colorspace(const struct tpg_data *tpg) |
| 315 | { |
| 316 | return tpg->colorspace; |
| 317 | } |
| 318 | |
Hans Verkuil | 481b97a | 2014-11-17 10:14:32 -0300 | [diff] [blame] | 319 | static inline void tpg_s_ycbcr_enc(struct tpg_data *tpg, u32 ycbcr_enc) |
| 320 | { |
| 321 | if (tpg->ycbcr_enc == ycbcr_enc) |
| 322 | return; |
| 323 | tpg->ycbcr_enc = ycbcr_enc; |
| 324 | tpg->recalc_colors = true; |
| 325 | } |
| 326 | |
| 327 | static inline u32 tpg_g_ycbcr_enc(const struct tpg_data *tpg) |
| 328 | { |
| 329 | return tpg->ycbcr_enc; |
| 330 | } |
| 331 | |
| 332 | static inline void tpg_s_quantization(struct tpg_data *tpg, u32 quantization) |
| 333 | { |
| 334 | if (tpg->quantization == quantization) |
| 335 | return; |
| 336 | tpg->quantization = quantization; |
| 337 | tpg->recalc_colors = true; |
| 338 | } |
| 339 | |
| 340 | static inline u32 tpg_g_quantization(const struct tpg_data *tpg) |
| 341 | { |
| 342 | return tpg->quantization; |
| 343 | } |
| 344 | |
Hans Verkuil | 06d1f0c | 2015-03-07 13:01:53 -0300 | [diff] [blame] | 345 | static inline unsigned tpg_g_buffers(const struct tpg_data *tpg) |
| 346 | { |
| 347 | return tpg->buffers; |
| 348 | } |
| 349 | |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 350 | static inline unsigned tpg_g_planes(const struct tpg_data *tpg) |
| 351 | { |
Hans Verkuil | 02aa769 | 2015-03-14 08:01:50 -0300 | [diff] [blame] | 352 | return tpg->interleaved ? 1 : tpg->planes; |
| 353 | } |
| 354 | |
| 355 | static inline bool tpg_g_interleaved(const struct tpg_data *tpg) |
| 356 | { |
| 357 | return tpg->interleaved; |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | static inline unsigned tpg_g_twopixelsize(const struct tpg_data *tpg, unsigned plane) |
| 361 | { |
| 362 | return tpg->twopixelsize[plane]; |
| 363 | } |
| 364 | |
Hans Verkuil | 9991def | 2015-03-08 05:53:10 -0300 | [diff] [blame] | 365 | static inline unsigned tpg_hdiv(const struct tpg_data *tpg, |
| 366 | unsigned plane, unsigned x) |
| 367 | { |
| 368 | return ((x / tpg->hdownsampling[plane]) & tpg->hmask[plane]) * |
| 369 | tpg->twopixelsize[plane] / 2; |
| 370 | } |
| 371 | |
| 372 | static inline unsigned tpg_hscale(const struct tpg_data *tpg, unsigned x) |
| 373 | { |
| 374 | return (x * tpg->scaled_width) / tpg->src_width; |
| 375 | } |
| 376 | |
| 377 | static inline unsigned tpg_hscale_div(const struct tpg_data *tpg, |
| 378 | unsigned plane, unsigned x) |
| 379 | { |
| 380 | return tpg_hdiv(tpg, plane, tpg_hscale(tpg, x)); |
| 381 | } |
| 382 | |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 383 | static inline unsigned tpg_g_bytesperline(const struct tpg_data *tpg, unsigned plane) |
| 384 | { |
| 385 | return tpg->bytesperline[plane]; |
| 386 | } |
| 387 | |
| 388 | static inline void tpg_s_bytesperline(struct tpg_data *tpg, unsigned plane, unsigned bpl) |
| 389 | { |
Hans Verkuil | 4db2204 | 2015-03-07 13:39:01 -0300 | [diff] [blame] | 390 | unsigned p; |
| 391 | |
| 392 | if (tpg->buffers > 1) { |
| 393 | tpg->bytesperline[plane] = bpl; |
| 394 | return; |
| 395 | } |
| 396 | |
Hans Verkuil | 02aa769 | 2015-03-14 08:01:50 -0300 | [diff] [blame] | 397 | for (p = 0; p < tpg_g_planes(tpg); p++) { |
Hans Verkuil | 4db2204 | 2015-03-07 13:39:01 -0300 | [diff] [blame] | 398 | unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0]; |
| 399 | |
Hans Verkuil | ba01f67 | 2015-03-07 13:57:27 -0300 | [diff] [blame] | 400 | tpg->bytesperline[p] = plane_w / tpg->hdownsampling[p]; |
Hans Verkuil | 4db2204 | 2015-03-07 13:39:01 -0300 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
Hans Verkuil | ba01f67 | 2015-03-07 13:57:27 -0300 | [diff] [blame] | 404 | |
Hans Verkuil | 4db2204 | 2015-03-07 13:39:01 -0300 | [diff] [blame] | 405 | static inline unsigned tpg_g_line_width(const struct tpg_data *tpg, unsigned plane) |
| 406 | { |
| 407 | unsigned w = 0; |
| 408 | unsigned p; |
| 409 | |
| 410 | if (tpg->buffers > 1) |
| 411 | return tpg_g_bytesperline(tpg, plane); |
Hans Verkuil | 02aa769 | 2015-03-14 08:01:50 -0300 | [diff] [blame] | 412 | for (p = 0; p < tpg_g_planes(tpg); p++) { |
Hans Verkuil | 4db2204 | 2015-03-07 13:39:01 -0300 | [diff] [blame] | 413 | unsigned plane_w = tpg_g_bytesperline(tpg, p); |
| 414 | |
Hans Verkuil | ba01f67 | 2015-03-07 13:57:27 -0300 | [diff] [blame] | 415 | w += plane_w / tpg->vdownsampling[p]; |
Hans Verkuil | 4db2204 | 2015-03-07 13:39:01 -0300 | [diff] [blame] | 416 | } |
| 417 | return w; |
| 418 | } |
| 419 | |
| 420 | static inline unsigned tpg_calc_line_width(const struct tpg_data *tpg, |
| 421 | unsigned plane, unsigned bpl) |
| 422 | { |
| 423 | unsigned w = 0; |
| 424 | unsigned p; |
| 425 | |
| 426 | if (tpg->buffers > 1) |
| 427 | return bpl; |
Hans Verkuil | 02aa769 | 2015-03-14 08:01:50 -0300 | [diff] [blame] | 428 | for (p = 0; p < tpg_g_planes(tpg); p++) { |
Hans Verkuil | 4db2204 | 2015-03-07 13:39:01 -0300 | [diff] [blame] | 429 | unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0]; |
| 430 | |
Hans Verkuil | ba01f67 | 2015-03-07 13:57:27 -0300 | [diff] [blame] | 431 | plane_w /= tpg->hdownsampling[p]; |
| 432 | w += plane_w / tpg->vdownsampling[p]; |
Hans Verkuil | 4db2204 | 2015-03-07 13:39:01 -0300 | [diff] [blame] | 433 | } |
| 434 | return w; |
| 435 | } |
| 436 | |
| 437 | static inline unsigned tpg_calc_plane_size(const struct tpg_data *tpg, unsigned plane) |
| 438 | { |
Hans Verkuil | 02aa769 | 2015-03-14 08:01:50 -0300 | [diff] [blame] | 439 | if (plane >= tpg_g_planes(tpg)) |
Hans Verkuil | 4db2204 | 2015-03-07 13:39:01 -0300 | [diff] [blame] | 440 | return 0; |
| 441 | |
Hans Verkuil | ba01f67 | 2015-03-07 13:57:27 -0300 | [diff] [blame] | 442 | return tpg_g_bytesperline(tpg, plane) * tpg->buf_height / |
| 443 | tpg->vdownsampling[plane]; |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | static inline void tpg_s_buf_height(struct tpg_data *tpg, unsigned h) |
| 447 | { |
| 448 | tpg->buf_height = h; |
| 449 | } |
| 450 | |
Hans Verkuil | 43047f6 | 2015-03-07 12:38:42 -0300 | [diff] [blame] | 451 | static inline void tpg_s_field(struct tpg_data *tpg, unsigned field, bool alternate) |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 452 | { |
| 453 | tpg->field = field; |
Hans Verkuil | 43047f6 | 2015-03-07 12:38:42 -0300 | [diff] [blame] | 454 | tpg->field_alternate = alternate; |
Hans Verkuil | 63881df | 2014-08-25 08:02:14 -0300 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | static inline void tpg_s_perc_fill(struct tpg_data *tpg, |
| 458 | unsigned perc_fill) |
| 459 | { |
| 460 | tpg->perc_fill = perc_fill; |
| 461 | } |
| 462 | |
| 463 | static inline unsigned tpg_g_perc_fill(const struct tpg_data *tpg) |
| 464 | { |
| 465 | return tpg->perc_fill; |
| 466 | } |
| 467 | |
| 468 | static inline void tpg_s_perc_fill_blank(struct tpg_data *tpg, |
| 469 | bool perc_fill_blank) |
| 470 | { |
| 471 | tpg->perc_fill_blank = perc_fill_blank; |
| 472 | } |
| 473 | |
| 474 | static inline void tpg_s_video_aspect(struct tpg_data *tpg, |
| 475 | enum tpg_video_aspect vid_aspect) |
| 476 | { |
| 477 | if (tpg->vid_aspect == vid_aspect) |
| 478 | return; |
| 479 | tpg->vid_aspect = vid_aspect; |
| 480 | tpg->recalc_square_border = true; |
| 481 | } |
| 482 | |
| 483 | static inline enum tpg_video_aspect tpg_g_video_aspect(const struct tpg_data *tpg) |
| 484 | { |
| 485 | return tpg->vid_aspect; |
| 486 | } |
| 487 | |
| 488 | static inline void tpg_s_pixel_aspect(struct tpg_data *tpg, |
| 489 | enum tpg_pixel_aspect pix_aspect) |
| 490 | { |
| 491 | if (tpg->pix_aspect == pix_aspect) |
| 492 | return; |
| 493 | tpg->pix_aspect = pix_aspect; |
| 494 | tpg->recalc_square_border = true; |
| 495 | } |
| 496 | |
| 497 | static inline void tpg_s_show_border(struct tpg_data *tpg, |
| 498 | bool show_border) |
| 499 | { |
| 500 | tpg->show_border = show_border; |
| 501 | } |
| 502 | |
| 503 | static inline void tpg_s_show_square(struct tpg_data *tpg, |
| 504 | bool show_square) |
| 505 | { |
| 506 | tpg->show_square = show_square; |
| 507 | } |
| 508 | |
| 509 | static inline void tpg_s_insert_sav(struct tpg_data *tpg, bool insert_sav) |
| 510 | { |
| 511 | tpg->insert_sav = insert_sav; |
| 512 | } |
| 513 | |
| 514 | static inline void tpg_s_insert_eav(struct tpg_data *tpg, bool insert_eav) |
| 515 | { |
| 516 | tpg->insert_eav = insert_eav; |
| 517 | } |
| 518 | |
| 519 | void tpg_update_mv_step(struct tpg_data *tpg); |
| 520 | |
| 521 | static inline void tpg_s_mv_hor_mode(struct tpg_data *tpg, |
| 522 | enum tpg_move_mode mv_hor_mode) |
| 523 | { |
| 524 | tpg->mv_hor_mode = mv_hor_mode; |
| 525 | tpg_update_mv_step(tpg); |
| 526 | } |
| 527 | |
| 528 | static inline void tpg_s_mv_vert_mode(struct tpg_data *tpg, |
| 529 | enum tpg_move_mode mv_vert_mode) |
| 530 | { |
| 531 | tpg->mv_vert_mode = mv_vert_mode; |
| 532 | tpg_update_mv_step(tpg); |
| 533 | } |
| 534 | |
| 535 | static inline void tpg_init_mv_count(struct tpg_data *tpg) |
| 536 | { |
| 537 | tpg->mv_hor_count = tpg->mv_vert_count = 0; |
| 538 | } |
| 539 | |
| 540 | static inline void tpg_update_mv_count(struct tpg_data *tpg, bool frame_is_field) |
| 541 | { |
| 542 | tpg->mv_hor_count += tpg->mv_hor_step * (frame_is_field ? 1 : 2); |
| 543 | tpg->mv_vert_count += tpg->mv_vert_step * (frame_is_field ? 1 : 2); |
| 544 | } |
| 545 | |
| 546 | static inline void tpg_s_hflip(struct tpg_data *tpg, bool hflip) |
| 547 | { |
| 548 | if (tpg->hflip == hflip) |
| 549 | return; |
| 550 | tpg->hflip = hflip; |
| 551 | tpg_update_mv_step(tpg); |
| 552 | tpg->recalc_lines = true; |
| 553 | } |
| 554 | |
| 555 | static inline bool tpg_g_hflip(const struct tpg_data *tpg) |
| 556 | { |
| 557 | return tpg->hflip; |
| 558 | } |
| 559 | |
| 560 | static inline void tpg_s_vflip(struct tpg_data *tpg, bool vflip) |
| 561 | { |
| 562 | tpg->vflip = vflip; |
| 563 | } |
| 564 | |
| 565 | static inline bool tpg_g_vflip(const struct tpg_data *tpg) |
| 566 | { |
| 567 | return tpg->vflip; |
| 568 | } |
| 569 | |
| 570 | static inline bool tpg_pattern_is_static(const struct tpg_data *tpg) |
| 571 | { |
| 572 | return tpg->pattern != TPG_PAT_NOISE && |
| 573 | tpg->mv_hor_mode == TPG_MOVE_NONE && |
| 574 | tpg->mv_vert_mode == TPG_MOVE_NONE; |
| 575 | } |
| 576 | |
| 577 | #endif |