History

avfilter/vf_v360: refactor rescaling of i/j

Paul B Mahol committed 5 years ago

Commit 1616f7f1 parent 25212851 file · +57 −52Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_v360.c+57−52
@@ -1373,6 +1373,11 @@ static void process_cube_coordinates(const V360Context *s, · 1372 unmodified lines
13731373 rotate_cube_face(new_uf, new_vf, s->in_cubemap_face_rotation[*face]);
13741374 }
13751375
1376+static av_always_inline float rescale(int x, int s)
1377+{
1378+ return (2.f * x + 1.f) / s - 1.f;
1379+}
1380+
13761381 /**
13771382 * Calculate 3D coordinates on sphere for corresponding frame position in cubemap3x2 format.
13781383 *
@@ -1402,8 +1407,8 @@ static int cube3x2_to_xyz(const V360Context *s, · 23 unmodified lines
14021407 const int ewi = ceilf(ew * (u_face + 1)) - u_shift;
14031408 const int ehi = ceilf(eh * (v_face + 1)) - v_shift;
14041409
1405− const float uf = 2.f * (i - u_shift + 0.5f) / ewi - 1.f;
1406− const float vf = 2.f * (j - v_shift + 0.5f) / ehi - 1.f;
1410+ const float uf = rescale(i - u_shift, ewi);
1411+ const float vf = rescale(j - v_shift, ehi);
14071412
14081413 cube_to_xyz(s, uf, vf, face, vec, scalew, scaleh);
14091414
@@ -1526,8 +1531,8 @@ static int cube1x6_to_xyz(const V360Context *s, · 116 unmodified lines
15261531 const int v_shift = ceilf(eh * face);
15271532 const int ehi = ceilf(eh * (face + 1)) - v_shift;
15281533
1529− const float uf = 2.f * (i + 0.5f) / ew - 1.f;
1530− const float vf = 2.f * (j - v_shift + 0.5f) / ehi - 1.f;
1534+ const float uf = rescale(i, ew);
1535+ const float vf = rescale(j - v_shift, ehi);
15311536
15321537 cube_to_xyz(s, uf, vf, face, vec, scalew, scaleh);
15331538
@@ -1559,8 +1564,8 @@ static int cube6x1_to_xyz(const V360Context *s, · 25 unmodified lines
15591564 const int u_shift = ceilf(ew * face);
15601565 const int ewi = ceilf(ew * (face + 1)) - u_shift;
15611566
1562− const float uf = 2.f * (i - u_shift + 0.5f) / ewi - 1.f;
1563− const float vf = 2.f * (j + 0.5f) / eh - 1.f;
1567+ const float uf = rescale(i - u_shift, ewi);
1568+ const float vf = rescale(j, eh);
15641569
15651570 cube_to_xyz(s, uf, vf, face, vec, scalew, scaleh);
15661571
@@ -1758,8 +1763,8 @@ static int equirect_to_xyz(const V360Context *s, · 191 unmodified lines
17581763 int i, int j, int width, int height,
17591764 float *vec)
17601765 {
1761− const float phi = ((2.f * i + 0.5f) / width - 1.f) * s->flat_range[0];
1762− const float theta = ((2.f * j + 0.5f) / height - 1.f) * s->flat_range[1];
1766+ const float phi = rescale(i, width) * s->flat_range[0];
1767+ const float theta = rescale(j, height) * s->flat_range[1];
17631768
17641769 const float sin_phi = sinf(phi);
17651770 const float cos_phi = cosf(phi);
@@ -1787,8 +1792,8 @@ static int hequirect_to_xyz(const V360Context *s, · 21 unmodified lines
17871792 int i, int j, int width, int height,
17881793 float *vec)
17891794 {
1790− const float phi = ((2.f * i + 0.5f) / width - 1.f) * M_PI_2;
1791− const float theta = ((2.f * j + 0.5f) / height - 1.f) * M_PI_2;
1795+ const float phi = rescale(i, width) * M_PI_2;
1796+ const float theta = rescale(j, height) * M_PI_2;
17921797
17931798 const float sin_phi = sinf(phi);
17941799 const float cos_phi = cosf(phi);
@@ -1833,8 +1838,8 @@ static int stereographic_to_xyz(const V360Context *s, · 38 unmodified lines
18331838 int i, int j, int width, int height,
18341839 float *vec)
18351840 {
1836− const float x = ((2.f * i + 1.f) / width - 1.f) * s->flat_range[0];
1837− const float y = ((2.f * j + 1.f) / height - 1.f) * s->flat_range[1];
1841+ const float x = rescale(i, width) * s->flat_range[0];
1842+ const float y = rescale(j, height) * s->flat_range[1];
18381843 const float r = hypotf(x, y);
18391844 const float theta = atanf(r) * 2.f;
18401845 const float sin_theta = sinf(theta);
@@ -1939,8 +1944,8 @@ static int equisolid_to_xyz(const V360Context *s, · 98 unmodified lines
19391944 int i, int j, int width, int height,
19401945 float *vec)
19411946 {
1942− const float x = ((2.f * i + 1.f) / width - 1.f) * s->flat_range[0];
1943− const float y = ((2.f * j + 1.f) / height - 1.f) * s->flat_range[1];
1947+ const float x = rescale(i, width) * s->flat_range[0];
1948+ const float y = rescale(j, height) * s->flat_range[1];
19441949 const float r = hypotf(x, y);
19451950 const float theta = asinf(r) * 2.f;
19461951 const float sin_theta = sinf(theta);
@@ -2045,8 +2050,8 @@ static int orthographic_to_xyz(const V360Context *s, · 98 unmodified lines
20452050 int i, int j, int width, int height,
20462051 float *vec)
20472052 {
2048− const float x = ((2.f * i + 1.f) / width - 1.f) * s->flat_range[0];
2049− const float y = ((2.f * j + 1.f) / height - 1.f) * s->flat_range[1];
2053+ const float x = rescale(i, width) * s->flat_range[0];
2054+ const float y = rescale(j, height) * s->flat_range[1];
20502055 const float r = hypotf(x, y);
20512056 const float theta = asinf(r);
20522057
@@ -2155,8 +2160,8 @@ static int xyz_to_equirect(const V360Context *s, · 102 unmodified lines
21552160 const float phi = atan2f(vec[0], vec[2]);
21562161 const float theta = asinf(vec[1]);
21572162
2158− const float uf = (phi / s->iflat_range[0] + 1.f) * width / 2.f;
2159− const float vf = (theta / s->iflat_range[1] + 1.f) * height / 2.f;
2163+ const float uf = (phi / s->iflat_range[0] + 1.f) * width / 2.f - 0.5f;
2164+ const float vf = (theta / s->iflat_range[1] + 1.f) * height / 2.f - 0.5f;
21602165
21612166 const int ui = floorf(uf);
21622167 const int vi = floorf(vf);
@@ -2333,8 +2338,8 @@ static int mercator_to_xyz(const V360Context *s, · 170 unmodified lines
23332338 int i, int j, int width, int height,
23342339 float *vec)
23352340 {
2336− const float phi = ((2.f * i + 1.f) / width - 1.f) * M_PI + M_PI_2;
2337− const float y = ((2.f * j + 1.f) / height - 1.f) * M_PI;
2341+ const float phi = rescale(i, width) * M_PI + M_PI_2;
2342+ const float y = rescale(j, height) * M_PI;
23382343 const float div = expf(2.f * y) + 1.f;
23392344
23402345 const float sin_phi = sinf(phi);
@@ -2401,8 +2406,8 @@ static int ball_to_xyz(const V360Context *s, · 60 unmodified lines
24012406 int i, int j, int width, int height,
24022407 float *vec)
24032408 {
2404− const float x = (2.f * i + 1.f) / width - 1.f;
2405− const float y = (2.f * j + 1.f) / height - 1.f;
2409+ const float x = rescale(i, width);
2410+ const float y = rescale(j, height);
24062411 const float l = hypotf(x, y);
24072412
24082413 if (l <= 1.f) {
@@ -2435,8 +2440,8 @@ static int hammer_to_xyz(const V360Context *s, · 26 unmodified lines
24352440 int i, int j, int width, int height,
24362441 float *vec)
24372442 {
2438− const float x = ((2.f * i + 1.f) / width - 1.f);
2439− const float y = ((2.f * j + 1.f) / height - 1.f);
2443+ const float x = rescale(i, width);
2444+ const float y = rescale(j, height);
24402445
24412446 const float xx = x * x;
24422447 const float yy = y * y;
@@ -2515,8 +2520,8 @@ static int sinusoidal_to_xyz(const V360Context *s, · 72 unmodified lines
25152520 int i, int j, int width, int height,
25162521 float *vec)
25172522 {
2518− const float theta = ((2.f * j + 1.f) / height - 1.f) * M_PI_2;
2519− const float phi = ((2.f * i + 1.f) / width - 1.f) * M_PI / cosf(theta);
2523+ const float theta = rescale(j, height) * M_PI_2;
2524+ const float phi = rescale(i, width) * M_PI / cosf(theta);
25202525
25212526 const float sin_phi = sinf(phi);
25222527 const float cos_phi = cosf(phi);
@@ -2820,8 +2825,8 @@ static int flat_to_xyz(const V360Context *s, · 297 unmodified lines
28202825 int i, int j, int width, int height,
28212826 float *vec)
28222827 {
2823− const float l_x = s->flat_range[0] * ((2.f * i + 0.5f) / width - 1.f);
2824− const float l_y = s->flat_range[1] * ((2.f * j + 0.5f) / height - 1.f);
2828+ const float l_x = s->flat_range[0] * rescale(i, width);
2829+ const float l_y = s->flat_range[1] * rescale(j, height);
28252830
28262831 vec[0] = l_x;
28272832 vec[1] = l_y;
@@ -2863,8 +2868,8 @@ static int fisheye_to_xyz(const V360Context *s, · 35 unmodified lines
28632868 int i, int j, int width, int height,
28642869 float *vec)
28652870 {
2866− const float uf = s->flat_range[0] * ((2.f * i) / width - 1.f);
2867− const float vf = s->flat_range[1] * ((2.f * j + 1.f) / height - 1.f);
2871+ const float uf = s->flat_range[0] * rescale(i, width);
2872+ const float vf = s->flat_range[1] * rescale(j, height);
28682873
28692874 const float phi = atan2f(vf, uf);
28702875 const float theta = M_PI_2 * (1.f - hypotf(uf, vf));
@@ -2959,8 +2964,8 @@ static int pannini_to_xyz(const V360Context *s, · 88 unmodified lines
29592964 int i, int j, int width, int height,
29602965 float *vec)
29612966 {
2962− const float uf = ((2.f * i + 1.f) / width - 1.f);
2963− const float vf = ((2.f * j + 1.f) / height - 1.f);
2967+ const float uf = rescale(i, width);
2968+ const float vf = rescale(j, height);
29642969
29652970 const float d = s->h_fov;
29662971 const float k = uf * uf / ((d + 1.f) * (d + 1.f));
@@ -3004,8 +3009,8 @@ static int xyz_to_pannini(const V360Context *s, · 37 unmodified lines
30043009 const float x = S * sinf(phi);
30053010 const float y = S * tanf(theta);
30063011
3007− const float uf = (x + 1.f) * width / 2.f;
3008− const float vf = (y + 1.f) * height / 2.f;
3012+ const float uf = (x + 1.f) * width / 2.f - 0.5f;
3013+ const float vf = (y + 1.f) * height / 2.f - 0.5f;
30093014
30103015 const int ui = floorf(uf);
30113016 const int vi = floorf(vf);
@@ -3056,8 +3061,8 @@ static int cylindrical_to_xyz(const V360Context *s, · 44 unmodified lines
30563061 int i, int j, int width, int height,
30573062 float *vec)
30583063 {
3059− const float uf = s->flat_range[0] * ((2.f * i + 1.f) / width - 1.f);
3060− const float vf = s->flat_range[1] * ((2.f * j + 1.f) / height - 1.f);
3064+ const float uf = s->flat_range[0] * rescale(i, width);
3065+ const float vf = s->flat_range[1] * rescale(j, height);
30613066
30623067 const float phi = uf;
30633068 const float theta = atanf(vf);
@@ -3183,8 +3188,8 @@ static int cylindricalea_to_xyz(const V360Context *s, · 119 unmodified lines
31833188 int i, int j, int width, int height,
31843189 float *vec)
31853190 {
3186− const float uf = s->flat_range[0] * ((2.f * i + 1.f) / width - 1.f);
3187− const float vf = s->flat_range[1] * ((2.f * j + 1.f) / height - 1.f);
3191+ const float uf = s->flat_range[0] * rescale(i, width);
3192+ const float vf = s->flat_range[1] * rescale(j, height);
31883193
31893194 const float phi = uf;
31903195 const float theta = asinf(vf);
@@ -3259,8 +3264,8 @@ static int perspective_to_xyz(const V360Context *s, · 68 unmodified lines
32593264 int i, int j, int width, int height,
32603265 float *vec)
32613266 {
3262− const float uf = ((2.f * i + 1.f) / width - 1.f);
3263− const float vf = ((2.f * j + 1.f) / height - 1.f);
3267+ const float uf = rescale(i, width);
3268+ const float vf = rescale(j, height);
32643269 const float rh = hypotf(uf, vf);
32653270 const float sinzz = 1.f - rh * rh;
32663271 const float h = 1.f + s->v_fov;
@@ -3305,8 +3310,8 @@ static int tetrahedron_to_xyz(const V360Context *s, · 38 unmodified lines
33053310 int i, int j, int width, int height,
33063311 float *vec)
33073312 {
3308− const float uf = (float)i / width;
3309− const float vf = (float)j / height;
3313+ const float uf = ((float)i + 0.5f) / width;
3314+ const float vf = ((float)j + 0.5f) / height;
33103315
33113316 vec[0] = uf < 0.5f ? uf * 4.f - 1.f : 3.f - uf * 4.f;
33123317 vec[1] = 1.f - vf * 2.f;
@@ -3394,8 +3399,8 @@ static int dfisheye_to_xyz(const V360Context *s, · 81 unmodified lines
33943399 const int ei = i >= ew ? i - ew : i;
33953400 const float m = i >= ew ? 1.f : -1.f;
33963401
3397− const float uf = s->flat_range[0] * ((2.f * ei) / ew - 1.f);
3398− const float vf = s->flat_range[1] * ((2.f * j + 1.f) / eh - 1.f);
3402+ const float uf = s->flat_range[0] * rescale(ei, ew);
3403+ const float vf = s->flat_range[1] * rescale(j, eh);
33993404
34003405 const float h = hypotf(uf, vf);
34013406 const float lh = h > 0.f ? h : 1.f;
@@ -3488,8 +3493,8 @@ static int barrel_to_xyz(const V360Context *s, · 86 unmodified lines
34883493 const int ew = 4 * width / 5;
34893494 const int eh = height;
34903495
3491− const float phi = ((2.f * i) / ew - 1.f) * M_PI / scale;
3492− const float theta = ((2.f * j) / eh - 1.f) * theta_range / scale;
3496+ const float phi = rescale(i, ew) * M_PI / scale;
3497+ const float theta = rescale(j, eh) * theta_range / scale;
34933498
34943499 const float sin_phi = sinf(phi);
34953500 const float cos_phi = cosf(phi);
@@ -3506,8 +3511,8 @@ static int barrel_to_xyz(const V360Context *s, · 10 unmodified lines
35063511 float uf, vf;
35073512
35083513 if (j < eh) { // UP
3509− uf = 2.f * (i - 4 * ew) / ew - 1.f;
3510− vf = 2.f * (j ) / eh - 1.f;
3514+ uf = rescale(i - 4 * ew, ew);
3515+ vf = rescale(j, eh);
35113516
35123517 uf /= scale;
35133518 vf /= scale;
@@ -3516,8 +3521,8 @@ static int barrel_to_xyz(const V360Context *s, · 2 unmodified lines
35163521 l_y = -1.f;
35173522 l_z = vf;
35183523 } else { // DOWN
3519− uf = 2.f * (i - 4 * ew) / ew - 1.f;
3520− vf = 2.f * (j - eh) / eh - 1.f;
3524+ uf = rescale(i - 4 * ew, ew);
3525+ vf = rescale(j - eh, eh);
35213526
35223527 uf /= scale;
35233528 vf /= scale;
@@ -3937,8 +3942,8 @@ static int octahedron_to_xyz(const V360Context *s, · 413 unmodified lines
39373942 int i, int j, int width, int height,
39383943 float *vec)
39393944 {
3940− const float x = ((i + 0.5f) / width) * 2.f - 1.f;
3941− const float y = ((j + 0.5f) / height) * 2.f - 1.f;
3945+ const float x = rescale(i, width);
3946+ const float y = rescale(j, height);
39423947 const float ax = fabsf(x);
39433948 const float ay = fabsf(y);
39443949

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