An outstanding formatting bug.
[AROS.git] / test / patchrgbconv.c
blob5273bd288b9c68fb40d68d9665ee5f9d1707e231
1 #define __OOP_NOATTRBASES__
3 #include <proto/dos.h>
4 #include <proto/graphics.h>
5 #include <proto/intuition.h>
6 #include <proto/oop.h>
7 #include <dos/rdargs.h>
8 #include <hidd/graphics.h>
9 #include <aros/macros.h>
10 #include <aros/debug.h>
12 #include <stdio.h>
13 #include <stdlib.h>
15 static BOOL noisy;
17 #include "patchrgbconv_macros.h"
18 #include "patchrgbconv_rgbswap.h"
19 #include "patchrgbconv_argb32.h"
20 #include "patchrgbconv_bgra32.h"
21 #include "patchrgbconv_rgba32.h"
22 #include "patchrgbconv_abgr32.h"
23 #include "patchrgbconv_rgb24.h"
24 #include "patchrgbconv_bgr24.h"
25 #include "patchrgbconv_rgb15.h"
26 #include "patchrgbconv_bgr15.h"
27 #include "patchrgbconv_rgb16.h"
28 #include "patchrgbconv_bgr16.h"
29 #include "patchrgbconv_rgb16oe.h"
30 #include "patchrgbconv_bgr16oe.h"
31 #include "patchrgbconv_rgb15oe.h"
32 #include "patchrgbconv_bgr15oe.h"
33 #include "patchrgbconv_xrgb32.h"
34 #include "patchrgbconv_bgrx32.h"
35 #include "patchrgbconv_rgbx32.h"
36 #include "patchrgbconv_xbgr32.h"
38 #include "patchrgbconv_verify.h"
40 #define VERIFY_SIZE 100
42 #define ARG_TEMPLATE "VERIFY=V/S,BENCH=B/N/K,NOISY=N/S"
43 #define ARG_VERIFY 0
44 #define ARG_BENCH 1
45 #define ARG_NOISY 2
46 #define ARG_NUM 3
48 #undef ConvertPixels
50 static OOP_AttrBase HiddBitMapAttrBase;
52 static IPTR args[ARG_NUM];
54 static ULONG dstbuf_orig[VERIFY_SIZE * 4 + 10];
55 static ULONG dstbuf_new[VERIFY_SIZE * 4 + 10];
56 static UBYTE *benchmem;
58 static void dumpmem(UBYTE *buf, ULONG num, ULONG size, STRPTR info)
60 int i, b;
62 bug(" %s", info);
64 for(i = 0; i < num; i++)
66 if ((i % (32 / size)) == 0)
68 bug("\n ");
71 for(b = 0; b < size; b++)
73 #if AROS_BIG_ENDAIN
74 bug("%02x", buf[b]);
75 #else
76 bug("%02x", buf[size - 1 -b]);
77 #endif
79 buf += size;
80 bug(" ");
82 bug("\n\n");
85 void ConvertPixels(APTR srcPixels, ULONG srcMod, HIDDT_StdPixFmt srcPixFmt,
86 APTR dstPixels, ULONG dstMod, HIDDT_StdPixFmt dstPixFmt,
87 ULONG width, ULONG height, OOP_Object *bm)
89 OOP_Object *gfxhidd = NULL;
90 OOP_Object *srcpf, *dstpf;
91 APTR src = srcPixels;
92 APTR dst = dstPixels;
94 OOP_GetAttr(bm, aHidd_BitMap_GfxHidd, &gfxhidd);
96 if (!gfxhidd) {
97 bug("ConvertPixels(): Failed to obtain graphics driver\n");
98 return;
101 srcpf = HIDD_Gfx_GetPixFmt(gfxhidd, srcPixFmt);
102 dstpf = HIDD_Gfx_GetPixFmt(gfxhidd, dstPixFmt);
104 if (!srcpf || !dstpf)
106 bug("ConvertPixels(): Bad source (%d) or dest (%d) pixfmt!\n", srcPixFmt, dstPixFmt);
107 return;
110 HIDD_BM_ConvertPixels(bm, &src, (HIDDT_PixelFormat *)srcpf, srcMod,
111 &dst, (HIDDT_PixelFormat *)dstpf, dstMod,
112 width, height, NULL);
115 typedef void (*DOFUNC)(ULONG srcfmt, ULONG dstfmt, ULONG srcbits, ULONG dstbits,
116 HIDDT_RGBConversionFunction f, BOOL verify, ULONG bench,
117 APTR testpixels, ULONG numtestpixels, char *srcfmt_string,
118 char *dstfmt_string, OOP_Object *bm);
120 static void uninstallfunc(ULONG srcfmt, ULONG dstfmt, ULONG srcbits, ULONG dstbits,
121 HIDDT_RGBConversionFunction f, BOOL verify, ULONG bench,
122 APTR testpixels, ULONG numtestpixels, char *srcfmt_string,
123 char *dstfmt_string, OOP_Object *bm)
125 (void)srcbits;
126 (void)dstbits;
127 (void)(f);
128 (void)verify;
129 (void)bench;
130 (void)testpixels;
131 (void)numtestpixels;
132 (void)srcfmt_string;
133 (void)dstfmt_string;
135 HIDD_BM_SetRGBConversionFunction(bm, srcfmt, dstfmt, NULL);
139 static void installfunc(ULONG srcfmt, ULONG dstfmt, ULONG srcbits, ULONG dstbits,
140 HIDDT_RGBConversionFunction f, BOOL verify, ULONG bench,
141 APTR testpixels, ULONG numtestpixels, char *srcfmt_string,
142 char *dstfmt_string, OOP_Object *bm)
144 ULONG srcbytes, dstbytes;
145 ULONG sec1, sec2, micro1, micro2, time1 = 0, time2;
147 srcbytes = (srcbits + 7) / 8;
148 dstbytes = (dstbits + 7) / 8;
150 if (verify)
152 ConvertPixels(testpixels, 0, srcfmt,
153 dstbuf_orig, numtestpixels * dstbytes, dstfmt,
154 numtestpixels,
155 VERIFY_SIZE / numtestpixels,
156 bm);
160 if (bench && benchmem)
162 CurrentTime(&sec1, &micro1);
163 ConvertPixels(benchmem, 0, srcfmt,
164 benchmem, 0, dstfmt,
165 bench, 1,
166 bm);
168 CurrentTime(&sec2, &micro2);
170 time1 = (sec2 - sec1) * 1000000 + (((LONG)micro2) - ((LONG)micro1));
173 HIDD_BM_SetRGBConversionFunction(bm, srcfmt, dstfmt, f);
175 if (verify)
177 ConvertPixels(testpixels, 0, srcfmt,
178 dstbuf_new, numtestpixels * dstbytes, dstfmt,
179 numtestpixels,
180 VERIFY_SIZE / numtestpixels,
181 bm);
183 if (memcmp(dstbuf_orig, dstbuf_new, (VERIFY_SIZE / numtestpixels) * (numtestpixels * dstbytes)) != 0)
185 int numtest = (VERIFY_SIZE / numtestpixels) * numtestpixels;
187 bug(" Verify %s to %s (%s to %s) failed!\n",
188 srcfmt_string, dstfmt_string,
189 pf_to_string[srcfmt], pf_to_string[dstfmt]);
191 dumpmem((UBYTE *)testpixels, numtestpixels, srcbytes, (STRPTR)"SRC:");
192 dumpmem((UBYTE *)dstbuf_orig, numtest, dstbytes, (STRPTR)"OLD:");
193 dumpmem((UBYTE *)dstbuf_new, numtest, dstbytes, (STRPTR)"NEW:");
199 if (bench && benchmem)
201 static char sbuf[256];
203 CurrentTime(&sec1, &micro1);
204 ConvertPixels(benchmem, 0, srcfmt,
205 benchmem, 0, dstfmt,
206 bench, 1,
207 bm);
209 CurrentTime(&sec2, &micro2);
211 time2 = (sec2 - sec1) * 1000000 + (((LONG)micro2) - ((LONG)micro1));
213 sprintf(sbuf, " Benchmark %s to %s (%s to %s): before %d (%f) after %d (%f) (%d %%)\n",
214 srcfmt_string, dstfmt_string,
215 pf_to_string[srcfmt], pf_to_string[dstfmt],
216 time1, time1 / 1000000.0,
217 time2, time2 / 1000000.0,
218 (time2 ? time1 * 100 / time2 : 0));
219 bug("%s", sbuf);
224 #define PATCHFUNC(a,b) \
225 (*func)(FMT_ ## a, FMT_ ## b, a ## _ ## BITS, b ## _ ## BITS, convert_ ## a ## _ ## b, \
226 verify, bench, testpixels_ ## a, NUMTESTPIXELS_ ## a, # a, # b, (OOP_Object *)bitmap->Planes[0]);
228 int main(int argc, char **argv)
230 struct RDArgs *myargs;
231 BOOL verify = FALSE;
232 ULONG bench = 0;
233 DOFUNC func = installfunc;
234 int i;
235 struct BitMap *bitmap;
237 HiddBitMapAttrBase = OOP_ObtainAttrBase(IID_Hidd_BitMap);
238 if (!HiddBitMapAttrBase) {
239 printf("Failed to obtain IID_Hidd_BitMap\n");
241 return RETURN_FAIL;
244 if ((myargs = ReadArgs((STRPTR)ARG_TEMPLATE, args, NULL)))
246 if (args[ARG_VERIFY]) verify = TRUE;
247 if (args[ARG_BENCH]) bench = *(IPTR *)args[ARG_BENCH];
248 if (args[ARG_NOISY]) noisy = TRUE;
250 FreeArgs(myargs);
252 else
254 PrintFault(IoErr(), (STRPTR)argv[0]);
255 OOP_ReleaseAttrBase(IID_Hidd_BitMap);
256 return RETURN_FAIL;
259 if (bench)
261 benchmem = malloc(bench * 4);
262 if (!benchmem)
264 PrintFault(ERROR_NO_FREE_STORE, (STRPTR)argv[0]);
265 OOP_ReleaseAttrBase(IID_Hidd_BitMap);
266 return RETURN_FAIL;
270 /* We need a placeholder bitmap object in order to talk to bitmap class */
271 bitmap = AllocBitMap(1, 1, 16, 0, NULL);
272 if (!bitmap) {
273 PrintFault(ERROR_NO_FREE_STORE, (STRPTR)argv[0]);
274 OOP_ReleaseAttrBase(IID_Hidd_BitMap);
275 return RETURN_FAIL;
278 #define P(a,b) PATCHFUNC(a,b)
280 for(i = 0; i < 2; i++)
282 /* ARGB32 to #? */
283 P(ARGB32,RGB16) P(ARGB32,BGR16) P(ARGB32,RGB15) P(ARGB32,BGR15)
284 P(ARGB32,BGRA32) P(ARGB32,RGBA32) P(ARGB32,ABGR32) P(ARGB32,RGB24)
285 P(ARGB32,BGR24) P(ARGB32,RGB16OE) P(ARGB32,BGR16OE) P(ARGB32,RGB15OE)
286 P(ARGB32,BGR15OE) P(ARGB32,XRGB32) P(ARGB32,BGRX32) P(ARGB32,RGBX32)
287 P(ARGB32,XBGR32)
289 /* BGRA32 to #? */
290 P(BGRA32,RGB16) P(BGRA32,BGR16) P(BGRA32,RGB15) P(BGRA32,BGR15)
291 P(BGRA32,ARGB32) P(BGRA32,RGBA32) P(BGRA32,ABGR32) P(BGRA32,RGB24)
292 P(BGRA32,BGR24) P(BGRA32,RGB16OE) P(BGRA32,BGR16OE) P(BGRA32,RGB15OE)
293 P(BGRA32,BGR15OE) P(BGRA32,XRGB32) P(BGRA32,BGRX32) P(BGRA32,RGBX32)
294 P(BGRA32,XBGR32)
296 /* RGBA32 to #? */
297 P(RGBA32,RGB16) P(RGBA32,BGR16) P(RGBA32,RGB15) P(RGBA32,BGR15)
298 P(RGBA32,BGRA32) P(RGBA32,ARGB32) P(RGBA32,ABGR32) P(RGBA32,RGB24)
299 P(RGBA32,BGR24) P(RGBA32,RGB16OE) P(RGBA32,BGR16OE) P(RGBA32,RGB15OE)
300 P(RGBA32,BGR15OE) P(RGBA32,XRGB32) P(RGBA32,BGRX32) P(RGBA32,RGBX32)
301 P(RGBA32,XBGR32)
303 /* ABGR32 to #? */
304 P(ABGR32,RGB16) P(ABGR32,BGR16) P(ABGR32,RGB15) P(ABGR32,BGR15)
305 P(ABGR32,BGRA32) P(ABGR32,ARGB32) P(ABGR32,RGBA32) P(ABGR32,RGB24)
306 P(ABGR32,BGR24) P(ABGR32,RGB16OE) P(ABGR32,BGR16OE) P(ABGR32,RGB15OE)
307 P(ABGR32,BGR15OE) P(ABGR32,XRGB32) P(ABGR32,BGRX32) P(ABGR32,RGBX32)
308 P(ABGR32,XBGR32)
310 /* RGB24 to #? */
311 P(RGB24,RGB16) P(RGB24,BGR16) P(RGB24,RGB15) P(RGB24,BGR15)
312 P(RGB24,ARGB32) P(RGB24,BGRA32) P(RGB24,RGBA32) P(RGB24,ABGR32)
313 P(RGB24,BGR24) P(RGB24,RGB16OE) P(RGB24,BGR16OE) P(RGB24,RGB15OE)
314 P(RGB24,BGR15OE) P(RGB24,XRGB32) P(RGB24,BGRX32) P(RGB24,RGBX32)
315 P(RGB24,XBGR32)
317 /* BGR24 to #? */
318 P(BGR24,RGB16) P(BGR24,BGR16) P(BGR24,RGB15) P(BGR24,BGR15)
319 P(BGR24,ARGB32) P(BGR24,BGRA32) P(BGR24,RGBA32) P(BGR24,ABGR32)
320 P(BGR24,RGB24) P(BGR24,RGB16OE) P(BGR24,BGR16OE) P(BGR24,RGB15OE)
321 P(BGR24,BGR15OE) P(BGR24,XRGB32) P(BGR24,BGRX32) P(BGR24,RGBX32)
322 P(BGR24,XBGR32)
324 /* RGB15 to #? */
325 P(RGB15,RGB16) P(RGB15,BGR16) P(RGB15,BGR15) P(RGB15,ARGB32)
326 P(RGB15,BGRA32) P(RGB15,RGBA32) P(RGB15,ABGR32) P(RGB15,RGB24)
327 P(RGB15,BGR24) P(RGB15,RGB16OE) P(RGB15,RGB15OE) P(RGB15,BGR16OE)
328 P(RGB15,BGR15OE) P(RGB15,XRGB32) P(RGB15,BGRX32) P(RGB15,RGBX32)
329 P(RGB15,XBGR32)
331 /* BGR15 to #? */
332 P(BGR15,RGB16) P(BGR15,BGR16) P(BGR15,RGB15) P(BGR15,ARGB32)
333 P(BGR15,BGRA32) P(BGR15,RGBA32) P(BGR15,ABGR32) P(BGR15,RGB24)
334 P(BGR15,BGR24) P(BGR15,RGB16OE) P(BGR15,RGB15OE) P(BGR15,BGR16OE)
335 P(BGR15,BGR15OE) P(BGR15,XRGB32) P(BGR15,BGRX32) P(BGR15,RGBX32)
336 P(BGR15,XBGR32)
338 /* RGB16 to #? */
339 P(RGB16,RGB15) P(RGB16,BGR16) P(RGB16,BGR15) P(RGB16,ARGB32)
340 P(RGB16,BGRA32) P(RGB16,RGBA32) P(RGB16,ABGR32) P(RGB16,RGB24)
341 P(RGB16,BGR24) P(RGB16,RGB16OE) P(RGB16,RGB15OE) P(RGB16,BGR16OE)
342 P(RGB16,BGR15OE) P(RGB16,XRGB32) P(RGB16,BGRX32) P(RGB16,RGBX32)
343 P(RGB16,XBGR32)
345 /* BGR16 to #? */
346 P(BGR16,RGB15) P(BGR16,RGB16) P(BGR16,BGR15) P(BGR16,ARGB32)
347 P(BGR16,BGRA32) P(BGR16,RGBA32) P(BGR16,ABGR32) P(BGR16,RGB24)
348 P(BGR16,BGR24) P(BGR16,RGB16OE) P(BGR16,RGB15OE) P(BGR16,BGR16OE)
349 P(BGR16,BGR15OE) P(BGR16,XRGB32) P(BGR16,BGRX32) P(BGR16,RGBX32)
350 P(BGR16,XBGR32)
352 /* RGB16OE to #? */
353 P(RGB16OE,RGB16) P(RGB16OE,RGB15) P(RGB16OE,BGR16) P(RGB16OE,BGR15)
354 P(RGB16OE,ARGB32) P(RGB16OE,BGRA32) P(RGB16OE,RGBA32) P(RGB16OE,ABGR32)
355 P(RGB16OE,RGB24) P(RGB16OE,BGR24) P(RGB16OE,RGB15OE) P(RGB16OE,BGR16OE)
356 P(RGB16OE,BGR15OE) P(RGB16OE,XRGB32) P(RGB16OE,BGRX32) P(RGB16OE,RGBX32)
357 P(RGB16OE,XBGR32)
359 /* BGR16OE to #? */
360 P(BGR16OE,RGB16) P(BGR16OE,RGB15) P(BGR16OE,BGR16) P(BGR16OE,BGR15)
361 P(BGR16OE,ARGB32) P(BGR16OE,BGRA32) P(BGR16OE,RGBA32) P(BGR16OE,ABGR32)
362 P(BGR16OE,RGB24) P(BGR16OE,BGR24) P(BGR16OE,RGB15OE) P(BGR16OE,RGB16OE)
363 P(BGR16OE,BGR15OE) P(BGR16OE,XRGB32) P(BGR16OE,BGRX32) P(BGR16OE,RGBX32)
364 P(BGR16OE,XBGR32)
366 /* RGB15OE to #? */
367 P(RGB15OE,RGB16) P(RGB15OE,RGB15) P(RGB15OE,BGR16) P(RGB15OE,BGR15)
368 P(RGB15OE,ARGB32) P(RGB15OE,BGRA32) P(RGB15OE,RGBA32) P(RGB15OE,ABGR32)
369 P(RGB15OE,RGB24) P(RGB15OE,BGR24) P(RGB15OE,RGB16OE) P(RGB15OE,BGR16OE)
370 P(RGB15OE,BGR15OE) P(RGB15OE,XRGB32) P(RGB15OE,BGRX32) P(RGB15OE,RGBX32)
371 P(RGB15OE,XBGR32)
373 /* BGR15OE to #? */
374 P(BGR15OE,RGB16) P(BGR15OE,RGB15) P(BGR15OE,BGR16) P(BGR15OE,BGR15)
375 P(BGR15OE,ARGB32) P(BGR15OE,BGRA32) P(BGR15OE,RGBA32) P(BGR15OE,ABGR32)
376 P(BGR15OE,RGB24) P(BGR15OE,BGR24) P(BGR15OE,RGB16OE) P(BGR15OE,BGR16OE)
377 P(BGR15OE,RGB15OE) P(BGR15OE,XRGB32) P(BGR15OE,BGRX32) P(BGR15OE,RGBX32)
378 P(BGR15OE,XBGR32)
380 /* XRGB32 to #? */
381 P(XRGB32,RGB16) P(XRGB32,BGR16) P(XRGB32,RGB15) P(XRGB32,BGR15)
382 P(XRGB32,ARGB32) P(XRGB32,BGRA32) P(XRGB32,RGBA32) P(XRGB32,ABGR32)
383 P(XRGB32,RGB24) P(XRGB32,BGR24) P(XRGB32,RGB16OE) P(XRGB32,BGR16OE)
384 P(XRGB32,RGB15OE) P(XRGB32,BGR15OE) P(XRGB32,BGRX32) P(XRGB32,RGBX32)
385 P(XRGB32,XBGR32)
387 /* BGRX32 to #? */
388 P(BGRX32,RGB16) P(BGRX32,BGR16) P(BGRX32,RGB15) P(BGRX32,BGR15)
389 P(BGRX32,ARGB32) P(BGRX32,BGRA32) P(BGRX32,RGBA32) P(BGRX32,ABGR32)
390 P(BGRX32,RGB24) P(BGRX32,BGR24) P(BGRX32,RGB16OE) P(BGRX32,BGR16OE)
391 P(BGRX32,RGB15OE) P(BGRX32,BGR15OE) P(BGRX32,XRGB32) P(BGRX32,RGBX32)
392 P(BGRX32,XBGR32)
394 /* RGBX32 to #? */
395 P(RGBX32,RGB16) P(RGBX32,BGR16) P(RGBX32,RGB15) P(RGBX32,BGR15)
396 P(RGBX32,BGRA32) P(RGBX32,ARGB32) P(RGBX32,ABGR32) P(RGBX32,RGBA32)
397 P(RGBX32,RGB24) P(RGBX32,BGR24) P(RGBX32,RGB16OE) P(RGBX32,BGR16OE)
398 P(RGBX32,RGB15OE) P(RGBX32,BGR15OE) P(RGBX32,XRGB32) P(RGBX32,BGRX32)
399 P(RGBX32,XBGR32)
401 /* XBGR32 to #? */
402 P(XBGR32,RGB16) P(XBGR32,BGR16) P(XBGR32,RGB15) P(XBGR32,BGR15)
403 P(XBGR32,BGRA32) P(XBGR32,ARGB32) P(XBGR32,RGBA32) P(XBGR32,ABGR32)
404 P(XBGR32,RGB24) P(XBGR32,BGR24) P(XBGR32,RGB16OE) P(XBGR32,BGR16OE)
405 P(XBGR32,RGB15OE) P(XBGR32,BGR15OE) P(XBGR32,XRGB32) P(XBGR32,BGRX32)
406 P(XBGR32,RGBX32)
408 if (i == 0)
410 Wait(SIGBREAKF_CTRL_C);
412 func = uninstallfunc;
415 } /* for(int i= 0; i < 2; i++) */
417 #undef P
419 FreeBitMap(bitmap);
420 OOP_ReleaseAttrBase(IID_Hidd_BitMap);
422 return RETURN_OK;