Statistics
| Branch: | Revision:

ffmpeg / libavcodec / h264_direct.c @ 33a6c0c9

History | View | Annotate | Download (20.3 KB)

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 "h264_mvpred.h"
34
#include "rectangle.h"
35

    
36
//#undef NDEBUG
37
#include <assert.h>
38

    
39

    
40
static int get_scale_factor(H264Context * const h, int poc, int poc1, int i){
41
    int poc0 = h->ref_list[0][i].poc;
42
    int td = av_clip(poc1 - poc0, -128, 127);
43
    if(td == 0 || h->ref_list[0][i].long_ref){
44
        return 256;
45
    }else{
46
        int tb = av_clip(poc - poc0, -128, 127);
47
        int tx = (16384 + (FFABS(td) >> 1)) / td;
48
        return av_clip((tb*tx + 32) >> 6, -1024, 1023);
49
    }
50
}
51

    
52
void ff_h264_direct_dist_scale_factor(H264Context * const h){
53
    MpegEncContext * const s = &h->s;
54
    const int poc = h->s.current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ];
55
    const int poc1 = h->ref_list[1][0].poc;
56
    int i, field;
57
    for(field=0; field<2; field++){
58
        const int poc  = h->s.current_picture_ptr->field_poc[field];
59
        const int poc1 = h->ref_list[1][0].field_poc[field];
60
        for(i=0; i < 2*h->ref_count[0]; i++)
61
            h->dist_scale_factor_field[field][i^field] = get_scale_factor(h, poc, poc1, i+16);
62
    }
63

    
64
    for(i=0; i<h->ref_count[0]; i++){
65
        h->dist_scale_factor[i] = get_scale_factor(h, poc, poc1, i);
66
    }
67
}
68

    
69
static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){
70
    MpegEncContext * const s = &h->s;
71
    Picture * const ref1 = &h->ref_list[1][0];
72
    int j, old_ref, rfield;
73
    int start= mbafi ? 16                      : 0;
74
    int end  = mbafi ? 16+2*h->ref_count[0]    : h->ref_count[0];
75
    int interl= mbafi || s->picture_structure != PICT_FRAME;
76

    
77
    /* bogus; fills in for missing frames */
78
    memset(map[list], 0, sizeof(map[list]));
79

    
80
    for(rfield=0; rfield<2; rfield++){
81
        for(old_ref=0; old_ref<ref1->ref_count[colfield][list]; old_ref++){
82
            int poc = ref1->ref_poc[colfield][list][old_ref];
83

    
84
            if     (!interl)
85
                poc |= 3;
86
            else if( interl && (poc&3) == 3) //FIXME store all MBAFF references so this isnt needed
87
                poc= (poc&~3) + rfield + 1;
88

    
89
            for(j=start; j<end; j++){
90
                if(4*h->ref_list[0][j].frame_num + (h->ref_list[0][j].reference&3) == poc){
91
                    int cur_ref= mbafi ? (j-16)^field : j;
92
                    map[list][2*old_ref + (rfield^field) + 16] = cur_ref;
93
                    if(rfield == field || !interl)
94
                        map[list][old_ref] = cur_ref;
95
                    break;
96
                }
97
            }
98
        }
99
    }
100
}
101

    
102
void ff_h264_direct_ref_list_init(H264Context * const h){
103
    MpegEncContext * const s = &h->s;
104
    Picture * const ref1 = &h->ref_list[1][0];
105
    Picture * const cur = s->current_picture_ptr;
106
    int list, j, field;
107
    int sidx= (s->picture_structure&1)^1;
108
    int ref1sidx= (ref1->reference&1)^1;
109

    
110
    for(list=0; list<2; list++){
111
        cur->ref_count[sidx][list] = h->ref_count[list];
112
        for(j=0; j<h->ref_count[list]; j++)
113
            cur->ref_poc[sidx][list][j] = 4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3);
114
    }
115

    
116
    if(s->picture_structure == PICT_FRAME){
117
        memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0]));
118
        memcpy(cur->ref_poc  [1], cur->ref_poc  [0], sizeof(cur->ref_poc  [0]));
119
    }
120

    
121
    cur->mbaff= FRAME_MBAFF;
122

    
123
    if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred)
124
        return;
125

    
126
    if(s->picture_structure == PICT_FRAME){
127
        int cur_poc = s->current_picture_ptr->poc;
128
        int *col_poc = h->ref_list[1]->field_poc;
129
        ref1sidx=sidx= (FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc));
130
    }
