Statistics
| Branch: | Revision:

ffmpeg / libavcodec / h264_loopfilter.c @ 6d7e6b26

History | View | Annotate | Download (34.4 KB)

1
/*
2
 * H.26L/H.264/AVC/JVT/14496-10/... loop filter
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_loopfilter.c
24
 * H.264 / AVC / MPEG4 part10 loop filter.
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 "mathops.h"
34
#include "rectangle.h"
35

    
36
#if ARCH_X86
37
#include "x86/h264_i386.h"
38
#endif
39

    
40
//#undef NDEBUG
41
#include <assert.h>
42

    
43
/* Deblocking filter (p153) */
44
static const uint8_t alpha_table[52*3] = {
45
     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
46
     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
47
     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
48
     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
49
     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
50
     0,  0,  0,  0,  0,  0,  4,  4,  5,  6,
51
     7,  8,  9, 10, 12, 13, 15, 17, 20, 22,
52
    25, 28, 32, 36, 40, 45, 50, 56, 63, 71,
53
    80, 90,101,113,127,144,162,182,203,226,
54
   255,255,
55
   255,255,255,255,255,255,255,255,255,255,255,255,255,
56
   255,255,255,255,255,255,255,255,255,255,255,255,255,
57
   255,255,255,255,255,255,255,255,255,255,255,255,255,
58
   255,255,255,255,255,255,255,255,255,255,255,255,255,
59
};
60
static const uint8_t beta_table[52*3] = {
61
     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
62
     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
63
     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
64
     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
65
     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
66
     0,  0,  0,  0,  0,  0,  2,  2,  2,  3,
67
     3,  3,  3,  4,  4,  4,  6,  6,  7,  7,
68
     8,  8,  9,  9, 10, 10, 11, 11, 12, 12,
69
    13, 13, 14, 14, 15, 15, 16, 16, 17, 17,
70
    18, 18,
71
    18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
72
    18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
73
    18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
74
    18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
75
};
76
static const uint8_t tc0_table[52*3][4] = {
77
    {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
78
    {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
79
    {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
80
    {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
81
    {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
82
    {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
83
    {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
84
    {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
85
    {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
86
    {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
87
    {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 },
88
    {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 1 },
89
    {-1, 0, 0, 1 }, {-1, 0, 0, 1 }, {-1, 0, 0, 1 }, {-1, 0, 1, 1 }, {-1, 0, 1, 1 }, {-1, 1, 1, 1 },
90
    {-1, 1, 1, 1 }, {-1, 1, 1, 1 }, {-1, 1, 1, 1 }, {-1, 1, 1, 2 }, {-1, 1, 1, 2 }, {-1, 1, 1, 2 },
91
    {-1, 1, 1, 2 }, {-1, 1, 2, 3 }, {-1, 1, 2, 3 }, {-1, 2, 2, 3 }, {-1, 2, 2, 4 }, {-1, 2, 3, 4 },
92
    {-1, 2, 3, 4 }, {-1, 3, 3, 5 }, {-1, 3, 4, 6 }, {-1, 3, 4, 6 }, {-1, 4, 5, 7 }, {-1, 4, 5, 8 },
93
    {-1, 4, 6, 9 }, {-1, 5, 7,10 }, {-1, 6, 8,11 }, {-1, 6, 8,13 }, {-1, 7,10,14 }, {-1, 8,11,16 },
94
    {-1, 9,12,18 }, {-1,10,13,20 }, {-1,11,15,23 }, {-1,13,17,25 },
95
    {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
96
    {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
97
    {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
98
    {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
99
    {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
100
    {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
101
    {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
102
    {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
103
    {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 },
104
};
105

    
106
static void av_noinline filter_mb_edgev( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) {
107
    const int index_a = qp + h->slice_alpha_c0_offset;
108
    const int alpha = (alpha_table+52)[index_a];
109
    const int beta  = (beta_table+52)[qp + h->slice_beta_offset];
110
    if (alpha ==0 || beta == 0) return;
111

    
112
    if( bS[0] < 4 ) {
113
        int8_t tc[4];
114
        tc[0] = (tc0_table+52)[index_a][bS[0]];
115
        tc[1] = (tc0_table+52)[index_a][bS[1]];
116
        tc[2] = (tc0_table+52)[index_a][bS[2]];
117
        tc[3] = (tc0_table+52)[index_a][bS[3]];
118
        h->s.dsp.h264_h_loop_filter_luma(pix, stride, alpha, beta, tc);
119
    } else {
120
        h->s.dsp.h264_h_loop_filter_luma_intra(pix, stride, alpha, beta);
121
    }
122
}
123
static void av_noinline filter_mb_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) {
124
    const int index_a = qp + h->slice_alpha_c0_offset;
125
    const int alpha = (alpha_table+52)[index_a];
126
    const int beta  = (beta_table+52)[qp + h->slice_beta_offset];
127
    if (alpha ==0 || beta == 0) return;
128

    
129
    if( bS[0] < 4 ) {
130
        int8_t tc[4];
131
        tc[0] = (tc0_table+52)[index_a][bS[0]]+1;
132
        tc[1] = (tc0_table+52)[index_a][bS[1]]+1;
133
        tc[2] = (tc0_table+52)[index_a][bS[2]]+1;
134
        tc[3] = (tc0_table+52)[index_a][bS[3]]+1;
135
        h->s.dsp.h264_h_loop_filter_chroma(pix, stride, alpha, beta, tc);
136
    } else {
137
        h->s.dsp.h264_h_loop_filter_chroma_intra(pix, stride, alpha, beta);
138
    }
139
}
140

    
141
static void filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, int16_t bS[8], int qp[2] ) {
142
    int i;
143
    for( i = 0; i < 16; i++, pix += stride) {
144
        int index_a;
145
        int alpha;
146
        int beta;
147

    
148
        int qp_index;
149
        int bS_index = (i >> 1);
150
        if (!MB_FIELD) {
151
            bS_index &= ~1;
152
            bS_index |= (i & 1);
153
        }
154

    
155
        if( bS[bS_index] == 0 ) {
156
            continue;
157
        }
158

    
159
        qp_index = MB_FIELD ? (i >> 3) : (i & 1);
160
        index_a = qp[qp_index] + h->slice_alpha_c0_offset;
161
        alpha = (alpha_table+52)[index_a];
162
        beta  = (beta_table+52)[qp[qp_index] + h->slice_beta_offset];
163

    
164
        if( bS[bS_index] < 4 ) {
165
            const int tc0 = (tc0_table+52)[index_a][bS[bS_index]];
166
            const int p0 = pix[-1];
167
            const int p1 = pix[-2];
168
            const int p2 = pix[-3];
169
            const int q0 = pix[0];
170
            const int q1 = pix[1];
171
            const int q2 = pix[2];
172

    
173
            if( FFABS( p0 - q0 ) < alpha &&
174
                FFABS( p1 - p0 ) < beta &&
175
                FFABS( q1 - q0 ) < beta ) {
176
                int tc = tc0;
177
                int i_delta;
178

    
179
                if( FFABS( p2 - p0 ) < beta ) {
180
                    pix[-2] = p1 + av_clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 );
181
                    tc++;
182
                }
183
                if( FFABS( q2 - q0 ) < beta ) {
184
                    pix[1] = q1 + av_clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 );
185
                    tc++;
186
                }
187

    
188
                i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
189
                pix[-1] = av_clip_uint8( p0 + i_delta );    /* p0' */
190
                pix[0]  = av_clip_uint8( q0 - i_delta );    /* q0' */
191
                tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1);
192
            }
193
        }else{
194
            const int p0 = pix[-1];
195
            const int p1 = pix[-2];
196
            const int p2 = pix[-3];
197

    
198
            const int q0 = pix[0];
199
            const int q1 = pix[1];
200
            const int q2 = pix[2];
201

    
202
            if( FFABS( p0 - q0 ) < alpha &&
203
                FFABS( p1 - p0 ) < beta &&
204
                FFABS( q1 - q0 ) < beta ) {
205

    
206
                if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){
207
                    if( FFABS( p2 - p0 ) < beta)
208
                    {
209
                        const int p3 = pix[-4];
210
                        /* p0', p1', p2' */
211
                        pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;
212
                        pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;
213
                        pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;
214
                    } else {
215
                        /* p0' */
216
                        pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
217
                    }
218
                    if( FFABS( q2 - q0 ) < beta)
219
                    {
220
                        const int q3 = pix[3];
221
                        /* q0', q1', q2' */
222
                        pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;
223
                        pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;
224
                        pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;
225
                    } else {
226
                        /* q0' */
227
                        pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
228
                    }
229
                }else{
230
                    /* p0', q0' */
231
                    pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2;
232
                    pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2;
233
                }
234
                tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, p2, p1, p0, q0, q1, q2, pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]);
235
            }
236
        }
237
    }
238
}
239
static void filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[8], int qp[2] ) {
240
    int i;
241
    for( i = 0; i < 8; i++, pix += stride) {
242
        int index_a;
243
        int alpha;
244
        int beta;
245

    
246
        int qp_index;
247
        int bS_index = i;
248

    
249
        if( bS[bS_index] == 0 ) {
250
            continue;
251
        }
252

    
253
        qp_index = MB_FIELD ? (i >> 2) : (i & 1);
254
        index_a = qp[qp_index] + h->slice_alpha_c0_offset;
255
        alpha = (alpha_table+52)[index_a];
256
        beta  = (beta_table+52)[qp[qp_index] + h->slice_beta_offset];
257

    
258
        if( bS[bS_index] < 4 ) {
259
            const int tc = (tc0_table+52)[index_a][bS[bS_index]] + 1;
260
            const int p0 = pix[-1];
261
            const int p1 = pix[-2];
262
            const int q0 = pix[0];
263
            const int q1 = pix[1];
264

    
265
            if( FFABS( p0 - q0 ) < alpha &&
266
                FFABS( p1 - p0 ) < beta &&
267
                FFABS( q1 - q0 ) < beta ) {
268
                const int i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
269

    
270
                pix[-1] = av_clip_uint8( p0 + i_delta );    /* p0' */
271
                pix[0]  = av_clip_uint8( q0 - i_delta );    /* q0' */
272
                tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1);
273
            }
274
        }else{
275
            const int p0 = pix[-1];
276
            const int p1 = pix[-2];
277
            const int q0 = pix[0];
278
            const int q1 = pix[1];
279

    
280
            if( FFABS( p0 - q0 ) < alpha &&
281
                FFABS( p1 - p0 ) < beta &&
282
                FFABS( q1 - q0 ) < beta ) {
283

    
284
                pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2;   /* p0' */
285
                pix[0]  = ( 2*q1 + q0 + p1 + 2 ) >> 2;   /* q0' */
286
                tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, pix[-3], p1, p0, q0, q1, pix[2], pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]);
287
            }
288
        }
289
    }
290
}
291

    
292
static void av_noinline filter_mb_edgeh( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) {
293
    const int index_a = qp + h->slice_alpha_c0_offset;
294
    const int alpha = (alpha_table+52)[index_a];
295
    const int beta  = (beta_table+52)[qp + h->slice_beta_offset];
296
    if (alpha ==0 || beta == 0) return;
297

    
298
    if( bS[0] < 4 ) {
299
        int8_t tc[4];
300
        tc[0] = (tc0_table+52)[index_a][bS[0]];
301
        tc[1] = (tc0_table+52)[index_a][bS[1]];
302
        tc[2] = (tc0_table+52)[index_a][bS[2]];
303
        tc[3] = (tc0_table+52)[index_a][bS[3]];
304
        h->s.dsp.h264_v_loop_filter_luma(pix, stride, alpha, beta, tc);
305
    } else {
306
        h->s.dsp.h264_v_loop_filter_luma_intra(pix, stride, alpha, beta);
307
    }
308
}
309

    
310
static void av_noinline filter_mb_edgech( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) {
311
    const int index_a = qp + h->slice_alpha_c0_offset;
312
    const int alpha = (alpha_table+52)[index_a];
313
    const int beta  = (beta_table+52)[qp + h->slice_beta_offset];
314
    if (alpha ==0 || beta == 0) return;
315

    
316
    if( bS[0] < 4 ) {
317
        int8_t tc[4];
318
        tc[0] = (tc0_table+52)[index_a][bS[0]]+1;
319
        tc[1] = (tc0_table+52)[index_a][bS[1]]+1;
320
        tc[2] = (tc0_table+52)[index_a][bS[2]]+1;
321
        tc[3] = (tc0_table+52)[index_a][bS[3]]+1;
322
        h->s.dsp.h264_v_loop_filter_chroma(pix, stride, alpha, beta, tc);
323
    } else {
324
        h->s.dsp.h264_v_loop_filter_chroma_intra(pix, stride, alpha, beta);
325
    }
326
}
327

    
328
void ff_h264_filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) {
329
    MpegEncContext * const s = &h->s;
330
    int mb_y_firstrow = s->picture_structure == PICT_BOTTOM_FIELD;
331
    int mb_xy, mb_type;
332
    int qp, qp0, qp1, qpc, qpc0, qpc1, qp_thresh;
333

    
334
    mb_xy = h->mb_xy;
335

    
336
    if(mb_x==0 || mb_y==mb_y_firstrow || !s->dsp.h264_loop_filter_strength || h->pps.chroma_qp_diff ||
337
        !(s->flags2 & CODEC_FLAG2_FAST) || //FIXME filter_mb_fast is broken, thus hasto be, but should not under CODEC_FLAG2_FAST
338
       (h->deblocking_filter == 2 && (h->slice_table[mb_xy] != h->slice_table[h->top_mb_xy] ||
339
                                      h->slice_table[mb_xy] != h->slice_table[mb_xy - 1]))) {
340
        ff_h264_filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize);
341
        return;
342
    }
343
    assert(!FRAME_MBAFF);
344

    
345
    mb_type = s->current_picture.mb_type[mb_xy];
346
    qp = s->current_picture.qscale_table[mb_xy];
347
    qp0 = s->current_picture.qscale_table[mb_xy-1];
348
    qp1 = s->current_picture.qscale_table[h->top_mb_xy];
349
    qpc = get_chroma_qp( h, 0, qp );
350
    qpc0 = get_chroma_qp( h, 0, qp0 );
351
    qpc1 = get_chroma_qp( h, 0, qp1 );
352
    qp0 = (qp + qp0 + 1) >> 1;
353
    qp1 = (qp + qp1 + 1) >> 1;
354
    qpc0 = (qpc + qpc0 + 1) >> 1;
355
    qpc1 = (qpc + qpc1 + 1) >> 1;
356
    qp_thresh = 15 - h->slice_alpha_c0_offset;
357
    if(qp <= qp_thresh && qp0 <= qp_thresh && qp1 <= qp_thresh &&
358
       qpc <= qp_thresh && qpc0 <= qp_thresh && qpc1 <= qp_thresh)
359
        return;
360

    
361
    if( IS_INTRA(mb_type) ) {
362
        int16_t bS4[4] = {4,4,4,4};
363
        int16_t bS3[4] = {3,3,3,3};
364
        int16_t *bSH = FIELD_PICTURE ? bS3 : bS4;
365
        if( IS_8x8DCT(mb_type) ) {
366
            filter_mb_edgev( h, &img_y[4*0], linesize, bS4, qp0 );
367
            filter_mb_edgev( h, &img_y[4*2], linesize, bS3, qp );
368
            filter_mb_edgeh( h, &img_y[4*0*linesize], linesize, bSH, qp1 );
369
            filter_mb_edgeh( h, &img_y[4*2*linesize], linesize, bS3, qp );
370
        } else {
371
            filter_mb_edgev( h, &img_y[4*0], linesize, bS4, qp0 );
372
            filter_mb_edgev( h, &img_y[4*1], linesize, bS3, qp );
373
            filter_mb_edgev( h, &img_y[4*2], linesize, bS3, qp );
374
            filter_mb_edgev( h, &img_y[4*3], linesize, bS3, qp );
375
            filter_mb_edgeh( h, &img_y[4*0*linesize], linesize, bSH, qp1 );
376
            filter_mb_edgeh( h, &img_y[4*1*linesize], linesize, bS3, qp );
377
            filter_mb_edgeh( h, &img_y[4*2*linesize], linesize, bS3, qp );
378
            filter_mb_edgeh( h, &img_y[4*3*linesize], linesize, bS3, qp );
379
        }
380
        filter_mb_edgecv( h, &img_cb[2*0], uvlinesize, bS4, qpc0 );
381
        filter_mb_edgecv( h, &img_cb[2*2], uvlinesize, bS3, qpc );
382
        filter_mb_edgecv( h, &img_cr[2*0], uvlinesize, bS4, qpc0 );
383
        filter_mb_edgecv( h, &img_cr[2*2], uvlinesize, bS3, qpc );
384
        filter_mb_edgech( h, &img_cb[2*0*uvlinesize], uvlinesize, bSH, qpc1 );
385
        filter_mb_edgech( h, &img_cb[2*2*uvlinesize], uvlinesize, bS3, qpc );
386
        filter_mb_edgech( h, &img_cr[2*0*uvlinesize], uvlinesize, bSH, qpc1 );
387
        filter_mb_edgech( h, &img_cr[2*2*uvlinesize], uvlinesize, bS3, qpc );
388
        return;
389
    } else {
390
        DECLARE_ALIGNED_8(int16_t, bS[2][4][4]);
391
        uint64_t (*bSv)[4] = (uint64_t(*)[4])bS;
392
        int edges;
393
        if( IS_8x8DCT(mb_type) && (h->cbp&7) == 7 ) {
394
            edges = 4;
395
            bSv[0][0] = bSv[0][2] = bSv[1][0] = bSv[1][2] = 0x0002000200020002ULL;
396
        } else {
397
            int mask_edge1 = (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) ? 3 :
398
                             (mb_type & MB_TYPE_16x8) ? 1 : 0;
399
            int mask_edge0 = (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16))
400
                             && (s->current_picture.mb_type[mb_xy-1] & (MB_TYPE_16x16 | MB_TYPE_8x16))
401
                             ? 3 : 0;
402
            int step = IS_8x8DCT(mb_type) ? 2 : 1;
403
            edges = (mb_type & MB_TYPE_16x16) && !(h->cbp & 15) ? 1 : 4;
404
            s->dsp.h264_loop_filter_strength( bS, h->non_zero_count_cache, h->ref_cache, h->mv_cache,
405
                                              (h->slice_type_nos == FF_B_TYPE), edges, step, mask_edge0, mask_edge1, FIELD_PICTURE);
406
        }
407
        if( IS_INTRA(s->current_picture.mb_type[mb_xy-1]) )
408
            bSv[0][0] = 0x0004000400040004ULL;
409
        if( IS_INTRA(s->current_picture.mb_type[h->top_mb_xy]) )
410
            bSv[1][0] = FIELD_PICTURE ? 0x0003000300030003ULL : 0x0004000400040004ULL;
411

    
412
#define FILTER(hv,dir,edge)\
413
        if(bSv[dir][edge]) {\
414
            filter_mb_edge##hv( h, &img_y[4*edge*(dir?linesize:1)], linesize, bS[dir][edge], edge ? qp : qp##dir );\
415
            if(!(edge&1)) {\
416
                filter_mb_edgec##hv( h, &img_cb[2*edge*(dir?uvlinesize:1)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir );\
417
                filter_mb_edgec##hv( h, &img_cr[2*edge*(dir?uvlinesize:1)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir );\
418
            }\
419
        }
420
        if( edges == 1 ) {
421
            FILTER(v,0,0);
422
            FILTER(h,1,0);
423
        } else if( IS_8x8DCT(mb_type) ) {
424
            FILTER(v,0,0);
425
            FILTER(v,0,2);
426
            FILTER(h,1,0);
427
            FILTER(h,1,2);
428
        } else {
429
            FILTER(v,0,0);
430
            FILTER(v,0,1);
431
            FILTER(v,0,2);
432
            FILTER(v,0,3);
433
            FILTER(h,1,0);
434
            FILTER(h,1,1);
435
            FILTER(h,1,2);
436
            FILTER(h,1,3);
437
        }
438
#undef FILTER
439
    }
440
}
441

    
442

    
443
static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize, int mb_xy, int mb_type, int mvy_limit, int first_vertical_edge_done, int dir) {
444
    MpegEncContext * const s = &h->s;
445
    int edge;
446
    const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy;
447
    const int mbm_type = s->current_picture.mb_type[mbm_xy];
448
    int start = h->slice_table[mbm_xy] == 0xFFFF ? 1 : 0;
449

    
450
    const int edges = (mb_type & (MB_TYPE_16x16|MB_TYPE_SKIP))
451
                              == (MB_TYPE_16x16|MB_TYPE_SKIP) ? 1 : 4;
452
    // how often to recheck mv-based bS when iterating between edges
453
    const int mask_edge = (mb_type & (MB_TYPE_16x16 | (MB_TYPE_16x8 << dir))) ? 3 :
454
                          (mb_type & (MB_TYPE_8x16 >> dir)) ? 1 : 0;
455
    // how often to recheck mv-based bS when iterating along each edge
456
    const int mask_par0 = mb_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir));
457

    
458
    if (first_vertical_edge_done) {
459
        start = 1;
460
    }
461

    
462
    if (h->deblocking_filter==2 && h->slice_table[mbm_xy] != h->slice_table[mb_xy])
463
        start = 1;
464

    
465
    if (FRAME_MBAFF && (dir == 1) && ((mb_y&1) == 0) && start == 0
466
        && !IS_INTERLACED(mb_type)
467
        && IS_INTERLACED(mbm_type)
468
        ) {
469
        // This is a special case in the norm where the filtering must
470
        // be done twice (one each of the field) even if we are in a
471
        // frame macroblock.
472
        //
473
        unsigned int tmp_linesize   = 2 *   linesize;
474
        unsigned int tmp_uvlinesize = 2 * uvlinesize;
475
        int mbn_xy = mb_xy - 2 * s->mb_stride;
476
        int qp;
477
        int i, j;
478
        int16_t bS[4];
479

    
480
        for(j=0; j<2; j++, mbn_xy += s->mb_stride){
481
            if( IS_INTRA(mb_type) ||
482
                IS_INTRA(s->current_picture.mb_type[mbn_xy]) ) {
483
                bS[0] = bS[1] = bS[2] = bS[3] = 3;
484
            } else {
485
                const uint8_t *mbn_nnz = h->non_zero_count[mbn_xy];
486
                for( i = 0; i < 4; i++ ) {
487
                    if( h->non_zero_count_cache[scan8[0]+i] != 0 ||
488
                        mbn_nnz[i+4+3*8] != 0 )
489
                        bS[i] = 2;
490
                    else
491
                        bS[i] = 1;
492
                }
493
            }
494
            // Do not use s->qscale as luma quantizer because it has not the same
495
            // value in IPCM macroblocks.
496
            qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1;
497
            tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize);
498
            { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
499
            filter_mb_edgeh( h, &img_y[j*linesize], tmp_linesize, bS, qp );
500
            filter_mb_edgech( h, &img_cb[j*uvlinesize], tmp_uvlinesize, bS,
501
                              ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1);
502
            filter_mb_edgech( h, &img_cr[j*uvlinesize], tmp_uvlinesize, bS,
503
                              ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1);
504
        }
505

    
506
        start = 1;
507
    }
508

    
509
    /* Calculate bS */
510
    for( edge = start; edge < edges; edge++ ) {
511
        /* mbn_xy: neighbor macroblock */
512
        const int mbn_xy = edge > 0 ? mb_xy : mbm_xy;
513
        const int mbn_type = s->current_picture.mb_type[mbn_xy];
514
        int16_t bS[4];
515
        int qp;
516

    
517
        if( (edge&1) && IS_8x8DCT(mb_type) )
518
            continue;
519

    
520
        if( IS_INTRA(mb_type) ||
521
            IS_INTRA(mbn_type) ) {
522
            int value;
523
            if (edge == 0) {
524
                if (   (!IS_INTERLACED(mb_type) && !IS_INTERLACED(mbm_type))
525
                    || ((FRAME_MBAFF || (s->picture_structure != PICT_FRAME)) && (dir == 0))
526
                ) {
527
                    value = 4;
528
                } else {
529
                    value = 3;
530
                }
531
            } else {
532
                value = 3;
533
            }
534
            bS[0] = bS[1] = bS[2] = bS[3] = value;
535
        } else {
536
            int i, l;
537
            int mv_done;
538

    
539
            if( edge & mask_edge ) {
540
                bS[0] = bS[1] = bS[2] = bS[3] = 0;
541
                mv_done = 1;
542
            }
543
            else if( FRAME_MBAFF && IS_INTERLACED(mb_type ^ mbn_type)) {
544
                bS[0] = bS[1] = bS[2] = bS[3] = 1;
545
                mv_done = 1;
546
            }
547
            else if( mask_par0 && (edge || (mbn_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)))) ) {
548
                int b_idx= 8 + 4 + edge * (dir ? 8:1);
549
                int bn_idx= b_idx - (dir ? 8:1);
550
                int v = 0;
551

    
552
                for( l = 0; !v && l < 1 + (h->slice_type_nos == FF_B_TYPE); l++ ) {
553
                    v |= h->ref_cache[l][b_idx] != h->ref_cache[l][bn_idx] |
554
                         h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] + 3 >= 7U |
555
                         FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit;
556
                }
557

    
558
                if(h->slice_type_nos == FF_B_TYPE && v){
559
                    v=0;
560
                    for( l = 0; !v && l < 2; l++ ) {
561
                        int ln= 1-l;
562
                        v |= h->ref_cache[l][b_idx] != h->ref_cache[ln][bn_idx] |
563
                            h->mv_cache[l][b_idx][0] - h->mv_cache[ln][bn_idx][0] + 3 >= 7U |
564
                            FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[ln][bn_idx][1] ) >= mvy_limit;
565
                    }
566
                }
