Fix issues with flexcat file paths
[AROS.git] / test / benchmarks / graphics / pixelarray.c
blobcb389aa75bba37a9bb9f7b9d920086fa13fa6d01
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Benchmark for:
6 cybergraphics.library/WritePixelArray
7 cybergraphics.library/WritePixelArrayAlpha
8 cybergraphics.library/ReadPixelArray
9 Lang: English
11 /*****************************************************************************
13 NAME
15 pixelarray
17 SYNOPSIS
19 LOCATION
21 FUNCTION
23 RESULT
25 NOTES
26 By default, WritePixelArray() is tested.
27 BUGS
29 INTERNALS
31 ******************************************************************************/
33 #if !defined(ONLY_BENCH_CODE)
34 #include <cybergraphx/cybergraphics.h>
35 #include <devices/timer.h>
37 #include <proto/exec.h>
38 #include <proto/dos.h>
39 #include <proto/graphics.h>
40 #include <proto/intuition.h>
41 #include <proto/cybergraphics.h>
43 #include <stdlib.h>
44 #include <stdio.h>
45 #include <string.h>
47 /****************************************************************************************/
49 #define ARG_TEMPLATE "WIDTH=W/N/K,HEIGHT=H/N/K,PIXELFMT=P/K,FUNCTION=F/K"
50 #define ARG_W 0
51 #define ARG_H 1
52 #define ARG_PIXFMT 2
53 #define ARG_FUNCTION 3
54 #define NUM_ARGS 4
56 /****************************************************************************************/
57 #endif /* #if !defined(ONLY_BENCH_CODE) */
59 #define P(x) {#x, x}
61 struct
63 STRPTR name;
64 LONG id;
66 pixfmt_table[] =
68 P(RECTFMT_RGB),
69 P(RECTFMT_RGBA),
70 P(RECTFMT_ARGB),
71 P(RECTFMT_LUT8),
72 P(RECTFMT_GREY8),
73 P(RECTFMT_RAW),
74 P(RECTFMT_RGB15),
75 P(RECTFMT_BGR15),
76 P(RECTFMT_RGB15PC),
77 P(RECTFMT_BGR15PC),
78 P(RECTFMT_RGB16),
79 P(RECTFMT_BGR16),
80 P(RECTFMT_RGB16PC),
81 P(RECTFMT_BGR16PC),
82 P(RECTFMT_RGB24),
83 P(RECTFMT_BGR24),
84 P(RECTFMT_ARGB32),
85 P(RECTFMT_BGRA32),
86 P(RECTFMT_RGBA32),
87 P(RECTFMT_ABGR32),
88 P(RECTFMT_0RGB32),
89 P(RECTFMT_BGR032),
90 P(RECTFMT_RGB032),
91 P(RECTFMT_0BGR32),
92 {0,0}
95 /****************************************************************************************/
97 #define FUNCTION_READ 0
98 #define FUNCTION_WRITE 1
99 #define FUNCTION_WRITE_ALPHA 2
101 #if !defined(ONLY_BENCH_CODE)
102 struct RDArgs *myargs;
103 IPTR args[NUM_ARGS];
104 UBYTE s[256];
105 LONG pixfmt = RECTFMT_ARGB;
106 LONG pixfmt_index = 2;
107 LONG width = 1280;
108 LONG height = 720;
109 LONG function = FUNCTION_WRITE;
110 STRPTR functionname = "WritePixelArray";
111 struct Window *win;
113 /****************************************************************************************/
115 static void cleanup(STRPTR msg, ULONG retcode)
117 if (msg)
119 fprintf(stderr, "pixelarray: %s\n", msg);
122 if (myargs) FreeArgs(myargs);
124 exit(retcode);
127 /****************************************************************************************/
129 static void getarguments(void)
131 if (!(myargs = ReadArgs(ARG_TEMPLATE, args, 0)))
133 Fault(IoErr(), 0, s, 255);
134 cleanup(s, RETURN_FAIL);
137 if (args[ARG_W]) width = *(LONG *)args[ARG_W];
139 if (args[ARG_H]) height = *(LONG *)args[ARG_H];
141 if (args[ARG_PIXFMT])
143 LONG i;
145 for(i = 0; pixfmt_table[i].name; i++)
147 if ((strcasecmp((STRPTR)args[ARG_PIXFMT], pixfmt_table[i].name) == 0) ||
148 (strcasecmp((STRPTR)args[ARG_PIXFMT], strchr(pixfmt_table[i].name, '_') + 1) == 0))
150 pixfmt = pixfmt_table[i].id;
151 pixfmt_index = i;
152 break;
156 if (pixfmt_table[i].name == NULL)
158 fprintf(stderr, "pixelarray: Bad pixel format! Valid ones are:\n\n");
160 for(i = 0; pixfmt_table[i].name; i++)
162 printf("%s\t== %s\n", pixfmt_table[i].name, strchr(pixfmt_table[i].name, '_') + 1);
165 cleanup(NULL, RETURN_WARN);
169 if (args[ARG_FUNCTION])
171 if (strcasecmp((STRPTR)args[ARG_FUNCTION], "READ") == 0)
173 function = FUNCTION_READ;
174 functionname = "ReadPixelArray";
177 if (strcasecmp((STRPTR)args[ARG_FUNCTION], "WRITE_ALPHA") == 0)
179 function = FUNCTION_WRITE_ALPHA;
180 functionname = "WritePixelArrayAlpha";
185 /****************************************************************************************/
186 static void printresults(LONG t, LONG i)
188 LONG bpp;
189 QUAD q;
191 printf("Function : %s\n", functionname);
192 printf("Pixel format : %s Width: %d Height %d\n\n",
193 pixfmt_table[pixfmt_index].name, (int)width, (int)height);
194 printf("Elapsed time : %d us (%f s)\n", (int)t, (double)t / 1000000);
195 printf("Blits : %d\n", (int)i);
196 printf("Blits/sec : %f\n", i * 1000000.0 / t);
197 printf("Time/blit : %f us (%f s) (%d%% of 25Hz Frame)\n",
198 (double)t / i,
199 (double)t / i / 1000000.0,
200 (int)(100.0 * ((double)t / i) / (1000000.0 / 25.0)));
202 bpp = GetCyberMapAttr(win->WScreen->RastPort.BitMap, CYBRMATTR_BPPIX);
203 printf("\nScreen Bytes Per Pixel: %d\n", (int)bpp);
204 printf("Area size in Pixels : %d\n", (int)(width * height));
205 printf("Area size in Bytes : %d\n", (int)(width * height * bpp));
207 q = ((QUAD)width) * ((QUAD)height) * ((QUAD)bpp) * ((QUAD)i) * ((QUAD)1000000) / (QUAD)t;
208 printf("Bytes/sec to gfx card : %lld (%lld MB)\n", (long long)q, (long long)q / 1048576);
211 /****************************************************************************************/
212 #endif /* !defined(ONLY_BENCH_CODE) */
214 static void action_pixelarray(void)
216 struct timeval tv_start, tv_end;
217 LONG t, i;
218 APTR buffer;
220 win = OpenWindowTags(NULL, WA_Borderless, TRUE,
221 WA_InnerWidth, width,
222 WA_InnerHeight, height,
223 WA_Activate, TRUE,
224 WA_IDCMP, IDCMP_VANILLAKEY,
225 TAG_DONE);
227 if (!win)
229 cleanup("Can't open window!", RETURN_FAIL);
232 width = win->Width;
233 height = win->Height;
235 /* Allocate and randomize the largest possible buffer */
236 buffer = AllocMem(width * height * 4, MEMF_ANY);
237 for (i = 0; i < width * height; i++)
238 *(((ULONG *)buffer) + i) = *(((ULONG*)GfxBase) + i);
240 SetAPen(win->RPort, 1);
241 RectFill(win->RPort, 0, 0, width, height);
243 Delay(2 * 50);
245 CurrentTime(&tv_start.tv_secs, &tv_start.tv_micro);
247 for(i = 0; ; i++)
249 CurrentTime(&tv_end.tv_secs, &tv_end.tv_micro);
250 t = (tv_end.tv_sec - tv_start.tv_sec) * 1000000 + tv_end.tv_micro - tv_start.tv_micro;
251 if (t >= 10 * 1000000) break;
253 switch(function)
255 case(FUNCTION_WRITE_ALPHA):
256 WritePixelArrayAlpha((ULONG *)buffer + ( i % 1000000), 0, 0, width * 4, win->RPort, 0, 0, width, height, 0);
257 break;
258 case(FUNCTION_WRITE):
259 WritePixelArray((ULONG *)buffer + ( i % 1000000), 0, 0, width * 4, win->RPort, 0, 0, width, height, pixfmt);
260 break;
261 case(FUNCTION_READ):
262 ReadPixelArray(buffer, 0, 0, width * 4, win->RPort, 0, 0, width, height, pixfmt);
263 break;
267 printresults(t, i);
269 FreeMem(buffer, width * height * 4);
271 CloseWindow(win);
274 #if !defined(ONLY_BENCH_CODE)
275 /****************************************************************************************/
277 int main(void)
279 getarguments();
280 action_pixelarray();
281 cleanup(NULL, 0);
283 return 0;
285 #endif