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.

150 lines
4.8KB

  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 AVPixelFormat pix_fmt);
  28. #define MAX_PLANES 4
  29. typedef struct FFDrawContext {
  30. const struct AVPixFmtDescriptor *desc;
  31. enum AVPixelFormat format;
  32. unsigned nb_planes;
  33. int pixelstep[MAX_PLANES]; /*< offset between pixels */
  34. uint8_t comp_mask[MAX_PLANES]; /*< bitmask of used non-alpha components */
  35. uint8_t hsub[MAX_PLANES]; /*< horizontal subsampling */
  36. uint8_t vsub[MAX_PLANES]; /*< vertical subsampling */
  37. uint8_t hsub_max;
  38. uint8_t vsub_max;
  39. int full_range;
  40. unsigned flags;
  41. } FFDrawContext;
  42. typedef struct FFDrawColor {
  43. uint8_t rgba[4];
  44. union {
  45. uint32_t u32[4];
  46. uint16_t u16[8];
  47. uint8_t u8[16];
  48. } comp[MAX_PLANES];
  49. } FFDrawColor;
  50. /**
  51. * Process alpha pixel component.
  52. */
  53. #define FF_DRAW_PROCESS_ALPHA 1
  54. /**
  55. * Init a draw context.
  56. *
  57. * Only a limited number of pixel formats are supported, if format is not
  58. * supported the function will return an error.
  59. * flags is combination of FF_DRAW_* flags.
  60. * @return 0 for success, < 0 for error
  61. */
  62. int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags);
  63. /**
  64. * Prepare a color.
  65. */
  66. void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4]);
  67. /**
  68. * Copy a rectangle from an image to another.
  69. *
  70. * The coordinates must be as even as the subsampling requires.
  71. */
  72. void ff_copy_rectangle2(FFDrawContext *draw,
  73. uint8_t *dst[], int dst_linesize[],
  74. uint8_t *src[], int src_linesize[],
  75. int dst_x, int dst_y, int src_x, int src_y,
  76. int w, int h);
  77. /**
  78. * Fill a rectangle with an uniform color.
  79. *
  80. * The coordinates must be as even as the subsampling requires.
  81. * The color needs to be inited with ff_draw_color.
  82. */
  83. void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color,
  84. uint8_t *dst[], int dst_linesize[],
  85. int dst_x, int dst_y, int w, int h);
  86. /**
  87. * Blend a rectangle with an uniform color.
  88. */
  89. void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color,
  90. uint8_t *dst[], int dst_linesize[],
  91. int dst_w, int dst_h,
  92. int x0, int y0, int w, int h);
  93. /**
  94. * Blend an alpha mask with an uniform color.
  95. *
  96. * @param draw draw context
  97. * @param color color for the overlay;
  98. * @param dst destination image
  99. * @param dst_linesize line stride of the destination
  100. * @param dst_w width of the destination image
  101. * @param dst_h height of the destination image
  102. * @param mask mask
  103. * @param mask_linesize line stride of the mask
  104. * @param mask_w width of the mask
  105. * @param mask_h height of the mask
  106. * @param l2depth log2 of depth of the mask (0 for 1bpp, 3 for 8bpp)
  107. * @param endianness bit order of the mask (0: MSB to the left)
  108. * @param x0 horizontal position of the overlay
  109. * @param y0 vertical position of the overlay
  110. */
  111. void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color,
  112. uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h,
  113. const uint8_t *mask, int mask_linesize, int mask_w, int mask_h,
  114. int l2depth, unsigned endianness, int x0, int y0);
  115. /**
  116. * Round a dimension according to subsampling.
  117. *
  118. * @param draw draw context
  119. * @param sub_dir 0 for horizontal, 1 for vertical
  120. * @param round_dir 0 nearest, -1 round down, +1 round up
  121. * @param value value to round
  122. * @return the rounded value
  123. */
  124. int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir,
  125. int value);
  126. /**
  127. * Return the list of pixel formats supported by the draw functions.
  128. *
  129. * The flags are the same as ff_draw_init, i.e., none currently.
  130. */
  131. AVFilterFormats *ff_draw_supported_pixel_formats(unsigned flags);
  132. #endif /* AVFILTER_DRAWUTILS_H */