FFmpeg
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 int ff_fill_ayuv_map(uint8_t *ayuv_map, enum AVPixelFormat pix_fmt);
33 
34 #define MAX_PLANES 4
35 
36 typedef struct FFDrawContext {
37  const struct AVPixFmtDescriptor *desc;
39  unsigned nb_planes;
40  int pixelstep[MAX_PLANES]; /*< offset between pixels */
41  uint8_t hsub[MAX_PLANES]; /*< horizontal subsampling */
42  uint8_t vsub[MAX_PLANES]; /*< vertical subsampling */
43  uint8_t hsub_max;
44  uint8_t vsub_max;
46  unsigned flags;
48  double rgb2yuv[3][3];
50 
51 typedef struct FFDrawColor {
52  uint8_t rgba[4];
53  union {
54  uint32_t u32[4];
55  uint16_t u16[8];
56  uint8_t u8[16];
57  } comp[MAX_PLANES];
58 } FFDrawColor;
59 
60 /**
61  * Process alpha pixel component.
62  */
63 #define FF_DRAW_PROCESS_ALPHA 1
64 
65 /**
66  * Init a draw context.
67  *
68  * Only a limited number of pixel formats are supported, if format is not
69  * supported the function will return an error.
70  * @param format pixel format of the frames that will be drawn onto
71  * @param csp color space of the frames that will be drawn onto,
72  * defaulting to BT601 or RGB depending on the specified format
73  * when AVCOL_SPC_UNSPECIFIED is passed.
74  * @param range sample value range of the frames that will be drawn onto,
75  * defaulting to TV-range unless using a legacy J format
76  * when AVCOL_RANGE_UNSPECIFIED is passed.
77  * @param flags combination of FF_DRAW_* flags.
78  * @return 0 for success, < 0 for error
79  */
81  enum AVColorRange range, unsigned flags);
82 
83 /*
84  * Legacy wrapper for ff_draw_init2.
85  */
87 
88 
89 
90 /**
91  * Prepare a color. The rgba value passed is always 8-bit full-range in the RGB space
92  * corresponding to the space set at initialization.
93  */
94 void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4]);
95 
96 /**
97  * Copy a rectangle from an image to another.
98  *
99  * The coordinates must be as even as the subsampling requires.
100  */
102  uint8_t *dst[], int dst_linesize[],
103  uint8_t *src[], int src_linesize[],
104  int dst_x, int dst_y, int src_x, int src_y,
105  int w, int h);
106 
107 /**
108  * Fill a rectangle with an uniform color.
109  *
110  * The coordinates must be as even as the subsampling requires.
111  * The color needs to be inited with ff_draw_color.
112  */
114  uint8_t *dst[], int dst_linesize[],
115  int dst_x, int dst_y, int w, int h);
116 
117 /**
118  * Blend a rectangle with an uniform color.
119  */
121  uint8_t *dst[], int dst_linesize[],
122  int dst_w, int dst_h,
123  int x0, int y0, int w, int h);
124 
125 /**
126  * Blend an alpha mask with an uniform color.
127  *
128  * @param draw draw context
129  * @param color color for the overlay;
130  * @param dst destination image
131  * @param dst_linesize line stride of the destination
132  * @param dst_w width of the destination image
133  * @param dst_h height of the destination image
134  * @param mask mask
135  * @param mask_linesize line stride of the mask
136  * @param mask_w width of the mask
137  * @param mask_h height of the mask
138  * @param l2depth log2 of depth of the mask (0 for 1bpp, 3 for 8bpp)
139  * @param endianness bit order of the mask (0: MSB to the left)
140  * @param x0 horizontal position of the overlay
141  * @param y0 vertical position of the overlay
142  */
144  uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h,
145  const uint8_t *mask, int mask_linesize, int mask_w, int mask_h,
146  int l2depth, unsigned endianness, int x0, int y0);
147 
148 /**
149  * Round a dimension according to subsampling.
150  *
151  * @param draw draw context
152  * @param sub_dir 0 for horizontal, 1 for vertical
153  * @param round_dir 0 nearest, -1 round down, +1 round up
154  * @param value value to round
155  * @return the rounded value
156  */
157 int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir,
158  int value);
159 
160 /**
161  * Return the list of pixel formats supported by the draw functions.
162  *
163  * The flags are the same as ff_draw_init, i.e., none currently.
164  */
166 
167 #endif /* AVFILTER_DRAWUTILS_H */
FFDrawColor
Definition: drawutils.h:51
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
color
Definition: vf_paletteuse.c:513
mask
int mask
Definition: mediacodecdec_common.c:154
FFDrawContext::hsub_max
uint8_t hsub_max
Definition: drawutils.h:43
FFDrawContext::desc
const struct AVPixFmtDescriptor * desc
Definition: drawutils.h:37
w
uint8_t w
Definition: llviddspenc.c:38
FFDrawColor::u16
uint16_t u16[8]
Definition: drawutils.h:55
ff_fill_rgba_map
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:79
FFDrawColor::rgba
uint8_t rgba[4]
Definition: drawutils.h:52
ff_blend_mask
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:549
ff_draw_color
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:171
ff_blend_rectangle
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:368
FFDrawContext::nb_planes
unsigned nb_planes
Definition: drawutils.h:39
FFDrawContext::pixelstep
int pixelstep[MAX_PLANES]
Definition: drawutils.h:40
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
FFDrawContext::vsub_max
uint8_t vsub_max
Definition: drawutils.h:44
FFDrawContext::rgb2yuv
double rgb2yuv[3][3]
Definition: drawutils.h:48
ff_draw_init
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Definition: drawutils.c:166
ff_draw_init2
int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSpace csp, enum AVColorRange range, unsigned flags)
Init a draw context.
Definition: drawutils.c:95
FFDrawContext::vsub
uint8_t vsub[MAX_PLANES]
Definition: drawutils.h:42
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
ff_fill_rectangle
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:246
FFDrawContext::csp
enum AVColorSpace csp
Definition: drawutils.h:47
FFDrawColor::u8
uint8_t u8[16]
Definition: drawutils.h:56
ff_copy_rectangle2
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:224
ff_fill_ayuv_map
int ff_fill_ayuv_map(uint8_t *ayuv_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:87
FFDrawColor::comp
union FFDrawColor::@314 comp[MAX_PLANES]
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
FFDrawColor::u32
uint32_t u32[4]
Definition: drawutils.h:54
FFDrawContext::format
enum AVPixelFormat format
Definition: drawutils.h:38
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2464
draw
static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: avf_showcwt.c:440
ff_draw_round_to_sub
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:650
MAX_PLANES
#define MAX_PLANES
Definition: drawutils.h:34
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:640
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
FFDrawContext
Definition: drawutils.h:36
ff_draw_supported_pixel_formats
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
Definition: drawutils.c:662
pixfmt.h
FFDrawContext::hsub
uint8_t hsub[MAX_PLANES]
Definition: drawutils.h:41
avfilter.h
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
FFDrawContext::range
enum AVColorRange range
Definition: drawutils.h:45
FFDrawContext::flags
unsigned flags
Definition: drawutils.h:46
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
h
h
Definition: vp9dsp_template.c:2070
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:682
src
#define src
Definition: vp8dsp.c:248