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.

475 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. ref[list] = -1;
  208. }
  209. if(ref[0] < 0 && ref[1] < 0){
  210. ref[0] = ref[1] = 0;
  211. mv[0][0] = mv[0][1] =
  212. mv[1][0] = mv[1][1] = 0;
  213. }else{
  214. for(list=0; list<2; list++){
  215. if(ref[list] >= 0)
  216. pred_motion(h, 0, 4, list, ref[list], &mv[list][0], &mv[list][1]);
  217. else
  218. mv[list][0] = mv[list][1] = 0;
  219. }
  220. }
  221. if(ref[1] < 0){
  222. if(!is_b8x8)
  223. *mb_type &= ~MB_TYPE_L1;
  224. sub_mb_type &= ~MB_TYPE_L1;
  225. }else if(ref[0] < 0){
  226. if(!is_b8x8)
  227. *mb_type &= ~MB_TYPE_L0;
  228. sub_mb_type &= ~MB_TYPE_L0;
  229. }
  230. if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
  231. for(i8=0; i8<4; i8++){
  232. int x8 = i8&1;
  233. int y8 = i8>>1;
  234. int xy8 = x8+y8*b8_stride;
  235. int xy4 = 3*x8+y8*b4_stride;
  236. int a=0, b=0;
  237. if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
  238. continue;
  239. h->sub_mb_type[i8] = sub_mb_type;
  240. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
  241. fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
  242. if(!IS_INTRA(mb_type_col[y8]) && !h->ref_list[1][0].long_ref
  243. && ( (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1)
  244. || (l1ref0[xy8] < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){
  245. if(ref[0] > 0)
  246. a= pack16to32(mv[0][0],mv[0][1]);
  247. if(ref[1] > 0)
  248. b= pack16to32(mv[1][0],mv[1][1]);
  249. }else{
  250. a= pack16to32(mv[0][0],mv[0][1]);
  251. b= pack16to32(mv[1][0],mv[1][1]);
  252. }
  253. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4);
  254. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4);
  255. }
  256. }else if(IS_16X16(*mb_type)){
  257. int a=0, b=0;
  258. fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
  259. fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
  260. if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref
  261. && ( (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)
  262. || (l1ref0[0] < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1
  263. && (h->x264_build>33 || !h->x264_build)))){
  264. if(ref[0] > 0)
  265. a= pack16to32(mv[0][0],mv[0][1]);
  266. if(ref[1] > 0)
  267. b= pack16to32(mv[1][0],mv[1][1]);
  268. }else{
  269. a= pack16to32(mv[0][0],mv[0][1]);
  270. b= pack16to32(mv[1][0],mv[1][1]);
  271. }
  272. fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);
  273. fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);
  274. }else{
  275. for(i8=0; i8<4; i8++){
  276. const int x8 = i8&1;
  277. const int y8 = i8>>1;
  278. if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
  279. continue;
  280. h->sub_mb_type[i8] = sub_mb_type;
  281. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mv[0][0],mv[0][1]), 4);
  282. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mv[1][0],mv[1][1]), 4);
  283. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
  284. fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
  285. /* col_zero_flag */
  286. if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref && ( l1ref0[x8 + y8*b8_stride] == 0
  287. || (l1ref0[x8 + y8*b8_stride] < 0 && l1ref1[x8 + y8*b8_stride] == 0
  288. && (h->x264_build>33 || !h->x264_build)))){
  289. const int16_t (*l1mv)[2]= l1ref0[x8 + y8*b8_stride] == 0 ? l1mv0 : l1mv1;
  290. if(IS_SUB_8X8(sub_mb_type)){
  291. const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
  292. if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
  293. if(ref[0] == 0)
  294. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
  295. if(ref[1] == 0)
  296. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
  297. }
  298. }else
  299. for(i4=0; i4<4; i4++){
  300. const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
  301. if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
  302. if(ref[0] == 0)
  303. *(uint32_t*)h->mv_cache[0][scan8[i8*4+i4]] = 0;
  304. if(ref[1] == 0)
  305. *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = 0;
  306. }
  307. }
  308. }
  309. }
  310. }
  311. }else{ /* direct temporal mv pred */
  312. const int *map_col_to_list0[2] = {h->map_col_to_list0[0], h->map_col_to_list0[1]};
  313. const int *dist_scale_factor = h->dist_scale_factor;
  314. int ref_offset= 0;
  315. if(FRAME_MBAFF && IS_INTERLACED(*mb_type)){
  316. map_col_to_list0[0] = h->map_col_to_list0_field[s->mb_y&1][0];
  317. map_col_to_list0[1] = h->map_col_to_list0_field[s->mb_y&1][1];
  318. dist_scale_factor =h->dist_scale_factor_field[s->mb_y&1];
  319. }
  320. if(h->ref_list[1][0].mbaff && IS_INTERLACED(mb_type_col[0]))
  321. ref_offset += 16;
  322. if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
  323. int y_shift = 2*!IS_INTERLACED(*mb_type);
  324. assert(h->sps.direct_8x8_inference_flag);
  325. for(i8=0; i8<4; i8++){
  326. const int x8 = i8&1;
  327. const int y8 = i8>>1;
  328. int ref0, scale;
  329. const int16_t (*l1mv)[2]= l1mv0;
  330. if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
  331. continue;
  332. h->sub_mb_type[i8] = sub_mb_type;
  333. fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
  334. if(IS_INTRA(mb_type_col[y8])){
  335. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
  336. fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
  337. fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
  338. continue;
  339. }
  340. ref0 = l1ref0[x8 + y8*b8_stride];
  341. if(ref0 >= 0)
  342. ref0 = map_col_to_list0[0][ref0 + ref_offset];
  343. else{
  344. ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
  345. l1mv= l1mv1;
  346. }
  347. scale = dist_scale_factor[ref0];
  348. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
  349. {
  350. const int16_t *mv_col = l1mv[x8*3 + y8*b4_stride];
  351. int my_col = (mv_col[1]<<y_shift)/2;
  352. int mx = (scale * mv_col[0] + 128) >> 8;
  353. int my = (scale * my_col + 128) >> 8;
  354. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
  355. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-my_col), 4);
  356. }
  357. }
  358. return;
  359. }
  360. /* one-to-one mv scaling */
  361. if(IS_16X16(*mb_type)){
  362. int ref, mv0, mv1;
  363. fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1);
  364. if(IS_INTRA(mb_type_col[0])){
  365. ref=mv0=mv1=0;
  366. }else{
  367. const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
  368. : map_col_to_list0[1][l1ref1[0] + ref_offset];
  369. const int scale = dist_scale_factor[ref0];
  370. const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
  371. int mv_l0[2];
  372. mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
  373. mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
  374. ref= ref0;
  375. mv0= pack16to32(mv_l0[0],mv_l0[1]);
  376. mv1= pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
  377. }
  378. fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
  379. fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4);
  380. fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4);
  381. }else{
  382. for(i8=0; i8<4; i8++){
  383. const int x8 = i8&1;
  384. const int y8 = i8>>1;
  385. int ref0, scale;
  386. const int16_t (*l1mv)[2]= l1mv0;
  387. if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
  388. continue;
  389. h->sub_mb_type[i8] = sub_mb_type;
  390. fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
  391. if(IS_INTRA(mb_type_col[0])){
  392. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
  393. fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
  394. fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
  395. continue;
  396. }
  397. ref0 = l1ref0[x8 + y8*b8_stride];
  398. if(ref0 >= 0)
  399. ref0 = map_col_to_list0[0][ref0 + ref_offset];
  400. else{
  401. ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
  402. l1mv= l1mv1;
  403. }
  404. scale = dist_scale_factor[ref0];
  405. fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
  406. if(IS_SUB_8X8(sub_mb_type)){
  407. const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
  408. int mx = (scale * mv_col[0] + 128) >> 8;
  409. int my = (scale * mv_col[1] + 128) >> 8;
  410. fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
  411. fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-mv_col[1]), 4);
  412. }else
  413. for(i4=0; i4<4; i4++){
  414. const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
  415. int16_t *mv_l0 = h->mv_cache[0][scan8[i8*4+i4]];
  416. mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
  417. mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
  418. *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] =
  419. pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
  420. }
  421. }
  422. }
  423. }
  424. }