diff options
author | Paul B Mahol <onemda@gmail.com> | 2020-01-21 20:42:46 +0300 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2020-01-21 22:12:54 +0300 |
commit | 103a29b89d6e0cd0fdc5d7a715cbf3212fe33684 (patch) | |
tree | 9bf83f59551fdd8b370244182820812a89126b8e /libavfilter | |
parent | 39b60359dbf7936eb1ef6a05b76ea7d821d115f5 (diff) |
avfilter/vf_v360: add support for fisheye input format
Diffstat (limited to 'libavfilter')
-rw-r--r-- | libavfilter/vf_v360.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c index 2570dc36af..c4a5926db7 100644 --- a/libavfilter/vf_v360.c +++ b/libavfilter/vf_v360.c @@ -72,6 +72,7 @@ static const AVOption v360_options[] = { { "ball", "ball", 0, AV_OPT_TYPE_CONST, {.i64=BALL}, 0, 0, FLAGS, "in" }, { "hammer", "hammer", 0, AV_OPT_TYPE_CONST, {.i64=HAMMER}, 0, 0, FLAGS, "in" }, {"sinusoidal", "sinusoidal", 0, AV_OPT_TYPE_CONST, {.i64=SINUSOIDAL}, 0, 0, FLAGS, "in" }, + { "fisheye", "fisheye", 0, AV_OPT_TYPE_CONST, {.i64=FISHEYE}, 0, 0, FLAGS, "in" }, {"cylindrical", "cylindrical", 0, AV_OPT_TYPE_CONST, {.i64=CYLINDRICAL}, 0, 0, FLAGS, "in" }, { "output", "set output projection", OFFSET(out), AV_OPT_TYPE_INT, {.i64=CUBEMAP_3_2}, 0, NB_PROJECTIONS-1, FLAGS, "out" }, { "e", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" }, @@ -2346,6 +2347,64 @@ static void fisheye_to_xyz(const V360Context *s, } /** + * Prepare data for processing fisheye input format. + * + * @param ctx filter context + * + * @return error code + */ +static int prepare_fisheye_in(AVFilterContext *ctx) +{ + V360Context *s = ctx->priv; + + s->iflat_range[0] = s->ih_fov / 180.f; + s->iflat_range[1] = s->iv_fov / 180.f; + + return 0; +} + +/** + * Calculate frame position in fisheye format for corresponding 3D coordinates on sphere. + * + * @param s filter private context + * @param vec coordinates on sphere + * @param width frame width + * @param height frame height + * @param us horizontal coordinates for interpolation window + * @param vs vertical coordinates for interpolation window + * @param du horizontal relative coordinate + * @param dv vertical relative coordinate + */ +static void xyz_to_fisheye(const V360Context *s, + const float *vec, int width, int height, + int16_t us[4][4], int16_t vs[4][4], float *du, float *dv) +{ + const float h = hypotf(vec[0], vec[1]); + const float lh = h > 0.f ? h : 1.f; + const float theta = acosf(fabsf(vec[2])) / M_PI; + + const float uf = (theta * ( vec[0] / lh) * s->input_mirror_modifier[0] / s->iflat_range[0] + 0.5f) * width; + const float vf = (theta * (-vec[1] / lh) * s->input_mirror_modifier[1] / s->iflat_range[1] + 0.5f) * height; + + int visible, ui, vi; + + ui = floorf(uf); + vi = floorf(vf); + + visible = vec[2] < 0.f; + + *du = uf - ui; + *dv = vf - vi; + + for (int i = -1; i < 3; i++) { + for (int j = -1; j < 3; j++) { + us[i + 1][j + 1] = visible ? av_clip(ui + j, 0, width - 1) : 0; + vs[i + 1][j + 1] = visible ? av_clip(vi + i, 0, height - 1) : 0; + } + } +} + +/** * Calculate 3D coordinates on sphere for corresponding frame position in pannini format. * * @param s filter private context @@ -3090,7 +3149,6 @@ static int config_output(AVFilterLink *outlink) break; case PERSPECTIVE: case PANNINI: - case FISHEYE: av_log(ctx, AV_LOG_ERROR, "Supplied format is not accepted as input.\n"); return AVERROR(EINVAL); case DUAL_FISHEYE: @@ -3135,6 +3193,12 @@ static int config_output(AVFilterLink *outlink) wf = w; hf = h; break; + case FISHEYE: + s->in_transform = xyz_to_fisheye; + err = prepare_fisheye_in(ctx); + wf = w * 2; + hf = h; + break; case CYLINDRICAL: s->in_transform = xyz_to_cylindrical; err = prepare_cylindrical_in(ctx); |