1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
25 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 /* Note: these #includes differ slightly from the testrgb.c file included
33 in the GdkRgb release. */
44 quit_func (GtkWidget *widget, gpointer dummy)
54 testrgb_rgb_test (GtkWidget *drawing_area)
60 gdouble start_time, total_time;
68 buf = g_malloc (WIDTH * HEIGHT * 8);
71 for (j = 0; j < WIDTH * HEIGHT * 8; j++)
73 val = (val + ((val + (rand () & 0xff)) >> 1)) >> 1;
77 /* Let's warm up the cache, and also wait for the window manager
79 for (i = 0; i < NUM_ITERS; i++)
81 offset = (rand () % (WIDTH * HEIGHT * 3)) & -4;
82 gdk_draw_rgb_image (drawing_area->window,
83 drawing_area->style->white_gc,
86 buf + offset, WIDTH * 3);
89 if (gdk_rgb_ditherable ())
94 timer = g_timer_new ();
95 for (dither = 0; dither < dith_max; dither++)
97 start_time = g_timer_elapsed (timer, NULL);
98 for (i = 0; i < NUM_ITERS; i++)
100 offset = (rand () % (WIDTH * HEIGHT * 3)) & -4;
101 gdk_draw_rgb_image (drawing_area->window,
102 drawing_area->style->white_gc,
104 dither ? GDK_RGB_DITHER_MAX :
106 buf + offset, WIDTH * 3);
109 total_time = g_timer_elapsed (timer, NULL) - start_time;
110 g_print ("Color test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
111 dither ? " (dithered)" : "",
113 NUM_ITERS / total_time,
114 NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / total_time);
117 for (dither = 0; dither < dith_max; dither++)
119 start_time = g_timer_elapsed (timer, NULL);
120 for (i = 0; i < NUM_ITERS; i++)
122 offset = (rand () % (WIDTH * HEIGHT)) & -4;
123 gdk_draw_gray_image (drawing_area->window,
124 drawing_area->style->white_gc,
126 dither ? GDK_RGB_DITHER_MAX :
128 buf + offset, WIDTH);
131 total_time = g_timer_elapsed (timer, NULL) - start_time;
132 g_print ("Grayscale test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
133 dither ? " (dithered)" : "",
135 NUM_ITERS / total_time,
136 NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / total_time);
139 for (to_pixmap = FALSE; to_pixmap <= TRUE; to_pixmap++)
143 GdkRectangle rect = { 0, 0, WIDTH, HEIGHT };
144 gdk_window_begin_paint_rect (drawing_area->window, &rect);
147 start_time = g_timer_elapsed (timer, NULL);
148 for (i = 0; i < NUM_ITERS; i++)
150 offset = (rand () % (WIDTH * HEIGHT * 4)) & -4;
151 pixbuf = gdk_pixbuf_new_from_data (buf + offset, GDK_COLORSPACE_RGB, TRUE,
152 8, WIDTH, HEIGHT, WIDTH * 4,
154 gdk_pixbuf_render_to_drawable_alpha (pixbuf, drawing_area->window,
155 0, 0, 0, 0, WIDTH, HEIGHT,
156 GDK_PIXBUF_ALPHA_FULL, /* ignored */
158 GDK_RGB_DITHER_NORMAL,
160 gdk_pixbuf_unref (pixbuf);
163 total_time = g_timer_elapsed (timer, NULL) - start_time;
166 gdk_window_end_paint (drawing_area->window);
168 g_print ("Alpha test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
169 to_pixmap ? " (to pixmap)" : "",
171 NUM_ITERS / total_time,
172 NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / total_time);
175 g_print ("Please submit these results to http://www.levien.com/gdkrgb/survey.html\n");
178 for (x = 0; x < WIDTH; x++)
182 cindex = (x * 8) / WIDTH;
183 buf[x * 3] = cindex & 4 ? 0 : 255;
184 buf[x * 3 + 1] = cindex & 2 ? 0 : 255;
185 buf[x * 3 + 2] = cindex & 1 ? 0 : 255;
187 for (y = 1; y < (HEIGHT * 19) / 32; y++)
189 memcpy (buf + y * WIDTH * 3, buf, WIDTH * 3);
191 for (; y < (HEIGHT * 20) / 32; y++)
193 for (x = 0; x < WIDTH; x++)
197 gray = (x * 255) / (WIDTH - 1);
198 buf[y * WIDTH * 3 + x * 3] = gray;
199 buf[y * WIDTH * 3 + x * 3 + 1] = 0;
200 buf[y * WIDTH * 3 + x * 3 + 2] = 0;
203 for (; y < (HEIGHT * 21) / 32; y++)
205 for (x = 0; x < WIDTH; x++)
209 gray = (x * 255) / (WIDTH - 1);
210 buf[y * WIDTH * 3 + x * 3] = 0;
211 buf[y * WIDTH * 3 + x * 3 + 1] = gray;
212 buf[y * WIDTH * 3 + x * 3 + 2] = 0;
215 for (; y < (HEIGHT * 22) / 32; y++)
217 for (x = 0; x < WIDTH; x++)
221 gray = (x * 255) / (WIDTH - 1);
222 buf[y * WIDTH * 3 + x * 3] = 0;
223 buf[y * WIDTH * 3 + x * 3 + 1] = 0;
224 buf[y * WIDTH * 3 + x * 3 + 2] = gray;
227 for (; y < (HEIGHT * 24) / 32; y++)
229 for (x = 0; x < WIDTH; x++)
233 gray = 112 + (x * 31) / (WIDTH - 1);
234 buf[y * WIDTH * 3 + x * 3] = gray;
235 buf[y * WIDTH * 3 + x * 3 + 1] = gray;
236 buf[y * WIDTH * 3 + x * 3 + 2] = gray;
239 for (; y < (HEIGHT * 26) / 32; y++)
241 for (x = 0; x < WIDTH; x++)
245 gray = (x * 255) / (WIDTH - 1);
246 buf[y * WIDTH * 3 + x * 3] = gray;
247 buf[y * WIDTH * 3 + x * 3 + 1] = gray;
248 buf[y * WIDTH * 3 + x * 3 + 2] = gray;
252 for (; y < HEIGHT; y++)
254 for (x = 0; x < WIDTH; x++)
259 cindex = (x * 16) / WIDTH;
260 gray = cindex < 3 ? 0 :
264 buf[y * WIDTH * 3 + x * 3] = gray;
265 buf[y * WIDTH * 3 + x * 3 + 1] = gray;
266 buf[y * WIDTH * 3 + x * 3 + 2] = gray;
269 gdk_draw_rgb_image (drawing_area->window,
270 drawing_area->style->white_gc,
271 0, 0, WIDTH, HEIGHT, GDK_RGB_DITHER_MAX,
277 new_testrgb_window (void)
282 GtkWidget *drawing_area;
284 window = gtk_widget_new (gtk_window_get_type (),
285 "GtkObject::user_data", NULL,
286 "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
287 "GtkWindow::title", "testrgb",
288 "GtkWindow::allow_shrink", FALSE,
290 gtk_signal_connect (GTK_OBJECT (window), "destroy",
291 (GtkSignalFunc) quit_func, NULL);
293 vbox = gtk_vbox_new (FALSE, 0);
295 drawing_area = gtk_drawing_area_new ();
297 gtk_widget_set_usize (drawing_area, WIDTH, HEIGHT);
298 gtk_box_pack_start (GTK_BOX (vbox), drawing_area, FALSE, FALSE, 0);
299 gtk_widget_show (drawing_area);
301 button = gtk_button_new_with_label ("Quit");
302 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
303 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
304 (GtkSignalFunc) gtk_widget_destroy,
305 GTK_OBJECT (window));
307 gtk_widget_show (button);
309 gtk_container_add (GTK_CONTAINER (window), vbox);
310 gtk_widget_show (vbox);
312 gtk_widget_show (window);
314 testrgb_rgb_test (drawing_area);
318 main (int argc, char **argv)
320 gtk_init (&argc, &argv);
322 gdk_rgb_set_verbose (TRUE);
326 gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
327 new_testrgb_window ();