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_draw_pixbuf (drawing_area->window, drawing_area->style->black_gc,
156 0, 0, 0, 0, WIDTH, HEIGHT,
157 GDK_RGB_DITHER_NORMAL,
159 g_object_unref (pixbuf);
162 total_time = g_timer_elapsed (timer, NULL) - start_time;
165 gdk_window_end_paint (drawing_area->window);
167 g_print ("Alpha test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
168 to_pixmap ? " (to pixmap)" : "",
170 NUM_ITERS / total_time,
171 NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / total_time);
174 g_print ("Please submit these results to http://www.levien.com/gdkrgb/survey.html\n");
177 for (x = 0; x < WIDTH; x++)
181 cindex = (x * 8) / WIDTH;
182 buf[x * 3] = cindex & 4 ? 0 : 255;
183 buf[x * 3 + 1] = cindex & 2 ? 0 : 255;
184 buf[x * 3 + 2] = cindex & 1 ? 0 : 255;
186 for (y = 1; y < (HEIGHT * 19) / 32; y++)
188 memcpy (buf + y * WIDTH * 3, buf, WIDTH * 3);
190 for (; y < (HEIGHT * 20) / 32; y++)
192 for (x = 0; x < WIDTH; x++)
196 gray = (x * 255) / (WIDTH - 1);
197 buf[y * WIDTH * 3 + x * 3] = gray;
198 buf[y * WIDTH * 3 + x * 3 + 1] = 0;
199 buf[y * WIDTH * 3 + x * 3 + 2] = 0;
202 for (; y < (HEIGHT * 21) / 32; y++)
204 for (x = 0; x < WIDTH; x++)
208 gray = (x * 255) / (WIDTH - 1);
209 buf[y * WIDTH * 3 + x * 3] = 0;
210 buf[y * WIDTH * 3 + x * 3 + 1] = gray;
211 buf[y * WIDTH * 3 + x * 3 + 2] = 0;
214 for (; y < (HEIGHT * 22) / 32; y++)
216 for (x = 0; x < WIDTH; x++)
220 gray = (x * 255) / (WIDTH - 1);
221 buf[y * WIDTH * 3 + x * 3] = 0;
222 buf[y * WIDTH * 3 + x * 3 + 1] = 0;
223 buf[y * WIDTH * 3 + x * 3 + 2] = gray;
226 for (; y < (HEIGHT * 24) / 32; y++)
228 for (x = 0; x < WIDTH; x++)
232 gray = 112 + (x * 31) / (WIDTH - 1);
233 buf[y * WIDTH * 3 + x * 3] = gray;
234 buf[y * WIDTH * 3 + x * 3 + 1] = gray;
235 buf[y * WIDTH * 3 + x * 3 + 2] = gray;
238 for (; y < (HEIGHT * 26) / 32; y++)
240 for (x = 0; x < WIDTH; x++)
244 gray = (x * 255) / (WIDTH - 1);
245 buf[y * WIDTH * 3 + x * 3] = gray;
246 buf[y * WIDTH * 3 + x * 3 + 1] = gray;
247 buf[y * WIDTH * 3 + x * 3 + 2] = gray;
251 for (; y < HEIGHT; y++)
253 for (x = 0; x < WIDTH; x++)
258 cindex = (x * 16) / WIDTH;
259 gray = cindex < 3 ? 0 :
263 buf[y * WIDTH * 3 + x * 3] = gray;
264 buf[y * WIDTH * 3 + x * 3 + 1] = gray;
265 buf[y * WIDTH * 3 + x * 3 + 2] = gray;
268 gdk_draw_rgb_image (drawing_area->window,
269 drawing_area->style->white_gc,
270 0, 0, WIDTH, HEIGHT, GDK_RGB_DITHER_MAX,
276 new_testrgb_window (void)
281 GtkWidget *drawing_area;
283 window = g_object_new (gtk_window_get_type (),
284 "GtkObject::user_data", NULL,
285 "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
286 "GtkWindow::title", "testrgb",
287 "GtkWindow::allow_shrink", FALSE,
289 g_signal_connect (window, "destroy",
290 G_CALLBACK (quit_func), NULL);
292 vbox = gtk_vbox_new (FALSE, 0);
294 drawing_area = gtk_drawing_area_new ();
296 gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
297 gtk_box_pack_start (GTK_BOX (vbox), drawing_area, FALSE, FALSE, 0);
298 gtk_widget_show (drawing_area);
300 button = gtk_button_new_with_label ("Quit");
301 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
302 g_signal_connect_swapped (button, "clicked",
303 G_CALLBACK (gtk_widget_destroy), window);
305 gtk_widget_show (button);
307 gtk_container_add (GTK_CONTAINER (window), vbox);
308 gtk_widget_show (vbox);
310 gtk_widget_show (window);
312 testrgb_rgb_test (drawing_area);
316 main (int argc, char **argv)
318 gtk_init (&argc, &argv);
320 gdk_rgb_set_verbose (TRUE);
322 gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
323 new_testrgb_window ();