History

avfilter/vf_v360: add dual fisheye format

Eugene Lyapustin committed 7 years ago

Commit 596ecc21 parent d0442522 files · +83 −0Browse files

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

Unified · Split

libavfilter/vf_v360.c+63−0
@@ -48,6 +48,7 @@ enum Projections { · 47 unmodified lines
4848 CUBEMAP_6_1,
4949 EQUIANGULAR,
5050 FLAT,
51+ DUAL_FISHEYE,
5152 NB_PROJECTIONS,
5253 };
5354
@@ -136,6 +137,7 @@ static const AVOption v360_options[] = { · 82 unmodified lines
136137 { "c3x2", "cubemap3x2", 0, AV_OPT_TYPE_CONST, {.i64=CUBEMAP_3_2}, 0, 0, FLAGS, "in" },
137138 { "c6x1", "cubemap6x1", 0, AV_OPT_TYPE_CONST, {.i64=CUBEMAP_6_1}, 0, 0, FLAGS, "in" },
138139 { "eac", "equi-angular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIANGULAR}, 0, 0, FLAGS, "in" },
140+ { "dfisheye", "dual fisheye", 0, AV_OPT_TYPE_CONST, {.i64=DUAL_FISHEYE}, 0, 0, FLAGS, "in" },
139141 { "output", "set output projection", OFFSET(out), AV_OPT_TYPE_INT, {.i64=CUBEMAP_3_2}, 0, NB_PROJECTIONS-1, FLAGS, "out" },
140142 { "e", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" },
141143 { "c3x2", "cubemap3x2", 0, AV_OPT_TYPE_CONST, {.i64=CUBEMAP_3_2}, 0, 0, FLAGS, "out" },
@@ -1593,6 +1595,58 @@ static void flat_to_xyz(const V360Context *s, · 1451 unmodified lines
15931595 vec[2] = l_z / norm;
15941596 }
15951597
1598+/**
1599+ * Calculate frame position in dual fisheye format for corresponding 3D coordinates on sphere.
1600+ *
1601+ * @param s filter context
1602+ * @param vec coordinates on sphere
1603+ * @param width frame width
1604+ * @param height frame height
1605+ * @param us horizontal coordinates for interpolation window
1606+ * @param vs vertical coordinates for interpolation window
1607+ * @param du horizontal relative coordinate
1608+ * @param dv vertical relative coordinate
1609+ */
1610+static void xyz_to_dfisheye(const V360Context *s,
1611+ const float *vec, int width, int height,
1612+ uint16_t us[4][4], uint16_t vs[4][4], float *du, float *dv)
1613+{
1614+ const float scale = 1.f - s->in_pad;
1615+
1616+ const float ew = width / 2.f;
1617+ const float eh = height;
1618+
1619+ const float phi = atan2f(-vec[1], -vec[0]);
1620+ const float theta = acosf(fabsf(vec[2])) / M_PI;
1621+
1622+ float uf = (theta * cosf(phi) * scale + 0.5f) * ew;
1623+ float vf = (theta * sinf(phi) * scale + 0.5f) * eh;
1624+
1625+ int ui, vi;
1626+ int u_shift;
1627+ int i, j;
1628+
1629+ if (vec[2] >= 0) {
1630+ u_shift = 0;
1631+ } else {
1632+ u_shift = ceilf(ew);
1633+ uf = ew - uf;
1634+ }
1635+
1636+ ui = floorf(uf);
1637+ vi = floorf(vf);
1638+
1639+ *du = uf - ui;
1640+ *dv = vf - vi;
1641+
1642+ for (i = -1; i < 3; i++) {
1643+ for (j = -1; j < 3; j++) {
1644+ us[i + 1][j + 1] = av_clip(u_shift + ui + j, 0, width - 1);
1645+ vs[i + 1][j + 1] = av_clip( vi + i, 0, height - 1);
1646+ }
1647+ }
1648+}
1649+
15961650 /**
15971651 * Calculate rotation matrix for yaw/pitch/roll angles.
15981652 */
@@ -1730,6 +1784,12 @@ static int config_output(AVFilterLink *outlink) · 131 unmodified lines
17301784 case FLAT:
17311785 av_log(ctx, AV_LOG_ERROR, "Flat format is not accepted as input.\n");
17321786 return AVERROR(EINVAL);
1787+ case DUAL_FISHEYE:
1788+ in_transform = xyz_to_dfisheye;
1789+ err = 0;
1790+ wf = inlink->w;
1791+ hf = inlink->h;
1792+ break;
17331793 default:
17341794 av_log(ctx, AV_LOG_ERROR, "Specified input format is not handled.\n");
17351795 return AVERROR_BUG;
@@ -1770,6 +1830,9 @@ static int config_output(AVFilterLink *outlink) · 34 unmodified lines
17701830 w = roundf(wf * s->flat_range[0] / s->flat_range[1] / 2.f);
17711831 h = roundf(hf);
17721832 break;
1833+ case DUAL_FISHEYE:
1834+ av_log(ctx, AV_LOG_ERROR, "Dual fisheye format is not accepted as output.\n");
1835+ return AVERROR(EINVAL);
17731836 default:
17741837 av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n");
17751838 return AVERROR_BUG;

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