display.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2014 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. #ifndef AVUTIL_DISPLAY_H
  21. #define AVUTIL_DISPLAY_H
  22. #include <stdint.h>
  23. /**
  24. * The display transformation matrix specifies an affine transformation that
  25. * should be applied to video frames for correct presentation. It is compatible
  26. * with the matrices stored in the ISO/IEC 14496-12 container format.
  27. *
  28. * The data is a 3x3 matrix represented as a 9-element array:
  29. *
  30. * | a b u |
  31. * (a, b, u, c, d, v, x, y, w) -> | c d v |
  32. * | x y w |
  33. *
  34. * All numbers are stored in native endianness, as 16.16 fixed-point values,
  35. * except for u, v and w, which are stored as 2.30 fixed-point values.
  36. *
  37. * The transformation maps a point (p, q) in the source (pre-transformation)
  38. * frame to the point (p', q') in the destination (post-transformation) frame as
  39. * follows:
  40. * | a b u |
  41. * (p, q, 1) . | c d v | = z * (p', q', 1)
  42. * | x y w |
  43. *
  44. * The transformation can also be more explicitly written in components as
  45. * follows:
  46. * p' = (a * p + c * q + x) / z;
  47. * q' = (b * p + d * q + y) / z;
  48. * z = u * p + v * q + w
  49. */
  50. /**
  51. * Extract the rotation component of the transformation matrix.
  52. *
  53. * @param matrix the transformation matrix
  54. * @return the angle (in degrees) by which the transformation rotates the frame.
  55. * The angle will be in range [-180.0, 180.0], or NaN if the matrix is
  56. * singular.
  57. *
  58. * @note floating point numbers are inherently inexact, so callers are
  59. * recommended to round the return value to nearest integer before use.
  60. */
  61. double av_display_rotation_get(const int32_t matrix[9]);
  62. /**
  63. * Initialize a transformation matrix describing a pure rotation by the
  64. * specified angle (in degrees).
  65. *
  66. * @param matrix an allocated transformation matrix (will be fully overwritten
  67. * by this function)
  68. * @param angle rotation angle in degrees.
  69. */
  70. void av_display_rotation_set(int32_t matrix[9], double angle);
  71. /**
  72. * Flip the input matrix horizontally and/or vertically.
  73. *
  74. * @param matrix an allocated transformation matrix
  75. * @param hflip whether the matrix should be flipped horizontally
  76. * @param vflip whether the matrix should be flipped vertically
  77. */
  78. void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip);
  79. #endif /* AVUTIL_DISPLAY_H */