Revision de0f445b libavfilter/vf_yadif.c

View differences:

libavfilter/vf_yadif.c
56 56
    const AVPixFmtDescriptor *csp;
57 57
} YADIFContext;
58 58

  
59
static void filter_line_c(uint8_t *dst,
60
                          uint8_t *prev, uint8_t *cur, uint8_t *next,
61
                          int w, int prefs, int mrefs, int parity, int mode)
62
{
63
    int x;
64
    uint8_t *prev2 = parity ? prev : cur ;
65
    uint8_t *next2 = parity ? cur  : next;
66
    for (x = 0;  x < w; x++) {
67
        int c = cur[mrefs];
68
        int d = (prev2[0] + next2[0])>>1;
69
        int e = cur[prefs];
70
        int temporal_diff0 = FFABS(prev2[0] - next2[0]);
71
        int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) )>>1;
72
        int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1;
73
        int diff = FFMAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2);
74
        int spatial_pred = (c+e)>>1;
75
        int spatial_score = FFABS(cur[mrefs-1] - cur[prefs-1]) + FFABS(c-e)
76
                          + FFABS(cur[mrefs+1] - cur[prefs+1]) - 1;
77

  
78 59
#define CHECK(j)\
79 60
    {   int score = FFABS(cur[mrefs-1+(j)] - cur[prefs-1-(j)])\
80 61
                  + FFABS(cur[mrefs  +(j)] - cur[prefs  -(j)])\
......
83 64
            spatial_score= score;\
84 65
            spatial_pred= (cur[mrefs  +(j)] + cur[prefs  -(j)])>>1;\
85 66

  
86
        CHECK(-1) CHECK(-2) }} }}
87
        CHECK( 1) CHECK( 2) }} }}
88

  
89
        if (mode < 2) {
90
            int b = (prev2[2*mrefs] + next2[2*mrefs])>>1;
91
            int f = (prev2[2*prefs] + next2[2*prefs])>>1;
92
#if 0
93
            int a = cur[-3*refs];
94
            int g = cur[+3*refs];
95
            int max = FFMAX3(d-e, d-c, FFMIN3(FFMAX(b-c,f-e),FFMAX(b-c,b-a),FFMAX(f-g,f-e)) );
96
            int min = FFMIN3(d-e, d-c, FFMAX3(FFMIN(b-c,f-e),FFMIN(b-c,b-a),FFMIN(f-g,f-e)) );
97
#else
98
            int max = FFMAX3(d-e, d-c, FFMIN(b-c, f-e));
99
            int min = FFMIN3(d-e, d-c, FFMAX(b-c, f-e));
100
#endif
101

  
102
            diff = FFMAX3(diff, min, -max);
103
        }
104

  
105
        if (spatial_pred > d + diff)
106
           spatial_pred = d + diff;
107
        else if (spatial_pred < d - diff)
108
           spatial_pred = d - diff;
67
#define FILTER \
68
    for (x = 0;  x < w; x++) { \
69
        int c = cur[mrefs]; \
70
        int d = (prev2[0] + next2[0])>>1; \
71
        int e = cur[prefs]; \
72
        int temporal_diff0 = FFABS(prev2[0] - next2[0]); \
73
        int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) )>>1; \
74
        int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1; \
75
        int diff = FFMAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2); \
76
        int spatial_pred = (c+e)>>1; \
77
        int spatial_score = FFABS(cur[mrefs-1] - cur[prefs-1]) + FFABS(c-e) \
78
                          + FFABS(cur[mrefs+1] - cur[prefs+1]) - 1; \
79
 \
80
        CHECK(-1) CHECK(-2) }} }} \
81
        CHECK( 1) CHECK( 2) }} }} \
82
 \
83
        if (mode < 2) { \
84
            int b = (prev2[2*mrefs] + next2[2*mrefs])>>1; \
85
            int f = (prev2[2*prefs] + next2[2*prefs])>>1; \
86
            int max = FFMAX3(d-e, d-c, FFMIN(b-c, f-e)); \
87
            int min = FFMIN3(d-e, d-c, FFMAX(b-c, f-e)); \
88
 \
89
            diff = FFMAX3(diff, min, -max); \
90
        } \
