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.

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