History

avfilters/vf_v360: add equisolid projection support

Paul B Mahol committed 6 years ago

Commit 44ce3331 parent 3f2be533 files · +150 −0Browse files

Unified · Split

3 files
  1. doc/filters.texi +20 −0
  2. libavfilter/v360.h +1 −0
  3. libavfilter/vf_v360.c +129 −0
doc/filters.texi+20−0
@@ -19322,6 +19322,26 @@ Truncated square pyramid projection. · 19321 unmodified lines
19322@item he19322@item he
19323@item hequirect19323@item hequirect
19324Half equirectangular projection.19324Half equirectangular projection.
19325
19326@item equisolid
19327Equisolid format.
19328
19329Format specific options:
19330@table @option
19331@item h_fov
19332@item v_fov
19333@item d_fov
19334Set output horizontal/vertical/diagonal field of view. Values in degrees.
19335
19336If diagonal field of view is set it overrides horizontal and vertical field of view.
19337
19338@item ih_fov
19339@item iv_fov
19340@item id_fov
19341Set input horizontal/vertical/diagonal field of view. Values in degrees.
19342
19343If diagonal field of view is set it overrides horizontal and vertical field of view.
19344@end table
19325@end table19345@end table
19326 19346
19327@item interp19347@item interp
libavfilter/v360.h+1−0
@@ -51,6 +51,7 @@ enum Projections { · 50 unmodified lines
51 BARREL_SPLIT,51 BARREL_SPLIT,
52 TSPYRAMID,52 TSPYRAMID,
53 HEQUIRECTANGULAR,53 HEQUIRECTANGULAR,
54 EQUISOLID,
54 NB_PROJECTIONS,55 NB_PROJECTIONS,
55};56};
56 57
libavfilter/vf_v360.c+129−0
@@ -81,6 +81,7 @@ static const AVOption v360_options[] = { · 80 unmodified lines
81 { "tsp", "truncated square pyramid", 0, AV_OPT_TYPE_CONST, {.i64=TSPYRAMID}, 0, 0, FLAGS, "in" },81 { "tsp", "truncated square pyramid", 0, AV_OPT_TYPE_CONST, {.i64=TSPYRAMID}, 0, 0, FLAGS, "in" },
82 { "hequirect", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "in" },82 { "hequirect", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "in" },
83 { "he", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "in" },83 { "he", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "in" },
84 { "equisolid", "equisolid", 0, AV_OPT_TYPE_CONST, {.i64=EQUISOLID}, 0, 0, FLAGS, "in" },
84 { "output", "set output projection", OFFSET(out), AV_OPT_TYPE_INT, {.i64=CUBEMAP_3_2}, 0, NB_PROJECTIONS-1, FLAGS, "out" },85 { "output", "set output projection", OFFSET(out), AV_OPT_TYPE_INT, {.i64=CUBEMAP_3_2}, 0, NB_PROJECTIONS-1, FLAGS, "out" },
85 { "e", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" },86 { "e", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" },
86 { "equirect", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" },87 { "equirect", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" },
@@ -108,6 +109,7 @@ static const AVOption v360_options[] = { · 21 unmodified lines
108 { "tsp", "truncated square pyramid", 0, AV_OPT_TYPE_CONST, {.i64=TSPYRAMID}, 0, 0, FLAGS, "out" },109 { "tsp", "truncated square pyramid", 0, AV_OPT_TYPE_CONST, {.i64=TSPYRAMID}, 0, 0, FLAGS, "out" },
109 { "hequirect", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "out" },110 { "hequirect", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "out" },
110 { "he", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "out" },111 { "he", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "out" },
112 { "equisolid", "equisolid", 0, AV_OPT_TYPE_CONST, {.i64=EQUISOLID}, 0, 0, FLAGS, "out" },
111 { "interp", "set interpolation method", OFFSET(interp), AV_OPT_TYPE_INT, {.i64=BILINEAR}, 0, NB_INTERP_METHODS-1, FLAGS, "interp" },113 { "interp", "set interpolation method", OFFSET(interp), AV_OPT_TYPE_INT, {.i64=BILINEAR}, 0, NB_INTERP_METHODS-1, FLAGS, "interp" },
112 { "near", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" },114 { "near", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" },
113 { "nearest", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" },115 { "nearest", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" },
@@ -1819,6 +1821,112 @@ static int xyz_to_stereographic(const V360Context *s, · 1705 unmodified lines
1819 return visible;1821 return visible;
1820}1822}
1821 1823
1824/**
1825 * Prepare data for processing equisolid output format.
1826 *
1827 * @param ctx filter context
1828 *
1829 * @return error code
1830 */
1831static int prepare_equisolid_out(AVFilterContext *ctx)
1832{
1833 V360Context *s = ctx->priv;
1834
1835 s->flat_range[0] = sinf(FFMIN(s->h_fov, 359.f) * M_PI / 720.f);
1836 s->flat_range[1] = sinf(FFMIN(s->v_fov, 359.f) * M_PI / 720.f);
1837
1838 return 0;
1839}
1840
1841/**
1842 * Calculate 3D coordinates on sphere for corresponding frame position in equisolid format.
1843 *
1844 * @param s filter private context
1845 * @param i horizontal position on frame [0, width)
1846 * @param j vertical position on frame [0, height)
1847 * @param width frame width
1848 * @param height frame height
1849 * @param vec coordinates on sphere
1850 */
1851static int equisolid_to_xyz(const V360Context *s,
1852 int i, int j, int width, int height,
1853 float *vec)
1854{
1855 const float x = ((2.f * i + 1.f) / width - 1.f) * s->flat_range[0];
1856 const float y = ((2.f * j + 1.f) / height - 1.f) * s->flat_range[1];
1857 const float r = hypotf(x, y);
1858 const float theta = asinf(r) * 2.f;
1859 const float sin_theta = sinf(theta);
1860
1861 vec[0] = x / r * sin_theta;
1862 vec[1] = y / r * sin_theta;
1863 vec[2] = cosf(theta);
1864
1865 normalize_vector(vec);
1866
1867 return 1;
1868}
1869
1870/**
1871 * Prepare data for processing equisolid input format.
1872 *
1873 * @param ctx filter context
1874 *
1875 * @return error code
1876 */
1877static int prepare_equisolid_in(AVFilterContext *ctx)
1878{
1879 V360Context *s = ctx->priv;
1880
1881 s->iflat_range[0] = sinf(FFMIN(s->ih_fov, 359.f) * M_PI / 720.f);
1882 s->iflat_range[1] = sinf(FFMIN(s->iv_fov, 359.f) * M_PI / 720.f);
1883
1884 return 0;
1885}
1886
1887/**
1888 * Calculate frame position in equisolid format for corresponding 3D coordinates on sphere.
1889 *
1890 * @param s filter private context
1891 * @param vec coordinates on sphere
1892 * @param width frame width
1893 * @param height frame height
1894 * @param us horizontal coordinates for interpolation window
1895 * @param vs vertical coordinates for interpolation window
1896 * @param du horizontal relative coordinate
1897 * @param dv vertical relative coordinate
1898 */
1899static int xyz_to_equisolid(const V360Context *s,
1900 const float *vec, int width, int height,
1901 int16_t us[4][4], int16_t vs[4][4], float *du, float *dv)
1902{
1903 const float theta = acosf(vec[2]);
1904 const float r = sinf(theta * 0.5f);
1905 const float c = r / hypotf(vec[0], vec[1]);
1906 const float x = vec[0] * c / s->iflat_range[0] * s->input_mirror_modifier[0];
1907 const float y = vec[1] * c / s->iflat_range[1] * s->input_mirror_modifier[1];
1908
1909 const float uf = (x + 1.f) * width / 2.f;
1910 const float vf = (y + 1.f) * height / 2.f;
1911
1912 const int ui = floorf(uf);
1913 const int vi = floorf(vf);
1914
1915 const int visible = isfinite(x) && isfinite(y) && vi >= 0 && vi < height && ui >= 0 && ui < width;
1916
1917 *du = visible ? uf - ui : 0.f;
1918 *dv = visible ? vf - vi : 0.f;
1919
1920 for (int i = 0; i < 4; i++) {
1921 for (int j = 0; j < 4; j++) {
1922 us[i][j] = visible ? av_clip(ui + j - 1, 0, width - 1) : 0;
1923 vs[i][j] = visible ? av_clip(vi + i - 1, 0, height - 1) : 0;
1924 }
1925 }
1926
1927 return visible;
1928}
1929
1822/**1930/**
1823 * Calculate frame position in equirectangular format for corresponding 3D coordinates on sphere.1931 * Calculate frame position in equirectangular format for corresponding 3D coordinates on sphere.
1824 *1932 *
@@ -3644,6 +3752,15 @@ static int allocate_plane(V360Context *s, int sizeof_uv, int sizeof_ker, int siz · 1819 unmodified lines
3644static void fov_from_dfov(int format, float d_fov, float w, float h, float *h_fov, float *v_fov)3752static void fov_from_dfov(int format, float d_fov, float w, float h, float *h_fov, float *v_fov)
3645{3753{
3646 switch (format) {3754 switch (format) {
3755 case EQUISOLID:
3756 {
3757 const float d = 0.5f * hypotf(w, h);
3758 const float l = d / (sinf(d_fov * M_PI / 720.f));
3759
3760 *h_fov = 2.f * asinf(w * 0.5f / l) * 360.f / M_PI;
3761 *v_fov = 2.f * asinf(h * 0.5f / l) * 360.f / M_PI;
3762 }
3763 break;
3647 case STEREOGRAPHIC:3764 case STEREOGRAPHIC:
3648 {3765 {
3649 const float d = 0.5f * hypotf(w, h);3766 const float d = 0.5f * hypotf(w, h);
@@ -4014,6 +4131,12 @@ static int config_output(AVFilterLink *outlink) · 364 unmodified lines
4014 wf = w * 2.f;4131 wf = w * 2.f;
4015 hf = h;4132 hf = h;
4016 break;4133 break;
4134 case EQUISOLID:
4135 s->in_transform = xyz_to_equisolid;
4136 err = prepare_equisolid_in(ctx);
4137 wf = w;
4138 hf = h / 2.f;
4139 break;
4017 default:4140 default:
4018 av_log(ctx, AV_LOG_ERROR, "Specified input format is not handled.\n");4141 av_log(ctx, AV_LOG_ERROR, "Specified input format is not handled.\n");
4019 return AVERROR_BUG;4142 return AVERROR_BUG;
@@ -4150,6 +4273,12 @@ static int config_output(AVFilterLink *outlink) · 130 unmodified lines
4150 w = lrintf(wf / 2.f);4273 w = lrintf(wf / 2.f);
4151 h = lrintf(hf);4274 h = lrintf(hf);
4152 break;4275 break;
4276 case EQUISOLID:
4277 s->out_transform = equisolid_to_xyz;
4278 prepare_out = prepare_equisolid_out;
4279 w = lrintf(wf);
4280 h = lrintf(hf * 2.f);
4281 break;
4153 default:4282 default:
4154 av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n");4283 av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n");
4155 return AVERROR_BUG;4284 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