You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
4.5KB

  1. /*
  2. * Copyright (c) 2016 Vittorio Giovara <vittorio.giovara@gmail.com>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * Spherical video
  23. */
  24. #ifndef AVUTIL_SPHERICAL_H
  25. #define AVUTIL_SPHERICAL_H
  26. /**
  27. * @addtogroup lavu_video
  28. * @{
  29. *
  30. * @defgroup lavu_video_spherical Spherical video mapping
  31. * @{
  32. */
  33. /**
  34. * @addtogroup lavu_video_spherical
  35. * A spherical video file contains surfaces that need to be mapped onto a
  36. * sphere. Depending on how the frame was converted, a different distortion
  37. * transformation or surface recomposition function needs to be applied before
  38. * the video should be mapped and displayed.
  39. */
  40. /**
  41. * Projection of the video surface(s) on a sphere.
  42. */
  43. enum AVSphericalProjection {
  44. /**
  45. * Video represents a sphere mapped on a flat surface using
  46. * equirectangular projection.
  47. */
  48. AV_SPHERICAL_EQUIRECTANGULAR,
  49. /**
  50. * Video frame is split into 6 faces of a cube, and arranged on a
  51. * 3x2 layout. Faces are oriented upwards for the front, left, right,
  52. * and back faces. The up face is oriented so the top of the face is
  53. * forwards and the down face is oriented so the top of the face is
  54. * to the back.
  55. */
  56. AV_SPHERICAL_CUBEMAP,
  57. };
  58. /**
  59. * This structure describes how to handle spherical videos, outlining
  60. * information about projection, initial layout, and any other view modifier.
  61. *
  62. * @note The struct must be allocated with av_spherical_alloc() and
  63. * its size is not a part of the public ABI.
  64. */
  65. typedef struct AVSphericalMapping {
  66. /**
  67. * Projection type.
  68. */
  69. enum AVSphericalProjection projection;
  70. /**
  71. * @name Initial orientation
  72. * @{
  73. * There fields describe additional rotations applied to the sphere after
  74. * the video frame is mapped onto it. The sphere is rotated around the
  75. * viewer, who remains stationary. The order of transformation is always
  76. * yaw, followed by pitch, and finally by roll.
  77. *
  78. * The coordinate system matches the one defined in OpenGL, where the
  79. * forward vector (z) is coming out of screen, and it is equivalent to
  80. * a rotation matrix of R = r_y(yaw) * r_x(pitch) * r_z(roll).
  81. *
  82. * A positive yaw rotates the portion of the sphere in front of the viewer
  83. * toward their right. A positive pitch rotates the portion of the sphere
  84. * in front of the viewer upwards. A positive roll tilts the portion of
  85. * the sphere in front of the viewer to the viewer's right.
  86. *
  87. * These values are exported as 16.16 fixed point.
  88. *
  89. * See this equirectangular projection as example:
  90. *
  91. * @code{.unparsed}
  92. * Yaw
  93. * -180 0 180
  94. * 90 +-------------+-------------+ 180
  95. * | | | up
  96. * P | | | y| forward
  97. * i | ^ | | /z
  98. * t 0 +-------------X-------------+ 0 Roll | /
  99. * c | | | | /
  100. * h | | | 0|/_____right
  101. * | | | x
  102. * -90 +-------------+-------------+ -180
  103. *
  104. * X - the default camera center
  105. * ^ - the default up vector
  106. * @endcode
  107. */
  108. int32_t yaw; ///< Rotation around the up vector [-180, 180].
  109. int32_t pitch; ///< Rotation around the right vector [-90, 90].
  110. int32_t roll; ///< Rotation around the forward vector [-180, 180].
  111. /**
  112. * @}
  113. */
  114. } AVSphericalMapping;
  115. /**
  116. * Allocate a AVSphericalVideo structure and initialize its fields to default
  117. * values.
  118. *
  119. * @return the newly allocated struct or NULL on failure
  120. */
  121. AVSphericalMapping *av_spherical_alloc(size_t *size);
  122. /**
  123. * @}
  124. * @}
  125. */
  126. #endif /* AVUTIL_SPHERICAL_H */