63
67
static int query_formats(AVFilterContext *ctx)
65
enum PixelFormat pix_fmts[] = {
66
PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P,
67
PIX_FMT_YUV411P, PIX_FMT_YUV410P,
68
PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P,
69
PIX_FMT_YUV440P, PIX_FMT_YUVJ440P,
69
enum AVPixelFormat pix_fmts[] = {
70
AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
71
AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
72
AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P,
73
AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUVJ440P,
73
avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
77
ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
77
81
static int config_input(AVFilterLink *inlink)
79
83
DrawBoxContext *drawbox = inlink->dst->priv;
84
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
81
drawbox->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
82
drawbox->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
86
drawbox->hsub = desc->log2_chroma_w;
87
drawbox->vsub = desc->log2_chroma_h;
84
89
if (drawbox->w == 0) drawbox->w = inlink->w;
85
90
if (drawbox->h == 0) drawbox->h = inlink->h;
87
av_log(inlink->dst, AV_LOG_INFO, "x:%d y:%d w:%d h:%d color:0x%02X%02X%02X%02X\n",
92
av_log(inlink->dst, AV_LOG_VERBOSE, "x:%d y:%d w:%d h:%d color:0x%02X%02X%02X%02X\n",
88
93
drawbox->w, drawbox->y, drawbox->w, drawbox->h,
89
94
drawbox->yuv_color[Y], drawbox->yuv_color[U], drawbox->yuv_color[V], drawbox->yuv_color[A]);
94
static void draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir)
99
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame)
96
101
DrawBoxContext *drawbox = inlink->dst->priv;
97
102
int plane, x, y, xb = drawbox->x, yb = drawbox->y;
98
103
unsigned char *row[4];
99
AVFilterBufferRef *picref = inlink->cur_buf;
101
for (y = FFMAX(yb, y0); y < (y0 + h) && y < (yb + drawbox->h); y++) {
102
row[0] = picref->data[0] + y * picref->linesize[0];
105
for (y = FFMAX(yb, 0); y < frame->video->h && y < (yb + drawbox->h); y++) {
106
row[0] = frame->data[0] + y * frame->linesize[0];
104
108
for (plane = 1; plane < 3; plane++)
105
row[plane] = picref->data[plane] +
106
picref->linesize[plane] * (y >> drawbox->vsub);
109
row[plane] = frame->data[plane] +
110
frame->linesize[plane] * (y >> drawbox->vsub);
108
for (x = FFMAX(xb, 0); x < (xb + drawbox->w) && x < picref->video->w; x++) {
112
for (x = FFMAX(xb, 0); x < (xb + drawbox->w) && x < frame->video->w; x++) {
109
113
double alpha = (double)drawbox->yuv_color[A] / 255;
111
115
if ((y - yb < 3) || (yb + drawbox->h - y < 4) ||
120
avfilter_draw_slice(inlink->dst->outputs[0], y0, h, 1);
124
return ff_filter_frame(inlink->dst->outputs[0], frame);
127
static const AVFilterPad avfilter_vf_drawbox_inputs[] = {
130
.type = AVMEDIA_TYPE_VIDEO,
131
.config_props = config_input,
132
.get_video_buffer = ff_null_get_video_buffer,
133
.filter_frame = filter_frame,
134
.min_perms = AV_PERM_WRITE | AV_PERM_READ,
135
.rej_perms = AV_PERM_PRESERVE
140
static const AVFilterPad avfilter_vf_drawbox_outputs[] = {
143
.type = AVMEDIA_TYPE_VIDEO,
123
148
AVFilter avfilter_vf_drawbox = {
124
149
.name = "drawbox",
125
150
.description = NULL_IF_CONFIG_SMALL("Draw a colored box on the input video."),
129
154
.query_formats = query_formats,
130
.inputs = (AVFilterPad[]) {{ .name = "default",
131
.type = AVMEDIA_TYPE_VIDEO,
132
.config_props = config_input,
133
.get_video_buffer = avfilter_null_get_video_buffer,
134
.start_frame = avfilter_null_start_frame,
135
.draw_slice = draw_slice,
136
.end_frame = avfilter_null_end_frame,
137
.min_perms = AV_PERM_WRITE | AV_PERM_READ,
138
.rej_perms = AV_PERM_PRESERVE },
140
.outputs = (AVFilterPad[]) {{ .name = "default",
141
.type = AVMEDIA_TYPE_VIDEO, },
155
.inputs = avfilter_vf_drawbox_inputs,
156
.outputs = avfilter_vf_drawbox_outputs,