Patch readapted by Stefano Sabatini, color values proposed by Tim
Nicholson <nichot20@yahoo.com>.
Address trac ticket #1462.
See thread:
Subject: [FFmpeg-devel] [PATCH] smptebars filter
Date: Wed, 20 Jun 2012 01:54:58 +0000
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
... | ... |
@@ -3918,7 +3918,7 @@ ffplay -f lavfi life=s=300x200:mold=10:r=60:ratio=0.1:death_color=#C83232:life_c |
3918 | 3918 |
@end example |
3919 | 3919 |
@end itemize |
3920 | 3920 |
|
3921 |
-@section color, nullsrc, rgbtestsrc, testsrc |
|
3921 |
+@section color, nullsrc, rgbtestsrc, smptebars, testsrc |
|
3922 | 3922 |
|
3923 | 3923 |
The @code{color} source provides an uniformly colored input. |
3924 | 3924 |
|
... | ... |
@@ -3930,6 +3930,9 @@ The @code{rgbtestsrc} source generates an RGB test pattern useful for |
3930 | 3930 |
detecting RGB vs BGR issues. You should see a red, green and blue |
3931 | 3931 |
stripe from top to bottom. |
3932 | 3932 |
|
3933 |
+The @code{smptebars} source generates a color bars pattern, based on |
|
3934 |
+the SMPTE Engineering Guideline EG 1-1990. |
|
3935 |
+ |
|
3933 | 3936 |
The @code{testsrc} source generates a test video pattern, showing a |
3934 | 3937 |
color pattern, a scrolling gradient and a timestamp. This is mainly |
3935 | 3938 |
intended for testing purposes. |
... | ... |
@@ -139,6 +139,7 @@ OBJS-$(CONFIG_MANDELBROT_FILTER) += vsrc_mandelbrot.o |
139 | 139 |
OBJS-$(CONFIG_MPTESTSRC_FILTER) += vsrc_mptestsrc.o |
140 | 140 |
OBJS-$(CONFIG_NULLSRC_FILTER) += vsrc_testsrc.o |
141 | 141 |
OBJS-$(CONFIG_RGBTESTSRC_FILTER) += vsrc_testsrc.o |
142 |
+OBJS-$(CONFIG_SMPTEBARS_FILTER) += vsrc_testsrc.o |
|
142 | 143 |
OBJS-$(CONFIG_TESTSRC_FILTER) += vsrc_testsrc.o |
143 | 144 |
|
144 | 145 |
OBJS-$(CONFIG_BUFFERSINK_FILTER) += sink_buffer.o |
... | ... |
@@ -129,6 +129,7 @@ void avfilter_register_all(void) |
129 | 129 |
REGISTER_FILTER (MPTESTSRC, mptestsrc, vsrc); |
130 | 130 |
REGISTER_FILTER (NULLSRC, nullsrc, vsrc); |
131 | 131 |
REGISTER_FILTER (RGBTESTSRC, rgbtestsrc, vsrc); |
132 |
+ REGISTER_FILTER (SMPTEBARS, smptebars, vsrc); |
|
132 | 133 |
REGISTER_FILTER (TESTSRC, testsrc, vsrc); |
133 | 134 |
|
134 | 135 |
REGISTER_FILTER (BUFFERSINK, buffersink, vsink); |
... | ... |
@@ -29,8 +29,8 @@ |
29 | 29 |
#include "libavutil/avutil.h" |
30 | 30 |
|
31 | 31 |
#define LIBAVFILTER_VERSION_MAJOR 3 |
32 |
-#define LIBAVFILTER_VERSION_MINOR 5 |
|
33 |
-#define LIBAVFILTER_VERSION_MICRO 102 |
|
32 |
+#define LIBAVFILTER_VERSION_MINOR 6 |
|
33 |
+#define LIBAVFILTER_VERSION_MICRO 100 |
|
34 | 34 |
|
35 | 35 |
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ |
36 | 36 |
LIBAVFILTER_VERSION_MINOR, \ |
... | ... |
@@ -1,6 +1,7 @@ |
1 | 1 |
/* |
2 | 2 |
* Copyright (c) 2007 Nicolas George <nicolas.george@normalesup.org> |
3 | 3 |
* Copyright (c) 2011 Stefano Sabatini |
4 |
+ * Copyright (c) 2012 Paul B Mahol |
|
4 | 5 |
* |
5 | 6 |
* This file is part of FFmpeg. |
6 | 7 |
* |
... | ... |
@@ -28,6 +29,8 @@ |
28 | 28 |
* |
29 | 29 |
* rgbtestsrc is ported from MPlayer libmpcodecs/vf_rgbtest.c by |
30 | 30 |
* Michael Niedermayer. |
31 |
+ * |
|
32 |
+ * smptebars is by Paul B Mahol. |
|
31 | 33 |
*/ |
32 | 34 |
|
33 | 35 |
#include <float.h> |
... | ... |
@@ -646,3 +649,131 @@ AVFilter avfilter_vsrc_rgbtestsrc = { |
646 | 646 |
}; |
647 | 647 |
|
648 | 648 |
#endif /* CONFIG_RGBTESTSRC_FILTER */ |
649 |
+ |
|
650 |
+#if CONFIG_SMPTEBARS_FILTER |
|
651 |
+ |
|
652 |
+#define smptebars_options options |
|
653 |
+AVFILTER_DEFINE_CLASS(smptebars); |
|
654 |
+ |
|
655 |
+static const uint8_t rainbow[7][4] = { |
|
656 |
+ { 191, 191, 191, 255 }, /* gray */ |
|
657 |
+ { 191, 191, 0, 255 }, /* yellow */ |
|
658 |
+ { 0, 191, 191, 255 }, /* cyan */ |
|
659 |
+ { 0, 191, 0, 255 }, /* green */ |
|
660 |
+ { 191, 0, 191, 255 }, /* magenta */ |
|
661 |
+ { 191, 0, 0, 255 }, /* red */ |
|
662 |
+ { 0, 0, 191, 255 }, /* blue */ |
|
663 |
+}; |
|
664 |
+ |
|
665 |
+static const uint8_t wobnair[7][4] = { |
|
666 |
+ { 0, 0, 191, 255 }, /* blue */ |
|
667 |
+ { 19, 19, 19, 255 }, /* 7.5% intensity black */ |
|
668 |
+ { 191, 0, 191, 255 }, /* magenta */ |
|
669 |
+ { 19, 19, 19, 255 }, /* 7.5% intensity black */ |
|
670 |
+ { 0, 191, 191, 255 }, /* cyan */ |
|
671 |
+ { 19, 19, 19, 255 }, /* 7.5% intensity black */ |
|
672 |
+ { 191, 191, 191, 255 }, /* gray */ |
|
673 |
+}; |
|
674 |
+ |
|
675 |
+static const uint8_t white[4] = { 255, 255, 255, 255 }; |
|
676 |
+static const uint8_t black[4] = { 19, 19, 19, 255 }; /* 7.5% intensity black */ |
|
677 |
+ |
|
678 |
+/* pluge pulses */ |
|
679 |
+static const uint8_t neg4ire[4] = { 9, 9, 9, 255 }; /* 3.5% intensity black */ |
|
680 |
+static const uint8_t pos4ire[4] = { 29, 29, 29, 255 }; /* 11.5% intensity black */ |
|
681 |
+ |
|
682 |
+/* fudged Q/-I */ |
|
683 |
+static const uint8_t i_pixel[4] = { 0, 68, 130, 255 }; |
|
684 |
+static const uint8_t q_pixel[4] = { 67, 0, 130, 255 }; |
|
685 |
+ |
|
686 |
+static void smptebars_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) |
|
687 |
+{ |
|
688 |
+ TestSourceContext *test = ctx->priv; |
|
689 |
+ FFDrawColor color; |
|
690 |
+ int r_w, r_h, w_h, p_w, p_h, i, x = 0; |
|
691 |
+ |
|
692 |
+ r_w = (test->w + 6) / 7; |
|
693 |
+ r_h = test->h * 2 / 3; |
|
694 |
+ w_h = test->h * 3 / 4 - r_h; |
|
695 |
+ p_w = r_w * 5 / 4; |
|
696 |
+ p_h = test->h - w_h - r_h; |
|
697 |
+ |
|
698 |
+#define DRAW_COLOR(rgba, x, y, w, h) \ |
|
699 |
+ ff_draw_color(&test->draw, &color, rgba); \ |
|
700 |
+ ff_fill_rectangle(&test->draw, &color, \ |
|
701 |
+ picref->data, picref->linesize, x, y, w, h) \ |
|
702 |
+ |
|
703 |
+ for (i = 0; i < 7; i++) { |
|
704 |
+ DRAW_COLOR(rainbow[i], x, 0, FFMIN(r_w, test->w - x), r_h); |
|
705 |
+ DRAW_COLOR(wobnair[i], x, r_h, FFMIN(r_w, test->w - x), w_h); |
|
706 |
+ x += r_w; |
|
707 |
+ } |
|
708 |
+ x = 0; |
|
709 |
+ DRAW_COLOR(i_pixel, x, r_h + w_h, p_w, p_h); |
|
710 |
+ x += p_w; |
|
711 |
+ DRAW_COLOR(white, x, r_h + w_h, p_w, p_h); |
|
712 |
+ x += p_w; |
|
713 |
+ DRAW_COLOR(q_pixel, x, r_h + w_h, p_w, p_h); |
|
714 |
+ x += p_w; |
|
715 |
+ DRAW_COLOR(black, x, r_h + w_h, 5 * r_w - x, p_h); |
|
716 |
+ x += 5 * r_w - x; |
|
717 |
+ DRAW_COLOR(neg4ire, x, r_h + w_h, r_w / 3, p_h); |
|
718 |
+ x += r_w / 3; |
|
719 |
+ DRAW_COLOR(black, x, r_h + w_h, r_w / 3, p_h); |
|
720 |
+ x += r_w / 3; |
|
721 |
+ DRAW_COLOR(pos4ire, x, r_h + w_h, r_w / 3, p_h); |
|
722 |
+ x += r_w / 3; |
|
723 |
+ DRAW_COLOR(black, x, r_h + w_h, test->w - x, p_h); |
|
724 |
+} |
|
725 |
+ |
|
726 |
+static av_cold int smptebars_init(AVFilterContext *ctx, const char *args) |
|
727 |
+{ |
|
728 |
+ TestSourceContext *test = ctx->priv; |
|
729 |
+ |
|
730 |
+ test->class = &smptebars_class; |
|
731 |
+ test->fill_picture_fn = smptebars_fill_picture; |
|
732 |
+ test->draw_once = 1; |
|
733 |
+ return init(ctx, args); |
|
734 |
+} |
|
735 |
+ |
|
736 |
+static int smptebars_query_formats(AVFilterContext *ctx) |
|
737 |
+{ |
|
738 |
+ ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0)); |
|
739 |
+ return 0; |
|
740 |
+} |
|
741 |
+ |
|
742 |
+static int smptebars_config_props(AVFilterLink *outlink) |
|
743 |
+{ |
|
744 |
+ AVFilterContext *ctx = outlink->src; |
|
745 |
+ TestSourceContext *test = ctx->priv; |
|
746 |
+ |
|
747 |
+ ff_draw_init(&test->draw, outlink->format, 0); |
|
748 |
+ |
|
749 |
+ return config_props(outlink); |
|
750 |
+} |
|
751 |
+ |
|
752 |
+AVFilter avfilter_vsrc_smptebars = { |
|
753 |
+ .name = "smptebars", |
|
754 |
+ .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."), |
|
755 |
+ .priv_size = sizeof(TestSourceContext), |
|
756 |
+ .init = smptebars_init, |
|
757 |
+ .uninit = uninit, |
|
758 |
+ |
|
759 |
+ .query_formats = smptebars_query_formats, |
|
760 |
+ |
|
761 |
+ .inputs = (const AVFilterPad[]) { |
|
762 |
+ { .name = NULL } |
|
763 |
+ }, |
|
764 |
+ |
|
765 |
+ .outputs = (const AVFilterPad[]) { |
|
766 |
+ { |
|
767 |
+ .name = "default", |
|
768 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
769 |
+ .request_frame = request_frame, |
|
770 |
+ .config_props = smptebars_config_props, |
|
771 |
+ }, |
|
772 |
+ { .name = NULL } |
|
773 |
+ }, |
|
774 |
+}; |
|
775 |
+ |
|
776 |
+#endif /* CONFIG_SMPTEBARS_FILTER */ |