Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -1373,6 +1373,11 @@ static void process_cube_coordinates(const V360Context *s, · 1372 unmodified lines | |||
| 1373 | rotate_cube_face(new_uf, new_vf, s->in_cubemap_face_rotation[*face]); | 1373 | rotate_cube_face(new_uf, new_vf, s->in_cubemap_face_rotation[*face]); |
| 1374 | } | 1374 | } |
| 1375 | 1375 | ||
| 1376 | static av_always_inline float rescale(int x, int s) | ||
| 1377 | { | ||
| 1378 | return (2.f * x + 1.f) / s - 1.f; | ||
| 1379 | } | ||
| 1380 | |||
| 1376 | /** | 1381 | /** |
| 1377 | * Calculate 3D coordinates on sphere for corresponding frame position in cubemap3x2 format. | 1382 | * Calculate 3D coordinates on sphere for corresponding frame position in cubemap3x2 format. |
| 1378 | * | 1383 | * |
| @@ -1402,8 +1407,8 @@ static int cube3x2_to_xyz(const V360Context *s, · 23 unmodified lines | |||
| 1402 | const int ewi = ceilf(ew * (u_face + 1)) - u_shift; | 1407 | const int ewi = ceilf(ew * (u_face + 1)) - u_shift; |
| 1403 | const int ehi = ceilf(eh * (v_face + 1)) - v_shift; | 1408 | const int ehi = ceilf(eh * (v_face + 1)) - v_shift; |
| 1404 | 1409 | ||
| 1405 | const float uf = 2.f * (i - u_shift + 0.5f) / ewi - 1.f; | 1410 | const float uf = rescale(i - u_shift, ewi); |
| 1406 | const float vf = 2.f * (j - v_shift + 0.5f) / ehi - 1.f; | 1411 | const float vf = rescale(j - v_shift, ehi); |
| 1407 | 1412 | ||
| 1408 | cube_to_xyz(s, uf, vf, face, vec, scalew, scaleh); | 1413 | cube_to_xyz(s, uf, vf, face, vec, scalew, scaleh); |
| 1409 | 1414 | ||
| @@ -1526,8 +1531,8 @@ static int cube1x6_to_xyz(const V360Context *s, · 116 unmodified lines | |||
| 1526 | const int v_shift = ceilf(eh * face); | 1531 | const int v_shift = ceilf(eh * face); |
| 1527 | const int ehi = ceilf(eh * (face + 1)) - v_shift; | 1532 | const int ehi = ceilf(eh * (face + 1)) - v_shift; |
| 1528 | 1533 | ||
| 1529 | const float uf = 2.f * (i + 0.5f) / ew - 1.f; | 1534 | const float uf = rescale(i, ew); |
| 1530 | const float vf = 2.f * (j - v_shift + 0.5f) / ehi - 1.f; | 1535 | const float vf = rescale(j - v_shift, ehi); |
| 1531 | 1536 | ||
| 1532 | cube_to_xyz(s, uf, vf, face, vec, scalew, scaleh); | 1537 | cube_to_xyz(s, uf, vf, face, vec, scalew, scaleh); |
| 1533 | 1538 | ||
| @@ -1559,8 +1564,8 @@ static int cube6x1_to_xyz(const V360Context *s, · 25 unmodified lines | |||
| 1559 | const int u_shift = ceilf(ew * face); | 1564 | const int u_shift = ceilf(ew * face); |
| 1560 | const int ewi = ceilf(ew * (face + 1)) - u_shift; | 1565 | const int ewi = ceilf(ew * (face + 1)) - u_shift; |
| 1561 | 1566 | ||
| 1562 | const float uf = 2.f * (i - u_shift + 0.5f) / ewi - 1.f; | 1567 | const float uf = rescale(i - u_shift, ewi); |
| 1563 | const float vf = 2.f * (j + 0.5f) / eh - 1.f; | 1568 | const float vf = rescale(j, eh); |
| 1564 | 1569 | ||
| 1565 | cube_to_xyz(s, uf, vf, face, vec, scalew, scaleh); | 1570 | cube_to_xyz(s, uf, vf, face, vec, scalew, scaleh); |
| 1566 | 1571 | ||
| @@ -1758,8 +1763,8 @@ static int equirect_to_xyz(const V360Context *s, · 191 unmodified lines | |||
| 1758 | int i, int j, int width, int height, | 1763 | int i, int j, int width, int height, |
| 1759 | float *vec) | 1764 | float *vec) |
| 1760 | { | 1765 | { |
| 1761 | const float phi = ((2.f * i + 0.5f) / width - 1.f) * s->flat_range[0]; | 1766 | const float phi = rescale(i, width) * s->flat_range[0]; |
| 1762 | const float theta = ((2.f * j + 0.5f) / height - 1.f) * s->flat_range[1]; | 1767 | const float theta = rescale(j, height) * s->flat_range[1]; |
| 1763 | 1768 | ||
| 1764 | const float sin_phi = sinf(phi); | 1769 | const float sin_phi = sinf(phi); |
| 1765 | const float cos_phi = cosf(phi); | 1770 | const float cos_phi = cosf(phi); |
| @@ -1787,8 +1792,8 @@ static int hequirect_to_xyz(const V360Context *s, · 21 unmodified lines | |||
| 1787 | int i, int j, int width, int height, | 1792 | int i, int j, int width, int height, |
| 1788 | float *vec) | 1793 | float *vec) |
| 1789 | { | 1794 | { |
| 1790 | const float phi = ((2.f * i + 0.5f) / width - 1.f) * M_PI_2; | 1795 | const float phi = rescale(i, width) * M_PI_2; |
| 1791 | const float theta = ((2.f * j + 0.5f) / height - 1.f) * M_PI_2; | 1796 | const float theta = rescale(j, height) * M_PI_2; |
| 1792 | 1797 | ||
| 1793 | const float sin_phi = sinf(phi); | 1798 | const float sin_phi = sinf(phi); |
| 1794 | const float cos_phi = cosf(phi); | 1799 | const float cos_phi = cosf(phi); |
| @@ -1833,8 +1838,8 @@ static int stereographic_to_xyz(const V360Context *s, · 38 unmodified lines | |||
| 1833 | int i, int j, int width, int height, | 1838 | int i, int j, int width, int height, |
| 1834 | float *vec) | 1839 | float *vec) |
| 1835 | { | 1840 | { |
| 1836 | const float x = ((2.f * i + 1.f) / width - 1.f) * s->flat_range[0]; | 1841 | const float x = rescale(i, width) * s->flat_range[0]; |
| 1837 | const float y = ((2.f * j + 1.f) / height - 1.f) * s->flat_range[1]; | 1842 | const float y = rescale(j, height) * s->flat_range[1]; |
| 1838 | const float r = hypotf(x, y); | 1843 | const float r = hypotf(x, y); |
| 1839 | const float theta = atanf(r) * 2.f; | 1844 | const float theta = atanf(r) * 2.f; |
| 1840 | const float sin_theta = sinf(theta); | 1845 | const float sin_theta = sinf(theta); |
| @@ -1939,8 +1944,8 @@ static int equisolid_to_xyz(const V360Context *s, · 98 unmodified lines | |||
| 1939 | int i, int j, int width, int height, | 1944 | int i, int j, int width, int height, |
| 1940 | float *vec) | 1945 | float *vec) |
| 1941 | { | 1946 | { |
| 1942 | const float x = ((2.f * i + 1.f) / width - 1.f) * s->flat_range[0]; | 1947 | const float x = rescale(i, width) * s->flat_range[0]; |
| 1943 | const float y = ((2.f * j + 1.f) / height - 1.f) * s->flat_range[1]; | 1948 | const float y = rescale(j, height) * s->flat_range[1]; |
| 1944 | const float r = hypotf(x, y); | 1949 | const float r = hypotf(x, y); |
| 1945 | const float theta = asinf(r) * 2.f; | 1950 | const float theta = asinf(r) * 2.f; |
| 1946 | const float sin_theta = sinf(theta); | 1951 | const float sin_theta = sinf(theta); |
| @@ -2045,8 +2050,8 @@ static int orthographic_to_xyz(const V360Context *s, · 98 unmodified lines | |||
| 2045 | int i, int j, int width, int height, | 2050 | int i, int j, int width, int height, |
| 2046 | float *vec) | 2051 | float *vec) |
| 2047 | { | 2052 | { |
| 2048 | const float x = ((2.f * i + 1.f) / width - 1.f) * s->flat_range[0]; | 2053 | const float x = rescale(i, width) * s->flat_range[0]; |
| 2049 | const float y = ((2.f * j + 1.f) / height - 1.f) * s->flat_range[1]; | 2054 | const float y = rescale(j, height) * s->flat_range[1]; |
| 2050 | const float r = hypotf(x, y); | 2055 | const float r = hypotf(x, y); |
| 2051 | const float theta = asinf(r); | 2056 | const float theta = asinf(r); |
| 2052 | 2057 | ||
| @@ -2155,8 +2160,8 @@ static int xyz_to_equirect(const V360Context *s, · 102 unmodified lines | |||
| 2155 | const float phi = atan2f(vec[0], vec[2]); | 2160 | const float phi = atan2f(vec[0], vec[2]); |
| 2156 | const float theta = asinf(vec[1]); | 2161 | const float theta = asinf(vec[1]); |
| 2157 | 2162 | ||
| 2158 | const float uf = (phi / s->iflat_range[0] + 1.f) * width / 2.f; | 2163 | const float uf = (phi / s->iflat_range[0] + 1.f) * width / 2.f - 0.5f; |
| 2159 | const float vf = (theta / s->iflat_range[1] + 1.f) * height / 2.f; | 2164 | const float vf = (theta / s->iflat_range[1] + 1.f) * height / 2.f - 0.5f; |
| 2160 | 2165 | ||
| 2161 | const int ui = floorf(uf); | 2166 | const int ui = floorf(uf); |
| 2162 | const int vi = floorf(vf); | 2167 | const int vi = floorf(vf); |
| @@ -2333,8 +2338,8 @@ static int mercator_to_xyz(const V360Context *s, · 170 unmodified lines | |||
| 2333 | int i, int j, int width, int height, | 2338 | int i, int j, int width, int height, |
| 2334 | float *vec) | 2339 | float *vec) |
| 2335 | { | 2340 | { |
| 2336 | const float phi = ((2.f * i + 1.f) / width - 1.f) * M_PI + M_PI_2; | 2341 | const float phi = rescale(i, width) * M_PI + M_PI_2; |
| 2337 | const float y = ((2.f * j + 1.f) / height - 1.f) * M_PI; | 2342 | const float y = rescale(j, height) * M_PI; |
| 2338 | const float div = expf(2.f * y) + 1.f; | 2343 | const float div = expf(2.f * y) + 1.f; |
| 2339 | 2344 | ||
| 2340 | const float sin_phi = sinf(phi); | 2345 | const float sin_phi = sinf(phi); |
| @@ -2401,8 +2406,8 @@ static int ball_to_xyz(const V360Context *s, · 60 unmodified lines | |||
| 2401 | int i, int j, int width, int height, | 2406 | int i, int j, int width, int height, |
| 2402 | float *vec) | 2407 | float *vec) |
| 2403 | { | 2408 | { |
| 2404 | const float x = (2.f * i + 1.f) / width - 1.f; | 2409 | const float x = rescale(i, width); |
| 2405 | const float y = (2.f * j + 1.f) / height - 1.f; | 2410 | const float y = rescale(j, height); |
| 2406 | const float l = hypotf(x, y); | 2411 | const float l = hypotf(x, y); |
| 2407 | 2412 | ||
| 2408 | if (l <= 1.f) { | 2413 | if (l <= 1.f) { |
| @@ -2435,8 +2440,8 @@ static int hammer_to_xyz(const V360Context *s, · 26 unmodified lines | |||
| 2435 | int i, int j, int width, int height, | 2440 | int i, int j, int width, int height, |
| 2436 | float *vec) | 2441 | float *vec) |
| 2437 | { | 2442 | { |
| 2438 | const float x = ((2.f * i + 1.f) / width - 1.f); | 2443 | const float x = rescale(i, width); |
| 2439 | const float y = ((2.f * j + 1.f) / height - 1.f); | 2444 | const float y = rescale(j, height); |
| 2440 | 2445 | ||
| 2441 | const float xx = x * x; | 2446 | const float xx = x * x; |
| 2442 | const float yy = y * y; | 2447 | const float yy = y * y; |
| @@ -2515,8 +2520,8 @@ static int sinusoidal_to_xyz(const V360Context *s, · 72 unmodified lines | |||
| 2515 | int i, int j, int width, int height, | 2520 | int i, int j, int width, int height, |
| 2516 | float *vec) | 2521 | float *vec) |
| 2517 | { | 2522 | { |
| 2518 | const float theta = ((2.f * j + 1.f) / height - 1.f) * M_PI_2; | 2523 | const float theta = rescale(j, height) * M_PI_2; |
| 2519 | const float phi = ((2.f * i + 1.f) / width - 1.f) * M_PI / cosf(theta); | 2524 | const float phi = rescale(i, width) * M_PI / cosf(theta); |
| 2520 | 2525 | ||
| 2521 | const float sin_phi = sinf(phi); | 2526 | const float sin_phi = sinf(phi); |
| 2522 | const float cos_phi = cosf(phi); | 2527 | const float cos_phi = cosf(phi); |
| @@ -2820,8 +2825,8 @@ static int flat_to_xyz(const V360Context *s, · 297 unmodified lines | |||
| 2820 | int i, int j, int width, int height, | 2825 | int i, int j, int width, int height, |
| 2821 | float *vec) | 2826 | float *vec) |
| 2822 | { | 2827 | { |
| 2823 | const float l_x = s->flat_range[0] * ((2.f * i + 0.5f) / width - 1.f); | 2828 | const float l_x = s->flat_range[0] * rescale(i, width); |
| 2824 | const float l_y = s->flat_range[1] * ((2.f * j + 0.5f) / height - 1.f); | 2829 | const float l_y = s->flat_range[1] * rescale(j, height); |
| 2825 | 2830 | ||
| 2826 | vec[0] = l_x; | 2831 | vec[0] = l_x; |
| 2827 | vec[1] = l_y; | 2832 | vec[1] = l_y; |
| @@ -2863,8 +2868,8 @@ static int fisheye_to_xyz(const V360Context *s, · 35 unmodified lines | |||
| 2863 | int i, int j, int width, int height, | 2868 | int i, int j, int width, int height, |
| 2864 | float *vec) | 2869 | float *vec) |
| 2865 | { | 2870 | { |
| 2866 | const float uf = s->flat_range[0] * ((2.f * i) / width - 1.f); | 2871 | const float uf = s->flat_range[0] * rescale(i, width); |
| 2867 | const float vf = s->flat_range[1] * ((2.f * j + 1.f) / height - 1.f); | 2872 | const float vf = s->flat_range[1] * rescale(j, height); |
| 2868 | 2873 | ||
| 2869 | const float phi = atan2f(vf, uf); | 2874 | const float phi = atan2f(vf, uf); |
| 2870 | const float theta = M_PI_2 * (1.f - hypotf(uf, vf)); | 2875 | 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 | |||
| 2959 | int i, int j, int width, int height, | 2964 | int i, int j, int width, int height, |
| 2960 | float *vec) | 2965 | float *vec) |
| 2961 | { | 2966 | { |
| 2962 | const float uf = ((2.f * i + 1.f) / width - 1.f); | 2967 | const float uf = rescale(i, width); |
| 2963 | const float vf = ((2.f * j + 1.f) / height - 1.f); | 2968 | const float vf = rescale(j, height); |
| 2964 | 2969 | ||
| 2965 | const float d = s->h_fov; | 2970 | const float d = s->h_fov; |
| 2966 | const float k = uf * uf / ((d + 1.f) * (d + 1.f)); | 2971 | 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 | |||
| 3004 | const float x = S * sinf(phi); | 3009 | const float x = S * sinf(phi); |
| 3005 | const float y = S * tanf(theta); | 3010 | const float y = S * tanf(theta); |
| 3006 | 3011 | ||
| 3007 | const float uf = (x + 1.f) * width / 2.f; | 3012 | const float uf = (x + 1.f) * width / 2.f - 0.5f; |
| 3008 | const float vf = (y + 1.f) * height / 2.f; | 3013 | const float vf = (y + 1.f) * height / 2.f - 0.5f; |
| 3009 | 3014 | ||
| 3010 | const int ui = floorf(uf); | 3015 | const int ui = floorf(uf); |
| 3011 | const int vi = floorf(vf); | 3016 | const int vi = floorf(vf); |
| @@ -3056,8 +3061,8 @@ static int cylindrical_to_xyz(const V360Context *s, · 44 unmodified lines | |||
| 3056 | int i, int j, int width, int height, | 3061 | int i, int j, int width, int height, |
| 3057 | float *vec) | 3062 | float *vec) |
| 3058 | { | 3063 | { |
| 3059 | const float uf = s->flat_range[0] * ((2.f * i + 1.f) / width - 1.f); | 3064 | const float uf = s->flat_range[0] * rescale(i, width); |
| 3060 | const float vf = s->flat_range[1] * ((2.f * j + 1.f) / height - 1.f); | 3065 | const float vf = s->flat_range[1] * rescale(j, height); |
| 3061 | 3066 | ||
| 3062 | const float phi = uf; | 3067 | const float phi = uf; |
| 3063 | const float theta = atanf(vf); | 3068 | const float theta = atanf(vf); |
| @@ -3183,8 +3188,8 @@ static int cylindricalea_to_xyz(const V360Context *s, · 119 unmodified lines | |||
| 3183 | int i, int j, int width, int height, | 3188 | int i, int j, int width, int height, |
| 3184 | float *vec) | 3189 | float *vec) |
| 3185 | { | 3190 | { |
| 3186 | const float uf = s->flat_range[0] * ((2.f * i + 1.f) / width - 1.f); | 3191 | const float uf = s->flat_range[0] * rescale(i, width); |
| 3187 | const float vf = s->flat_range[1] * ((2.f * j + 1.f) / height - 1.f); | 3192 | const float vf = s->flat_range[1] * rescale(j, height); |
| 3188 | 3193 | ||
| 3189 | const float phi = uf; | 3194 | const float phi = uf; |
| 3190 | const float theta = asinf(vf); | 3195 | const float theta = asinf(vf); |
| @@ -3259,8 +3264,8 @@ static int perspective_to_xyz(const V360Context *s, · 68 unmodified lines | |||
| 3259 | int i, int j, int width, int height, | 3264 | int i, int j, int width, int height, |
| 3260 | float *vec) | 3265 | float *vec) |
| 3261 | { | 3266 | { |
| 3262 | const float uf = ((2.f * i + 1.f) / width - 1.f); | 3267 | const float uf = rescale(i, width); |
| 3263 | const float vf = ((2.f * j + 1.f) / height - 1.f); | 3268 | const float vf = rescale(j, height); |
| 3264 | const float rh = hypotf(uf, vf); | 3269 | const float rh = hypotf(uf, vf); |
| 3265 | const float sinzz = 1.f - rh * rh; | 3270 | const float sinzz = 1.f - rh * rh; |
| 3266 | const float h = 1.f + s->v_fov; | 3271 | const float h = 1.f + s->v_fov; |
| @@ -3305,8 +3310,8 @@ static int tetrahedron_to_xyz(const V360Context *s, · 38 unmodified lines | |||
| 3305 | int i, int j, int width, int height, | 3310 | int i, int j, int width, int height, |
| 3306 | float *vec) | 3311 | float *vec) |
| 3307 | { | 3312 | { |
| 3308 | const float uf = (float)i / width; | 3313 | const float uf = ((float)i + 0.5f) / width; |
| 3309 | const float vf = (float)j / height; | 3314 | const float vf = ((float)j + 0.5f) / height; |
| 3310 | 3315 | ||
| 3311 | vec[0] = uf < 0.5f ? uf * 4.f - 1.f : 3.f - uf * 4.f; | 3316 | vec[0] = uf < 0.5f ? uf * 4.f - 1.f : 3.f - uf * 4.f; |
| 3312 | vec[1] = 1.f - vf * 2.f; | 3317 | vec[1] = 1.f - vf * 2.f; |
| @@ -3394,8 +3399,8 @@ static int dfisheye_to_xyz(const V360Context *s, · 81 unmodified lines | |||
| 3394 | const int ei = i >= ew ? i - ew : i; | 3399 | const int ei = i >= ew ? i - ew : i; |
| 3395 | const float m = i >= ew ? 1.f : -1.f; | 3400 | const float m = i >= ew ? 1.f : -1.f; |
| 3396 | 3401 | ||
| 3397 | const float uf = s->flat_range[0] * ((2.f * ei) / ew - 1.f); | 3402 | const float uf = s->flat_range[0] * rescale(ei, ew); |
| 3398 | const float vf = s->flat_range[1] * ((2.f * j + 1.f) / eh - 1.f); | 3403 | const float vf = s->flat_range[1] * rescale(j, eh); |
| 3399 | 3404 | ||
| 3400 | const float h = hypotf(uf, vf); | 3405 | const float h = hypotf(uf, vf); |
| 3401 | const float lh = h > 0.f ? h : 1.f; | 3406 | const float lh = h > 0.f ? h : 1.f; |
| @@ -3488,8 +3493,8 @@ static int barrel_to_xyz(const V360Context *s, · 86 unmodified lines | |||
| 3488 | const int ew = 4 * width / 5; | 3493 | const int ew = 4 * width / 5; |
| 3489 | const int eh = height; | 3494 | const int eh = height; |
| 3490 | 3495 | ||
| 3491 | const float phi = ((2.f * i) / ew - 1.f) * M_PI / scale; | 3496 | const float phi = rescale(i, ew) * M_PI / scale; |
| 3492 | const float theta = ((2.f * j) / eh - 1.f) * theta_range / scale; | 3497 | const float theta = rescale(j, eh) * theta_range / scale; |
| 3493 | 3498 | ||
| 3494 | const float sin_phi = sinf(phi); | 3499 | const float sin_phi = sinf(phi); |
| 3495 | const float cos_phi = cosf(phi); | 3500 | const float cos_phi = cosf(phi); |
| @@ -3506,8 +3511,8 @@ static int barrel_to_xyz(const V360Context *s, · 10 unmodified lines | |||
| 3506 | float uf, vf; | 3511 | float uf, vf; |
| 3507 | 3512 | ||
| 3508 | if (j < eh) { // UP | 3513 | if (j < eh) { // UP |
| 3509 | uf = 2.f * (i - 4 * ew) / ew - 1.f; | 3514 | uf = rescale(i - 4 * ew, ew); |
| 3510 | vf = 2.f * (j ) / eh - 1.f; | 3515 | vf = rescale(j, eh); |
| 3511 | 3516 | ||
| 3512 | uf /= scale; | 3517 | uf /= scale; |
| 3513 | vf /= scale; | 3518 | vf /= scale; |
| @@ -3516,8 +3521,8 @@ static int barrel_to_xyz(const V360Context *s, · 2 unmodified lines | |||
| 3516 | l_y = -1.f; | 3521 | l_y = -1.f; |
| 3517 | l_z = vf; | 3522 | l_z = vf; |
| 3518 | } else { // DOWN | 3523 | } else { // DOWN |
| 3519 | uf = 2.f * (i - 4 * ew) / ew - 1.f; | 3524 | uf = rescale(i - 4 * ew, ew); |
| 3520 | vf = 2.f * (j - eh) / eh - 1.f; | 3525 | vf = rescale(j - eh, eh); |
| 3521 | 3526 | ||
| 3522 | uf /= scale; | 3527 | uf /= scale; |
| 3523 | vf /= scale; | 3528 | vf /= scale; |
| @@ -3937,8 +3942,8 @@ static int octahedron_to_xyz(const V360Context *s, · 413 unmodified lines | |||
| 3937 | int i, int j, int width, int height, | 3942 | int i, int j, int width, int height, |
| 3938 | float *vec) | 3943 | float *vec) |
| 3939 | { | 3944 | { |
| 3940 | const float x = ((i + 0.5f) / width) * 2.f - 1.f; | 3945 | const float x = rescale(i, width); |
| 3941 | const float y = ((j + 0.5f) / height) * 2.f - 1.f; | 3946 | const float y = rescale(j, height); |
| 3942 | const float ax = fabsf(x); | 3947 | const float ax = fabsf(x); |
| 3943 | const float ay = fabsf(y); | 3948 | const float ay = fabsf(y); |
| 3944 | 3949 | ||