History

avfilter: add colorspectrum source video filter

Paul B Mahol committed 5 years ago

Commit d401b1c1 parent 08b47166 files · +111 −3Browse files

Unified · Split

6 files
  1. Changelog +1 −0
  2. doc/filters.texi +14 −1
  3. libavfilter/Makefile +1 −0
  4. libavfilter/allfilters.c +1 −0
  5. libavfilter/version.h +2 −2
  6. libavfilter/vsrc_testsrc.c +92 −0
Changelog+1−0
@@ -30,6 +30,7 @@ version <next>: · 29 unmodified lines
3030 - xcorrelate video filter
3131 - varblur video filter
3232 - huesaturation video filter
33+- colorspectrum source video filter
3334
3435
3536 version 4.4:
doc/filters.texi+14−1
@@ -25257,6 +25257,7 @@ ffplay -f lavfi life=s=300x200:mold=10:r=60:ratio=0.1:death_color=#C83232:life_c · 25256 unmodified lines
2525725257 @anchor{allrgb}
2525825258 @anchor{allyuv}
2525925259 @anchor{color}
25260+@anchor{colorspectrum}
2526025261 @anchor{haldclutsrc}
2526125262 @anchor{nullsrc}
2526225263 @anchor{pal75bars}
@@ -25267,7 +25268,7 @@ ffplay -f lavfi life=s=300x200:mold=10:r=60:ratio=0.1:death_color=#C83232:life_c · 4 unmodified lines
2526725268 @anchor{testsrc}
2526825269 @anchor{testsrc2}
2526925270 @anchor{yuvtestsrc}
25270−@section allrgb, allyuv, color, haldclutsrc, nullsrc, pal75bars, pal100bars, rgbtestsrc, smptebars, smptehdbars, testsrc, testsrc2, yuvtestsrc
25271+@section allrgb, allyuv, color, colorspectrum, haldclutsrc, nullsrc, pal75bars, pal100bars, rgbtestsrc, smptebars, smptehdbars, testsrc, testsrc2, yuvtestsrc
2527125272
2527225273 The @code{allrgb} source returns frames of size 4096x4096 of all rgb colors.
2527325274
@@ -25275,6 +25276,8 @@ The @code{allyuv} source returns frames of size 4096x4096 of all yuv colors. · 1 unmodified line
2527525276
2527625277 The @code{color} source provides an uniformly colored input.
2527725278
25279+The @code{colorspectrum} source provides a color spectrum input.
25280+
2527825281 The @code{haldclutsrc} source provides an identity Hald CLUT. See also
2527925282 @ref{haldclut} filter.
2528025283
@@ -25366,6 +25369,16 @@ Set the number of decimals to show in the timestamp, only available in the · 85 unmodified lines
2536625369 The displayed timestamp value will correspond to the original
2536725370 timestamp value multiplied by the power of 10 of the specified
2536825371 value. Default value is 0.
25372+
25373+@item type
25374+Set the type of the color spectrum, only available in the
25375+@code{colorspectrum} source. Can be one of the following:
25376+
25377+@table @samp
25378+@item black
25379+@item white
25380+@item all
25381+@end table
2536925382 @end table
2537025383
2537125384 @subsection Examples
libavfilter/Makefile+1−0
@@ -522,6 +522,7 @@ OBJS-$(CONFIG_ALLRGB_FILTER) += vsrc_testsrc.o · 521 unmodified lines
522522 OBJS-$(CONFIG_ALLYUV_FILTER) += vsrc_testsrc.o
523523 OBJS-$(CONFIG_CELLAUTO_FILTER) += vsrc_cellauto.o
524524 OBJS-$(CONFIG_COLOR_FILTER) += vsrc_testsrc.o
525+OBJS-$(CONFIG_COLORSPECTRUM_FILTER) += vsrc_testsrc.o
525526 OBJS-$(CONFIG_COREIMAGESRC_FILTER) += vf_coreimage.o
526527 OBJS-$(CONFIG_FREI0R_SRC_FILTER) += vf_frei0r.o
527528 OBJS-$(CONFIG_GRADIENTS_FILTER) += vsrc_gradients.o
libavfilter/allfilters.c+1−0
@@ -498,6 +498,7 @@ extern const AVFilter ff_vsrc_allrgb; · 497 unmodified lines
498498 extern const AVFilter ff_vsrc_allyuv;
499499 extern const AVFilter ff_vsrc_cellauto;
500500 extern const AVFilter ff_vsrc_color;
501+extern const AVFilter ff_vsrc_colorspectrum;
501502 extern const AVFilter ff_vsrc_coreimagesrc;
502503 extern const AVFilter ff_vsrc_frei0r_src;
503504 extern const AVFilter ff_vsrc_gradients;
libavfilter/version.h+2−2
@@ -30,8 +30,8 @@ · 29 unmodified lines
3030 #include "libavutil/version.h"
3131
3232 #define LIBAVFILTER_VERSION_MAJOR 8
33−#define LIBAVFILTER_VERSION_MINOR 16
34−#define LIBAVFILTER_VERSION_MICRO 102
33+#define LIBAVFILTER_VERSION_MINOR 17
34+#define LIBAVFILTER_VERSION_MICRO 100
3535
3636
3737 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
libavfilter/vsrc_testsrc.c+92−0
@@ -70,6 +70,9 @@ typedef struct TestSourceContext { · 69 unmodified lines
7070 /* only used by testsrc2 */
7171 int alpha;
7272
73+ /* only used by colorspectrum */
74+ int type;
75+
7376 /* only used by color */
7477 FFDrawContext draw;
7578 FFDrawColor color;
@@ -1791,3 +1794,92 @@ const AVFilter ff_vsrc_allrgb = { · 1715 unmodified lines
17911794 };
17921795
17931796 #endif /* CONFIG_ALLRGB_FILTER */
1797+
1798+#if CONFIG_COLORSPECTRUM_FILTER
1799+
1800+static const AVOption colorspectrum_options[] = {
1801+ COMMON_OPTIONS
1802+ { "type", "set the color spectrum type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, "type" },
1803+ { "black","fade to black", 0, AV_OPT_TYPE_CONST,{.i64=0},0, 0, FLAGS, "type" },
1804+ { "white","fade to white", 0, AV_OPT_TYPE_CONST,{.i64=1},0, 0, FLAGS, "type" },
1805+ { "all", "white to black", 0, AV_OPT_TYPE_CONST,{.i64=2},0, 0, FLAGS, "type" },
1806+ { NULL }
1807+};
1808+
1809+AVFILTER_DEFINE_CLASS(colorspectrum);
1810+
1811+static inline float mix(float a, float b, float mix)
1812+{
1813+ return a * mix + b * (1.f - mix);
1814+}
1815+
1816+static void hsb2rgb(const float *c, float *rgb)
1817+{
1818+ rgb[0] = av_clipf(fabsf(fmodf(c[0] * 6.f + 0.f, 6.f) - 3.f) - 1.f, 0.f, 1.f);
1819+ rgb[1] = av_clipf(fabsf(fmodf(c[0] * 6.f + 4.f, 6.f) - 3.f) - 1.f, 0.f, 1.f);
1820+ rgb[2] = av_clipf(fabsf(fmodf(c[0] * 6.f + 2.f, 6.f) - 3.f) - 1.f, 0.f, 1.f);
1821+ rgb[0] = mix(c[3], (rgb[0] * rgb[0] * (3.f - 2.f * rgb[0])), c[1]) * c[2];
1822+ rgb[1] = mix(c[3], (rgb[1] * rgb[1] * (3.f - 2.f * rgb[1])), c[1]) * c[2];
1823+ rgb[2] = mix(c[3], (rgb[2] * rgb[2] * (3.f - 2.f * rgb[2])), c[1]) * c[2];
1824+}
1825+
1826+static void colorspectrum_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1827+{
1828+ TestSourceContext *test = ctx->priv;
1829+ const float w = frame->width - 1.f;
1830+ const float h = frame->height - 1.f;
1831+ float c[4];
1832+
1833+ for (int y = 0; y < frame->height; y++) {
1834+ float *r = (float *)(frame->data[2] + y * frame->linesize[2]);
1835+ float *g = (float *)(frame->data[0] + y * frame->linesize[0]);
1836+ float *b = (float *)(frame->data[1] + y * frame->linesize[1]);
1837+ const float yh = y / h;
1838+
1839+ c[1] = test->type == 2 ? yh > 0.5f ? 2.f * (yh - 0.5f) : 1.f - 2.f * yh : test->type == 1 ? 1.f - yh : yh;
1840+ c[2] = 1.f;
1841+ c[3] = test->type == 1 ? 1.f : test->type == 2 ? (yh > 0.5f ? 0.f : 1.f): 0.f;
1842+ for (int x = 0; x < frame->width; x++) {
1843+ float rgb[3];
1844+
1845+ c[0] = x / w;
1846+ hsb2rgb(c, rgb);
1847+
1848+ r[x] = rgb[0];
1849+ g[x] = rgb[1];
1850+ b[x] = rgb[2];
1851+ }
1852+ }
1853+}
1854+
1855+static av_cold int colorspectrum_init(AVFilterContext *ctx)
1856+{
1857+ TestSourceContext *test = ctx->priv;
1858+
1859+ test->draw_once = 1;
1860+ test->fill_picture_fn = colorspectrum_fill_picture;
1861+ return init(ctx);
1862+}
1863+
1864+static const AVFilterPad avfilter_vsrc_colorspectrum_outputs[] = {
1865+ {
1866+ .name = "default",
1867+ .type = AVMEDIA_TYPE_VIDEO,
1868+ .config_props = config_props,
1869+ },
1870+};
1871+
1872+const AVFilter ff_vsrc_colorspectrum = {
1873+ .name = "colorspectrum",
1874+ .description = NULL_IF_CONFIG_SMALL("Generate colors spectrum."),
1875+ .priv_size = sizeof(TestSourceContext),
1876+ .priv_class = &colorspectrum_class,
1877+ .init = colorspectrum_init,
1878+ .uninit = uninit,
1879+ .activate = activate,
1880+ .inputs = NULL,
1881+ FILTER_OUTPUTS(avfilter_vsrc_colorspectrum_outputs),
1882+ FILTER_SINGLE_PIXFMT(AV_PIX_FMT_GBRPF32),
1883+};
1884+
1885+#endif /* CONFIG_COLORSPECTRUM_FILTER */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t