34 #define PERM_RWP AV_PERM_WRITE | AV_PERM_PRESERVE | AV_PERM_REUSE
37 { int score = FFABS(cur[mrefs + off_left + (j)] - cur[prefs + off_left - (j)])\
38 + FFABS(cur[mrefs +(j)] - cur[prefs -(j)])\
39 + FFABS(cur[mrefs + off_right + (j)] - cur[prefs + off_right - (j)]);\
40 if (score < spatial_score) {\
41 spatial_score= score;\
42 spatial_pred= (cur[mrefs +(j)] + cur[prefs -(j)])>>1;\
44 #define FILTER(start, end) \
45 for (x = start; x < end; x++) { \
47 int d = (prev2[0] + next2[0])>>1; \
49 int temporal_diff0 = FFABS(prev2[0] - next2[0]); \
50 int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) )>>1; \
51 int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1; \
52 int diff = FFMAX3(temporal_diff0 >> 1, temporal_diff1, temporal_diff2); \
53 int spatial_pred = (c+e) >> 1; \
54 int off_right = (x < w - 1) ? 1 : -1;\
55 int off_left = x ? -1 : 1;\
56 int spatial_score = FFABS(cur[mrefs + off_left] - cur[prefs + off_left]) + FFABS(c-e) \
57 + FFABS(cur[mrefs + off_right] - cur[prefs + off_right]) - 1; \
59 if (x > 2 && x < w - 3) {\
60 CHECK(-1) CHECK(-2) }} }} \
61 CHECK( 1) CHECK( 2) }} }} \
65 int b = (prev2[2 * mrefs] + next2[2 * mrefs])>>1; \
66 int f = (prev2[2 * prefs] + next2[2 * prefs])>>1; \
67 int max = FFMAX3(d - e, d - c, FFMIN(b - c, f - e)); \
68 int min = FFMIN3(d - e, d - c, FFMAX(b - c, f - e)); \
70 diff = FFMAX3(diff, min, -max); \
73 if (spatial_pred > d + diff) \
74 spatial_pred = d + diff; \
75 else if (spatial_pred < d - diff) \
76 spatial_pred = d - diff; \
78 dst[0] = spatial_pred; \
89 void *prev1,
void *cur1,
void *next1,
90 int w,
int prefs,
int mrefs,
int parity,
int mode)
97 uint8_t *prev2 = parity ? prev : cur ;
98 uint8_t *next2 = parity ? cur : next;
103 static void filter_edges(
void *dst1,
void *prev1,
void *cur1,
void *next1,
104 int w,
int prefs,
int mrefs,
int parity,
int mode,
112 uint8_t *prev2 = parity ? prev : cur ;
113 uint8_t *next2 = parity ? cur : next;
118 prev = (
uint8_t*)prev1 + w - 3;
120 next = (
uint8_t*)next1 + w - 3;
121 prev2 = (
uint8_t*)(parity ? prev : cur);
122 next2 = (
uint8_t*)(parity ? cur : next);
129 void *prev1,
void *cur1,
void *next1,
130 int w,
int prefs,
int mrefs,
int parity,
133 uint16_t *
dst = dst1;
134 uint16_t *prev = prev1;
135 uint16_t *cur = cur1;
136 uint16_t *next = next1;
138 uint16_t *prev2 = parity ? prev : cur ;
139 uint16_t *next2 = parity ? cur : next;
147 int w,
int prefs,
int mrefs,
int parity,
int mode,
150 uint16_t *
dst = dst1;
151 uint16_t *prev = prev1;
152 uint16_t *cur = cur1;
153 uint16_t *next = next1;
155 uint16_t *prev2 = parity ? prev : cur ;
156 uint16_t *next2 = parity ? cur : next;
160 dst = (uint16_t*)dst1 + w - 3;
161 prev = (uint16_t*)prev1 + w - 3;
162 cur = (uint16_t*)cur1 + w - 3;
163 next = (uint16_t*)next1 + w - 3;
164 prev2 = (uint16_t*)(parity ? prev : cur);
165 next2 = (uint16_t*)(parity ? cur : next);
181 int l_edge, l_edge_pix;
183 if (i == 1 || i == 2) {
193 l_edge_pix = l_edge / df;
195 for (y = 0; y < h; y++) {
196 if ((y ^ parity) & 1) {
201 int mode = y == 1 || y + 2 == h ? 2 : yadif->
mode;
203 yadif->
filter_line(dst + l_edge, prev + l_edge, cur + l_edge,
204 next + l_edge, w - l_edge_pix - 3,
205 y + 1 < h ? refs : -refs,
209 y + 1 < h ? refs : -refs,
211 parity ^ tff, mode, l_edge_pix);
213 yadif->
filter_line(dst, prev, cur, next + l_edge, w,
214 y + 1 < h ? refs : -refs,
220 &yadif->
cur->
data[i][y * refs], w * df);
234 if (yadif->
parity == -1) {
250 filter(ctx, yadif->
out, tff ^ !is_second, tff);
253 int64_t cur_pts = yadif->
cur->
pts;
254 int64_t next_pts = yadif->
next->
pts;
257 yadif->
out->
pts = cur_pts + next_pts;
282 yadif->
next = picref;
344 }
else if (ret < 0) {
347 }
while (!yadif->
cur);
352 #define OFFSET(x) offsetof(YADIFContext, x)
353 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
355 #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, INT_MIN, INT_MAX, FLAGS, unit }
432 static const char *shorthand[] = {
"mode",
"parity",
"deint",
NULL };
435 yadif->
class = &yadif_class;
460 if (link->w < 3 || link->h < 3) {
461 av_log(ctx,
AV_LOG_ERROR,
"Video of less than 3 columns or lines is not supported\n");
466 if (s->csp->comp[0].depth_minus1 / 8 == 1) {
509 .
inputs = avfilter_vf_yadif_inputs,
510 .
outputs = avfilter_vf_yadif_outputs,
512 .priv_class = &yadif_class,