summaryrefslogtreecommitdiff
path: root/libavfilter
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2020-01-22 12:23:58 +0100
committerPaul B Mahol <onemda@gmail.com>2020-01-22 12:59:35 +0100
commita00fa73f47c7b201d2b82475f88f94a754b5b87c (patch)
tree9a0f9992d4640f191dc1bfcb3670a39de07c28f5 /libavfilter
parent2bae3da79e71d04dd7ec79cb7d48e845b69f6e21 (diff)
avfilter/vf_v360: improve fisheye input format
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/vf_v360.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c
index c4a5926db7..2ed0acb5a7 100644
--- a/libavfilter/vf_v360.c
+++ b/libavfilter/vf_v360.c
@@ -2379,22 +2379,23 @@ 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 phi = -atan2f(hypotf(vec[0], vec[1]), -vec[2]) / M_PI;
+ const float theta = -atan2f(vec[0], vec[1]);
- 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;
+ float uf = sinf(theta) * phi * s->input_mirror_modifier[0] / s->iflat_range[0];
+ float vf = cosf(theta) * phi * s->input_mirror_modifier[1] / s->iflat_range[1];
- int visible, ui, vi;
+ const int visible = hypotf(uf, vf) <= 0.5f;
+ int ui, vi;
+
+ uf = (uf + 0.5f) * width;
+ vf = (vf + 0.5f) * height;
ui = floorf(uf);
vi = floorf(vf);
- visible = vec[2] < 0.f;
-
- *du = uf - ui;
- *dv = vf - vi;
+ *du = visible ? uf - ui : 0.f;
+ *dv = visible ? vf - vi : 0.f;
for (int i = -1; i < 3; i++) {
for (int j = -1; j < 3; j++) {