drawutils.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVFILTER_DRAWUTILS_H
  19. #define AVFILTER_DRAWUTILS_H
  20. /**
  21. * @file
  22. * misc drawing utilities
  23. */
  24. #include <stdint.h>
  25. #include "avfilter.h"
  26. #include "libavutil/pixfmt.h"
  27. int ff_fill_rgba_map(uint8_t *rgba_map, enum PixelFormat pix_fmt);
  28. int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w,
  29. uint8_t dst_color[4],
  30. enum PixelFormat pix_fmt, uint8_t rgba_color[4],
  31. int *is_packed_rgba, uint8_t rgba_map[4]);
  32. void ff_draw_rectangle(uint8_t *dst[4], int dst_linesize[4],
  33. uint8_t *src[4], int pixelstep[4],
  34. int hsub, int vsub, int x, int y, int w, int h);
  35. void ff_copy_rectangle(uint8_t *dst[4], int dst_linesize[4],
  36. uint8_t *src[4], int src_linesize[4], int pixelstep[4],
  37. int hsub, int vsub, int x, int y, int y2, int w, int h);
  38. #define MAX_PLANES 4
  39. typedef struct FFDrawContext {
  40. const struct AVPixFmtDescriptor *desc;
  41. enum PixelFormat format;
  42. unsigned nb_planes;
  43. int pixelstep[MAX_PLANES]; /*< offset between pixels */
  44. uint8_t comp_mask[MAX_PLANES]; /*< bitmask of used non-alpha components */
  45. uint8_t hsub[MAX_PLANES]; /*< horizontal subsamling */
  46. uint8_t vsub[MAX_PLANES]; /*< vertical subsamling */
  47. uint8_t hsub_max;
  48. uint8_t vsub_max;
  49. } FFDrawContext;
  50. typedef struct FFDrawColor {
  51. uint8_t rgba[4];
  52. union {
  53. uint32_t u32;
  54. uint16_t u16;
  55. uint8_t u8[4];
  56. } comp[MAX_PLANES];
  57. } FFDrawColor;
  58. /**
  59. * Init a draw context.
  60. *
  61. * Only a limited number of pixel formats are supported, if format is not
  62. * supported the function will return an error.
  63. * No flags currently defined.
  64. * @return 0 for success, < 0 for error
  65. */
  66. int ff_draw_init(FFDrawContext *draw, enum PixelFormat format, unsigned flags);
  67. /**
  68. * Prepare a color.
  69. */
  70. void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4]);
  71. /**
  72. * Copy a rectangle from an image to another.
  73. *
  74. * The coordinates must be as even as the subsampling requires.
  75. */
  76. void ff_copy_rectangle2(FFDrawContext *draw,
  77. uint8_t *dst[], int dst_linesize[],
  78. uint8_t *src[], int src_linesize[],
  79. int dst_x, int dst_y, int src_x, int src_y,
  80. int w, int h);
  81. /**
  82. * Fill a rectangle with an uniform color.
  83. *
  84. * The coordinates must be as even as the subsampling requires.
  85. * The color needs to be inited with ff_draw_color.
  86. */
  87. void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color,
  88. uint8_t *dst[], int dst_linesize[],
  89. int dst_x, int dst_y, int w, int h);
  90. /**
  91. * Blend a rectangle with an uniform color.
  92. */
  93. void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color,
  94. uint8_t *dst[], int dst_linesize[],
  95. int dst_w, int dst_h,
  96. int x0, int y0, int w, int h);
  97. /**
  98. * Blend an alpha mask with an uniform color.
  99. *
  100. * @param draw draw context
  101. * @param color color for the overlay;
  102. * @param dst destination image
  103. * @param dst_linesize line stride of the destination
  104. * @param dst_w width of the destination image
  105. * @param dst_h height of the destination image
  106. * @param mask mask
  107. * @param mask_linesize line stride of the mask
  108. * @param mask_w width of the mask
  109. * @param mask_h height of the mask
  110. * @param l2depth log2 of depth of the mask (0 for 1bpp, 3 for 8bpp)
  111. * @param endianness bit order of the mask (0: MSB to the left)
  112. * @param x0 horizontal position of the overlay
  113. * @param y0 vertical position of the overlay
  114. */
  115. void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color,
  116. uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h,
  117. uint8_t *mask, int mask_linesize, int mask_w, int mask_h,
  118. int l2depth, unsigned endianness, int x0, int y0);
  119. /**
  120. * Round a dimension according to subsampling.
  121. *
  122. * @param draw draw context
  123. * @param sub_dir 0 for horizontal, 1 for vertical
  124. * @param round_dir 0 nearest, -1 round down, +1 round up
  125. * @param value value to round
  126. * @return the rounded value
  127. */
  128. int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir,
  129. int value);
  130. /**
  131. * Return the list of pixel formats supported by the draw functions.
  132. *
  133. * The flags are the same as ff_draw_init, i.e., none currently.
  134. */
  135. AVFilterFormats *ff_draw_supported_pixel_formats(unsigned flags);
  136. #endif /* AVFILTER_DRAWUTILS_H */