You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

468 lines
20KB

  1. /*
  2. * H.26L/H.264/AVC/JVT/14496-10/... direct mb/block decoding
  3. * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file libavcodec/h264_direct.c
  23. * H.264 / AVC / MPEG4 part10 direct mb/block decoding.
  24. * @author Michael Niedermayer <michaelni@gmx.at>
  25. */
  26. #include "internal.h"
  27. #include "dsputil.h"
  28. #include "avcodec.h"
  29. #include "mpegvideo.h"
  30. #include "h264.h"
  31. #include "h264_mvpred.h"
  32. #include "rectangle.h"
  33. //#undef NDEBUG
  34. #include <assert.h>
  35. static int get_scale_factor(H264Context * const h, int poc, int poc1, int i){
  36. int poc0 = h->ref_list[0][i].poc;
  37. int td = av_clip(poc1 - poc0, -128, 127);
  38. if(td == 0 || h->ref_list[0][i].long_ref){
  39. return 256;
  40. }else{
  41. int tb = av_clip(poc - poc0, -128, 127);
  42. int tx = (16384 + (FFABS(td) >> 1)) / td;
  43. return av_clip((tb*tx + 32) >> 6, -1024, 1023);
  44. }
  45. }
  46. void ff_h264_direct_dist_scale_factor(H264Context * const h){
  47. MpegEncContext * const s = &h->s;
  48. const int poc = h->s.current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ];
  49. const int poc1 = h->ref_list[1][0].poc;
  50. int i, field;
  51. for(field=0; field<2; field++){
  52. const int poc = h->s.current_picture_ptr->field_poc[field];
  53. const int poc1 = h->ref_list[1][0].field_poc[field];
  54. for(i=0; i < 2*h->ref_count[0]; i++)
  55. h->dist_scale_factor_field[field][i^field] = get_scale_factor(h, poc, poc1, i+16);
  56. }
  57. for(i=0; i<h->ref_count[0]; i++){
  58. h->dist_scale_factor[i] = get_scale_factor(h, poc, poc1, i);
  59. }
  60. }
  61. static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){
  62. MpegEncContext * const s = &h->s;
  63. Picture * const ref1 = &h->ref_list[1][0];
  64. int j, old_ref, rfield;
  65. int start= mbafi ? 16 : 0;
  66. int end = mbafi ? 16+2*h->ref_count[0] : h->ref_count[0];
  67. int interl= mbafi || s->picture_structure != PICT_FRAME;
  68. /* bogus; fills in for missing frames */
  69. memset(map[list], 0, sizeof(map[list]));
  70. for(rfield=0; rfield<2; rfield++){
  71. for(old_ref=0; old_ref<ref1->ref_count[colfield][list]; old_ref++){
  72. int poc = ref1->ref_poc[colfield][list][old_ref];
  73. if (!interl)
  74. poc |= 3;
  75. else if( interl && (poc&3) == 3) //FIXME store all MBAFF references so this isnt needed
  76. poc= (poc&~3) + rfield + 1;
  77. for(j=start; j<end; j++){
  78. if(4*h->ref_list[0][j].frame_num + (h->ref_list[0][j].reference&3) == poc){
  79. int cur_ref= mbafi ? (j-16)^field : j;
  80. map[list][2*old_ref + (rfield^field) + 16] = cur_ref;
  81. if(rfield == field || !interl)
  82. map[list][old_ref] = cur_ref;
  83. break;
  84. }
  85. }
  86. }
  87. }
  88. }
  89. void ff_h264_direct_ref_list_init(H264Context * const h){
  90. MpegEncContext * const s = &h->s;
  91. Picture * const ref1 = &h->ref_list[1][0];
  92. Picture * const cur = s->current_picture_ptr;
  93. int list, j, field;
  94. int sidx= (s->picture_structure&1)^1;
  95. int ref1sidx= (ref1->reference&1)^1;
  96. for(list=0; list<2; list++){
  97. cur->ref_count[sidx][list] = h->ref_count[list];
  98. for(j=0; j<h->ref_count[list]; j++)
  99. cur->ref_poc[sidx][list][j] = 4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3);
  100. }
  101. if(s->picture_structure == PICT_FRAME){
  102. memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0]));
  103. memcpy(cur->ref_poc [1], cur->ref_poc [0], sizeof(cur->ref_poc [0]));
  104. }
  105. cur->mbaff= FRAME_MBAFF;
  106. h->col_fieldoff= 0;
  107. if(s->picture_structure == PICT_FRAME){
  108. int cur_poc = s->current_picture_ptr->poc;
  109. int *col_poc = h->ref_list[1]->field_poc;
  110. h->col_parity= (FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc));
  111. ref1sidx=sidx= h->col_parity;
  112. }else if(!(s->picture_structure & h->ref_list[1][0].reference) && !h->ref_list[1][0].mbaff){ // FL -> FL & differ parity
  113. h->col_fieldoff= s->mb_stride*(2*(h->ref_list[1][0].reference) - 3);
  114. }
  115. if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred)
  116. return;
  117. for(list=0; list<2; list++){
  118. fill_colmap(h, h->map_col_to_list0, list, sidx, ref1sidx, 0);
  119. if(FRAME_MBAFF)
  120. for(field=0; field<2; field++)
  121. fill_colmap(h, h->map_col_to_list0_field[field], list, field, field, 1);
  122. }
  123. }
  124. void ff_h264_pred_direct_motion(H264Context * const h, int *mb_type){
  125. MpegEncContext * const s = &h->s;
  126. int b8_stride = h->b8_stride;
  127. int b4_stride = h->b_stride;
  128. int mb_xy = h->mb_xy;
  129. int mb_type_col[2];
  130. const int16_t (*l1mv0)[2], (*l1mv1)[2];
  131. const int8_t *l1ref0, *l1ref1;
  132. const int is_b8x8 = IS_8X8(*mb_type);
  133. unsigned int sub_mb_type;
  134. int i8, i4;
  135. assert(h->ref_list[1][0].reference&3);
  136. #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
  137. if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL
  138. if(!IS_INTERLACED(*mb_type)){ // AFR/FR -> AFL/FL
  139. mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;
  140. b8_stride = 0;
  141. }else{
  142. mb_xy += h->col_fieldoff; // non zero for FL -> FL & differ parity
  143. }
  144. goto single_col;
  145. }else{ // AFL/AFR/FR/FL -> AFR/FR
  146. if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR
  147. mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
  148. mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
  149. mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
  150. b8_stride *= 3;
  151. b4_stride *= 6;
  152. sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
  153. if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)
  154. && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)
  155. && !is_b8x8){
  156. *mb_type |= MB_TYPE_16x8 |MB_TYPE_L0L1|MB_TYPE_DIRECT2; /* B_16x8 */
  157. }else{
  158. *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
  159. }
  160. }else{ // AFR/FR -> AFR/FR
  161. single_col:
  162. mb_type_col[0] =
  163. mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy];
  164. if(IS_8X8(mb_type_col[0]) && !h->sps.direct_8x8_inference_flag){
  165. /* FIXME save sub mb types from previous frames (or derive from MVs)
  166. * so we know exactly what block size to use */
  167. sub_mb_type = MB_TYPE_8x8|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_4x4 */
  168. *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
  169. }else if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){
  170. sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
  171. *mb_type |= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_16x16 */
  172. }else if(!is_b8x8 && (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16))){
  173. sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
  174. *mb_type |= MB_TYPE_L0L1|MB_TYPE_DIRECT2 | (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16));
  175. }else{
  176. sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
  177. *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
  178. }
  179. }
  180. }
  181. l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
  182. l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
  183. l1ref0 = &h->ref_list[1][0].ref_index [0][h->mb2b8_xy[mb_xy]];
  184. l1ref1 = &h->ref_list[1][0].ref_index [1][h->mb2b8_xy[mb_xy]];
  185. if(!b8_stride){
  186. if(s->mb_y&1){
  187. l1ref0 += h->b8_stride;
  188. l1ref1 += h->b8_stride;
  189. l1mv0 += 2*b4_stride;
  190. l1mv1 += 2*b4_stride;
  191. }
  192. }
  193. if(h->direct_spatial_mv_pred){
  194. int ref[2];
  195. int mv[2][2];
  196. int list;
  197. /* FIXME interlacing + spatial direct uses wrong colocated block positions */
  198. /* ref = min(neighbors) */
  199. for(list=0; list<2; list++){
  200. int refa = h->ref_cache[list][scan8[0] - 1];
  201. int refb = h->ref_cache[list][scan8[0] - 8];
  202. int refc = h->ref_cache[list][scan8[0] - 8 + 4];
  203. if(refc == PART_NOT_AVAILABLE)
  204. refc = h->ref_cache[list][scan8[0] - 8 - 1];
  205. ref[list] = FFMIN3((unsigned)refa, (unsigned)refb, (unsigned)refc);
  206. if(ref[list] >= 0){
  207. pred_motion(h, 0, 4, list, ref[list], &mv[list][0], &mv[list][1]);
  208. }else{
  209. int mask= ~(MB_TYPE_L0 << (2*list));
  210. mv[list][0] = mv[list][1] = 0;
  211. ref[list] = -1;
  212. if(!is_b8x8)
  213. *mb_type &= mask;
  214. sub_mb_type &= mask;
  215. }
  216. }
  217. if(ref[0] < 0 && ref[1] < 0){
  218. ref[0] = ref[1] = 0;
  219. if(!is_b8x8)
  220. *mb_type |= MB_TYPE_L0L1;
  221. sub_mb_type |= MB_TYPE_L0L1;
  222. }
  223. if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
  224. for(i8=0; i8<4; i8++){
  225. int x8 = i8&1;
  226. int y8 = i8>>1;
  227. int xy8 = x8+y8*b8_stride;
  228. int xy4 = 3*x8+y8*b4_stride;
  229. int a,b;
  230. if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
  231. continue;
  232. h->sub_mb_type[i8] = sub_mb_type;
  233. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
  234. fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
  235. if(!IS_INTRA(mb_type_col[y8]) && !h->ref_list[1][0].long_ref
  236. && ( (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1)
  237. || (l1ref0[xy8] < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){
  238. a=b=0;
  239. if(ref[0] > 0)
  240. a= pack16to32(mv[0][0],mv[0][1]);
  241. if(ref[1] > 0)
  242. b= pack16to32(mv[1][0],mv[1][1]);
  243. }else{
  244. a= pack16to32(mv[0][0],mv[0][1]);
  245. b= pack16to32(mv[1][0],mv[1][1]);
  246. }
  247. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4);
  248. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4);
  249. }
  250. }else if(IS_16X16(*mb_type)){
  251. int a,b;
  252. fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
  253. fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
  254. if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref
  255. && ( (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)
  256. || (l1ref0[0] < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1
  257. && (h->x264_build>33 || !h->x264_build)))){
  258. a=b=0;
  259. if(ref[0] > 0)
  260. a= pack16to32(mv[0][0],mv[0][1]);
  261. if(ref[1] > 0)
  262. b= pack16to32(mv[1][0],mv[1][1]);
  263. }else{
  264. a= pack16to32(mv[0][0],mv[0][1]);
  265. b= pack16to32(mv[1][0],mv[1][1]);
  266. }
  267. fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);
  268. fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);
  269. }else{
  270. for(i8=0; i8<4; i8++){
  271. const int x8 = i8&1;
  272. const int y8 = i8>>1;
  273. if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
  274. continue;
  275. h->sub_mb_type[i8] = sub_mb_type;
  276. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mv[0][0],mv[0][1]), 4);
  277. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mv[1][0],mv[1][1]), 4);
  278. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
  279. fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
  280. /* col_zero_flag */
  281. if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref && ( l1ref0[x8 + y8*b8_stride] == 0
  282. || (l1ref0[x8 + y8*b8_stride] < 0 && l1ref1[x8 + y8*b8_stride] == 0
  283. && (h->x264_build>33 || !h->x264_build)))){
  284. const int16_t (*l1mv)[2]= l1ref0[x8 + y8*b8_stride] == 0 ? l1mv0 : l1mv1;
  285. if(IS_SUB_8X8(sub_mb_type)){
  286. const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
  287. if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
  288. if(ref[0] == 0)
  289. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
  290. if(ref[1] == 0)
  291. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
  292. }
  293. }else
  294. for(i4=0; i4<4; i4++){
  295. const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
  296. if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
  297. if(ref[0] == 0)
  298. *(uint32_t*)h->mv_cache[0][scan8[i8*4+i4]] = 0;
  299. if(ref[1] == 0)
  300. *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = 0;
  301. }
  302. }
  303. }
  304. }
  305. }
  306. }else{ /* direct temporal mv pred */
  307. const int *map_col_to_list0[2] = {h->map_col_to_list0[0], h->map_col_to_list0[1]};
  308. const int *dist_scale_factor = h->dist_scale_factor;
  309. int ref_offset= 0;
  310. if(FRAME_MBAFF && IS_INTERLACED(*mb_type)){
  311. map_col_to_list0[0] = h->map_col_to_list0_field[s->mb_y&1][0];
  312. map_col_to_list0[1] = h->map_col_to_list0_field[s->mb_y&1][1];
  313. dist_scale_factor =h->dist_scale_factor_field[s->mb_y&1];
  314. }
  315. if(h->ref_list[1][0].mbaff && IS_INTERLACED(mb_type_col[0]))
  316. ref_offset += 16;
  317. if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
  318. int y_shift = 2*!IS_INTERLACED(*mb_type);
  319. assert(h->sps.direct_8x8_inference_flag);
  320. for(i8=0; i8<4; i8++){
  321. const int x8 = i8&1;
  322. const int y8 = i8>>1;
  323. int ref0, scale;
  324. const int16_t (*l1mv)[2]= l1mv0;
  325. if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
  326. continue;
  327. h->sub_mb_type[i8] = sub_mb_type;
  328. fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
  329. if(IS_INTRA(mb_type_col[y8])){
  330. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
  331. fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
  332. fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
  333. continue;
  334. }
  335. ref0 = l1ref0[x8 + y8*b8_stride];
  336. if(ref0 >= 0)
  337. ref0 = map_col_to_list0[0][ref0 + ref_offset];
  338. else{
  339. ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
  340. l1mv= l1mv1;
  341. }
  342. scale = dist_scale_factor[ref0];
  343. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
  344. {
  345. const int16_t *mv_col = l1mv[x8*3 + y8*b4_stride];
  346. int my_col = (mv_col[1]<<y_shift)/2;
  347. int mx = (scale * mv_col[0] + 128) >> 8;
  348. int my = (scale * my_col + 128) >> 8;
  349. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
  350. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-my_col), 4);
  351. }
  352. }
  353. return;
  354. }
  355. /* one-to-one mv scaling */
  356. if(IS_16X16(*mb_type)){
  357. int ref, mv0, mv1;
  358. fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1);
  359. if(IS_INTRA(mb_type_col[0])){
  360. ref=mv0=mv1=0;
  361. }else{
  362. const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
  363. : map_col_to_list0[1][l1ref1[0] + ref_offset];
  364. const int scale = dist_scale_factor[ref0];
  365. const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
  366. int mv_l0[2];
  367. mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
  368. mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
  369. ref= ref0;
  370. mv0= pack16to32(mv_l0[0],mv_l0[1]);
  371. mv1= pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
  372. }
  373. fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
  374. fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4);
  375. fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4);
  376. }else{
  377. for(i8=0; i8<4; i8++){
  378. const int x8 = i8&1;
  379. const int y8 = i8>>1;
  380. int ref0, scale;
  381. const int16_t (*l1mv)[2]= l1mv0;
  382. if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
  383. continue;
  384. h->sub_mb_type[i8] = sub_mb_type;
  385. fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
  386. if(IS_INTRA(mb_type_col[0])){
  387. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
  388. fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
  389. fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
  390. continue;
  391. }
  392. ref0 = l1ref0[x8 + y8*b8_stride];
  393. if(ref0 >= 0)
  394. ref0 = map_col_to_list0[0][ref0 + ref_offset];
  395. else{
  396. ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
  397. l1mv= l1mv1;
  398. }
  399. scale = dist_scale_factor[ref0];
  400. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
  401. if(IS_SUB_8X8(sub_mb_type)){
  402. const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
  403. int mx = (scale * mv_col[0] + 128) >> 8;
  404. int my = (scale * mv_col[1] + 128) >> 8;
  405. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
  406. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-mv_col[1]), 4);
  407. }else
  408. for(i4=0; i4<4; i4++){
  409. const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
  410. int16_t *mv_l0 = h->mv_cache[0][scan8[i8*4+i4]];
  411. mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
  412. mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
  413. *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] =
  414. pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
  415. }
  416. }
  417. }
  418. }
  419. }