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;
29 void start_timing (void)
31 g_get_current_time (&start_time);
35 stop_timing (const char *test, int iterations, int bytes)
40 g_get_current_time (&stop_time);
41 if (stop_time.tv_usec < start_time.tv_usec)
43 stop_time.tv_usec += 1000000;
44 stop_time.tv_sec -= 1;
47 msecs = (stop_time.tv_sec - start_time.tv_sec) * 1000. +
48 (stop_time.tv_usec - start_time.tv_usec) / 1000.;
50 printf("%s%d\t%.1f\t\t%.2f\t\t%.2f\n",
51 test, iterations, msecs, msecs / iterations, ((double)bytes * iterations) / (1000*msecs));
53 return ((double)bytes * iterations) / (1000*msecs);
57 init_array (double times[3][3][4])
68 dump_array (double times[3][3][4])
72 printf(" 3\t4\t4a\n");
93 printf("%6.2f %6.2f %6.2f",
94 times[i][0][j], times[i][1][j], times[i][2][j]);
98 case PIXOPS_INTERP_NEAREST:
99 printf (" NEAREST\n");
101 case PIXOPS_INTERP_TILES:
104 case PIXOPS_INTERP_BILINEAR:
105 printf (" BILINEAR\n");
107 case PIXOPS_INTERP_HYPER:
118 int main (int argc, char **argv)
120 int src_width, src_height, dest_width, dest_height;
121 unsigned char *src_buf, *dest_buf;
122 int src_index, dest_index;
124 double scale_times[3][3][4];
125 double composite_times[3][3][4];
126 double composite_color_times[3][3][4];
130 src_width = atoi(argv[1]);
131 src_height = atoi(argv[2]);
132 dest_width = atoi(argv[3]);
133 dest_height = atoi(argv[4]);
144 fprintf (stderr, "Usage: scale [src_width src_height dest_width dest_height]\n");
149 printf ("Scaling from (%d, %d) to (%d, %d)\n\n", src_width, src_height, dest_width, dest_height);
151 init_array (scale_times);
152 init_array (composite_times);
153 init_array (composite_color_times);
155 for (src_index = 0; src_index < 3; src_index++)
156 for (dest_index = 0; dest_index < 3; dest_index++)
158 int src_channels = (src_index == 0) ? 3 : 4;
159 int src_has_alpha = (src_index == 2);
160 int dest_channels = (dest_index == 0) ? 3 : 4;
161 int dest_has_alpha = (dest_index == 2);
163 int src_rowstride = (src_channels*src_width + 3) & ~3;
164 int dest_rowstride = (dest_channels *dest_width + 3) & ~3;
168 src_buf = g_malloc(src_rowstride * src_height);
169 memset (src_buf, 0x80, src_rowstride * src_height);
171 dest_buf = g_malloc(dest_rowstride * dest_height);
172 memset (dest_buf, 0x80, dest_rowstride * dest_height);
174 for (filter_level = PIXOPS_INTERP_NEAREST ; filter_level <= PIXOPS_INTERP_HYPER; filter_level++)
176 printf ("src_channels = %d (%s); dest_channels = %d (%s); filter_level=",
177 src_channels, src_has_alpha ? "alpha" : "no alpha",
178 dest_channels, dest_has_alpha ? "alpha" : "no alpha");
179 switch (filter_level)
181 case PIXOPS_INTERP_NEAREST:
182 printf ("PIXOPS_INTERP_NEAREST\n");
184 case PIXOPS_INTERP_TILES:
185 printf ("PIXOPS_INTERP_TILES\n");
187 case PIXOPS_INTERP_BILINEAR:
188 printf ("PIXOPS_INTERP_BILINEAR\n");
190 case PIXOPS_INTERP_HYPER:
191 printf ("PIXOPS_INTERP_HYPER\n");
195 printf("\t\t\titers\ttotal\t\tmsecs/iter\tMpixels/sec\t\n");
198 if (!(src_has_alpha && !dest_has_alpha))
201 for (i = 0; i < ITERS; i++)
203 _pixops_scale (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
204 src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
205 (double)dest_width / src_width, (double)dest_height / src_height,
208 scale_times[src_index][dest_index][filter_level] =
209 stop_timing (" scale\t\t", ITERS, dest_height * dest_width);
213 for (i = 0; i < ITERS; i++)
215 _pixops_composite (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
216 src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
217 (double)dest_width / src_width, (double)dest_height / src_height,
220 composite_times[src_index][dest_index][filter_level] =
221 stop_timing (" composite\t\t", ITERS, dest_height * dest_width);
224 for (i = 0; i < ITERS; i++)
226 _pixops_composite_color (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
227 src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
228 (double)dest_width / src_width, (double)dest_height / src_height,
229 filter_level, 255, 0, 0, 16, 0xaaaaaa, 0x555555);
231 composite_color_times[src_index][dest_index][filter_level] =
232 stop_timing (" composite color\t", ITERS, dest_height * dest_width);
242 printf ("SCALE\n=====\n\n");
243 dump_array (scale_times);
245 printf ("COMPOSITE\n=========\n\n");
246 dump_array (composite_times);
248 printf ("COMPOSITE_COLOR\n===============\n\n");
249 dump_array (composite_color_times);