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
3535 int deint; ///< which frames to deinterlace
3636 int rslope; ///< best edge slope search radius
3737 int redge; ///< best edge match search radius
38+ int interp; ///< type of interpolation
3839 int linesize[4]; ///< bytes of pixel data per line for each plane
3940 int planewidth[4]; ///< width of each plane
4041 int planeheight[4]; ///< height of each plane
@@ -47,11 +48,28 @@ typedef struct ESTDIFContext { · 6 unmodified lines
4748 int64_t pts;
4849 AVFrame *prev;
4950
50− void (*interpolate)(uint8_t *dst,
51− const uint8_t *prev_line, const uint8_t *next_line,
51+ void (*interpolate)(struct ESTDIFContext *s, uint8_t *dst,
52+ const uint8_t *prev_line, const uint8_t *next_line,
5253 const uint8_t *prev2_line, const uint8_t *next2_line,
54+ const uint8_t *prev3_line, const uint8_t *next3_line,
5355 int x, int width, int rslope, int redge, unsigned half,
5456 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);
5573 } ESTDIFContext;
5674
5775 #define MAX_R 15
@@ -74,6 +92,10 @@ static const AVOption estdif_options[] = { · 16 unmodified lines
7492 CONST("interlaced", "only deinterlace frames marked as interlaced", 1, "deint"),
7593 { "rslope", "specify the search radius for edge slope tracing", OFFSET(rslope), AV_OPT_TYPE_INT, {.i64=1}, 1, MAX_R, FLAGS, },
7694 { "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"),
7799 { NULL }
78100 };
79101
@@ -142,11 +164,29 @@ static unsigned midl_##ss(const type *const prev, \ · 62 unmodified lines
142164 MIDL(uint8_t, 8)
143165 MIDL(uint16_t, 16)
144166
167+#define MID2(type, ss) \
168+static 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+
180+MID2(uint8_t, 8)
181+MID2(uint16_t, 16)
182+
145183 #define MID4(type, ss) \
146184 static unsigned mid4_##ss(const type *const prev, \
147185 const type *const next, \
148186 const type *const prev2, \
149187 const type *const next2, \
188+ const type *const prev3, \
189+ const type *const next3, \
150190 int end, int x, int k, int depth) \
151191 { \
152192 return av_clip_uintp2_c(( \
@@ -160,6 +200,28 @@ static unsigned mid4_##ss(const type *const prev, \ · 7 unmodified lines
160200 MID4(uint8_t, 8)
161201 MID4(uint16_t, 16)
162202
203+#define MID6(type, ss) \
204+static 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+
222+MID6(uint8_t, 8)
223+MID6(uint16_t, 16)
224+
163225 #define DIFF(type, ss) \
164226 static unsigned diff_##ss(const type *const prev, \
165227 const type *const next, \
@@ -188,11 +250,13 @@ COST(uint8_t, 8) · 22 unmodified lines
188250 COST(uint16_t, 16)
189251
190252 #define INTERPOLATE(type, atype, max, ss) \
191−static void interpolate_##ss(uint8_t *ddst, \
253+static void interpolate_##ss(ESTDIFContext *s, uint8_t *ddst, \
192254 const uint8_t *const pprev_line, \
193255 const uint8_t *const nnext_line, \
194256 const uint8_t *const pprev2_line, \
195257 const uint8_t *const nnext2_line, \
258+ const uint8_t *const pprev3_line, \
259+ const uint8_t *const nnext3_line, \
196260 int x, int width, int rslope, \
197261 int redge, unsigned h, int depth, \
198262 int *K) \
@@ -200,8 +264,11 @@ static void interpolate_##ss(uint8_t *ddst, \ · 1 unmodified line
200264 type *dst = (type *)ddst; \
201265 const type *const prev_line = (const type *const)pprev_line; \
202266 const type *const prev2_line = (const type *const)pprev2_line; \
267+ const type *const prev3_line = (const type *const)pprev3_line; \
203268 const type *const next_line = (const type *const)nnext_line; \
204269 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; \
205272 const int end = width - 1; \
206273 const atype f = redge + 2; \
207274 atype sd[S], sD[S], di = 0; \
@@ -255,8 +322,10 @@ static void interpolate_##ss(uint8_t *ddst, \ · 47 unmodified lines
255322 } \
256323 } \
257324 \
258− dst[x] = mid4_##ss(prev_line, next_line, prev2_line, next2_line, \
259− end, x, k, depth); \
325+ dst[x] = s->mid_##ss[interp](prev_line, next_line, \
326+ prev2_line, next2_line, \
327+ prev3_line, next3_line, \
328+ end, x, k, depth); \
260329 \
261330 *K = k; \
262331 }
@@ -290,6 +359,7 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, · 27 unmodified lines
290359 const int start = (height * jobnr) / nb_jobs;
291360 const int end = (height * (jobnr+1)) / nb_jobs;
292361 const uint8_t *prev_line, *prev2_line, *next_line, *next2_line, *in_line;
362+ const uint8_t *prev3_line, *next3_line;
293363 uint8_t *out_line;
294364 int y_out;
295365
@@ -309,12 +379,20 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, · 13 unmodified lines
309379 out_line = dst_data + (y_out * dst_linesize);
310380
311381 for (int y = y_out; y < end; y += 2) {
382+ int y_prev3_in = y - 5;
383+ int y_next3_in = y + 5;
312384 int y_prev2_in = y - 3;
313385 int y_next2_in = y + 3;
314386 int y_prev_in = y - 1;
315387 int y_next_in = y + 1;
316388 int k;
317389
390+ while (y_prev3_in < 0)
391+ y_prev3_in += 2;
392+
393+ while (y_next3_in >= height)
394+ y_next3_in -= 2;
395+
318396 while (y_prev2_in < 0)
319397 y_prev2_in += 2;
320398
@@ -327,6 +405,9 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, · 6 unmodified lines
327405 while (y_next_in >= height)
328406 y_next_in -= 2;
329407
408+ prev3_line = src_data + (y_prev3_in * src_linesize);
409+ next3_line = src_data + (y_next3_in * src_linesize);
410+
330411 prev2_line = src_data + (y_prev2_in * src_linesize);
331412 next2_line = src_data + (y_next2_in * src_linesize);
332413
@@ -336,9 +417,10 @@ static int deinterlace_slice(AVFilterContext *ctx, void *arg, · 3 unmodified lines
336417 k = 0;
337418
338419 for (int x = 0; x < width; x++) {
339− s->interpolate(out_line,
420+ s->interpolate(s, out_line,
340421 prev_line, next_line,
341422 prev2_line, next2_line,
423+ prev3_line, next3_line,
342424 x, width, rslope, redge, half, depth, &k);
343425 }
344426
@@ -397,6 +479,12 @@ static int config_input(AVFilterLink *inlink) · 52 unmodified lines
397479 s->nb_threads = ff_filter_get_nb_threads(ctx);
398480 s->depth = desc->comp[0].depth;
399481 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;
400488 s->half = 1 << (s->depth - 1);
401489
402490 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