Browse code

Add pixdesctest filter and corresponding test.

Originally committed as revision 24092 to svn://svn.ffmpeg.org/ffmpeg/trunk

Stefano Sabatini authored on 2010/07/08 03:24:55
Showing 7 changed files
... ...
@@ -268,6 +268,7 @@ LAVFI_TESTS =           \
268 268
     vflip               \
269 269
     vflip_crop          \
270 270
     vflip_vflip         \
271
+    lavfi_pixdesc       \
271 272
 #   lavfi_pix_fmts      \
272 273
 
273 274
 ACODEC_TESTS := $(addprefix regtest-, $(ACODEC_TESTS) $(ACODEC_TESTS-yes))
... ...
@@ -112,6 +112,18 @@ The default value of @var{color} is ``black''.
112 112
 
113 113
 @end table
114 114
 
115
+@section pixdesctest
116
+
117
+Pixel format descriptor test filter, mainly useful for internal
118
+testing. The output video should be equal to the input video.
119
+
120
+For example:
121
+@example
122
+format=monow, pixdesctest
123
+@end example
124
+
125
+can be used to test the monowhite pixel format descriptor definition.
126
+
115 127
 @section scale
116 128
 
117 129
 Scale the input video to @var{width}:@var{height} and/or convert the image format.
... ...
@@ -20,6 +20,7 @@ OBJS-$(CONFIG_FORMAT_FILTER)                 += vf_format.o
20 20
 OBJS-$(CONFIG_NOFORMAT_FILTER)               += vf_format.o
21 21
 OBJS-$(CONFIG_NULL_FILTER)                   += vf_null.o
22 22
 OBJS-$(CONFIG_PAD_FILTER)                    += vf_pad.o
23
+OBJS-$(CONFIG_PIXDESCTEST_FILTER)            += vf_pixdesctest.o
23 24
 OBJS-$(CONFIG_PIXELASPECT_FILTER)            += vf_aspect.o
24 25
 OBJS-$(CONFIG_SCALE_FILTER)                  += vf_scale.o
25 26
 OBJS-$(CONFIG_SLICIFY_FILTER)                += vf_slicify.o
... ...
@@ -40,6 +40,7 @@ void avfilter_register_all(void)
40 40
     REGISTER_FILTER (NOFORMAT,    noformat,    vf);
41 41
     REGISTER_FILTER (NULL,        null,        vf);
42 42
     REGISTER_FILTER (PAD,         pad,         vf);
43
+    REGISTER_FILTER (PIXDESCTEST, pixdesctest, vf);
43 44
     REGISTER_FILTER (PIXELASPECT, pixelaspect, vf);
44 45
     REGISTER_FILTER (SCALE,       scale,       vf);
45 46
     REGISTER_FILTER (SLICIFY,     slicify,     vf);
... ...
@@ -25,7 +25,7 @@
25 25
 #include "libavutil/avutil.h"
26 26
 
27 27
 #define LIBAVFILTER_VERSION_MAJOR  1
28
-#define LIBAVFILTER_VERSION_MINOR 21
28
+#define LIBAVFILTER_VERSION_MINOR 22
29 29
 #define LIBAVFILTER_VERSION_MICRO  0
30 30
 
