rowdiffscan.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. /****************************************************************************
  2. *
  3. * Module Title : RowDiffScan.c
  4. *
  5. * Description : Pre-processor row difference Scan
  6. *
  7. * AUTHOR : Paul Wilkins
  8. *
  9. *****************************************************************************
  10. * Revision History
  11. *
  12. * 1.00 JBB 22 AUG 00 Configuration baseline
  13. *
  14. *****************************************************************************
  15. */
  16. /****************************************************************************
  17. * Header Frames
  18. *****************************************************************************
  19. */
  20. #define STRICT /* Strict type checking. */
  21. #include "type_aliases.h"
  22. #include "preproc.h"
  23. /****************************************************************************
  24. * Module constants.
  25. *****************************************************************************
  26. /****************************************************************************
  27. *
  28. * ROUTINE : RowDiffScan
  29. *
  30. * INPUTS : UINT8 * YuvPtr1, YuvPtr2
  31. * Pointers into current and previous frame
  32. * BOOL EdgeRow
  33. * Is this row an edge row.
  34. *
  35. * OUTPUTS : UINT16 * YUVDiffsPtr
  36. * Differnece map
  37. * UINT8 * bits_map_ptr
  38. * Pixels changed map
  39. * UINT8 * SgcPtr
  40. * Level change score.
  41. * INT8 * DispFragPtr
  42. * Block update map.
  43. * INT32 * RowDiffsPtr
  44. * Total sig changes for row
  45. * UINT8 * ChLocalsPtr
  46. * Changed locals data structure
  47. *
  48. *
  49. * RETURNS :
  50. *
  51. * FUNCTION : Initial pixel differences scan
  52. *
  53. * SPECIAL NOTES : None.
  54. *
  55. *
  56. * ERRORS : None.
  57. *
  58. ****************************************************************************/
  59. void RowDiffScan( PP_INSTANCE *ppi, UINT8 * YuvPtr1, UINT8 * YuvPtr2,
  60. INT16 * YUVDiffsPtr, UINT8 * bits_map_ptr,
  61. INT8 * SgcPtr, INT8 * DispFragPtr,
  62. UINT8 * FDiffPixels, INT32 * RowDiffsPtr,
  63. UINT8 * ChLocalsPtr, BOOL EdgeRow )
  64. {
  65. INT32 i;
  66. INT32 FragChangedPixels;
  67. INT16 Diff[8];
  68. UINT32 ZeroData[2] = { 0,0 };
  69. UINT8 OneData[8] = { 1,1,1,1,1,1,1,1 };
  70. UINT8 ChlocalsDummyData[8] = { 8,8,8,8,8,8,8,8 };
  71. // Cannot use kernel if at edge or if PAK disabled
  72. if ( (!ppi->PAKEnabled) || EdgeRow )
  73. {
  74. for ( i = 0; i < ppi->PlaneWidth; i += ppi->HFragPixels )
  75. {
  76. // Reset count of pixels changed for the current fragment.
  77. FragChangedPixels = 0;
  78. // Test for break out conditions to save time.
  79. if ((*DispFragPtr == CANDIDATE_BLOCK) )//|| !ppi->EarlyBreakAllowed)
  80. {
  81. __asm
  82. {
  83. movd esi, [YuvPtr1];
  84. movd ebx, [YuvPtr2];
  85. movd edx, FragChangedPixels
  86. pxor mm7, mm7;
  87. movq mm0, [esi] ;76543210
  88. movq mm1, [ebx] ;76543210
  89. movq mm2, mm0 ;make a copy
  90. movq mm3, mm1 ;make a copy
  91. punpcklbw mm0, mm7 ; 3 2 1 0
  92. punpcklbw mm1, mm7 ; 3 2 1 0
  93. punpckhbw mm2, mm7 ; 7 6 5 4
  94. punpckhbw mm3, mm7 ; 7 6 5 4
  95. psubw mm0 mm1 ; Diff[3,2,1,0]
  96. psubw mm2, mm3 ; Diff[7,6,5,4]
  97. movq QWORD PTR [YUVDiffsPtr], mm0
  98. movq QWORD PTR [YUVDiffsPtr], mm2
  99. ;------------------------------------------------------
  100. ; mm0, mm1, mm3, mm4, m5, mm6, mm7, Free
  101. ; mm2, keep the Diff[7 6 5 4]
  102. ;------------------------------------------------------
  103. movd eax, ppi->LevelThresh
  104. movd mm1, eax ;
  105. movd mm3, eax ;
  106. packsdw mm1, mm3 ;
  107. movq mm4, mm1 ;
  108. psllw mm1, 16
  109. por mm1, mm4 ;4 ppi->LevelThresh
  110. ;-------------------------------------------------------
  111. ; mm3, mm4, mm5, mm6, mm7 Free
  112. ;
  113. ;-------------------------------------------------------
  114. movd eax, ppi->SrfThresh
  115. movd mm3, eax ;
  116. movd mm4, eax ;
  117. packsdw mm3, mm4 ;
  118. movq mm5, mm3 ;
  119. psllw mm3, 16
  120. por mm3, mm6 ;4 ppi->SrfThresh
  121. ;--------------------------------------------------------
  122. ; mm0 mm2 diff[0]-diff[7]
  123. ; mm1 ppi->LevelThresh
  124. ; mm3 ppi->SrfThresh
  125. ; mm4-mm7 free
  126. ; Note, ppi->NegLevelThresh = - ppi->LevelThresh
  127. ; ppi->NegSrfThresh = - ppi->SrfThresh
  128. ;--------------------------------------------------------
  129. movq mm4, mm0 ; diff[0][1][2][3]
  130. movq mm5, mm0 ;
  131. psubsw mm4, mm1 ; if diff >= LevelThresh
  132. psraw mm4, 15 ; 00s(True) and ffs (False)
  133. pandn mm4, FFFFFFFFh ; ffs(True) and 00s (False)
  134. psrlw mm4, 15 ; 01 (True) and 00 (False)
  135. pcmpgtw mm5, mm3 ; if diff > SrfThresh
  136. ; ffs(True) and 00s (False)
  137. psrlw mm5, 15 ; 01 (True) and 00 (False)
  138. pand mm5, mm4 ;
  139. movq mm7, mm0 ; save a copy of diff[0][1][2][3]
  140. pxor mm6, mm6 ; clear MM6
  141. psubsw mm6, mm1 ; mm6 = NegLevelThresh
  142. pcmpgtw mm0, mm6 ; if diff > NegLevelThresh
  143. ; ffs(True) and 00s (False)
  144. pandn mm0, FFFFFFFFh ; if diff <= NegLevelThresh
  145. ; ffs(True) and 00 (False)
  146. psrlw mm0, 15 ; 01 (True) and 00 (False)
  147. paddsw mm7, mm3 ; if diff < -NegSrfThresh
  148. psraw mm7, 15 ; ffs(True) and 00s (False)
  149. psrlw mm7, 15 ; 01 (True) and 00s (False)
  150. pand mm7, mm0 ;
  151. ;----------------------------------------------------------------------------
  152. ; mm0, mm1, mm2, mm3, mm4, mm5, mm7 in use
  153. ; mm6 free
  154. ;----------------------------------------------------------------------------
  155. por mm5, mm7 ; mm7 is free now
  156. pxor mm6, mm6 ;
  157. movq mm7, mm5 ;
  158. punpcklwd mm5, mm6 ;
  159. punpckhwd mm7, mm6 ;
  160. paddw mm5, mm7 ;
  161. movq mm7, mm5 ;
  162. psrlq mm7, 32 ;
  163. paddd mm7, mm5 ;
  164. movd eax, mm7 ;
  165. add eax, ebx
  166. // Calculate the diference values and copy to YUVDiffsPtr
  167. Diff[0] = ((INT16)YuvPtr1[0]) - ((INT16)YuvPtr2[0]);
  168. Diff[1] = ((INT16)YuvPtr1[1]) - ((INT16)YuvPtr2[1]);
  169. Diff[2] = ((INT16)YuvPtr1[2]) - ((INT16)YuvPtr2[2]);
  170. Diff[3] = ((INT16)YuvPtr1[3]) - ((INT16)YuvPtr2[3]);
  171. ((INT32 *)YUVDiffsPtr)[0] = ((INT32 *)Diff)[0];
  172. ((INT32 *)YUVDiffsPtr)[1] = ((INT32 *)Diff)[1];
  173. // Test against the Level and ppi->SRF thresholds and record the results
  174. // Pixel 0
  175. if ( Diff[0] >= ppi->LevelThresh )
  176. {
  177. SgcPtr[0]++;
  178. if ( Diff[0] > ppi->SrfThresh )
  179. {
  180. bits_map_ptr[0] = 1;
  181. FragChangedPixels++;
  182. }
  183. }
  184. else if ( Diff[0] <= ppi->NegLevelThresh )
  185. {
  186. SgcPtr[0]--;
  187. if ( Diff[0] < ppi->NegSrfThresh )
  188. {
  189. bits_map_ptr[0] = 1;
  190. FragChangedPixels++;
  191. }
  192. }
  193. // Pixel 1
  194. if ( Diff[1] >= ppi->LevelThresh )
  195. {
  196. SgcPtr[0]++;
  197. if ( Diff[1] > ppi->SrfThresh )
  198. {
  199. bits_map_ptr[1] = 1;
  200. FragChangedPixels++;
  201. }
  202. }
  203. else if ( Diff[1] <= ppi->NegLevelThresh )
  204. {
  205. SgcPtr[0]--;
  206. if ( Diff[1] < ppi->NegSrfThresh )
  207. {
  208. bits_map_ptr[1] = 1;
  209. FragChangedPixels++;
  210. }
  211. }
  212. // Pixel 2
  213. if ( Diff[2] >= ppi->LevelThresh )
  214. {
  215. SgcPtr[0]++;
  216. if ( Diff[2] > ppi->SrfThresh )
  217. {
  218. bits_map_ptr[2] = 1;
  219. FragChangedPixels++;
  220. }
  221. }
  222. else if ( Diff[2] <= ppi->NegLevelThresh )
  223. {
  224. SgcPtr[0]--;
  225. if ( Diff[2] < ppi->NegSrfThresh )
  226. {
  227. bits_map_ptr[2] = 1;
  228. FragChangedPixels++;
  229. }
  230. }
  231. // Pixel 3
  232. if ( Diff[3] >= ppi->LevelThresh )
  233. {
  234. SgcPtr[0]++;
  235. if ( Diff[3] > ppi->SrfThresh )
  236. {
  237. bits_map_ptr[3] = 1;
  238. FragChangedPixels++;
  239. }
  240. }
  241. else if ( Diff[3] <= ppi->NegLevelThresh )
  242. {
  243. SgcPtr[0]--;
  244. if ( Diff[3] < ppi->NegSrfThresh )
  245. {
  246. bits_map_ptr[3] = 1;
  247. FragChangedPixels++;
  248. }
  249. }
  250. // Clear down entries in changed locals array
  251. ((UINT32 *)ChLocalsPtr)[0] = ((UINT32 *)ZeroData)[0];
  252. // Calculate the diference values and copy to YUVDiffsPtr
  253. Diff[4] = ((INT16)YuvPtr1[4]) - ((INT16)YuvPtr2[4]);
  254. Diff[5] = ((INT16)YuvPtr1[5]) - ((INT16)YuvPtr2[5]);
  255. Diff[6] = ((INT16)YuvPtr1[6]) - ((INT16)YuvPtr2[6]);
  256. Diff[7] = ((INT16)YuvPtr1[7]) - ((INT16)YuvPtr2[7]);
  257. ((INT32 *)YUVDiffsPtr)[2] = ((INT32 *)Diff)[2];
  258. ((INT32 *)YUVDiffsPtr)[3] = ((INT32 *)Diff)[3];
  259. // Test against the Level and ppi->SRF thresholds and record the results
  260. // Pixel 4
  261. if ( Diff[4] >= ppi->LevelThresh )
  262. {
  263. SgcPtr[0]++;
  264. if ( Diff[4] > ppi->SrfThresh )
  265. {
  266. bits_map_ptr[4] = 1;
  267. FragChangedPixels++;
  268. }
  269. }
  270. else if ( Diff[4] <= ppi->NegLevelThresh )
  271. {
  272. SgcPtr[0]--;
  273. if ( Diff[4] < ppi->NegSrfThresh )
  274. {
  275. bits_map_ptr[4] = 1;
  276. FragChangedPixels++;
  277. }
  278. }
  279. // Pixel 5
  280. if ( Diff[5] >= ppi->LevelThresh )
  281. {
  282. SgcPtr[0]++;
  283. if ( Diff[5] > ppi->SrfThresh )
  284. {
  285. bits_map_ptr[5] = 1;
  286. FragChangedPixels++;
  287. }
  288. }
  289. else if ( Diff[5] <= ppi->NegLevelThresh )
  290. {
  291. SgcPtr[0]--;
  292. if ( Diff[5] < ppi->NegSrfThresh )
  293. {
  294. bits_map_ptr[5] = 1;
  295. FragChangedPixels++;
  296. }
  297. }
  298. // Pixel 6
  299. if ( Diff[6] >= ppi->LevelThresh )
  300. {
  301. SgcPtr[0]++;
  302. if ( Diff[6] > ppi->SrfThresh )
  303. {
  304. bits_map_ptr[6] = 1;
  305. FragChangedPixels++;
  306. }
  307. }
  308. else if ( Diff[6] <= ppi->NegLevelThresh )
  309. {
  310. SgcPtr[0]--;
  311. if ( Diff[6] < ppi->NegSrfThresh )
  312. {
  313. bits_map_ptr[6] = 1;
  314. FragChangedPixels++;
  315. }
  316. }
  317. // Pixel 7
  318. if ( Diff[7] >= ppi->LevelThresh )
  319. {
  320. SgcPtr[0]++;
  321. if ( Diff[7] > ppi->SrfThresh )
  322. {
  323. bits_map_ptr[7] = 1;
  324. FragChangedPixels++;
  325. }
  326. }
  327. else if ( Diff[7] <= ppi->NegLevelThresh )
  328. {
  329. SgcPtr[0]--;
  330. if ( Diff[7] < ppi->NegSrfThresh )
  331. {
  332. bits_map_ptr[7] = 1;
  333. FragChangedPixels++;
  334. }
  335. }
  336. // Clear down entries in changed locals array
  337. ((UINT32 *)ChLocalsPtr)[1] = ((UINT32 *)ZeroData)[1];
  338. }
  339. else
  340. {
  341. // For EBO coded blocks mark all pixels as changed.
  342. if ( *DispFragPtr > BLOCK_NOT_CODED )
  343. {
  344. ((UINT32 *)bits_map_ptr)[0] = ((UINT32 *)OneData)[0];
  345. ((UINT32 *)ChLocalsPtr)[0] = ((UINT32 *)ChlocalsDummyData)[0];
  346. ((UINT32 *)bits_map_ptr)[1] = ((UINT32 *)OneData)[1];
  347. ((UINT32 *)ChLocalsPtr)[1] = ((UINT32 *)ChlocalsDummyData)[1];
  348. }
  349. else
  350. {
  351. ((UINT32 *)ChLocalsPtr)[0] = ((UINT32 *)ZeroData)[0];
  352. ((UINT32 *)ChLocalsPtr)[1] = ((UINT32 *)ZeroData)[1];
  353. }
  354. }
  355. *RowDiffsPtr += FragChangedPixels;
  356. *FDiffPixels += (UINT8)FragChangedPixels;
  357. YuvPtr1 += ppi->HFragPixels;
  358. YuvPtr2 += ppi->HFragPixels;
  359. bits_map_ptr += ppi->HFragPixels;
  360. ChLocalsPtr += ppi->HFragPixels;
  361. YUVDiffsPtr += ppi->HFragPixels;
  362. SgcPtr ++;
  363. FDiffPixels ++;
  364. // If we have a lot of changed pixels for this fragment on this row then
  365. // the fragment is almost sure to be picked (e.g. through the line search) so we
  366. // can mark it as selected and then ignore it.
  367. // if ( ppi->EarlyBreakAllowed )
  368. {
  369. if (FragChangedPixels >= 7)
  370. {
  371. *DispFragPtr = BLOCK_CODED;
  372. }
  373. }
  374. DispFragPtr++;
  375. }
  376. }
  377. else
  378. {
  379. for ( i = 0; i < ppi->PlaneWidth; i += ppi->HFragPixels )
  380. {
  381. // Reset count of pixels changed for the current fragment.
  382. FragChangedPixels = 0;
  383. // Test for break out conditions to save time.
  384. if ((*DispFragPtr == CANDIDATE_BLOCK) )//|| !ppi->EarlyBreakAllowed)
  385. {
  386. // Calculate the diference values and copy to YUVDiffsPtr
  387. Diff[0] = ((INT16)YuvPtr1[0]) - ((INT16)YuvPtr2[0]);
  388. Diff[1] = ((INT16)YuvPtr1[1]) - ((INT16)YuvPtr2[1]);
  389. Diff[2] = ((INT16)YuvPtr1[2]) - ((INT16)YuvPtr2[2]);
  390. Diff[3] = ((INT16)YuvPtr1[3]) - ((INT16)YuvPtr2[3]);
  391. ((INT32 *)YUVDiffsPtr)[0] = ((INT32 *)Diff)[0];
  392. ((INT32 *)YUVDiffsPtr)[1] = ((INT32 *)Diff)[1];
  393. // Test against the Level and ppi->SRF thresholds and record the results
  394. // Pixel 0
  395. if ( Diff[0] >= ppi->LevelThresh )
  396. {
  397. SgcPtr[0]++;
  398. // If the level change is still suspect then apply PAK kernel.
  399. if ( (Diff[0] > ppi->SrfThresh) && (Diff[0] <= ppi->HighChange) )
  400. Diff[0] = (int)ApplyPakLowPass( ppi, &YuvPtr1[0] ) -
  401. (int)ApplyPakLowPass( ppi, &YuvPtr2[0] );
  402. if ( Diff[0] > ppi->SrfThresh )
  403. {
  404. bits_map_ptr[0] = 1;
  405. FragChangedPixels++;
  406. }
  407. }
  408. else if ( Diff[0] <= ppi->NegLevelThresh )
  409. {
  410. SgcPtr[0]--;
  411. // If the level change is still suspect then apply PAK kernel.
  412. if ( (Diff[0] < ppi->NegSrfThresh) && (Diff[0] >= ppi->NegHighChange) )
  413. Diff[0] = (int)ApplyPakLowPass( ppi, &YuvPtr1[0] ) -
  414. (int)ApplyPakLowPass( ppi, &YuvPtr2[0] );
  415. if ( Diff[0] < ppi->NegSrfThresh )
  416. {
  417. bits_map_ptr[0] = 1;
  418. FragChangedPixels++;
  419. }
  420. }
  421. // Pixel 1
  422. if ( Diff[1] >= ppi->LevelThresh )
  423. {
  424. SgcPtr[0]++;
  425. // If the level change is still suspect then apply PAK kernel.
  426. if ( (Diff[1] > ppi->SrfThresh) && (Diff[1] <= ppi->HighChange) )
  427. Diff[1] = (int)ApplyPakLowPass( ppi, &YuvPtr1[1] ) -
  428. (int)ApplyPakLowPass( ppi, &YuvPtr2[1] );
  429. if ( Diff[1] > ppi->SrfThresh )
  430. {
  431. bits_map_ptr[1] = 1;
  432. FragChangedPixels++;
  433. }
  434. }
  435. else if ( Diff[1] <= ppi->NegLevelThresh )
  436. {
  437. SgcPtr[0]--;
  438. // If the level change is still suspect then apply PAK kernel.
  439. if ( (Diff[1] < ppi->NegSrfThresh) && (Diff[1] >= ppi->NegHighChange) )
  440. Diff[1] = (int)ApplyPakLowPass( ppi, &YuvPtr1[1] ) -
  441. (int)ApplyPakLowPass( ppi, &YuvPtr2[1] );
  442. if ( Diff[1] < ppi->NegSrfThresh )
  443. {
  444. bits_map_ptr[1] = 1;
  445. FragChangedPixels++;
  446. }
  447. }
  448. // Pixel 2
  449. if ( Diff[2] >= ppi->LevelThresh )
  450. {
  451. SgcPtr[0]++;
  452. // If the level change is still suspect then apply PAK kernel.
  453. if ( (Diff[2] > ppi->SrfThresh) && (Diff[2] <= ppi->HighChange) )
  454. Diff[2] = (int)ApplyPakLowPass( ppi, &YuvPtr1[2] ) -
  455. (int)ApplyPakLowPass( ppi, &YuvPtr2[2] );
  456. if ( Diff[2] > ppi->SrfThresh )
  457. {
  458. bits_map_ptr[2] = 1;
  459. FragChangedPixels++;
  460. }
  461. }
  462. else if ( Diff[2] <= ppi->NegLevelThresh )
  463. {
  464. SgcPtr[0]--;
  465. // If the level change is still suspect then apply PAK kernel.
  466. if ( (Diff[2] < ppi->NegSrfThresh) && (Diff[2] >= ppi->NegHighChange) )
  467. Diff[2] = (int)ApplyPakLowPass( ppi, &YuvPtr1[2] ) -
  468. (int)ApplyPakLowPass( ppi, &YuvPtr2[2] );
  469. if ( Diff[2] < ppi->NegSrfThresh )
  470. {
  471. bits_map_ptr[2] = 1;
  472. FragChangedPixels++;
  473. }
  474. }
  475. // Pixel 3
  476. if ( Diff[3] >= ppi->LevelThresh )
  477. {
  478. SgcPtr[0]++;
  479. // If the level change is still suspect then apply PAK kernel.
  480. if ( (Diff[3] > ppi->SrfThresh) && (Diff[3] <= ppi->HighChange) )
  481. Diff[3] = (int)ApplyPakLowPass( ppi, &YuvPtr1[3] ) -
  482. (int)ApplyPakLowPass( ppi, &YuvPtr2[3] );
  483. if ( Diff[3] > ppi->SrfThresh )
  484. {
  485. bits_map_ptr[3] = 1;
  486. FragChangedPixels++;
  487. }
  488. }
  489. else if ( Diff[3] <= ppi->NegLevelThresh )
  490. {
  491. SgcPtr[0]--;
  492. // If the level change is still suspect then apply PAK kernel.
  493. if ( (Diff[3] < ppi->NegSrfThresh) && (Diff[3] >= ppi->NegHighChange) )
  494. Diff[3] = (int)ApplyPakLowPass( ppi, &YuvPtr1[3] ) -
  495. (int)ApplyPakLowPass( ppi, &YuvPtr2[3] );
  496. if ( Diff[3] < ppi->NegSrfThresh )
  497. {
  498. bits_map_ptr[3] = 1;
  499. FragChangedPixels++;
  500. }
  501. }
  502. // Clear down entries in changed locals array
  503. ((UINT32 *)ChLocalsPtr)[0] = ((UINT32 *)ZeroData)[0];
  504. // Calculate the diference values and copy to YUVDiffsPtr
  505. Diff[4] = ((INT16)YuvPtr1[4]) - ((INT16)YuvPtr2[4]);
  506. Diff[5] = ((INT16)YuvPtr1[5]) - ((INT16)YuvPtr2[5]);
  507. Diff[6] = ((INT16)YuvPtr1[6]) - ((INT16)YuvPtr2[6]);
  508. Diff[7] = ((INT16)YuvPtr1[7]) - ((INT16)YuvPtr2[7]);
  509. ((INT32 *)YUVDiffsPtr)[2] = ((INT32 *)Diff)[2];
  510. ((INT32 *)YUVDiffsPtr)[3] = ((INT32 *)Diff)[3];
  511. // Test against the Level and ppi->SRF thresholds and record the results
  512. // Pixel 4
  513. if ( Diff[4] >= ppi->LevelThresh )
  514. {
  515. SgcPtr[0]++;
  516. // If the level change is still suspect then apply PAK kernel.
  517. if ( (Diff[4] > ppi->SrfThresh) && (Diff[4] <= ppi->HighChange) )
  518. Diff[4] = (int)ApplyPakLowPass( ppi, &YuvPtr1[4] ) -
  519. (int)ApplyPakLowPass( ppi, &YuvPtr2[4] );
  520. if ( Diff[4] > ppi->SrfThresh )
  521. {
  522. bits_map_ptr[4] = 1;
  523. FragChangedPixels++;
  524. }
  525. }
  526. else if ( Diff[4] <= ppi->NegLevelThresh )
  527. {
  528. SgcPtr[0]--;
  529. // If the level change is still suspect then apply PAK kernel.
  530. if ( (Diff[4] < ppi->NegSrfThresh) && (Diff[4] >= ppi->NegHighChange) )
  531. Diff[4] = (int)ApplyPakLowPass( ppi, &YuvPtr1[4] ) -
  532. (int)ApplyPakLowPass( ppi, &YuvPtr2[4] );
  533. if ( Diff[4] < ppi->NegSrfThresh )
  534. {
  535. bits_map_ptr[4] = 1;
  536. FragChangedPixels++;
  537. }
  538. }
  539. // Pixel 5
  540. if ( Diff[5] >= ppi->LevelThresh )
  541. {
  542. SgcPtr[0]++;
  543. // If the level change is still suspect then apply PAK kernel.
  544. if ( (Diff[5] > ppi->SrfThresh) && (Diff[5] <= ppi->HighChange) )
  545. Diff[5] = (int)ApplyPakLowPass( ppi, &YuvPtr1[5] ) -
  546. (int)ApplyPakLowPass( ppi, &YuvPtr2[5] );
  547. if ( Diff[5] > ppi->SrfThresh )
  548. {
  549. bits_map_ptr[5] = 1;
  550. FragChangedPixels++;
  551. }
  552. }
  553. else if ( Diff[5] <= ppi->NegLevelThresh )
  554. {
  555. SgcPtr[0]--;
  556. // If the level change is still suspect then apply PAK kernel.
  557. if ( (Diff[5] < ppi->NegSrfThresh) && (Diff[5] >= ppi->NegHighChange) )
  558. Diff[5] = (int)ApplyPakLowPass( ppi, &YuvPtr1[5] ) -
  559. (int)ApplyPakLowPass( ppi, &YuvPtr2[5] );
  560. if ( Diff[5] < ppi->NegSrfThresh )
  561. {
  562. bits_map_ptr[5] = 1;
  563. FragChangedPixels++;
  564. }
  565. }
  566. // Pixel 6
  567. if ( Diff[6] >= ppi->LevelThresh )
  568. {
  569. SgcPtr[0]++;
  570. // If the level change is still suspect then apply PAK kernel.
  571. if ( (Diff[6] > ppi->SrfThresh) && (Diff[6] <= ppi->HighChange) )
  572. Diff[6] = (int)ApplyPakLowPass( ppi, &YuvPtr1[6] ) -
  573. (int)ApplyPakLowPass( ppi, &YuvPtr2[6] );
  574. if ( Diff[6] > ppi->SrfThresh )
  575. {
  576. bits_map_ptr[6] = 1;
  577. FragChangedPixels++;
  578. }
  579. }
  580. else if ( Diff[6] <= ppi->NegLevelThresh )
  581. {
  582. SgcPtr[0]--;
  583. // If the level change is still suspect then apply PAK kernel.
  584. if ( (Diff[6] < ppi->NegSrfThresh) && (Diff[6] >= ppi->NegHighChange) )
  585. Diff[6] = (int)ApplyPakLowPass( ppi, &YuvPtr1[6] ) -
  586. (int)ApplyPakLowPass( ppi, &YuvPtr2[6] );
  587. if ( Diff[6] < ppi->NegSrfThresh )
  588. {
  589. bits_map_ptr[6] = 1;
  590. FragChangedPixels++;
  591. }
  592. }
  593. // Pixel 7
  594. if ( Diff[7] >= ppi->LevelThresh )
  595. {
  596. SgcPtr[0]++;
  597. // If the level change is still suspect then apply PAK kernel.
  598. if ( (Diff[7] > ppi->SrfThresh) && (Diff[7] <= ppi->HighChange) )
  599. Diff[7] = (int)ApplyPakLowPass( ppi, &YuvPtr1[7] ) -
  600. (int)ApplyPakLowPass( ppi, &YuvPtr2[7] );
  601. if ( Diff[7] > ppi->SrfThresh )
  602. {
  603. bits_map_ptr[7] = 1;
  604. FragChangedPixels++;
  605. }
  606. }
  607. else if ( Diff[7] <= ppi->NegLevelThresh )
  608. {
  609. SgcPtr[0]--;
  610. // If the level change is still suspect then apply PAK kernel.
  611. if ( (Diff[7] < ppi->NegSrfThresh) && (Diff[7] >= ppi->NegHighChange) )
  612. Diff[7] = (int)ApplyPakLowPass( ppi, &YuvPtr1[7] ) -
  613. (int)ApplyPakLowPass( ppi, &YuvPtr2[7] );
  614. if ( Diff[7] < ppi->NegSrfThresh )
  615. {
  616. bits_map_ptr[7] = 1;
  617. FragChangedPixels++;
  618. }
  619. }
  620. // Clear down entries in changed locals array
  621. ((UINT32 *)ChLocalsPtr)[1] = ((UINT32 *)ZeroData)[1];
  622. }
  623. else
  624. {
  625. // For EBO coded blocks mark all pixels as changed.
  626. if ( *DispFragPtr > BLOCK_NOT_CODED )
  627. {
  628. ((UINT32 *)bits_map_ptr)[0] = ((UINT32 *)OneData)[0];
  629. ((UINT32 *)ChLocalsPtr)[0] = ((UINT32 *)ChlocalsDummyData)[0];
  630. ((UINT32 *)bits_map_ptr)[1] = ((UINT32 *)OneData)[1];
  631. ((UINT32 *)ChLocalsPtr)[1] = ((UINT32 *)ChlocalsDummyData)[1];
  632. }
  633. else
  634. {
  635. ((UINT32 *)ChLocalsPtr)[0] = ((UINT32 *)ZeroData)[0];
  636. ((UINT32 *)ChLocalsPtr)[1] = ((UINT32 *)ZeroData)[1];
  637. }
  638. }
  639. *RowDiffsPtr += FragChangedPixels;
  640. *FDiffPixels += (UINT8)FragChangedPixels;
  641. YuvPtr1 += ppi->HFragPixels;
  642. YuvPtr2 += ppi->HFragPixels;
  643. bits_map_ptr += ppi->HFragPixels;
  644. ChLocalsPtr += ppi->HFragPixels;
  645. YUVDiffsPtr += ppi->HFragPixels;
  646. SgcPtr ++;
  647. FDiffPixels ++;
  648. // If we have a lot of changed pixels for this fragment on this row then
  649. // the fragment is almost sure to be picked (e.g. through the line search) so we
  650. // can mark it as selected and then ignore it.
  651. // if ( ppi->EarlyBreakAllowed )
  652. {
  653. if (FragChangedPixels >= 7)
  654. {
  655. *DispFragPtr = BLOCK_CODED;
  656. }
  657. }
  658. DispFragPtr++;
  659. }
  660. }
  661. }