91
 \
92
        if (spatial_pred > d + diff) \
93
           spatial_pred = d + diff; \
94
        else if (spatial_pred < d - diff) \
95
           spatial_pred = d - diff; \
96
 \
97
        dst[0] = spatial_pred; \
98
 \
99
        dst++; \
100
        cur++; \
101
        prev++; \
102
        next++; \
103
        prev2++; \
104
        next2++; \
105
    }
109 106

  
110
        dst[0] = spatial_pred;
107
static void filter_line_c(uint8_t *dst,
108
                          uint8_t *prev, uint8_t *cur, uint8_t *next,
109
                          int w, int prefs, int mrefs, int parity, int mode)
110
{
111
    int x;
112
    uint8_t *prev2 = parity ? prev : cur ;
113
    uint8_t *next2 = parity ? cur  : next;
111 114

  
112
        dst++;
113
        cur++;
114
        prev++;
115
        next++;
116
        prev2++;
117
        next2++;
118
    }
115
    FILTER
119 116
}
120 117

  
121 118
static void filter_line_c_16bit(uint16_t *dst,
......
127 124
    uint16_t *next2 = parity ? cur  : next;
128 125
    mrefs /= 2;
129 126
    prefs /= 2;
130
    for (x = 0;  x < w; x++) {
131
        int c = cur[mrefs];
132
        int d = (prev2[0] + next2[0])>>1;
133
        int e = cur[prefs];
134
        int temporal_diff0 = FFABS(prev2[0] - next2[0]);
135
        int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) )>>1;
136
        int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1;
137
        int diff = FFMAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2);
138
        int spatial_pred = (c+e)>>1;
139
        int spatial_score = FFABS(cur[mrefs-1] - cur[prefs-1]) + FFABS(c-e)
140
                          + FFABS(cur[mrefs+1] - cur[prefs+1]) - 1;
141 127

  
142
#define CHECK(j)\
143
    {   int score = FFABS(cur[mrefs-1+j] - cur[prefs-1-j])\
144
                  + FFABS(cur[mrefs  +j] - cur[prefs  -j])\
145
                  + FFABS(cur[mrefs+1+j] - cur[prefs+1-j]);\
146
        if (score < spatial_score) {\
147
            spatial_score= score;\
148
            spatial_pred= (cur[mrefs  +j] + cur[prefs  -j])>>1;\
149

  
150
        CHECK(-1) CHECK(-2) }} }}
151
        CHECK( 1) CHECK( 2) }} }}
152

  
153
        if (mode < 2) {
154
            int b = (prev2[2*mrefs] + next2[2*mrefs])>>1;
155
            int f = (prev2[2*prefs] + next2[2*prefs])>>1;
156
#if 0
157
            int a = cur[-3*refs];
158
            int g = cur[+3*refs];
159
            int max = FFMAX3(d-e, d-c, FFMIN3(FFMAX(b-c,f-e),FFMAX(b-c,b-a),FFMAX(f-g,f-e)) );
160
            int min = FFMIN3(d-e, d-c, FFMAX3(FFMIN(b-c,f-e),FFMIN(b-c,b-a),FFMIN(f-g,f-e)) );
161
#else
162
            int max = FFMAX3(d-e, d-c, FFMIN(b-c, f-e));
163
            int min = FFMIN3(d-e, d-c, FFMAX(b-c, f-e));
164
#endif
165

  
166
            diff = FFMAX3(diff, min, -max);
167
        }
168

  
169
        if (spatial_pred > d + diff)
170
           spatial_pred = d + diff;
171
        else if (spatial_pred < d - diff)
172
           spatial_pred = d - diff;
173

  
174
        dst[0] = spatial_pred;
175

  
176
        dst++;
177
        cur++;
178
        prev++;
179
        next++;
180
        prev2++;
181
        next2++;
182
    }
128
    FILTER
183 129
}
184 130

  
185 131
static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic,

Also available in: Unified diff