From 16229fae9c0da763061c679e766e9c66dd478b02 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sat, 29 Aug 2015 13:40:25 +0000 Subject: [PATCH] avfilter/vf_vectorscope: add yet another mode Signed-off-by: Paul B Mahol --- doc/filters.texi | 5 +++++ libavfilter/vf_vectorscope.c | 25 +++++++++++++++++++++++- tests/fate/filter-video.mak | 3 +++ tests/ref/fate/filter-vectorscope_color4 | 4 ++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/ref/fate/filter-vectorscope_color4 diff --git a/doc/filters.texi b/doc/filters.texi index c9ac107ef6..3b5f817151 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -10587,6 +10587,11 @@ Actual color components values present in video frame are displayed on graph. Similar as color2 but higher frequency of same values @code{x} and @code{y} on graph increases value of another color component, which is luminance by default values of @code{x} and @code{y}. + +@item color4 +Actual colors present in video frame are displayed on graph. If two different +colors map to same position on graph then color with higher value of component +not present in graph is picked. @end table @item x diff --git a/libavfilter/vf_vectorscope.c b/libavfilter/vf_vectorscope.c index dbcf67517e..88d69b7dab 100644 --- a/libavfilter/vf_vectorscope.c +++ b/libavfilter/vf_vectorscope.c @@ -32,6 +32,7 @@ enum VectorscopeMode { COLOR, COLOR2, COLOR3, + COLOR4, MODE_NB }; @@ -56,6 +57,7 @@ static const AVOption vectorscope_options[] = { { "color", 0, 0, AV_OPT_TYPE_CONST, {.i64=COLOR}, 0, 0, FLAGS, "mode" }, { "color2", 0, 0, AV_OPT_TYPE_CONST, {.i64=COLOR2}, 0, 0, FLAGS, "mode" }, { "color3", 0, 0, AV_OPT_TYPE_CONST, {.i64=COLOR3}, 0, 0, FLAGS, "mode" }, + { "color4", 0, 0, AV_OPT_TYPE_CONST, {.i64=COLOR4}, 0, 0, FLAGS, "mode" }, { "x", "set color component on X axis", OFFSET(x), AV_OPT_TYPE_INT, {.i64=1}, 0, 2, FLAGS}, { "y", "set color component on Y axis", OFFSET(y), AV_OPT_TYPE_INT, {.i64=2}, 0, 2, FLAGS}, { "intensity", "set intensity", OFFSET(intensity), AV_OPT_TYPE_INT, {.i64=1}, 1, 255, FLAGS}, @@ -107,7 +109,8 @@ static int query_formats(AVFilterContext *ctx) if (!ctx->inputs[0]->out_formats) { const enum AVPixelFormat *in_pix_fmts; - if ((s->x == 1 && s->y == 2) || (s->x == 2 && s->y == 1)) + if (((s->x == 1 && s->y == 2) || (s->x == 2 && s->y == 1)) && + (s->mode != COLOR4)) in_pix_fmts = in2_pix_fmts; else in_pix_fmts = in1_pix_fmts; @@ -185,6 +188,7 @@ static void vectorscope(VectorscopeContext *s, AVFrame *in, AVFrame *out, int pd const uint8_t * const *src = (const uint8_t * const *)in->data; const int slinesizex = in->linesize[s->x]; const int slinesizey = in->linesize[s->y]; + const int slinesized = in->linesize[pd]; const int dlinesize = out->linesize[0]; const int intensity = s->intensity; int i, j, px = s->x, py = s->y; @@ -192,6 +196,7 @@ static void vectorscope(VectorscopeContext *s, AVFrame *in, AVFrame *out, int pd const int w = s->planewidth[px]; const uint8_t *spx = src[px]; const uint8_t *spy = src[py]; + const uint8_t *spd = src[pd]; uint8_t **dst = out->data; uint8_t *dpx = dst[px]; uint8_t *dpy = dst[py]; @@ -296,6 +301,24 @@ static void vectorscope(VectorscopeContext *s, AVFrame *in, AVFrame *out, int pd } } break; + case COLOR4: + for (i = 0; i < h; i++) { + const int iwx = i * slinesizex; + const int iwy = i * slinesizey; + const int iwd = i * slinesized; + for (j = 0; j < w; j++) { + const int x = spx[iwx + j]; + const int y = spy[iwy + j]; + const int pos = y * dlinesize + x; + + dpd[pos] = FFMAX(spd[iwd + j], dpd[pos]); + dpx[pos] = x; + dpy[pos] = y; + if (dst[3]) + dst[3][pos] = 255; + } + } + break; default: av_assert0(0); } diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index 5bd5c98cf4..c208d04af4 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -135,6 +135,9 @@ fate-filter-vectorscope_color2: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf vectors FATE_FILTER_VSYNTH-$(CONFIG_VECTORSCOPE_FILTER) += fate-filter-vectorscope_color3 fate-filter-vectorscope_color3: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf vectorscope=color3 -sws_flags +accurate_rnd+bitexact -vframes 3 +FATE_FILTER_VSYNTH-$(CONFIG_VECTORSCOPE_FILTER) += fate-filter-vectorscope_color4 +fate-filter-vectorscope_color4: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf vectorscope=color4 -sws_flags +accurate_rnd+bitexact -vframes 3 + FATE_FILTER_VSYNTH-$(CONFIG_VECTORSCOPE_FILTER) += fate-filter-vectorscope_xy fate-filter-vectorscope_xy: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf vectorscope=x=0:y=1 -sws_flags +accurate_rnd+bitexact -vframes 3 diff --git a/tests/ref/fate/filter-vectorscope_color4 b/tests/ref/fate/filter-vectorscope_color4 new file mode 100644 index 0000000000..137c1896cd --- /dev/null +++ b/tests/ref/fate/filter-vectorscope_color4 @@ -0,0 +1,4 @@ +#tb 0: 1/25 +0, 0, 0, 1, 196608, 0xb6d22af1 +0, 1, 1, 1, 196608, 0xd7c6f971 +0, 2, 2, 1, 196608, 0xfe729faa