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