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];
139 const int yc =
ctx->yuv_color[
Y];
140 const int uc =
ctx->yuv_color[
U];
141 const int vc =
ctx->yuv_color[
V];
143 for (
y = top;
y < down;
y++) {
145 if (
ctx->invert_color) {
147 if (pixel_belongs_to_region(
ctx,
x,
y))
148 row[0][
x] = 0xff - row[0][
x];
150 for (
x =
left;
x < right;
x++) {
151 if (pixel_belongs_to_region(
ctx,
x,
y)) {
162#define ASSIGN_THREE_CHANNELS_PACKED \
163 row[0] = frame->data[0] + y * frame->linesize[0] + ctx->rgba_map[0]; \
164 row[1] = frame->data[0] + y * frame->linesize[0] + ctx->rgba_map[1]; \
165 row[2] = frame->data[0] + y * frame->linesize[0] + ctx->rgba_map[2];
167#define ASSIGN_FOUR_CHANNELS_PACKED \
168 ASSIGN_THREE_CHANNELS_PACKED \
169 row[3] = frame->data[0] + y * frame->linesize[0] + ctx->rgba_map[3];
174 const int C =
ctx->step;
177 if (
ctx->have_alpha &&
ctx->replace) {
178 for (
int y = top;
y < down;
y++) {
180 if (
ctx->invert_color) {
181 for (
int x =
left;
x < right;
x++)
182 if (pixel_belongs_to_region(
ctx,
x,
y)) {
183 row[0][
x*
C] = 0xff - row[0][
x*
C];
184 row[1][
x*
C] = 0xff - row[1][
x*
C];
185 row[2][
x*
C] = 0xff - row[2][
x*
C];
188 for (
int x =
left;
x < right;
x++) {
189 if (pixel_belongs_to_region(
ctx,
x,
y)) {
190 row[0][
x*
C] =
ctx->rgba_color[
R];
191 row[1][
x*
C] =
ctx->rgba_color[
G];
192 row[2][
x*
C] =
ctx->rgba_color[
B];
193 row[3][
x*
C] =
ctx->rgba_color[
A];
201 for (
int y = top;
y < down;
y++) {
203 if (
ctx->invert_color) {
204 for (
int x =
left;
x < right;
x++)
205 if (pixel_belongs_to_region(
ctx,
x,
y)) {
206 row[0][
x*
C] = 0xff - row[0][
x*
C];
207 row[1][
x*
C] = 0xff - row[1][
x*
C];
208 row[2][
x*
C] = 0xff - row[2][
x*
C];
211 for (
int x =
left;
x < right;
x++) {
212 if (pixel_belongs_to_region(
ctx,
x,
y)) {
238 if (
s->box_source_string) {
240 if ((
int)
s->box_source < 0) {
246 if (!strcmp(
s->color_str,
"invert"))
251 if (!
s->invert_color) {
252 s->yuv_color[
Y] =
RGB_TO_Y_CCIR(
s->rgba_color[0],
s->rgba_color[1],
s->rgba_color[2]);
253 s->yuv_color[
U] =
RGB_TO_U_CCIR(
s->rgba_color[0],
s->rgba_color[1],
s->rgba_color[2], 0);
254 s->yuv_color[
V] =
RGB_TO_V_CCIR(
s->rgba_color[0],
s->rgba_color[1],
s->rgba_color[2], 0);
255 s->yuv_color[
A] =
s->rgba_color[3];
280 double var_values[
VARS_NB], res;
293 s->hsub =
desc->log2_chroma_w;
294 s->vsub =
desc->log2_chroma_h;
316 var_values[
VAR_X] = res;
323 var_values[
VAR_Y] = res;
330 var_values[
VAR_W] = res;
337 var_values[
VAR_H] = res;
344 var_values[
VAR_T] = res;
347 if (!(
fabs(var_values[
VAR_X]) <= INT_MAX / 4 &&
fabs(var_values[
VAR_Y]) <= INT_MAX / 4 &&
357 s->thickness = var_values[
VAR_T];
360 s->w = (
s->w > 0) ?
s->w : inlink->
w;
361 s->h = (
s->h > 0) ?
s->h : inlink->
h;
364 if (
s->w < 0 ||
s->h < 0) {
370 s->x,
s->y,
s->w,
s->h,
371 s->yuv_color[
Y],
s->yuv_color[
U],
s->yuv_color[
V],
s->yuv_color[
A]);
377 "Error when evaluating the expression '%s'.\n",
384 return (
y -
s->y <
s->thickness) || (
s->y +
s->h - 1 -
y <
s->thickness) ||
385 (
x -
s->x <
s->thickness) || (
s->x +
s->w - 1 -
x <
s->thickness);
408 for (
int i = 0;
i <
loop;
i++) {
432 int old_t =
s->thickness;
433 int old_r =
s->replace;
450 s->thickness = old_t;
457#define OFFSET(x) offsetof(DrawBoxContext, x)
458#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
460#if CONFIG_DRAWBOX_FILTER
462static const AVOption drawbox_options[] = {
493 .p.priv_class = &drawbox_class,
505#if CONFIG_DRAWGRID_FILTER
517 x_modulo =
x % drawgrid->
w;
518 y_modulo =
y % drawgrid->
h;
522 x_modulo += drawgrid->
w;
524 y_modulo += drawgrid->
h;
539static const AVOption drawgrid_options[] = {
562 .filter_frame = drawgrid_filter_frame,
567 .p.name =
"drawgrid",
569 .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
static AVFormatContext * ctx
#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 __device__ float fabs(float a)
static __device__ float trunc(float a)
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 FF_FILTER_FLAG_DYNAMIC_FRAME_SIZE
The filter handles input frames whose size differs from the one its input link was configured with.
#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
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.