567

    
568
                bS[0] = bS[1] = bS[2] = bS[3] = v;
569
                mv_done = 1;
570
            }
571
            else
572
                mv_done = 0;
573

    
574
            for( i = 0; i < 4; i++ ) {
575
                int x = dir == 0 ? edge : i;
576
                int y = dir == 0 ? i    : edge;
577
                int b_idx= 8 + 4 + x + 8*y;
578
                int bn_idx= b_idx - (dir ? 8:1);
579

    
580
                if( h->non_zero_count_cache[b_idx] |
581
                    h->non_zero_count_cache[bn_idx] ) {
582
                    bS[i] = 2;
583
                }
584
                else if(!mv_done)
585
                {
586
                    bS[i] = 0;
587
                    for( l = 0; l < 1 + (h->slice_type_nos == FF_B_TYPE); l++ ) {
588
                        if( h->ref_cache[l][b_idx] != h->ref_cache[l][bn_idx] |
589
                            h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] + 3 >= 7U |
590
                            FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit ) {
591
                            bS[i] = 1;
592
                            break;
593
                        }
594
                    }
595

    
596
                    if(h->slice_type_nos == FF_B_TYPE && bS[i]){
597
                        bS[i] = 0;
598
                        for( l = 0; l < 2; l++ ) {
599
                            int ln= 1-l;
600
                            if( h->ref_cache[l][b_idx] != h->ref_cache[ln][bn_idx] |
601
                                h->mv_cache[l][b_idx][0] - h->mv_cache[ln][bn_idx][0] + 3 >= 7U |
602
                                FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[ln][bn_idx][1] ) >= mvy_limit ) {
603
                                bS[i] = 1;
604
                                break;
605
                            }
606
                        }
607
                    }
