strength_horiz.c 21 KB

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