31 31
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
32 32
new file mode 100644
... ...
@@ -0,0 +1,128 @@
0
+/*
1
+ * This file is part of FFmpeg.
2
+ * copyright (C) 2009 Stefano Sabatini
3
+ *
4
+ * FFmpeg is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU Lesser General Public
6
+ * License as published by the Free Software Foundation; either
7
+ * version 2.1 of the License, or (at your option) any later version.
8
+ *
9
+ * FFmpeg is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * Lesser General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Lesser General Public
15
+ * License along with FFmpeg; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
18
+
19
+/**
20
+ * @file
21
+ * pixdesc test filter
22
+ */
23
+
24
+#include "libavutil/pixdesc.h"
25
+#include "avfilter.h"
26
+
27
+typedef struct {
28
+    const AVPixFmtDescriptor *pix_desc;
29
+    uint16_t *line;
30
+} PixdescTestContext;
31
+
32
+static av_cold void uninit(AVFilterContext *ctx)
33
+{
34
+    PixdescTestContext *priv = ctx->priv;
35
+    av_freep(&priv->line);
36
+}
37
+
38
+static int config_props(AVFilterLink *inlink)
39
+{
40
+    PixdescTestContext *priv = inlink->dst->priv;
41
+
42
+    priv->pix_desc = &av_pix_fmt_descriptors[inlink->format];
43
+
44
+    if (!(priv->line = av_malloc(sizeof(*priv->line) * inlink->w)))
45
+        return AVERROR(ENOMEM);
46
+
47
+    return 0;
48
+}
49
+
50
+static void start_frame(AVFilterLink *inlink, AVFilterPicRef *picref)
51
+{
52
+    PixdescTestContext *priv = inlink->dst->priv;
53
+    AVFilterLink *outlink    = inlink->dst->outputs[0];
54
+    AVFilterPicRef *outpicref;
55
+    int i;
56
+
57
+    outlink->outpic = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
58
+                                                outlink->w, outlink->h);
59
+    outpicref = outlink->outpic;
60
+    avfilter_copy_picref_props(outpicref, picref);
61
+
62
+    for (i = 0; i < 4; i++) {
63
+        int h = outlink->h;
64
+        h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
65
+        if (outpicref->data[i]) {
66
+            uint8_t *data = outpicref->data[i] +
67
+                (outpicref->linesize[i] > 0 ? 0 : outpicref->linesize[i] * (h-1));
68
+            memset(data, 0, FFABS(outpicref->linesize[i]) * h);
69
+        }
70
+    }
71
+
72
+    /* copy palette */
73
+    if (priv->pix_desc->flags & PIX_FMT_PAL)
74
+        memcpy(outpicref->data[1], outpicref->data[1], 256*4);
75
+
76
+    avfilter_start_frame(outlink, avfilter_ref_pic(outpicref, ~0));
77
+}
78
+
79
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
80
+{
81
+    PixdescTestContext *priv = inlink->dst->priv;
82
+    AVFilterPicRef *inpic    = inlink->cur_pic;
83
+    AVFilterPicRef *outpic   = inlink->dst->outputs[0]->outpic;
84
+    int i, c, w = inlink->w;
85
+
86
+    for (c = 0; c < priv->pix_desc->nb_components; c++) {
87
+        int w1 = c == 1 || c == 2 ? w>>priv->pix_desc->log2_chroma_w : w;
88
+        int h1 = c == 1 || c == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
89
+        int y1 = c == 1 || c == 2 ? y>>priv->pix_desc->log2_chroma_h : y;
90
+
91
+        for (i = y1; i < y1 + h1; i++) {
92
+            read_line(priv->line,
93
+                      inpic->data,
94
+                      inpic->linesize,
95
+                      priv->pix_desc,
96
+                      0, i, c, w1, 0);
97
+
98
+            write_line(priv->line,
99
+                       outpic->data,
100
+                       outpic->linesize,
101
+                       priv->pix_desc,
102
+                       0, i, c, w1);
103
+        }
104
+    }
105
+
106
+    avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
107
+}
108
+
109
+AVFilter avfilter_vf_pixdesctest = {
110
+    .name        = "pixdesctest",
111
+    .description = "Test pixel format definitions.",
112
+
113
+    .priv_size = sizeof(PixdescTestContext),
114
+    .uninit    = uninit,
115
+
116
+    .inputs    = (AVFilterPad[]) {{ .name            = "default",
117
+                                    .type            = AVMEDIA_TYPE_VIDEO,
118
+                                    .start_frame     = start_frame,
119
+                                    .draw_slice      = draw_slice,
120
+                                    .config_props    = config_props,
121
+                                    .min_perms       = AV_PERM_READ, },
122
+                                  { .name = NULL}},
123
+
124
+    .outputs   = (AVFilterPad[]) {{ .name            = "default",
125
+                                    .type            = AVMEDIA_TYPE_VIDEO, },
126
+                                  { .name = NULL}},
127
+};
... ...
@@ -86,6 +86,26 @@ if [ -n "$do_lavfi_pix_fmts" ]; then
86 86
     done
87 87
 fi
88 88
 
89
+if [ -n "$do_lavfi_pixdesc" ]; then
90
+    pix_fmts="$($ffmpeg -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^IO' | cut -d' ' -f2)"
91
+
92
+    ref_file=tests/ref/lavfi/lavfi_pixdesc
93
+    rm -f $ref_file
94
+    res_file=$logfile
95
+
96
+    for pix_fmt in $pix_fmts; do
97
+        # print to the reference logfile
98
+        logfile=$ref_file
99
+        do_video_encoding "lavfi_pixdesc-${pix_fmt}.nut" "" \
100
+            "-vf slicify=random,format=$pix_fmt -vcodec rawvideo -pix_fmt $pix_fmt"
101
+
102
+        # print to the result logfile
103
+        logfile=$res_file
104
+        do_video_encoding "lavfi_pixdesc-${pix_fmt}.nut" "" \
105
+            "-vf slicify=random,format=$pix_fmt,pixdesctest -vcodec rawvideo -pix_fmt $pix_fmt"
106
+    done
107
+fi
108
+
89 109
 # TODO: add tests for
90 110
 # direct rendering,
91 111
 # chains with feedback loops