| @@ -48,6 +48,7 @@ enum Projections { · 47 unmodified lines |
| 48 | CUBEMAP_6_1, | 48 | CUBEMAP_6_1, |
| 49 | EQUIANGULAR, | 49 | EQUIANGULAR, |
| 50 | FLAT, | 50 | FLAT, |
| | 51 | DUAL_FISHEYE, |
| 51 | NB_PROJECTIONS, | 52 | NB_PROJECTIONS, |
| 52 | }; | 53 | }; |
| 53 | | 54 | |
| @@ -136,6 +137,7 @@ static const AVOption v360_options[] = { · 82 unmodified lines |
| 136 | { "c3x2", "cubemap3x2", 0, AV_OPT_TYPE_CONST, {.i64=CUBEMAP_3_2}, 0, 0, FLAGS, "in" }, | 137 | { "c3x2", "cubemap3x2", 0, AV_OPT_TYPE_CONST, {.i64=CUBEMAP_3_2}, 0, 0, FLAGS, "in" }, |
| 137 | { "c6x1", "cubemap6x1", 0, AV_OPT_TYPE_CONST, {.i64=CUBEMAP_6_1}, 0, 0, FLAGS, "in" }, | 138 | { "c6x1", "cubemap6x1", 0, AV_OPT_TYPE_CONST, {.i64=CUBEMAP_6_1}, 0, 0, FLAGS, "in" }, |
| 138 | { "eac", "equi-angular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIANGULAR}, 0, 0, FLAGS, "in" }, | 139 | { "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" }, |
| 139 | { "output", "set output projection", OFFSET(out), AV_OPT_TYPE_INT, {.i64=CUBEMAP_3_2}, 0, NB_PROJECTIONS-1, FLAGS, "out" }, | 141 | { "output", "set output projection", OFFSET(out), AV_OPT_TYPE_INT, {.i64=CUBEMAP_3_2}, 0, NB_PROJECTIONS-1, FLAGS, "out" }, |
| 140 | { "e", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" }, | 142 | { "e", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" }, |
| 141 | { "c3x2", "cubemap3x2", 0, AV_OPT_TYPE_CONST, {.i64=CUBEMAP_3_2}, 0, 0, FLAGS, "out" }, | 143 | { "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 |
| 1593 | vec[2] = l_z / norm; | 1595 | vec[2] = l_z / norm; |
| 1594 | } | 1596 | } |
| 1595 | | 1597 | |
| | 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 | |
| 1596 | /** | 1650 | /** |
| 1597 | * Calculate rotation matrix for yaw/pitch/roll angles. | 1651 | * Calculate rotation matrix for yaw/pitch/roll angles. |
| 1598 | */ | 1652 | */ |
| @@ -1730,6 +1784,12 @@ static int config_output(AVFilterLink *outlink) · 131 unmodified lines |
| 1730 | case FLAT: | 1784 | case FLAT: |
| 1731 | av_log(ctx, AV_LOG_ERROR, "Flat format is not accepted as input.\n"); | 1785 | av_log(ctx, AV_LOG_ERROR, "Flat format is not accepted as input.\n"); |
| 1732 | return AVERROR(EINVAL); | 1786 | 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; |
| 1733 | default: | 1793 | default: |
| 1734 | av_log(ctx, AV_LOG_ERROR, "Specified input format is not handled.\n"); | 1794 | av_log(ctx, AV_LOG_ERROR, "Specified input format is not handled.\n"); |
| 1735 | return AVERROR_BUG; | 1795 | return AVERROR_BUG; |
| @@ -1770,6 +1830,9 @@ static int config_output(AVFilterLink *outlink) · 34 unmodified lines |
| 1770 | w = roundf(wf * s->flat_range[0] / s->flat_range[1] / 2.f); | 1830 | w = roundf(wf * s->flat_range[0] / s->flat_range[1] / 2.f); |
| 1771 | h = roundf(hf); | 1831 | h = roundf(hf); |
| 1772 | break; | 1832 | 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); |
| 1773 | default: | 1836 | default: |
| 1774 | av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n"); | 1837 | av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n"); |
| 1775 | return AVERROR_BUG; | 1838 | return AVERROR_BUG; |