2
* Copyright (C) 2000 Red Hat, Inc
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library 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 GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
27
static GTimeVal start_time;
32
g_get_current_time (&start_time);
36
stop_timing (const char *test, int iterations, int bytes)
41
g_get_current_time (&stop_time);
42
if (stop_time.tv_usec < start_time.tv_usec)
44
stop_time.tv_usec += 1000000;
45
stop_time.tv_sec -= 1;
48
msecs = (stop_time.tv_sec - start_time.tv_sec) * 1000. +
49
(stop_time.tv_usec - start_time.tv_usec) / 1000.;
51
printf("%s%d\t%.1f\t\t%.2f\t\t%.2f\n",
52
test, iterations, msecs, msecs / iterations, ((double)bytes * iterations) / (1000*msecs));
54
return ((double)bytes * iterations) / (1000*msecs);
58
init_array (double times[3][3][4])
69
dump_array (double times[3][3][4])
73
printf(" 3\t4\t4a\n");
94
printf("%6.2f %6.2f %6.2f",
95
times[i][0][j], times[i][1][j], times[i][2][j]);
99
case PIXOPS_INTERP_NEAREST:
100
printf (" NEAREST\n");
102
case PIXOPS_INTERP_TILES:
105
case PIXOPS_INTERP_BILINEAR:
106
printf (" BILINEAR\n");
108
case PIXOPS_INTERP_HYPER:
119
int main (int argc, char **argv)
121
int src_width, src_height, dest_width, dest_height;
122
unsigned char *src_buf, *dest_buf;
123
int src_index, dest_index;
125
double scale_times[3][3][4];
126
double composite_times[3][3][4];
127
double composite_color_times[3][3][4];
131
src_width = atoi(argv[1]);
132
src_height = atoi(argv[2]);
133
dest_width = atoi(argv[3]);
134
dest_height = atoi(argv[4]);
145
fprintf (stderr, "Usage: scale [src_width src_height dest_width dest_height]\n");
150
printf ("Scaling from (%d, %d) to (%d, %d)\n\n", src_width, src_height, dest_width, dest_height);
152
init_array (scale_times);
153
init_array (composite_times);
154
init_array (composite_color_times);
156
for (src_index = 0; src_index < 3; src_index++)
157
for (dest_index = 0; dest_index < 3; dest_index++)
159
int src_channels = (src_index == 0) ? 3 : 4;
160
int src_has_alpha = (src_index == 2);
161
int dest_channels = (dest_index == 0) ? 3 : 4;
162
int dest_has_alpha = (dest_index == 2);
164
int src_rowstride = (src_channels*src_width + 3) & ~3;
165
int dest_rowstride = (dest_channels *dest_width + 3) & ~3;
169
src_buf = g_malloc(src_rowstride * src_height);
170
memset (src_buf, 0x80, src_rowstride * src_height);
172
dest_buf = g_malloc(dest_rowstride * dest_height);
173
memset (dest_buf, 0x80, dest_rowstride * dest_height);
175
for (filter_level = PIXOPS_INTERP_NEAREST ; filter_level <= PIXOPS_INTERP_HYPER; filter_level++)
177
printf ("src_channels = %d (%s); dest_channels = %d (%s); filter_level=",
178
src_channels, src_has_alpha ? "alpha" : "no alpha",
179
dest_channels, dest_has_alpha ? "alpha" : "no alpha");
180
switch (filter_level)
182
case PIXOPS_INTERP_NEAREST:
183
printf ("PIXOPS_INTERP_NEAREST\n");
185
case PIXOPS_INTERP_TILES:
186
printf ("PIXOPS_INTERP_TILES\n");
188
case PIXOPS_INTERP_BILINEAR:
189
printf ("PIXOPS_INTERP_BILINEAR\n");
191
case PIXOPS_INTERP_HYPER:
192
printf ("PIXOPS_INTERP_HYPER\n");
196
printf("\t\t\titers\ttotal\t\tmsecs/iter\tMpixels/sec\t\n");
199
if (!(src_has_alpha && !dest_has_alpha))
202
for (i = 0; i < ITERS; i++)
204
_pixops_scale (dest_buf, dest_width, dest_height,
205
dest_rowstride, dest_channels,
206
dest_has_alpha, src_buf, src_width,
207
src_height, src_rowstride, src_channels,
208
src_has_alpha, 0, 0, 0, 0, 0, 0,
209
(double)dest_width / src_width,
210
(double)dest_height / src_height,
213
scale_times[src_index][dest_index][filter_level] =
214
stop_timing (" scale\t\t", ITERS, dest_height * dest_width);
218
for (i = 0; i < ITERS; i++)
220
_pixops_composite (dest_buf, dest_width, dest_height,
221
dest_rowstride, dest_channels,
222
dest_has_alpha, src_buf, src_width,
223
src_height, src_rowstride, src_channels,
224
src_has_alpha, 0, 0, 0, 0, 0, 0,
225
(double)dest_width / src_width,
226
(double)dest_height / src_height,
229
composite_times[src_index][dest_index][filter_level] =
230
stop_timing (" composite\t\t", ITERS,
231
dest_height * dest_width);
234
for (i = 0; i < ITERS; i++)
236
_pixops_composite_color (dest_buf, dest_width, dest_height,
237
dest_rowstride, dest_channels,
238
dest_has_alpha, src_buf, src_width,
239
src_height, src_rowstride,
240
src_channels, src_has_alpha, 0, 0,
242
(double)dest_width / src_width,
243
(double)dest_height / src_height,
244
filter_level, 255, 0, 0, 16,
247
composite_color_times[src_index][dest_index][filter_level] =
248
stop_timing (" composite color\t", ITERS, dest_height * dest_width);
258
printf ("SCALE\n=====\n\n");
259
dump_array (scale_times);
261
printf ("COMPOSITE\n=========\n\n");
262
dump_array (composite_times);
264
printf ("COMPOSITE_COLOR\n===============\n\n");
265
dump_array (composite_color_times);