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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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-1999. 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;
66 buf = g_malloc (WIDTH * HEIGHT * 6);
69 for (j = 0; j < WIDTH * HEIGHT * 6; j++)
71 val = (val + ((val + (rand () & 0xff)) >> 1)) >> 1;
75 /* Let's warm up the cache, and also wait for the window manager
77 for (i = 0; i < NUM_ITERS; i++)
79 offset = (rand () % (WIDTH * HEIGHT * 3)) & -4;
80 gdk_draw_rgb_image (drawing_area->window,
81 drawing_area->style->white_gc,
84 buf + offset, WIDTH * 3);
87 if (gdk_rgb_ditherable ())
92 timer = g_timer_new ();
93 for (dither = 0; dither < dith_max; dither++)
95 start_time = g_timer_elapsed (timer, NULL);
96 for (i = 0; i < NUM_ITERS; i++)
98 offset = (rand () % (WIDTH * HEIGHT * 3)) & -4;
99 gdk_draw_rgb_image (drawing_area->window,
100 drawing_area->style->white_gc,
102 dither ? GDK_RGB_DITHER_MAX :
104 buf + offset, WIDTH * 3);
106 total_time = g_timer_elapsed (timer, NULL) - start_time;
107 g_print ("Color test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
108 dither ? " (dithered)" : "",
110 NUM_ITERS / total_time,
111 NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / total_time);
114 for (dither = 0; dither < dith_max; dither++)
116 start_time = g_timer_elapsed (timer, NULL);
117 for (i = 0; i < NUM_ITERS; i++)
119 offset = (rand () % (WIDTH * HEIGHT)) & -4;
120 gdk_draw_gray_image (drawing_area->window,
121 drawing_area->style->white_gc,
123 dither ? GDK_RGB_DITHER_MAX :
125 buf + offset, WIDTH);
127 total_time = g_timer_elapsed (timer, NULL) - start_time;
128 g_print ("Grayscale test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
129 dither ? " (dithered)" : "",
131 NUM_ITERS / total_time,
132 NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / total_time);
135 g_print ("Please submit these results to http://www.levien.com/gdkrgb/survey.html\n");
138 for (x = 0; x < WIDTH; x++)
142 cindex = (x * 8) / WIDTH;
143 buf[x * 3] = cindex & 4 ? 0 : 255;
144 buf[x * 3 + 1] = cindex & 2 ? 0 : 255;
145 buf[x * 3 + 2] = cindex & 1 ? 0 : 255;
147 for (y = 1; y < (HEIGHT * 19) / 32; y++)
149 memcpy (buf + y * WIDTH * 3, buf, WIDTH * 3);
151 for (; y < (HEIGHT * 20) / 32; y++)
153 for (x = 0; x < WIDTH; x++)
157 gray = (x * 255) / (WIDTH - 1);
158 buf[y * WIDTH * 3 + x * 3] = gray;
159 buf[y * WIDTH * 3 + x * 3 + 1] = 0;
160 buf[y * WIDTH * 3 + x * 3 + 2] = 0;
163 for (; y < (HEIGHT * 21) / 32; y++)
165 for (x = 0; x < WIDTH; x++)
169 gray = (x * 255) / (WIDTH - 1);
170 buf[y * WIDTH * 3 + x * 3] = 0;
171 buf[y * WIDTH * 3 + x * 3 + 1] = gray;
172 buf[y * WIDTH * 3 + x * 3 + 2] = 0;
175 for (; y < (HEIGHT * 22) / 32; y++)
177 for (x = 0; x < WIDTH; x++)
181 gray = (x * 255) / (WIDTH - 1);
182 buf[y * WIDTH * 3 + x * 3] = 0;
183 buf[y * WIDTH * 3 + x * 3 + 1] = 0;
184 buf[y * WIDTH * 3 + x * 3 + 2] = gray;
187 for (; y < (HEIGHT * 24) / 32; y++)
189 for (x = 0; x < WIDTH; x++)
193 gray = 112 + (x * 31) / (WIDTH - 1);
194 buf[y * WIDTH * 3 + x * 3] = gray;
195 buf[y * WIDTH * 3 + x * 3 + 1] = gray;
196 buf[y * WIDTH * 3 + x * 3 + 2] = gray;
199 for (; y < (HEIGHT * 26) / 32; y++)
201 for (x = 0; x < WIDTH; x++)
205 gray = (x * 255) / (WIDTH - 1);
206 buf[y * WIDTH * 3 + x * 3] = gray;
207 buf[y * WIDTH * 3 + x * 3 + 1] = gray;
208 buf[y * WIDTH * 3 + x * 3 + 2] = gray;
212 for (; y < HEIGHT; y++)
214 for (x = 0; x < WIDTH; x++)
219 cindex = (x * 16) / WIDTH;
220 gray = cindex < 3 ? 0 :
224 buf[y * WIDTH * 3 + x * 3] = gray;
225 buf[y * WIDTH * 3 + x * 3 + 1] = gray;
226 buf[y * WIDTH * 3 + x * 3 + 2] = gray;
229 gdk_draw_rgb_image (drawing_area->window,
230 drawing_area->style->white_gc,
231 0, 0, WIDTH, HEIGHT, GDK_RGB_DITHER_MAX,
237 new_testrgb_window (void)
242 GtkWidget *drawing_area;
244 window = gtk_widget_new (gtk_window_get_type (),
245 "GtkObject::user_data", NULL,
246 "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
247 "GtkWindow::title", "testrgb",
248 "GtkWindow::allow_shrink", FALSE,
250 gtk_signal_connect (GTK_OBJECT (window), "destroy",
251 (GtkSignalFunc) quit_func, NULL);
253 vbox = gtk_vbox_new (FALSE, 0);
255 drawing_area = gtk_drawing_area_new ();
257 gtk_widget_set_usize (drawing_area, WIDTH, HEIGHT);
258 gtk_box_pack_start (GTK_BOX (vbox), drawing_area, FALSE, FALSE, 0);
259 gtk_widget_show (drawing_area);
261 button = gtk_button_new_with_label ("Quit");
262 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
263 gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
264 (GtkSignalFunc) gtk_widget_destroy,
265 GTK_OBJECT (window));
267 gtk_widget_show (button);
269 gtk_container_add (GTK_CONTAINER (window), vbox);
270 gtk_widget_show (vbox);
272 gtk_widget_show (window);
274 testrgb_rgb_test (drawing_area);
278 main (int argc, char **argv)
280 gtk_init (&argc, &argv);
282 gdk_rgb_set_verbose (TRUE);
286 gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
287 gtk_widget_set_default_visual (gdk_rgb_get_visual ());
288 new_testrgb_window ();