From ecaef69fbb1ed011a14624d944113e32a17d7780 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sat, 21 Sep 2019 16:07:16 +0200 Subject: [PATCH] avfilter/vf_v360: simplify xyz_to_ball() calculations --- libavfilter/vf_v360.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c index d966723770..1a0fe90909 100644 --- a/libavfilter/vf_v360.c +++ b/libavfilter/vf_v360.c @@ -1603,12 +1603,13 @@ static void xyz_to_ball(const V360Context *s, uint16_t us[4][4], uint16_t vs[4][4], float *du, float *dv) { const float l = hypotf(vec[0], vec[1]); - const float r = sinf(acosf(-vec[2]) * 0.5f); + const float r = sqrtf(1.f + vec[2]) / M_SQRT2; float uf, vf; int ui, vi; - uf = (1.f - r * vec[0] * s->input_mirror_modifier[0] / l) * width / 2.f; - vf = (1.f + r * vec[1] * s->input_mirror_modifier[1] / l) * height / 2.f; + uf = (1.f + r * vec[0] * s->input_mirror_modifier[0] / (l > 0.f ? l : 1.f)) * width * 0.5f; + vf = (1.f - r * vec[1] * s->input_mirror_modifier[1] / (l > 0.f ? l : 1.f)) * height * 0.5f; + ui = floorf(uf); vi = floorf(vf);