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.

466 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[list] : h->ref_count[list];
  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[list][j].frame_num + (h->ref_list[list][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)
  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. if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred)
  107. return;
  108. for(list=0; list<2; list++){
  109. fill_colmap(h, h->map_col_to_list0, list, sidx, ref1sidx, 0);
  110. for(field=0; field<2; field++)
  111. fill_colmap(h, h->map_col_to_list0_field[field], list, field, field, 1);
  112. }
  113. }
  114. void ff_h264_pred_direct_motion(H264Context * const h, int *mb_type){
  115. MpegEncContext * const s = &h->s;
  116. int b8_stride = h->b8_stride;
  117. int b4_stride = h->b_stride;
  118. int mb_xy = h->mb_xy;
  119. int mb_type_col[2];
  120. const int16_t (*l1mv0)[2], (*l1mv1)[2];
  121. const int8_t *l1ref0, *l1ref1;
  122. const int is_b8x8 = IS_8X8(*mb_type);
  123. unsigned int sub_mb_type;
  124. int i8, i4;
  125. assert(h->ref_list[1][0].reference&3);
  126. #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
  127. if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL
  128. if(!IS_INTERLACED(*mb_type)){ // AFR/FR -> AFL/FL
  129. int cur_poc = s->current_picture_ptr->poc;
  130. int *col_poc = h->ref_list[1]->field_poc;
  131. int col_parity = FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc);
  132. mb_xy= s->mb_x + ((s->mb_y&~1) + col_parity)*s->mb_stride;
  133. b8_stride = 0;
  134. }else if(!(s->picture_structure & h->ref_list[1][0].reference) && !h->ref_list[1][0].mbaff){// FL -> FL & differ parity
  135. int fieldoff= 2*(h->ref_list[1][0].reference)-3;
  136. mb_xy += s->mb_stride*fieldoff;
  137. }
  138. goto single_col;
  139. }else{ // AFL/AFR/FR/FL -> AFR/FR
  140. if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR
  141. mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
  142. mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
  143. mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
  144. b8_stride *= 3;
  145. b4_stride *= 6;
  146. //FIXME IS_8X8(mb_type_col[0]) && !h->sps.direct_8x8_inference_flag
  147. if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)
  148. && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)
  149. && !is_b8x8){
  150. sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
  151. *mb_type |= MB_TYPE_16x8 |MB_TYPE_L0L1|MB_TYPE_DIRECT2; /* B_16x8 */
  152. }else{
  153. sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
  154. *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
  155. }
  156. }else{ // AFR/FR -> AFR/FR
  157. single_col:
  158. mb_type_col[0] =
  159. mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy];
  160. if(IS_8X8(mb_type_col[0]) && !h->sps.direct_8x8_inference_flag){
  161. /* FIXME save sub mb types from previous frames (or derive from MVs)
  162. * so we know exactly what block size to use */
  163. sub_mb_type = MB_TYPE_8x8|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_4x4 */
  164. *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
  165. }else if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){
  166. sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
  167. *mb_type |= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_16x16 */
  168. }else{
  169. sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
  170. *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
  171. }
  172. }
  173. }
  174. l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
  175. l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
  176. l1ref0 = &h->ref_list[1][0].ref_index [0][h->mb2b8_xy[mb_xy]];
  177. l1ref1 = &h->ref_list[1][0].ref_index [1][h->mb2b8_xy[mb_xy]];
  178. if(!b8_stride){
  179. if(s->mb_y&1){
  180. l1ref0 += h->b8_stride;
  181. l1ref1 += h->b8_stride;
  182. l1mv0 += 2*b4_stride;
  183. l1mv1 += 2*b4_stride;
  184. }
  185. }
  186. if(h->direct_spatial_mv_pred){
  187. int ref[2];
  188. int mv[2][2];
  189. int list;
  190. /* FIXME interlacing + spatial direct uses wrong colocated block positions */
  191. /* ref = min(neighbors) */
  192. for(list=0; list<2; list++){
  193. int refa = h->ref_cache[list][scan8[0] - 1];
  194. int refb = h->ref_cache[list][scan8[0] - 8];
  195. int refc = h->ref_cache[list][scan8[0] - 8 + 4];
  196. if(refc == PART_NOT_AVAILABLE)
  197. refc = h->ref_cache[list][scan8[0] - 8 - 1];
  198. ref[list] = FFMIN3((unsigned)refa, (unsigned)refb, (unsigned)refc);
  199. if(ref[list] < 0)
  200. ref[list] = -1;
  201. }
  202. if(ref[0] < 0 && ref[1] < 0){
  203. ref[0] = ref[1] = 0;
  204. mv[0][0] = mv[0][1] =
  205. mv[1][0] = mv[1][1] = 0;
  206. }else{
  207. for(list=0; list<2; list++){
  208. if(ref[list] >= 0)
  209. pred_motion(h, 0, 4, list, ref[list], &mv[list][0], &mv[list][1]);
  210. else
  211. mv[list][0] = mv[list][1] = 0;
  212. }
  213. }
  214. if(ref[1] < 0){
  215. if(!is_b8x8)
  216. *mb_type &= ~MB_TYPE_L1;
  217. sub_mb_type &= ~MB_TYPE_L1;
  218. }else if(ref[0] < 0){
  219. if(!is_b8x8)
  220. *mb_type &= ~MB_TYPE_L0;
  221. sub_mb_type &= ~MB_TYPE_L0;
  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=0, b=0;
  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])
  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. if(ref[0] > 0)
  239. a= pack16to32(mv[0][0],mv[0][1]);
  240. if(ref[1] > 0)
  241. b= pack16to32(mv[1][0],mv[1][1]);
  242. }else{
  243. a= pack16to32(mv[0][0],mv[0][1]);
  244. b= pack16to32(mv[1][0],mv[1][1]);
  245. }
  246. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4);
  247. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4);
  248. }
  249. }else if(IS_16X16(*mb_type)){
  250. int a=0, b=0;
  251. fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
  252. fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
  253. if(!IS_INTRA(mb_type_col[0])
  254. && ( (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)
  255. || (l1ref0[0] < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1
  256. && (h->x264_build>33 || !h->x264_build)))){
  257. if(ref[0] > 0)
  258. a= pack16to32(mv[0][0],mv[0][1]);
  259. if(ref[1] > 0)
  260. b= pack16to32(mv[1][0],mv[1][1]);
  261. }else{
  262. a= pack16to32(mv[0][0],mv[0][1]);
  263. b= pack16to32(mv[1][0],mv[1][1]);
  264. }
  265. fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);
  266. fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);
  267. }else{
  268. for(i8=0; i8<4; i8++){
  269. const int x8 = i8&1;
  270. const int y8 = i8>>1;
  271. if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
  272. continue;
  273. h->sub_mb_type[i8] = sub_mb_type;
  274. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mv[0][0],mv[0][1]), 4);
  275. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mv[1][0],mv[1][1]), 4);
  276. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
  277. fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
  278. /* col_zero_flag */
  279. if(!IS_INTRA(mb_type_col[0]) && ( l1ref0[x8 + y8*b8_stride] == 0
  280. || (l1ref0[x8 + y8*b8_stride] < 0 && l1ref1[x8 + y8*b8_stride] == 0
  281. && (h->x264_build>33 || !h->x264_build)))){
  282. const int16_t (*l1mv)[2]= l1ref0[x8 + y8*b8_stride] == 0 ? l1mv0 : l1mv1;
  283. if(IS_SUB_8X8(sub_mb_type)){
  284. const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
  285. if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
  286. if(ref[0] == 0)
  287. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
  288. if(ref[1] == 0)
  289. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
  290. }
  291. }else
  292. for(i4=0; i4<4; i4++){
  293. const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
  294. if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
  295. if(ref[0] == 0)
  296. *(uint32_t*)h->mv_cache[0][scan8[i8*4+i4]] = 0;
  297. if(ref[1] == 0)
  298. *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = 0;
  299. }
  300. }
  301. }
  302. }
  303. }
  304. }else{ /* direct temporal mv pred */
  305. const int *map_col_to_list0[2] = {h->map_col_to_list0[0], h->map_col_to_list0[1]};
  306. const int *dist_scale_factor = h->dist_scale_factor;
  307. int ref_offset= 0;
  308. if(FRAME_MBAFF && IS_INTERLACED(*mb_type)){
  309. map_col_to_list0[0] = h->map_col_to_list0_field[s->mb_y&1][0];
  310. map_col_to_list0[1] = h->map_col_to_list0_field[s->mb_y&1][1];
  311. dist_scale_factor =h->dist_scale_factor_field[s->mb_y&1];
  312. }
  313. if(h->ref_list[1][0].mbaff && IS_INTERLACED(mb_type_col[0]))
  314. ref_offset += 16;
  315. if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
  316. /* FIXME assumes direct_8x8_inference == 1 */
  317. int y_shift = 2*!IS_INTERLACED(*mb_type);
  318. for(i8=0; i8<4; i8++){
  319. const int x8 = i8&1;
  320. const int y8 = i8>>1;
  321. int ref0, scale;
  322. const int16_t (*l1mv)[2]= l1mv0;
  323. if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
  324. continue;
  325. h->sub_mb_type[i8] = sub_mb_type;
  326. fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
  327. if(IS_INTRA(mb_type_col[y8])){
  328. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
  329. fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
  330. fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
  331. continue;
  332. }
  333. ref0 = l1ref0[x8 + y8*b8_stride];
  334. if(ref0 >= 0)
  335. ref0 = map_col_to_list0[0][ref0 + ref_offset];
  336. else{
  337. ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
  338. l1mv= l1mv1;
  339. }
  340. scale = dist_scale_factor[ref0];
  341. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
  342. {
  343. const int16_t *mv_col = l1mv[x8*3 + y8*b4_stride];
  344. int my_col = (mv_col[1]<<y_shift)/2;
  345. int mx = (scale * mv_col[0] + 128) >> 8;
  346. int my = (scale * my_col + 128) >> 8;
  347. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
  348. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-my_col), 4);
  349. }
  350. }
  351. return;
  352. }
  353. /* one-to-one mv scaling */
  354. if(IS_16X16(*mb_type)){
  355. int ref, mv0, mv1;
  356. fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1);
  357. if(IS_INTRA(mb_type_col[0])){
  358. ref=mv0=mv1=0;
  359. }else{
  360. const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
  361. : map_col_to_list0[1][l1ref1[0] + ref_offset];
  362. const int scale = dist_scale_factor[ref0];
  363. const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
  364. int mv_l0[2];
  365. mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
  366. mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
  367. ref= ref0;
  368. mv0= pack16to32(mv_l0[0],mv_l0[1]);
  369. mv1= pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
  370. }
  371. fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
  372. fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4);
  373. fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4);
  374. }else{
  375. for(i8=0; i8<4; i8++){
  376. const int x8 = i8&1;
  377. const int y8 = i8>>1;
  378. int ref0, scale;
  379. const int16_t (*l1mv)[2]= l1mv0;
  380. if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
  381. continue;
  382. h->sub_mb_type[i8] = sub_mb_type;
  383. fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
  384. if(IS_INTRA(mb_type_col[0])){
  385. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
  386. fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
  387. fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
  388. continue;
  389. }
  390. ref0 = l1ref0[x8 + y8*b8_stride] + ref_offset;
  391. if(ref0 >= 0)
  392. ref0 = map_col_to_list0[0][ref0];
  393. else{
  394. ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
  395. l1mv= l1mv1;
  396. }
  397. scale = dist_scale_factor[ref0];
  398. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
  399. if(IS_SUB_8X8(sub_mb_type)){
  400. const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
  401. int mx = (scale * mv_col[0] + 128) >> 8;
  402. int my = (scale * mv_col[1] + 128) >> 8;
  403. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
  404. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-mv_col[1]), 4);
  405. }else
  406. for(i4=0; i4<4; i4++){
  407. const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
  408. int16_t *mv_l0 = h->mv_cache[0][scan8[i8*4+i4]];
  409. mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
  410. mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
  411. *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] =
  412. pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
  413. }
  414. }
  415. }
  416. }
  417. }