| @@ -128,6 +128,7 @@ static const AVOption v360_options[] = { · 127 unmodified lines |
| 128 | 128 | { "spline16", "spline16 interpolation", 0, AV_OPT_TYPE_CONST, {.i64=SPLINE16}, 0, 0, FLAGS, "interp" }, |
| 129 | 129 | { "gauss", "gaussian interpolation", 0, AV_OPT_TYPE_CONST, {.i64=GAUSSIAN}, 0, 0, FLAGS, "interp" }, |
| 130 | 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 | 132 | { "w", "output width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, INT16_MAX, FLAGS, "w"}, |
| 132 | 133 | { "h", "output height", OFFSET(height), AV_OPT_TYPE_INT, {.i64=0}, 0, INT16_MAX, FLAGS, "h"}, |
| 133 | 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 | 382 | case LANCZOS: |
| 382 | 383 | case SPLINE16: |
| 383 | 384 | case GAUSSIAN: |
| 385 | + case MITCHELL: |
| 384 | 386 | s->remap_line = depth <= 8 ? remap4_8bit_line_c : remap4_16bit_line_c; |
| 385 | 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 | + */ |
| 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 | + |
| 672 | 739 | /** |
| 673 | 740 | * Modulo operation with only positive remainders. |
| 674 | 741 | * |
| @@ -4138,6 +4205,13 @@ static int config_output(AVFilterLink *outlink) · 3463 unmodified lines |
| 4138 | 4205 | sizeof_uv = sizeof(int16_t) * s->elements; |
| 4139 | 4206 | sizeof_ker = sizeof(int16_t) * s->elements; |
| 4140 | 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 | 4215 | default: |
| 4142 | 4216 | av_assert0(0); |
| 4143 | 4217 | } |