2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 cybergraphics.library/WritePixelArray
7 cybergraphics.library/WritePixelArrayAlpha
8 cybergraphics.library/ReadPixelArray
11 /*****************************************************************************
26 By default, WritePixelArray() is tested.
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>
47 /****************************************************************************************/
49 #define ARG_TEMPLATE "WIDTH=W/N/K,HEIGHT=H/N/K,PIXELFMT=P/K,FUNCTION=F/K"
53 #define ARG_FUNCTION 3
56 /****************************************************************************************/
57 #endif /* #if !defined(ONLY_BENCH_CODE) */
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
;
105 LONG pixfmt
= RECTFMT_ARGB
;
106 LONG pixfmt_index
= 2;
109 LONG function
= FUNCTION_WRITE
;
110 STRPTR functionname
= "WritePixelArray";
113 /****************************************************************************************/
115 static void cleanup(STRPTR msg
, ULONG retcode
)
119 fprintf(stderr
, "pixelarray: %s\n", msg
);
122 if (myargs
) FreeArgs(myargs
);
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
])
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
;
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
)
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",
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
;
220 win
= OpenWindowTags(NULL
, WA_Borderless
, TRUE
,
221 WA_InnerWidth
, width
,
222 WA_InnerHeight
, height
,
224 WA_IDCMP
, IDCMP_VANILLAKEY
,
229 cleanup("Can't open window!", RETURN_FAIL
);
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
);
245 CurrentTime(&tv_start
.tv_secs
, &tv_start
.tv_micro
);
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;
255 case(FUNCTION_WRITE_ALPHA
):
256 WritePixelArrayAlpha((ULONG
*)buffer
+ ( i
% 1000000), 0, 0, width
* 4, win
->RPort
, 0, 0, width
, height
, 0);
258 case(FUNCTION_WRITE
):
259 WritePixelArray((ULONG
*)buffer
+ ( i
% 1000000), 0, 0, width
* 4, win
->RPort
, 0, 0, width
, height
, pixfmt
);
262 ReadPixelArray(buffer
, 0, 0, width
* 4, win
->RPort
, 0, 0, width
, height
, pixfmt
);
269 FreeMem(buffer
, width
* height
* 4);
274 #if !defined(ONLY_BENCH_CODE)
275 /****************************************************************************************/