History

avfilter/vf_v360: extend stereographic projection

Add option to change central point projection.

Paul B Mahol committed 7 years ago

Commit 976617c1 parent 79854303 files · +31 −9Browse files

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

Unified · Split

2 files
  1. libavfilter/v360.h +1 −0
  2. libavfilter/vf_v360.c +24 −8
libavfilter/v360.h+1−0
@@ -105,6 +105,7 @@ typedef struct V360Context { · 104 unmodified lines
105105
106106 float h_fov, v_fov;
107107 float flat_range[3];
108+ float p_lon, p_lat;
108109
109110 float input_mirror_modifier[2];
110111
libavfilter/vf_v360.c+24−8
@@ -33,6 +33,8 @@ · 32 unmodified lines
3333 * 5) Remap input frame to output frame using precalculated data
3434 */
3535
36+#include <float.h>
37+
3638 #include "libavutil/avassert.h"
3739 #include "libavutil/imgutils.h"
3840 #include "libavutil/pixdesc.h"
@@ -105,6 +107,8 @@ static const AVOption v360_options[] = { · 66 unmodified lines
105107 { "iv_flip", "flip in video vertically", OFFSET(iv_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "iv_flip"},
106108 { "in_trans", "transpose video input", OFFSET(in_transpose), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "in_transpose"},
107109 { "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"},
108112 { NULL }
109113 };
110114
@@ -1406,14 +1410,26 @@ static void stereographic_to_xyz(const V360Context *s, · 1295 unmodified lines
14061410 int i, int j, int width, int height,
14071411 float *vec)
14081412 {
1409− const float z = 0.5f * s->h_fov * M_PI / 180.f;
1410− const float x = z * (2.f * i / width - 1.f);
1411− const float y = z * (2.f * j / height - 1.f);
1412− const float xy = x * x + y * y;
1413−
1414− vec[0] = 2.f * x / (1.f + xy);
1415− vec[1] = (-1.f + xy) / (1.f + xy);
1416− vec[2] = 2.f * y / (1.f + xy);
1413+ const float x = ((2.f * i) / width - 1.f) * (s->h_fov / 180.f) * M_PI;
1414+ const float y = ((2.f * j) / height - 1.f) * (s->v_fov / 90.f) * M_PI_2;
1415+ const float rho = hypotf(x, y) + FLT_EPSILON;
1416+ const float c = 2.f * atan2f(rho, 0.15f / 2.f);
1417+ const float cos_c = cosf(c);
1418+ const float sin_c = sinf(c);
1419+ const float cp_x = s->p_lon / 180.f * M_PI;
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;
14171433
14181434 normalize_vector(vec);
14191435 }

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