2 * (c) 2001 Fabrice Bellard
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32 #include "libavutil/internal.h"
33 #include "libavutil/lfg.h"
34 #include "libavutil/mem.h"
35 #include "libavutil/time.h"
42 static uint8_t img1
[WIDTH
* HEIGHT
];
43 static uint8_t img2
[WIDTH
* HEIGHT
];
45 static void fill_random(uint8_t *tab
, int size
)
50 av_lfg_init(&prng
, 1);
52 tab
[i
] = av_lfg_get(&prng
) % 256;
56 static void help(void)
58 printf("motion-test [-h]\n"
59 "test motion implementations\n");
66 static void test_motion(const char *name
,
67 me_cmp_func test_func
, me_cmp_func ref_func
)
72 printf("testing '%s'\n", name
);
74 /* test correctness */
75 for(it
=0;it
<20;it
++) {
77 fill_random(img1
, WIDTH
* HEIGHT
);
78 fill_random(img2
, WIDTH
* HEIGHT
);
80 for(y
=0;y
<HEIGHT
-17;y
++) {
81 for(x
=0;x
<WIDTH
-17;x
++) {
82 ptr
= img2
+ y
* WIDTH
+ x
;
83 d1
= test_func(NULL
, img1
, ptr
, WIDTH
, 8);
84 d2
= ref_func(NULL
, img1
, ptr
, WIDTH
, 8);
86 printf("error: mmx=%d c=%d\n", d1
, d2
);
94 ti
= av_gettime_relative();
96 for(it
=0;it
<NB_ITS
;it
++) {
97 for(y
=0;y
<HEIGHT
-17;y
++) {
98 for(x
=0;x
<WIDTH
-17;x
++) {
99 ptr
= img2
+ y
* WIDTH
+ x
;
100 d1
+= test_func(NULL
, img1
, ptr
, WIDTH
, 8);
105 dummy
= d1
; /* avoid optimization */
106 ti
= av_gettime_relative() - ti
;
108 printf(" %0.0f kop/s\n",
109 (double)NB_ITS
* (WIDTH
- 16) * (HEIGHT
- 16) /
110 (double)(ti
/ 1000.0));
114 int main(int argc
, char **argv
)
118 MECmpContext cctx
, mmxctx
;
119 int flags
[2] = { AV_CPU_FLAG_MMX
, AV_CPU_FLAG_MMXEXT
};
120 int flags_size
= HAVE_MMXEXT
? 2 : 1;
127 printf("ffmpeg motion test\n");
129 ctx
= avcodec_alloc_context3(NULL
);
130 ctx
->flags
|= CODEC_FLAG_BITEXACT
;
131 av_force_cpu_flags(0);
132 memset(&cctx
, 0, sizeof(cctx
));
133 ff_me_cmp_init(&cctx
, ctx
);
134 for (c
= 0; c
< flags_size
; c
++) {
136 av_force_cpu_flags(flags
[c
]);
137 memset(&mmxctx
, 0, sizeof(mmxctx
));
138 ff_me_cmp_init(&mmxctx
, ctx
);
140 for (x
= 0; x
< 2; x
++) {
141 printf("%s for %dx%d pixels\n", c
? "mmx2" : "mmx",
142 x
? 8 : 16, x
? 8 : 16);
143 test_motion("mmx", mmxctx
.pix_abs
[x
][0], cctx
.pix_abs
[x
][0]);
144 test_motion("mmx_x2", mmxctx
.pix_abs
[x
][1], cctx
.pix_abs
[x
][1]);
145 test_motion("mmx_y2", mmxctx
.pix_abs
[x
][2], cctx
.pix_abs
[x
][2]);
146 test_motion("mmx_xy2", mmxctx
.pix_abs
[x
][3], cctx
.pix_abs
[x
][3]);