131

    
132
    for(list=0; list<2; list++){
133
        fill_colmap(h, h->map_col_to_list0, list, sidx, ref1sidx, 0);
134
        if(FRAME_MBAFF)
135
        for(field=0; field<2; field++)
136
            fill_colmap(h, h->map_col_to_list0_field[field], list, field, field, 1);
137
    }
138
}
139

    
140
void ff_h264_pred_direct_motion(H264Context * const h, int *mb_type){
141
    MpegEncContext * const s = &h->s;
142
    int b8_stride = h->b8_stride;
143
    int b4_stride = h->b_stride;
144
    int mb_xy = h->mb_xy;
145
    int mb_type_col[2];
146
    const int16_t (*l1mv0)[2], (*l1mv1)[2];
147
    const int8_t *l1ref0, *l1ref1;
148
    const int is_b8x8 = IS_8X8(*mb_type);
149
    unsigned int sub_mb_type;
150
    int i8, i4;
151

    
152
    assert(h->ref_list[1][0].reference&3);
153

    
154
#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
155

    
156
    if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL
157
        if(!IS_INTERLACED(*mb_type)){                    //     AFR/FR    -> AFL/FL
158
            int cur_poc = s->current_picture_ptr->poc;
159
            int *col_poc = h->ref_list[1]->field_poc;
160
            int col_parity = FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc);
161
            mb_xy= s->mb_x + ((s->mb_y&~1) + col_parity)*s->mb_stride;
162
            b8_stride = 0;
163
        }else if(!(s->picture_structure & h->ref_list[1][0].reference) && !h->ref_list[1][0].mbaff){// FL -> FL & differ parity
164
            int fieldoff= 2*(h->ref_list[1][0].reference)-3;
165
            mb_xy += s->mb_stride*fieldoff;
166
        }
167
        goto single_col;
168
    }else{                                               // AFL/AFR/FR/FL -> AFR/FR
169
        if(IS_INTERLACED(*mb_type)){                     // AFL       /FL -> AFR/FR
170
            mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
171
            mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
172
            mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
173
            b8_stride *= 3;
174
            b4_stride *= 6;
175
            //FIXME IS_8X8(mb_type_col[0]) && !h->sps.direct_8x8_inference_flag
176
            if(    (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)
177
                && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)
178
                && !is_b8x8){
179
                sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
180
                *mb_type   |= MB_TYPE_16x8 |MB_TYPE_L0L1|MB_TYPE_DIRECT2; /* B_16x8 */
181
            }else{
182
                sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
183
                *mb_type   |= MB_TYPE_8x8|MB_TYPE_L0L1;
184
            }
185
        }else{                                           //     AFR/FR    -> AFR/FR
186
single_col:
187
            mb_type_col[0] =
188
            mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy];
189
            if(IS_8X8(mb_type_col[0]) && !h->sps.direct_8x8_inference_flag){
190
                /* FIXME save sub mb types from previous frames (or derive from MVs)
191
                * so we know exactly what block size to use */
192
                sub_mb_type = MB_TYPE_8x8|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_4x4 */
193
                *mb_type   |= MB_TYPE_8x8|MB_TYPE_L0L1;
194
            }else if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){
195
                sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
196
                *mb_type   |= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_16x16 */
197
            }else{
198
                sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
199
                *mb_type   |= MB_TYPE_8x8|MB_TYPE_L0L1;
200
            }
201
        }
202
    }
203

    
204
    l1mv0  = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
205
    l1mv1  = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
206
    l1ref0 = &h->ref_list[1][0].ref_index [0][h->mb2b8_xy[mb_xy]];
207
    l1ref1 = &h->ref_list[1][0].ref_index [1][h->mb2b8_xy[mb_xy]];
208
    if(!b8_stride){
209
        if(s->mb_y&1){
210
            l1ref0 += h->b8_stride;
211
            l1ref1 += h->b8_stride;
212
            l1mv0  +=  2*b4_stride;
213
            l1mv1  +=  2*b4_stride;
214
        }
215
    }
