FFmpeg
Loading...
Searching...
No Matches
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
31int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt);
32int ff_fill_ayuv_map(uint8_t *ayuv_map, enum AVPixelFormat pix_fmt);
33
34#define MAX_PLANES 4
35
36typedef 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;
49 double rgb2yuv[3][3];
51
52typedef struct FFDrawColor {
53 uint8_t rgba[4];
54 union {
55 uint32_t u32[4];
56 uint16_t u16[8];
57 uint8_t u8[16];
60
61/**
62 * Process alpha pixel component.
63 */
64#define FF_DRAW_PROCESS_ALPHA 1
65
66/**
67 * Init a draw context.
68 *
69 * Only a limited number of pixel formats are supported, if format is not
70 * supported the function will return an error.
71 * @param format pixel format of the frames that will be drawn onto
72 * @param csp color space of the frames that will be drawn onto,
73 * defaulting to BT601 or RGB depending on the specified format
74 * when AVCOL_SPC_UNSPECIFIED is passed.
75 * @param range sample value range of the frames that will be drawn onto,
76 * defaulting to TV-range unless using a legacy J format
77 * when AVCOL_RANGE_UNSPECIFIED is passed.
78 * @param flags combination of FF_DRAW_* flags.
79 * @return 0 for success, < 0 for error
80 */
82 enum AVColorRange range, enum AVAlphaMode alpha, unsigned flags);
83
84/**
85 * Init a draw context, taking the format, colorspace and range from the given
86 * filter link.
87 */
89 unsigned flags);
90
91/*
92 * Legacy wrapper for ff_draw_init2.
93 */
95
96
97
98/**
99 * Prepare a color. The rgba value passed is always 8-bit full-range in the RGB space
100 * corresponding to the space set at initialization.
101 */
102void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4]);
103
104/**
105 * Copy a rectangle from an image to another.
106 *
107 * The coordinates must be as even as the subsampling requires.
108 */
110 uint8_t *dst[], int dst_linesize[],
111 uint8_t *src[], int src_linesize[],
112 int dst_x, int dst_y, int src_x, int src_y,
113 int w, int h);
114
115/**
116 * Fill a rectangle with an uniform color.
117 *
118 * The coordinates must be as even as the subsampling requires.
119 * The color needs to be inited with ff_draw_color.
120 */
122 uint8_t *dst[], int dst_linesize[],
123 int dst_x, int dst_y, int w, int h);
124
125/**
126 * Blend a rectangle with an uniform color.
127 */
129 uint8_t *dst[], int dst_linesize[],
130 int dst_w, int dst_h,
131 int x0, int y0, int w, int h);
132
133/**
134 * Blend an alpha mask with an uniform color.
135 *
136 * @param draw draw context
137 * @param color color for the overlay;
138 * @param dst destination image
139 * @param dst_linesize line stride of the destination
140 * @param dst_w width of the destination image
141 * @param dst_h height of the destination image
142 * @param mask mask
143 * @param mask_linesize line stride of the mask
144 * @param mask_w width of the mask
145 * @param mask_h height of the mask
146 * @param l2depth log2 of depth of the mask (0 for 1bpp, 3 for 8bpp)
147 * @param endianness bit order of the mask (0: MSB to the left)
148 * @param x0 horizontal position of the overlay
149 * @param y0 vertical position of the overlay
150 */
152 uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h,
153 const uint8_t *mask, int mask_linesize, int mask_w, int mask_h,
154 int l2depth, unsigned endianness, int x0, int y0);
155
156/**
157 * Round a dimension according to subsampling.
158 *
159 * @param draw draw context
160 * @param sub_dir 0 for horizontal, 1 for vertical
161 * @param round_dir 0 nearest, -1 round down, +1 round up
162 * @param value value to round
163 * @return the rounded value
164 */
165int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir,
166 int value);
167
168/**
169 * Return the list of pixel formats supported by the draw functions.
170 *
171 * The flags are the same as ff_draw_init, i.e., none currently.
172 */
174
175#endif /* AVFILTER_DRAWUTILS_H */
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static const char *const format[]
Definition af_aiir.c:444
static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Main libavfilter public API header.
#define flags(name, subs,...)
Definition cbs_h264.c:74
static enum AVPixelFormat pix_fmt
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:378
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:236
int ff_fill_ayuv_map(uint8_t *ayuv_map, enum AVPixelFormat pix_fmt)
Definition drawutils.c:88
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:658
#define MAX_PLANES
Definition drawutils.h:34
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Definition drawutils.c:174
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition drawutils.c:179
int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSpace csp, enum AVColorRange range, enum AVAlphaMode alpha, unsigned flags)
Init a draw context.
Definition drawutils.c:96
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
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:670
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:258
int ff_draw_init_from_link(FFDrawContext *draw, const AVFilterLink *link, unsigned flags)
Init a draw context, taking the format, colorspace and range from the given filter link.
Definition drawutils.c:168
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:557
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition eamad.c:79
double value
Definition eval.c:102
#define MAX_PLANES
Definition ffv1.h:44
static const int16_t alpha[]
Definition ilbcdata.h:55
uint8_t w
Definition llvidencdsp.c:39
static const uint16_t mask[17]
Definition lzw.c:38
enum AVColorRange range
pixel format definitions
AVColorRange
Visual content value range.
Definition pixfmt.h:748
AVAlphaMode
Correlation between the alpha channel and color values.
Definition pixfmt.h:816
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
AVColorSpace
YUV colorspace type.
Definition pixfmt.h:706
A list of supported formats for one end of a filter link.
Definition formats.h:64
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
uint32_t u32[4]
Definition drawutils.h:55
uint16_t u16[8]
Definition drawutils.h:56
uint8_t rgba[4]
Definition drawutils.h:53
uint8_t u8[16]
Definition drawutils.h:57
unsigned nb_planes
Definition drawutils.h:39
unsigned flags
Definition drawutils.h:46
enum AVAlphaMode alpha
Definition drawutils.h:48
enum AVColorSpace csp
Definition drawutils.h:47
const struct AVPixFmtDescriptor * desc
Definition drawutils.h:37
uint8_t vsub[MAX_PLANES]
Definition drawutils.h:42
enum AVPixelFormat format
Definition drawutils.h:38
uint8_t hsub[MAX_PLANES]
Definition drawutils.h:41
uint8_t vsub_max
Definition drawutils.h:44
double rgb2yuv[3][3]
Definition drawutils.h:49
int pixelstep[MAX_PLANES]
Definition drawutils.h:40
enum AVColorRange range
Definition drawutils.h:45
uint8_t hsub_max
Definition drawutils.h:43
#define src
Definition vp8dsp.c:248