v4l2-tpg.h 16 KB

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