| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
/* |
| 3 |
* v4l2-tpg.h - Test Pattern Generator |
| 4 |
* |
| 5 |
* Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef _V4L2_TPG_H_ |
| 9 |
#define _V4L2_TPG_H_ |
| 10 |
|
| 11 |
#include <linux/videodev2.h> |
| 12 |
|
| 13 |
#include <stdbool.h> |
| 14 |
#include <stdlib.h> |
| 15 |
#include <stdio.h> |
| 16 |
#include <string.h> |
| 17 |
#include <errno.h> |
| 18 |
|
| 19 |
typedef __u32 u32; |
| 20 |
typedef __u16 u16; |
| 21 |
typedef __s16 s16; |
| 22 |
typedef __u8 u8; |
| 23 |
typedef __s8 s8; |
| 24 |
|
| 25 |
#ifndef __packed |
| 26 |
#define __packed __attribute__((packed)) |
| 27 |
#endif |
| 28 |
#define pr_info printf |
| 29 |
#define noinline |
| 30 |
|
| 31 |
#define tpg_min(a,b) ((a) < (b) ? (a) : (b)) |
| 32 |
#define tpg_max(a,b) ((a) > (b) ? (a) : (b)) |
| 33 |
#define min3(x, y, z) tpg_min((typeof(x))tpg_min(x, y), z) |
| 34 |
#define max3(x, y, z) tpg_max((typeof(x))tpg_max(x, y), z) |
| 35 |
#define array_size(a, b) ((a) * (b)) |
| 36 |
#define array3_size(a, b, c) ((a) * (b) * (c)) |
| 37 |
#define WARN_ON_ONCE(a) (a) |
| 38 |
|
| 39 |
static inline void vfree(void *p) |
| 40 |
{ |
| 41 |
free(p); |
| 42 |
} |
| 43 |
|
| 44 |
static inline void *vzalloc(unsigned long size) |
| 45 |
{ |
| 46 |
return calloc(1, size); |
| 47 |
} |
| 48 |
|
| 49 |
#define clamp(val, min, max) ({ \ |
| 50 |
typeof(val) __val = (val); \ |
| 51 |
typeof(min) __min = (min); \ |
| 52 |
typeof(max) __max = (max); \ |
| 53 |
(void) (&__val == &__min); \ |
| 54 |
(void) (&__val == &__max); \ |
| 55 |
__val = __val < __min ? __min: __val; \ |
| 56 |
__val > __max ? __max: __val; }) |
| 57 |
|
| 58 |
#define clamp_t(type, val, min, max) clamp((type)val, (type)min, (type)max) |
| 59 |
|
| 60 |
static inline u32 get_random_u32_below(u32 ep_ro) |
| 61 |
{ |
| 62 |
return rand() % ep_ro; |
| 63 |
} |
| 64 |
|
| 65 |
static inline u32 get_random_u8(void) |
| 66 |
{ |
| 67 |
return get_random_u32_below(256); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
struct tpg_rbg_color8 { |
| 72 |
unsigned char r, g, b; |
| 73 |
}; |
| 74 |
|
| 75 |
struct tpg_rbg_color16 { |
| 76 |
__u16 r, g, b; |
| 77 |
}; |
| 78 |
|
| 79 |
enum tpg_color { |
| 80 |
TPG_COLOR_CSC_WHITE, |
| 81 |
TPG_COLOR_CSC_YELLOW, |
| 82 |
TPG_COLOR_CSC_CYAN, |
| 83 |
TPG_COLOR_CSC_GREEN, |
| 84 |
TPG_COLOR_CSC_MAGENTA, |
| 85 |
TPG_COLOR_CSC_RED, |
| 86 |
TPG_COLOR_CSC_BLUE, |
| 87 |
TPG_COLOR_CSC_BLACK, |
| 88 |
TPG_COLOR_75_YELLOW, |
| 89 |
TPG_COLOR_75_CYAN, |
| 90 |
TPG_COLOR_75_GREEN, |
| 91 |
TPG_COLOR_75_MAGENTA, |
| 92 |
TPG_COLOR_75_RED, |
| 93 |
TPG_COLOR_75_BLUE, |
| 94 |
TPG_COLOR_100_WHITE, |
| 95 |
TPG_COLOR_100_YELLOW, |
| 96 |
TPG_COLOR_100_CYAN, |
| 97 |
TPG_COLOR_100_GREEN, |
| 98 |
TPG_COLOR_100_MAGENTA, |
| 99 |
TPG_COLOR_100_RED, |
| 100 |
TPG_COLOR_100_BLUE, |
| 101 |
TPG_COLOR_100_BLACK, |
| 102 |
TPG_COLOR_TEXTFG, |
| 103 |
TPG_COLOR_TEXTBG, |
| 104 |
TPG_COLOR_RANDOM, |
| 105 |
TPG_COLOR_RAMP, |
| 106 |
TPG_COLOR_MAX = TPG_COLOR_RAMP + 256 |
| 107 |
}; |
| 108 |
|
| 109 |
extern const struct tpg_rbg_color8 tpg_colors[TPG_COLOR_MAX]; |
| 110 |
extern const unsigned short tpg_rec709_to_linear[255 * 16 + 1]; |
| 111 |
extern const unsigned short tpg_linear_to_rec709[255 * 16 + 1]; |
| 112 |
extern const struct tpg_rbg_color16 tpg_csc_colors[V4L2_COLORSPACE_DCI_P3 + 1] |
| 113 |
[V4L2_XFER_FUNC_SMPTE2084 + 1] |
| 114 |
[TPG_COLOR_CSC_BLACK + 1]; |
| 115 |
enum tpg_pattern { |
| 116 |
TPG_PAT_75_COLORBAR, |
| 117 |
TPG_PAT_100_COLORBAR, |
| 118 |
TPG_PAT_CSC_COLORBAR, |
| 119 |
TPG_PAT_100_HCOLORBAR, |
| 120 |
TPG_PAT_100_COLORSQUARES, |
| 121 |
TPG_PAT_BLACK, |
| 122 |
TPG_PAT_WHITE, |
| 123 |
TPG_PAT_RED, |
| 124 |
TPG_PAT_GREEN, |
| 125 |
TPG_PAT_BLUE, |
| 126 |
TPG_PAT_CHECKERS_16X16, |
| 127 |
TPG_PAT_CHECKERS_2X2, |
| 128 |
TPG_PAT_CHECKERS_1X1, |
| 129 |
TPG_PAT_COLOR_CHECKERS_2X2, |
| 130 |
TPG_PAT_COLOR_CHECKERS_1X1, |
| 131 |
TPG_PAT_ALTERNATING_HLINES, |
| 132 |
TPG_PAT_ALTERNATING_VLINES, |
| 133 |
TPG_PAT_CROSS_1_PIXEL, |
| 134 |
TPG_PAT_CROSS_2_PIXELS, |
| 135 |
TPG_PAT_CROSS_10_PIXELS, |
| 136 |
TPG_PAT_GRAY_RAMP, |
| 137 |
|
| 138 |
/* Must be the last pattern */ |
| 139 |
TPG_PAT_NOISE, |
| 140 |
}; |
| 141 |
|
| 142 |
extern const char * const tpg_pattern_strings[]; |
| 143 |
|
| 144 |
enum tpg_quality { |
| 145 |
TPG_QUAL_COLOR, |
| 146 |
TPG_QUAL_GRAY, |
| 147 |
TPG_QUAL_NOISE |
| 148 |
}; |
| 149 |
|
| 150 |
enum tpg_video_aspect { |
| 151 |
TPG_VIDEO_ASPECT_IMAGE, |
| 152 |
TPG_VIDEO_ASPECT_4X3, |
| 153 |
TPG_VIDEO_ASPECT_14X9_CENTRE, |
| 154 |
TPG_VIDEO_ASPECT_16X9_CENTRE, |
| 155 |
TPG_VIDEO_ASPECT_16X9_ANAMORPHIC, |
| 156 |
}; |
| 157 |
|
| 158 |
enum tpg_pixel_aspect { |
| 159 |
TPG_PIXEL_ASPECT_SQUARE, |
| 160 |
TPG_PIXEL_ASPECT_NTSC, |
| 161 |
TPG_PIXEL_ASPECT_PAL, |
| 162 |
}; |
| 163 |
|
| 164 |
enum tpg_move_mode { |
| 165 |
TPG_MOVE_NEG_FAST, |
| 166 |
TPG_MOVE_NEG, |
| 167 |
TPG_MOVE_NEG_SLOW, |
| 168 |
TPG_MOVE_NONE, |
| 169 |
TPG_MOVE_POS_SLOW, |
| 170 |
TPG_MOVE_POS, |
| 171 |
TPG_MOVE_POS_FAST, |
| 172 |
}; |
| 173 |
|
| 174 |
enum tgp_color_enc { |
| 175 |
TGP_COLOR_ENC_RGB, |
| 176 |
TGP_COLOR_ENC_YCBCR, |
| 177 |
TGP_COLOR_ENC_HSV, |
| 178 |
TGP_COLOR_ENC_LUMA, |
| 179 |
}; |
| 180 |
|
| 181 |
extern const char * const tpg_aspect_strings[]; |
| 182 |
|
| 183 |
#define TPG_MAX_PLANES 3 |
| 184 |
#define TPG_MAX_PAT_LINES 8 |
| 185 |
|
| 186 |
struct tpg_data { |
| 187 |
/* Source frame size */ |
| 188 |
unsigned src_width, src_height; |
| 189 |
/* Buffer height */ |
| 190 |
unsigned buf_height; |
| 191 |
/* Scaled output frame size */ |
| 192 |
unsigned scaled_width; |
| 193 |
u32 field; |
| 194 |
bool field_alternate; |
| 195 |
/* crop coordinates are frame-based */ |
| 196 |
struct v4l2_rect crop; |
| 197 |
/* compose coordinates are format-based */ |
| 198 |
struct v4l2_rect compose; |
| 199 |
/* border and square coordinates are frame-based */ |
| 200 |
struct v4l2_rect border; |
| 201 |
struct v4l2_rect square; |
| 202 |
|
| 203 |
/* Color-related fields */ |
| 204 |
enum tpg_quality qual; |
| 205 |
unsigned qual_offset; |
| 206 |
u8 alpha_component; |
| 207 |
bool alpha_red_only; |
| 208 |
u8 brightness; |
| 209 |
u8 contrast; |
| 210 |
u8 saturation; |
| 211 |
s16 hue; |
| 212 |
u32 fourcc; |
| 213 |
enum tgp_color_enc color_enc; |
| 214 |
u32 colorspace; |
| 215 |
u32 xfer_func; |
| 216 |
u32 ycbcr_enc; |
| 217 |
u32 hsv_enc; |
| 218 |
/* |
| 219 |
* Stores the actual transfer function, i.e. will never be |
| 220 |
* V4L2_XFER_FUNC_DEFAULT. |
| 221 |
*/ |
| 222 |
u32 real_xfer_func; |
| 223 |
/* |
| 224 |
* Stores the actual Y'CbCr encoding, i.e. will never be |
| 225 |
* V4L2_YCBCR_ENC_DEFAULT. |
| 226 |
*/ |
| 227 |
u32 real_hsv_enc; |
| 228 |
u32 real_ycbcr_enc; |
| 229 |
u32 quantization; |
| 230 |
/* |
| 231 |
* Stores the actual quantization, i.e. will never be |
| 232 |
* V4L2_QUANTIZATION_DEFAULT. |
| 233 |
*/ |
| 234 |
u32 real_quantization; |
| 235 |
enum tpg_video_aspect vid_aspect; |
| 236 |
enum tpg_pixel_aspect pix_aspect; |
| 237 |
unsigned rgb_range; |
| 238 |
unsigned real_rgb_range; |
| 239 |
unsigned buffers; |
| 240 |
unsigned planes; |
| 241 |
bool interleaved; |
| 242 |
u8 vdownsampling[TPG_MAX_PLANES]; |
| 243 |
u8 hdownsampling[TPG_MAX_PLANES]; |
| 244 |
/* |
| 245 |
* horizontal positions must be ANDed with this value to enforce |
| 246 |
* correct boundaries for packed YUYV values. |
| 247 |
*/ |
| 248 |
unsigned hmask[TPG_MAX_PLANES]; |
| 249 |
/* Used to store the colors in native format, either RGB or YUV */ |
| 250 |
u8 colors[TPG_COLOR_MAX][3]; |
| 251 |
u8 textfg[TPG_MAX_PLANES][8], textbg[TPG_MAX_PLANES][8]; |
| 252 |
/* size in bytes for two pixels in each plane */ |
| 253 |
unsigned twopixelsize[TPG_MAX_PLANES]; |
| 254 |
unsigned bytesperline[TPG_MAX_PLANES]; |
| 255 |
|
| 256 |
/* Configuration */ |
| 257 |
enum tpg_pattern pattern; |
| 258 |
bool hflip; |
| 259 |
bool vflip; |
| 260 |
unsigned perc_fill; |
| 261 |
bool perc_fill_blank; |
| 262 |
bool show_border; |
| 263 |
bool show_square; |
| 264 |
bool insert_sav; |
| 265 |
bool insert_eav; |
| 266 |
bool insert_hdmi_video_guard_band; |
| 267 |
|
| 268 |
/* Test pattern movement */ |
| 269 |
enum tpg_move_mode mv_hor_mode; |
| 270 |
int mv_hor_count; |
| 271 |
int mv_hor_step; |
| 272 |
enum tpg_move_mode mv_vert_mode; |
| 273 |
int mv_vert_count; |
| 274 |
int mv_vert_step; |
| 275 |
|
| 276 |
bool recalc_colors; |
| 277 |
bool recalc_lines; |
| 278 |
bool recalc_square_border; |
| 279 |
|
| 280 |
/* Used to store TPG_MAX_PAT_LINES lines, each with up to two planes */ |
| 281 |
unsigned max_line_width; |
| 282 |
u8 *lines[TPG_MAX_PAT_LINES][TPG_MAX_PLANES]; |
| 283 |
u8 *downsampled_lines[TPG_MAX_PAT_LINES][TPG_MAX_PLANES]; |
| 284 |
u8 *random_line[TPG_MAX_PLANES]; |
| 285 |
u8 *contrast_line[TPG_MAX_PLANES]; |
| 286 |
u8 *black_line[TPG_MAX_PLANES]; |
| 287 |
}; |
| 288 |
|
| 289 |
void tpg_init(struct tpg_data *tpg, unsigned w, unsigned h); |
| 290 |
int tpg_alloc(struct tpg_data *tpg, unsigned max_w); |
| 291 |
void tpg_free(struct tpg_data *tpg); |
| 292 |
void tpg_reset_source(struct tpg_data *tpg, unsigned width, unsigned height, |
| 293 |
u32 field); |
| 294 |
void tpg_log_status(struct tpg_data *tpg); |
| 295 |
|
| 296 |
void tpg_set_font(const u8 *f); |
| 297 |
void tpg_gen_text(const struct tpg_data *tpg, |
| 298 |
u8 *basep[TPG_MAX_PLANES][2], int y, int x, const char *text); |
| 299 |
void tpg_calc_text_basep(struct tpg_data *tpg, |
| 300 |
u8 *basep[TPG_MAX_PLANES][2], unsigned p, u8 *vbuf); |
| 301 |
unsigned tpg_g_interleaved_plane(const struct tpg_data *tpg, unsigned buf_line); |
| 302 |
void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std, |
| 303 |
unsigned p, u8 *vbuf); |
| 304 |
void tpg_fillbuffer(struct tpg_data *tpg, v4l2_std_id std, |
| 305 |
unsigned p, u8 *vbuf); |
| 306 |
bool tpg_s_fourcc(struct tpg_data *tpg, u32 fourcc); |
| 307 |
void tpg_s_crop_compose(struct tpg_data *tpg, const struct v4l2_rect *crop, |
| 308 |
const struct v4l2_rect *compose); |
| 309 |
const char *tpg_g_color_order(const struct tpg_data *tpg); |
| 310 |
|
| 311 |
static inline void tpg_s_pattern(struct tpg_data *tpg, enum tpg_pattern pattern) |
| 312 |
{ |
| 313 |
if (tpg->pattern == pattern) |
| 314 |
return; |
| 315 |
tpg->pattern = pattern; |
| 316 |
tpg->recalc_colors = true; |
| 317 |
} |
| 318 |
|
| 319 |
static inline void tpg_s_quality(struct tpg_data *tpg, |
| 320 |
enum tpg_quality qual, unsigned qual_offset) |
| 321 |
{ |
| 322 |
if (tpg->qual == qual && tpg->qual_offset == qual_offset) |
| 323 |
return; |
| 324 |
tpg->qual = qual; |
| 325 |
tpg->qual_offset = qual_offset; |
| 326 |
tpg->recalc_colors = true; |
| 327 |
} |
| 328 |
|
| 329 |
static inline enum tpg_quality tpg_g_quality(const struct tpg_data *tpg) |
| 330 |
{ |
| 331 |
return tpg->qual; |
| 332 |
} |
| 333 |
|
| 334 |
static inline void tpg_s_alpha_component(struct tpg_data *tpg, |
| 335 |
u8 alpha_component) |
| 336 |
{ |
| 337 |
if (tpg->alpha_component == alpha_component) |
| 338 |
return; |
| 339 |
tpg->alpha_component = alpha_component; |
| 340 |
tpg->recalc_colors = true; |
| 341 |
} |
| 342 |
|
| 343 |
static inline void tpg_s_alpha_mode(struct tpg_data *tpg, |
| 344 |
bool red_only) |
| 345 |
{ |
| 346 |
if (tpg->alpha_red_only == red_only) |
| 347 |
return; |
| 348 |
tpg->alpha_red_only = red_only; |
| 349 |
tpg->recalc_colors = true; |
| 350 |
} |
| 351 |
|
| 352 |
static inline void tpg_s_brightness(struct tpg_data *tpg, |
| 353 |
u8 brightness) |
| 354 |
{ |
| 355 |
if (tpg->brightness == brightness) |
| 356 |
return; |
| 357 |
tpg->brightness = brightness; |
| 358 |
tpg->recalc_colors = true; |
| 359 |
} |
| 360 |
|
| 361 |
static inline void tpg_s_contrast(struct tpg_data *tpg, |
| 362 |
u8 contrast) |
| 363 |
{ |
| 364 |
if (tpg->contrast == contrast) |
| 365 |
return; |
| 366 |
tpg->contrast = contrast; |
| 367 |
tpg->recalc_colors = true; |
| 368 |
} |
| 369 |
|
| 370 |
static inline void tpg_s_saturation(struct tpg_data *tpg, |
| 371 |
u8 saturation) |
| 372 |
{ |
| 373 |
if (tpg->saturation == saturation) |
| 374 |
return; |
| 375 |
tpg->saturation = saturation; |
| 376 |
tpg->recalc_colors = true; |
| 377 |
} |
| 378 |
|
| 379 |
static inline void tpg_s_hue(struct tpg_data *tpg, |
| 380 |
s16 hue) |
| 381 |
{ |
| 382 |
hue = clamp_t(s16, hue, -128, 128); |
| 383 |
if (tpg->hue == hue) |
| 384 |
return; |
| 385 |
tpg->hue = hue; |
| 386 |
tpg->recalc_colors = true; |
| 387 |
} |
| 388 |
|
| 389 |
static inline void tpg_s_rgb_range(struct tpg_data *tpg, |
| 390 |
unsigned rgb_range) |
| 391 |
{ |
| 392 |
if (tpg->rgb_range == rgb_range) |
| 393 |
return; |
| 394 |
tpg->rgb_range = rgb_range; |
| 395 |
tpg->recalc_colors = true; |
| 396 |
} |
| 397 |
|
| 398 |
static inline void tpg_s_real_rgb_range(struct tpg_data *tpg, |
| 399 |
unsigned rgb_range) |
| 400 |
{ |
| 401 |
if (tpg->real_rgb_range == rgb_range) |
| 402 |
return; |
| 403 |
tpg->real_rgb_range = rgb_range; |
| 404 |
tpg->recalc_colors = true; |
| 405 |
} |
| 406 |
|
| 407 |
static inline void tpg_s_colorspace(struct tpg_data *tpg, u32 colorspace) |
| 408 |
{ |
| 409 |
if (tpg->colorspace == colorspace) |
| 410 |
return; |
| 411 |
tpg->colorspace = colorspace; |
| 412 |
tpg->recalc_colors = true; |
| 413 |
} |
| 414 |
|
| 415 |
static inline u32 tpg_g_colorspace(const struct tpg_data *tpg) |
| 416 |
{ |
| 417 |
return tpg->colorspace; |
| 418 |
} |
| 419 |
|
| 420 |
static inline void tpg_s_ycbcr_enc(struct tpg_data *tpg, u32 ycbcr_enc) |
| 421 |
{ |
| 422 |
if (tpg->ycbcr_enc == ycbcr_enc) |
| 423 |
return; |
| 424 |
tpg->ycbcr_enc = ycbcr_enc; |
| 425 |
tpg->recalc_colors = true; |
| 426 |
} |
| 427 |
|
| 428 |
static inline u32 tpg_g_ycbcr_enc(const struct tpg_data *tpg) |
| 429 |
{ |
| 430 |
return tpg->ycbcr_enc; |
| 431 |
} |
| 432 |
|
| 433 |
static inline void tpg_s_hsv_enc(struct tpg_data *tpg, u32 hsv_enc) |
| 434 |
{ |
| 435 |
if (tpg->hsv_enc == hsv_enc) |
| 436 |
return; |
| 437 |
tpg->hsv_enc = hsv_enc; |
| 438 |
tpg->recalc_colors = true; |
| 439 |
} |
| 440 |
|
| 441 |
static inline u32 tpg_g_hsv_enc(const struct tpg_data *tpg) |
| 442 |
{ |
| 443 |
return tpg->hsv_enc; |
| 444 |
} |
| 445 |
|
| 446 |
static inline void tpg_s_xfer_func(struct tpg_data *tpg, u32 xfer_func) |
| 447 |
{ |
| 448 |
if (tpg->xfer_func == xfer_func) |
| 449 |
return; |
| 450 |
tpg->xfer_func = xfer_func; |
| 451 |
tpg->recalc_colors = true; |
| 452 |
} |
| 453 |
|
| 454 |
static inline u32 tpg_g_xfer_func(const struct tpg_data *tpg) |
| 455 |
{ |
| 456 |
return tpg->xfer_func; |
| 457 |
} |
| 458 |
|
| 459 |
static inline void tpg_s_quantization(struct tpg_data *tpg, u32 quantization) |
| 460 |
{ |
| 461 |
if (tpg->quantization == quantization) |
| 462 |
return; |
| 463 |
tpg->quantization = quantization; |
| 464 |
tpg->recalc_colors = true; |
| 465 |
} |
| 466 |
|
| 467 |
static inline u32 tpg_g_quantization(const struct tpg_data *tpg) |
| 468 |
{ |
| 469 |
return tpg->quantization; |
| 470 |
} |
| 471 |
|
| 472 |
static inline unsigned tpg_g_buffers(const struct tpg_data *tpg) |
| 473 |
{ |
| 474 |
return tpg->buffers; |
| 475 |
} |
| 476 |
|
| 477 |
static inline unsigned tpg_g_planes(const struct tpg_data *tpg) |
| 478 |
{ |
| 479 |
return tpg->interleaved ? 1 : tpg->planes; |
| 480 |
} |
| 481 |
|
| 482 |
static inline bool tpg_g_interleaved(const struct tpg_data *tpg) |
| 483 |
{ |
| 484 |
return tpg->interleaved; |
| 485 |
} |
| 486 |
|
| 487 |
static inline unsigned tpg_g_twopixelsize(const struct tpg_data *tpg, unsigned plane) |
| 488 |
{ |
| 489 |
return tpg->twopixelsize[plane]; |
| 490 |
} |
| 491 |
|
| 492 |
static inline unsigned tpg_hdiv(const struct tpg_data *tpg, |
| 493 |
unsigned plane, unsigned x) |
| 494 |
{ |
| 495 |
return ((x / tpg->hdownsampling[plane]) & tpg->hmask[plane]) * |
| 496 |
tpg->twopixelsize[plane] / 2; |
| 497 |
} |
| 498 |
|
| 499 |
static inline unsigned tpg_hscale(const struct tpg_data *tpg, unsigned x) |
| 500 |
{ |
| 501 |
return (x * tpg->scaled_width) / tpg->src_width; |
| 502 |
} |
| 503 |
|
| 504 |
static inline unsigned tpg_hscale_div(const struct tpg_data *tpg, |
| 505 |
unsigned plane, unsigned x) |
| 506 |
{ |
| 507 |
return tpg_hdiv(tpg, plane, tpg_hscale(tpg, x)); |
| 508 |
} |
| 509 |
|
| 510 |
static inline unsigned tpg_g_bytesperline(const struct tpg_data *tpg, unsigned plane) |
| 511 |
{ |
| 512 |
return tpg->bytesperline[plane]; |
| 513 |
} |
| 514 |
|
| 515 |
static inline void tpg_s_bytesperline(struct tpg_data *tpg, unsigned plane, unsigned bpl) |
| 516 |
{ |
| 517 |
unsigned p; |
| 518 |
|
| 519 |
if (tpg->buffers > 1) { |
| 520 |
tpg->bytesperline[plane] = bpl; |
| 521 |
return; |
| 522 |
} |
| 523 |
|
| 524 |
for (p = 0; p < tpg_g_planes(tpg); p++) { |
| 525 |
unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0]; |
| 526 |
|
| 527 |
tpg->bytesperline[p] = plane_w / tpg->hdownsampling[p]; |
| 528 |
} |
| 529 |
if (tpg_g_interleaved(tpg)) |
| 530 |
tpg->bytesperline[1] = tpg->bytesperline[0]; |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
static inline unsigned tpg_g_line_width(const struct tpg_data *tpg, unsigned plane) |
| 535 |
{ |
| 536 |
unsigned w = 0; |
| 537 |
unsigned p; |
| 538 |
|
| 539 |
if (tpg->buffers > 1) |
| 540 |
return tpg_g_bytesperline(tpg, plane); |
| 541 |
for (p = 0; p < tpg_g_planes(tpg); p++) { |
| 542 |
unsigned plane_w = tpg_g_bytesperline(tpg, p); |
| 543 |
|
| 544 |
w += plane_w / tpg->vdownsampling[p]; |
| 545 |
} |
| 546 |
return w; |
| 547 |
} |
| 548 |
|
| 549 |
static inline unsigned tpg_calc_line_width(const struct tpg_data *tpg, |
| 550 |
unsigned plane, unsigned bpl) |
| 551 |
{ |
| 552 |
unsigned w = 0; |
| 553 |
unsigned p; |
| 554 |
|
| 555 |
if (tpg->buffers > 1) |
| 556 |
return bpl; |
| 557 |
for (p = 0; p < tpg_g_planes(tpg); p++) { |
| 558 |
unsigned plane_w = bpl * tpg->twopixelsize[p] / tpg->twopixelsize[0]; |
| 559 |
|
| 560 |
plane_w /= tpg->hdownsampling[p]; |
| 561 |
w += plane_w / tpg->vdownsampling[p]; |
| 562 |
} |
| 563 |
return w; |
| 564 |
} |
| 565 |
|
| 566 |
static inline unsigned tpg_calc_plane_size(const struct tpg_data *tpg, unsigned plane) |
| 567 |
{ |
| 568 |
if (plane >= tpg_g_planes(tpg)) |
| 569 |
return 0; |
| 570 |
|
| 571 |
return tpg_g_bytesperline(tpg, plane) * tpg->buf_height / |
| 572 |
tpg->vdownsampling[plane]; |
| 573 |
} |
| 574 |
|
| 575 |
static inline void tpg_s_buf_height(struct tpg_data *tpg, unsigned h) |
| 576 |
{ |
| 577 |
tpg->buf_height = h; |
| 578 |
} |
| 579 |
|
| 580 |
static inline void tpg_s_field(struct tpg_data *tpg, unsigned field, bool alternate) |
| 581 |
{ |
| 582 |
tpg->field = field; |
| 583 |
tpg->field_alternate = alternate; |
| 584 |
} |
| 585 |
|
| 586 |
static inline void tpg_s_perc_fill(struct tpg_data *tpg, |
| 587 |
unsigned perc_fill) |
| 588 |
{ |
| 589 |
tpg->perc_fill = perc_fill; |
| 590 |
} |
| 591 |
|
| 592 |
static inline unsigned tpg_g_perc_fill(const struct tpg_data *tpg) |
| 593 |
{ |
| 594 |
return tpg->perc_fill; |
| 595 |
} |
| 596 |
|
| 597 |
static inline void tpg_s_perc_fill_blank(struct tpg_data *tpg, |
| 598 |
bool perc_fill_blank) |
| 599 |
{ |
| 600 |
tpg->perc_fill_blank = perc_fill_blank; |
| 601 |
} |
| 602 |
|
| 603 |
static inline void tpg_s_video_aspect(struct tpg_data *tpg, |
| 604 |
enum tpg_video_aspect vid_aspect) |
| 605 |
{ |
| 606 |
if (tpg->vid_aspect == vid_aspect) |
| 607 |
return; |
| 608 |
tpg->vid_aspect = vid_aspect; |
| 609 |
tpg->recalc_square_border = true; |
| 610 |
} |
| 611 |
|
| 612 |
static inline enum tpg_video_aspect tpg_g_video_aspect(const struct tpg_data *tpg) |
| 613 |
{ |
| 614 |
return tpg->vid_aspect; |
| 615 |
} |
| 616 |
|
| 617 |
static inline void tpg_s_pixel_aspect(struct tpg_data *tpg, |
| 618 |
enum tpg_pixel_aspect pix_aspect) |
| 619 |
{ |
| 620 |
if (tpg->pix_aspect == pix_aspect) |
| 621 |
return; |
| 622 |
tpg->pix_aspect = pix_aspect; |
| 623 |
tpg->recalc_square_border = true; |
| 624 |
} |
| 625 |
|
| 626 |
static inline void tpg_s_show_border(struct tpg_data *tpg, |
| 627 |
bool show_border) |
| 628 |
{ |
| 629 |
tpg->show_border = show_border; |
| 630 |
} |
| 631 |
|
| 632 |
static inline void tpg_s_show_square(struct tpg_data *tpg, |
| 633 |
bool show_square) |
| 634 |
{ |
| 635 |
tpg->show_square = show_square; |
| 636 |
} |
| 637 |
|
| 638 |
static inline void tpg_s_insert_sav(struct tpg_data *tpg, bool insert_sav) |
| 639 |
{ |
| 640 |
tpg->insert_sav = insert_sav; |
| 641 |
} |
| 642 |
|
| 643 |
static inline void tpg_s_insert_eav(struct tpg_data *tpg, bool insert_eav) |
| 644 |
{ |
| 645 |
tpg->insert_eav = insert_eav; |
| 646 |
} |
| 647 |
|
| 648 |
/* |
| 649 |
* This inserts 4 pixels of the RGB color 0xab55ab at the left hand side of the |
| 650 |
* image. This is only done for 3 or 4 byte RGB pixel formats. This pixel value |
| 651 |
* equals the Video Guard Band value as defined by HDMI (see section 5.2.2.1 |
| 652 |
* in the HDMI 1.3 Specification) that preceeds the first actual pixel. If the |
| 653 |
* HDMI receiver doesn't handle this correctly, then it might keep skipping |
| 654 |
* these Video Guard Band patterns and end up with a shorter video line. So this |
| 655 |
* is a nice pattern to test with. |
| 656 |
*/ |
| 657 |
static inline void tpg_s_insert_hdmi_video_guard_band(struct tpg_data *tpg, |
| 658 |
bool insert_hdmi_video_guard_band) |
| 659 |
{ |
| 660 |
tpg->insert_hdmi_video_guard_band = insert_hdmi_video_guard_band; |
| 661 |
} |
| 662 |
|
| 663 |
void tpg_update_mv_step(struct tpg_data *tpg); |
| 664 |
|
| 665 |
static inline void tpg_s_mv_hor_mode(struct tpg_data *tpg, |
| 666 |
enum tpg_move_mode mv_hor_mode) |
| 667 |
{ |
| 668 |
tpg->mv_hor_mode = mv_hor_mode; |
| 669 |
tpg_update_mv_step(tpg); |
| 670 |
} |
| 671 |
|
| 672 |
static inline void tpg_s_mv_vert_mode(struct tpg_data *tpg, |
| 673 |
enum tpg_move_mode mv_vert_mode) |
| 674 |
{ |
| 675 |
tpg->mv_vert_mode = mv_vert_mode; |
| 676 |
tpg_update_mv_step(tpg); |
| 677 |
} |
| 678 |
|
| 679 |
static inline void tpg_init_mv_count(struct tpg_data *tpg) |
| 680 |
{ |
| 681 |
tpg->mv_hor_count = tpg->mv_vert_count = 0; |
| 682 |
} |
| 683 |
|
| 684 |
static inline void tpg_update_mv_count(struct tpg_data *tpg, bool frame_is_field) |
| 685 |
{ |
| 686 |
tpg->mv_hor_count += tpg->mv_hor_step * (frame_is_field ? 1 : 2); |
| 687 |
tpg->mv_vert_count += tpg->mv_vert_step * (frame_is_field ? 1 : 2); |
| 688 |
} |
| 689 |
|
| 690 |
static inline void tpg_s_hflip(struct tpg_data *tpg, bool hflip) |
| 691 |
{ |
| 692 |
if (tpg->hflip == hflip) |
| 693 |
return; |
| 694 |
tpg->hflip = hflip; |
| 695 |
tpg_update_mv_step(tpg); |
| 696 |
tpg->recalc_lines = true; |
| 697 |
} |
| 698 |
|
| 699 |
static inline bool tpg_g_hflip(const struct tpg_data *tpg) |
| 700 |
{ |
| 701 |
return tpg->hflip; |
| 702 |
} |
| 703 |
|
| 704 |
static inline void tpg_s_vflip(struct tpg_data *tpg, bool vflip) |
| 705 |
{ |
| 706 |
tpg->vflip = vflip; |
| 707 |
} |
| 708 |
|
| 709 |
static inline bool tpg_g_vflip(const struct tpg_data *tpg) |
| 710 |
{ |
| 711 |
return tpg->vflip; |
| 712 |
} |
| 713 |
|
| 714 |
static inline bool tpg_pattern_is_static(const struct tpg_data *tpg) |
| 715 |
{ |
| 716 |
return tpg->pattern != TPG_PAT_NOISE && |
| 717 |
tpg->mv_hor_mode == TPG_MOVE_NONE && |
| 718 |
tpg->mv_vert_mode == TPG_MOVE_NONE; |
| 719 |
} |
| 720 |
|
| 721 |
#endif |