608
                }
609
            }
610

    
611
            if(bS[0]+bS[1]+bS[2]+bS[3] == 0)
612
                continue;
613
        }
614

    
615
        /* Filter edge */
616
        // Do not use s->qscale as luma quantizer because it has not the same
617
        // value in IPCM macroblocks.
618
        qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1;
619
        //tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], s->current_picture.qscale_table[mbn_xy]);
620
        tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
621
        //{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
622
        if( dir == 0 ) {
623
            filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp );
624
            if( (edge&1) == 0 ) {
625
                filter_mb_edgecv( h, &img_cb[2*edge], uvlinesize, bS,
626
                                  ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1);
627
                filter_mb_edgecv( h, &img_cr[2*edge], uvlinesize, bS,
628
                                  ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1);
629
            }
630
        } else {
631
            filter_mb_edgeh( h, &img_y[4*edge*linesize], linesize, bS, qp );
632
            if( (edge&1) == 0 ) {
633
                filter_mb_edgech( h, &img_cb[2*edge*uvlinesize], uvlinesize, bS,
634
                                  ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1);
635
                filter_mb_edgech( h, &img_cr[2*edge*uvlinesize], uvlinesize, bS,
636
                                  ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1);
637
            }
638
        }
639
    }
640
}
641

    
642
void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) {
643
    MpegEncContext * const s = &h->s;
644
    const int mb_xy= mb_x + mb_y*s->mb_stride;
645
    const int mb_type = s->current_picture.mb_type[mb_xy];
646
    const int mvy_limit = IS_INTERLACED(mb_type) ? 2 : 4;
647
    int first_vertical_edge_done = 0;
648
    av_unused int dir;
649
    int list;
650

    
651
    // CAVLC 8x8dct requires NNZ values for residual decoding that differ from what the loop filter needs
652
    if(!h->pps.cabac && h->pps.transform_8x8_mode){
653
        int top_type, left_type[2];
654
        top_type     = s->current_picture.mb_type[h->top_mb_xy]    ;
655
        left_type[0] = s->current_picture.mb_type[h->left_mb_xy[0]];
656
        left_type[1] = s->current_picture.mb_type[h->left_mb_xy[1]];
657

    
658
        if(IS_8x8DCT(top_type)){
659
            h->non_zero_count_cache[4+8*0]=
660
            h->non_zero_count_cache[5+8*0]= h->cbp_table[h->top_mb_xy] & 4;
661
            h->non_zero_count_cache[6+8*0]=
662
            h->non_zero_count_cache[7+8*0]= h->cbp_table[h->top_mb_xy] & 8;
663
        }
664
        if(IS_8x8DCT(left_type[0])){
665
            h->non_zero_count_cache[3+8*1]=
666
            h->non_zero_count_cache[3+8*2]= h->cbp_table[h->left_mb_xy[0]]&2; //FIXME check MBAFF
667
        }
668
        if(IS_8x8DCT(left_type[1])){
669
            h->non_zero_count_cache[3+8*3]=
670
            h->non_zero_count_cache[3+8*4]= h->cbp_table[h->left_mb_xy[1]]&8; //FIXME check MBAFF
671
        }
672

    
673
        if(IS_8x8DCT(mb_type)){
674
            h->non_zero_count_cache[scan8[0   ]]= h->non_zero_count_cache[scan8[1   ]]=
675
            h->non_zero_count_cache[scan8[2   ]]= h->non_zero_count_cache[scan8[3   ]]= h->cbp_table[mb_xy] & 1;
676

    
677
            h->non_zero_count_cache[scan8[0+ 4]]= h->non_zero_count_cache[scan8[1+ 4]]=
678
            h->non_zero_count_cache[scan8[2+ 4]]= h->non_zero_count_cache[scan8[3+ 4]]= h->cbp_table[mb_xy] & 2;
679

    
680
            h->non_zero_count_cache[scan8[0+ 8]]= h->non_zero_count_cache[scan8[1+ 8]]=
681
            h->non_zero_count_cache[scan8[2+ 8]]= h->non_zero_count_cache[scan8[3+ 8]]= h->cbp_table[mb_xy] & 4;
682

    
683
            h->non_zero_count_cache[scan8[0+12]]= h->non_zero_count_cache[scan8[1+12]]=
684
            h->non_zero_count_cache[scan8[2+12]]= h->non_zero_count_cache[scan8[3+12]]= h->cbp_table[mb_xy] & 8;
685
        }
686
    }
687

    
688
    if (FRAME_MBAFF
689
            // left mb is in picture
690
            && h->slice_table[mb_xy-1] != 0xFFFF
691
            // and current and left pair do not have the same interlaced type
692
            && (IS_INTERLACED(mb_type) != IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]))
