9 static GTimeVal start_time;
11 void start_timing (void)
13 g_get_current_time (&start_time);
17 stop_timing (const char *test, int iterations, int bytes)
22 g_get_current_time (&stop_time);
23 if (stop_time.tv_usec < start_time.tv_usec)
25 stop_time.tv_usec += 1000000;
26 stop_time.tv_sec -= 1;
29 msecs = (stop_time.tv_sec - start_time.tv_sec) * 1000. +
30 (stop_time.tv_usec - start_time.tv_usec) / 1000.;
32 printf("%s%d\t%.1f\t\t%.2f\t\t%.2f\n",
33 test, iterations, msecs, msecs / iterations, ((double)bytes * iterations) / (1000*msecs));
35 return ((double)bytes * iterations) / (1000*msecs);
39 init_array (double times[3][3][4])
50 dump_array (double times[3][3][4])
54 printf(" 3\t4\t4a\n");
75 printf("%6.2f %6.2f %6.2f",
76 times[i][0][j], times[i][1][j], times[i][2][j]);
80 case PIXOPS_INTERP_NEAREST:
81 printf (" NEAREST\n");
83 case PIXOPS_INTERP_TILES:
86 case PIXOPS_INTERP_BILINEAR:
87 printf (" BILINEAR\n");
89 case PIXOPS_INTERP_HYPER:
100 int main (int argc, char **argv)
102 int src_width, src_height, dest_width, dest_height;
103 char *src_buf, *dest_buf;
104 int src_index, dest_index;
106 double scale_times[3][3][4];
107 double composite_times[3][3][4];
108 double composite_color_times[3][3][4];
112 src_width = atoi(argv[1]);
113 src_height = atoi(argv[2]);
114 dest_width = atoi(argv[3]);
115 dest_height = atoi(argv[4]);
126 fprintf (stderr, "Usage: scale [src_width src_height dest_width dest_height]\n");
131 printf ("Scaling from (%d, %d) to (%d, %d)\n\n", src_width, src_height, dest_width, dest_height);
133 init_array (scale_times);
134 init_array (composite_times);
135 init_array (composite_color_times);
137 for (src_index = 0; src_index < 3; src_index++)
138 for (dest_index = 0; dest_index < 3; dest_index++)
140 int src_channels = (src_index == 0) ? 3 : 4;
141 int src_has_alpha = (src_index == 2);
142 int dest_channels = (dest_index == 0) ? 3 : 4;
143 int dest_has_alpha = (dest_index == 2);
145 int src_rowstride = (src_channels*src_width + 3) & ~3;
146 int dest_rowstride = (dest_channels *dest_width + 3) & ~3;
150 src_buf = g_malloc(src_rowstride * src_height);
151 memset (src_buf, 0x80, src_rowstride * src_height);
153 dest_buf = g_malloc(dest_rowstride * dest_height);
154 memset (dest_buf, 0x80, dest_rowstride * dest_height);
156 for (filter_level = PIXOPS_INTERP_NEAREST ; filter_level <= PIXOPS_INTERP_HYPER; filter_level++)
158 printf ("src_channels = %d (%s); dest_channels = %d (%s); filter_level=",
159 src_channels, src_has_alpha ? "alpha" : "no alpha",
160 dest_channels, dest_has_alpha ? "alpha" : "no alpha");
161 switch (filter_level)
163 case PIXOPS_INTERP_NEAREST:
164 printf ("PIXOPS_INTERP_NEAREST\n");
166 case PIXOPS_INTERP_TILES:
167 printf ("PIXOPS_INTERP_TILES\n");
169 case PIXOPS_INTERP_BILINEAR:
170 printf ("PIXOPS_INTERP_BILINEAR\n");
172 case PIXOPS_INTERP_HYPER:
173 printf ("PIXOPS_INTERP_HYPER\n");
177 printf("\t\t\titers\ttotal\t\tmsecs/iter\tMpixels/sec\t\n");
180 if (!(src_has_alpha && !dest_has_alpha))
183 for (i = 0; i < ITERS; i++)
185 pixops_scale (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
186 src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
187 (double)dest_width / src_width, (double)dest_height / src_height,
190 scale_times[src_index][dest_index][filter_level] =
191 stop_timing (" scale\t\t", ITERS, dest_height * dest_width);
195 for (i = 0; i < ITERS; i++)
197 pixops_composite (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
198 src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
199 (double)dest_width / src_width, (double)dest_height / src_height,
202 composite_times[src_index][dest_index][filter_level] =
203 stop_timing (" composite\t\t", ITERS, dest_height * dest_width);
206 for (i = 0; i < ITERS; i++)
208 pixops_composite_color (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
209 src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
210 (double)dest_width / src_width, (double)dest_height / src_height,
211 filter_level, 255, 0, 0, 16, 0xaaaaaa, 0x555555);
213 composite_color_times[src_index][dest_index][filter_level] =
214 stop_timing (" composite color\t", ITERS, dest_height * dest_width);
224 printf ("SCALE\n=====\n\n");
225 dump_array (scale_times);
227 printf ("COMPOSITE\n=========\n\n");
228 dump_array (composite_times);
230 printf ("COMPOSITE_COLOR\n===============\n\n");
231 dump_array (composite_color_times);