source: trunk/third/gtk/gtk/testrgb.c @ 15781

Revision 15781, 7.2 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r15780, which included commits to RCS files with non-trunk default branches.
Line 
1/* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 *
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.
8 *
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.
13 *
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.
18 */
19
20/*
21 * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
22 * file for a list of people on the GTK+ Team.  See the ChangeLog
23 * files for a list of changes.  These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
25 */
26
27
28/* Note: these #includes differ slightly from the testrgb.c file included
29   in the GdkRgb release. */
30
31/* For gettimeofday */
32#include <sys/time.h>
33#include <stdlib.h>
34#include <unistd.h>
35#include <string.h>
36
37#include "gtk.h"
38
39static void
40quit_func (GtkWidget *widget, gpointer dummy)
41{
42  gtk_main_quit ();
43}
44
45#define WIDTH 640
46#define HEIGHT 480
47
48gdouble
49get_time (void)
50{
51  struct timeval tv;
52  struct timezone tz;
53
54  gettimeofday (&tv, &tz);
55
56  return tv.tv_sec + 1e-6 * tv.tv_usec;
57}
58
59#define NUM_ITERS 100
60
61static void
62testrgb_rgb_test (GtkWidget *drawing_area)
63{
64  guchar buf[WIDTH * HEIGHT * 6];
65  gint i, j;
66  gint offset;
67  guchar val;
68  gdouble start_time, total_time;
69  gint x, y;
70  gboolean dither;
71  int dith_max;
72
73  val = 0;
74  for (j = 0; j < WIDTH * HEIGHT * 6; j++)
75    {
76      val = (val + ((val + (rand () & 0xff)) >> 1)) >> 1;
77      buf[j] = val;
78    }
79
80  /* Let's warm up the cache, and also wait for the window manager
81     to settle. */
82  for (i = 0; i < NUM_ITERS; i++)
83    {
84      offset = (rand () % (WIDTH * HEIGHT * 3)) & -4;
85      gdk_draw_rgb_image (drawing_area->window,
86                          drawing_area->style->white_gc,
87                          0, 0, WIDTH, HEIGHT,
88                          GDK_RGB_DITHER_NONE,
89                          buf + offset, WIDTH * 3);
90    }
91
92  if (gdk_rgb_ditherable ())
93    dith_max = 2;
94  else
95    dith_max = 1;
96
97  for (dither = 0; dither < dith_max; dither++)
98    {
99      start_time = get_time ();
100      for (i = 0; i < NUM_ITERS; i++)
101        {
102          offset = (rand () % (WIDTH * HEIGHT * 3)) & -4;
103          gdk_draw_rgb_image (drawing_area->window,
104                              drawing_area->style->white_gc,
105                              0, 0, WIDTH, HEIGHT,
106                              dither ? GDK_RGB_DITHER_MAX :
107                              GDK_RGB_DITHER_NONE,
108                              buf + offset, WIDTH * 3);
109        }
110      total_time = get_time () - start_time;
111      g_print ("Color test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
112               dither ? " (dithered)" : "",
113               total_time,
114               NUM_ITERS / total_time,
115               NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / total_time);
116    }
117
118  for (dither = 0; dither < dith_max; dither++)
119    {
120      start_time = get_time ();
121      for (i = 0; i < NUM_ITERS; i++)
122        {
123          offset = (rand () % (WIDTH * HEIGHT)) & -4;
124          gdk_draw_gray_image (drawing_area->window,
125                               drawing_area->style->white_gc,
126                               0, 0, WIDTH, HEIGHT,
127                               dither ? GDK_RGB_DITHER_MAX :
128                               GDK_RGB_DITHER_NONE,
129                               buf + offset, WIDTH);
130        }
131      total_time = get_time () - start_time;
132      g_print ("Grayscale test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
133               dither ? " (dithered)" : "",
134               total_time,
135               NUM_ITERS / total_time,
136               NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / total_time);
137    }
138
139  g_print ("Please submit these results to http://www.levien.com/gdkrgb/survey.html\n");
140
141#if 1
142  for (x = 0; x < WIDTH; x++)
143    {
144      int cindex;
145
146      cindex = (x * 8) / WIDTH;
147      buf[x * 3] = cindex & 4 ? 0 : 255;
148      buf[x * 3 + 1] = cindex & 2 ? 0 : 255;
149      buf[x * 3 + 2] = cindex & 1 ? 0 : 255;
150    }
151  for (y = 1; y < (HEIGHT * 19) / 32; y++)
152    {
153      memcpy (buf + y * WIDTH * 3, buf, WIDTH * 3);
154    }
155  for (; y < (HEIGHT * 20) / 32; y++)
156    {
157      for (x = 0; x < WIDTH; x++)
158        {
159          guchar gray;
160
161          gray = (x * 255) / (WIDTH - 1);
162          buf[y * WIDTH * 3 + x * 3] = gray;
163          buf[y * WIDTH * 3 + x * 3 + 1] = 0;
164          buf[y * WIDTH * 3 + x * 3 + 2] = 0;
165        }
166    }
167  for (; y < (HEIGHT * 21) / 32; y++)
168    {
169      for (x = 0; x < WIDTH; x++)
170        {
171          guchar gray;
172
173          gray = (x * 255) / (WIDTH - 1);
174          buf[y * WIDTH * 3 + x * 3] = 0;
175          buf[y * WIDTH * 3 + x * 3 + 1] = gray;
176          buf[y * WIDTH * 3 + x * 3 + 2] = 0;
177        }
178    }
179  for (; y < (HEIGHT * 22) / 32; y++)
180    {
181      for (x = 0; x < WIDTH; x++)
182        {
183          guchar gray;
184
185          gray = (x * 255) / (WIDTH - 1);
186          buf[y * WIDTH * 3 + x * 3] = 0;
187          buf[y * WIDTH * 3 + x * 3 + 1] = 0;
188          buf[y * WIDTH * 3 + x * 3 + 2] = gray;
189        }
190    }
191  for (; y < (HEIGHT * 24) / 32; y++)
192    {
193      for (x = 0; x < WIDTH; x++)
194        {
195          guchar gray;
196
197          gray = 112 + (x * 31) / (WIDTH - 1);
198          buf[y * WIDTH * 3 + x * 3] = gray;
199          buf[y * WIDTH * 3 + x * 3 + 1] = gray;
200          buf[y * WIDTH * 3 + x * 3 + 2] = gray;
201        }
202    }
203  for (; y < (HEIGHT * 26) / 32; y++)
204    {
205      for (x = 0; x < WIDTH; x++)
206        {
207          guchar gray;
208
209          gray = (x * 255) / (WIDTH - 1);
210          buf[y * WIDTH * 3 + x * 3] = gray;
211          buf[y * WIDTH * 3 + x * 3 + 1] = gray;
212          buf[y * WIDTH * 3 + x * 3 + 2] = gray;
213        }
214    }
215
216  for (; y < HEIGHT; y++)
217    {
218      for (x = 0; x < WIDTH; x++)
219        {
220          int cindex;
221          guchar gray;
222
223          cindex = (x * 16) / WIDTH;
224          gray = cindex < 3 ? 0 :
225            cindex < 5 ? 255 :
226            cindex < 7 ? 128 :
227            0;
228          buf[y * WIDTH * 3 + x * 3] = gray;
229          buf[y * WIDTH * 3 + x * 3 + 1] = gray;
230          buf[y * WIDTH * 3 + x * 3 + 2] = gray;
231        }
232    }
233  gdk_draw_rgb_image (drawing_area->window,
234                      drawing_area->style->white_gc,
235                      0, 0, WIDTH, HEIGHT, GDK_RGB_DITHER_MAX,
236                      buf, WIDTH * 3);
237#endif
238}
239
240void
241new_testrgb_window (void)
242{
243  GtkWidget *window;
244  GtkWidget *vbox;
245  GtkWidget *button;
246  GtkWidget *drawing_area;
247
248  window = gtk_widget_new (gtk_window_get_type (),
249                           "GtkObject::user_data", NULL,
250                           "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
251                           "GtkWindow::title", "testrgb",
252                           "GtkWindow::allow_shrink", FALSE,
253                           NULL);
254  gtk_signal_connect (GTK_OBJECT (window), "destroy",
255                      (GtkSignalFunc) quit_func, NULL);
256
257  vbox = gtk_vbox_new (FALSE, 0);
258
259  drawing_area = gtk_drawing_area_new ();
260
261  gtk_widget_set_usize (drawing_area, WIDTH, HEIGHT);
262  gtk_box_pack_start (GTK_BOX (vbox), drawing_area, FALSE, FALSE, 0);
263  gtk_widget_show (drawing_area);
264
265  button = gtk_button_new_with_label ("Quit");
266  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
267  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
268                             (GtkSignalFunc) gtk_widget_destroy,
269                             GTK_OBJECT (window));
270
271  gtk_widget_show (button);
272
273  gtk_container_add (GTK_CONTAINER (window), vbox);
274  gtk_widget_show (vbox);
275
276  gtk_widget_show (window);
277
278  testrgb_rgb_test (drawing_area);
279}
280
281int
282main (int argc, char **argv)
283{
284  gtk_init (&argc, &argv);
285
286  gdk_rgb_set_verbose (TRUE);
287
288  gdk_rgb_init ();
289
290  gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
291  gtk_widget_set_default_visual (gdk_rgb_get_visual ());
292  new_testrgb_window ();
293
294  gtk_main ();
295
296  return 0;
297}
Note: See TracBrowser for help on using the repository browser.