28#include "config_components.h"
104#define ASSIGN_THREE_CHANNELS \
105 row[0] = frame->data[0] + y * frame->linesize[0]; \
106 row[1] = frame->data[1] + (y >> ctx->vsub) * frame->linesize[1]; \
107 row[2] = frame->data[2] + (y >> ctx->vsub) * frame->linesize[2];
109#define ASSIGN_FOUR_CHANNELS \
110 ASSIGN_THREE_CHANNELS \
111 row[3] = frame->data[3] + y * frame->linesize[3];
116 unsigned char *row[4];
118 if (
ctx->have_alpha &&
ctx->replace) {
119 for (
y = top;
y < down;
y++) {
121 if (
ctx->invert_color) {
123 if (pixel_belongs_to_region(
ctx,
x,
y))
124 row[0][
x] = 0xff - row[0][
x];
126 for (
x =
left;
x < right;
x++) {
127 if (pixel_belongs_to_region(
ctx,
x,
y)) {
128 row[0][
x ] =
ctx->yuv_color[
Y];
129 row[1][
x >>
ctx->hsub] =
ctx->yuv_color[
U];
130 row[2][
x >>
ctx->hsub] =
ctx->yuv_color[
V];
131 row[3][
x ] =
ctx->yuv_color[
A];
137 for (
y = top;
y < down;
y++) {
139 if (
ctx->invert_color) {
141 if (pixel_belongs_to_region(
ctx,
x,
y))
142 row[0][
x] = 0xff - row[0][
x];
144 for (
x =
left;
x < right;
x++) {
147 if (pixel_belongs_to_region(
ctx,
x,
y)) {
158#define ASSIGN_THREE_CHANNELS_PACKED \
159 row[0] = frame->data[0] + y * frame->linesize[0] + ctx->rgba_map[0]; \
160 row[1] = frame->data[0] + y * frame->linesize[0] + ctx->rgba_map[1]; \
161 row[2] = frame->data[0] + y * frame->linesize[0] + ctx->rgba_map[2];
163#define ASSIGN_FOUR_CHANNELS_PACKED \
164 ASSIGN_THREE_CHANNELS_PACKED \
165 row[3] = frame->data[0] + y * frame->linesize[0] + ctx->rgba_map[3];
170 const int C =
ctx->step;
173 if (
ctx->have_alpha &&
ctx->replace) {
174 for (
int y = top;
y < down;
y++) {
176 if (
ctx->invert_color) {
177 for (
int x =
left;
x < right;
x++)
178 if (pixel_belongs_to_region(
ctx,
x,
y)) {
179 row[0][
x*
C] = 0xff - row[0][
x*
C];
180 row[1][
x*
C] = 0xff - row[1][
x*
C];
181 row[2][
x*
C] = 0xff - row[2][
x*
C];
184 for (
int x =
left;
x < right;
x++) {
185 if (pixel_belongs_to_region(
ctx,
x,
y)) {
186 row[0][
x*
C] =
ctx->rgba_color[
R];
187 row[1][
x*
C] =
ctx->rgba_color[
G];
188 row[2][
x*
C] =
ctx->rgba_color[
B];
189 row[3][
x*
C] =
ctx->rgba_color[
A];
195 for (
int y = top;
y < down;
y++) {
197 if (
ctx->invert_color) {
198 for (
int x =
left;
x < right;
x++)
199 if (pixel_belongs_to_region(
ctx,
x,
y)) {
200 row[0][
x*
C] = 0xff - row[0][
x*
C];
201 row[1][
x*
C] = 0xff - row[1][
x*
C];
202 row[2][
x*
C] = 0xff - row[2][
x*
C];
205 for (
int x =
left;
x < right;
x++) {
208 if (pixel_belongs_to_region(
ctx,
x,
y)) {
234 if (
s->box_source_string) {
236 if ((
int)
s->box_source < 0) {
242 if (!strcmp(
s->color_str,
"invert"))
247 if (!
s->invert_color) {
248 s->yuv_color[
Y] =
RGB_TO_Y_CCIR(
s->rgba_color[0],
s->rgba_color[1],
s->rgba_color[2]);
249 s->yuv_color[
U] =
RGB_TO_U_CCIR(
s->rgba_color[0],
s->rgba_color[1],
s->rgba_color[2], 0);
250 s->yuv_color[
V] =
RGB_TO_V_CCIR(
s->rgba_color[0],
s->rgba_color[1],
s->rgba_color[2], 0);
251 s->yuv_color[
A] =
s->rgba_color[3];
276 double var_values[
VARS_NB], res;
289 s->hsub =
desc->log2_chroma_w;
290 s->vsub =
desc->log2_chroma_h;
312 s->x = var_values[
VAR_X] = res;
319 s->y = var_values[
VAR_Y] = res;
326 s->w = var_values[
VAR_W] = res;
333 s->h = var_values[
VAR_H] = res;
340 s->thickness = var_values[
VAR_T] = res;
344 s->w = (
s->w > 0) ?
s->w : inlink->
w;
345 s->h = (
s->h > 0) ?
s->h : inlink->
h;
348 if (
s->w < 0 ||
s->h < 0) {
354 s->x,
s->y,
s->w,
s->h,
355 s->yuv_color[
Y],
s->yuv_color[
U],
s->yuv_color[
V],
s->yuv_color[
A]);
361 "Error when evaluating the expression '%s'.\n",
368 return (
y -
s->y <
s->thickness) || (
s->y +
s->h - 1 -
y <
s->thickness) ||
369 (
x -
s->x <
s->thickness) || (
s->x +
s->w - 1 -
x <
s->thickness);
392 for (
int i = 0;
i <
loop;
i++) {
416 int old_t =
s->thickness;
417 int old_r =
s->replace;
434 s->thickness = old_t;
441#define OFFSET(x) offsetof(DrawBoxContext, x)
442#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
444#if CONFIG_DRAWBOX_FILTER
446static const AVOption drawbox_options[] = {
477 .p.priv_class = &drawbox_class,
488#if CONFIG_DRAWGRID_FILTER
500 x_modulo =
x % drawgrid->
w;
501 y_modulo =
y % drawgrid->
h;
505 x_modulo += drawgrid->
w;
507 y_modulo += drawgrid->
h;
522static const AVOption drawgrid_options[] = {
545 .filter_frame = drawgrid_filter_frame,
550 .p.name =
"drawgrid",
552 .p.priv_class = &drawgrid_class,
static int config_input(AVFilterLink *inlink)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
const FFFilter ff_vf_drawbox
const FFFilter ff_vf_drawgrid
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Main libavfilter public API header.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
common internal and external API header
static av_always_inline AVDetectionBBox * av_get_detection_bbox(const AVDetectionBBoxHeader *header, unsigned int idx)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
int(* init)(AVBSFContext *ctx)
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
simple arithmetic expression evaluator
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
@ AV_FRAME_DATA_DETECTION_BBOXES
Bounding boxes for object detection and classification, as described by AVDetectionBBoxHeader.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static const int16_t alpha[]
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
#define FILTER_PIXFMTS_ARRAY(array)
#define AVFILTER_DEFINE_CLASS(fname)
Various defines for YUV<->RGB conversion.
#define RGB_TO_U_CCIR(r1, g1, b1, shift)
#define RGB_TO_Y_CCIR(r, g, b)
#define RGB_TO_V_CCIR(r1, g1, b1, shift)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
static const char *const var_names[]
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
int av_get_padded_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel for the pixel format described by pixdesc, including any padding ...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static const uint8_t header[24]
Describe the class of an AVClass context structure.
int x
Distance in pixels from the left/top edge of the frame, together with width and height,...
void * priv
private data for use by the filter
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
char * y_expr
expression for x and y
void(* draw_region)(AVFrame *frame, struct DrawBoxContext *ctx, int left, int top, int right, int down, PixelBelongsToRegion pixel_belongs_to_region)
char * h_expr
expression for width and height
int invert_color
invert luma color
char * t_expr
expression for thickness
int hsub
chroma subsampling
unsigned char yuv_color[4]
char * box_source_string
string for box data source
enum AVFrameSideDataType box_source
static AVFormatContext * ctx
int(* PixelBelongsToRegion)(struct DrawBoxContext *s, int x, int y)
static const int NUM_EXPR_EVALS
static int config_input(AVFilterLink *inlink)
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
#define ASSIGN_FOUR_CHANNELS
#define ASSIGN_FOUR_CHANNELS_PACKED
static av_pure av_always_inline int pixel_belongs_to_box(DrawBoxContext *s, int x, int y)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
#define ASSIGN_THREE_CHANNELS_PACKED
static void draw_region_rgb_packed(AVFrame *frame, DrawBoxContext *ctx, int left, int top, int right, int down, PixelBelongsToRegion pixel_belongs_to_region)
static void draw_region(AVFrame *frame, DrawBoxContext *ctx, int left, int top, int right, int down, PixelBelongsToRegion pixel_belongs_to_region)
#define ASSIGN_THREE_CHANNELS
static enum AVFrameSideDataType box_source_string_parse(const char *box_source_string)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.