Mercurial > libavcodec.hg
annotate motion_test.c @ 3777:20545fbb6f7c libavcodec
add some #ifdef CONFIG_ENCODERS/DECODERS
| author | mru |
|---|---|
| date | Wed, 27 Sep 2006 19:54:07 +0000 |
| parents | c537a97eec66 |
| children | c8c591fe26f8 |
| rev | line source |
|---|---|
|
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
1 /* |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
2 * (c) 2001 Fabrice Bellard |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
3 * |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
4 * This library is free software; you can redistribute it and/or |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
5 * modify it under the terms of the GNU Lesser General Public |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
6 * License as published by the Free Software Foundation; either |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
7 * version 2 of the License, or (at your option) any later version. |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
8 * |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
9 * This library is distributed in the hope that it will be useful, |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
12 * Lesser General Public License for more details. |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
13 * |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
14 * You should have received a copy of the GNU Lesser General Public |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
15 * License along with this library; if not, write to the Free Software |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
2967
diff
changeset
|
17 */ |
| 1106 | 18 |
| 19 /** | |
| 20 * @file motion_test.c | |
| 21 * motion test. | |
| 22 */ | |
| 23 | |
| 75 | 24 #include <stdlib.h> |
| 25 #include <stdio.h> | |
| 26 #include <string.h> | |
| 27 #include <sys/time.h> | |
| 28 #include <unistd.h> | |
| 29 | |
| 30 #include "dsputil.h" | |
| 31 | |
| 32 #include "i386/mmx.h" | |
| 33 | |
| 1064 | 34 int pix_abs16x16_mmx(uint8_t *blk1, uint8_t *blk2, int lx); |
| 35 int pix_abs16x16_mmx1(uint8_t *blk1, uint8_t *blk2, int lx); | |
| 36 int pix_abs16x16_x2_mmx(uint8_t *blk1, uint8_t *blk2, int lx); | |
| 37 int pix_abs16x16_x2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx); | |
| 38 int pix_abs16x16_x2_c(uint8_t *blk1, uint8_t *blk2, int lx); | |
| 39 int pix_abs16x16_y2_mmx(uint8_t *blk1, uint8_t *blk2, int lx); | |
| 40 int pix_abs16x16_y2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx); | |
| 41 int pix_abs16x16_y2_c(uint8_t *blk1, uint8_t *blk2, int lx); | |
| 42 int pix_abs16x16_xy2_mmx(uint8_t *blk1, uint8_t *blk2, int lx); | |
| 43 int pix_abs16x16_xy2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx); | |
| 44 int pix_abs16x16_xy2_c(uint8_t *blk1, uint8_t *blk2, int lx); | |
| 75 | 45 |
| 1064 | 46 typedef int motion_func(uint8_t *blk1, uint8_t *blk2, int lx); |
| 75 | 47 |
| 48 #define WIDTH 64 | |
| 49 #define HEIGHT 64 | |
| 50 | |
| 1064 | 51 uint8_t img1[WIDTH * HEIGHT]; |
| 52 uint8_t img2[WIDTH * HEIGHT]; | |
| 75 | 53 |
| 1064 | 54 void fill_random(uint8_t *tab, int size) |
| 75 | 55 { |
| 56 int i; | |
| 57 for(i=0;i<size;i++) { | |
| 58 #if 1 | |
| 59 tab[i] = random() % 256; | |
| 60 #else | |
| 61 tab[i] = i; | |
| 62 #endif | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 void help(void) | |
| 67 { | |
| 68 printf("motion-test [-h]\n" | |
| 69 "test motion implementations\n"); | |
| 70 exit(1); | |
| 71 } | |
| 72 | |
| 1064 | 73 int64_t gettime(void) |
| 75 | 74 { |
| 75 struct timeval tv; | |
| 76 gettimeofday(&tv,NULL); | |
| 1064 | 77 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; |
| 75 | 78 } |
| 79 | |
| 80 #define NB_ITS 500 | |
| 81 | |
| 82 int dummy; | |
| 83 | |
| 84 void test_motion(const char *name, | |
| 85 motion_func *test_func, motion_func *ref_func) | |
| 86 { | |
| 87 int x, y, d1, d2, it; | |
| 1064 | 88 uint8_t *ptr; |
| 89 int64_t ti; | |
| 75 | 90 printf("testing '%s'\n", name); |
| 91 | |
| 92 /* test correctness */ | |
| 93 for(it=0;it<20;it++) { | |
| 94 | |
| 95 fill_random(img1, WIDTH * HEIGHT); | |
| 96 fill_random(img2, WIDTH * HEIGHT); | |
| 2967 | 97 |
| 75 | 98 for(y=0;y<HEIGHT-17;y++) { |
| 99 for(x=0;x<WIDTH-17;x++) { | |
| 2967 | 100 ptr = img2 + y * WIDTH + x; |
| 644 | 101 d1 = test_func(img1, ptr, WIDTH); |
| 102 d2 = ref_func(img1, ptr, WIDTH); | |
| 75 | 103 if (d1 != d2) { |
| 104 printf("error: mmx=%d c=%d\n", d1, d2); | |
| 105 } | |
| 106 } | |
| 107 } | |
| 108 } | |
| 109 emms(); | |
| 2967 | 110 |
| 75 | 111 /* speed test */ |
| 112 ti = gettime(); | |
| 113 d1 = 0; | |
| 114 for(it=0;it<NB_ITS;it++) { | |
| 115 for(y=0;y<HEIGHT-17;y++) { | |
| 116 for(x=0;x<WIDTH-17;x++) { | |
| 2967 | 117 ptr = img2 + y * WIDTH + x; |
| 644 | 118 d1 += test_func(img1, ptr, WIDTH); |
| 75 | 119 } |
| 120 } | |
| 121 } | |
| 122 emms(); | |
| 123 dummy = d1; /* avoid optimisation */ | |
| 124 ti = gettime() - ti; | |
| 2967 | 125 |
| 126 printf(" %0.0f kop/s\n", | |
| 127 (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) / | |
| 75 | 128 (double)(ti / 1000.0)); |
| 129 } | |
| 130 | |
| 131 | |
| 132 int main(int argc, char **argv) | |
| 133 { | |
| 134 int c; | |
| 2967 | 135 |
| 75 | 136 for(;;) { |
| 137 c = getopt(argc, argv, "h"); | |
| 138 if (c == -1) | |
| 139 break; | |
| 140 switch(c) { | |
| 141 case 'h': | |
| 142 help(); | |
| 143 break; | |
| 144 } | |
| 145 } | |
| 2967 | 146 |
| 75 | 147 printf("ffmpeg motion test\n"); |
| 148 | |
| 149 test_motion("mmx", pix_abs16x16_mmx, pix_abs16x16_c); | |
| 150 test_motion("mmx_x2", pix_abs16x16_x2_mmx, pix_abs16x16_x2_c); | |
| 151 test_motion("mmx_y2", pix_abs16x16_y2_mmx, pix_abs16x16_y2_c); | |
| 152 test_motion("mmx_xy2", pix_abs16x16_xy2_mmx, pix_abs16x16_xy2_c); | |
| 153 return 0; | |
| 154 } |
