History

avfilter/vf_v360: add mitchell interpolation

Paul B Mahol committed 6 years ago

Commit eaba6ce1 parent acd735e4 files · +79 −1Browse files

Unified · Split

4 files
  1. doc/filters.texi +2 −0
  2. libavfilter/v360.h +1 −0
  3. libavfilter/vf_v360.c +74 −0
  4. libavfilter/x86/vf_v360_init.c +2 −1
doc/filters.texi+2−0
@@ -19543,6 +19543,8 @@ Spline16 interpolation. · 19542 unmodified lines
1954319543 @item gauss
1954419544 @item gaussian
1954519545 Gaussian interpolation.
19546+@item mitchell
19547+Mitchell interpolation.
1954619548 @end table
1954719549
1954819550 Default value is @b{@samp{line}}.
libavfilter/v360.h+1−0
@@ -65,6 +65,7 @@ enum InterpMethod { · 64 unmodified lines
6565 LANCZOS,
6666 SPLINE16,
6767 GAUSSIAN,
68+ MITCHELL,
6869 NB_INTERP_METHODS,
6970 };
7071
libavfilter/vf_v360.c+74−0
@@ -128,6 +128,7 @@ static const AVOption v360_options[] = { · 127 unmodified lines
128128 { "spline16", "spline16 interpolation", 0, AV_OPT_TYPE_CONST, {.i64=SPLINE16}, 0, 0, FLAGS, "interp" },
129129 { "gauss", "gaussian interpolation", 0, AV_OPT_TYPE_CONST, {.i64=GAUSSIAN}, 0, 0, FLAGS, "interp" },
130130 { "gaussian", "gaussian interpolation", 0, AV_OPT_TYPE_CONST, {.i64=GAUSSIAN}, 0, 0, FLAGS, "interp" },
131+ { "mitchell", "mitchell interpolation", 0, AV_OPT_TYPE_CONST, {.i64=MITCHELL}, 0, 0, FLAGS, "interp" },
131132 { "w", "output width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, INT16_MAX, FLAGS, "w"},
132133 { "h", "output height", OFFSET(height), AV_OPT_TYPE_INT, {.i64=0}, 0, INT16_MAX, FLAGS, "h"},
133134 { "in_stereo", "input stereo format", OFFSET(in_stereo), AV_OPT_TYPE_INT, {.i64=STEREO_2D}, 0, NB_STEREO_FMTS-1, FLAGS, "stereo" },
@@ -381,6 +382,7 @@ void ff_v360_init(V360Context *s, int depth) · 247 unmodified lines
381382 case LANCZOS:
382383 case SPLINE16:
383384 case GAUSSIAN:
385+ case MITCHELL:
384386 s->remap_line = depth <= 8 ? remap4_8bit_line_c : remap4_16bit_line_c;
385387 break;
386388 }
@@ -669,6 +671,71 @@ static void gaussian_kernel(float du, float dv, const XYRemap *rmap, · 282 unmodified lines
669671 }
670672 }
671673
674+/**
675+ * Calculate 1-dimensional cubic_bc_spline coefficients.
676+ *
677+ * @param t relative coordinate
678+ * @param coeffs coefficients
679+ */
680+static void calculate_cubic_bc_coeffs(float t, float *coeffs,
681+ float b, float c)
682+{
683+ float sum = 0.f;
684+ float p0 = (6.f - 2.f * b) / 6.f,
685+ p2 = (-18.f + 12.f * b + 6.f * c) / 6.f,
686+ p3 = (12.f - 9.f * b - 6.f * c) / 6.f,
687+ q0 = (8.f * b + 24.f * c) / 6.f,
688+ q1 = (-12.f * b - 48.f * c) / 6.f,
689+ q2 = (6.f * b + 30.f * c) / 6.f,
690+ q3 = (-b - 6.f * c) / 6.f;
691+
692+ for (int i = 0; i < 4; i++) {
693+ const float x = fabsf(t - i + 1.f);
694+ if (x < 1.f) {
695+ coeffs[i] = (p0 + x * x * (p2 + x * p3)) *
696+ (p0 + x * x * (p2 + x * p3 / 2.f) / 4.f);
697+ } else if (x < 2.f) {
698+ coeffs[i] = (q0 + x * (q1 + x * (q2 + x * q3))) *
699+ (q0 + x * (q1 + x * (q2 + x / 2.f * q3) / 2.f) / 2.f);
700+ } else {
701+ coeffs[i] = 0.f;
702+ }
703+ sum += coeffs[i];
704+ }
705+
706+ for (int i = 0; i < 4; i++) {
707+ coeffs[i] /= sum;
708+ }
709+}
710+
711+/**
712+ * Calculate kernel for mitchell interpolation.
713+ *
714+ * @param du horizontal relative coordinate
715+ * @param dv vertical relative coordinate
716+ * @param rmap calculated 4x4 window
717+ * @param u u remap data
718+ * @param v v remap data
719+ * @param ker ker remap data
720+ */
721+static void mitchell_kernel(float du, float dv, const XYRemap *rmap,
722+ int16_t *u, int16_t *v, int16_t *ker)
723+{
724+ float du_coeffs[4];
725+ float dv_coeffs[4];
726+
727+ calculate_cubic_bc_coeffs(du, du_coeffs, 1.f / 3.f, 1.f / 3.f);
728+ calculate_cubic_bc_coeffs(dv, dv_coeffs, 1.f / 3.f, 1.f / 3.f);
729+
730+ for (int i = 0; i < 4; i++) {
731+ for (int j = 0; j < 4; j++) {
732+ u[i * 4 + j] = rmap->u[i][j];
733+ v[i * 4 + j] = rmap->v[i][j];
734+ ker[i * 4 + j] = lrintf(du_coeffs[j] * dv_coeffs[i] * 16385.f);
735+ }
736+ }
737+}
738+
672739 /**
673740 * Modulo operation with only positive remainders.
674741 *
@@ -4138,6 +4205,13 @@ static int config_output(AVFilterLink *outlink) · 3463 unmodified lines
41384205 sizeof_uv = sizeof(int16_t) * s->elements;
41394206 sizeof_ker = sizeof(int16_t) * s->elements;
41404207 break;
4208+ case MITCHELL:
4209+ s->calculate_kernel = mitchell_kernel;
4210+ s->remap_slice = depth <= 8 ? remap4_8bit_slice : remap4_16bit_slice;
4211+ s->elements = 4 * 4;
4212+ sizeof_uv = sizeof(int16_t) * s->elements;
4213+ sizeof_ker = sizeof(int16_t) * s->elements;
4214+ break;
41414215 default:
41424216 av_assert0(0);
41434217 }
libavfilter/x86/vf_v360_init.c+2−1
@@ -64,7 +64,8 @@ av_cold void ff_v360_init_x86(V360Context *s, int depth) · 63 unmodified lines
6464 if (EXTERNAL_AVX2_FAST(cpu_flags) && (s->interp == BICUBIC ||
6565 s->interp == LANCZOS ||
6666 s->interp == SPLINE16 ||
67− s->interp == GAUSSIAN) && depth <= 8)
67+ s->interp == GAUSSIAN ||
68+ s->interp == MITCHELL) && depth <= 8)
6869 s->remap_line = ff_remap4_8bit_line_avx2;
6970 #endif
7071 }

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