History

avfilter/vf_estdif: make interpolation used user configurable

Paul B Mahol committed 5 years ago

Commit bb66fd71 parent 95183d22 files · +107 −6Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/vf_estdif.c+94−6
@@ -35,6 +35,7 @@ typedef struct ESTDIFContext { · 34 unmodified lines
35 int deint; ///< which frames to deinterlace35 int deint; ///< which frames to deinterlace
36 int rslope; ///< best edge slope search radius36 int rslope; ///< best edge slope search radius
37 int redge; ///< best edge match search radius37 int redge; ///< best edge match search radius
38 int interp; ///< type of interpolation
38 int linesize[4]; ///< bytes of pixel data per line for each plane39 int linesize[4]; ///< bytes of pixel data per line for each plane
39 int planewidth[4]; ///< width of each plane40 int planewidth[4]; ///< width of each plane
40 int planeheight[4]; ///< height of each plane41 int planeheight[4]; ///< height of each plane
@@ -47,11 +48,28 @@ typedef struct ESTDIFContext { · 6 unmodified lines
47 int64_t pts;48 int64_t pts;
48 AVFrame *prev;49 AVFrame *prev;
49 50
50 void (*interpolate)(uint8_t *dst,51 void (*interpolate)(struct ESTDIFContext *s, uint8_t *dst,
51 const uint8_t *prev_line, const uint8_t *next_line,52 const uint8_t *prev_line, const uint8_t *next_line,
52 const uint8_t *prev2_line, const uint8_t *next2_line,53 const uint8_t *prev2_line, const uint8_t *next2_line,
54 const uint8_t *prev3_line, const uint8_t *next3_line,
53 int x, int width, int rslope, int redge, unsigned half,55 int x, int width, int rslope, int redge, unsigned half,
54 int depth, int *K);56 int depth, int *K);
57
58 unsigned (*mid_8[3])(const uint8_t *const prev,
59 const uint8_t *const next,
60 const uint8_t *const prev2,
61 const uint8_t *const next2,
62 const uint8_t *const prev3,
63 const uint8_t *const next3,
64 int end, int x, int k, int depth);
65
66 unsigned (*mid_16[3])(const uint16_t *const prev,
67 const uint16_t *const next,
68 const uint16_t *const prev2,
69 const uint16_t *const next2,
70 const uint16_t *const prev3,
71 const uint16_t *const next3,
72 int end, int x, int k, int depth);
55} ESTDIFContext;73} ESTDIFContext;
56 74
57#define MAX_R 1575#define MAX_R 15
@@ -74,6 +92,10 @@ static const AVOption estdif_options[] = { · 16 unmodified lines
74 CONST("interlaced", "only deinterlace frames marked as interlaced", 1, "deint"),92 CONST("interlaced", "only deinterlace frames marked as interlaced", 1, "deint"),
75 { "rslope", "specify the search radius for edge slope tracing", OFFSET(rslope), AV_OPT_TYPE_INT, {.i64=1}, 1, MAX_R, FLAGS, },93 { "rslope", "specify the search radius for edge slope tracing", OFFSET(rslope), AV_OPT_TYPE_INT, {.i64=1}, 1, MAX_R, FLAGS, },
76 { "redge", "specify the search radius for best edge matching", OFFSET(redge), AV_OPT_TYPE_INT, {.i64=2}, 0, MAX_R, FLAGS, },94 { "redge", "specify the search radius for best edge matching", OFFSET(redge), AV_OPT_TYPE_INT, {.i64=2}, 0, MAX_R, FLAGS, },
95 { "interp", "specify the type of interpolation", OFFSET(interp), AV_OPT_TYPE_INT, {.i64=1}, 0, 2, FLAGS, "interp" },
96 CONST("2p", "two-point interpolation", 0, "interp"),
97 CONST("4p", "four-point interpolation", 1, "interp"),
98 CONST("6p", "six-point interpolation", 2, "interp"),
77 { NULL }99 { NULL }
78};100};
79 101
@@ -142,11 +164,29 @@ static unsigned midl_##ss(const type *const prev, \ · 62 unmodified lines
142MIDL(uint8_t, 8)164MIDL(uint8_t, 8)
143MIDL(uint16_t, 16)165MIDL(uint16_t, 16)
144 166
167#define MID2(type, ss) \
168static unsigned mid2_##ss(const type *const prev, \
169 const type *const next, \
170 const type *const prev2, \
171 const type *const next2, \
172 const type *const prev3, \
173 const type *const next3, \
174 int end, int x, int k, int depth) \
175{ \
176 return (prev[av_clip(x + k, 0, end)] + \
177 next[av_clip(x - k, 0, end)] + 1) >> 1; \
178}
179
180MID2(uint8_t, 8)
181MID2(uint16_t, 16)
182
145#define MID4(type, ss) \183#define MID4(type, ss) \
146static unsigned mid4_##ss(const type *const prev, \184static unsigned mid4_##ss(const type *const prev, \
147 const type *const next, \185 const type *const next, \
148 const type *const prev2, \186 const type *const prev2, \
149 const type *const next2, \187 const type *const next2, \
188 const type *const prev3, \
189 const type *const next3, \
150 int end, int x, int k, int depth) \190 int end, int x, int k, int depth) \
151{ \191{ \
152 return av_clip_uintp2_c(( \192 return av_clip_uintp2_c(( \
@@ -160,6 +200,28 @@ static unsigned mid4_##ss(const type *const prev, \ · 7 unmodified lines
160MID4(uint8_t, 8)200MID4(uint8_t, 8)
161MID4(uint16_t, 16)201MID4(uint16_t, 16)
162 202
203#define MID6(type, ss) \
204static unsigned mid6_##ss(const type *const prev, \
205 const type *const next, \
206 const type *const prev2, \
207 const type *const next2, \
208 const type *const prev3, \
209 const type *const next3, \
210 int end, int x, int k, int depth) \
211{ \
212 return av_clip_uintp2_c(( \
213 20 * (prev[av_clip(x + k, 0, end)] + \
214 next[av_clip(x - k, 0, end)]) - \
215 5 * (prev2[av_clip(x + k*3, 0, end)] + \
216 next2[av_clip(x - k*3, 0, end)]) + \
217 1 * (prev3[av_clip(x + k*5, 0, end)] + \
218 next3[av_clip(x - k*5, 0, end)]) + 16) >> 5, \
219 depth); \
220}
221
222MID6(uint8_t, 8)
223MID6(uint16_t, 16)
224
163#define DIFF(type, ss) \225#define DIFF(type, ss) \
164static unsigned diff_##ss(const type *const prev, \226static unsigned diff_##ss(const type *const prev, \
165 const type *const next, \227 const type *const next, \
@@ -188,11 +250,13 @@ COST(uint8_t, 8) · 22 unmodified lines
188COST(uint16_t, 16)250COST(uint16_t, 16)
189 251
190#define INTERPOLATE(type, atype, max, ss) \252#define INTERPOLATE(type, atype, max, ss) \
191static void interpolate_##ss(uint8_t *ddst, \253static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \
192 const uint8_t *const pprev_line, \254 const uint8_t *const pprev_line, \
193 const uint8_t *const nnext_line, \255 const uint8_t *const nnext_line, \
194 const uint8_t *const pprev2_line, \256 const uint8_t *const pprev2_line, \
195 const uint8_t *const nnext2_line, \257 const uint8_t *const nnext2_line, \
258 const uint8_t *const pprev3_line, \
259 const uint8_t *const nnext3_line, \
196 int x, int width, int rslope, \260 int x, int width, int rslope, \
197 int redge, unsigned h, int depth, \261 int redge, unsigned h, int depth, \
198 int *K) \262 int *K) \
@@ -200,8 +264,11 @@ static void interpolate_##ss(uint8_t *ddst, \ · 1 unmodified line
200 type *dst = (type *)ddst; \264 type *dst = (type *)ddst; \
201 const type *const prev_line = (const type *const)pprev_line; \265 const type *const prev_line = (const type *const)pprev_line; \
202 const type *const prev2_line = (const type *const)pprev2_line; \266 const type *const prev2_line = (const type *const)pprev2_line; \
267 const type *const prev3_line = (const type *const)pprev3_line; \
203 const type *const next_line = (const type *const)nnext_line; \268 const type *const next_line = (const type *const)nnext_line; \
204 const type *const next2_line = (const type *const)nnext2_line; \269 const type *const next2_line = (const type *const)nnext2_line; \
270 const type *const next3_line = (const type *const)nnext3_line; \
271 const int interp = s->interp; \
205 const int end = width - 1; \272 const int end = width - 1; \
206 const atype f = redge + 2; \273 const atype f = redge + 2; \
207 atype sd[S], sD[S], di = 0; \274 atype sd[S], sD[S], di = 0; \
@@ -255,8 +322,10 @@ static void interpolate_##ss(uint8_t *ddst, \ · 47 unmodified lines
255 } \322 } \
256 } \323 } \
257 \324 \
258 dst[x] = mid4_##ss(prev_line, next_line, prev2_line, next2_line, \325 dst[x] = s->mid_##ss[interp](prev_line, next_line, \
259 end, x, k, depth); \326 prev2_line, next2_line, \
327 prev3_line, next3_line, \
328 end, x, k, depth); \
260 \329 \
261 *K = k; \330 *K = k; \
262}331}
@@ -290,6 +359,7 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, · 27 unmodified lines
290 const int start = (height * jobnr) / nb_jobs;359 const int start = (height * jobnr) / nb_jobs;
291 const int end = (height * (jobnr+1)) / nb_jobs;360 const int end = (height * (jobnr+1)) / nb_jobs;
292 const uint8_t *prev_line, *prev2_line, *next_line, *next2_line, *in_line;361 const uint8_t *prev_line, *prev2_line, *next_line, *next2_line, *in_line;
362 const uint8_t *prev3_line, *next3_line;
293 uint8_t *out_line;363 uint8_t *out_line;
294 int y_out;364 int y_out;
295 365
@@ -309,12 +379,20 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, · 13 unmodified lines
309 out_line = dst_data + (y_out * dst_linesize);379 out_line = dst_data + (y_out * dst_linesize);
310 380
311 for (int y = y_out; y < end; y += 2) {381 for (int y = y_out; y < end; y += 2) {
382 int y_prev3_in = y - 5;
383 int y_next3_in = y + 5;
312 int y_prev2_in = y - 3;384 int y_prev2_in = y - 3;
313 int y_next2_in = y + 3;385 int y_next2_in = y + 3;
314 int y_prev_in = y - 1;386 int y_prev_in = y - 1;
315 int y_next_in = y + 1;387 int y_next_in = y + 1;
316 int k;388 int k;
317 389
390 while (y_prev3_in < 0)
391 y_prev3_in += 2;
392
393 while (y_next3_in >= height)
394 y_next3_in -= 2;
395
318 while (y_prev2_in < 0)396 while (y_prev2_in < 0)
319 y_prev2_in += 2;397 y_prev2_in += 2;
320 398
@@ -327,6 +405,9 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, · 6 unmodified lines
327 while (y_next_in >= height)405 while (y_next_in >= height)
328 y_next_in -= 2;406 y_next_in -= 2;
329 407
408 prev3_line = src_data + (y_prev3_in * src_linesize);
409 next3_line = src_data + (y_next3_in * src_linesize);
410
330 prev2_line = src_data + (y_prev2_in * src_linesize);411 prev2_line = src_data + (y_prev2_in * src_linesize);
331 next2_line = src_data + (y_next2_in * src_linesize);412 next2_line = src_data + (y_next2_in * src_linesize);
332 413
@@ -336,9 +417,10 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, · 3 unmodified lines
336 k = 0;417 k = 0;
337 418
338 for (int x = 0; x < width; x++) {419 for (int x = 0; x < width; x++) {
339 s->interpolate(out_line,420 s->interpolate(s, out_line,
340 prev_line, next_line,421 prev_line, next_line,
341 prev2_line, next2_line,422 prev2_line, next2_line,
423 prev3_line, next3_line,
342 x, width, rslope, redge, half, depth, &k);424 x, width, rslope, redge, half, depth, &k);
343 }425 }
344 426
@@ -397,6 +479,12 @@ static int config_input(AVFilterLink *inlink) · 52 unmodified lines
397 s->nb_threads = ff_filter_get_nb_threads(ctx);479 s->nb_threads = ff_filter_get_nb_threads(ctx);
398 s->depth = desc->comp[0].depth;480 s->depth = desc->comp[0].depth;
399 s->interpolate = s->depth <= 8 ? interpolate_8 : interpolate_16;481 s->interpolate = s->depth <= 8 ? interpolate_8 : interpolate_16;
482 s->mid_8[0] = mid2_8;
483 s->mid_8[1] = mid4_8;
484 s->mid_8[2] = mid6_8;
485 s->mid_16[0] = mid2_16;
486 s->mid_16[1] = mid4_16;
487 s->mid_16[2] = mid6_16;
400 s->half = 1 << (s->depth - 1);488 s->half = 1 << (s->depth - 1);
401 489
402 return 0;490 return 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t