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
30- xcorrelate video filter30- xcorrelate video filter
31- varblur video filter31- varblur video filter
32- huesaturation video filter32- huesaturation video filter
33- colorspectrum source video filter
33 34
34 35
35version 4.4:36version 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
25257@anchor{allrgb}25257@anchor{allrgb}
25258@anchor{allyuv}25258@anchor{allyuv}
25259@anchor{color}25259@anchor{color}
25260@anchor{colorspectrum}
25260@anchor{haldclutsrc}25261@anchor{haldclutsrc}
25261@anchor{nullsrc}25262@anchor{nullsrc}
25262@anchor{pal75bars}25263@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
25267@anchor{testsrc}25268@anchor{testsrc}
25268@anchor{testsrc2}25269@anchor{testsrc2}
25269@anchor{yuvtestsrc}25270@anchor{yuvtestsrc}
25270@section allrgb, allyuv, color, haldclutsrc, nullsrc, pal75bars, pal100bars, rgbtestsrc, smptebars, smptehdbars, testsrc, testsrc2, yuvtestsrc25271@section allrgb, allyuv, color, colorspectrum, haldclutsrc, nullsrc, pal75bars, pal100bars, rgbtestsrc, smptebars, smptehdbars, testsrc, testsrc2, yuvtestsrc
25271 25272
25272The @code{allrgb} source returns frames of size 4096x4096 of all rgb colors.25273The @code{allrgb} source returns frames of size 4096x4096 of all rgb colors.
25273 25274
@@ -25275,6 +25276,8 @@ The @code{allyuv} source returns frames of size 4096x4096 of all yuv colors. · 1 unmodified line
25275 25276
25276The @code{color} source provides an uniformly colored input.25277The @code{color} source provides an uniformly colored input.
25277 25278
25279The @code{colorspectrum} source provides a color spectrum input.
25280
25278The @code{haldclutsrc} source provides an identity Hald CLUT. See also25281The @code{haldclutsrc} source provides an identity Hald CLUT. See also
25279@ref{haldclut} filter.25282@ref{haldclut} filter.
25280 25283
@@ -25366,6 +25369,16 @@ Set the number of decimals to show in the timestamp, only available in the · 85 unmodified lines
25366The displayed timestamp value will correspond to the original25369The displayed timestamp value will correspond to the original
25367timestamp value multiplied by the power of 10 of the specified25370timestamp value multiplied by the power of 10 of the specified
25368value. Default value is 0.25371value. Default value is 0.
25372
25373@item type
25374Set 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
25369@end table25382@end table
25370 25383
25371@subsection Examples25384@subsection Examples
libavfilter/Makefile+1−0
@@ -522,6 +522,7 @@ OBJS-$(CONFIG_ALLRGB_FILTER) += vsrc_testsrc.o · 521 unmodified lines
522OBJS-$(CONFIG_ALLYUV_FILTER) += vsrc_testsrc.o522OBJS-$(CONFIG_ALLYUV_FILTER) += vsrc_testsrc.o
523OBJS-$(CONFIG_CELLAUTO_FILTER) += vsrc_cellauto.o523OBJS-$(CONFIG_CELLAUTO_FILTER) += vsrc_cellauto.o
524OBJS-$(CONFIG_COLOR_FILTER) += vsrc_testsrc.o524OBJS-$(CONFIG_COLOR_FILTER) += vsrc_testsrc.o
525OBJS-$(CONFIG_COLORSPECTRUM_FILTER) += vsrc_testsrc.o
525OBJS-$(CONFIG_COREIMAGESRC_FILTER) += vf_coreimage.o526OBJS-$(CONFIG_COREIMAGESRC_FILTER) += vf_coreimage.o
526OBJS-$(CONFIG_FREI0R_SRC_FILTER) += vf_frei0r.o527OBJS-$(CONFIG_FREI0R_SRC_FILTER) += vf_frei0r.o
527OBJS-$(CONFIG_GRADIENTS_FILTER) += vsrc_gradients.o528OBJS-$(CONFIG_GRADIENTS_FILTER) += vsrc_gradients.o
libavfilter/allfilters.c+1−0
@@ -498,6 +498,7 @@ extern const AVFilter ff_vsrc_allrgb; · 497 unmodified lines
498extern const AVFilter ff_vsrc_allyuv;498extern const AVFilter ff_vsrc_allyuv;
499extern const AVFilter ff_vsrc_cellauto;499extern const AVFilter ff_vsrc_cellauto;
500extern const AVFilter ff_vsrc_color;500extern const AVFilter ff_vsrc_color;
501extern const AVFilter ff_vsrc_colorspectrum;
501extern const AVFilter ff_vsrc_coreimagesrc;502extern const AVFilter ff_vsrc_coreimagesrc;
502extern const AVFilter ff_vsrc_frei0r_src;503extern const AVFilter ff_vsrc_frei0r_src;
503extern const AVFilter ff_vsrc_gradients;504extern const AVFilter ff_vsrc_gradients;
libavfilter/version.h+2−2
@@ -30,8 +30,8 @@ · 29 unmodified lines
30#include "libavutil/version.h"30#include "libavutil/version.h"
31 31
32#define LIBAVFILTER_VERSION_MAJOR 832#define LIBAVFILTER_VERSION_MAJOR 8
33#define LIBAVFILTER_VERSION_MINOR 1633#define LIBAVFILTER_VERSION_MINOR 17
34#define LIBAVFILTER_VERSION_MICRO 10234#define LIBAVFILTER_VERSION_MICRO 100
35 35
36 36
37#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \37#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
70 /* only used by testsrc2 */70 /* only used by testsrc2 */
71 int alpha;71 int alpha;
72 72
73 /* only used by colorspectrum */
74 int type;
75
73 /* only used by color */76 /* only used by color */
74 FFDrawContext draw;77 FFDrawContext draw;
75 FFDrawColor color;78 FFDrawColor color;
@@ -1791,3 +1794,92 @@ const AVFilter ff_vsrc_allrgb = { · 1715 unmodified lines
1791};1794};
1792 1795
1793#endif /* CONFIG_ALLRGB_FILTER */1796#endif /* CONFIG_ALLRGB_FILTER */
1797
1798#if CONFIG_COLORSPECTRUM_FILTER
1799
1800static 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
1809AVFILTER_DEFINE_CLASS(colorspectrum);
1810
1811static inline float mix(float a, float b, float mix)
1812{
1813 return a * mix + b * (1.f - mix);
1814}
1815
1816static 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
1826static 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
1855static 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
1864static const AVFilterPad avfilter_vsrc_colorspectrum_outputs[] = {
1865 {
1866 .name = "default",
1867 .type = AVMEDIA_TYPE_VIDEO,
1868 .config_props = config_props,
1869 },
1870};
1871
1872const 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