strength_vert.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. #include "global.h"
  2. #include "image.h"
  3. #include "mb_access.h"
  4. #include "loopfilter.h"
  5. void GetStrengthNormal_Vert(byte Strength[MB_BLOCK_SIZE], Macroblock *MbQ, int edge, int mvlimit, StorablePicture *p)
  6. {
  7. // dir == 0
  8. PixelPos pixP, pixMB;
  9. byte StrValue;
  10. Macroblock *MbP;
  11. if ((p->slice_type==SP_SLICE)||(p->slice_type==SI_SLICE) )
  12. {
  13. // Set strength to either 3 or 4 regardless of pixel position
  14. StrValue = (edge == 0) ? 4 : 3;
  15. memset(&Strength[0], (byte) StrValue, MB_BLOCK_SIZE * sizeof(byte));
  16. }
  17. else
  18. {
  19. VideoParameters *p_Vid = MbQ->p_Vid;
  20. int xQ = edge - 1;
  21. int yQ = 0;
  22. p_Vid->getNeighbourX0(MbQ, xQ, p_Vid->mb_size[IS_LUMA], &pixMB);
  23. pixP = pixMB;
  24. MbP = &(p_Vid->mb_data[pixP.mb_addr]);
  25. if (!(MbP->mb_type==I4MB||MbP->mb_type==I8MB||MbP->mb_type==I16MB||MbP->mb_type==IPCM||MbQ->mb_type==I4MB||MbQ->mb_type==I8MB||MbQ->mb_type==I16MB||MbQ->mb_type==IPCM))
  26. {
  27. PicMotionParams *motion = &p->motion;
  28. h264_ref_t ref_p0,ref_p1,ref_q0,ref_q1;
  29. int blkP, blkQ, idx;
  30. int blk_x, blk_x2, blk_y, blk_y2 ;
  31. PicMotion **motion0 = motion->motion[LIST_0];
  32. PicMotion **motion1 = motion->motion[LIST_1];
  33. short mb_x, mb_y;
  34. p_Vid->get_mb_block_pos (p_Vid->PicPos, MbQ->mbAddrX, &mb_x, &mb_y);
  35. mb_x <<= 2;
  36. mb_y <<= 2;
  37. xQ ++;
  38. for( idx = 0 ; idx < MB_BLOCK_SIZE ; idx += BLOCK_SIZE )
  39. {
  40. yQ = idx;
  41. blkQ = (yQ & 0xFFFC) + (xQ >> 2);
  42. blkP = (idx & 0xFFFC) + (pixP.x >> 2);
  43. if( ((MbQ->cbp_blk[0] & ((int64)1 << blkQ )) != 0) || ((MbP->cbp_blk[0] & ((int64)1 << blkP)) != 0) )
  44. StrValue = 2;
  45. else
  46. {
  47. // if no coefs, but vector difference >= 1 set Strength=1
  48. // if this is a mixed mode edge then one set of reference pictures will be frame and the
  49. // other will be field
  50. PicMotion *motion_p0, *motion_q0, *motion_p1, *motion_q1;
  51. blk_y = mb_y + (blkQ >> 2);
  52. blk_x = mb_x + (blkQ & 3);
  53. blk_y2 = (pixMB.pos_y + idx) >> 2;
  54. blk_x2 = pixMB.pos_x >> 2;
  55. motion_p0=&motion0[blk_y ][blk_x ];
  56. motion_q0=&motion0[blk_y2][blk_x2];
  57. motion_p1=&motion1[blk_y ][blk_x ];
  58. motion_q1=&motion1[blk_y2][blk_x2];
  59. ref_p0 = motion_p0->ref_idx < 0 ? UNDEFINED_REFERENCE : motion_p0->ref_pic_id;
  60. ref_q0 = motion_q0->ref_idx < 0 ? UNDEFINED_REFERENCE : motion_q0->ref_pic_id;
  61. ref_p1 = motion_p1->ref_idx < 0 ? UNDEFINED_REFERENCE : motion_p1->ref_pic_id;
  62. ref_q1 = motion_q1->ref_idx < 0 ? UNDEFINED_REFERENCE : motion_q1->ref_pic_id;
  63. if ( ((ref_p0==ref_q0) && (ref_p1==ref_q1)) || ((ref_p0==ref_q1) && (ref_p1==ref_q0)))
  64. {
  65. // L0 and L1 reference pictures of p0 are different; q0 as well
  66. if (ref_p0 != ref_p1)
  67. {
  68. // compare MV for the same reference picture
  69. if (ref_p0 == ref_q0)
  70. {
  71. if (ref_p0 == UNDEFINED_REFERENCE)
  72. {
  73. StrValue = (byte) (
  74. (abs( motion_p1->mv[0] - motion_q1->mv[0]) >= 4) ||
  75. (abs( motion_p1->mv[1] - motion_q1->mv[1]) >= mvlimit));
  76. }
  77. else if (ref_p1 == UNDEFINED_REFERENCE)
  78. {
  79. StrValue = (byte) (
  80. (abs( motion_p0->mv[0] - motion_q0->mv[0]) >= 4) ||
  81. (abs( motion_p0->mv[1] - motion_q0->mv[1]) >= mvlimit));
  82. }
  83. else
  84. {
  85. StrValue = (byte) (
  86. (abs( motion_p0->mv[0] - motion_q0->mv[0]) >= 4) ||
  87. (abs( motion_p0->mv[1] - motion_q0->mv[1]) >= mvlimit) ||
  88. (abs( motion_p1->mv[0] - motion_q1->mv[0]) >= 4) ||
  89. (abs( motion_p1->mv[1] - motion_q1->mv[1]) >= mvlimit));
  90. }
  91. }
  92. else
  93. {
  94. StrValue = (byte) (
  95. (abs( motion_p0->mv[0] - motion_q1->mv[0]) >= 4) ||
  96. (abs( motion_p0->mv[1] - motion_q1->mv[1]) >= mvlimit) ||
  97. (abs( motion_p1->mv[0] - motion_q0->mv[0]) >= 4) ||
  98. (abs( motion_p1->mv[1] - motion_q0->mv[1]) >= mvlimit));
  99. }
  100. }
  101. else
  102. { // L0 and L1 reference pictures of p0 are the same; q0 as well
  103. StrValue = (byte) (
  104. ((abs( motion_p0->mv[0] - motion_q0->mv[0]) >= 4) ||
  105. (abs( motion_p0->mv[1] - motion_q0->mv[1]) >= mvlimit ) ||
  106. (abs( motion_p1->mv[0] - motion_q1->mv[0]) >= 4) ||
  107. (abs( motion_p1->mv[1] - motion_q1->mv[1]) >= mvlimit))
  108. &&
  109. ((abs( motion_p0->mv[0] - motion_q1->mv[0]) >= 4) ||
  110. (abs( motion_p0->mv[1] - motion_q1->mv[1]) >= mvlimit) ||
  111. (abs( motion_p1->mv[0] - motion_q0->mv[0]) >= 4) ||
  112. (abs( motion_p1->mv[1] - motion_q0->mv[1]) >= mvlimit)));
  113. }
  114. }
  115. else
  116. {
  117. StrValue = 1;
  118. }
  119. }
  120. memset(&Strength[idx], (byte) StrValue, BLOCK_SIZE * sizeof(byte));
  121. }
  122. }
  123. else
  124. {
  125. // Start with Strength=3. or Strength=4 for Mb-edge
  126. StrValue = (edge == 0) ? 4 : 3;
  127. memset(&Strength[0], (byte) StrValue, MB_BLOCK_SIZE * sizeof(byte));
  128. }
  129. }
  130. }
  131. void GetStrength_Vert_YUV420(uint8_t Strength[4], Macroblock *MbQ, int edge, int mvlimit, StorablePicture *p, PixelPos pixMB, Macroblock *MbP)
  132. {
  133. // dir == 0
  134. int i;
  135. uint8_t StrValue;
  136. if ((p->slice_type==SP_SLICE)||(p->slice_type==SI_SLICE) )
  137. {
  138. // Set strength to either 3 or 4 regardless of pixel position
  139. StrValue = (edge == 0) ? 4 : 3;
  140. for (i=0;i<4;i++)
  141. {
  142. Strength[i]=StrValue;
  143. }
  144. }
  145. else
  146. {
  147. VideoParameters *p_Vid = MbQ->p_Vid;
  148. if (!(MbP->mb_type==I4MB||MbP->mb_type==I8MB||MbP->mb_type==I16MB||MbP->mb_type==IPCM||MbQ->mb_type==I4MB||MbQ->mb_type==I8MB||MbQ->mb_type==I16MB||MbQ->mb_type==IPCM))
  149. {
  150. PicMotionParams *motion = &p->motion;
  151. h264_ref_t ref_p0,ref_p1,ref_q0,ref_q1;
  152. int blkP, blkQ, idx;
  153. int blk_x2, blk_y, blk_y2 ;
  154. PicMotion **motion0 = motion->motion[LIST_0];
  155. PicMotion **motion1 = motion->motion[LIST_1];
  156. short mb_x, mb_y;
  157. const int cbp_p=(int)MbP->cbp_blk[0], cbp_q=(int)MbQ->cbp_blk[0];
  158. get_mb_block_pos_normal(p_Vid->PicPos, MbQ->mbAddrX, &mb_x, &mb_y);
  159. mb_x <<= 2;
  160. mb_y <<= 2;
  161. mb_x += edge;
  162. blkQ = edge;
  163. blkP = pixMB.x >> 2;
  164. blk_x2 = pixMB.pos_x >> 2;
  165. for( idx = 0 ; idx < BLOCK_SIZE ; idx++,blkQ+=BLOCK_SIZE, blkP+=BLOCK_SIZE)
  166. {
  167. if (_bittest(&cbp_p, blkP) || _bittest(&cbp_q, blkQ))
  168. StrValue = 2;
  169. else
  170. {
  171. // if no coefs, but vector difference >= 1 set Strength=1
  172. // if this is a mixed mode edge then one set of reference pictures will be frame and the
  173. // other will be field
  174. PicMotion *motion_p0, *motion_q0, *motion_p1, *motion_q1;
  175. blk_y = mb_y + idx;
  176. blk_y2 = (pixMB.pos_y >> 2) + idx;
  177. motion_p0=&motion0[blk_y ][mb_x ];
  178. motion_q0=&motion0[blk_y2][blk_x2];
  179. motion_p1=&motion1[blk_y ][mb_x ];
  180. motion_q1=&motion1[blk_y2][blk_x2];
  181. ref_p0 = motion_p0->ref_idx < 0 ? UNDEFINED_REFERENCE : motion_p0->ref_pic_id;
  182. ref_q0 = motion_q0->ref_idx < 0 ? UNDEFINED_REFERENCE : motion_q0->ref_pic_id;
  183. ref_p1 = motion_p1->ref_idx < 0 ? UNDEFINED_REFERENCE : motion_p1->ref_pic_id;
  184. ref_q1 = motion_q1->ref_idx < 0 ? UNDEFINED_REFERENCE : motion_q1->ref_pic_id;
  185. if ( ((ref_p0==ref_q0) && (ref_p1==ref_q1)) || ((ref_p0==ref_q1) && (ref_p1==ref_q0)))
  186. {
  187. // L0 and L1 reference pictures of p0 are different; q0 as well
  188. if (ref_p0 != ref_p1)
  189. {
  190. // compare MV for the same reference picture
  191. if (ref_p0 == ref_q0)
  192. {
  193. if (ref_p0 == UNDEFINED_REFERENCE)
  194. {
  195. StrValue = (byte) (
  196. (abs( motion_p1->mv[0] - motion_q1->mv[0]) >= 4) ||
  197. (abs( motion_p1->mv[1] - motion_q1->mv[1]) >= mvlimit));
  198. }
  199. else if (ref_p1 == UNDEFINED_REFERENCE)
  200. {
  201. StrValue = (byte) (
  202. (abs( motion_p0->mv[0] - motion_q0->mv[0]) >= 4) ||
  203. (abs( motion_p0->mv[1] - motion_q0->mv[1]) >= mvlimit));
  204. }
  205. else
  206. {
  207. StrValue = (byte) (
  208. (abs( motion_p0->mv[0] - motion_q0->mv[0]) >= 4) ||
  209. (abs( motion_p0->mv[1] - motion_q0->mv[1]) >= mvlimit) ||
  210. (abs( motion_p1->mv[0] - motion_q1->mv[0]) >= 4) ||
  211. (abs( motion_p1->mv[1] - motion_q1->mv[1]) >= mvlimit));
  212. }
  213. }
  214. else
  215. {
  216. StrValue = (byte) (
  217. (abs( motion_p0->mv[0] - motion_q1->mv[0]) >= 4) ||
  218. (abs( motion_p0->mv[1] - motion_q1->mv[1]) >= mvlimit) ||
  219. (abs( motion_p1->mv[0] - motion_q0->mv[0]) >= 4) ||
  220. (abs( motion_p1->mv[1] - motion_q0->mv[1]) >= mvlimit));
  221. }
  222. }
  223. else
  224. { // L0 and L1 reference pictures of p0 are the same; q0 as well
  225. StrValue = (byte) (
  226. ((abs( motion_p0->mv[0] - motion_q0->mv[0]) >= 4) ||
  227. (abs( motion_p0->mv[1] - motion_q0->mv[1]) >= mvlimit ) ||
  228. (abs( motion_p1->mv[0] - motion_q1->mv[0]) >= 4) ||
  229. (abs( motion_p1->mv[1] - motion_q1->mv[1]) >= mvlimit))
  230. &&
  231. ((abs( motion_p0->mv[0] - motion_q1->mv[0]) >= 4) ||
  232. (abs( motion_p0->mv[1] - motion_q1->mv[1]) >= mvlimit) ||
  233. (abs( motion_p1->mv[0] - motion_q0->mv[0]) >= 4) ||
  234. (abs( motion_p1->mv[1] - motion_q0->mv[1]) >= mvlimit)));
  235. }
  236. }
  237. else
  238. {
  239. StrValue = 1;
  240. }
  241. }
  242. Strength[idx] = StrValue;
  243. }
  244. }
  245. else
  246. {
  247. // Start with Strength=3. or Strength=4 for Mb-edge
  248. StrValue = (edge == 0) ? 4 : 3;
  249. for (i=0;i<4;i++)
  250. {
  251. Strength[i]=StrValue;
  252. }
  253. }
  254. }
  255. }
  256. // assumes YUV420, MB Aff
  257. void GetStrength_MBAff_Vert_YUV420(byte Strength[16], Macroblock *MbQ, int edge, int mvlimit, StorablePicture *p)
  258. {
  259. // dir == 0
  260. if ((p->slice_type==SP_SLICE)||(p->slice_type==SI_SLICE)
  261. || (MbQ->mb_type==I4MB || MbQ->mb_type==I16MB || MbQ->mb_type==I8MB || MbQ->mb_type==IPCM))
  262. {
  263. memset(Strength,(edge == 0) ? 4 : 3, 16);
  264. }
  265. else
  266. {
  267. short blkP, blkQ, idx;
  268. short blk_x, blk_x2, blk_y, blk_y2 ;
  269. h264_ref_t ref_p0,ref_p1,ref_q0,ref_q1;
  270. int xQ, yQ;
  271. short mb_x, mb_y;
  272. Macroblock *MbP;
  273. PixelPos pixP;
  274. PicMotionParams *motion = &p->motion;
  275. PicMotion **motion0 = motion->motion[LIST_0];
  276. PicMotion **motion1 = motion->motion[LIST_1];
  277. xQ = edge;
  278. for( idx = 0; idx < 16; ++idx )
  279. {
  280. VideoParameters *p_Vid = MbQ->p_Vid;
  281. yQ = idx;
  282. getAffNeighbourXPLuma(MbQ, xQ - 1, yQ, &pixP);
  283. blkQ = (short) ((yQ & 0xC) + (xQ >> 2)); // blkQ changes once every 4 loop iterations
  284. blkP = (short) ((pixP.y & 0xFFFC) + (pixP.x >> 2));
  285. MbP = &(p_Vid->mb_data[pixP.mb_addr]);
  286. p_Vid->mixedModeEdgeFlag = (byte) (MbQ->mb_field != MbP->mb_field);
  287. // Start with Strength=3. or Strength=4 for Mb-edge
  288. Strength[idx] = (edge == 0) ? 4 : 3;
  289. if( !(MbP->mb_type==I4MB || MbP->mb_type==I16MB || MbP->mb_type==I8MB || MbP->mb_type==IPCM))
  290. {
  291. if( ((MbQ->cbp_blk[0] & ((int64)1 << blkQ )) != 0) || ((MbP->cbp_blk[0] & ((int64)1 << blkP)) != 0) )
  292. Strength[idx] = 2 ;
  293. else
  294. {
  295. // if no coefs, but vector difference >= 1 set Strength=1
  296. // if this is a mixed mode edge then one set of reference pictures will be frame and the
  297. // other will be field
  298. if (p_Vid->mixedModeEdgeFlag)
  299. {
  300. (Strength[idx] = 1);
  301. }
  302. else
  303. {
  304. get_mb_block_pos_mbaff(p_Vid->PicPos, MbQ->mbAddrX, &mb_x, &mb_y);
  305. blk_y = (short) ((mb_y<<2) + (blkQ >> 2));
  306. blk_x = (short) ((mb_x<<2) + (blkQ & 3));
  307. blk_y2 = (short) (pixP.pos_y >> 2);
  308. blk_x2 = (short) (pixP.pos_x >> 2);
  309. {
  310. PicMotion *motion_p0, *motion_q0, *motion_p1, *motion_q1;
  311. motion_p0=&motion0[blk_y ][blk_x ];
  312. motion_q0=&motion0[blk_y2][blk_x2];
  313. motion_p1=&motion1[blk_y ][blk_x ];
  314. motion_q1=&motion1[blk_y2][blk_x2];
  315. ref_p0 = motion_p0->ref_idx < 0 ? UNDEFINED_REFERENCE : motion_p0->ref_pic_id;
  316. ref_q0 = motion_q0->ref_idx < 0 ? UNDEFINED_REFERENCE : motion_q0->ref_pic_id;
  317. ref_p1 = motion_p1->ref_idx < 0 ? UNDEFINED_REFERENCE : motion_p1->ref_pic_id;
  318. ref_q1 = motion_q1->ref_idx < 0 ? UNDEFINED_REFERENCE : motion_q1->ref_pic_id;
  319. if ( ((ref_p0==ref_q0) && (ref_p1==ref_q1)) ||
  320. ((ref_p0==ref_q1) && (ref_p1==ref_q0)))
  321. {
  322. Strength[idx]=0;
  323. // L0 and L1 reference pictures of p0 are different; q0 as well
  324. if (ref_p0 != ref_p1)
  325. {
  326. // compare MV for the same reference picture
  327. if (ref_p0==ref_q0)
  328. {
  329. Strength[idx] = (byte) (
  330. (abs( motion_p0->mv[0] - motion_q0->mv[0]) >= 4) ||
  331. (abs( motion_p0->mv[1] - motion_q0->mv[1]) >= mvlimit) ||
  332. (abs( motion_p1->mv[0] - motion_q1->mv[0]) >= 4) ||
  333. (abs( motion_p1->mv[1] - motion_q1->mv[1]) >= mvlimit));
  334. }
  335. else
  336. {
  337. Strength[idx] = (byte) (
  338. (abs( motion_p0->mv[0] - motion_q1->mv[0]) >= 4) ||
  339. (abs( motion_p0->mv[1] - motion_q1->mv[1]) >= mvlimit) ||
  340. (abs( motion_p1->mv[0] - motion_q0->mv[0]) >= 4) ||
  341. (abs( motion_p1->mv[1] - motion_q0->mv[1]) >= mvlimit));
  342. }
  343. }
  344. else
  345. { // L0 and L1 reference pictures of p0 are the same; q0 as well
  346. Strength[idx] = (byte) (
  347. ((abs( motion_p0->mv[0] - motion_q0->mv[0]) >= 4) ||
  348. (abs( motion_p0->mv[1] - motion_q0->mv[1]) >= mvlimit ) ||
  349. (abs( motion_p1->mv[0] - motion_q1->mv[0]) >= 4) ||
  350. (abs( motion_p1->mv[1] - motion_q1->mv[1]) >= mvlimit))
  351. &&
  352. ((abs( motion_p0->mv[0] - motion_q1->mv[0]) >= 4) ||
  353. (abs( motion_p0->mv[1] - motion_q1->mv[1]) >= mvlimit) ||
  354. (abs( motion_p1->mv[0] - motion_q0->mv[0]) >= 4) ||
  355. (abs( motion_p1->mv[1] - motion_q0->mv[1]) >= mvlimit)));
  356. }
  357. }
  358. else
  359. {
  360. Strength[idx] = 1;
  361. }
  362. }
  363. }
  364. }
  365. }
  366. }
  367. }
  368. }
  369. static __forceinline uint8_t GetMotionStrength(PicMotion *motion0, PicMotion *motion1, int mvlimit)
  370. {
  371. uint8_t StrValue;
  372. h264_ref_t ref_p0,ref_p1,ref_q0,ref_q1;
  373. ref_p0 = motion0[0].ref_idx < 0 ? UNDEFINED_REFERENCE : motion0[0].ref_pic_id;
  374. ref_p1 = motion1[0].ref_idx < 0 ? UNDEFINED_REFERENCE : motion1[0].ref_pic_id;
  375. ref_q0 = motion0[1].ref_idx < 0 ? UNDEFINED_REFERENCE : motion0[1].ref_pic_id;
  376. ref_q1 = motion1[1].ref_idx < 0 ? UNDEFINED_REFERENCE : motion1[1].ref_pic_id;
  377. if (ref_p0==ref_q0 && ref_p1==ref_q1)
  378. {
  379. if (ref_p0 != ref_p1)
  380. {
  381. // compare MV for the same reference picture
  382. if (ref_p0 == UNDEFINED_REFERENCE)
  383. {
  384. StrValue = (byte) (
  385. (abs( motion1[0].mv[0] - motion1[1].mv[0]) >= 4) ||
  386. (abs( motion1[0].mv[1] - motion1[1].mv[1]) >= mvlimit));
  387. }
  388. else if (ref_p1 == UNDEFINED_REFERENCE)
  389. {
  390. StrValue = (byte) (
  391. (abs( motion0[0].mv[0] - motion0[1].mv[0]) >= 4) ||
  392. (abs( motion0[0].mv[1] - motion0[1].mv[1]) >= mvlimit));
  393. }
  394. else
  395. {
  396. StrValue = (byte) (
  397. (abs( motion0[0].mv[0] - motion0[1].mv[0]) >= 4) ||
  398. (abs( motion0[0].mv[1] - motion0[1].mv[1]) >= mvlimit) ||
  399. (abs( motion1[0].mv[0] - motion1[1].mv[0]) >= 4) ||
  400. (abs( motion1[0].mv[1] - motion1[1].mv[1]) >= mvlimit));
  401. }
  402. }
  403. else
  404. { // L0 and L1 reference pictures of p0 are the same; q0 as well
  405. StrValue = (byte) (
  406. ((abs( motion0[0].mv[0] - motion0[1].mv[0]) >= 4) ||
  407. (abs( motion0[0].mv[1] - motion0[1].mv[1]) >= mvlimit ) ||
  408. (abs( motion1[0].mv[0] - motion1[1].mv[0]) >= 4) ||
  409. (abs( motion1[0].mv[1] - motion1[1].mv[1]) >= mvlimit))
  410. &&
  411. ((abs( motion0[0].mv[0] - motion1[1].mv[0]) >= 4) ||
  412. (abs( motion0[0].mv[1] - motion1[1].mv[1]) >= mvlimit) ||
  413. (abs( motion1[0].mv[0] - motion0[1].mv[0]) >= 4) ||
  414. (abs( motion1[0].mv[1] - motion0[1].mv[1]) >= mvlimit)));
  415. }
  416. }
  417. else if (ref_p0==ref_q1 && ref_p1==ref_q0)
  418. {
  419. StrValue = (byte) (
  420. (abs( motion0[0].mv[0] - motion1[1].mv[0]) >= 4) ||
  421. (abs( motion0[0].mv[1] - motion1[1].mv[1]) >= mvlimit) ||
  422. (abs( motion1[0].mv[0] - motion0[1].mv[0]) >= 4) ||
  423. (abs( motion1[0].mv[1] - motion0[1].mv[1]) >= mvlimit));
  424. }
  425. else
  426. {
  427. StrValue = 1;
  428. }
  429. return StrValue;
  430. }
  431. void GetStrength_Vert_YUV420_All(uint8_t Strength[4][4], Macroblock *MbQ, int mvlimit, StorablePicture *p, int pos_x, int pos_y, Macroblock *MbP, int luma_transform_size_8x8_flag)
  432. {
  433. // dir == 0
  434. if ((p->slice_type>=SP_SLICE) //(p->slice_type==SP_SLICE)||(p->slice_type==SI_SLICE) )
  435. || ((1 << MbQ->mb_type) & 26112))
  436. {
  437. // Set strength to either 3 or 4 regardless of pixel position
  438. *(int32_t *)(Strength[0]) = MbP?0x04040404:0;
  439. *(int32_t *)(Strength[1]) = luma_transform_size_8x8_flag?0:0x03030303;
  440. *(int32_t *)(Strength[2]) = 0x03030303;
  441. *(int32_t *)(Strength[3]) = luma_transform_size_8x8_flag?0:0x03030303;
  442. }
  443. else
  444. {
  445. PicMotionParams *motion = &p->motion;
  446. int motion_stride = p->size_x >> 2;
  447. PicMotion *motion0 = &motion->motion[LIST_0][pos_y][pos_x];
  448. PicMotion *motion1 = &motion->motion[LIST_1][pos_y][pos_x];
  449. int cbp_q=(int)MbQ->cbp_blk[0];
  450. // edge 0
  451. if (!MbP)
  452. {
  453. *(int32_t *)(Strength[0]) = 0;
  454. }
  455. else if ((1 << MbP->mb_type) & 26112)
  456. {
  457. *(int32_t *)(Strength[0]) = 0x04040404;
  458. }
  459. else
  460. {
  461. int cbp_p = (int)MbP->cbp_blk[0];
  462. if( ((cbp_q & (1 << 0 )) != 0) || ((cbp_p & (1 << (3))) != 0) )
  463. Strength[0][0] = 2;
  464. else
  465. Strength[0][0] = GetMotionStrength(&motion0[0-1], &motion1[0-1], mvlimit);
  466. if( ((cbp_q & (1 << 4 )) != 0) || ((cbp_p & (1 << (4 + 3))) != 0) )
  467. Strength[0][1] = 2;
  468. else
  469. Strength[0][1] = GetMotionStrength(&motion0[motion_stride-1], &motion1[motion_stride-1], mvlimit);
  470. if( ((cbp_q & (1 << 8 )) != 0) || ((cbp_p & (1 << (8 + 3))) != 0) )
  471. Strength[0][2] = 2;
  472. else
  473. Strength[0][2] = GetMotionStrength(&motion0[2*motion_stride-1], &motion1[2*motion_stride-1], mvlimit);
  474. if( ((cbp_q & (1 << 12 )) != 0) || ((cbp_p & (1 << (12 + 3))) != 0) )
  475. Strength[0][3] = 2;
  476. else
  477. Strength[0][3] = GetMotionStrength(&motion0[3*motion_stride-1], &motion1[3*motion_stride-1], mvlimit);
  478. }
  479. // edge 1
  480. if (luma_transform_size_8x8_flag)
  481. {
  482. *(int32_t *)(Strength[1]) = 0;
  483. }
  484. else
  485. {
  486. if (cbp_q & (3 << 0))
  487. Strength[1][0] = 2;
  488. else
  489. Strength[1][0] = GetMotionStrength(&motion0[0], &motion1[0], mvlimit);
  490. if (cbp_q & (3 << 4))
  491. Strength[1][1] = 2;
  492. else
  493. Strength[1][1] = GetMotionStrength(&motion0[1*motion_stride], &motion1[1*motion_stride], mvlimit);
  494. if (cbp_q & (3 << 8))
  495. Strength[1][2] = 2;
  496. else
  497. Strength[1][2] = GetMotionStrength(&motion0[2*motion_stride], &motion1[2*motion_stride], mvlimit);
  498. if (cbp_q & (3 << 12))
  499. Strength[1][3] = 2;
  500. else
  501. Strength[1][3] = GetMotionStrength(&motion0[3*motion_stride], &motion1[3*motion_stride], mvlimit);
  502. }
  503. // edge 2
  504. if (cbp_q & (6 << 0))
  505. Strength[2][0] = 2;
  506. else
  507. Strength[2][0] = GetMotionStrength(&motion0[1], &motion1[1], mvlimit);
  508. if (cbp_q & (6 << 4))
  509. Strength[2][1] = 2;
  510. else
  511. Strength[2][1] = GetMotionStrength(&motion0[motion_stride+1], &motion1[motion_stride+1], mvlimit);
  512. if (cbp_q & (6 << 8))
  513. Strength[2][2] = 2;
  514. else
  515. Strength[2][2] = GetMotionStrength(&motion0[2*motion_stride+1], &motion1[2*motion_stride+1], mvlimit);
  516. if (cbp_q & (6 << 12))
  517. Strength[2][3] = 2;
  518. else
  519. Strength[2][3] = GetMotionStrength(&motion0[3*motion_stride+1], &motion1[3*motion_stride+1], mvlimit);
  520. // edge 3
  521. if (luma_transform_size_8x8_flag)
  522. {
  523. *(int32_t *)(Strength[3]) = 0;
  524. }
  525. else
  526. {
  527. if (cbp_q & (0xC << 0))
  528. Strength[3][0] = 2;
  529. else
  530. Strength[3][0] = GetMotionStrength(&motion0[2], &motion1[2], mvlimit);
  531. if (cbp_q & (0xC << 4))
  532. Strength[3][1] = 2;
  533. else
  534. Strength[3][1] = GetMotionStrength(&motion0[motion_stride+2], &motion1[motion_stride+2], mvlimit);
  535. if (cbp_q & (0xC << 8))
  536. Strength[3][2] = 2;
  537. else
  538. Strength[3][2] = GetMotionStrength(&motion0[2*motion_stride+2], &motion1[2*motion_stride+2], mvlimit);
  539. if (cbp_q & (0xC << 12))
  540. Strength[3][3] = 2;
  541. else
  542. Strength[3][3] = GetMotionStrength(&motion0[3*motion_stride+2], &motion1[3*motion_stride+2], mvlimit);
  543. }
  544. }
  545. }