avfilter/avfiltergraph: fix constant string comparision
[ffmpeg.git] / libavutil / spherical.h
1 /*
2 * Copyright (c) 2016 Vittorio Giovara <vittorio.giovara@gmail.com>
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 /**
22 * @file
23 * @ingroup lavu_video_spherical
24 * Spherical video
25 */
26
27 #ifndef AVUTIL_SPHERICAL_H
28 #define AVUTIL_SPHERICAL_H
29
30 #include <stddef.h>
31 #include <stdint.h>
32
33 /**
34 * @defgroup lavu_video_spherical Spherical video mapping
35 * @ingroup lavu_video
36 *
37 * A spherical video file contains surfaces that need to be mapped onto a
38 * sphere. Depending on how the frame was converted, a different distortion
39 * transformation or surface recomposition function needs to be applied before
40 * the video should be mapped and displayed.
41 * @{
42 */
43
44 /**
45 * Projection of the video surface(s) on a sphere.
46 */
47 enum AVSphericalProjection {
48 /**
49 * Video represents a sphere mapped on a flat surface using
50 * equirectangular projection.
51 */
52 AV_SPHERICAL_EQUIRECTANGULAR,
53
54 /**
55 * Video frame is split into 6 faces of a cube, and arranged on a
56 * 3x2 layout. Faces are oriented upwards for the front, left, right,
57 * and back faces. The up face is oriented so the top of the face is
58 * forwards and the down face is oriented so the top of the face is
59 * to the back.
60 */
61 AV_SPHERICAL_CUBEMAP,
62
63 /**
64 * Video represents a portion of a sphere mapped on a flat surface
65 * using equirectangular projection. The @ref bounding fields indicate
66 * the position of the current video in a larger surface.
67 */
68 AV_SPHERICAL_EQUIRECTANGULAR_TILE,
69
70 /**
71 * Video frame displays as a 180 degree equirectangular projection.
72 */
73 AV_SPHERICAL_HALF_EQUIRECTANGULAR,
74
75 /**
76 * Video frame displays on a flat, rectangular 2D surface.
77 */
78 AV_SPHERICAL_RECTILINEAR,
79
80 /**
81 * Fisheye projection (Apple).
82 * See: https://developer.apple.com/documentation/coremedia/cmprojectiontype/fisheye
83 */
84 AV_SPHERICAL_FISHEYE,
85
86 /**
87 * Parametric Immersive projection (Apple).
88 * See: https://developer.apple.com/documentation/coremedia/cmprojectiontype/parametricimmersive
89 */
90 AV_SPHERICAL_PARAMETRIC_IMMERSIVE,
91 };
92
93 /**
94 * This structure describes how to handle spherical videos, outlining
95 * information about projection, initial layout, and any other view modifier.
96 *
97 * @note The struct must be allocated with av_spherical_alloc() and
98 * its size is not a part of the public ABI.
99 */
100 typedef struct AVSphericalMapping {
101 /**
102 * Projection type.
103 */
104 enum AVSphericalProjection projection;
105
106 /**
107 * @name Initial orientation
108 * @{
109 * There fields describe additional rotations applied to the sphere after
110 * the video frame is mapped onto it. The sphere is rotated around the
111 * viewer, who remains stationary. The order of transformation is always
112 * yaw, followed by pitch, and finally by roll.
113 *
114 * The coordinate system matches the one defined in OpenGL, where the
115 * forward vector (z) is coming out of screen, and it is equivalent to
116 * a rotation matrix of R = r_y(yaw) * r_x(pitch) * r_z(roll).
117 *
118 * A positive yaw rotates the portion of the sphere in front of the viewer
119 * toward their right. A positive pitch rotates the portion of the sphere
120 * in front of the viewer upwards. A positive roll tilts the portion of
121 * the sphere in front of the viewer to the viewer's right.
122 *
123 * These values are exported as 16.16 fixed point.
124 *
125 * See this equirectangular projection as example:
126 *
127 * @code{.unparsed}
128 * Yaw
129 * -180 0 180
130 * 90 +-------------+-------------+ 180
131 * | | | up
132 * P | | | y| forward
133 * i | ^ | | /z
134 * t 0 +-------------X-------------+ 0 Roll | /
135 * c | | | | /
136 * h | | | 0|/_____right
137 * | | | x
138 * -90 +-------------+-------------+ -180
139 *
140 * X - the default camera center
141 * ^ - the default up vector
142 * @endcode
143 */
144 int32_t yaw; ///< Rotation around the up vector [-180, 180].
145 int32_t pitch; ///< Rotation around the right vector [-90, 90].
146 int32_t roll; ///< Rotation around the forward vector [-180, 180].
147 /**
148 * @}
149 */
150
151 /**
152 * @name Bounding rectangle
153 * @anchor bounding
154 * @{
155 * These fields indicate the location of the current tile, and where
156 * it should be mapped relative to the original surface. They are
157 * exported as 0.32 fixed point, and can be converted to classic
158 * pixel values with av_spherical_bounds().
159 *
160 * @code{.unparsed}
161 * +----------------+----------+
162 * | |bound_top |
163 * | +--------+ |
164 * | bound_left |tile | |
165 * +<---------->| |<--->+bound_right
166 * | +--------+ |
167 * | | |
168 * | bound_bottom| |
169 * +----------------+----------+
170 * @endcode
171 *
172 * If needed, the original video surface dimensions can be derived
173 * by adding the current stream or frame size to the related bounds,
174 * like in the following example:
175 *
176 * @code{c}
177 * original_width = tile->width + bound_left + bound_right;
178 * original_height = tile->height + bound_top + bound_bottom;
179 * @endcode
180 *
181 * @note These values are valid only for the tiled equirectangular
182 * projection type (@ref AV_SPHERICAL_EQUIRECTANGULAR_TILE),
183 * and should be ignored in all other cases.
184 */
185 uint32_t bound_left; ///< Distance from the left edge
186 uint32_t bound_top; ///< Distance from the top edge
187 uint32_t bound_right; ///< Distance from the right edge
188 uint32_t bound_bottom; ///< Distance from the bottom edge
189 /**
190 * @}
191 */
192
193 /**
194 * Number of pixels to pad from the edge of each cube face.
195 *
196 * @note This value is valid for only for the cubemap projection type
197 * (@ref AV_SPHERICAL_CUBEMAP), and should be ignored in all other
198 * cases.
199 */
200 uint32_t padding;
201 } AVSphericalMapping;
202
203 /**
204 * Allocate a AVSphericalVideo structure and initialize its fields to default
205 * values.
206 *
207 * @return the newly allocated struct or NULL on failure
208 */
209 AVSphericalMapping *av_spherical_alloc(size_t *size);
210
211 /**
212 * Convert the @ref bounding fields from an AVSphericalVideo
213 * from 0.32 fixed point to pixels.
214 *
215 * @param map The AVSphericalVideo map to read bound values from.
216 * @param width Width of the current frame or stream.
217 * @param height Height of the current frame or stream.
218 * @param left Pixels from the left edge.
219 * @param top Pixels from the top edge.
220 * @param right Pixels from the right edge.
221 * @param bottom Pixels from the bottom edge.
222 */
223 void av_spherical_tile_bounds(const AVSphericalMapping *map,
224 size_t width, size_t height,
225 size_t *left, size_t *top,
226 size_t *right, size_t *bottom);
227
228 /**
229 * Provide a human-readable name of a given AVSphericalProjection.
230 *
231 * @param projection The input AVSphericalProjection.
232 *
233 * @return The name of the AVSphericalProjection, or "unknown".
234 */
235 const char *av_spherical_projection_name(enum AVSphericalProjection projection);
236
237 /**
238 * Get the AVSphericalProjection form a human-readable name.
239 *
240 * @param name The input string.
241 *
242 * @return The AVSphericalProjection value, or -1 if not found.
243 */
244 int av_spherical_from_name(const char *name);
245 /**
246 * @}
247 */
248
249 #endif /* AVUTIL_SPHERICAL_H */