FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
drawutils.h
Go to the documentation of this file.
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 
19 #ifndef AVFILTER_DRAWUTILS_H
20 #define AVFILTER_DRAWUTILS_H
21 
22 /**
23  * @file
24  * misc drawing utilities
25  */
26 
27 #include <stdint.h>
28 #include "avfilter.h"
29 #include "libavutil/pixfmt.h"
30 
31 int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt);
32 
33 int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w,
34  uint8_t dst_color[4],
35  enum AVPixelFormat pix_fmt, uint8_t rgba_color[4],
36  int *is_packed_rgba, uint8_t rgba_map[4]);
37 
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);
41 
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);
45 
46 #define MAX_PLANES 4
47 
48 typedef struct FFDrawContext {
49  const struct AVPixFmtDescriptor *desc;
51  unsigned nb_planes;
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 */
59  unsigned flags;
61 
62 typedef struct FFDrawColor {
64  union {
65  uint32_t u32[4];
66  uint16_t u16[8];
67  uint8_t u8[16];
68  } comp[MAX_PLANES];
69 } FFDrawColor;
70 
71 /**
72  * Process alpha pixel component.
73  */
74 #define FF_DRAW_PROCESS_ALPHA 1
75 
76 /**
77  * Init a draw context.
78  *
79  * Only a limited number of pixel formats are supported, if format is not
80  * supported the function will return an error.
81  * flags is combination of FF_DRAW_* flags.
82  * @return 0 for success, < 0 for error
83  */
84 int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags);
85 
86 /**
87  * Prepare a color.
88  */
89 void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4]);
90 
91 /**
92  * Copy a rectangle from an image to another.
93  *
94  * The coordinates must be as even as the subsampling requires.
95  */
97  uint8_t *dst[], int dst_linesize[],
98  uint8_t *src[], int src_linesize[],
99  int dst_x, int dst_y, int src_x, int src_y,
100  int w, int h);
101 
102 /**
103  * Fill a rectangle with an uniform color.
104  *
105  * The coordinates must be as even as the subsampling requires.
106  * The color needs to be inited with ff_draw_color.
107  */
109  uint8_t *dst[], int dst_linesize[],
110  int dst_x, int dst_y, int w, int h);
111 
112 /**
113  * Blend a rectangle with an uniform color.
114  */
116  uint8_t *dst[], int dst_linesize[],
117  int dst_w, int dst_h,
118  int x0, int y0, int w, int h);
119 
120 /**
121  * Blend an alpha mask with an uniform color.
122  *
123  * @param draw draw context
124  * @param color color for the overlay;
125  * @param dst destination image
126  * @param dst_linesize line stride of the destination
127  * @param dst_w width of the destination image
128  * @param dst_h height of the destination image
129  * @param mask mask
130  * @param mask_linesize line stride of the mask
131  * @param mask_w width of the mask
132  * @param mask_h height of the mask
133  * @param l2depth log2 of depth of the mask (0 for 1bpp, 3 for 8bpp)
134  * @param endianness bit order of the mask (0: MSB to the left)
135  * @param x0 horizontal position of the overlay
136  * @param y0 vertical position of the overlay
137  */
139  uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h,
140  const uint8_t *mask, int mask_linesize, int mask_w, int mask_h,
141  int l2depth, unsigned endianness, int x0, int y0);
142 
143 /**
144  * Round a dimension according to subsampling.
145  *
146  * @param draw draw context
147  * @param sub_dir 0 for horizontal, 1 for vertical
148  * @param round_dir 0 nearest, -1 round down, +1 round up
149  * @param value value to round
150  * @return the rounded value
151  */
152 int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir,
153  int value);
154 
155 /**
156  * Return the list of pixel formats supported by the draw functions.
157  *
158  * The flags are the same as ff_draw_init, i.e., none currently.
159  */
161 
162 #endif /* AVFILTER_DRAWUTILS_H */
void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, const uint8_t *mask, int mask_linesize, int mask_w, int mask_h, int l2depth, unsigned endianness, int x0, int y0)
Blend an alpha mask with an uniform color.
Definition: drawutils.c:622
#define MAX_PLANES
Definition: drawutils.h:46
static enum AVPixelFormat pix_fmt
static const char * format[]
Definition: af_aiir.c:330
uint16_t u16[8]
Definition: drawutils.h:66
uint8_t hsub[MAX_PLANES]
Definition: drawutils.h:54
Main libavfilter public API header.
uint32_t u32[4]
Definition: drawutils.h:65
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
Definition: drawutils.c:178
#define src
Definition: vp8dsp.c:254
int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w, uint8_t dst_color[4], enum AVPixelFormat pix_fmt, uint8_t rgba_color[4], int *is_packed_rgba, uint8_t rgba_map[4])
Definition: drawutils.c:80
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
Definition: drawutils.c:731
uint8_t
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:231
uint8_t comp_mask[MAX_PLANES]
Definition: drawutils.h:53
union FFDrawColor::@206 comp[MAX_PLANES]
static const uint16_t mask[17]
Definition: lzw.c:38
Definition: graph2dot.c:48
uint8_t vsub_max
Definition: drawutils.h:57
uint8_t u8[16]
Definition: drawutils.h:67
unsigned flags
Definition: drawutils.h:59
uint8_t w
Definition: llviddspenc.c:38
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
void ff_copy_rectangle2(FFDrawContext *draw, uint8_t *dst[], int dst_linesize[], uint8_t *src[], int src_linesize[], int dst_x, int dst_y, int src_x, int src_y, int w, int h)
Copy a rectangle from an image to another.
Definition: drawutils.c:296
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:35
unsigned nb_planes
Definition: drawutils.h:51
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
int full_range
Definition: drawutils.h:58
uint8_t hsub_max
Definition: drawutils.h:56
void ff_copy_rectangle(uint8_t *dst[4], int dst_linesize[4], uint8_t *src[4], int src_linesize[4], int pixelstep[4], int hsub, int vsub, int x, int y, int y2, int w, int h)
Definition: drawutils.c:156
#define flags(name, subs,...)
Definition: cbs_av1.c:596
void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, int x0, int y0, int w, int h)
Blend a rectangle with an uniform color.
Definition: drawutils.c:445
void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_x, int dst_y, int w, int h)
Fill a rectangle with an uniform color.
Definition: drawutils.c:318
pixel format definitions
int pixelstep[MAX_PLANES]
Definition: drawutils.h:52
A list of supported formats for one end of a filter link.
Definition: formats.h:64
const struct AVPixFmtDescriptor * desc
Definition: drawutils.h:49
void ff_draw_rectangle(uint8_t *dst[4], int dst_linesize[4], uint8_t *src[4], int pixelstep[4], int hsub, int vsub, int x, int y, int w, int h)
Definition: drawutils.c:134
uint8_t vsub[MAX_PLANES]
Definition: drawutils.h:55
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir, int value)
Round a dimension according to subsampling.
Definition: drawutils.c:719
enum AVPixelFormat format
Definition: drawutils.h:50
uint8_t rgba[4]
Definition: drawutils.h:63