Browse code

lavfi: add smptehdbars source

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2013/04/12 00:49:44
Showing 6 changed files
... ...
@@ -21,6 +21,7 @@ version <next>:
21 21
 - uniform options syntax across all filters
22 22
 - telecine filter
23 23
 - new interlace filter
24
+- smptehdbars source
24 25
 
25 26
 
26 27
 version 1.2:
... ...
@@ -6194,7 +6194,7 @@ ffplay -f lavfi life=s=300x200:mold=10:r=60:ratio=0.1:death_color=#C83232:life_c
6194 6194
 @end example
6195 6195
 @end itemize
6196 6196
 
6197
-@section color, nullsrc, rgbtestsrc, smptebars, testsrc
6197
+@section color, nullsrc, rgbtestsrc, smptebars, smptehdbars, testsrc
6198 6198
 
6199 6199
 The @code{color} source provides an uniformly colored input.
6200 6200
 
... ...
@@ -6209,6 +6209,9 @@ stripe from top to bottom.
6209 6209
 The @code{smptebars} source generates a color bars pattern, based on
6210 6210
 the SMPTE Engineering Guideline EG 1-1990.
6211 6211
 
6212
+The @code{smptehdbars} source generates a color bars pattern, based on
6213
+the SMPTE RP 219-2002.
6214
+
6212 6215
 The @code{testsrc} source generates a test video pattern, showing a
6213 6216
 color pattern, a scrolling gradient and a timestamp. This is mainly
6214 6217
 intended for testing purposes.
... ...
@@ -183,6 +183,7 @@ OBJS-$(CONFIG_MPTESTSRC_FILTER)              += vsrc_mptestsrc.o
183 183
 OBJS-$(CONFIG_NULLSRC_FILTER)                += vsrc_testsrc.o
184 184
 OBJS-$(CONFIG_RGBTESTSRC_FILTER)             += vsrc_testsrc.o
185 185
 OBJS-$(CONFIG_SMPTEBARS_FILTER)              += vsrc_testsrc.o
186
+OBJS-$(CONFIG_SMPTEHDBARS_FILTER)            += vsrc_testsrc.o
186 187
 OBJS-$(CONFIG_TESTSRC_FILTER)                += vsrc_testsrc.o
187 188
 
188 189
 OBJS-$(CONFIG_NULLSINK_FILTER)               += vsink_nullsink.o
... ...
@@ -180,6 +180,7 @@ void avfilter_register_all(void)
180 180
     REGISTER_FILTER(NULLSRC,        nullsrc,        vsrc);
181 181
     REGISTER_FILTER(RGBTESTSRC,     rgbtestsrc,     vsrc);
182 182
     REGISTER_FILTER(SMPTEBARS,      smptebars,      vsrc);
183
+    REGISTER_FILTER(SMPTEHDBARS,    smptehdbars,    vsrc);
183 184
     REGISTER_FILTER(TESTSRC,        testsrc,        vsrc);
184 185
 
