]> git.sesse.net Git - ffmpeg/blob - libavfilter/v360.h
avfilter/vf_v360: add fisheye output projection
[ffmpeg] / libavfilter / v360.h
1 /*
2  * Copyright (c) 2019 Eugene Lyapustin
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #ifndef AVFILTER_V360_H
22 #define AVFILTER_V360_H
23 #include "avfilter.h"
24
25 enum StereoFormats {
26     STEREO_2D,
27     STEREO_SBS,
28     STEREO_TB,
29     NB_STEREO_FMTS,
30 };
31
32 enum Projections {
33     EQUIRECTANGULAR,
34     CUBEMAP_3_2,
35     CUBEMAP_6_1,
36     EQUIANGULAR,
37     FLAT,
38     DUAL_FISHEYE,
39     BARREL,
40     CUBEMAP_1_6,
41     STEREOGRAPHIC,
42     MERCATOR,
43     BALL,
44     HAMMER,
45     SINUSOIDAL,
46     FISHEYE,
47     NB_PROJECTIONS,
48 };
49
50 enum InterpMethod {
51     NEAREST,
52     BILINEAR,
53     BICUBIC,
54     LANCZOS,
55     NB_INTERP_METHODS,
56 };
57
58 enum Faces {
59     TOP_LEFT,
60     TOP_MIDDLE,
61     TOP_RIGHT,
62     BOTTOM_LEFT,
63     BOTTOM_MIDDLE,
64     BOTTOM_RIGHT,
65     NB_FACES,
66 };
67
68 enum Direction {
69     RIGHT,  ///< Axis +X
70     LEFT,   ///< Axis -X
71     UP,     ///< Axis +Y
72     DOWN,   ///< Axis -Y
73     FRONT,  ///< Axis -Z
74     BACK,   ///< Axis +Z
75     NB_DIRECTIONS,
76 };
77
78 enum Rotation {
79     ROT_0,
80     ROT_90,
81     ROT_180,
82     ROT_270,
83     NB_ROTATIONS,
84 };
85
86 enum RotationOrder {
87     YAW,
88     PITCH,
89     ROLL,
90     NB_RORDERS,
91 };
92
93 typedef struct XYRemap {
94     uint16_t u[4][4];
95     uint16_t v[4][4];
96     float ker[4][4];
97 } XYRemap;
98
99 typedef struct V360Context {
100     const AVClass *class;
101     int in, out;
102     int interp;
103     int width, height;
104     char *in_forder;
105     char *out_forder;
106     char *in_frot;
107     char *out_frot;
108     char *rorder;
109
110     int in_cubemap_face_order[6];
111     int out_cubemap_direction_order[6];
112     int in_cubemap_face_rotation[6];
113     int out_cubemap_face_rotation[6];
114     int rotation_order[3];
115
116     int in_stereo, out_stereo;
117
118     float in_pad, out_pad;
119     int fin_pad, fout_pad;
120
121     float yaw, pitch, roll;
122
123     int ih_flip, iv_flip;
124     int h_flip, v_flip, d_flip;
125     int in_transpose, out_transpose;
126
127     float h_fov, v_fov, d_fov;
128     float flat_range[2];
129
130     float rot_mat[3][3];
131
132     float input_mirror_modifier[2];
133     float output_mirror_modifier[3];
134
135     int in_width, in_height;
136     int out_width, out_height;
137
138     int pr_width[4], pr_height[4];
139
140     int in_offset_w[4], in_offset_h[4];
141     int out_offset_w[4], out_offset_h[4];
142
143     int planewidth[4], planeheight[4];
144     int inplanewidth[4], inplaneheight[4];
145     int uv_linesize[4];
146     int nb_planes;
147     int nb_allocated;
148     int elements;
149
150     uint16_t *u[2], *v[2];
151     int16_t *ker[2];
152     unsigned map[4];
153
154     void (*in_transform)(const struct V360Context *s,
155                          const float *vec, int width, int height,
156                          uint16_t us[4][4], uint16_t vs[4][4], float *du, float *dv);
157
158     void (*out_transform)(const struct V360Context *s,
159                           int i, int j, int width, int height,
160                           float *vec);
161
162     void (*calculate_kernel)(float du, float dv, const XYRemap *rmap,
163                              uint16_t *u, uint16_t *v, int16_t *ker);
164
165     int (*remap_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
166
167     void (*remap_line)(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
168                        const uint16_t *u, const uint16_t *v, const int16_t *ker);
169 } V360Context;
170
171 void ff_v360_init(V360Context *s, int depth);
172 void ff_v360_init_x86(V360Context *s, int depth);
173
174 #endif /* AVFILTER_V360_H */