deinterlace.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #ifndef _DI_H
  2. #define _DI_H
  3. /************************************
  4. * di hardware level interface
  5. *************************************/
  6. #define WIN_SIZE_FACTOR 100
  7. #define PD32_PAR_NUM 6
  8. #define PD22_PAR_NUM 6
  9. #define MAX_WIN_NUM 5
  10. typedef struct{
  11. unsigned field_diff; /* total pixels difference between current field and previous field */
  12. unsigned field_diff_num; /* the number of pixels with big difference between current field and previous field */
  13. unsigned frame_diff; /* total pixels difference between current field and previouse-previouse field */
  14. unsigned frame_diff_num; /* the number of pixels with big difference between current field and previouse-previous field */
  15. /**/
  16. unsigned frame_diff_skew; /* the difference between current frame_diff and previous frame_diff */
  17. unsigned frame_diff_num_skew; /* the difference between current frame_diff_num and previous frame_diff_num */
  18. /* parameters for detection */
  19. unsigned field_diff_by_pre;
  20. unsigned field_diff_by_next;
  21. unsigned field_diff_num_by_pre;
  22. unsigned field_diff_num_by_next;
  23. unsigned frame_diff_by_pre;
  24. unsigned frame_diff_num_by_pre;
  25. unsigned frame_diff_skew_ratio;
  26. unsigned frame_diff_num_skew_ratio;
  27. /* matching pattern */
  28. unsigned field_diff_pattern;
  29. unsigned field_diff_num_pattern;
  30. unsigned frame_diff_pattern;
  31. unsigned frame_diff_num_pattern;
  32. }pulldown_detect_info_t;
  33. typedef struct{
  34. /*
  35. if frame_diff < threshold, cur_field and pre_pre_field is top/bot or bot/top;
  36. if field_diff < threshold, cur_field and pre_field is top/bot or bot/top;
  37. */
  38. unsigned frame_diff_chg_th;
  39. unsigned frame_diff_num_chg_th;
  40. unsigned field_diff_chg_th;
  41. unsigned field_diff_num_chg_th;
  42. /*
  43. if frame_diff_skew < threshold, pre_field/cur_filed is top/bot
  44. */
  45. unsigned frame_diff_skew_th;
  46. unsigned frame_diff_num_skew_th;
  47. /*
  48. */
  49. unsigned field_diff_num_th;
  50. }pd_detect_threshold_t;
  51. typedef struct{
  52. uint win_start_x_r;
  53. uint win_end_x_r;
  54. uint win_start_y_r;
  55. uint win_end_y_r;
  56. uint win_32lvl;
  57. uint win_22lvl;
  58. uint pixels_num;
  59. }pd_win_prop_t;
  60. extern uint ei_ctrl0;
  61. extern uint ei_ctrl1;
  62. extern uint ei_ctrl2;
  63. extern uint nr_ctrl0;
  64. extern uint nr_ctrl1;
  65. extern uint nr_ctrl2;
  66. extern uint nr_ctrl3;
  67. extern uint mtn_ctrl;
  68. extern uint mtn_ctrl_char_diff_cnt;
  69. extern uint mtn_ctrl_low_level;
  70. extern uint mtn_ctrl_high_level;
  71. extern uint mtn_ctrl_diff_level;
  72. extern uint mtn_ctrl1;
  73. extern uint mtn_ctrl1_reduce;
  74. extern uint mtn_ctrl1_shift;
  75. extern uint blend_ctrl;
  76. extern uint kdeint0;
  77. extern uint kdeint1;
  78. extern uint kdeint2;
  79. extern uint reg_mtn_info0;
  80. extern uint reg_mtn_info1;
  81. extern uint reg_mtn_info2;
  82. extern uint reg_mtn_info3;
  83. extern uint reg_mtn_info4;
  84. extern uint mtn_thre_1_low;
  85. extern uint mtn_thre_1_high;
  86. extern uint mtn_thre_2_low;
  87. extern uint mtn_thre_2_high;
  88. extern uint blend_ctrl1;
  89. extern uint blend_ctrl1_char_level;
  90. extern uint blend_ctrl1_angle_thd;
  91. extern uint blend_ctrl1_filt_thd;
  92. extern uint blend_ctrl1_diff_thd;
  93. extern uint blend_ctrl2;
  94. extern uint blend_ctrl2_black_level;
  95. extern uint blend_ctrl2_mtn_no_mov;
  96. extern uint post_ctrl__di_blend_en;
  97. extern uint post_ctrl__di_post_repeat;
  98. extern uint di_pre_ctrl__di_pre_repeat;
  99. extern uint noise_reduction_level;
  100. extern uint field_32lvl;
  101. extern uint field_22lvl;
  102. extern pd_detect_threshold_t field_pd_th;
  103. extern pd_detect_threshold_t win_pd_th[MAX_WIN_NUM];
  104. extern pd_win_prop_t pd_win_prop[MAX_WIN_NUM];
  105. extern int pd_enable;
  106. extern void di_hw_init(void);
  107. extern void di_hw_uninit(void);
  108. extern int di_vscale_skip_count;
  109. /*
  110. di hardware internal
  111. */
  112. #if defined(CONFIG_AM_DEINTERLACE_SD_ONLY)
  113. #define MAX_CANVAS_WIDTH 720
  114. #define MAX_CANVAS_HEIGHT 576
  115. #else
  116. #define MAX_CANVAS_WIDTH 1920
  117. #define MAX_CANVAS_HEIGHT 1088
  118. #endif
  119. #define DI_BUF_NUM 6
  120. typedef struct DI_MIF_TYPE
  121. {
  122. unsigned short luma_x_start0;
  123. unsigned short luma_x_end0;
  124. unsigned short luma_y_start0;
  125. unsigned short luma_y_end0;
  126. unsigned short chroma_x_start0;
  127. unsigned short chroma_x_end0;
  128. unsigned short chroma_y_start0;
  129. unsigned short chroma_y_end0;
  130. unsigned set_separate_en : 1; // 1 : y cb cr seperated canvas. 0 : one canvas.
  131. unsigned src_field_mode : 1; // 1 frame . 0 field.
  132. unsigned video_mode : 1; // 1 : 4:4:4. 0 : 4:2:2
  133. unsigned output_field_num : 1; // 0 top field 1 bottom field.
  134. unsigned burst_size_y : 2;
  135. unsigned burst_size_cb : 2;
  136. unsigned burst_size_cr : 2;
  137. unsigned canvas0_addr0 : 8;
  138. unsigned canvas0_addr1 : 8;
  139. unsigned canvas0_addr2 : 8;
  140. } DI_MIF_t;
  141. typedef struct DI_SIM_MIF_TYPE
  142. {
  143. unsigned short start_x;
  144. unsigned short end_x;
  145. unsigned short start_y;
  146. unsigned short end_y;
  147. unsigned short canvas_num;
  148. } DI_SIM_MIF_t;
  149. void disable_deinterlace(void);
  150. void disable_pre_deinterlace(void);
  151. void disable_post_deinterlace(void);
  152. int get_di_pre_recycle_buf(void);
  153. void disable_post_deinterlace_2(void);
  154. void enable_di_mode_check_2 (
  155. int win0_start_x, int win0_end_x, int win0_start_y, int win0_end_y,
  156. int win1_start_x, int win1_end_x, int win1_start_y, int win1_end_y,
  157. int win2_start_x, int win2_end_x, int win2_start_y, int win2_end_y,
  158. int win3_start_x, int win3_end_x, int win3_start_y, int win3_end_y,
  159. int win4_start_x, int win4_end_x, int win4_start_y, int win4_end_y
  160. );
  161. void enable_di_pre_aml (
  162. DI_MIF_t *di_inp_mif,
  163. DI_MIF_t *di_mem_mif,
  164. DI_MIF_t *di_chan2_mif,
  165. DI_SIM_MIF_t *di_nrwr_mif,
  166. DI_SIM_MIF_t *di_mtnwr_mif,
  167. int nr_en, int mtn_en, int pd32_check_en, int pd22_check_en, int hist_check_en,
  168. int pre_field_num, int pre_viu_link, int hold_line
  169. );
  170. void enable_region_blend (
  171. int reg0_en, int reg0_start_x, int reg0_end_x, int reg0_start_y, int reg0_end_y, int reg0_mode,
  172. int reg1_en, int reg1_start_x, int reg1_end_x, int reg1_start_y, int reg1_end_y, int reg1_mode,
  173. int reg2_en, int reg2_start_x, int reg2_end_x, int reg2_start_y, int reg2_end_y, int reg2_mode,
  174. int reg3_en, int reg3_start_x, int reg3_end_x, int reg3_start_y, int reg3_end_y, int reg3_mode
  175. );
  176. void run_deinterlace(unsigned zoom_start_x_lines, unsigned zoom_end_x_lines, unsigned zoom_start_y_lines, unsigned zoom_end_y_lines,
  177. unsigned type, int mode, int hold_line);
  178. void deinterlace_init(void);
  179. void initial_di_pre_aml ( int hsize_pre, int vsize_pre, int hold_line );
  180. void initial_di_post_2 ( int hsize_post, int vsize_post, int hold_line ) ;
  181. void enable_di_post_2 (
  182. DI_MIF_t *di_buf0_mif,
  183. DI_MIF_t *di_buf1_mif,
  184. DI_SIM_MIF_t *di_diwr_mif,
  185. DI_SIM_MIF_t *di_mtncrd_mif,
  186. DI_SIM_MIF_t *di_mtnprd_mif,
  187. int ei_en, int blend_en, int blend_mtn_en, int blend_mode, int di_vpp_en, int di_ddr_en,
  188. int post_field_num, int hold_line ,
  189. unsigned long * reg_mtn_info);
  190. void enable_di_post_pd(
  191. DI_MIF_t *di_buf0_mif,
  192. DI_MIF_t *di_buf1_mif,
  193. DI_SIM_MIF_t *di_diwr_mif,
  194. DI_SIM_MIF_t *di_mtncrd_mif,
  195. DI_SIM_MIF_t *di_mtnprd_mif,
  196. int ei_en, int blend_en, int blend_mtn_en, int blend_mode, int di_vpp_en, int di_ddr_en,
  197. int post_field_num, int hold_line);
  198. void read_pulldown_info(pulldown_detect_info_t* field_pd_info,
  199. pulldown_detect_info_t* win_pd_info);
  200. void read_mtn_info(unsigned long* mtn_info, unsigned long* );
  201. void reset_pulldown_state(void);
  202. void cal_pd_parameters(pulldown_detect_info_t* cur_info, pulldown_detect_info_t* pre_info, pulldown_detect_info_t* next_info, pd_detect_threshold_t* pd_th);
  203. void pattern_check_pre_2(int idx, pulldown_detect_info_t* cur_info, pulldown_detect_info_t* pre_info, pulldown_detect_info_t* pre2_info,
  204. int* pre_pulldown_mode, int* pre2_pulldown_mode, int* type,
  205. pd_detect_threshold_t* pd_th);
  206. void reset_di_para(void);
  207. /* new pd algorithm */
  208. void reset_pd_his(void);
  209. void insert_pd_his(pulldown_detect_info_t* pd_info);
  210. void reset_pd32_status(void);
  211. int detect_pd32(void);
  212. extern unsigned int pd32_match_num;
  213. extern unsigned int pd32_debug_th;
  214. extern unsigned int pd32_diff_num_0_th;
  215. extern unsigned int pd22_th;
  216. extern unsigned int pd22_num_th;
  217. extern int nr_hfilt_en;
  218. #undef DI_DEBUG
  219. #define DI_LOG_MTNINFO 0x02
  220. #define DI_LOG_PULLDOWN 0x10
  221. #define DI_LOG_BUFFER_STATE 0x20
  222. #define DI_LOG_TIMESTAMP 0x100
  223. #define DI_LOG_PRECISE_TIMESTAMP 0x200
  224. #define DI_LOG_QUEUE 0x40
  225. extern unsigned int di_log_flag;
  226. int di_print(const char *fmt, ...);
  227. #endif