216

    
217
    if(h->direct_spatial_mv_pred){
218
        int ref[2];
219
        int mv[2][2];
220
        int list;
221

    
222
        /* FIXME interlacing + spatial direct uses wrong colocated block positions */
223

    
224
        /* ref = min(neighbors) */
225
        for(list=0; list<2; list++){
226
            int refa = h->ref_cache[list][scan8[0] - 1];
227
            int refb = h->ref_cache[list][scan8[0] - 8];
228
            int refc = h->ref_cache[list][scan8[0] - 8 + 4];
229
            if(refc == PART_NOT_AVAILABLE)
230
                refc = h->ref_cache[list][scan8[0] - 8 - 1];
231
            ref[list] = FFMIN3((unsigned)refa, (unsigned)refb, (unsigned)refc);
232
            if(ref[list] < 0)
233
                ref[list] = -1;
234
        }
235

    
236
        if(ref[0] < 0 && ref[1] < 0){
237
            ref[0] = ref[1] = 0;
238
            mv[0][0] = mv[0][1] =
239
            mv[1][0] = mv[1][1] = 0;
240
        }else{
241
            for(list=0; list<2; list++){
242
                if(ref[list] >= 0)
243
                    pred_motion(h, 0, 4, list, ref[list], &mv[list][0], &mv[list][1]);
244
                else
245
                    mv[list][0] = mv[list][1] = 0;
246
            }
247
        }
248

    
249
        if(ref[1] < 0){
250
            if(!is_b8x8)
251
                *mb_type &= ~MB_TYPE_L1;
252
            sub_mb_type &= ~MB_TYPE_L1;
253
        }else if(ref[0] < 0){
254
            if(!is_b8x8)
255
                *mb_type &= ~MB_TYPE_L0;
256
            sub_mb_type &= ~MB_TYPE_L0;
257
        }
258

    
259
        if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
260
            for(i8=0; i8<4; i8++){
261
                int x8 = i8&1;
262
                int y8 = i8>>1;
263
                int xy8 = x8+y8*b8_stride;
264
                int xy4 = 3*x8+y8*b4_stride;
265
                int a=0, b=0;
266

    
267
                if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
268
                    continue;
269
                h->sub_mb_type[i8] = sub_mb_type;
270

    
271
                fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
272
                fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
273
                if(!IS_INTRA(mb_type_col[y8]) && !h->ref_list[1][0].long_ref
274
                   && (   (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1)
275
                       || (l1ref0[xy8]  < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){
276
                    if(ref[0] > 0)
277
                        a= pack16to32(mv[0][0],mv[0][1]);
278
                    if(ref[1] > 0)
279
                        b= pack16to32(mv[1][0],mv[1][1]);
280
                }else{
281
                    a= pack16to32(mv[0][0],mv[0][1]);
282
                    b= pack16to32(mv[1][0],mv[1][1]);
283
                }
284
                fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4);
285
                fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4);
286
            }
287
        }else if(IS_16X16(*mb_type)){
288
            int a=0, b=0;
289

    
290
            fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
291
            fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
292
            if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref
293
               && (   (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)
294
                   || (l1ref0[0]  < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1
295
                       && (h->x264_build>33 || !h->x264_build)))){
296
                if(ref[0] > 0)
297
                    a= pack16to32(mv[0][0],mv[0][1]);
298
                if(ref[1] > 0)
299
                    b= pack16to32(mv[1][0],mv[1][1]);
300
            }else{
301
                a= pack16to32(mv[0][0],mv[0][1]);
302
                b= pack16to32(mv[1][0],mv[1][1]);
303
            }
304
            fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);
305
            fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);
306
        }else{
307
            for(i8=0; i8<4; i8++){
308
                const int x8 = i8&1;
309
                const int y8 = i8>>1;
310

    
311
                if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
312
                    continue;
313
                h->sub_mb_type[i8] = sub_mb_type;
314

    
315
                fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mv[0][0],mv[0][1]), 4);
316
                fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mv[1][0],mv[1][1]), 4);
317
                fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
318
                fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
319

    
320
                /* col_zero_flag */
321
                if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref && (   l1ref0[x8 + y8*b8_stride] == 0
322
                                              || (l1ref0[x8 + y8*b8_stride] < 0 && l1ref1[x8 + y8*b8_stride] == 0
323
                                                  && (h->x264_build>33 || !h->x264_build)))){
324
                    const int16_t (*l1mv)[2]= l1ref0[x8 + y8*b8_stride] == 0 ? l1mv0 : l1mv1;
325
                    if(IS_SUB_8X8(sub_mb_type)){
326
                        const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
327
                        if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
328
                            if(ref[0] == 0)
329
                                fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
330
                            if(ref[1] == 0)
331
                                fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
332
                        }
333
                    }else
334
                    for(i4=0; i4<4; i4++){
335
                        const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
336
                        if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
337
                            if(ref[0] == 0)
338
                                *(uint32_t*)h->mv_cache[0][scan8[i8*4+i4]] = 0;
339
                            if(ref[1] == 0)
340
                                *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = 0;
341
                        }
342
                    }
343
                }
344
            }
345
        }
