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