(Partial?) fix for building outside the source tree.
[cake.git] / test / patchrgbconv.c
blob6e96921b5deddb2d7b5457cca6402d93f107f73a
1 #include <proto/dos.h>
2 #include <proto/graphics.h>
3 #include <proto/intuition.h>
4 #include <dos/rdargs.h>
5 #include <hidd/graphics.h>
6 #include <aros/macros.h>
7 #include <aros/debug.h>
9 #include <stdio.h>
10 #include <stdlib.h>
12 static BOOL noisy;
14 #include "patchrgbconv_macros.h"
15 #include "patchrgbconv_rgbswap.h"
16 #include "patchrgbconv_argb32.h"
17 #include "patchrgbconv_bgra32.h"
18 #include "patchrgbconv_rgba32.h"
19 #include "patchrgbconv_abgr32.h"
20 #include "patchrgbconv_rgb24.h"
21 #include "patchrgbconv_bgr24.h"
22 #include "patchrgbconv_rgb15.h"
23 #include "patchrgbconv_bgr15.h"
24 #include "patchrgbconv_rgb16.h"
25 #include "patchrgbconv_bgr16.h"
26 #include "patchrgbconv_rgb16oe.h"
27 #include "patchrgbconv_bgr16oe.h"
28 #include "patchrgbconv_rgb15oe.h"
29 #include "patchrgbconv_bgr15oe.h"
30 #include "patchrgbconv_xrgb32.h"
31 #include "patchrgbconv_bgrx32.h"
32 #include "patchrgbconv_rgbx32.h"
33 #include "patchrgbconv_xbgr32.h"
35 #include "patchrgbconv_verify.h"
37 #define VERIFY_SIZE 100
39 #define ARG_TEMPLATE "VERIFY=V/S,BENCH=B/N/K,NOISY=N/S"
40 #define ARG_VERIFY 0
41 #define ARG_BENCH 1
42 #define ARG_NOISY 2
43 #define ARG_NUM 3
45 static IPTR args[ARG_NUM];
47 static ULONG dstbuf_orig[VERIFY_SIZE * 4 + 10];
48 static ULONG dstbuf_new[VERIFY_SIZE * 4 + 10];
49 static UBYTE *benchmem;
51 static void dumpmem(UBYTE *buf, ULONG num, ULONG size, STRPTR info)
53 int i, b;
55 bug(" %s", info);
57 for(i = 0; i < num; i++)
59 if ((i % (32 / size)) == 0)
61 bug("\n ");
64 for(b = 0; b < size; b++)
66 #if AROS_BIG_ENDAIN
67 bug("%02x", buf[b]);
68 #else
69 bug("%02x", buf[size - 1 -b]);
70 #endif
72 buf += size;
73 bug(" ");
75 bug("\n\n");
78 typedef void (*DOFUNC)(ULONG srcfmt, ULONG dstfmt, ULONG srcbits, ULONG dstbits,
79 HIDDT_RGBConversionFunction f, BOOL verify, ULONG bench,
80 APTR testpixels, ULONG numtestpixels, char *srcfmt_string,
81 char *dstfmt_string);
83 static void uninstallfunc(ULONG srcfmt, ULONG dstfmt, ULONG srcbits, ULONG dstbits,
84 HIDDT_RGBConversionFunction f, BOOL verify, ULONG bench,
85 APTR testpixels, ULONG numtestpixels, char *srcfmt_string,
86 char *dstfmt_string)
88 (void)srcbits;
89 (void)dstbits;
90 (void)(f);
91 (void)verify;
92 (void)bench;
93 (void)testpixels;
94 (void)numtestpixels;
95 (void)srcfmt_string;
96 (void)dstfmt_string;
98 SetRGBConversionFunctionA(srcfmt, dstfmt, 0, 0);
102 static void installfunc(ULONG srcfmt, ULONG dstfmt, ULONG srcbits, ULONG dstbits,
103 HIDDT_RGBConversionFunction f, BOOL verify, ULONG bench,
104 APTR testpixels, ULONG numtestpixels, char *srcfmt_string,
105 char *dstfmt_string)
107 ULONG srcbytes, dstbytes;
108 ULONG sec1, sec2, micro1, micro2, time1 = 0, time2;
110 srcbytes = (srcbits + 7) / 8;
111 dstbytes = (dstbits + 7) / 8;
113 if (verify)
115 ConvertPixelsA(testpixels, 0, srcfmt,
116 dstbuf_orig, numtestpixels * dstbytes, dstfmt,
117 numtestpixels,
118 VERIFY_SIZE / numtestpixels,
123 if (bench && benchmem)
125 CurrentTime(&sec1, &micro1);
126 ConvertPixelsA(benchmem, 0, srcfmt,
127 benchmem, 0, dstfmt,
128 bench, 1,
131 CurrentTime(&sec2, &micro2);
133 time1 = (sec2 - sec1) * 1000000 + (((LONG)micro2) - ((LONG)micro1));
136 SetRGBConversionFunctionA(srcfmt, dstfmt, f, 0);
138 if (verify)
140 ConvertPixelsA(testpixels, 0, srcfmt,
141 dstbuf_new, numtestpixels * dstbytes, dstfmt,
142 numtestpixels,
143 VERIFY_SIZE / numtestpixels,
146 if (memcmp(dstbuf_orig, dstbuf_new, (VERIFY_SIZE / numtestpixels) * (numtestpixels * dstbytes)) != 0)
148 int numtest = (VERIFY_SIZE / numtestpixels) * numtestpixels;
150 bug(" Verify %s to %s (%s to %s) failed!\n",
151 srcfmt_string, dstfmt_string,
152 pf_to_string[srcfmt], pf_to_string[dstfmt]);
154 dumpmem((UBYTE *)testpixels, numtestpixels, srcbytes, (STRPTR)"SRC:");
155 dumpmem((UBYTE *)dstbuf_orig, numtest, dstbytes, (STRPTR)"OLD:");
156 dumpmem((UBYTE *)dstbuf_new, numtest, dstbytes, (STRPTR)"NEW:");
162 if (bench && benchmem)
164 static char sbuf[256];
166 CurrentTime(&sec1, &micro1);
167 ConvertPixelsA(benchmem, 0, srcfmt,
168 benchmem, 0, dstfmt,
169 bench, 1,
172 CurrentTime(&sec2, &micro2);
174 time2 = (sec2 - sec1) * 1000000 + (((LONG)micro2) - ((LONG)micro1));
176 sprintf(sbuf, " Benchmark %s to %s (%s to %s): before %ld (%f) after %ld (%f) (%ld %%)\n",
177 srcfmt_string, dstfmt_string,
178 pf_to_string[srcfmt], pf_to_string[dstfmt],
179 time1, time1 / 1000000.0,
180 time2, time2 / 1000000.0,
181 (time2 ? time1 * 100 / time2 : 0));
182 bug("%s", sbuf);
187 #define PATCHFUNC(a,b) \
188 (*func)(FMT_ ## a, FMT_ ## b, a ## _ ## BITS, b ## _ ## BITS, convert_ ## a ## _ ## b, \
189 verify, bench, testpixels_ ## a, NUMTESTPIXELS_ ## a, # a, # b);
191 int main(int argc, char **argv)
193 struct RDArgs *myargs;
194 BOOL verify = FALSE;
195 ULONG bench = 0;
196 DOFUNC func = installfunc;
197 int i;
199 if ((myargs = ReadArgs((STRPTR)ARG_TEMPLATE, args, NULL)))
201 if (args[ARG_VERIFY]) verify = TRUE;
202 if (args[ARG_BENCH]) bench = *(IPTR *)args[ARG_BENCH];
203 if (args[ARG_NOISY]) noisy = TRUE;
205 FreeArgs(myargs);
207 else
209 PrintFault(IoErr(), (STRPTR)argv[0]);
211 return RETURN_FAIL;
214 if (bench)
216 benchmem = malloc(bench * 4);
217 if (!benchmem)
219 PrintFault(ERROR_NO_FREE_STORE, (STRPTR)argv[0]);
221 return RETURN_FAIL;
225 #define P(a,b) PATCHFUNC(a,b)
227 for(i = 0; i < 2; i++)
229 /* ARGB32 to #? */
230 P(ARGB32,RGB16) P(ARGB32,BGR16) P(ARGB32,RGB15) P(ARGB32,BGR15)
231 P(ARGB32,BGRA32) P(ARGB32,RGBA32) P(ARGB32,ABGR32) P(ARGB32,RGB24)
232 P(ARGB32,BGR24) P(ARGB32,RGB16OE) P(ARGB32,BGR16OE) P(ARGB32,RGB15OE)
233 P(ARGB32,BGR15OE) P(ARGB32,XRGB32) P(ARGB32,BGRX32) P(ARGB32,RGBX32)
234 P(ARGB32,XBGR32)
236 /* BGRA32 to #? */
237 P(BGRA32,RGB16) P(BGRA32,BGR16) P(BGRA32,RGB15) P(BGRA32,BGR15)
238 P(BGRA32,ARGB32) P(BGRA32,RGBA32) P(BGRA32,ABGR32) P(BGRA32,RGB24)
239 P(BGRA32,BGR24) P(BGRA32,RGB16OE) P(BGRA32,BGR16OE) P(BGRA32,RGB15OE)
240 P(BGRA32,BGR15OE) P(BGRA32,XRGB32) P(BGRA32,BGRX32) P(BGRA32,RGBX32)
241 P(BGRA32,XBGR32)
243 /* RGBA32 to #? */
244 P(RGBA32,RGB16) P(RGBA32,BGR16) P(RGBA32,RGB15) P(RGBA32,BGR15)
245 P(RGBA32,BGRA32) P(RGBA32,ARGB32) P(RGBA32,ABGR32) P(RGBA32,RGB24)
246 P(RGBA32,BGR24) P(RGBA32,RGB16OE) P(RGBA32,BGR16OE) P(RGBA32,RGB15OE)
247 P(RGBA32,BGR15OE) P(RGBA32,XRGB32) P(RGBA32,BGRX32) P(RGBA32,RGBX32)
248 P(RGBA32,XBGR32)
250 /* ABGR32 to #? */
251 P(ABGR32,RGB16) P(ABGR32,BGR16) P(ABGR32,RGB15) P(ABGR32,BGR15)
252 P(ABGR32,BGRA32) P(ABGR32,ARGB32) P(ABGR32,RGBA32) P(ABGR32,RGB24)
253 P(ABGR32,BGR24) P(ABGR32,RGB16OE) P(ABGR32,BGR16OE) P(ABGR32,RGB15OE)
254 P(ABGR32,BGR15OE) P(ABGR32,XRGB32) P(ABGR32,BGRX32) P(ABGR32,RGBX32)
255 P(ABGR32,XBGR32)
257 /* RGB24 to #? */
258 P(RGB24,RGB16) P(RGB24,BGR16) P(RGB24,RGB15) P(RGB24,BGR15)
259 P(RGB24,ARGB32) P(RGB24,BGRA32) P(RGB24,RGBA32) P(RGB24,ABGR32)
260 P(RGB24,BGR24) P(RGB24,RGB16OE) P(RGB24,BGR16OE) P(RGB24,RGB15OE)
261 P(RGB24,BGR15OE) P(RGB24,XRGB32) P(RGB24,BGRX32) P(RGB24,RGBX32)
262 P(RGB24,XBGR32)
264 /* BGR24 to #? */
265 P(BGR24,RGB16) P(BGR24,BGR16) P(BGR24,RGB15) P(BGR24,BGR15)
266 P(BGR24,ARGB32) P(BGR24,BGRA32) P(BGR24,RGBA32) P(BGR24,ABGR32)
267 P(BGR24,RGB24) P(BGR24,RGB16OE) P(BGR24,BGR16OE) P(BGR24,RGB15OE)
268 P(BGR24,BGR15OE) P(BGR24,XRGB32) P(BGR24,BGRX32) P(BGR24,RGBX32)
269 P(BGR24,XBGR32)
271 /* RGB15 to #? */
272 P(RGB15,RGB16) P(RGB15,BGR16) P(RGB15,BGR15) P(RGB15,ARGB32)
273 P(RGB15,BGRA32) P(RGB15,RGBA32) P(RGB15,ABGR32) P(RGB15,RGB24)
274 P(RGB15,BGR24) P(RGB15,RGB16OE) P(RGB15,RGB15OE) P(RGB15,BGR16OE)
275 P(RGB15,BGR15OE) P(RGB15,XRGB32) P(RGB15,BGRX32) P(RGB15,RGBX32)
276 P(RGB15,XBGR32)
278 /* BGR15 to #? */
279 P(BGR15,RGB16) P(BGR15,BGR16) P(BGR15,RGB15) P(BGR15,ARGB32)
280 P(BGR15,BGRA32) P(BGR15,RGBA32) P(BGR15,ABGR32) P(BGR15,RGB24)
281 P(BGR15,BGR24) P(BGR15,RGB16OE) P(BGR15,RGB15OE) P(BGR15,BGR16OE)
282 P(BGR15,BGR15OE) P(BGR15,XRGB32) P(BGR15,BGRX32) P(BGR15,RGBX32)
283 P(BGR15,XBGR32)
285 /* RGB16 to #? */
286 P(RGB16,RGB15) P(RGB16,BGR16) P(RGB16,BGR15) P(RGB16,ARGB32)
287 P(RGB16,BGRA32) P(RGB16,RGBA32) P(RGB16,ABGR32) P(RGB16,RGB24)
288 P(RGB16,BGR24) P(RGB16,RGB16OE) P(RGB16,RGB15OE) P(RGB16,BGR16OE)
289 P(RGB16,BGR15OE) P(RGB16,XRGB32) P(RGB16,BGRX32) P(RGB16,RGBX32)
290 P(RGB16,XBGR32)
292 /* BGR16 to #? */
293 P(BGR16,RGB15) P(BGR16,RGB16) P(BGR16,BGR15) P(BGR16,ARGB32)
294 P(BGR16,BGRA32) P(BGR16,RGBA32) P(BGR16,ABGR32) P(BGR16,RGB24)
295 P(BGR16,BGR24) P(BGR16,RGB16OE) P(BGR16,RGB15OE) P(BGR16,BGR16OE)
296 P(BGR16,BGR15OE) P(BGR16,XRGB32) P(BGR16,BGRX32) P(BGR16,RGBX32)
297 P(BGR16,XBGR32)
299 /* RGB16OE to #? */
300 P(RGB16OE,RGB16) P(RGB16OE,RGB15) P(RGB16OE,BGR16) P(RGB16OE,BGR15)
301 P(RGB16OE,ARGB32) P(RGB16OE,BGRA32) P(RGB16OE,RGBA32) P(RGB16OE,ABGR32)
302 P(RGB16OE,RGB24) P(RGB16OE,BGR24) P(RGB16OE,RGB15OE) P(RGB16OE,BGR16OE)
303 P(RGB16OE,BGR15OE) P(RGB16OE,XRGB32) P(RGB16OE,BGRX32) P(RGB16OE,RGBX32)
304 P(RGB16OE,XBGR32)
306 /* BGR16OE to #? */
307 P(BGR16OE,RGB16) P(BGR16OE,RGB15) P(BGR16OE,BGR16) P(BGR16OE,BGR15)
308 P(BGR16OE,ARGB32) P(BGR16OE,BGRA32) P(BGR16OE,RGBA32) P(BGR16OE,ABGR32)
309 P(BGR16OE,RGB24) P(BGR16OE,BGR24) P(BGR16OE,RGB15OE) P(BGR16OE,RGB16OE)
310 P(BGR16OE,BGR15OE) P(BGR16OE,XRGB32) P(BGR16OE,BGRX32) P(BGR16OE,RGBX32)
311 P(BGR16OE,XBGR32)
313 /* RGB15OE to #? */
314 P(RGB15OE,RGB16) P(RGB15OE,RGB15) P(RGB15OE,BGR16) P(RGB15OE,BGR15)
315 P(RGB15OE,ARGB32) P(RGB15OE,BGRA32) P(RGB15OE,RGBA32) P(RGB15OE,ABGR32)
316 P(RGB15OE,RGB24) P(RGB15OE,BGR24) P(RGB15OE,RGB16OE) P(RGB15OE,BGR16OE)
317 P(RGB15OE,BGR15OE) P(RGB15OE,XRGB32) P(RGB15OE,BGRX32) P(RGB15OE,RGBX32)
318 P(RGB15OE,XBGR32)
320 /* BGR15OE to #? */
321 P(BGR15OE,RGB16) P(BGR15OE,RGB15) P(BGR15OE,BGR16) P(BGR15OE,BGR15)
322 P(BGR15OE,ARGB32) P(BGR15OE,BGRA32) P(BGR15OE,RGBA32) P(BGR15OE,ABGR32)
323 P(BGR15OE,RGB24) P(BGR15OE,BGR24) P(BGR15OE,RGB16OE) P(BGR15OE,BGR16OE)
324 P(BGR15OE,RGB15OE) P(BGR15OE,XRGB32) P(BGR15OE,BGRX32) P(BGR15OE,RGBX32)
325 P(BGR15OE,XBGR32)
327 /* XRGB32 to #? */
328 P(XRGB32,RGB16) P(XRGB32,BGR16) P(XRGB32,RGB15) P(XRGB32,BGR15)
329 P(XRGB32,ARGB32) P(XRGB32,BGRA32) P(XRGB32,RGBA32) P(XRGB32,ABGR32)
330 P(XRGB32,RGB24) P(XRGB32,BGR24) P(XRGB32,RGB16OE) P(XRGB32,BGR16OE)
331 P(XRGB32,RGB15OE) P(XRGB32,BGR15OE) P(XRGB32,BGRX32) P(XRGB32,RGBX32)
332 P(XRGB32,XBGR32)
334 /* BGRX32 to #? */
335 P(BGRX32,RGB16) P(BGRX32,BGR16) P(BGRX32,RGB15) P(BGRX32,BGR15)
336 P(BGRX32,ARGB32) P(BGRX32,BGRA32) P(BGRX32,RGBA32) P(BGRX32,ABGR32)
337 P(BGRX32,RGB24) P(BGRX32,BGR24) P(BGRX32,RGB16OE) P(BGRX32,BGR16OE)
338 P(BGRX32,RGB15OE) P(BGRX32,BGR15OE) P(BGRX32,XRGB32) P(BGRX32,RGBX32)
339 P(BGRX32,XBGR32)
341 /* RGBX32 to #? */
342 P(RGBX32,RGB16) P(RGBX32,BGR16) P(RGBX32,RGB15) P(RGBX32,BGR15)
343 P(RGBX32,BGRA32) P(RGBX32,ARGB32) P(RGBX32,ABGR32) P(RGBX32,RGBA32)
344 P(RGBX32,RGB24) P(RGBX32,BGR24) P(RGBX32,RGB16OE) P(RGBX32,BGR16OE)
345 P(RGBX32,RGB15OE) P(RGBX32,BGR15OE) P(RGBX32,XRGB32) P(RGBX32,BGRX32)
346 P(RGBX32,XBGR32)
348 /* XBGR32 to #? */
349 P(XBGR32,RGB16) P(XBGR32,BGR16) P(XBGR32,RGB15) P(XBGR32,BGR15)
350 P(XBGR32,BGRA32) P(XBGR32,ARGB32) P(XBGR32,RGBA32) P(XBGR32,ABGR32)
351 P(XBGR32,RGB24) P(XBGR32,BGR24) P(XBGR32,RGB16OE) P(XBGR32,BGR16OE)
352 P(XBGR32,RGB15OE) P(XBGR32,BGR15OE) P(XBGR32,XRGB32) P(XBGR32,BGRX32)
353 P(XBGR32,RGBX32)
355 if (i == 0)
357 Wait(SIGBREAKF_CTRL_C);
359 func = uninstallfunc;
362 } /* for(int i= 0; i < 2; i++) */
364 #undef P
366 return RETURN_OK;