| @@ -82,6 +82,7 @@ static const AVOption v360_options[] = { · 81 unmodified lines |
| 82 | 82 | { "hequirect", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "in" }, |
| 83 | 83 | { "he", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "in" }, |
| 84 | 84 | { "equisolid", "equisolid", 0, AV_OPT_TYPE_CONST, {.i64=EQUISOLID}, 0, 0, FLAGS, "in" }, |
| 85 | + { "og", "orthographic", 0, AV_OPT_TYPE_CONST, {.i64=ORTHOGRAPHIC}, 0, 0, FLAGS, "in" }, |
| 85 | 86 | { "output", "set output projection", OFFSET(out), AV_OPT_TYPE_INT, {.i64=CUBEMAP_3_2}, 0, NB_PROJECTIONS-1, FLAGS, "out" }, |
| 86 | 87 | { "e", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" }, |
| 87 | 88 | { "equirect", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" }, |
| @@ -110,6 +111,7 @@ static const AVOption v360_options[] = { · 22 unmodified lines |
| 110 | 111 | { "hequirect", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "out" }, |
| 111 | 112 | { "he", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "out" }, |
| 112 | 113 | { "equisolid", "equisolid", 0, AV_OPT_TYPE_CONST, {.i64=EQUISOLID}, 0, 0, FLAGS, "out" }, |
| 114 | + { "og", "orthographic", 0, AV_OPT_TYPE_CONST, {.i64=ORTHOGRAPHIC}, 0, 0, FLAGS, "out" }, |
| 113 | 115 | { "interp", "set interpolation method", OFFSET(interp), AV_OPT_TYPE_INT, {.i64=BILINEAR}, 0, NB_INTERP_METHODS-1, FLAGS, "interp" }, |
| 114 | 116 | { "near", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" }, |
| 115 | 117 | { "nearest", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" }, |
| @@ -1832,8 +1834,8 @@ static int prepare_equisolid_out(AVFilterContext *ctx) · 1716 unmodified lines |
| 1832 | 1834 | { |
| 1833 | 1835 | V360Context *s = ctx->priv; |
| 1834 | 1836 | |
| 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 | + s->flat_range[0] = sinf(s->h_fov * M_PI / 720.f); |
| 1838 | + s->flat_range[1] = sinf(s->v_fov * M_PI / 720.f); |
| 1837 | 1839 | |
| 1838 | 1840 | return 0; |
| 1839 | 1841 | } |
| @@ -1927,6 +1929,111 @@ static int xyz_to_equisolid(const V360Context *s, · 87 unmodified lines |
| 1927 | 1929 | return visible; |
| 1928 | 1930 | } |
| 1929 | 1931 | |
| 1932 | +/** |
| 1933 | + * Prepare data for processing orthographic output format. |
| 1934 | + * |
| 1935 | + * @param ctx filter context |
| 1936 | + * |
| 1937 | + * @return error code |
| 1938 | + */ |
| 1939 | +static int prepare_orthographic_out(AVFilterContext *ctx) |
| 1940 | +{ |
| 1941 | + V360Context *s = ctx->priv; |
| 1942 | + |
| 1943 | + s->flat_range[0] = sinf(FFMIN(s->h_fov, 180.f) * M_PI / 360.f); |
| 1944 | + s->flat_range[1] = sinf(FFMIN(s->v_fov, 180.f) * M_PI / 360.f); |
| 1945 | + |
| 1946 | + return 0; |
| 1947 | +} |
| 1948 | + |
| 1949 | +/** |
| 1950 | + * Calculate 3D coordinates on sphere for corresponding frame position in orthographic format. |
| 1951 | + * |
| 1952 | + * @param s filter private context |
| 1953 | + * @param i horizontal position on frame [0, width) |
| 1954 | + * @param j vertical position on frame [0, height) |
| 1955 | + * @param width frame width |
| 1956 | + * @param height frame height |
| 1957 | + * @param vec coordinates on sphere |
| 1958 | + */ |
| 1959 | +static int orthographic_to_xyz(const V360Context *s, |
| 1960 | + int i, int j, int width, int height, |
| 1961 | + float *vec) |
| 1962 | +{ |
| 1963 | + const float x = ((2.f * i + 1.f) / width - 1.f) * s->flat_range[0]; |
| 1964 | + const float y = ((2.f * j + 1.f) / height - 1.f) * s->flat_range[1]; |
| 1965 | + const float r = hypotf(x, y); |
| 1966 | + const float theta = asinf(r); |
| 1967 | + |
| 1968 | + vec[0] = x; |
| 1969 | + vec[1] = y; |
| 1970 | + vec[2] = cosf(theta); |
| 1971 | + |
| 1972 | + normalize_vector(vec); |
| 1973 | + |
| 1974 | + return 1; |
| 1975 | +} |
| 1976 | + |
| 1977 | +/** |
| 1978 | + * Prepare data for processing orthographic input format. |
| 1979 | + * |
| 1980 | + * @param ctx filter context |
| 1981 | + * |
| 1982 | + * @return error code |
| 1983 | + */ |
| 1984 | +static int prepare_orthographic_in(AVFilterContext *ctx) |
| 1985 | +{ |
| 1986 | + V360Context *s = ctx->priv; |
| 1987 | + |
| 1988 | + s->iflat_range[0] = sinf(FFMIN(s->ih_fov, 180.f) * M_PI / 360.f); |
| 1989 | + s->iflat_range[1] = sinf(FFMIN(s->iv_fov, 180.f) * M_PI / 360.f); |
| 1990 | + |
| 1991 | + return 0; |
| 1992 | +} |
| 1993 | + |
| 1994 | +/** |
| 1995 | + * Calculate frame position in orthographic format for corresponding 3D coordinates on sphere. |
| 1996 | + * |
| 1997 | + * @param s filter private context |
| 1998 | + * @param vec coordinates on sphere |
| 1999 | + * @param width frame width |
| 2000 | + * @param height frame height |
| 2001 | + * @param us horizontal coordinates for interpolation window |
| 2002 | + * @param vs vertical coordinates for interpolation window |
| 2003 | + * @param du horizontal relative coordinate |
| 2004 | + * @param dv vertical relative coordinate |
| 2005 | + */ |
| 2006 | +static int xyz_to_orthographic(const V360Context *s, |
| 2007 | + const float *vec, int width, int height, |
| 2008 | + int16_t us[4][4], int16_t vs[4][4], float *du, float *dv) |
| 2009 | +{ |
| 2010 | + const float theta = acosf(vec[2]); |
| 2011 | + const float r = sinf(theta); |
| 2012 | + const float c = r / hypotf(vec[0], vec[1]); |
| 2013 | + const float x = vec[0] * c / s->iflat_range[0] * s->input_mirror_modifier[0]; |
| 2014 | + const float y = vec[1] * c / s->iflat_range[1] * s->input_mirror_modifier[1]; |
| 2015 | + |
| 2016 | + const float uf = (x + 1.f) * width / 2.f; |
| 2017 | + const float vf = (y + 1.f) * height / 2.f; |
| 2018 | + |
| 2019 | + const int ui = floorf(uf); |
| 2020 | + const int vi = floorf(vf); |
| 2021 | + |
| 2022 | + const int visible = vec[2] >= 0.f && isfinite(x) && isfinite(y) && vi >= 0 && vi < height && ui >= 0 && ui < width; |
| 2023 | + |
| 2024 | + *du = visible ? uf - ui : 0.f; |
| 2025 | + *dv = visible ? vf - vi : 0.f; |
| 2026 | + |
| 2027 | + for (int i = 0; i < 4; i++) { |
| 2028 | + for (int j = 0; j < 4; j++) { |
| 2029 | + us[i][j] = visible ? av_clip(ui + j - 1, 0, width - 1) : 0; |
| 2030 | + vs[i][j] = visible ? av_clip(vi + i - 1, 0, height - 1) : 0; |
| 2031 | + } |
| 2032 | + } |
| 2033 | + |
| 2034 | + return visible; |
| 2035 | +} |
| 2036 | + |
| 1930 | 2037 | /** |
| 1931 | 2038 | * Calculate frame position in equirectangular format for corresponding 3D coordinates on sphere. |
| 1932 | 2039 | * |
| @@ -3752,6 +3859,20 @@ static int allocate_plane(V360Context *s, int sizeof_uv, int sizeof_ker, int siz · 1819 unmodified lines |
| 3752 | 3859 | static void fov_from_dfov(int format, float d_fov, float w, float h, float *h_fov, float *v_fov) |
| 3753 | 3860 | { |
| 3754 | 3861 | switch (format) { |
| 3862 | + case ORTHOGRAPHIC: |
| 3863 | + { |
| 3864 | + const float d = 0.5f * hypotf(w, h); |
| 3865 | + const float l = sinf(d_fov * M_PI / 360.f) / d; |
| 3866 | + |
| 3867 | + *h_fov = asinf(w * 0.5 * l) * 360.f / M_PI; |
| 3868 | + *v_fov = asinf(h * 0.5 * l) * 360.f / M_PI; |
| 3869 | + |
| 3870 | + if (d_fov > 180.f) { |
| 3871 | + *h_fov = 180.f - *h_fov; |
| 3872 | + *v_fov = 180.f - *v_fov; |
| 3873 | + } |
| 3874 | + } |
| 3875 | + break; |
| 3755 | 3876 | case EQUISOLID: |
| 3756 | 3877 | { |
| 3757 | 3878 | const float d = 0.5f * hypotf(w, h); |
| @@ -4137,6 +4258,12 @@ static int config_output(AVFilterLink *outlink) · 379 unmodified lines |
| 4137 | 4258 | wf = w; |
| 4138 | 4259 | hf = h / 2.f; |
| 4139 | 4260 | break; |
| 4261 | + case ORTHOGRAPHIC: |
| 4262 | + s->in_transform = xyz_to_orthographic; |
| 4263 | + err = prepare_orthographic_in(ctx); |
| 4264 | + wf = w; |
| 4265 | + hf = h / 2.f; |
| 4266 | + break; |
| 4140 | 4267 | default: |
| 4141 | 4268 | av_log(ctx, AV_LOG_ERROR, "Specified input format is not handled.\n"); |
| 4142 | 4269 | return AVERROR_BUG; |
| @@ -4279,6 +4406,12 @@ static int config_output(AVFilterLink *outlink) · 136 unmodified lines |
| 4279 | 4406 | w = lrintf(wf); |
| 4280 | 4407 | h = lrintf(hf * 2.f); |
| 4281 | 4408 | break; |
| 4409 | + case ORTHOGRAPHIC: |
| 4410 | + s->out_transform = orthographic_to_xyz; |
| 4411 | + prepare_out = prepare_orthographic_out; |
| 4412 | + w = lrintf(wf); |
| 4413 | + h = lrintf(hf * 2.f); |
| 4414 | + break; |
| 4282 | 4415 | default: |
| 4283 | 4416 | av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n"); |
| 4284 | 4417 | return AVERROR_BUG; |