deinterlace_pd.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. /*
  2. * Amlogic M2
  3. * frame buffer driver-----------Deinterlace
  4. * Copyright (C) 2010 Amlogic, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the named License,
  9. * or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #include <linux/version.h>
  18. #include <linux/module.h>
  19. #include <linux/types.h>
  20. #include <linux/kernel.h>
  21. #include <linux/kthread.h>
  22. #include <linux/semaphore.h>
  23. #include <linux/workqueue.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/delay.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/fs.h>
  28. #include <linux/init.h>
  29. #include <linux/device.h>
  30. #include <linux/mm.h>
  31. #include <linux/major.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/mutex.h>
  34. #include <linux/cdev.h>
  35. #include <linux/proc_fs.h>
  36. #include <linux/list.h>
  37. #include <asm/uaccess.h>
  38. #include <mach/am_regs.h>
  39. #include <linux/osd/osd_dev.h>
  40. #include <linux/amports/vframe.h>
  41. #include <linux/amports/vframe_provider.h>
  42. #include <linux/amports/vframe_receiver.h>
  43. #include <linux/amports/canvas.h>
  44. #include "deinterlace.h"
  45. #include "deinterlace_module.h"
  46. #define PATTERN32_NUM 2
  47. #define PATTERN22_NUM 32
  48. #if (PATTERN22_NUM < 32)
  49. #define PATTERN22_MARK ((1LL<<PATTERN22_NUM)-1)
  50. #elif (PATTERN22_NUM < 64)
  51. #define PATTERN22_MARK ((0x100000000LL<<(PATTERN22_NUM-32))-1)
  52. #else
  53. #define PATTERN22_MARK 0xffffffffffffffffLL
  54. #endif
  55. static int pattern_len[MAX_WIN_NUM+1] = {0, 0, 0, 0, 0, 0};
  56. static int di_p32_counter[MAX_WIN_NUM+1] = {0, 0, 0, 0, 0, 0};
  57. static unsigned int last_big_frame_diff[MAX_WIN_NUM+1] = {0, 0, 0, 0, 0, 0};
  58. static unsigned int last_big_frame_diff_num[MAX_WIN_NUM+1] = {0, 0, 0, 0, 0, 0};
  59. static unsigned long long di_p32_info[MAX_WIN_NUM+1], di_p22_info[MAX_WIN_NUM+1], di_p32_info_2[MAX_WIN_NUM+1], di_p22_info_2[MAX_WIN_NUM+1];
  60. void reset_pulldown_state(void)
  61. {
  62. int ii;
  63. for(ii=0; ii<(MAX_WIN_NUM+1); ii++){
  64. pattern_len[ii] = 0;
  65. di_p32_counter[ii] = 0;
  66. last_big_frame_diff[ii] = 0;
  67. last_big_frame_diff_num[ii] = 0;
  68. di_p32_info[ii] = 0;
  69. di_p32_info_2[ii] = 0;
  70. di_p22_info[ii] = 0;
  71. di_p22_info_2[ii] = 0;
  72. }
  73. reset_pd_his();
  74. reset_pd32_status();
  75. }
  76. void cal_pd_parameters(pulldown_detect_info_t* cur_info, pulldown_detect_info_t* pre_info, pulldown_detect_info_t* next_info,
  77. pd_detect_threshold_t* pd_th)
  78. {
  79. cur_info->frame_diff_skew =
  80. cur_info->frame_diff>pre_info->frame_diff ? cur_info->frame_diff-pre_info->frame_diff :
  81. pre_info->frame_diff-cur_info->frame_diff;
  82. cur_info->frame_diff_num_skew =
  83. cur_info->frame_diff_num>pre_info->frame_diff_num ? cur_info->frame_diff_num-pre_info->frame_diff_num :
  84. pre_info->frame_diff_num-cur_info->frame_diff_num;
  85. cur_info->field_diff_by_pre = (cur_info->field_diff==0)?0xff:pre_info->field_diff/cur_info->field_diff;
  86. cur_info->field_diff_by_next = (cur_info->field_diff==0)?0xff:next_info->field_diff/cur_info->field_diff;
  87. cur_info->field_diff_num_by_pre = (cur_info->field_diff_num==0)?0xff:pre_info->field_diff_num/cur_info->field_diff_num;
  88. cur_info->field_diff_num_by_next = (cur_info->field_diff_num==0)?0xff:next_info->field_diff_num/cur_info->field_diff_num;
  89. cur_info->frame_diff_by_pre = (cur_info->frame_diff==0)?0xff:pre_info->frame_diff/cur_info->frame_diff;
  90. cur_info->frame_diff_num_by_pre = (cur_info->frame_diff_num==0)?0xff:pre_info->frame_diff_num/cur_info->frame_diff_num;
  91. cur_info->frame_diff_skew_ratio = (cur_info->frame_diff_skew==0)?0xff:cur_info->frame_diff/cur_info->frame_diff_skew;
  92. cur_info->frame_diff_num_skew_ratio = (cur_info->frame_diff_num_skew==0)?0xff:cur_info->frame_diff_num/cur_info->frame_diff_num_skew;
  93. if( cur_info->field_diff_by_pre > 0xff) cur_info->field_diff_by_pre = 0xff;
  94. if( cur_info->field_diff_by_next > 0xff) cur_info->field_diff_by_next = 0xff;
  95. if( cur_info->field_diff_num_by_pre > 0xff) cur_info->field_diff_num_by_pre = 0xff;
  96. if( cur_info->field_diff_num_by_next > 0xff) cur_info->field_diff_num_by_next = 0xff;
  97. if( cur_info->frame_diff_by_pre > 0xff) cur_info->frame_diff_by_pre = 0xff;
  98. if( cur_info->frame_diff_num_by_pre > 0xff) cur_info->frame_diff_num_by_pre = 0xff;
  99. if( cur_info->frame_diff_skew_ratio > 0xff) cur_info->frame_diff_skew_ratio = 0xff;
  100. if( cur_info->frame_diff_num_skew_ratio > 0xff) cur_info->frame_diff_num_skew_ratio = 0xff;
  101. cur_info->field_diff_pattern = pre_info->field_diff_pattern<<1;
  102. cur_info->field_diff_num_pattern = pre_info->field_diff_num_pattern<<1;
  103. cur_info->frame_diff_pattern = pre_info->frame_diff_pattern<<1;
  104. cur_info->frame_diff_num_pattern = pre_info->frame_diff_num_pattern<<1;
  105. if(( cur_info->field_diff_by_pre > pd_th->field_diff_chg_th) &&
  106. ( cur_info->field_diff_by_next > pd_th->field_diff_chg_th)
  107. ){
  108. cur_info->field_diff_pattern |= 1;
  109. }
  110. if(( cur_info->field_diff_num_by_pre > pd_th->field_diff_num_chg_th) &&
  111. ( cur_info->field_diff_num_by_next > pd_th->field_diff_num_chg_th)
  112. ){
  113. cur_info->field_diff_num_pattern |= 1;
  114. }
  115. if( cur_info->frame_diff_by_pre > pd_th->frame_diff_chg_th){
  116. cur_info->frame_diff_pattern |= 1;
  117. }
  118. if( cur_info->frame_diff_num_by_pre > pd_th->frame_diff_num_chg_th){
  119. cur_info->frame_diff_num_pattern |= 1;
  120. }
  121. }
  122. static int check_p32_p22(pulldown_detect_info_t* cur_info, pulldown_detect_info_t* pre_info, pulldown_detect_info_t* pre2_info,
  123. pd_detect_threshold_t* pd_th,int idx)
  124. {
  125. di_p22_info[idx] = di_p22_info[idx] << 1;
  126. di_p22_info_2[idx] = di_p22_info_2[idx] << 1;
  127. di_p32_info[idx] = di_p32_info[idx] << 1;
  128. di_p32_info_2[idx] = di_p32_info_2[idx] << 1;
  129. if ( cur_info->field_diff*pd_th->field_diff_chg_th <= pre_info->field_diff &&
  130. pre2_info->field_diff*pd_th->field_diff_chg_th <= pre_info->field_diff &&
  131. cur_info->field_diff_num*pd_th->field_diff_num_chg_th <= pre_info->field_diff_num &&
  132. pre2_info->field_diff_num*pd_th->field_diff_num_chg_th <= pre_info->field_diff_num ){
  133. di_p22_info[idx] |= 1;
  134. }
  135. if ( (di_p22_info[idx] & 0x1) && cur_info->frame_diff_skew*pd_th->frame_diff_skew_th <= cur_info->frame_diff
  136. && cur_info->frame_diff_num_skew*pd_th->frame_diff_num_skew_th <= cur_info->frame_diff_num ){
  137. di_p22_info_2[idx] |= 1;
  138. }
  139. if ( di_p32_counter[idx] > 0 || di_p32_info[idx] == 0 )
  140. {
  141. if ( cur_info->frame_diff*pd_th->frame_diff_chg_th <= pre_info->frame_diff &&
  142. cur_info->frame_diff_num*pd_th->frame_diff_num_chg_th <= pre_info->frame_diff_num )
  143. {
  144. di_p32_info[idx] |= 1;
  145. last_big_frame_diff[idx] = pre_info->frame_diff;
  146. last_big_frame_diff_num[idx] = pre_info->frame_diff_num;
  147. di_p32_counter[idx] = -1;
  148. }
  149. else
  150. {
  151. last_big_frame_diff[idx] = 0;
  152. last_big_frame_diff_num[idx] = 0;
  153. if ( (di_p32_counter[idx] & 0x1) && cur_info->frame_diff_skew*pd_th->frame_diff_skew_th <= cur_info->frame_diff
  154. && cur_info->frame_diff_num_skew*pd_th->frame_diff_num_skew_th <= cur_info->frame_diff_num )
  155. di_p32_info_2[idx] |= 1;
  156. }
  157. }
  158. else
  159. {
  160. if ( cur_info->frame_diff*pd_th->frame_diff_chg_th <= last_big_frame_diff[idx] &&
  161. cur_info->frame_diff_num*pd_th->frame_diff_num_chg_th <= last_big_frame_diff_num[idx] )
  162. {
  163. di_p32_info[idx] |= 1;
  164. di_p32_counter[idx] = -1;
  165. }
  166. }
  167. di_p32_counter[idx]++;
  168. return 0;
  169. }
  170. 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,
  171. int* pre_pulldown_mode, int* pre2_pulldown_mode, int* type,
  172. pd_detect_threshold_t* pd_th)
  173. {
  174. check_p32_p22(cur_info, pre_info, pre2_info, pd_th, idx);
  175. *pre_pulldown_mode = -1;
  176. if ( ((di_p22_info[idx] & PATTERN22_MARK) == (0x5555555555555555LL & PATTERN22_MARK))
  177. && ((di_p22_info_2[idx] & PATTERN22_MARK) == (0x5555555555555555LL & PATTERN22_MARK)) )
  178. {
  179. *pre_pulldown_mode = 1;
  180. *type = 0;
  181. }
  182. else if ( ((di_p22_info[idx] & PATTERN22_MARK) == (0xaaaaaaaaaaaaaaaaLL & PATTERN22_MARK))
  183. && ((di_p22_info_2[idx] & PATTERN22_MARK) == (0xaaaaaaaaaaaaaaaaLL & PATTERN22_MARK)) )
  184. {
  185. *pre_pulldown_mode = 0;
  186. *type=0;
  187. }
  188. else if ( pattern_len[idx] == 0 ){
  189. if(pre2_pulldown_mode)
  190. *pre2_pulldown_mode = -1;
  191. }
  192. if ( pattern_len[idx] == 0 )
  193. {
  194. int i, j, pattern, pattern_2, mask;
  195. for ( j = 5 ; j < 22 ; j++ )
  196. {
  197. mask = (1<<j) - 1;
  198. pattern = di_p32_info[idx] & mask;
  199. pattern_2 = di_p32_info_2[idx] & mask;
  200. if ( pattern != 0 && pattern_2 != 0 && pattern != mask )
  201. {
  202. for ( i = j ; i < j*PATTERN32_NUM ; i += j )
  203. if ( ((di_p32_info[idx]>>i) & mask) != pattern || ((di_p32_info_2[idx]>>i) & mask) != pattern_2 )
  204. break;
  205. if ( i == j*PATTERN32_NUM )
  206. {
  207. if ( (pattern_len[idx] == 5) && ((pattern & (pattern-1)) == 0) )
  208. {
  209. if ( (di_p32_info[idx] & 0x1) || (di_p32_info[idx] & 0x2) || (di_p32_info[idx] & 0x8) )
  210. *pre_pulldown_mode = 0;
  211. else
  212. *pre_pulldown_mode = 1;
  213. *type = 1;
  214. }
  215. else
  216. {
  217. if ( (pattern & (pattern-1)) != 0 )
  218. {
  219. if ( cur_info->field_diff_num < pre_info->field_diff_num )
  220. *pre_pulldown_mode = 1;
  221. else
  222. *pre_pulldown_mode = 0;
  223. *type=1;
  224. }
  225. }
  226. pattern_len[idx] = j;
  227. break;
  228. }
  229. }
  230. }
  231. }
  232. else
  233. {
  234. int i, pattern, pattern_2, mask;
  235. mask = (1<<pattern_len[idx]) - 1;
  236. pattern = di_p32_info[idx] & mask;
  237. pattern_2 = di_p32_info_2[idx] & mask;
  238. for ( i = pattern_len[idx] ; i < pattern_len[idx]*PATTERN32_NUM ; i += pattern_len[idx] )
  239. if ( ((di_p32_info[idx]>>i) & mask) != pattern || ((di_p32_info_2[idx]>>i) & mask) != pattern_2 )
  240. break;
  241. if ( i == pattern_len[idx]*PATTERN32_NUM ) //// if is pal and tuner input ,set unenable
  242. {
  243. if ( (pattern_len[idx] == 5) && ((pattern & (pattern-1)) == 0) )
  244. {
  245. if ( (di_p32_info[idx] & 0x1) || (di_p32_info[idx] & 0x2) || (di_p32_info[idx] & 0x8) )
  246. *pre_pulldown_mode = 0;
  247. else
  248. *pre_pulldown_mode = 1;
  249. *type=1;
  250. }
  251. else
  252. {
  253. if ( (pattern & (pattern-1)) != 0 )
  254. {
  255. if ( cur_info->field_diff_num < pre_info->field_diff_num )
  256. *pre_pulldown_mode = 1;
  257. else
  258. *pre_pulldown_mode = 0;
  259. *type=1;
  260. }
  261. }
  262. }
  263. else
  264. {
  265. pattern_len[idx] = 0;
  266. if(pre2_pulldown_mode)
  267. *pre2_pulldown_mode = -1;
  268. }
  269. }
  270. }
  271. /* new PD algorithm */
  272. #define PD_HIS_NUM 1024
  273. typedef struct{
  274. unsigned frame_diff;
  275. unsigned frame_diff_num;
  276. unsigned field_diff;
  277. unsigned field_diff_num;
  278. }pd_his_t;
  279. static pd_his_t pd_his_pool[PD_HIS_NUM*2];
  280. static unsigned pd_his_wr_pos = 0;
  281. static unsigned pd_his_size = 0;
  282. #define pd_his(i, pattern_len) (&pd_his_pool[pd_his_wr_pos+PD_HIS_NUM-pattern_len+i])
  283. void reset_pd_his(void)
  284. {
  285. pd_his_wr_pos = 0;
  286. pd_his_size = 0;
  287. }
  288. void insert_pd_his(pulldown_detect_info_t* pd_info)
  289. {
  290. pd_his_t* phis = &pd_his_pool[pd_his_wr_pos];
  291. phis->frame_diff = (phis+PD_HIS_NUM)->frame_diff = pd_info->frame_diff;
  292. phis->frame_diff_num = (phis+PD_HIS_NUM)->frame_diff_num = pd_info->frame_diff_num;
  293. phis->field_diff = (phis+PD_HIS_NUM)->field_diff = pd_info->field_diff;
  294. phis->field_diff_num = (phis+PD_HIS_NUM)->field_diff_num = pd_info->field_diff_num;
  295. pd_his_wr_pos++;
  296. if(pd_his_wr_pos >= PD_HIS_NUM){
  297. pd_his_wr_pos = 0;
  298. }
  299. if(pd_his_size < PD_HIS_NUM){
  300. pd_his_size++;
  301. }
  302. }
  303. /* algorithm to detect pd32 */
  304. unsigned int pd32_match_num=0x10;
  305. unsigned int pd32_diff_num_0_th=1;
  306. unsigned int pd32_match_num_th;
  307. unsigned int pd32_debug_th =0;
  308. unsigned int pd22_th = 0x3;
  309. unsigned int pd22_num_th = 0x5;
  310. unsigned int pd22_match_num = 0x5;
  311. /* ...
  312. A-odd
  313. A-even
  314. A-odd cur_pd32_status = 1
  315. B-even cur_pd32_status = 2
  316. B-odd cur_pd32_status = 3
  317. C-even cur_pd32_status = 4
  318. C-odd cur_pd32_status = 5
  319. C-even cur_pd32_status = 1
  320. D-odd
  321. D-even
  322. ...
  323. */
  324. static int cur_pd22_status = 0;
  325. static int cur_pd32_status = 0;
  326. static unsigned int last_small_frame_diff_num =0;
  327. static unsigned int pattern_match_count = 0;
  328. static unsigned int pd32_diff_num_0_count = 0;
  329. static unsigned int pd22_num = 0 ;
  330. void reset_pd32_status(void)
  331. {
  332. cur_pd22_status = 0;
  333. cur_pd32_status = 0;
  334. last_small_frame_diff_num = 0;
  335. pattern_match_count = 0;
  336. pd32_diff_num_0_count = 0;
  337. /**/
  338. pd32_match_num_th = pd32_match_num;
  339. }
  340. int detect_pd32(void)
  341. {
  342. int blend_mode = -1;
  343. int i, ii;
  344. pd_his_t* phis;
  345. pd_his_t* phis_22;
  346. unsigned pd22_pattern_len = pd22_match_num*4;
  347. unsigned pd32_pattern_len = pd32_match_num*5;
  348. /*
  349. phis_22 = pd_his(pd22_pattern_len-1,pd22_pattern_len);
  350. if (pd22_th==0xff)
  351. {
  352. printk("phis_22->field_diff_num = %08x\n",phis_22->field_diff_num );
  353. }
  354. if (phis_22->field_diff_num >((phis_22-1)->field_diff_num*pd22_th)){
  355. blend_mode = 1;
  356. for (ii = 0; ii < (pd22_pattern_len>>1) ; ii ++){
  357. if (((phis_22-2*ii)->field_diff_num <= ((phis_22-2*ii-1)->field_diff_num * pd22_th)) ||
  358. (((phis_22-2*ii-1)->field_diff_num *pd22_th) > (phis_22-2*(ii+1))->field_diff_num)) {
  359. blend_mode = -1;
  360. break;
  361. }
  362. }
  363. }
  364. else if ((phis_22->field_diff_num*pd22_th) <=(phis_22-1)->field_diff_num)
  365. {
  366. blend_mode = 0;
  367. for (ii = 0; ii < (pd22_pattern_len>>1) ; ii ++){
  368. if ((((phis_22-2*ii)->field_diff_num * pd22_th ) > (phis_22-2*ii-1)->field_diff_num ) ||
  369. (((phis_22-2*ii-1)->field_diff_num) <=(( phis_22-2*ii-2)->field_diff_num * pd22_th))) {
  370. blend_mode = -1;
  371. break;
  372. }
  373. }
  374. }
  375. else
  376. {
  377. blend_mode = -1;
  378. */
  379. if(cur_pd32_status){
  380. phis = pd_his(pd32_pattern_len-1,pd32_pattern_len);
  381. cur_pd32_status++;
  382. if(cur_pd32_status>5){
  383. cur_pd32_status=1;
  384. }
  385. if(cur_pd32_status>1){
  386. if(pattern_match_count==pd32_match_num_th){
  387. if(phis->frame_diff_num<last_small_frame_diff_num){
  388. pattern_match_count--;
  389. if(pattern_match_count<pd32_match_num_th){
  390. reset_pd32_status();
  391. }
  392. }
  393. }
  394. }
  395. else{
  396. unsigned tmp_count;
  397. if(pattern_match_count>pd32_match_num_th){
  398. for(ii=1;ii<5;ii++){
  399. if((phis-ii)->frame_diff_num <= (phis-5)->frame_diff_num)
  400. break;
  401. }
  402. if(ii<5){
  403. pattern_match_count--;
  404. }
  405. }
  406. tmp_count=phis->frame_diff_num;
  407. for(ii=1;ii<5;ii++){
  408. if((phis-ii)->frame_diff_num <= phis->frame_diff_num)
  409. break;
  410. tmp_count+=(phis-ii)->frame_diff_num;
  411. }
  412. if((tmp_count==0)&&(ii==5)){
  413. pd32_diff_num_0_count++;
  414. if(pd32_diff_num_0_count>pd32_match_num){
  415. pd32_diff_num_0_count=pd32_match_num;
  416. }
  417. }
  418. else{
  419. if(pd32_diff_num_0_count>0){
  420. pd32_diff_num_0_count--;
  421. }
  422. }
  423. if(ii<5){
  424. pattern_match_count--;
  425. }
  426. else{
  427. pattern_match_count++;
  428. if(pattern_match_count>pd32_match_num){
  429. pattern_match_count=pd32_match_num;
  430. }
  431. }
  432. if((pattern_match_count<pd32_match_num_th)
  433. ||(pd32_diff_num_0_count>pd32_diff_num_0_th)){
  434. reset_pd32_status();
  435. }
  436. if(cur_pd32_status>0){
  437. last_small_frame_diff_num = phis->frame_diff_num;
  438. }
  439. }
  440. }
  441. if((cur_pd32_status==0)&&(pd_his_size>=pd32_pattern_len)){
  442. phis = pd_his(0,pd32_pattern_len);
  443. pd32_diff_num_0_count = 0;
  444. pattern_match_count=0;
  445. for( i=0; i<pd32_pattern_len; i+=5){
  446. unsigned tmp_count=(phis+4)->frame_diff_num;
  447. for(ii=0;ii<4;ii++){
  448. if((phis+ii)->frame_diff_num < ((phis+4)->frame_diff_num)<<1)
  449. break;
  450. tmp_count+=(phis+ii)->frame_diff_num;
  451. }
  452. if((tmp_count==0)&&(ii==4)){
  453. pd32_diff_num_0_count++;
  454. }
  455. if(ii==4){
  456. if((i+5)<pd32_pattern_len){
  457. for(ii=0;ii<4;ii++){
  458. if((phis+5+ii)->frame_diff_num < ((phis+4)->frame_diff_num)<<1)
  459. break;
  460. }
  461. if(ii==4){
  462. pattern_match_count++;
  463. }
  464. }
  465. else{
  466. pattern_match_count++;
  467. }
  468. }
  469. phis+=5;
  470. }
  471. if((pattern_match_count>=pd32_match_num_th)
  472. &&(pd32_diff_num_0_count<=pd32_diff_num_0_th)){
  473. cur_pd32_status = 1;
  474. last_small_frame_diff_num = pd_his(pd32_pattern_len-1,pd32_pattern_len)->frame_diff_num;
  475. }
  476. }
  477. if(cur_pd32_status > 0){
  478. if(cur_pd32_status==2 || cur_pd32_status==4){
  479. blend_mode=1; //blend with next
  480. }
  481. else{
  482. blend_mode=0; //blend with pervious
  483. }
  484. }
  485. // }
  486. return blend_mode;
  487. }