Fix warnings:
[ffmpeg.git] / libswscale / cs_test.c
1 /*
2     Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program 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
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdio.h>
20 #include <string.h>              /* for memset() */
21 #include <unistd.h>
22 #include <stdlib.h>
23 #include <inttypes.h>
24 #include <malloc.h>
25
26 #include "swscale.h"
27 #include "rgb2rgb.h"
28
29 #define SIZE 1000
30 #define srcByte 0x55
31 #define dstByte 0xBB
32
33 #ifdef __APPLE_CC__
34 #define memalign(x,y) malloc(y)
35 #endif
36
37 static int cpu_caps;
38
39 static char *args_parse(int argc, char *argv[])
40 {
41     int o;
42
43     while ((o = getopt(argc, argv, "m23")) != -1) {
44         switch (o) {
45             case 'm':
46                 cpu_caps |= SWS_CPU_CAPS_MMX;
47                 break;
48             case '2':
49                 cpu_caps |= SWS_CPU_CAPS_MMX2;
50                 break;
51             case '3':
52                 cpu_caps |= SWS_CPU_CAPS_3DNOW;
53                 break;
54             default:
55                 fprintf(stderr, "Unknown option %c\n", o);
56         }
57     }
58
59     return argv[optind];
60 }
61
62 int main(int argc, char **argv)
63 {
64         int i, funcNum;
65         uint8_t *srcBuffer= (uint8_t*)memalign(128, SIZE);
66         uint8_t *dstBuffer= (uint8_t*)memalign(128, SIZE);
67         int failedNum=0;
68         int passedNum=0;
69         
70         printf("memory corruption test ...\n");
71         args_parse(argc, argv);
72         fprintf(stderr, "CPU capabilities forced to %x\n", cpu_caps);
73         sws_rgb2rgb_init(cpu_caps);
74         
75         for(funcNum=0; funcNum<100; funcNum++){
76                 int width;
77                 int failed=0;
78                 int srcBpp=0;
79                 int dstBpp=0;
80
81                 printf("."); fflush(stdout);
82                 memset(srcBuffer, srcByte, SIZE);
83
84                 for(width=32; width<64; width++){
85                         int dstOffset;
86                         for(dstOffset=128; dstOffset<196; dstOffset++){
87                                 int srcOffset;
88                                 memset(dstBuffer, dstByte, SIZE);
89
90                                 for(srcOffset=128; srcOffset<196; srcOffset++){
91                                         uint8_t *src= srcBuffer+srcOffset;
92                                         uint8_t *dst= dstBuffer+dstOffset;
93                                         char *name=NULL;
94                                         
95                                         if(failed) break; //don't fill the screen with shit ...
96
97                                         switch(funcNum){
98                                         case 0:
99                                                 srcBpp=2;
100                                                 dstBpp=2;
101                                                 name="rgb15to16";
102                                                 rgb15to16(src, dst, width*srcBpp);
103                                                 break;
104                                         case 1:
105                                                 srcBpp=2;
106                                                 dstBpp=3;
107                                                 name="rgb15to24";
108                                                 rgb15to24(src, dst, width*srcBpp);
109                                                 break;
110                                         case 2:
111                                                 srcBpp=2;
112                                                 dstBpp=4;
113                                                 name="rgb15to32";
114                                                 rgb15to32(src, dst, width*srcBpp);
115                                                 break;
116                                         case 3:
117                                                 srcBpp=2;
118                                                 dstBpp=3;
119                                                 name="rgb16to24";
120                                                 rgb16to24(src, dst, width*srcBpp);
121                                                 break;
122                                         case 4:
123                                                 srcBpp=2;
124                                                 dstBpp=4;
125                                                 name="rgb16to32";
126                                                 rgb16to32(src, dst, width*srcBpp);
127                                                 break;
128                                         case 5:
129                                                 srcBpp=3;
130                                                 dstBpp=2;
131                                                 name="rgb24to15";
132                                                 rgb24to15(src, dst, width*srcBpp);
133                                                 break;
134                                         case 6:
135                                                 srcBpp=3;
136                                                 dstBpp=2;
137                                                 name="rgb24to16";
138                                                 rgb24to16(src, dst, width*srcBpp);
139                                                 break;
140                                         case 7:
141                                                 srcBpp=3;
142                                                 dstBpp=4;
143                                                 name="rgb24to32";
144                                                 rgb24to32(src, dst, width*srcBpp);
145                                                 break;
146                                         case 8:
147                                                 srcBpp=4;
148                                                 dstBpp=2;
149                                                 name="rgb32to15";
150                                                 rgb32to15(src, dst, width*srcBpp);
151                                                 break;
152                                         case 9:
153                                                 srcBpp=4;
154                                                 dstBpp=2;
155                                                 name="rgb32to16";
156                                                 rgb32to16(src, dst, width*srcBpp);
157                                                 break;
158                                         case 10:
159                                                 srcBpp=4;
160                                                 dstBpp=3;
161                                                 name="rgb32to24";
162                                                 rgb32to24(src, dst, width*srcBpp);
163                                                 break;
164                                         case 11:
165                                                 srcBpp=2;
166                                                 dstBpp=2;
167                                                 name="rgb16to15";
168                                                 rgb16to15(src, dst, width*srcBpp);
169                                                 break;
170                                         
171                                         case 14:
172                                                 srcBpp=2;
173                                                 dstBpp=2;
174                                                 name="rgb15tobgr15";
175                                                 rgb15tobgr15(src, dst, width*srcBpp);
176                                                 break;
177                                         case 15:
178                                                 srcBpp=2;
179                                                 dstBpp=2;
180                                                 name="rgb15tobgr16";
181                                                 rgb15tobgr16(src, dst, width*srcBpp);
182                                                 break;
183                                         case 16:
184                                                 srcBpp=2;
185                                                 dstBpp=3;
186                                                 name="rgb15tobgr24";
187                                                 rgb15tobgr24(src, dst, width*srcBpp);
188                                                 break;
189                                         case 17:
190                                                 srcBpp=2;
191                                                 dstBpp=4;
192                                                 name="rgb15tobgr32";
193                                                 rgb15tobgr32(src, dst, width*srcBpp);
194                                                 break;
195                                         case 18:
196                                                 srcBpp=2;
197                                                 dstBpp=2;
198                                                 name="rgb16tobgr15";
199                                                 rgb16tobgr15(src, dst, width*srcBpp);
200                                                 break;
201                                         case 19:
202                                                 srcBpp=2;
203                                                 dstBpp=2;
204                                                 name="rgb16tobgr16";
205                                                 rgb16tobgr16(src, dst, width*srcBpp);
206                                                 break;
207                                         case 20:
208                                                 srcBpp=2;
209                                                 dstBpp=3;
210                                                 name="rgb16tobgr24";
211                                                 rgb16tobgr24(src, dst, width*srcBpp);
212                                                 break;
213                                         case 21:
214                                                 srcBpp=2;
215                                                 dstBpp=4;
216                                                 name="rgb16tobgr32";
217                                                 rgb16tobgr32(src, dst, width*srcBpp);
218                                                 break;
219                                         case 22:
220                                                 srcBpp=3;
221                                                 dstBpp=2;
222                                                 name="rgb24tobgr15";
223                                                 rgb24tobgr15(src, dst, width*srcBpp);
224                                                 break;
225                                         case 23:
226                                                 srcBpp=3;
227                                                 dstBpp=2;
228                                                 name="rgb24tobgr16";
229                                                 rgb24tobgr16(src, dst, width*srcBpp);
230                                                 break;
231                                         case 24:
232                                                 srcBpp=3;
233                                                 dstBpp=3;
234                                                 name="rgb24tobgr24";
235                                                 rgb24tobgr24(src, dst, width*srcBpp);
236                                                 break;
237                                         case 25:
238                                                 srcBpp=3;
239                                                 dstBpp=4;
240                                                 name="rgb24tobgr32";
241                                                 rgb24tobgr32(src, dst, width*srcBpp);
242                                                 break;
243                                         case 26:
244                                                 srcBpp=4;
245                                                 dstBpp=2;
246                                                 name="rgb32tobgr15";
247                                                 rgb32tobgr15(src, dst, width*srcBpp);
248                                                 break;
249                                         case 27:
250                                                 srcBpp=4;
251                                                 dstBpp=2;
252                                                 name="rgb32tobgr16";
253                                                 rgb32tobgr16(src, dst, width*srcBpp);
254                                                 break;
255                                         case 28:
256                                                 srcBpp=4;
257                                                 dstBpp=3;
258                                                 name="rgb32tobgr24";
259                                                 rgb32tobgr24(src, dst, width*srcBpp);
260                                                 break;
261                                         case 29:
262                                                 srcBpp=4;
263                                                 dstBpp=4;
264                                                 name="rgb32tobgr32";
265                                                 rgb32tobgr32(src, dst, width*srcBpp);
266                                                 break;
267
268                                         }
269                                         if(!srcBpp) break;
270
271                                         for(i=0; i<SIZE; i++){
272                                                 if(srcBuffer[i]!=srcByte){
273                                                         printf("src damaged at %d w:%d src:%d dst:%d %s\n", 
274                                                                 i, width, srcOffset, dstOffset, name);
275                                                         failed=1;
276                                                         break;
277                                                 }
278                                         }
279                                         for(i=0; i<dstOffset; i++){
280                                                 if(dstBuffer[i]!=dstByte){
281                                                         printf("dst damaged at %d w:%d src:%d dst:%d %s\n", 
282                                                                 i, width, srcOffset, dstOffset, name);
283                                                         failed=1;
284                                                         break;
285                                                 }
286                                         }
287                                         for(i=dstOffset + width*dstBpp; i<SIZE; i++){
288                                                 if(dstBuffer[i]!=dstByte){
289                                                         printf("dst damaged at %d w:%d src:%d dst:%d %s\n", 
290                                                                 i, width, srcOffset, dstOffset, name);
291                                                         failed=1;
292                                                         break;
293                                                 }
294                                         }
295                                 }
296                         }
297                 }
298                 if(failed) failedNum++;
299                 else if(srcBpp) passedNum++;
300         }
301         
302         printf("%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
303         return failedNum;
304 }