2 * Copyright (c) 2016 Vittorio Giovara <vittorio.giovara@gmail.com>
4 * This file is part of FFmpeg.
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.
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.
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
26 #ifndef AVUTIL_SPHERICAL_H
27 #define AVUTIL_SPHERICAL_H
33 * @addtogroup lavu_video
36 * @defgroup lavu_video_spherical Spherical video mapping
41 * @addtogroup lavu_video_spherical
42 * A spherical video file contains surfaces that need to be mapped onto a
43 * sphere. Depending on how the frame was converted, a different distortion
44 * transformation or surface recomposition function needs to be applied before
45 * the video should be mapped and displayed.
49 * Projection of the video surface(s) on a sphere.
51 enum AVSphericalProjection {
53 * Video represents a sphere mapped on a flat surface using
54 * equirectangular projection.
56 AV_SPHERICAL_EQUIRECTANGULAR,
59 * Video frame is split into 6 faces of a cube, and arranged on a
60 * 3x2 layout. Faces are oriented upwards for the front, left, right,
61 * and back faces. The up face is oriented so the top of the face is
62 * forwards and the down face is oriented so the top of the face is
68 * Video represents a portion of a sphere mapped on a flat surface
69 * using equirectangular projection. The @ref bounding fields indicate
70 * the position of the current video in a larger surface.
72 AV_SPHERICAL_EQUIRECTANGULAR_TILE,
76 * This structure describes how to handle spherical videos, outlining
77 * information about projection, initial layout, and any other view modifier.
79 * @note The struct must be allocated with av_spherical_alloc() and
80 * its size is not a part of the public ABI.
82 typedef struct AVSphericalMapping {
86 enum AVSphericalProjection projection;
89 * @name Initial orientation
91 * There fields describe additional rotations applied to the sphere after
92 * the video frame is mapped onto it. The sphere is rotated around the
93 * viewer, who remains stationary. The order of transformation is always
94 * yaw, followed by pitch, and finally by roll.
96 * The coordinate system matches the one defined in OpenGL, where the
97 * forward vector (z) is coming out of screen, and it is equivalent to
98 * a rotation matrix of R = r_y(yaw) * r_x(pitch) * r_z(roll).
100 * A positive yaw rotates the portion of the sphere in front of the viewer
101 * toward their right. A positive pitch rotates the portion of the sphere
102 * in front of the viewer upwards. A positive roll tilts the portion of
103 * the sphere in front of the viewer to the viewer's right.
105 * These values are exported as 16.16 fixed point.
107 * See this equirectangular projection as example:
112 * 90 +-------------+-------------+ 180
116 * t 0 +-------------X-------------+ 0 Roll | /
118 * h | | | 0|/_____right
120 * -90 +-------------+-------------+ -180
122 * X - the default camera center
123 * ^ - the default up vector
126 int32_t yaw; ///< Rotation around the up vector [-180, 180].
127 int32_t pitch; ///< Rotation around the right vector [-90, 90].
128 int32_t roll; ///< Rotation around the forward vector [-180, 180].
134 * @name Bounding rectangle
137 * These fields indicate the location of the current tile, and where
138 * it should be mapped relative to the original surface. They are
139 * exported as 0.32 fixed point, and can be converted to classic
140 * pixel values with av_spherical_bounds().
143 * +----------------+----------+
146 * | bound_left |tile | |
147 * +<---------->| |<--->+bound_right
151 * +----------------+----------+
154 * If needed, the original video surface dimensions can be derived
155 * by adding the current stream or frame size to the related bounds,
156 * like in the following example:
159 * original_width = tile->width + bound_left + bound_right;
160 * original_height = tile->height + bound_top + bound_bottom;
163 * @note These values are valid only for the tiled equirectangular
164 * projection type (@ref AV_SPHERICAL_EQUIRECTANGULAR_TILE),
165 * and should be ignored in all other cases.
167 uint32_t bound_left; ///< Distance from the left edge
168 uint32_t bound_top; ///< Distance from the top edge
169 uint32_t bound_right; ///< Distance from the right edge
170 uint32_t bound_bottom; ///< Distance from the bottom edge
176 * Number of pixels to pad from the edge of each cube face.
178 * @note This value is valid for only for the cubemap projection type
179 * (@ref AV_SPHERICAL_CUBEMAP), and should be ignored in all other
183 } AVSphericalMapping;
186 * Allocate a AVSphericalVideo structure and initialize its fields to default
189 * @return the newly allocated struct or NULL on failure
191 AVSphericalMapping *av_spherical_alloc(size_t *size);
194 * Convert the @ref bounding fields from an AVSphericalVideo
195 * from 0.32 fixed point to pixels.
197 * @param map The AVSphericalVideo map to read bound values from.
198 * @param width Width of the current frame or stream.
199 * @param height Height of the current frame or stream.
200 * @param left Pixels from the left edge.
201 * @param top Pixels from the top edge.
202 * @param right Pixels from the right edge.
203 * @param bottom Pixels from the bottom edge.
205 void av_spherical_tile_bounds(const AVSphericalMapping *map,
206 size_t width, size_t height,
207 size_t *left, size_t *top,
208 size_t *right, size_t *bottom);
211 * Provide a human-readable name of a given AVSphericalProjection.
213 * @param projection The input AVSphericalProjection.
215 * @return The name of the AVSphericalProjection, or "unknown".
217 const char *av_spherical_projection_name(enum AVSphericalProjection projection);
220 * Get the AVSphericalProjection form a human-readable name.
222 * @param name The input string.
224 * @return The AVSphericalProjection value, or -1 if not found.
226 int av_spherical_from_name(const char *name);
232 #endif /* AVUTIL_SPHERICAL_H */