346
    }else{ /* direct temporal mv pred */
347
        const int *map_col_to_list0[2] = {h->map_col_to_list0[0], h->map_col_to_list0[1]};
348
        const int *dist_scale_factor = h->dist_scale_factor;
349
        int ref_offset= 0;
350

    
351
        if(FRAME_MBAFF && IS_INTERLACED(*mb_type)){
352
            map_col_to_list0[0] = h->map_col_to_list0_field[s->mb_y&1][0];
353
            map_col_to_list0[1] = h->map_col_to_list0_field[s->mb_y&1][1];
354
            dist_scale_factor   =h->dist_scale_factor_field[s->mb_y&1];
355
        }
356
        if(h->ref_list[1][0].mbaff && IS_INTERLACED(mb_type_col[0]))
357
            ref_offset += 16;
358

    
359
        if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
360
            /* FIXME assumes direct_8x8_inference == 1 */
361
            int y_shift  = 2*!IS_INTERLACED(*mb_type);
362
            assert(h->sps.direct_8x8_inference_flag);
363

    
364
            for(i8=0; i8<4; i8++){
365
                const int x8 = i8&1;
366
                const int y8 = i8>>1;
367
                int ref0, scale;
368
                const int16_t (*l1mv)[2]= l1mv0;
369

    
370
                if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
371
                    continue;
372
                h->sub_mb_type[i8] = sub_mb_type;
373

    
374
                fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
375
                if(IS_INTRA(mb_type_col[y8])){
376
                    fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
377
                    fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
378
                    fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
379
                    continue;
380
                }
381

    
382
                ref0 = l1ref0[x8 + y8*b8_stride];
383
                if(ref0 >= 0)
384
                    ref0 = map_col_to_list0[0][ref0 + ref_offset];
385
                else{
386
                    ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
387
                    l1mv= l1mv1;
388
                }
389
                scale = dist_scale_factor[ref0];
390
                fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
391

    
392
                {
393
                    const int16_t *mv_col = l1mv[x8*3 + y8*b4_stride];
394
                    int my_col = (mv_col[1]<<y_shift)/2;
395
                    int mx = (scale * mv_col[0] + 128) >> 8;
396
                    int my = (scale * my_col + 128) >> 8;
397
                    fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
398
                    fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-my_col), 4);
399
                }
400
            }
401
            return;
402
        }
403

    
404
        /* one-to-one mv scaling */
405

    
406
        if(IS_16X16(*mb_type)){
407
            int ref, mv0, mv1;
408

    
409
            fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1);
410
            if(IS_INTRA(mb_type_col[0])){
411
                ref=mv0=mv1=0;
412
            }else{
413
                const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
414
                                                : map_col_to_list0[1][l1ref1[0] + ref_offset];
415
                const int scale = dist_scale_factor[ref0];
416
                const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
417
                int mv_l0[2];
418
                mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
419
                mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
420
                ref= ref0;
421
                mv0= pack16to32(mv_l0[0],mv_l0[1]);
422
                mv1= pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
423
            }
424
            fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
425
            fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4);
426
            fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4);
427
        }else{
428
            for(i8=0; i8<4; i8++){
429
                const int x8 = i8&1;
430
                const int y8 = i8>>1;
431
                int ref0, scale;
432
                const int16_t (*l1mv)[2]= l1mv0;
433

    
434
                if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
435
                    continue;
436
                h->sub_mb_type[i8] = sub_mb_type;
437
                fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
438
                if(IS_INTRA(mb_type_col[0])){
439
                    fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
440
                    fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
441
                    fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
442
                    continue;
443
                }
444

    
445
                ref0 = l1ref0[x8 + y8*b8_stride];
446
                if(ref0 >= 0)
447
                    ref0 = map_col_to_list0[0][ref0 + ref_offset];
448
                else{
449
                    ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
450
                    l1mv= l1mv1;
451
                }
452
                scale = dist_scale_factor[ref0];
453

    
454
                fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
455
                if(IS_SUB_8X8(sub_mb_type)){
456
                    const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
457
                    int mx = (scale * mv_col[0] + 128) >> 8;
458
                    int my = (scale * mv_col[1] + 128) >> 8;
459
                    fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
460
                    fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-mv_col[1]), 4);
461
                }else
462
                for(i4=0; i4<4; i4++){
463
                    const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
464
                    int16_t *mv_l0 = h->mv_cache[0][scan8[i8*4+i4]];
465
                    mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
466
                    mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
467
                    *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] =
468
                        pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
469
                }
470
            }
471
        }
472
    }
473
}