Showing the changes to libavfilter (2 of 3 files). Show all
Unified · Split
| @@ -70,20 +70,29 @@ enum Rotation { · 69 unmodified lines | ||
| 70 | 70 | NB_ROTATIONS, |
| 71 | 71 | }; |
| 72 | 72 | |
| 73 | +enum RotationOrder { | |
| 74 | + YAW, | |
| 75 | + PITCH, | |
| 76 | + ROLL, | |
| 77 | + NB_RORDERS, | |
| 78 | +}; | |
| 79 | + | |
| 73 | 80 | typedef struct V360Context { |
| 74 | 81 | const AVClass *class; |
| 75 | 82 | int in, out; |
| 76 | 83 | int interp; |
| 77 | 84 | int width, height; |
| 78 | − char* in_forder; | |
| 79 | − char* out_forder; | |
| 80 | − char* in_frot; | |
| 81 | − char* out_frot; | |
| 85 | + char *in_forder; | |
| 86 | + char *out_forder; | |
| 87 | + char *in_frot; | |
| 88 | + char *out_frot; | |
| 89 | + char *rorder; | |
| 82 | 90 | |
| 83 | 91 | int in_cubemap_face_order[6]; |
| 84 | 92 | int out_cubemap_direction_order[6]; |
| 85 | 93 | int in_cubemap_face_rotation[6]; |
| 86 | 94 | int out_cubemap_face_rotation[6]; |
| 95 | + int rotation_order[3]; | |
| 87 | 96 | |
| 88 | 97 | float in_pad, out_pad; |
| 89 | 98 | |
| @@ -90,6 +90,7 @@ static const AVOption v360_options[] = { · 89 unmodified lines | ||
| 90 | 90 | { "yaw", "yaw rotation", OFFSET(yaw), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "yaw"}, |
| 91 | 91 | { "pitch", "pitch rotation", OFFSET(pitch), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "pitch"}, |
| 92 | 92 | { "roll", "roll rotation", OFFSET(roll), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "roll"}, |
| 93 | + { "rorder", "rotation order", OFFSET(rorder), AV_OPT_TYPE_STRING, {.str="ypr"}, 0, 0, FLAGS, "rorder"}, | |
| 93 | 94 | { "h_fov", "horizontal field of view", OFFSET(h_fov), AV_OPT_TYPE_FLOAT, {.dbl=90.f}, 0.f, 180.f, FLAGS, "h_fov"}, |
| 94 | 95 | { "v_fov", "vertical field of view", OFFSET(v_fov), AV_OPT_TYPE_FLOAT, {.dbl=45.f}, 0.f, 90.f, FLAGS, "v_fov"}, |
| 95 | 96 | { "h_flip", "flip video horizontally", OFFSET(h_flip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS, "h_flip"}, |
| @@ -499,6 +500,26 @@ static int get_rotation(char c) · 403 unmodified lines | ||
| 499 | 500 | } |
| 500 | 501 | } |
| 501 | 502 | |
| 503 | +/** | |
| 504 | + * Convert char to corresponding rotation order. | |
| 505 | + */ | |
| 506 | +static int get_rorder(char c) | |
| 507 | +{ | |
| 508 | + switch (c) { | |
| 509 | + case 'Y': | |
| 510 | + case 'y': | |
| 511 | + return YAW; | |
| 512 | + case 'P': | |
| 513 | + case 'p': | |
| 514 | + return PITCH; | |
| 515 | + case 'R': | |
| 516 | + case 'r': | |
| 517 | + return ROLL; | |
| 518 | + default: | |
| 519 | + return -1; | |
| 520 | + } | |
| 521 | +} | |
| 522 | + | |
| 502 | 523 | /** |
| 503 | 524 | * Prepare data for processing cubemap input format. |
| 504 | 525 | * |
| @@ -1849,11 +1870,26 @@ static void xyz_to_barrel(const V360Context *s, · 1344 unmodified lines | ||
| 1849 | 1870 | |
| 1850 | 1871 | } |
| 1851 | 1872 | |
| 1873 | +static void multiply_matrix(float c[3][3], const float a[3][3], const float b[3][3]) | |
| 1874 | +{ | |
| 1875 | + for (int i = 0; i < 3; i++) { | |
| 1876 | + for (int j = 0; j < 3; j++) { | |
| 1877 | + float sum = 0; | |
| 1878 | + | |
| 1879 | + for (int k = 0; k < 3; k++) | |
| 1880 | + sum += a[i][k] * b[k][j]; | |
| 1881 | + | |
| 1882 | + c[i][j] = sum; | |
| 1883 | + } | |
| 1884 | + } | |
| 1885 | +} | |
| 1886 | + | |
| 1852 | 1887 | /** |
| 1853 | 1888 | * Calculate rotation matrix for yaw/pitch/roll angles. |
| 1854 | 1889 | */ |
| 1855 | 1890 | static inline void calculate_rotation_matrix(float yaw, float pitch, float roll, |
| 1856 | − float rot_mat[3][3]) | |
| 1891 | + float rot_mat[3][3], | |
| 1892 | + const int rotation_order[3]) | |
| 1857 | 1893 | { |
| 1858 | 1894 | const float yaw_rad = yaw * M_PI / 180.f; |
| 1859 | 1895 | const float pitch_rad = pitch * M_PI / 180.f; |
| @@ -1866,17 +1902,23 @@ static inline void calculate_rotation_matrix(float yaw, float pitch, float roll, · 6 unmodified lines | ||
| 1866 | 1902 | const float sin_roll = sinf(roll_rad); |
| 1867 | 1903 | const float cos_roll = cosf(roll_rad); |
| 1868 | 1904 | |
| 1869 | − rot_mat[0][0] = sin_yaw * sin_pitch * sin_roll + cos_yaw * cos_roll; | |
| 1870 | − rot_mat[0][1] = sin_yaw * sin_pitch * cos_roll - cos_yaw * sin_roll; | |
| 1871 | − rot_mat[0][2] = sin_yaw * cos_pitch; | |
| 1905 | + float m[3][3][3]; | |
| 1906 | + float temp[3][3]; | |
| 1907 | + | |
| 1908 | + m[0][0][0] = cos_yaw; m[0][0][1] = 0; m[0][0][2] = sin_yaw; | |
| 1909 | + m[0][1][0] = 0; m[0][1][1] = 1; m[0][1][2] = 0; | |
| 1910 | + m[0][2][0] = -sin_yaw; m[0][2][1] = 0; m[0][2][2] = cos_yaw; | |
| 1872 | 1911 | |
| 1873 | − rot_mat[1][0] = cos_pitch * sin_roll; | |
| 1874 | − rot_mat[1][1] = cos_pitch * cos_roll; | |
| 1875 | − rot_mat[1][2] = -sin_pitch; | |
| 1912 | + m[1][0][0] = 1; m[1][0][1] = 0; m[1][0][2] = 0; | |
| 1913 | + m[1][1][0] = 0; m[1][1][1] = cos_pitch; m[1][1][2] = -sin_pitch; | |
| 1914 | + m[1][2][0] = 0; m[1][2][1] = sin_pitch; m[1][2][2] = cos_pitch; | |
| 1876 | 1915 | |
| 1877 | − rot_mat[2][0] = cos_yaw * sin_pitch * sin_roll - sin_yaw * cos_roll; | |
| 1878 | − rot_mat[2][1] = cos_yaw * sin_pitch * cos_roll + sin_yaw * sin_roll; | |
| 1879 | − rot_mat[2][2] = cos_yaw * cos_pitch; | |
| 1916 | + m[2][0][0] = cos_roll; m[2][0][1] = -sin_roll; m[2][0][2] = 0; | |
| 1917 | + m[2][1][0] = sin_roll; m[2][1][1] = cos_roll; m[2][1][2] = 0; | |
| 1918 | + m[2][2][0] = 0; m[2][2][1] = 0; m[2][2][2] = 1; | |
| 1919 | + | |
| 1920 | + multiply_matrix(temp, m[rotation_order[0]], m[rotation_order[1]]); | |
| 1921 | + multiply_matrix(rot_mat, temp, m[rotation_order[2]]); | |
| 1880 | 1922 | } |
| 1881 | 1923 | |
| 1882 | 1924 | /** |
| @@ -1986,6 +2028,26 @@ static int config_output(AVFilterLink *outlink) · 103 unmodified lines | ||
| 1986 | 2028 | |
| 1987 | 2029 | ff_v360_init(s, depth); |
| 1988 | 2030 | |
| 2031 | + for (int order = 0; order < NB_RORDERS; order++) { | |
| 2032 | + const char c = s->rorder[order]; | |
| 2033 | + int rorder; | |
| 2034 | + | |
| 2035 | + if (c == '\0') { | |
| 2036 | + av_log(ctx, AV_LOG_ERROR, | |
| 2037 | + "Incomplete rorder option. Direction for all 3 rotation orders should be specified.\n"); | |
| 2038 | + return AVERROR(EINVAL); | |
| 2039 | + } | |
| 2040 | + | |
| 2041 | + rorder = get_rorder(c); | |
| 2042 | + if (rorder == -1) { | |
| 2043 | + av_log(ctx, AV_LOG_ERROR, | |
| 2044 | + "Incorrect rotation order symbol '%c' in rorder option.\n", c); | |
| 2045 | + return AVERROR(EINVAL); | |
| 2046 | + } | |
| 2047 | + | |
| 2048 | + s->rotation_order[order] = rorder; | |
| 2049 | + } | |
| 2050 | + | |
| 1989 | 2051 | switch (s->in) { |
| 1990 | 2052 | case EQUIRECTANGULAR: |
| 1991 | 2053 | in_transform = xyz_to_equirect; |
| @@ -2141,7 +2203,7 @@ static int config_output(AVFilterLink *outlink) · 149 unmodified lines | ||
| 2141 | 2203 | allocate_plane(s, sizeof_uv, sizeof_ker, 2); |
| 2142 | 2204 | } |
| 2143 | 2205 | |
| 2144 | − calculate_rotation_matrix(s->yaw, s->pitch, s->roll, rot_mat); | |
| 2206 | + calculate_rotation_matrix(s->yaw, s->pitch, s->roll, rot_mat, s->rotation_order); | |
| 2145 | 2207 | set_mirror_modifier(s->h_flip, s->v_flip, s->d_flip, mirror_modifier); |
| 2146 | 2208 | |
| 2147 | 2209 | // Calculate remap data |