Add option to change central point projection.
Showing the changes to libavfilter (2 of 3 files). Show all
Unified · Split
| @@ -105,6 +105,7 @@ typedef struct V360Context { · 104 unmodified lines | |||
| 105 | 105 | ||
| 106 | float h_fov, v_fov; | 106 | float h_fov, v_fov; |
| 107 | float flat_range[3]; | 107 | float flat_range[3]; |
| 108 | float p_lon, p_lat; | ||
| 108 | 109 | ||
| 109 | float input_mirror_modifier[2]; | 110 | float input_mirror_modifier[2]; |
| 110 | 111 | ||
| @@ -33,6 +33,8 @@ · 32 unmodified lines | |||
| 33 | * 5) Remap input frame to output frame using precalculated data | 33 | * 5) Remap input frame to output frame using precalculated data |
| 34 | */ | 34 | */ |
| 35 | 35 | ||
| 36 | #include <float.h> | ||
| 37 | |||
| 36 | #include "libavutil/avassert.h" | 38 | #include "libavutil/avassert.h" |
| 37 | #include "libavutil/imgutils.h" | 39 | #include "libavutil/imgutils.h" |
| 38 | #include "libavutil/pixdesc.h" | 40 | #include "libavutil/pixdesc.h" |
| @@ -105,6 +107,8 @@ static const AVOption v360_options[] = { · 66 unmodified lines | |||
| 105 | { "iv_flip", "flip in video vertically", OFFSET(iv_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "iv_flip"}, | 107 | { "iv_flip", "flip in video vertically", OFFSET(iv_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "iv_flip"}, |
| 106 | { "in_trans", "transpose video input", OFFSET(in_transpose), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "in_transpose"}, | 108 | { "in_trans", "transpose video input", OFFSET(in_transpose), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "in_transpose"}, |
| 107 | { "out_trans", "transpose video output", OFFSET(out_transpose), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "out_transpose"}, | 109 | { "out_trans", "transpose video output", OFFSET(out_transpose), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "out_transpose"}, |
| 110 | { "p_lon", "central projection longitude", OFFSET(p_lon), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "p_lon"}, | ||
| 111 | { "p_lat", "central projection latitude", OFFSET(p_lat), AV_OPT_TYPE_FLOAT, {.dbl=90.f}, -90.f, 90.f, FLAGS, "p_lat"}, | ||
| 108 | { NULL } | 112 | { NULL } |
| 109 | }; | 113 | }; |
| 110 | 114 | ||
| @@ -1406,14 +1410,26 @@ static void stereographic_to_xyz(const V360Context *s, · 1295 unmodified lines | |||
| 1406 | int i, int j, int width, int height, | 1410 | int i, int j, int width, int height, |
| 1407 | float *vec) | 1411 | float *vec) |
| 1408 | { | 1412 | { |
| 1409 | const float z = 0.5f * s->h_fov * M_PI / 180.f; | 1413 | const float x = ((2.f * i) / width - 1.f) * (s->h_fov / 180.f) * M_PI; |
| 1410 | const float x = z * (2.f * i / width - 1.f); | 1414 | const float y = ((2.f * j) / height - 1.f) * (s->v_fov / 90.f) * M_PI_2; |
| 1411 | const float y = z * (2.f * j / height - 1.f); | 1415 | const float rho = hypotf(x, y) + FLT_EPSILON; |
| 1412 | const float xy = x * x + y * y; | 1416 | const float c = 2.f * atan2f(rho, 0.15f / 2.f); |
| 1413 | 1417 | const float cos_c = cosf(c); | |
| 1414 | vec[0] = 2.f * x / (1.f + xy); | 1418 | const float sin_c = sinf(c); |
| 1415 | vec[1] = (-1.f + xy) / (1.f + xy); | 1419 | const float cp_x = s->p_lon / 180.f * M_PI; |
| 1416 | vec[2] = 2.f * y / (1.f + xy); | 1420 | const float cp_y = s->p_lat / 90.f * M_PI_2; |
| 1421 | |||
| 1422 | const float phi = cp_x + atan2f(x * sin_c, rho * cosf(cp_y) * cos_c - y * sinf(cp_y) * sin_c); | ||
| 1423 | const float theta = asinf(cos_c * sinf(cp_y) + (y * sin_c * cosf(cp_y)) / rho); | ||
| 1424 | |||
| 1425 | const float sin_phi = sinf(phi); | ||
| 1426 | const float cos_phi = cosf(phi); | ||
| 1427 | const float sin_theta = sinf(theta); | ||
| 1428 | const float cos_theta = cosf(theta); | ||
| 1429 | |||
| 1430 | vec[0] = cos_theta * sin_phi; | ||
| 1431 | vec[1] = -sin_theta; | ||
| 1432 | vec[2] = -cos_theta * cos_phi; | ||
| 1417 | 1433 | ||
| 1418 | normalize_vector(vec); | 1434 | normalize_vector(vec); |
| 1419 | } | 1435 | } |