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