History

avfilter/vf_v360: add padding option for cubemap

Eugene Lyapustin committed 7 years ago

Commit d0442521 parent b26094e2 files · +93 −25Browse files

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

Unified · Split

libavfilter/vf_v360.c+77−23
@@ -102,6 +102,8 @@ typedef struct V360Context { · 101 unmodified lines
102 int in_cubemap_face_rotation[6];102 int in_cubemap_face_rotation[6];
103 int out_cubemap_face_rotation[6];103 int out_cubemap_face_rotation[6];
104 104
105 float in_pad, out_pad;
106
105 float yaw, pitch, roll;107 float yaw, pitch, roll;
106 108
107 int h_flip, v_flip, d_flip;109 int h_flip, v_flip, d_flip;
@@ -155,6 +157,8 @@ static const AVOption v360_options[] = { · 47 unmodified lines
155 {"out_forder", "output cubemap face order", OFFSET(out_forder), AV_OPT_TYPE_STRING, {.str="rludfb"}, 0, NB_DIRECTIONS-1, FLAGS, "out_forder"},157 {"out_forder", "output cubemap face order", OFFSET(out_forder), AV_OPT_TYPE_STRING, {.str="rludfb"}, 0, NB_DIRECTIONS-1, FLAGS, "out_forder"},
156 { "in_frot", "input cubemap face rotation", OFFSET(in_frot), AV_OPT_TYPE_STRING, {.str="000000"}, 0, NB_DIRECTIONS-1, FLAGS, "in_frot"},158 { "in_frot", "input cubemap face rotation", OFFSET(in_frot), AV_OPT_TYPE_STRING, {.str="000000"}, 0, NB_DIRECTIONS-1, FLAGS, "in_frot"},
157 { "out_frot", "output cubemap face rotation",OFFSET(out_frot), AV_OPT_TYPE_STRING, {.str="000000"}, 0, NB_DIRECTIONS-1, FLAGS, "out_frot"},159 { "out_frot", "output cubemap face rotation",OFFSET(out_frot), AV_OPT_TYPE_STRING, {.str="000000"}, 0, NB_DIRECTIONS-1, FLAGS, "out_frot"},
160 { "in_pad", "input cubemap pads", OFFSET(in_pad), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, 0.f, 1.f, FLAGS, "in_pad"},
161 { "out_pad", "output cubemap pads", OFFSET(out_pad), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, 0.f, 1.f, FLAGS, "out_pad"},
158 { "yaw", "yaw rotation", OFFSET(yaw), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "yaw"},162 { "yaw", "yaw rotation", OFFSET(yaw), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "yaw"},
159 { "pitch", "pitch rotation", OFFSET(pitch), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "pitch"},163 { "pitch", "pitch rotation", OFFSET(pitch), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "pitch"},
160 { "roll", "roll rotation", OFFSET(roll), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "roll"},164 { "roll", "roll rotation", OFFSET(roll), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180.f, 180.f, FLAGS, "roll"},
@@ -734,6 +738,9 @@ static void cube_to_xyz(const V360Context *s, · 573 unmodified lines
734 float norm;738 float norm;
735 float l_x, l_y, l_z;739 float l_x, l_y, l_z;
736 740
741 uf /= (1.f - s->out_pad);
742 vf /= (1.f - s->out_pad);
743
737 rotate_cube_face_inverse(&uf, &vf, s->out_cubemap_face_rotation[face]);744 rotate_cube_face_inverse(&uf, &vf, s->out_cubemap_face_rotation[face]);
738 745
739 switch (direction) {746 switch (direction) {
@@ -1091,6 +1098,9 @@ static void xyz_to_cube3x2(const V360Context *s, · 351 unmodified lines
1091 1098
1092 xyz_to_cube(s, vec, &uf, &vf, &direction);1099 xyz_to_cube(s, vec, &uf, &vf, &direction);
1093 1100
1101 uf *= (1.f - s->in_pad);
1102 vf *= (1.f - s->in_pad);
1103
1094 face = s->in_cubemap_face_order[direction];1104 face = s->in_cubemap_face_order[direction];
1095 u_face = face % 3;1105 u_face = face % 3;
1096 v_face = face / 3;1106 v_face = face / 3;
@@ -1108,22 +1118,44 @@ static void xyz_to_cube3x2(const V360Context *s, · 11 unmodified lines
1108 1118
1109 for (i = -1; i < 3; i++) {1119 for (i = -1; i < 3; i++) {
1110 for (j = -1; j < 3; j++) {1120 for (j = -1; j < 3; j++) {
1111 float u, v;1121 int new_ui = ui + j;
1122 int new_vi = vi + i;
1112 int u_shift, v_shift;1123 int u_shift, v_shift;
1113 int new_ewi, new_ehi;1124 int new_ewi, new_ehi;
1114 1125
1115 process_cube_coordinates(s, 2.f * (ui + j) / ewi - 1.f,1126 if (new_ui >= 0 && new_ui < ewi && new_vi >= 0 && new_vi < ehi) {
1116 2.f * (vi + i) / ehi - 1.f,1127 face = s->in_cubemap_face_order[direction];
1117 direction, &u, &v, &face);1128
1118 u_face = face % 3;1129 u_face = face % 3;
1119 v_face = face / 3;1130 v_face = face / 3;
1120 u_shift = ceilf(ew * u_face);1131 u_shift = ceilf(ew * u_face);
1121 v_shift = ceilf(eh * v_face);1132 v_shift = ceilf(eh * v_face);
1122 new_ewi = ceilf(ew * (u_face + 1)) - u_shift;1133 } else {
1123 new_ehi = ceilf(eh * (v_face + 1)) - v_shift;1134 uf = 2.f * new_ui / ewi - 1.f;
1124 1135 vf = 2.f * new_vi / ehi - 1.f;
1125 us[i + 1][j + 1] = u_shift + av_clip(roundf(0.5f * new_ewi * (u + 1.f)), 0, new_ewi - 1);1136
1126 vs[i + 1][j + 1] = v_shift + av_clip(roundf(0.5f * new_ehi * (v + 1.f)), 0, new_ehi - 1);1137 uf /= (1.f - s->in_pad);
1138 vf /= (1.f - s->in_pad);
1139
1140 process_cube_coordinates(s, uf, vf, direction, &uf, &vf, &face);
1141
1142 uf *= (1.f - s->in_pad);
1143 vf *= (1.f - s->in_pad);
1144
1145 u_face = face % 3;
1146 v_face = face / 3;
1147 u_shift = ceilf(ew * u_face);
1148 v_shift = ceilf(eh * v_face);
1149 new_ewi = ceilf(ew * (u_face + 1)) - u_shift;
1150 new_ehi = ceilf(eh * (v_face + 1)) - v_shift;
1151
1152 new_ui = av_clip(roundf(0.5f * new_ewi * (uf + 1.f)), 0, new_ewi - 1);
1153 new_vi = av_clip(roundf(0.5f * new_ehi * (vf + 1.f)), 0, new_ehi - 1);
1154 }
1155
1156
1157 us[i + 1][j + 1] = u_shift + new_ui;
1158 vs[i + 1][j + 1] = v_shift + new_vi;
1127 }1159 }
1128 }1160 }
1129}1161}
@@ -1173,7 +1205,7 @@ static void xyz_to_cube6x1(const V360Context *s, · 43 unmodified lines
1173 uint16_t us[4][4], uint16_t vs[4][4], float *du, float *dv)1205 uint16_t us[4][4], uint16_t vs[4][4], float *du, float *dv)
1174{1206{
1175 const float ew = width / 6.f;1207 const float ew = width / 6.f;
1176 const float eh = height;1208 const int ehi = height;
1177 float uf, vf;1209 float uf, vf;
1178 int ui, vi;1210 int ui, vi;
1179 int ewi;1211 int ewi;
@@ -1182,11 +1214,14 @@ static void xyz_to_cube6x1(const V360Context *s, · 2 unmodified lines
1182 1214
1183 xyz_to_cube(s, vec, &uf, &vf, &direction);1215 xyz_to_cube(s, vec, &uf, &vf, &direction);
1184 1216
1217 uf *= (1.f - s->in_pad);
1218 vf *= (1.f - s->in_pad);
1219
1185 face = s->in_cubemap_face_order[direction];1220 face = s->in_cubemap_face_order[direction];
1186 ewi = ceilf(ew * (face + 1)) - ceilf(ew * face);1221 ewi = ceilf(ew * (face + 1)) - ceilf(ew * face);
1187 1222
1188 uf = 0.5f * ewi * (uf + 1.f);1223 uf = 0.5f * ewi * (uf + 1.f);
1189 vf = 0.5f * eh * (vf + 1.f);1224 vf = 0.5f * ehi * (vf + 1.f);
1190 1225
1191 ui = floorf(uf);1226 ui = floorf(uf);
1192 vi = floorf(vf);1227 vi = floorf(vf);
@@ -1196,18 +1231,37 @@ static void xyz_to_cube6x1(const V360Context *s, · 3 unmodified lines
1196 1231
1197 for (i = -1; i < 3; i++) {1232 for (i = -1; i < 3; i++) {
1198 for (j = -1; j < 3; j++) {1233 for (j = -1; j < 3; j++) {
1199 float u, v;1234 int new_ui = ui + j;
1235 int new_vi = vi + i;
1200 int u_shift;1236 int u_shift;
1201 int new_ewi;1237 int new_ewi;
1202 1238
1203 process_cube_coordinates(s, 2.f * (ui + j) / ewi - 1.f,1239 if (new_ui >= 0 && new_ui < ewi && new_vi >= 0 && new_vi < ehi) {
1204 2.f * (vi + i) / eh - 1.f,1240 face = s->in_cubemap_face_order[direction];
1205 direction, &u, &v, &face);1241
1206 u_shift = ceilf(ew * face);1242 u_shift = ceilf(ew * face);
1207 new_ewi = ceilf(ew * (face + 1)) - u_shift;1243 } else {
1244 uf = 2.f * new_ui / ewi - 1.f;
1245 vf = 2.f * new_vi / ehi - 1.f;
1246
1247 uf /= (1.f - s->in_pad);
1248 vf /= (1.f - s->in_pad);
1249
1250 process_cube_coordinates(s, uf, vf, direction, &uf, &vf, &face);
1251
1252 uf *= (1.f - s->in_pad);
1253 vf *= (1.f - s->in_pad);
1254
1255 u_shift = ceilf(ew * face);
1256 new_ewi = ceilf(ew * (face + 1)) - u_shift;
1257
1258 new_ui = av_clip(roundf(0.5f * new_ewi * (uf + 1.f)), 0, new_ewi - 1);
1259 new_vi = av_clip(roundf(0.5f * ehi * (vf + 1.f)), 0, ehi - 1);
1260 }
1261
1208 1262
1209 us[i + 1][j + 1] = u_shift + av_clip(roundf(0.5f * new_ewi * (u + 1.f)), 0, new_ewi - 1);1263 us[i + 1][j + 1] = u_shift + new_ui;
1210 vs[i + 1][j + 1] = av_clip(roundf(0.5f * eh * (v + 1.f)), 0, eh - 1);1264 vs[i + 1][j + 1] = new_vi;
1211 }1265 }
1212 }1266 }
1213}1267}

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