]> git.sesse.net Git - ffmpeg/blob - libavfilter/v360.h
avfilter/vf_v360: add orthographic projection support
[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     PANNINI,
48     CYLINDRICAL,
49     PERSPECTIVE,
50     TETRAHEDRON,
51     BARREL_SPLIT,
52     TSPYRAMID,
53     HEQUIRECTANGULAR,
54     EQUISOLID,
55     ORTHOGRAPHIC,
56     NB_PROJECTIONS,
57 };
58
59 enum InterpMethod {
60     NEAREST,
61     BILINEAR,
62     LAGRANGE9,
63     BICUBIC,
64     LANCZOS,
65     SPLINE16,
66     GAUSSIAN,
67     NB_INTERP_METHODS,
68 };
69
70 enum Faces {
71     TOP_LEFT,
72     TOP_MIDDLE,
73     TOP_RIGHT,
74     BOTTOM_LEFT,
75     BOTTOM_MIDDLE,
76     BOTTOM_RIGHT,
77     NB_FACES,
78 };
79
80 enum Direction {
81     RIGHT,  ///< Axis +X
82     LEFT,   ///< Axis -X
83     UP,     ///< Axis +Y
84     DOWN,   ///< Axis -Y
85     FRONT,  ///< Axis -Z
86     BACK,   ///< Axis +Z
87     NB_DIRECTIONS,
88 };
89
90 enum Rotation {
91     ROT_0,
92     ROT_90,
93     ROT_180,
94     ROT_270,
95     NB_ROTATIONS,
96 };
97
98 enum RotationOrder {
99     YAW,
100     PITCH,
101     ROLL,
102     NB_RORDERS,
103 };
104
105 typedef struct XYRemap {
106     int16_t u[4][4];
107     int16_t v[4][4];
108     float ker[4][4];
109 } XYRemap;
110
111 typedef struct V360Context {
112     const AVClass *class;
113     int in, out;
114     int interp;
115     int alpha;
116     int width, height;
117     char *in_forder;
118     char *out_forder;
119     char *in_frot;
120     char *out_frot;
121     char *rorder;
122
123     int in_cubemap_face_order[6];
124     int out_cubemap_direction_order[6];
125     int in_cubemap_face_rotation[6];
126     int out_cubemap_face_rotation[6];
127     int rotation_order[3];
128
129     int in_stereo, out_stereo;
130
131     float in_pad, out_pad;
132     int fin_pad, fout_pad;
133
134     float yaw, pitch, roll;
135
136     int ih_flip, iv_flip;
137     int h_flip, v_flip, d_flip;
138     int in_transpose, out_transpose;
139
140     float h_fov, v_fov, d_fov;
141     float ih_fov, iv_fov, id_fov;
142     float flat_range[2];
143     float iflat_range[2];
144
145     float rot_mat[3][3];
146
147     float input_mirror_modifier[2];
148     float output_mirror_modifier[3];
149
150     int in_width, in_height;
151     int out_width, out_height;
152
153     int pr_width[4], pr_height[4];
154
155     int in_offset_w[4], in_offset_h[4];
156     int out_offset_w[4], out_offset_h[4];
157
158     int planewidth[4], planeheight[4];
159     int inplanewidth[4], inplaneheight[4];
160     int uv_linesize[4];
161     int nb_planes;
162     int nb_allocated;
163     int elements;
164     int mask_size;
165     int max_value;
166
167     int16_t *u[2], *v[2];
168     int16_t *ker[2];
169     uint8_t *mask;
170     unsigned map[4];
171
172     int (*in_transform)(const struct V360Context *s,
173                         const float *vec, int width, int height,
174                         int16_t us[4][4], int16_t vs[4][4], float *du, float *dv);
175
176     int (*out_transform)(const struct V360Context *s,
177                          int i, int j, int width, int height,
178                          float *vec);
179
180     void (*calculate_kernel)(float du, float dv, const XYRemap *rmap,
181                              int16_t *u, int16_t *v, int16_t *ker);
182
183     int (*remap_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
184
185     void (*remap_line)(uint8_t *dst, int width, const uint8_t *const src, ptrdiff_t in_linesize,
186                        const int16_t *const u, const int16_t *const v, const int16_t *const ker);
187 } V360Context;
188
189 void ff_v360_init(V360Context *s, int depth);
190 void ff_v360_init_x86(V360Context *s, int depth);
191
192 #endif /* AVFILTER_V360_H */