| @@ -72,6 +72,7 @@ static const AVOption v360_options[] = { · 71 unmodified lines |
| 72 | { "ball", "ball", 0, AV_OPT_TYPE_CONST, {.i64=BALL}, 0, 0, FLAGS, "in" }, | 72 | { "ball", "ball", 0, AV_OPT_TYPE_CONST, {.i64=BALL}, 0, 0, FLAGS, "in" }, |
| 73 | { "hammer", "hammer", 0, AV_OPT_TYPE_CONST, {.i64=HAMMER}, 0, 0, FLAGS, "in" }, | 73 | { "hammer", "hammer", 0, AV_OPT_TYPE_CONST, {.i64=HAMMER}, 0, 0, FLAGS, "in" }, |
| 74 | {"sinusoidal", "sinusoidal", 0, AV_OPT_TYPE_CONST, {.i64=SINUSOIDAL}, 0, 0, FLAGS, "in" }, | 74 | {"sinusoidal", "sinusoidal", 0, AV_OPT_TYPE_CONST, {.i64=SINUSOIDAL}, 0, 0, FLAGS, "in" }, |
| | 75 | {"cylindrical", "cylindrical", 0, AV_OPT_TYPE_CONST, {.i64=CYLINDRICAL}, 0, 0, FLAGS, "in" }, |
| 75 | { "output", "set output projection", OFFSET(out), AV_OPT_TYPE_INT, {.i64=CUBEMAP_3_2}, 0, NB_PROJECTIONS-1, FLAGS, "out" }, | 76 | { "output", "set output projection", OFFSET(out), AV_OPT_TYPE_INT, {.i64=CUBEMAP_3_2}, 0, NB_PROJECTIONS-1, FLAGS, "out" }, |
| 76 | { "e", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" }, | 77 | { "e", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" }, |
| 77 | { "equirect", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" }, | 78 | { "equirect", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" }, |
| @@ -2406,6 +2407,64 @@ static void cylindrical_to_xyz(const V360Context *s, · 2328 unmodified lines |
| 2406 | normalize_vector(vec); | 2407 | normalize_vector(vec); |
| 2407 | } | 2408 | } |
| 2408 | | 2409 | |
| | 2410 | /** |
| | 2411 | * Prepare data for processing cylindrical input format. |
| | 2412 | * |
| | 2413 | * @param ctx filter context |
| | 2414 | * |
| | 2415 | * @return error code |
| | 2416 | */ |
| | 2417 | static int prepare_cylindrical_in(AVFilterContext *ctx) |
| | 2418 | { |
| | 2419 | V360Context *s = ctx->priv; |
| | 2420 | |
| | 2421 | s->iflat_range[0] = M_PI * s->ih_fov / 360.f; |
| | 2422 | s->iflat_range[1] = tanf(0.5f * s->iv_fov * M_PI / 180.f); |
| | 2423 | |
| | 2424 | return 0; |
| | 2425 | } |
| | 2426 | |
| | 2427 | /** |
| | 2428 | * Calculate frame position in cylindrical format for corresponding 3D coordinates on sphere. |
| | 2429 | * |
| | 2430 | * @param s filter private context |
| | 2431 | * @param vec coordinates on sphere |
| | 2432 | * @param width frame width |
| | 2433 | * @param height frame height |
| | 2434 | * @param us horizontal coordinates for interpolation window |
| | 2435 | * @param vs vertical coordinates for interpolation window |
| | 2436 | * @param du horizontal relative coordinate |
| | 2437 | * @param dv vertical relative coordinate |
| | 2438 | */ |
| | 2439 | static void xyz_to_cylindrical(const V360Context *s, |
| | 2440 | const float *vec, int width, int height, |
| | 2441 | int16_t us[4][4], int16_t vs[4][4], float *du, float *dv) |
| | 2442 | { |
| | 2443 | const float phi = atan2f(vec[0], -vec[2]) * s->input_mirror_modifier[0] / s->iflat_range[0]; |
| | 2444 | const float theta = atan2f(-vec[1], hypotf(vec[0], vec[2])) * s->input_mirror_modifier[1] / s->iflat_range[1]; |
| | 2445 | int visible, ui, vi; |
| | 2446 | float uf, vf; |
| | 2447 | |
| | 2448 | uf = (phi + 1.f) * (width - 1) / 2.f; |
| | 2449 | vf = (tanf(theta) + 1.f) * height / 2.f; |
| | 2450 | ui = floorf(uf); |
| | 2451 | vi = floorf(vf); |
| | 2452 | |
| | 2453 | visible = vi >= 0 && vi < height && ui >= 0 && ui < width && |
| | 2454 | theta <= M_PI * s->iv_fov / 180.f && |
| | 2455 | theta >= -M_PI * s->iv_fov / 180.f; |
| | 2456 | |
| | 2457 | *du = uf - ui; |
| | 2458 | *dv = vf - vi; |
| | 2459 | |
| | 2460 | for (int i = -1; i < 3; i++) { |
| | 2461 | for (int j = -1; j < 3; j++) { |
| | 2462 | us[i + 1][j + 1] = visible ? av_clip(ui + j, 0, width - 1) : 0; |
| | 2463 | vs[i + 1][j + 1] = visible ? av_clip(vi + i, 0, height - 1) : 0; |
| | 2464 | } |
| | 2465 | } |
| | 2466 | } |
| | 2467 | |
| 2409 | /** | 2468 | /** |
| 2410 | * Calculate 3D coordinates on sphere for corresponding frame position in perspective format. | 2469 | * Calculate 3D coordinates on sphere for corresponding frame position in perspective format. |
| 2411 | * | 2470 | * |
| @@ -3011,7 +3070,6 @@ static int config_output(AVFilterLink *outlink) · 599 unmodified lines |
| 3011 | hf = h; | 3070 | hf = h; |
| 3012 | break; | 3071 | break; |
| 3013 | case PERSPECTIVE: | 3072 | case PERSPECTIVE: |
| 3014 | case CYLINDRICAL: | | |
| 3015 | case PANNINI: | 3073 | case PANNINI: |
| 3016 | case FISHEYE: | 3074 | case FISHEYE: |
| 3017 | av_log(ctx, AV_LOG_ERROR, "Supplied format is not accepted as input.\n"); | 3075 | av_log(ctx, AV_LOG_ERROR, "Supplied format is not accepted as input.\n"); |
| @@ -3058,6 +3116,12 @@ static int config_output(AVFilterLink *outlink) · 40 unmodified lines |
| 3058 | wf = w; | 3116 | wf = w; |
| 3059 | hf = h; | 3117 | hf = h; |
| 3060 | break; | 3118 | break; |
| | 3119 | case CYLINDRICAL: |
| | 3120 | s->in_transform = xyz_to_cylindrical; |
| | 3121 | err = prepare_cylindrical_in(ctx); |
| | 3122 | wf = w; |
| | 3123 | hf = h * 2.f; |
| | 3124 | break; |
| 3061 | default: | 3125 | default: |
| 3062 | av_log(ctx, AV_LOG_ERROR, "Specified input format is not handled.\n"); | 3126 | av_log(ctx, AV_LOG_ERROR, "Specified input format is not handled.\n"); |
| 3063 | return AVERROR_BUG; | 3127 | return AVERROR_BUG; |