History

avfilter/vf_v360: add mitchell interpolation

Paul B Mahol committed 6 years ago

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

Showing the changes to libavfilter (3 of 4 files). Show all

Unified · Split

3 files
  1. libavfilter/v360.h +1 −0
  2. libavfilter/vf_v360.c +74 −0
  3. libavfilter/x86/vf_v360_init.c +2 −1
libavfilter/v360.h+1−0
@@ -65,6 +65,7 @@ enum InterpMethod { · 64 unmodified lines
65 LANCZOS,65 LANCZOS,
66 SPLINE16,66 SPLINE16,
67 GAUSSIAN,67 GAUSSIAN,
68 MITCHELL,
68 NB_INTERP_METHODS,69 NB_INTERP_METHODS,
69};70};
70 71
libavfilter/vf_v360.c+74−0
@@ -128,6 +128,7 @@ static const AVOption v360_options[] = { · 127 unmodified lines
128 { "spline16", "spline16 interpolation", 0, AV_OPT_TYPE_CONST, {.i64=SPLINE16}, 0, 0, FLAGS, "interp" },128 { "spline16", "spline16 interpolation", 0, AV_OPT_TYPE_CONST, {.i64=SPLINE16}, 0, 0, FLAGS, "interp" },
129 { "gauss", "gaussian interpolation", 0, AV_OPT_TYPE_CONST, {.i64=GAUSSIAN}, 0, 0, FLAGS, "interp" },129 { "gauss", "gaussian interpolation", 0, AV_OPT_TYPE_CONST, {.i64=GAUSSIAN}, 0, 0, FLAGS, "interp" },
130 { "gaussian", "gaussian interpolation", 0, AV_OPT_TYPE_CONST, {.i64=GAUSSIAN}, 0, 0, FLAGS, "interp" },130 { "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" },
131 { "w", "output width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, INT16_MAX, FLAGS, "w"},132 { "w", "output width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, INT16_MAX, FLAGS, "w"},
132 { "h", "output height", OFFSET(height), AV_OPT_TYPE_INT, {.i64=0}, 0, INT16_MAX, FLAGS, "h"},133 { "h", "output height", OFFSET(height), AV_OPT_TYPE_INT, {.i64=0}, 0, INT16_MAX, FLAGS, "h"},
133 { "in_stereo", "input stereo format", OFFSET(in_stereo), AV_OPT_TYPE_INT, {.i64=STEREO_2D}, 0, NB_STEREO_FMTS-1, FLAGS, "stereo" },134 { "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
381 case LANCZOS:382 case LANCZOS:
382 case SPLINE16:383 case SPLINE16:
383 case GAUSSIAN:384 case GAUSSIAN:
385 case MITCHELL:
384 s->remap_line = depth <= 8 ? remap4_8bit_line_c : remap4_16bit_line_c;386 s->remap_line = depth <= 8 ? remap4_8bit_line_c : remap4_16bit_line_c;
385 break;387 break;
386 }388 }
@@ -669,6 +671,71 @@ static void gaussian_kernel(float du, float dv, const XYRemap *rmap, · 282 unmodified lines
669 }671 }
670}672}
671 673
674/**
675 * Calculate 1-dimensional cubic_bc_spline coefficients.
676 *
677 * @param t relative coordinate
678 * @param coeffs coefficients
679 */
680static 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 */
721static 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
672/**739/**
673 * Modulo operation with only positive remainders.740 * Modulo operation with only positive remainders.
674 *741 *
@@ -4138,6 +4205,13 @@ static int config_output(AVFilterLink *outlink) · 3463 unmodified lines
4138 sizeof_uv = sizeof(int16_t) * s->elements;4205 sizeof_uv = sizeof(int16_t) * s->elements;
4139 sizeof_ker = sizeof(int16_t) * s->elements;4206 sizeof_ker = sizeof(int16_t) * s->elements;
4140 break;4207 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;
4141 default:4215 default:
4142 av_assert0(0);4216 av_assert0(0);
4143 }4217 }
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
64 if (EXTERNAL_AVX2_FAST(cpu_flags) && (s->interp == BICUBIC ||64 if (EXTERNAL_AVX2_FAST(cpu_flags) && (s->interp == BICUBIC ||
65 s->interp == LANCZOS ||65 s->interp == LANCZOS ||
66 s->interp == SPLINE16 ||66 s->interp == SPLINE16 ||
67 s->interp == GAUSSIAN) && depth <= 8)67 s->interp == GAUSSIAN ||
68 s->interp == MITCHELL) && depth <= 8)
68 s->remap_line = ff_remap4_8bit_line_avx2;69 s->remap_line = ff_remap4_8bit_line_avx2;
69#endif70#endif
70}71}

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