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