2 * This file is part of FFmpeg.
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.
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.
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
19 #ifndef AVFILTER_DRAWUTILS_H
20 #define AVFILTER_DRAWUTILS_H
24 * misc drawing utilities
29 #include "libavutil/pixfmt.h"
31 int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt);
33 int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w,
35 enum AVPixelFormat pix_fmt, uint8_t rgba_color[4],
36 int *is_packed_rgba, uint8_t rgba_map[4]);
38 void ff_draw_rectangle(uint8_t *dst[4], int dst_linesize[4],
39 uint8_t *src[4], int pixelstep[4],
40 int hsub, int vsub, int x, int y, int w, int h);
42 void ff_copy_rectangle(uint8_t *dst[4], int dst_linesize[4],
43 uint8_t *src[4], int src_linesize[4], int pixelstep[4],
44 int hsub, int vsub, int x, int y, int y2, int w, int h);
48 typedef struct FFDrawContext {
49 const struct AVPixFmtDescriptor *desc;
50 enum AVPixelFormat format;
52 int pixelstep[MAX_PLANES]; /*< offset between pixels */
53 uint8_t comp_mask[MAX_PLANES]; /*< bitmask of used non-alpha components */
54 uint8_t hsub[MAX_PLANES]; /*< horizontal subsampling */
55 uint8_t vsub[MAX_PLANES]; /*< vertical subsampling */
61 typedef struct FFDrawColor {
71 * Process alpha pixel component.
73 #define FF_DRAW_PROCESS_ALPHA 1
76 * Init a draw context.
78 * Only a limited number of pixel formats are supported, if format is not
79 * supported the function will return an error.
80 * flags is combination of FF_DRAW_* flags.
81 * @return 0 for success, < 0 for error
83 int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags);
88 void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4]);
91 * Copy a rectangle from an image to another.
93 * The coordinates must be as even as the subsampling requires.
95 void ff_copy_rectangle2(FFDrawContext *draw,
96 uint8_t *dst[], int dst_linesize[],
97 uint8_t *src[], int src_linesize[],
98 int dst_x, int dst_y, int src_x, int src_y,
102 * Fill a rectangle with an uniform color.
104 * The coordinates must be as even as the subsampling requires.
105 * The color needs to be inited with ff_draw_color.
107 void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color,
108 uint8_t *dst[], int dst_linesize[],
109 int dst_x, int dst_y, int w, int h);
112 * Blend a rectangle with an uniform color.
114 void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color,
115 uint8_t *dst[], int dst_linesize[],
116 int dst_w, int dst_h,
117 int x0, int y0, int w, int h);
120 * Blend an alpha mask with an uniform color.
122 * @param draw draw context
123 * @param color color for the overlay;
124 * @param dst destination image
125 * @param dst_linesize line stride of the destination
126 * @param dst_w width of the destination image
127 * @param dst_h height of the destination image
129 * @param mask_linesize line stride of the mask
130 * @param mask_w width of the mask
131 * @param mask_h height of the mask
132 * @param l2depth log2 of depth of the mask (0 for 1bpp, 3 for 8bpp)
133 * @param endianness bit order of the mask (0: MSB to the left)
134 * @param x0 horizontal position of the overlay
135 * @param y0 vertical position of the overlay
137 void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color,
138 uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h,
139 const uint8_t *mask, int mask_linesize, int mask_w, int mask_h,
140 int l2depth, unsigned endianness, int x0, int y0);
143 * Round a dimension according to subsampling.
145 * @param draw draw context
146 * @param sub_dir 0 for horizontal, 1 for vertical
147 * @param round_dir 0 nearest, -1 round down, +1 round up
148 * @param value value to round
149 * @return the rounded value
151 int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir,
155 * Return the list of pixel formats supported by the draw functions.
157 * The flags are the same as ff_draw_init, i.e., none currently.
159 AVFilterFormats *ff_draw_supported_pixel_formats(unsigned flags);
161 #endif /* AVFILTER_DRAWUTILS_H */