History

avfilter/vf_v360: define variables in for loops consistently

Paul B Mahol committed 7 years ago

Commit 2a672a91 parent f78abca1 file · +29 −44Browse files

Unified · Split

libavfilter/vf_v360.c+29−44
@@ -337,10 +337,8 @@ static void nearest_kernel(float du, float dv, const XYRemap *r_tmp, · 336 unmodified lines
337static void bilinear_kernel(float du, float dv, const XYRemap *r_tmp,337static void bilinear_kernel(float du, float dv, const XYRemap *r_tmp,
338 uint16_t *u, uint16_t *v, int16_t *ker)338 uint16_t *u, uint16_t *v, int16_t *ker)
339{339{
340 int i, j;340 for (int i = 0; i < 2; i++) {
341 341 for (int j = 0; j < 2; j++) {
342 for (i = 0; i < 2; i++) {
343 for (j = 0; j < 2; j++) {
344 u[i * 2 + j] = r_tmp->u[i + 1][j + 1];342 u[i * 2 + j] = r_tmp->u[i + 1][j + 1];
345 v[i * 2 + j] = r_tmp->v[i + 1][j + 1];343 v[i * 2 + j] = r_tmp->v[i + 1][j + 1];
346 }344 }
@@ -382,15 +380,14 @@ static inline void calculate_bicubic_coeffs(float t, float *coeffs) · 35 unmodified lines
382static void bicubic_kernel(float du, float dv, const XYRemap *r_tmp,380static void bicubic_kernel(float du, float dv, const XYRemap *r_tmp,
383 uint16_t *u, uint16_t *v, int16_t *ker)381 uint16_t *u, uint16_t *v, int16_t *ker)
384{382{
385 int i, j;
386 float du_coeffs[4];383 float du_coeffs[4];
387 float dv_coeffs[4];384 float dv_coeffs[4];
388 385
389 calculate_bicubic_coeffs(du, du_coeffs);386 calculate_bicubic_coeffs(du, du_coeffs);
390 calculate_bicubic_coeffs(dv, dv_coeffs);387 calculate_bicubic_coeffs(dv, dv_coeffs);
391 388
392 for (i = 0; i < 4; i++) {389 for (int i = 0; i < 4; i++) {
393 for (j = 0; j < 4; j++) {390 for (int j = 0; j < 4; j++) {
394 u[i * 4 + j] = r_tmp->u[i][j];391 u[i * 4 + j] = r_tmp->u[i][j];
395 v[i * 4 + j] = r_tmp->v[i][j];392 v[i * 4 + j] = r_tmp->v[i][j];
396 ker[i * 4 + j] = du_coeffs[j] * dv_coeffs[i] * 16384;393 ker[i * 4 + j] = du_coeffs[j] * dv_coeffs[i] * 16384;
@@ -406,10 +403,9 @@ static void bicubic_kernel(float du, float dv, const XYRemap *r_tmp, · 9 unmodified lines
406 */403 */
407static inline void calculate_lanczos_coeffs(float t, float *coeffs)404static inline void calculate_lanczos_coeffs(float t, float *coeffs)
408{405{
409 int i;
410 float sum = 0.f;406 float sum = 0.f;
411 407
412 for (i = 0; i < 4; i++) {408 for (int i = 0; i < 4; i++) {
413 const float x = M_PI * (t - i + 1);409 const float x = M_PI * (t - i + 1);
414 if (x == 0.f) {410 if (x == 0.f) {
415 coeffs[i] = 1.f;411 coeffs[i] = 1.f;
@@ -419,7 +415,7 @@ static inline void calculate_lanczos_coeffs(float t, float *coeffs) · 3 unmodified lines
419 sum += coeffs[i];415 sum += coeffs[i];
420 }416 }
421 417
422 for (i = 0; i < 4; i++) {418 for (int i = 0; i < 4; i++) {
423 coeffs[i] /= sum;419 coeffs[i] /= sum;
424 }420 }
425}421}
@@ -437,15 +433,14 @@ static inline void calculate_lanczos_coeffs(float t, float *coeffs) · 11 unmodified lines
437static void lanczos_kernel(float du, float dv, const XYRemap *r_tmp,433static void lanczos_kernel(float du, float dv, const XYRemap *r_tmp,
438 uint16_t *u, uint16_t *v, int16_t *ker)434 uint16_t *u, uint16_t *v, int16_t *ker)
439{435{
440 int i, j;
441 float du_coeffs[4];436 float du_coeffs[4];
442 float dv_coeffs[4];437 float dv_coeffs[4];
443 438
444 calculate_lanczos_coeffs(du, du_coeffs);439 calculate_lanczos_coeffs(du, du_coeffs);
445 calculate_lanczos_coeffs(dv, dv_coeffs);440 calculate_lanczos_coeffs(dv, dv_coeffs);
446 441
447 for (i = 0; i < 4; i++) {442 for (int i = 0; i < 4; i++) {
448 for (j = 0; j < 4; j++) {443 for (int j = 0; j < 4; j++) {
449 u[i * 4 + j] = r_tmp->u[i][j];444 u[i * 4 + j] = r_tmp->u[i][j];
450 v[i * 4 + j] = r_tmp->v[i][j];445 v[i * 4 + j] = r_tmp->v[i][j];
451 ker[i * 4 + j] = du_coeffs[j] * dv_coeffs[i] * 16384;446 ker[i * 4 + j] = du_coeffs[j] * dv_coeffs[i] * 16384;
@@ -1094,7 +1089,6 @@ static void xyz_to_cube3x2(const V360Context *s, · 642 unmodified lines
1094 float uf, vf;1089 float uf, vf;
1095 int ui, vi;1090 int ui, vi;
1096 int ewi, ehi;1091 int ewi, ehi;
1097 int i, j;
1098 int direction, face;1092 int direction, face;
1099 int u_face, v_face;1093 int u_face, v_face;
1100 1094
@@ -1118,8 +1112,8 @@ static void xyz_to_cube3x2(const V360Context *s, · 17 unmodified lines
1118 *du = uf - ui;1112 *du = uf - ui;
1119 *dv = vf - vi;1113 *dv = vf - vi;
1120 1114
1121 for (i = -1; i < 3; i++) {1115 for (int i = -1; i < 3; i++) {
1122 for (j = -1; j < 3; j++) {1116 for (int j = -1; j < 3; j++) {
1123 int new_ui = ui + j;1117 int new_ui = ui + j;
1124 int new_vi = vi + i;1118 int new_vi = vi + i;
1125 int u_shift, v_shift;1119 int u_shift, v_shift;
@@ -1238,7 +1232,6 @@ static void xyz_to_cube1x6(const V360Context *s, · 112 unmodified lines
1238 float uf, vf;1232 float uf, vf;
1239 int ui, vi;1233 int ui, vi;
1240 int ehi;1234 int ehi;
1241 int i, j;
1242 int direction, face;1235 int direction, face;
1243 1236
1244 xyz_to_cube(s, vec, &uf, &vf, &direction);1237 xyz_to_cube(s, vec, &uf, &vf, &direction);
@@ -1258,8 +1251,8 @@ static void xyz_to_cube1x6(const V360Context *s, · 13 unmodified lines
1258 *du = uf - ui;1251 *du = uf - ui;
1259 *dv = vf - vi;1252 *dv = vf - vi;
1260 1253
1261 for (i = -1; i < 3; i++) {1254 for (int i = -1; i < 3; i++) {
1262 for (j = -1; j < 3; j++) {1255 for (int j = -1; j < 3; j++) {
1263 int new_ui = ui + j;1256 int new_ui = ui + j;
1264 int new_vi = vi + i;1257 int new_vi = vi + i;
1265 int v_shift;1258 int v_shift;
@@ -1315,7 +1308,6 @@ static void xyz_to_cube6x1(const V360Context *s, · 49 unmodified lines
1315 float uf, vf;1308 float uf, vf;
1316 int ui, vi;1309 int ui, vi;
1317 int ewi;1310 int ewi;
1318 int i, j;
1319 int direction, face;1311 int direction, face;
1320 1312
1321 xyz_to_cube(s, vec, &uf, &vf, &direction);1313 xyz_to_cube(s, vec, &uf, &vf, &direction);
@@ -1335,8 +1327,8 @@ static void xyz_to_cube6x1(const V360Context *s, · 13 unmodified lines
1335 *du = uf - ui;1327 *du = uf - ui;
1336 *dv = vf - vi;1328 *dv = vf - vi;
1337 1329
1338 for (i = -1; i < 3; i++) {1330 for (int i = -1; i < 3; i++) {
1339 for (j = -1; j < 3; j++) {1331 for (int j = -1; j < 3; j++) {
1340 int new_ui = ui + j;1332 int new_ui = ui + j;
1341 int new_vi = vi + i;1333 int new_vi = vi + i;
1342 int u_shift;1334 int u_shift;
@@ -1463,7 +1455,6 @@ static void xyz_to_stereographic(const V360Context *s, · 120 unmodified lines
1463 const float y = av_clipf(vec[2] / (1.f - vec[1]), -1.f, 1.f) * s->input_mirror_modifier[1];1455 const float y = av_clipf(vec[2] / (1.f - vec[1]), -1.f, 1.f) * s->input_mirror_modifier[1];
1464 float uf, vf;1456 float uf, vf;
1465 int ui, vi;1457 int ui, vi;
1466 int i, j;
1467 1458
1468 uf = (x + 1.f) * width / 2.f;1459 uf = (x + 1.f) * width / 2.f;
1469 vf = (y + 1.f) * height / 2.f;1460 vf = (y + 1.f) * height / 2.f;
@@ -1473,8 +1464,8 @@ static void xyz_to_stereographic(const V360Context *s, · 3 unmodified lines
1473 *du = uf - ui;1464 *du = uf - ui;
1474 *dv = vf - vi;1465 *dv = vf - vi;
1475 1466
1476 for (i = -1; i < 3; i++) {1467 for (int i = -1; i < 3; i++) {
1477 for (j = -1; j < 3; j++) {1468 for (int j = -1; j < 3; j++) {
1478 us[i + 1][j + 1] = av_clip(ui + j, 0, width - 1);1469 us[i + 1][j + 1] = av_clip(ui + j, 0, width - 1);
1479 vs[i + 1][j + 1] = av_clip(vi + i, 0, height - 1);1470 vs[i + 1][j + 1] = av_clip(vi + i, 0, height - 1);
1480 }1471 }
@@ -1501,7 +1492,6 @@ static void xyz_to_equirect(const V360Context *s, · 20 unmodified lines
1501 const float theta = asinf(-vec[1]) * s->input_mirror_modifier[1];1492 const float theta = asinf(-vec[1]) * s->input_mirror_modifier[1];
1502 float uf, vf;1493 float uf, vf;
1503 int ui, vi;1494 int ui, vi;
1504 int i, j;
1505 1495
1506 uf = (phi / M_PI + 1.f) * width / 2.f;1496 uf = (phi / M_PI + 1.f) * width / 2.f;
1507 vf = (theta / M_PI_2 + 1.f) * height / 2.f;1497 vf = (theta / M_PI_2 + 1.f) * height / 2.f;
@@ -1511,8 +1501,8 @@ static void xyz_to_equirect(const V360Context *s, · 3 unmodified lines
1511 *du = uf - ui;1501 *du = uf - ui;
1512 *dv = vf - vi;1502 *dv = vf - vi;
1513 1503
1514 for (i = -1; i < 3; i++) {1504 for (int i = -1; i < 3; i++) {
1515 for (j = -1; j < 3; j++) {1505 for (int j = -1; j < 3; j++) {
1516 us[i + 1][j + 1] = mod(ui + j, width);1506 us[i + 1][j + 1] = mod(ui + j, width);
1517 vs[i + 1][j + 1] = av_clip(vi + i, 0, height - 1);1507 vs[i + 1][j + 1] = av_clip(vi + i, 0, height - 1);
1518 }1508 }
@@ -1730,7 +1720,6 @@ static void xyz_to_eac(const V360Context *s, · 211 unmodified lines
1730 1720
1731 float uf, vf;1721 float uf, vf;
1732 int ui, vi;1722 int ui, vi;
1733 int i, j;
1734 int direction, face;1723 int direction, face;
1735 int u_face, v_face;1724 int u_face, v_face;
1736 1725
@@ -1756,8 +1745,8 @@ static void xyz_to_eac(const V360Context *s, · 19 unmodified lines
1756 *du = uf - ui;1745 *du = uf - ui;
1757 *dv = vf - vi;1746 *dv = vf - vi;
1758 1747
1759 for (i = -1; i < 3; i++) {1748 for (int i = -1; i < 3; i++) {
1760 for (j = -1; j < 3; j++) {1749 for (int j = -1; j < 3; j++) {
1761 us[i + 1][j + 1] = av_clip(ui + j, 0, width - 1);1750 us[i + 1][j + 1] = av_clip(ui + j, 0, width - 1);
1762 vs[i + 1][j + 1] = av_clip(vi + i, 0, height - 1);1751 vs[i + 1][j + 1] = av_clip(vi + i, 0, height - 1);
1763 }1752 }
@@ -1874,7 +1863,6 @@ static void xyz_to_dfisheye(const V360Context *s, · 110 unmodified lines
1874 1863
1875 int ui, vi;1864 int ui, vi;
1876 int u_shift;1865 int u_shift;
1877 int i, j;
1878 1866
1879 if (vec[2] >= 0) {1867 if (vec[2] >= 0) {
1880 u_shift = 0;1868 u_shift = 0;
@@ -1889,8 +1877,8 @@ static void xyz_to_dfisheye(const V360Context *s, · 8 unmodified lines
1889 *du = uf - ui;1877 *du = uf - ui;
1890 *dv = vf - vi;1878 *dv = vf - vi;
1891 1879
1892 for (i = -1; i < 3; i++) {1880 for (int i = -1; i < 3; i++) {
1893 for (j = -1; j < 3; j++) {1881 for (int j = -1; j < 3; j++) {
1894 us[i + 1][j + 1] = av_clip(u_shift + ui + j, 0, width - 1);1882 us[i + 1][j + 1] = av_clip(u_shift + ui + j, 0, width - 1);
1895 vs[i + 1][j + 1] = av_clip( vi + i, 0, height - 1);1883 vs[i + 1][j + 1] = av_clip( vi + i, 0, height - 1);
1896 }1884 }
@@ -1993,7 +1981,6 @@ static void xyz_to_barrel(const V360Context *s, · 96 unmodified lines
1993 int u_shift, v_shift;1981 int u_shift, v_shift;
1994 float uf, vf;1982 float uf, vf;
1995 int ui, vi;1983 int ui, vi;
1996 int i, j;
1997 1984
1998 if (theta > -theta_range && theta < theta_range) {1985 if (theta > -theta_range && theta < theta_range) {
1999 ew = 4 * width / 5;1986 ew = 4 * width / 5;
@@ -2033,8 +2020,8 @@ static void xyz_to_barrel(const V360Context *s, · 33 unmodified lines
2033 *du = uf - ui;2020 *du = uf - ui;
2034 *dv = vf - vi;2021 *dv = vf - vi;
2035 2022
2036 for (i = -1; i < 3; i++) {2023 for (int i = -1; i < 3; i++) {
2037 for (j = -1; j < 3; j++) {2024 for (int j = -1; j < 3; j++) {
2038 us[i + 1][j + 1] = u_shift + av_clip(ui + j, 0, ew - 1);2025 us[i + 1][j + 1] = u_shift + av_clip(ui + j, 0, ew - 1);
2039 vs[i + 1][j + 1] = v_shift + av_clip(vi + i, 0, eh - 1);2026 vs[i + 1][j + 1] = v_shift + av_clip(vi + i, 0, eh - 1);
2040 }2027 }
@@ -2165,7 +2152,7 @@ static int config_output(AVFilterLink *outlink) · 124 unmodified lines
2165 int sizeof_ker;2152 int sizeof_ker;
2166 int elements;2153 int elements;
2167 int err;2154 int err;
2168 int p, h, w;2155 int h, w;
2169 float hf, wf;2156 float hf, wf;
2170 float output_mirror_modifier[3];2157 float output_mirror_modifier[3];
2171 void (*in_transform)(const V360Context *s,2158 void (*in_transform)(const V360Context *s,
@@ -2416,7 +2403,7 @@ static int config_output(AVFilterLink *outlink) · 244 unmodified lines
2416 set_mirror_modifier(s->h_flip, s->v_flip, s->d_flip, output_mirror_modifier);2403 set_mirror_modifier(s->h_flip, s->v_flip, s->d_flip, output_mirror_modifier);
2417 2404
2418 // Calculate remap data2405 // Calculate remap data
2419 for (p = 0; p < s->nb_allocated; p++) {2406 for (int p = 0; p < s->nb_allocated; p++) {
2420 const int width = s->planewidth[p];2407 const int width = s->planewidth[p];
2421 const int uv_linesize = s->uv_linesize[p];2408 const int uv_linesize = s->uv_linesize[p];
2422 const int height = s->planeheight[p];2409 const int height = s->planeheight[p];
@@ -2425,10 +2412,9 @@ static int config_output(AVFilterLink *outlink) · 2 unmodified lines
2425 float du, dv;2412 float du, dv;
2426 float vec[3];2413 float vec[3];
2427 XYRemap r_tmp;2414 XYRemap r_tmp;
2428 int i, j;
2429 2415
2430 for (i = 0; i < width; i++) {2416 for (int i = 0; i < width; i++) {
2431 for (j = 0; j < height; j++) {2417 for (int j = 0; j < height; j++) {
2432 uint16_t *u = s->u[p] + (j * uv_linesize + i) * elements;2418 uint16_t *u = s->u[p] + (j * uv_linesize + i) * elements;
2433 uint16_t *v = s->v[p] + (j * uv_linesize + i) * elements;2419 uint16_t *v = s->v[p] + (j * uv_linesize + i) * elements;
2434 int16_t *ker = s->ker[p] + (j * uv_linesize + i) * elements;2420 int16_t *ker = s->ker[p] + (j * uv_linesize + i) * elements;
@@ -2482,9 +2468,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 47 unmodified lines
2482static av_cold void uninit(AVFilterContext *ctx)2468static av_cold void uninit(AVFilterContext *ctx)
2483{2469{
2484 V360Context *s = ctx->priv;2470 V360Context *s = ctx->priv;
2485 int p;
2486 2471
2487 for (p = 0; p < s->nb_allocated; p++) {2472 for (int p = 0; p < s->nb_allocated; p++) {
2488 av_freep(&s->u[p]);2473 av_freep(&s->u[p]);
2489 av_freep(&s->v[p]);2474 av_freep(&s->v[p]);
2490 av_freep(&s->ker[p]);2475 av_freep(&s->ker[p]);

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