diff options
author | Paul B Mahol <onemda@gmail.com> | 2016-09-09 14:16:22 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2016-09-09 14:16:22 +0200 |
commit | 7055b28d988a59acb529b8043c70cd8cc65505e6 (patch) | |
tree | 830b073e1a1a58593c6f1de9275a6851b478d272 | |
parent | 5556392b3b3ccfedfc780a541431b6b83881f7e4 (diff) | |
download | ffmpeg-7055b28d988a59acb529b8043c70cd8cc65505e6.tar.gz |
avfilter/vf_datascope: cleanup code a little
Make few helper functions.
Signed-off-by: Paul B Mahol <onemda@gmail.com>
-rw-r--r-- | libavfilter/vf_datascope.c | 90 |
1 files changed, 56 insertions, 34 deletions
diff --git a/libavfilter/vf_datascope.c b/libavfilter/vf_datascope.c index 57478fd942..01a5d992b0 100644 --- a/libavfilter/vf_datascope.c +++ b/libavfilter/vf_datascope.c @@ -47,6 +47,8 @@ typedef struct DatascopeContext { FFDrawColor black; FFDrawColor gray; + void (*pick_color)(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value); + void (*reverse_color)(FFDrawContext *draw, FFDrawColor *color, FFDrawColor *reverse); int (*filter)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); } DatascopeContext; @@ -97,54 +99,66 @@ static void draw_text(DatascopeContext *s, AVFrame *frame, FFDrawColor *color, } } -static void pick_color(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value) +static void pick_color8(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value) { int p, i; color->rgba[3] = 255; for (p = 0; p < draw->nb_planes; p++) { - if (draw->desc->comp[p].depth == 8) { - if (draw->nb_planes == 1) { - for (i = 0; i < 4; i++) { - value[i] = in->data[0][y * in->linesize[0] + x * draw->pixelstep[0] + i]; - color->comp[0].u8[i] = value[i]; - } - } else { - value[p] = in->data[p][(y >> draw->vsub[p]) * in->linesize[p] + (x >> draw->hsub[p])]; - color->comp[p].u8[0] = value[p]; + if (draw->nb_planes == 1) { + for (i = 0; i < 4; i++) { + value[i] = in->data[0][y * in->linesize[0] + x * draw->pixelstep[0] + i]; + color->comp[0].u8[i] = value[i]; } } else { - if (draw->nb_planes == 1) { - for (i = 0; i < 4; i++) { - value[i] = AV_RL16(in->data[0] + y * in->linesize[0] + x * draw->pixelstep[0] + i * 2); - color->comp[0].u16[i] = value[i]; - } - } else { - value[p] = AV_RL16(in->data[p] + (y >> draw->vsub[p]) * in->linesize[p] + (x >> draw->hsub[p]) * 2); - color->comp[p].u16[0] = value[p]; + value[p] = in->data[p][(y >> draw->vsub[p]) * in->linesize[p] + (x >> draw->hsub[p])]; + color->comp[p].u8[0] = value[p]; + } + } +} + +static void pick_color16(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value) +{ + int p, i; + + color->rgba[3] = 255; + for (p = 0; p < draw->nb_planes; p++) { + if (draw->nb_planes == 1) { + for (i = 0; i < 4; i++) { + value[i] = AV_RL16(in->data[0] + y * in->linesize[0] + x * draw->pixelstep[0] + i * 2); + color->comp[0].u16[i] = value[i]; } + } else { + value[p] = AV_RL16(in->data[p] + (y >> draw->vsub[p]) * in->linesize[p] + (x >> draw->hsub[p]) * 2); + color->comp[p].u16[0] = value[p]; } } } -static void reverse_color(FFDrawContext *draw, FFDrawColor *color, FFDrawColor *reverse) +static void reverse_color8(FFDrawContext *draw, FFDrawColor *color, FFDrawColor *reverse) { int p; reverse->rgba[3] = 255; for (p = 0; p < draw->nb_planes; p++) { - if (draw->desc->comp[p].depth == 8) { - reverse->comp[p].u8[0] = color->comp[p].u8[0] > 127 ? 0 : 255; - reverse->comp[p].u8[1] = color->comp[p].u8[1] > 127 ? 0 : 255; - reverse->comp[p].u8[2] = color->comp[p].u8[2] > 127 ? 0 : 255; - } else { - const unsigned max = (1 << draw->desc->comp[p].depth) - 1; - const unsigned mid = (max + 1) / 2; + reverse->comp[p].u8[0] = color->comp[p].u8[0] > 127 ? 0 : 255; + reverse->comp[p].u8[1] = color->comp[p].u8[1] > 127 ? 0 : 255; + reverse->comp[p].u8[2] = color->comp[p].u8[2] > 127 ? 0 : 255; + } +} - reverse->comp[p].u16[0] = color->comp[p].u16[0] > mid ? 0 : max; - reverse->comp[p].u16[1] = color->comp[p].u16[1] > mid ? 0 : max; - reverse->comp[p].u16[2] = color->comp[p].u16[2] > mid ? 0 : max; - } +static void reverse_color16(FFDrawContext *draw, FFDrawColor *color, FFDrawColor *reverse) +{ + int p; + + reverse->rgba[3] = 255; + for (p = 0; p < draw->nb_planes; p++) { + const unsigned max = (1 << draw->desc->comp[p].depth) - 1; + const unsigned mid = (max + 1) / 2; + + reverse->comp[p].u16[0] = color->comp[p].u16[0] > mid ? 0 : max; + reverse->comp[p].u16[1] = color->comp[p].u16[1] > mid ? 0 : max; + reverse->comp[p].u16[2] = color->comp[p].u16[2] > mid ? 0 : max; } } @@ -178,8 +192,8 @@ static int filter_color2(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs FFDrawColor reverse = { { 0 } }; int value[4] = { 0 }; - pick_color(&s->draw, &color, in, x + s->x, y + s->y, value); - reverse_color(&s->draw, &color, &reverse); + s->pick_color(&s->draw, &color, in, x + s->x, y + s->y, value); + s->reverse_color(&s->draw, &color, &reverse); ff_fill_rectangle(&s->draw, &color, out->data, out->linesize, xoff + x * C * 10, yoff + y * P * 12, C * 10, P * 12); @@ -219,7 +233,7 @@ static int filter_color(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) FFDrawColor color = { { 0 } }; int value[4] = { 0 }; - pick_color(&s->draw, &color, in, x + s->x, y + s->y, value); + s->pick_color(&s->draw, &color, in, x + s->x, y + s->y, value); for (p = 0; p < P; p++) { char text[256]; @@ -257,7 +271,7 @@ static int filter_mono(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) FFDrawColor color = { { 0 } }; int value[4] = { 0 }; - pick_color(&s->draw, &color, in, x + s->x, y + s->y, value); + s->pick_color(&s->draw, &color, in, x + s->x, y + s->y, value); for (p = 0; p < P; p++) { char text[256]; @@ -354,6 +368,14 @@ static int config_input(AVFilterLink *inlink) case 2: s->filter = filter_color2; break; } + if (s->draw.desc->comp[0].depth <= 8) { + s->pick_color = pick_color8; + s->reverse_color = reverse_color8; + } else { + s->pick_color = pick_color16; + s->reverse_color = reverse_color16; + } + return 0; } |