185 186
     REGISTER_FILTER(NULLSINK,       nullsink,       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  53
33
-#define LIBAVFILTER_VERSION_MICRO 101
32
+#define LIBAVFILTER_VERSION_MINOR  54
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, \
... ...
@@ -30,7 +30,7 @@
30 30
  * rgbtestsrc is ported from MPlayer libmpcodecs/vf_rgbtest.c by
31 31
  * Michael Niedermayer.
32 32
  *
33
- * smptebars is by Paul B Mahol.
33
+ * smptebars and smptehdbars is by Paul B Mahol.
34 34
  */
35 35
 
36 36
 #include <float.h>
... ...
@@ -654,10 +654,7 @@ AVFilter avfilter_vsrc_rgbtestsrc = {
654 654
 
655 655
 #endif /* CONFIG_RGBTESTSRC_FILTER */
656 656
 
657
-#if CONFIG_SMPTEBARS_FILTER
658
-
659
-#define smptebars_options options
660
-AVFILTER_DEFINE_CLASS(smptebars);
657
+#if CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER
661 658
 
662 659
 static const uint8_t rainbow[7][4] = {
663 660
     { 191, 191, 191, 255 },     /* gray */
... ...
@@ -690,6 +687,17 @@ static const uint8_t pos4ire[4] = {  29,  29,  29, 255 }; /* 11.5% intensity bla
690 690
 static const uint8_t i_pixel[4] = {   0,  68, 130, 255 };
691 691
 static const uint8_t q_pixel[4] = {  67,   0, 130, 255 };
692 692
 
693
+static const uint8_t gray40[4] = { 102, 102, 102, 255 };
694
+static const uint8_t gray15[4] = {  38,  38,  38, 255 };
695
+static const uint8_t   cyan[4] = {   0, 255, 255, 255 };
696
+static const uint8_t yellow[4] = { 255, 255,   0, 255 };
697
+static const uint8_t   blue[4] = {   0,   0, 255, 255 };
698
+static const uint8_t    red[4] = { 255,   0,   0, 255 };
699
+static const uint8_t black0[4] = {   5,   5,   5, 255 };
700
+static const uint8_t black2[4] = {  10,  10,  10, 255 };
701
+static const uint8_t black4[4] = {  15,  15,  15, 255 };
702
+static const uint8_t   neg2[4] = {   0,   0,   0, 255 };
703
+
693 704
 static void inline draw_bar(TestSourceContext *test, const uint8_t *color,
694 705
                             unsigned x, unsigned y, unsigned w, unsigned h,
695 706
                             AVFrame *frame)
... ...
@@ -709,6 +717,37 @@ static void inline draw_bar(TestSourceContext *test, const uint8_t *color,
709 709
                       frame->data, frame->linesize, x, y, w, h);
710 710
 }
711 711
 
712
+static int smptebars_query_formats(AVFilterContext *ctx)
713
+{
714
+    ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
715
+    return 0;
716
+}
717
+
718
+static int smptebars_config_props(AVFilterLink *outlink)
719
+{
720
+    AVFilterContext *ctx = outlink->src;
721
+    TestSourceContext *test = ctx->priv;
722
+
723
+    ff_draw_init(&test->draw, outlink->format, 0);
724
+
725
+    return config_props(outlink);
726
+}
727
+
728
+static const AVFilterPad smptebars_outputs[] = {
729
+    {
730
+        .name          = "default",
731
+        .type          = AVMEDIA_TYPE_VIDEO,
732
+        .request_frame = request_frame,
733
+        .config_props  = smptebars_config_props,
734
+    },
735
+    { NULL }
736
+};
737
+
738
+#if CONFIG_SMPTEHDBARS_FILTER
739
+
740
+#define smptebars_options options
741
+AVFILTER_DEFINE_CLASS(smptebars);
742
+
712 743
 static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
713 744
 {
714 745
     TestSourceContext *test = ctx->priv;
... ...
@@ -755,37 +794,115 @@ static av_cold int smptebars_init(AVFilterContext *ctx)
755 755
     return init(ctx);
756 756
 }
757 757
 
758
-static int smptebars_query_formats(AVFilterContext *ctx)
759
-{
760
-    ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
761
-    return 0;
762
-}
758
+AVFilter avfilter_vsrc_smptebars = {
759
+    .name      = "smptebars",
760
+    .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
761
+    .priv_size = sizeof(TestSourceContext),
762
+    .init      = smptebars_init,
763
+    .uninit    = uninit,
763 764
 
764
-static int smptebars_config_props(AVFilterLink *outlink)
765
+    .query_formats = smptebars_query_formats,
766
+    .inputs        = NULL,
767
+    .outputs       = smptebars_outputs,
768
+    .priv_class    = &smptebars_class,
769
+};
770
+
771
+#endif  /* CONFIG_SMPTEBARS_FILTER */
772
+
773
+#if CONFIG_SMPTEHDBARS_FILTER
774
+
775
+#define smptehdbars_options options
776
+AVFILTER_DEFINE_CLASS(smptehdbars);
777
+
778
+static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
765 779
 {
766
-    AVFilterContext *ctx = outlink->src;
767 780
     TestSourceContext *test = ctx->priv;
781
+    int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
782
+    const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
768 783
 
769
-    ff_draw_init(&test->draw, outlink->format, 0);
784
+    d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);
785
+    r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);
786
+    draw_bar(test, gray40, x, 0, d_w, r_h, picref);
787
+    x += d_w;
770 788
 
771
-    return config_props(outlink);
789
+    r_w = FFALIGN((((test->w + 3) / 4) * 3) / 7, 1 << pixdesc->log2_chroma_w);
790
+    for (i = 0; i < 7; i++) {
791
+        draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
792
+        x += r_w;
793
+    }
794
+    draw_bar(test, gray40, x, 0, test->w - x, r_h, picref);
795
+    y = r_h;
796
+    r_h = FFALIGN(test->h / 12, 1 << pixdesc->log2_chroma_h);
797
+    draw_bar(test, cyan, 0, y, d_w, r_h, picref);
798
+    x = d_w;
799
+    draw_bar(test, i_pixel, x, y, r_w, r_h, picref);
800
+    x += r_w;
801
+    tmp = r_w * 6;
802
+    draw_bar(test, rainbow[0], x, y, tmp, r_h, picref);
803
+    x += tmp;
804
+    l_w = x;
805
+    draw_bar(test, blue, x, y, test->w - x, r_h, picref);
806
+    y += r_h;
807
+    draw_bar(test, yellow, 0, y, d_w, r_h, picref);
808
+    x = d_w;
809
+    draw_bar(test, q_pixel, x, y, r_w, r_h, picref);
810
+    x += r_w;
811
+
812
+    for (i = 0; i < tmp; i += 1 << pixdesc->log2_chroma_w) {
813
+        uint8_t yramp[4] = {0};
814
+
815
+        yramp[0] =
816
+        yramp[1] =
817
+        yramp[2] = i * 255 / tmp;
818
+        yramp[3] = 255;
819
+
820
+        draw_bar(test, yramp, x, y, 1 << pixdesc->log2_chroma_w, r_h, picref);
821
+        x += 1 << pixdesc->log2_chroma_w;
822
+    }
823
+    draw_bar(test, red, x, y, test->w - x, r_h, picref);
824
+    y += r_h;
825
+    draw_bar(test, gray15, 0, y, d_w, test->h - y, picref);
826
+    x = d_w;
827
+    tmp = FFALIGN(r_w * 3 / 2, 1 << pixdesc->log2_chroma_w);
828
+    draw_bar(test, black0, x, y, tmp, test->h - y, picref);
829
+    x += tmp;
830
+    tmp = FFALIGN(r_w * 2, 1 << pixdesc->log2_chroma_w);
831
+    draw_bar(test, white, x, y, tmp, test->h - y, picref);
832
+    x += tmp;
833
+    tmp = FFALIGN(r_w * 5 / 6, 1 << pixdesc->log2_chroma_w);
834
+    draw_bar(test, black0, x, y, tmp, test->h - y, picref);
835
+    x += tmp;
836
+    tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
837
+    draw_bar(test,   neg2, x, y, tmp, test->h - y, picref);
838
+    x += tmp;
839
+    draw_bar(test, black0, x, y, tmp, test->h - y, picref);
840
+    x += tmp;
841
+    draw_bar(test, black2, x, y, tmp, test->h - y, picref);
842
+    x += tmp;
843
+    draw_bar(test, black0, x, y, tmp, test->h - y, picref);
844
+    x += tmp;
845
+    draw_bar(test, black4, x, y, tmp, test->h - y, picref);
846
+    x += tmp;
847
+    r_w = l_w - x;
848
+    draw_bar(test, black0, x, y, r_w, test->h - y, picref);
849
+    x += r_w;
850
+    draw_bar(test, gray15, x, y, test->w - x, test->h - y, picref);
772 851
 }
773 852
 
774
-static const AVFilterPad smptebars_outputs[] = {
775
-    {
776
-        .name          = "default",
777
-        .type          = AVMEDIA_TYPE_VIDEO,
778
-        .request_frame = request_frame,
779
-        .config_props  = smptebars_config_props,
780
-    },
781
-    { NULL }
782
-};
853
+static av_cold int smptehdbars_init(AVFilterContext *ctx)
854
+{
855
+    TestSourceContext *test = ctx->priv;
783 856
 
784
-AVFilter avfilter_vsrc_smptebars = {
785
-    .name      = "smptebars",
786
-    .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
857
+    test->fill_picture_fn = smptehdbars_fill_picture;
858
+    test->draw_once = 1;
859
+    return init(ctx);
860
+}
861
+
862
+AVFilter avfilter_vsrc_smptehdbars = {
863
+    .name      = "smptehdbars",
864
+    .description = NULL_IF_CONFIG_SMALL("Generate SMPTE HD color bars."),
787 865
     .priv_size = sizeof(TestSourceContext),
788
-    .init      = smptebars_init,
866
+    .init      = smptehdbars_init,
789 867
     .uninit    = uninit,
790 868
 
791 869
     .query_formats = smptebars_query_formats,
... ...
@@ -794,4 +911,5 @@ AVFilter avfilter_vsrc_smptebars = {
794 794
     .priv_class    = &smptebars_class,
795 795
 };
796 796
 
797
-#endif  /* CONFIG_SMPTEBARS_FILTER */
797
+#endif  /* CONFIG_SMPTEHDBARS_FILTER */
798
+#endif  /* CONFIG_SMPTEHDBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER */