History

avfilter/vf_v360: refactor FoV calculation for stereographic

Move in out of loop.

Paul B Mahol committed 7 years ago

Commit 7ce70021 parent 78b86c31 file · +23 −6Browse files

Unified · Split

libavfilter/vf_v360.c+23−6
@@ -1396,6 +1396,26 @@ static void equirect_to_xyz(const V360Context *s, · 1395 unmodified lines
13961396 vec[2] = -cos_theta * cos_phi;
13971397 }
13981398
1399+/**
1400+ * Prepare data for processing stereographic output format.
1401+ *
1402+ * @param ctx filter context
1403+ *
1404+ * @return error code
1405+ */
1406+static int prepare_stereographic_out(AVFilterContext *ctx)
1407+{
1408+ V360Context *s = ctx->priv;
1409+
1410+ const float h_angle = tan(FFMIN(s->h_fov, 359.f) * M_PI / 720.f);
1411+ const float v_angle = tan(FFMIN(s->v_fov, 359.f) * M_PI / 720.f);
1412+
1413+ s->flat_range[0] = h_angle;
1414+ s->flat_range[1] = v_angle;
1415+
1416+ return 0;
1417+}
1418+
13991419 /**
14001420 * Calculate 3D coordinates on sphere for corresponding frame position in stereographic format.
14011421 *
@@ -1410,11 +1430,8 @@ static void stereographic_to_xyz(const V360Context *s, · 8 unmodified lines
14101430 int i, int j, int width, int height,
14111431 float *vec)
14121432 {
1413− const float h_angle = tan(FFMIN(s->h_fov, 359.f) * M_PI / 720.f);
1414− const float v_angle = tan(FFMIN(s->v_fov, 359.f) * M_PI / 720.f);
1415−
1416− const float x = ((2.f * i) / width - 1.f) * h_angle;
1417− const float y = ((2.f * j) / height - 1.f) * v_angle;
1433+ const float x = ((2.f * i) / width - 1.f) * s->flat_range[0];
1434+ const float y = ((2.f * j) / height - 1.f) * s->flat_range[1];
14181435 const float xy = x * x + y * y;
14191436
14201437 vec[0] = 2.f * x / (1.f + xy);
@@ -2282,7 +2299,7 @@ static int config_output(AVFilterLink *outlink) · 861 unmodified lines
22822299 break;
22832300 case STEREOGRAPHIC:
22842301 out_transform = stereographic_to_xyz;
2285− err = 0;
2302+ err = prepare_stereographic_out(ctx);
22862303 w = FFMAX(roundf(wf), roundf(hf));
22872304 h = w;
22882305 break;

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