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.

469 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 "rectangle.h"
  32. #if ARCH_X86
  33. #include "x86/h264_i386.h"
  34. #endif
  35. //#undef NDEBUG
  36. #include <assert.h>
  37. static int get_scale_factor(H264Context * const h, int poc, int poc1, int i){
  38. int poc0 = h->ref_list[0][i].poc;
  39. int td = av_clip(poc1 - poc0, -128, 127);
  40. if(td == 0 || h->ref_list[0][i].long_ref){
  41. return 256;
  42. }else{
  43. int tb = av_clip(poc - poc0, -128, 127);
  44. int tx = (16384 + (FFABS(td) >> 1)) / td;
  45. return av_clip((tb*tx + 32) >> 6, -1024, 1023);
  46. }
  47. }
  48. void ff_h264_direct_dist_scale_factor(H264Context * const h){
  49. MpegEncContext * const s = &h->s;
  50. const int poc = h->s.current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ];
  51. const int poc1 = h->ref_list[1][0].poc;
  52. int i, field;
  53. for(field=0; field<2; field++){
  54. const int poc = h->s.current_picture_ptr->field_poc[field];
  55. const int poc1 = h->ref_list[1][0].field_poc[field];
  56. for(i=0; i < 2*h->ref_count[0]; i++)
  57. h->dist_scale_factor_field[field][i^field] = get_scale_factor(h, poc, poc1, i+16);
  58. }
  59. for(i=0; i<h->ref_count[0]; i++){
  60. h->dist_scale_factor[i] = get_scale_factor(h, poc, poc1, i);
  61. }
  62. }
  63. static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){
  64. MpegEncContext * const s = &h->s;
  65. Picture * const ref1 = &h->ref_list[1][0];
  66. int j, old_ref, rfield;
  67. int start= mbafi ? 16 : 0;
  68. int end = mbafi ? 16+2*h->ref_count[list] : h->ref_count[list];
  69. int interl= mbafi || s->picture_structure != PICT_FRAME;
  70. /* bogus; fills in for missing frames */
  71. memset(map[list], 0, sizeof(map[list]));
  72. for(rfield=0; rfield<2; rfield++){
  73. for(old_ref=0; old_ref<ref1->ref_count[colfield][list]; old_ref++){
  74. int poc = ref1->ref_poc[colfield][list][old_ref];
  75. if (!interl)
  76. poc |= 3;
  77. else if( interl && (poc&3) == 3) //FIXME store all MBAFF references so this isnt needed
  78. poc= (poc&~3) + rfield + 1;
  79. for(j=start; j<end; j++){
  80. if(4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3) == poc){
  81. int cur_ref= mbafi ? (j-16)^field : j;
  82. map[list][2*old_ref + (rfield^field) + 16] = cur_ref;
  83. if(rfield == field)
  84. map[list][old_ref] = cur_ref;
  85. break;
  86. }
  87. }
  88. }
  89. }
  90. }
  91. void ff_h264_direct_ref_list_init(H264Context * const h){
  92. MpegEncContext * const s = &h->s;
  93. Picture * const ref1 = &h->ref_list[1][0];
  94. Picture * const cur = s->current_picture_ptr;
  95. int list, j, field;
  96. int sidx= (s->picture_structure&1)^1;
  97. int ref1sidx= (ref1->reference&1)^1;
  98. for(list=0; list<2; list++){
  99. cur->ref_count[sidx][list] = h->ref_count[list];
  100. for(j=0; j<h->ref_count[list]; j++)
  101. cur->ref_poc[sidx][list][j] = 4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3);
  102. }
  103. if(s->picture_structure == PICT_FRAME){
  104. memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0]));
  105. memcpy(cur->ref_poc [1], cur->ref_poc [0], sizeof(cur->ref_poc [0]));
  106. }
  107. cur->mbaff= FRAME_MBAFF;
  108. if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred)
  109. return;
  110. for(list=0; list<2; list++){
  111. fill_colmap(h, h->map_col_to_list0, list, sidx, ref1sidx, 0);
  112. for(field=0; field<2; field++)
  113. fill_colmap(h, h->map_col_to_list0_field[field], list, field, field, 1);
  114. }
  115. }
  116. void ff_h264_pred_direct_motion(H264Context * const h, int *mb_type){
  117. MpegEncContext * const s = &h->s;
  118. int b8_stride = h->b8_stride;
  119. int b4_stride = h->b_stride;
  120. int mb_xy = h->mb_xy;
  121. int mb_type_col[2];
  122. const int16_t (*l1mv0)[2], (*l1mv1)[2];
  123. const int8_t *l1ref0, *l1ref1;
  124. const int is_b8x8 = IS_8X8(*mb_type);
  125. unsigned int sub_mb_type;
  126. int i8, i4;
  127. assert(h->ref_list[1][0].reference&3);
  128. #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
  129. if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL
  130. if(!IS_INTERLACED(*mb_type)){ // AFR/FR -> AFL/FL
  131. int cur_poc = s->current_picture_ptr->poc;
  132. int *col_poc = h->ref_list[1]->field_poc;
  133. int col_parity = FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc);
  134. mb_xy= s->mb_x + ((s->mb_y&~1) + col_parity)*s->mb_stride;
  135. b8_stride = 0;
  136. }else if(!(s->picture_structure & h->ref_list[1][0].reference) && !h->ref_list[1][0].mbaff){// FL -> FL & differ parity
  137. int fieldoff= 2*(h->ref_list[1][0].reference)-3;
  138. mb_xy += s->mb_stride*fieldoff;
  139. }
  140. goto single_col;
  141. }else{ // AFL/AFR/FR/FL -> AFR/FR
  142. if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR
  143. mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
  144. mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
  145. mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
  146. b8_stride *= 3;
  147. b4_stride *= 6;
  148. //FIXME IS_8X8(mb_type_col[0]) && !h->sps.direct_8x8_inference_flag
  149. if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)
  150. && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)
  151. && !is_b8x8){
  152. sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
  153. *mb_type |= MB_TYPE_16x8 |MB_TYPE_L0L1|MB_TYPE_DIRECT2; /* B_16x8 */
  154. }else{
  155. sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
  156. *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
  157. }
  158. }else{ // AFR/FR -> AFR/FR
  159. single_col:
  160. mb_type_col[0] =
  161. mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy];
  162. if(IS_8X8(mb_type_col[0]) && !h->sps.direct_8x8_inference_flag){
  163. /* FIXME save sub mb types from previous frames (or derive from MVs)
  164. * so we know exactly what block size to use */
  165. sub_mb_type = MB_TYPE_8x8|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_4x4 */
  166. *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
  167. }else if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){
  168. sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
  169. *mb_type |= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_16x16 */
  170. }else{
  171. sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
  172. *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
  173. }
  174. }
  175. }
  176. l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
  177. l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
  178. l1ref0 = &h->ref_list[1][0].ref_index [0][h->mb2b8_xy[mb_xy]];
  179. l1ref1 = &h->ref_list[1][0].ref_index [1][h->mb2b8_xy[mb_xy]];
  180. if(!b8_stride){
  181. if(s->mb_y&1){
  182. l1ref0 += h->b8_stride;
  183. l1ref1 += h->b8_stride;
  184. l1mv0 += 2*b4_stride;
  185. l1mv1 += 2*b4_stride;
  186. }
  187. }
  188. if(h->direct_spatial_mv_pred){
  189. int ref[2];
  190. int mv[2][2];
  191. int list;
  192. /* FIXME interlacing + spatial direct uses wrong colocated block positions */
  193. /* ref = min(neighbors) */
  194. for(list=0; list<2; list++){
  195. int refa = h->ref_cache[list][scan8[0] - 1];
  196. int refb = h->ref_cache[list][scan8[0] - 8];
  197. int refc = h->ref_cache[list][scan8[0] - 8 + 4];
  198. if(refc == PART_NOT_AVAILABLE)
  199. refc = h->ref_cache[list][scan8[0] - 8 - 1];
  200. ref[list] = FFMIN3((unsigned)refa, (unsigned)refb, (unsigned)refc);
  201. if(ref[list] < 0)
  202. ref[list] = -1;
  203. }
  204. if(ref[0] < 0 && ref[1] < 0){
  205. ref[0] = ref[1] = 0;
  206. mv[0][0] = mv[0][1] =
  207. mv[1][0] = mv[1][1] = 0;
  208. }else{
  209. for(list=0; list<2; list++){
  210. if(ref[list] >= 0)
  211. pred_motion(h, 0, 4, list, ref[list], &mv[list][0], &mv[list][1]);
  212. else
  213. mv[list][0] = mv[list][1] = 0;
  214. }
  215. }
  216. if(ref[1] < 0){
  217. if(!is_b8x8)
  218. *mb_type &= ~MB_TYPE_L1;
  219. sub_mb_type &= ~MB_TYPE_L1;
  220. }else if(ref[0] < 0){
  221. if(!is_b8x8)
  222. *mb_type &= ~MB_TYPE_L0;
  223. sub_mb_type &= ~MB_TYPE_L0;
  224. }
  225. if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
  226. for(i8=0; i8<4; i8++){
  227. int x8 = i8&1;
  228. int y8 = i8>>1;
  229. int xy8 = x8+y8*b8_stride;
  230. int xy4 = 3*x8+y8*b4_stride;
  231. int a=0, b=0;
  232. if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
  233. continue;
  234. h->sub_mb_type[i8] = sub_mb_type;
  235. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
  236. fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
  237. if(!IS_INTRA(mb_type_col[y8])
  238. && ( (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1)
  239. || (l1ref0[xy8] < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){
  240. if(ref[0] > 0)
  241. a= pack16to32(mv[0][0],mv[0][1]);
  242. if(ref[1] > 0)
  243. b= pack16to32(mv[1][0],mv[1][1]);
  244. }else{
  245. a= pack16to32(mv[0][0],mv[0][1]);
  246. b= pack16to32(mv[1][0],mv[1][1]);
  247. }
  248. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4);
  249. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4);
  250. }
  251. }else if(IS_16X16(*mb_type)){
  252. int a=0, b=0;
  253. fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
  254. fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
  255. if(!IS_INTRA(mb_type_col[0])
  256. && ( (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)
  257. || (l1ref0[0] < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1
  258. && (h->x264_build>33 || !h->x264_build)))){
  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]) && ( 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. /* FIXME assumes direct_8x8_inference == 1 */
  319. int y_shift = 2*!IS_INTERLACED(*mb_type);
  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] + ref_offset;
  393. if(ref0 >= 0)
  394. ref0 = map_col_to_list0[0][ref0];
  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. }