693
            // and left mb is in the same slice if deblocking_filter == 2
694
            && (h->deblocking_filter!=2 || h->slice_table[mb_xy-1] == h->slice_table[mb_xy])) {
695
        /* First vertical edge is different in MBAFF frames
696
         * There are 8 different bS to compute and 2 different Qp
697
         */
698
        const int pair_xy = mb_x + (mb_y&~1)*s->mb_stride;
699
        const int left_mb_xy[2] = { pair_xy-1, pair_xy-1+s->mb_stride };
700
        int16_t bS[8];
701
        int qp[2];
702
        int bqp[2];
703
        int rqp[2];
704
        int mb_qp, mbn0_qp, mbn1_qp;
705
        int i;
706
        first_vertical_edge_done = 1;
707

    
708
        if( IS_INTRA(mb_type) )
709
            bS[0] = bS[1] = bS[2] = bS[3] = bS[4] = bS[5] = bS[6] = bS[7] = 4;
710
        else {
711
            for( i = 0; i < 8; i++ ) {
712
                int mbn_xy = MB_FIELD ? left_mb_xy[i>>2] : left_mb_xy[i&1];
713

    
714
                if( IS_INTRA( s->current_picture.mb_type[mbn_xy] ) )
715
                    bS[i] = 4;
716
                else if( h->non_zero_count_cache[12+8*(i>>1)] != 0 ||
717
                         ((!h->pps.cabac && IS_8x8DCT(s->current_picture.mb_type[mbn_xy])) ?
718
                            (h->cbp_table[mbn_xy] & ((MB_FIELD ? (i&2) : (mb_y&1)) ? 8 : 2))
719
                                                                       :
720
                            h->non_zero_count[mbn_xy][7+(MB_FIELD ? (i&3) : (i>>2)+(mb_y&1)*2)*8]))
721
                    bS[i] = 2;
722
                else
723
                    bS[i] = 1;
724
            }
725
        }
726

    
727
        mb_qp = s->current_picture.qscale_table[mb_xy];
728
        mbn0_qp = s->current_picture.qscale_table[left_mb_xy[0]];
729
        mbn1_qp = s->current_picture.qscale_table[left_mb_xy[1]];
730
        qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1;
731
        bqp[0] = ( get_chroma_qp( h, 0, mb_qp ) +
732
                   get_chroma_qp( h, 0, mbn0_qp ) + 1 ) >> 1;
733
        rqp[0] = ( get_chroma_qp( h, 1, mb_qp ) +
734
                   get_chroma_qp( h, 1, mbn0_qp ) + 1 ) >> 1;
735
        qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1;
736
        bqp[1] = ( get_chroma_qp( h, 0, mb_qp ) +
737
                   get_chroma_qp( h, 0, mbn1_qp ) + 1 ) >> 1;
738
        rqp[1] = ( get_chroma_qp( h, 1, mb_qp ) +
739
                   get_chroma_qp( h, 1, mbn1_qp ) + 1 ) >> 1;
740

    
741
        /* Filter edge */
742
        tprintf(s->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize);
743
        { int i; for (i = 0; i < 8; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
744
        filter_mb_mbaff_edgev ( h, &img_y [0], linesize,   bS, qp );
745
        filter_mb_mbaff_edgecv( h, &img_cb[0], uvlinesize, bS, bqp );
746
        filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, rqp );
747
    }
748

    
749
#if CONFIG_SMALL
750
    for( dir = 0; dir < 2; dir++ )
751
        filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, dir ? 0 : first_vertical_edge_done, dir);
752
#else
753
    filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, first_vertical_edge_done, 0);
754
    filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0, 1);
755
#endif
756
}