History

avfilter/vf_v360: add option to pick rotation order

Paul B Mahol committed 7 years ago

Commit cb8c3531 parent d1315413 files · +100 −15Browse files

Showing the changes to libavfilter (2 of 3 files). Show all

Unified · Split

2 files
  1. libavfilter/v360.h +13 −4
  2. libavfilter/vf_v360.c +73 −11
libavfilter/v360.h+13−4
@@ -70,20 +70,29 @@ enum Rotation { · 69 unmodified lines
7070 NB_ROTATIONS,
7171 };
7272
73+enum RotationOrder {
74+ YAW,
75+ PITCH,
76+ ROLL,
77+ NB_RORDERS,
78+};
79+
7380 typedef struct V360Context {
7481 const AVClass *class;
7582 int in, out;
7683 int interp;
7784 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;
8290
8391 int in_cubemap_face_order[6];
8492 int out_cubemap_direction_order[6];
8593 int in_cubemap_face_rotation[6];
8694 int out_cubemap_face_rotation[6];
95+ int rotation_order[3];
8796
8897 float in_pad, out_pad;
8998
libavfilter/vf_v360.c+73−11
@@ -90,6 +90,7 @@ static const AVOption v360_options[] = { · 89 unmodified lines
9090 { "yaw", "yaw rotation", OFFSET(yaw), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "yaw"},
9191 { "pitch", "pitch rotation", OFFSET(pitch), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "pitch"},
9292 { "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"},
9394 { "h_fov", "horizontal field of view", OFFSET(h_fov), AV_OPT_TYPE_FLOAT, {.dbl=90.f}, 0.f, 180.f, FLAGS, "h_fov"},
9495 { "v_fov", "vertical field of view", OFFSET(v_fov), AV_OPT_TYPE_FLOAT, {.dbl=45.f}, 0.f, 90.f, FLAGS, "v_fov"},
9596 { "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
499500 }
500501 }
501502
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+
502523 /**
503524 * Prepare data for processing cubemap input format.
504525 *
@@ -1849,11 +1870,26 @@ static void xyz_to_barrel(const V360Context *s, · 1344 unmodified lines
18491870
18501871 }
18511872
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+
18521887 /**
18531888 * Calculate rotation matrix for yaw/pitch/roll angles.
18541889 */
18551890 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])
18571893 {
18581894 const float yaw_rad = yaw * M_PI / 180.f;
18591895 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
18661902 const float sin_roll = sinf(roll_rad);
18671903 const float cos_roll = cosf(roll_rad);
18681904
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;
18721911
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;
18761915
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]]);
18801922 }
18811923
18821924 /**
@@ -1986,6 +2028,26 @@ static int config_output(AVFilterLink *outlink) · 103 unmodified lines
19862028
19872029 ff_v360_init(s, depth);
19882030
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+
19892051 switch (s->in) {
19902052 case EQUIRECTANGULAR:
19912053 in_transform = xyz_to_equirect;
@@ -2141,7 +2203,7 @@ static int config_output(AVFilterLink *outlink) · 149 unmodified lines
21412203 allocate_plane(s, sizeof_uv, sizeof_ker, 2);
21422204 }
21432205
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);
21452207 set_mirror_modifier(s->h_flip, s->v_flip, s->d_flip, mirror_modifier);
21462208
21472209 // Calculate remap data

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