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.

136 lines
4.5KB

  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. #ifndef AVFILTER_TRANSFORM_H
  22. #define AVFILTER_TRANSFORM_H
  23. #include <stdint.h>
  24. /**
  25. * @file
  26. * transform input video
  27. *
  28. * All matrices are defined as a single 9-item block of contiguous memory. For
  29. * example, the identity matrix would be:
  30. *
  31. * float *matrix = {1, 0, 0,
  32. * 0, 1, 0,
  33. * 0, 0, 1};
  34. */
  35. enum InterpolateMethod {
  36. INTERPOLATE_NEAREST, //< Nearest-neighbor (fast)
  37. INTERPOLATE_BILINEAR, //< Bilinear
  38. INTERPOLATE_BIQUADRATIC, //< Biquadratic (best)
  39. INTERPOLATE_COUNT, //< Number of interpolation methods
  40. };
  41. // Shortcuts for the fastest and best interpolation methods
  42. #define INTERPOLATE_DEFAULT INTERPOLATE_BILINEAR
  43. #define INTERPOLATE_FAST INTERPOLATE_NEAREST
  44. #define INTERPOLATE_BEST INTERPOLATE_BIQUADRATIC
  45. enum FillMethod {
  46. FILL_BLANK, //< Fill zeroes at blank locations
  47. FILL_ORIGINAL, //< Original image at blank locations
  48. FILL_CLAMP, //< Extruded edge value at blank locations
  49. FILL_MIRROR, //< Mirrored edge at blank locations
  50. FILL_COUNT, //< Number of edge fill methods
  51. };
  52. // Shortcuts for fill methods
  53. #define FILL_DEFAULT FILL_ORIGINAL
  54. /**
  55. * Get an affine transformation matrix from given translation, rotation, and
  56. * zoom factors. The matrix will look like:
  57. *
  58. * [ scale_x * cos(angle), -sin(angle), x_shift,
  59. * sin(angle), scale_y * cos(angle), y_shift,
  60. * 0, 0, 1 ]
  61. *
  62. * @param x_shift horizontal translation
  63. * @param y_shift vertical translation
  64. * @param angle rotation in radians
  65. * @param scale_x x scale percent (1.0 = 100%)
  66. * @param scale_y y scale percent (1.0 = 100%)
  67. * @param matrix 9-item affine transformation matrix
  68. */
  69. void ff_get_matrix(
  70. float x_shift,
  71. float y_shift,
  72. float angle,
  73. float scale_x,
  74. float scale_y,
  75. float *matrix
  76. );
  77. /**
  78. * Add two matrices together. result = m1 + m2.
  79. *
  80. * @param m1 9-item transformation matrix
  81. * @param m2 9-item transformation matrix
  82. * @param result 9-item transformation matrix
  83. */
  84. void avfilter_add_matrix(const float *m1, const float *m2, float *result);
  85. /**
  86. * Subtract one matrix from another. result = m1 - m2.
  87. *
  88. * @param m1 9-item transformation matrix
  89. * @param m2 9-item transformation matrix
  90. * @param result 9-item transformation matrix
  91. */
  92. void avfilter_sub_matrix(const float *m1, const float *m2, float *result);
  93. /**
  94. * Multiply a matrix by a scalar value. result = m1 * scalar.
  95. *
  96. * @param m1 9-item transformation matrix
  97. * @param scalar a number
  98. * @param result 9-item transformation matrix
  99. */
  100. void avfilter_mul_matrix(const float *m1, float scalar, float *result);
  101. /**
  102. * Do an affine transformation with the given interpolation method. This
  103. * multiplies each vector [x,y,1] by the matrix and then interpolates to
  104. * get the final value.
  105. *
  106. * @param src source image
  107. * @param dst destination image
  108. * @param src_stride source image line size in bytes
  109. * @param dst_stride destination image line size in bytes
  110. * @param width image width in pixels
  111. * @param height image height in pixels
  112. * @param matrix 9-item affine transformation matrix
  113. * @param interpolate pixel interpolation method
  114. * @param fill edge fill method
  115. * @return negative on error
  116. */
  117. int avfilter_transform(const uint8_t *src, uint8_t *dst,
  118. int src_stride, int dst_stride,
  119. int width, int height, const float *matrix,
  120. enum InterpolateMethod interpolate,
  121. enum FillMethod fill);
  122. #endif /* AVFILTER_TRANSFORM_H */