Showing the changes to libavfilter (2 of 3 files). Show all
Unified · Split
| @@ -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 | ||
| @@ -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 | */ | ||
| 1831 | static 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 | */ | ||
| 1851 | static 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 | */ | ||
| 1877 | static 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 | */ | ||
| 1899 | static 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 | |||
| 3644 | static void fov_from_dfov(int format, float d_fov, float w, float h, float *h_fov, float *v_fov) | 3752 | static 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; |