Unified · Split
| @@ -1373,6 +1373,11 @@ static void process_cube_coordinates(const V360Context *s, · 1372 unmodified lines | ||
| 1373 | 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 | 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 | 1407 | const int ewi = ceilf(ew * (u_face + 1)) - u_shift; |
| 1403 | 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; | |
| 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); | |
| 1407 | 1412 | |
| 1408 | 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 | 1531 | const int v_shift = ceilf(eh * face); |
| 1527 | 1532 | const int ehi = ceilf(eh * (face + 1)) - v_shift; |
| 1528 | 1533 | |
| 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); | |
| 1531 | 1536 | |
| 1532 | 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 | 1564 | const int u_shift = ceilf(ew * face); |
| 1560 | 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; | |
| 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); | |
| 1564 | 1569 | |
| 1565 | 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 | 1763 | int i, int j, int width, int height, |
| 1759 | 1764 | float *vec) |
| 1760 | 1765 | { |
| 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]; | |
| 1763 | 1768 | |
| 1764 | 1769 | const float sin_phi = sinf(phi); |
| 1765 | 1770 | const float cos_phi = cosf(phi); |
| @@ -1787,8 +1792,8 @@ static int hequirect_to_xyz(const V360Context *s, · 21 unmodified lines | ||
| 1787 | 1792 | int i, int j, int width, int height, |
| 1788 | 1793 | float *vec) |
| 1789 | 1794 | { |
| 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; | |
| 1792 | 1797 | |
| 1793 | 1798 | const float sin_phi = sinf(phi); |
| 1794 | 1799 | const float cos_phi = cosf(phi); |
| @@ -1833,8 +1838,8 @@ static int stereographic_to_xyz(const V360Context *s, · 38 unmodified lines | ||
| 1833 | 1838 | int i, int j, int width, int height, |
| 1834 | 1839 | float *vec) |
| 1835 | 1840 | { |
| 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]; | |
| 1838 | 1843 | const float r = hypotf(x, y); |
| 1839 | 1844 | const float theta = atanf(r) * 2.f; |
| 1840 | 1845 | const float sin_theta = sinf(theta); |
| @@ -1939,8 +1944,8 @@ static int equisolid_to_xyz(const V360Context *s, · 98 unmodified lines | ||
| 1939 | 1944 | int i, int j, int width, int height, |
| 1940 | 1945 | float *vec) |
| 1941 | 1946 | { |
| 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]; | |
| 1944 | 1949 | const float r = hypotf(x, y); |
| 1945 | 1950 | const float theta = asinf(r) * 2.f; |
| 1946 | 1951 | const float sin_theta = sinf(theta); |
| @@ -2045,8 +2050,8 @@ static int orthographic_to_xyz(const V360Context *s, · 98 unmodified lines | ||
| 2045 | 2050 | int i, int j, int width, int height, |
| 2046 | 2051 | float *vec) |
| 2047 | 2052 | { |
| 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]; | |
| 2050 | 2055 | const float r = hypotf(x, y); |
| 2051 | 2056 | const float theta = asinf(r); |
| 2052 | 2057 | |
| @@ -2155,8 +2160,8 @@ static int xyz_to_equirect(const V360Context *s, · 102 unmodified lines | ||
| 2155 | 2160 | const float phi = atan2f(vec[0], vec[2]); |
| 2156 | 2161 | const float theta = asinf(vec[1]); |
| 2157 | 2162 | |
| 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; | |
| 2160 | 2165 | |
| 2161 | 2166 | const int ui = floorf(uf); |
| 2162 | 2167 | const int vi = floorf(vf); |
| @@ -2333,8 +2338,8 @@ static int mercator_to_xyz(const V360Context *s, · 170 unmodified lines | ||
| 2333 | 2338 | int i, int j, int width, int height, |
| 2334 | 2339 | float *vec) |
| 2335 | 2340 | { |
| 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; | |
| 2338 | 2343 | const float div = expf(2.f * y) + 1.f; |
| 2339 | 2344 | |
| 2340 | 2345 | const float sin_phi = sinf(phi); |
| @@ -2401,8 +2406,8 @@ static int ball_to_xyz(const V360Context *s, · 60 unmodified lines | ||
| 2401 | 2406 | int i, int j, int width, int height, |
| 2402 | 2407 | float *vec) |
| 2403 | 2408 | { |
| 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); | |
| 2406 | 2411 | const float l = hypotf(x, y); |
| 2407 | 2412 | |
| 2408 | 2413 | if (l <= 1.f) { |
| @@ -2435,8 +2440,8 @@ static int hammer_to_xyz(const V360Context *s, · 26 unmodified lines | ||
| 2435 | 2440 | int i, int j, int width, int height, |
| 2436 | 2441 | float *vec) |
| 2437 | 2442 | { |
| 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); | |
| 2440 | 2445 | |
| 2441 | 2446 | const float xx = x * x; |
| 2442 | 2447 | const float yy = y * y; |
| @@ -2515,8 +2520,8 @@ static int sinusoidal_to_xyz(const V360Context *s, · 72 unmodified lines | ||
| 2515 | 2520 | int i, int j, int width, int height, |
| 2516 | 2521 | float *vec) |
| 2517 | 2522 | { |
| 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); | |
| 2520 | 2525 | |
| 2521 | 2526 | const float sin_phi = sinf(phi); |
| 2522 | 2527 | const float cos_phi = cosf(phi); |
| @@ -2820,8 +2825,8 @@ static int flat_to_xyz(const V360Context *s, · 297 unmodified lines | ||
| 2820 | 2825 | int i, int j, int width, int height, |
| 2821 | 2826 | float *vec) |
| 2822 | 2827 | { |
| 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); | |
| 2825 | 2830 | |
| 2826 | 2831 | vec[0] = l_x; |
| 2827 | 2832 | vec[1] = l_y; |
| @@ -2863,8 +2868,8 @@ static int fisheye_to_xyz(const V360Context *s, · 35 unmodified lines | ||
| 2863 | 2868 | int i, int j, int width, int height, |
| 2864 | 2869 | float *vec) |
| 2865 | 2870 | { |
| 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); | |
| 2868 | 2873 | |
| 2869 | 2874 | const float phi = atan2f(vf, uf); |
| 2870 | 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 | 2964 | int i, int j, int width, int height, |
| 2960 | 2965 | float *vec) |
| 2961 | 2966 | { |
| 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); | |
| 2964 | 2969 | |
| 2965 | 2970 | const float d = s->h_fov; |
| 2966 | 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 | 3009 | const float x = S * sinf(phi); |
| 3005 | 3010 | const float y = S * tanf(theta); |
| 3006 | 3011 | |
| 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; | |
| 3009 | 3014 | |
| 3010 | 3015 | const int ui = floorf(uf); |
| 3011 | 3016 | const int vi = floorf(vf); |
| @@ -3056,8 +3061,8 @@ static int cylindrical_to_xyz(const V360Context *s, · 44 unmodified lines | ||
| 3056 | 3061 | int i, int j, int width, int height, |
| 3057 | 3062 | float *vec) |
| 3058 | 3063 | { |
| 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); | |
| 3061 | 3066 | |
| 3062 | 3067 | const float phi = uf; |
| 3063 | 3068 | const float theta = atanf(vf); |
| @@ -3183,8 +3188,8 @@ static int cylindricalea_to_xyz(const V360Context *s, · 119 unmodified lines | ||
| 3183 | 3188 | int i, int j, int width, int height, |
| 3184 | 3189 | float *vec) |
| 3185 | 3190 | { |
| 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); | |
| 3188 | 3193 | |
| 3189 | 3194 | const float phi = uf; |
| 3190 | 3195 | const float theta = asinf(vf); |
| @@ -3259,8 +3264,8 @@ static int perspective_to_xyz(const V360Context *s, · 68 unmodified lines | ||
| 3259 | 3264 | int i, int j, int width, int height, |
| 3260 | 3265 | float *vec) |
| 3261 | 3266 | { |
| 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); | |
| 3264 | 3269 | const float rh = hypotf(uf, vf); |
| 3265 | 3270 | const float sinzz = 1.f - rh * rh; |
| 3266 | 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 | 3310 | int i, int j, int width, int height, |
| 3306 | 3311 | float *vec) |
| 3307 | 3312 | { |
| 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; | |
| 3310 | 3315 | |
| 3311 | 3316 | vec[0] = uf < 0.5f ? uf * 4.f - 1.f : 3.f - uf * 4.f; |
| 3312 | 3317 | vec[1] = 1.f - vf * 2.f; |
| @@ -3394,8 +3399,8 @@ static int dfisheye_to_xyz(const V360Context *s, · 81 unmodified lines | ||
| 3394 | 3399 | const int ei = i >= ew ? i - ew : i; |
| 3395 | 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); | |
| 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); | |
| 3399 | 3404 | |
| 3400 | 3405 | const float h = hypotf(uf, vf); |
| 3401 | 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 | 3493 | const int ew = 4 * width / 5; |
| 3489 | 3494 | const int eh = height; |
| 3490 | 3495 | |
| 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; | |
| 3493 | 3498 | |
| 3494 | 3499 | const float sin_phi = sinf(phi); |
| 3495 | 3500 | const float cos_phi = cosf(phi); |
| @@ -3506,8 +3511,8 @@ static int barrel_to_xyz(const V360Context *s, · 10 unmodified lines | ||
| 3506 | 3511 | float uf, vf; |
| 3507 | 3512 | |
| 3508 | 3513 | 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); | |
| 3511 | 3516 | |
| 3512 | 3517 | uf /= scale; |
| 3513 | 3518 | vf /= scale; |
| @@ -3516,8 +3521,8 @@ static int barrel_to_xyz(const V360Context *s, · 2 unmodified lines | ||
| 3516 | 3521 | l_y = -1.f; |
| 3517 | 3522 | l_z = vf; |
| 3518 | 3523 | } 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); | |
| 3521 | 3526 | |
| 3522 | 3527 | uf /= scale; |
| 3523 | 3528 | vf /= scale; |
| @@ -3937,8 +3942,8 @@ static int octahedron_to_xyz(const V360Context *s, · 413 unmodified lines | ||
| 3937 | 3942 | int i, int j, int width, int height, |
| 3938 | 3943 | float *vec) |
| 3939 | 3944 | { |
| 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); | |
| 3942 | 3947 | const float ax = fabsf(x); |
| 3943 | 3948 | const float ay = fabsf(y); |
| 3944 | 3949 | |