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.

126 lines
4.2KB

  1. /*
  2. * Copyright (C) 2010 Georg Martius <georg.martius@web.de>
  3. * Copyright (C) 2010 Daniel G. Taylor <dan@programmer-art.org>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * transform input video
  24. *
  25. * All matrices are defined as a single 9-item block of contiguous memory. For
  26. * example, the identity matrix would be:
  27. *
  28. * float *matrix = {1, 0, 0,
  29. * 0, 1, 0,
  30. * 0, 0, 1};
  31. */
  32. enum InterpolateMethod {
  33. INTERPOLATE_NEAREST, //< Nearest-neighbor (fast)
  34. INTERPOLATE_BILINEAR, //< Bilinear
  35. INTERPOLATE_BIQUADRATIC, //< Biquadratic (best)
  36. INTERPOLATE_COUNT, //< Number of interpolation methods
  37. };
  38. // Shortcuts for the fastest and best interpolation methods
  39. #define INTERPOLATE_DEFAULT INTERPOLATE_BILINEAR
  40. #define INTERPOLATE_FAST INTERPOLATE_NEAREST
  41. #define INTERPOLATE_BEST INTERPOLATE_BIQUADRATIC
  42. enum FillMethod {
  43. FILL_BLANK, //< Fill zeroes at blank locations
  44. FILL_ORIGINAL, //< Original image at blank locations
  45. FILL_CLAMP, //< Extruded edge value at blank locations
  46. FILL_MIRROR, //< Mirrored edge at blank locations
  47. FILL_COUNT, //< Number of edge fill methods
  48. };
  49. // Shortcuts for fill methods
  50. #define FILL_DEFAULT FILL_ORIGINAL
  51. /**
  52. * Get an affine transformation matrix from a given translation, rotation, and
  53. * zoom factor. The matrix will look like:
  54. *
  55. * [ zoom * cos(angle), -sin(angle), x_shift,
  56. * sin(angle), zoom * cos(angle), y_shift,
  57. 0, 0, 1 ]
  58. *
  59. * Paramters:
  60. * x_shift: Horizontal translation
  61. * y_shift: Vertical translation
  62. * angle: Rotation in radians
  63. * zoom: Scale percent (1.0 = 100%)
  64. * matrix: 9-item affine transformation matrix
  65. */
  66. void avfilter_get_matrix(float x_shift, float y_shift, float angle, float zoom, float *matrix);
  67. /**
  68. * Add two matrices together. result = m1 + m2.
  69. *
  70. * Parameters:
  71. * m1: 9-item transformation matrix
  72. * m2: 9-item transformation matrix
  73. * result: 9-item transformation matrix
  74. */
  75. void avfilter_add_matrix(const float *m1, const float *m2, float *result);
  76. /**
  77. * Subtract one matrix from another. result = m1 - m2.
  78. *
  79. * Parameters:
  80. * m1: 9-item transformation matrix
  81. * m2: 9-item transformation matrix
  82. * result: 9-item transformation matrix
  83. */
  84. void avfilter_sub_matrix(const float *m1, const float *m2, float *result);
  85. /**
  86. * Multiply a matrix by a scalar value. result = m1 * scalar.
  87. *
  88. * Parameters:
  89. * m1: 9-item transformation matrix
  90. * scalar: A number
  91. * result: 9-item transformation matrix
  92. */
  93. void avfilter_mul_matrix(const float *m1, float scalar, float *result);
  94. /**
  95. * Do an affine transformation with the given interpolation method. This
  96. * multiplies each vector [x,y,1] by the matrix and then interpolates to
  97. * get the final value.
  98. *
  99. * Parameters:
  100. * src: Source image
  101. * dst: Destination image
  102. * src_stride: Source image line size in bytes
  103. * dst_stride: Destination image line size in bytes
  104. * width: Image width in pixels
  105. * height: Image height in pixels
  106. * matrix: 9-item affine transformation matrix
  107. * interpolate: Pixel interpolation method
  108. * fill: Edge fill method
  109. */
  110. void avfilter_transform(const uint8_t *src, uint8_t *dst,
  111. int src_stride, int dst_stride,
  112. int width, int height, const float *matrix,
  113. enum InterpolateMethod interpolate,
  114. enum FillMethod fill);