summaryrefslogtreecommitdiffstats
path: root/libavfilter/vf_drawbox.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2019-10-01 19:22:17 +0200
committerPaul B Mahol <onemda@gmail.com>2019-10-01 20:28:11 +0200
commit027a53dc4905ecc8440f32665487c5e46d1dc500 (patch)
tree44910a1dbcaa56b3697376777bc6c76ecbdee6cd /libavfilter/vf_drawbox.c
parenta650e8c8e957d81959282d9b6c1f20e87f385031 (diff)
downloadffmpeg-streaming-027a53dc4905ecc8440f32665487c5e46d1dc500.zip
ffmpeg-streaming-027a53dc4905ecc8440f32665487c5e46d1dc500.tar.gz
avfilter/vf_drawbox: reduce code duplication
Diffstat (limited to 'libavfilter/vf_drawbox.c')
-rw-r--r--libavfilter/vf_drawbox.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c
index c9cb63d..91bfeb2 100644
--- a/libavfilter/vf_drawbox.c
+++ b/libavfilter/vf_drawbox.c
@@ -208,6 +208,12 @@ fail:
return ret;
}
+static av_pure av_always_inline int pixel_belongs_to_box(DrawBoxContext *s, int x, int y)
+{
+ return (y - s->y < s->thickness) || (s->y + s->h - 1 - y < s->thickness) ||
+ (x - s->x < s->thickness) || (s->x + s->w - 1 - x < s->thickness);
+}
+
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
DrawBoxContext *s = inlink->dst->priv;
@@ -225,13 +231,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
if (s->invert_color) {
for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++)
- if ((y - yb < s->thickness) || (yb + s->h - 1 - y < s->thickness) ||
- (x - xb < s->thickness) || (xb + s->w - 1 - x < s->thickness))
+ if (pixel_belongs_to_box(s, x, y))
row[0][x] = 0xff - row[0][x];
} else {
for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++) {
- if ((y - yb < s->thickness) || (yb + s->h - 1 - y < s->thickness) ||
- (x - xb < s->thickness) || (xb + s->w - 1 - x < s->thickness)) {
+ if (pixel_belongs_to_box(s, x, y)) {
row[0][x ] = s->yuv_color[Y];
row[1][x >> s->hsub] = s->yuv_color[U];
row[2][x >> s->hsub] = s->yuv_color[V];
@@ -250,15 +254,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
if (s->invert_color) {
for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++)
- if ((y - yb < s->thickness) || (yb + s->h - 1 - y < s->thickness) ||
- (x - xb < s->thickness) || (xb + s->w - 1 - x < s->thickness))
+ if (pixel_belongs_to_box(s, x, y))
row[0][x] = 0xff - row[0][x];
} else {
for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++) {
double alpha = (double)s->yuv_color[A] / 255;
- if ((y - yb < s->thickness) || (yb + s->h - 1 - y < s->thickness) ||
- (x - xb < s->thickness) || (xb + s->w - 1 - x < s->thickness)) {
+ if (pixel_belongs_to_box(s, x, y)) {
row[0][x ] = (1 - alpha) * row[0][x ] + alpha * s->yuv_color[Y];
row[1][x >> s->hsub] = (1 - alpha) * row[1][x >> s->hsub] + alpha * s->yuv_color[U];
row[2][x >> s->hsub] = (1 - alpha) * row[2][x >> s->hsub] + alpha * s->yuv_color[V];
OpenPOWER on IntegriCloud