summaryrefslogtreecommitdiff
path: root/libavfilter/vf_drawbox.c
diff options
context:
space:
mode:
authorGyan Doshi <gyandoshi@gmail.com>2017-12-11 22:35:18 +0530
committerLou Logan <lou@lrcd.com>2017-12-14 13:44:45 -0900
commit1c76134fe37ac20695627e3f5ce1f2bbf1245fcc (patch)
tree3db7109fea202a62e3d53231db89ce904070af86 /libavfilter/vf_drawbox.c
parent980af9a88cfd743d71fad67e7dd905231ea0a4f7 (diff)
downloadffmpeg-1c76134fe37ac20695627e3f5ce1f2bbf1245fcc.tar.gz
avfilter/drawbox+drawgrid - add option to prevent overwriting of source pixels
If the user-supplied color in drawbox and drawgrid filters is non-opaque, the box & grid painting overwrites the input's pixels (including alpha). Users typically expect the alpha of the specified color to only act as a key for compositing on top of the main input. Added option allows users to select between replacement and composition. Tested and documented.
Diffstat (limited to 'libavfilter/vf_drawbox.c')
-rw-r--r--libavfilter/vf_drawbox.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c
index d351846594..c9cb63dbd1 100644
--- a/libavfilter/vf_drawbox.c
+++ b/libavfilter/vf_drawbox.c
@@ -80,6 +80,7 @@ typedef struct DrawBoxContext {
char *w_expr, *h_expr; ///< expression for width and height
char *t_expr; ///< expression for thickness
int have_alpha;
+ int replace;
} DrawBoxContext;
static const int NUM_EXPR_EVALS = 5;
@@ -213,7 +214,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
int plane, x, y, xb = s->x, yb = s->y;
unsigned char *row[4];
- if (s->have_alpha) {
+ if (s->have_alpha && s->replace) {
for (y = FFMAX(yb, 0); y < frame->height && y < (yb + s->h); y++) {
row[0] = frame->data[0] + y * frame->linesize[0];
row[3] = frame->data[3] + y * frame->linesize[3];
@@ -286,6 +287,7 @@ static const AVOption drawbox_options[] = {
{ "c", "set color of the box", OFFSET(color_str), AV_OPT_TYPE_STRING, { .str = "black" }, CHAR_MIN, CHAR_MAX, FLAGS },
{ "thickness", "set the box thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, { .str="3" }, CHAR_MIN, CHAR_MAX, FLAGS },
{ "t", "set the box thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, { .str="3" }, CHAR_MIN, CHAR_MAX, FLAGS },
+ { "replace", "replace color & alpha", OFFSET(replace), AV_OPT_TYPE_BOOL, { .i64=0 }, 0, 1, FLAGS },
{ NULL }
};
@@ -354,7 +356,7 @@ static int drawgrid_filter_frame(AVFilterLink *inlink, AVFrame *frame)
int plane, x, y;
uint8_t *row[4];
- if (drawgrid->have_alpha) {
+ if (drawgrid->have_alpha && drawgrid->replace) {
for (y = 0; y < frame->height; y++) {
row[0] = frame->data[0] + y * frame->linesize[0];
row[3] = frame->data[3] + y * frame->linesize[3];
@@ -418,6 +420,7 @@ static const AVOption drawgrid_options[] = {
{ "c", "set color of the grid", OFFSET(color_str), AV_OPT_TYPE_STRING, { .str = "black" }, CHAR_MIN, CHAR_MAX, FLAGS },
{ "thickness", "set grid line thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, {.str="1"}, CHAR_MIN, CHAR_MAX, FLAGS },
{ "t", "set grid line thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, {.str="1"}, CHAR_MIN, CHAR_MAX, FLAGS },
+ { "replace", "replace color & alpha", OFFSET(replace), AV_OPT_TYPE_BOOL, { .i64=0 }, 0, 1, FLAGS },
{ NULL }
};