mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 06:00:22 +00:00
c65508d272
should break on Unix/X11. Win32 merge and general portability stuff: * acconfig.h,configure.in: Check for <sys/time.h>. * gdk/win32: New directory (actually, been there for a while). * gtk/fnmatch.c: Include <glib.h> for G_DIR_SEPARATOR, WIN32 and NATIVE_WIN32, and use these. Always case fold on Win32. No backslashed escapes on native Win32. * gtk/{gtk.def,makefile.msc}: New files. * gtk/Makefile.am: Add above new files. * gtk/{gtkaccelgroup,gtkbindings}.c: Include <string.h> instead of <strings.h>. * gtk/{gtkcalendar,gtkitemfactory,gtkpreview,gtkrc}.c: Include config.h. Protect inclusion of <sys/param.h>, <sys/time.h>, and <unistd.h> appropriately. * gtk/gtkdnd.c: Merge in Win32 version (which doesn't do much). Use ABS() (from <glib.h>) instead of abs(). * gtk/gtkfilesel.c: Moved Win32-specific includes after inclusion of gtk (and thus glib) headers, so that WIN32 will be defined. With MS C, include <direct.h> for mkdir prototype. * gtk/gtkitemfactory.c (gtk_item_factory_callback_marshal): Add some casts, needed by MS C. * gtk/{gtklayout,gtkplug}.c: Merge in Win32 version (which isn't implemented). * gtk/gtkmain.c: Include gdk/gdkx.h for GDK_WINDOWING. Include <X11/Xlocale.h> only on X11 platform, otherwise <locale.h>. Use G_SEARCHPATH_SEPARATOR_S and g_module_build_path. * gtk/gtkmain.h: Mark variables for export/import on Win32. * gtk/gtkrange.c (gtk_range_motion_notify): Set mods also in case the event is not a hint, or its window is not the slider. Needed on Win32, at least. * gtk/gtkrc.c: Include config.h and gdk/gdkx.h. Use <locale.h> unless on X11. Skip \r chars, too. Use G_DIR_SEPARATOR and G_SEARCHPATH_SEPARATOR(_S). Use g_path_is_absolute. On Win32, use a subdirectory of the Windows directory as gtk system configuration directory. * gtk/gtkselection.c: No chunks on Win32. * gtk/gtksocket.c: Not implemented on Win32. * gtk/gtkthemes.c (gtk_theme_engine_get): Use g_module_build_path. * gtk/makeenums.h: Include gdkprivate.h after gdk.h. * gtk/testrgb.c: Use dynamically allocated buffer. Use GTimers.
294 lines
7.2 KiB
C
294 lines
7.2 KiB
C
/* GTK - The GIMP Toolkit
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Library General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this library; if not, write to the
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
* Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <glib.h>
|
|
|
|
/*
|
|
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
* files for a list of changes. These files are distributed with
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
*/
|
|
|
|
|
|
/* Note: these #includes differ slightly from the testrgb.c file included
|
|
in the GdkRgb release. */
|
|
|
|
#include <stdlib.h>
|
|
#ifdef HAVE_UNISTD_H
|
|
#include <unistd.h>
|
|
#endif
|
|
#include <string.h>
|
|
|
|
#include "gtk.h"
|
|
|
|
static void
|
|
quit_func (GtkWidget *widget, gpointer dummy)
|
|
{
|
|
gtk_main_quit ();
|
|
}
|
|
|
|
#define WIDTH 320
|
|
#define HEIGHT 200
|
|
#define NUM_ITERS 100
|
|
|
|
static void
|
|
testrgb_rgb_test (GtkWidget *drawing_area)
|
|
{
|
|
guchar *buf;
|
|
gint i, j;
|
|
gint offset;
|
|
guchar val;
|
|
gdouble start_time, total_time;
|
|
gint x, y;
|
|
gboolean dither;
|
|
int dith_max;
|
|
GTimer *timer;
|
|
|
|
buf = g_malloc (WIDTH * HEIGHT * 6);
|
|
|
|
val = 0;
|
|
for (j = 0; j < WIDTH * HEIGHT * 6; j++)
|
|
{
|
|
val = (val + ((val + (rand () & 0xff)) >> 1)) >> 1;
|
|
buf[j] = val;
|
|
}
|
|
|
|
/* Let's warm up the cache, and also wait for the window manager
|
|
to settle. */
|
|
for (i = 0; i < NUM_ITERS; i++)
|
|
{
|
|
offset = (rand () % (WIDTH * HEIGHT * 3)) & -4;
|
|
gdk_draw_rgb_image (drawing_area->window,
|
|
drawing_area->style->white_gc,
|
|
0, 0, WIDTH, HEIGHT,
|
|
GDK_RGB_DITHER_NONE,
|
|
buf + offset, WIDTH * 3);
|
|
}
|
|
|
|
if (gdk_rgb_ditherable ())
|
|
dith_max = 2;
|
|
else
|
|
dith_max = 1;
|
|
|
|
timer = g_timer_new ();
|
|
for (dither = 0; dither < dith_max; dither++)
|
|
{
|
|
start_time = g_timer_elapsed (timer, NULL);
|
|
for (i = 0; i < NUM_ITERS; i++)
|
|
{
|
|
offset = (rand () % (WIDTH * HEIGHT * 3)) & -4;
|
|
gdk_draw_rgb_image (drawing_area->window,
|
|
drawing_area->style->white_gc,
|
|
0, 0, WIDTH, HEIGHT,
|
|
dither ? GDK_RGB_DITHER_MAX :
|
|
GDK_RGB_DITHER_NONE,
|
|
buf + offset, WIDTH * 3);
|
|
}
|
|
total_time = g_timer_elapsed (timer, NULL) - start_time;
|
|
g_print ("Color test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
|
|
dither ? " (dithered)" : "",
|
|
total_time,
|
|
NUM_ITERS / total_time,
|
|
NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / total_time);
|
|
}
|
|
|
|
for (dither = 0; dither < dith_max; dither++)
|
|
{
|
|
start_time = g_timer_elapsed (timer, NULL);
|
|
for (i = 0; i < NUM_ITERS; i++)
|
|
{
|
|
offset = (rand () % (WIDTH * HEIGHT)) & -4;
|
|
gdk_draw_gray_image (drawing_area->window,
|
|
drawing_area->style->white_gc,
|
|
0, 0, WIDTH, HEIGHT,
|
|
dither ? GDK_RGB_DITHER_MAX :
|
|
GDK_RGB_DITHER_NONE,
|
|
buf + offset, WIDTH);
|
|
}
|
|
total_time = g_timer_elapsed (timer, NULL) - start_time;
|
|
g_print ("Grayscale test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
|
|
dither ? " (dithered)" : "",
|
|
total_time,
|
|
NUM_ITERS / total_time,
|
|
NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / total_time);
|
|
}
|
|
|
|
g_print ("Please submit these results to http://www.levien.com/gdkrgb/survey.html\n");
|
|
|
|
#if 1
|
|
for (x = 0; x < WIDTH; x++)
|
|
{
|
|
int cindex;
|
|
|
|
cindex = (x * 8) / WIDTH;
|
|
buf[x * 3] = cindex & 4 ? 0 : 255;
|
|
buf[x * 3 + 1] = cindex & 2 ? 0 : 255;
|
|
buf[x * 3 + 2] = cindex & 1 ? 0 : 255;
|
|
}
|
|
for (y = 1; y < (HEIGHT * 19) / 32; y++)
|
|
{
|
|
memcpy (buf + y * WIDTH * 3, buf, WIDTH * 3);
|
|
}
|
|
for (; y < (HEIGHT * 20) / 32; y++)
|
|
{
|
|
for (x = 0; x < WIDTH; x++)
|
|
{
|
|
guchar gray;
|
|
|
|
gray = (x * 255) / (WIDTH - 1);
|
|
buf[y * WIDTH * 3 + x * 3] = gray;
|
|
buf[y * WIDTH * 3 + x * 3 + 1] = 0;
|
|
buf[y * WIDTH * 3 + x * 3 + 2] = 0;
|
|
}
|
|
}
|
|
for (; y < (HEIGHT * 21) / 32; y++)
|
|
{
|
|
for (x = 0; x < WIDTH; x++)
|
|
{
|
|
guchar gray;
|
|
|
|
gray = (x * 255) / (WIDTH - 1);
|
|
buf[y * WIDTH * 3 + x * 3] = 0;
|
|
buf[y * WIDTH * 3 + x * 3 + 1] = gray;
|
|
buf[y * WIDTH * 3 + x * 3 + 2] = 0;
|
|
}
|
|
}
|
|
for (; y < (HEIGHT * 22) / 32; y++)
|
|
{
|
|
for (x = 0; x < WIDTH; x++)
|
|
{
|
|
guchar gray;
|
|
|
|
gray = (x * 255) / (WIDTH - 1);
|
|
buf[y * WIDTH * 3 + x * 3] = 0;
|
|
buf[y * WIDTH * 3 + x * 3 + 1] = 0;
|
|
buf[y * WIDTH * 3 + x * 3 + 2] = gray;
|
|
}
|
|
}
|
|
for (; y < (HEIGHT * 24) / 32; y++)
|
|
{
|
|
for (x = 0; x < WIDTH; x++)
|
|
{
|
|
guchar gray;
|
|
|
|
gray = 112 + (x * 31) / (WIDTH - 1);
|
|
buf[y * WIDTH * 3 + x * 3] = gray;
|
|
buf[y * WIDTH * 3 + x * 3 + 1] = gray;
|
|
buf[y * WIDTH * 3 + x * 3 + 2] = gray;
|
|
}
|
|
}
|
|
for (; y < (HEIGHT * 26) / 32; y++)
|
|
{
|
|
for (x = 0; x < WIDTH; x++)
|
|
{
|
|
guchar gray;
|
|
|
|
gray = (x * 255) / (WIDTH - 1);
|
|
buf[y * WIDTH * 3 + x * 3] = gray;
|
|
buf[y * WIDTH * 3 + x * 3 + 1] = gray;
|
|
buf[y * WIDTH * 3 + x * 3 + 2] = gray;
|
|
}
|
|
}
|
|
|
|
for (; y < HEIGHT; y++)
|
|
{
|
|
for (x = 0; x < WIDTH; x++)
|
|
{
|
|
int cindex;
|
|
guchar gray;
|
|
|
|
cindex = (x * 16) / WIDTH;
|
|
gray = cindex < 3 ? 0 :
|
|
cindex < 5 ? 255 :
|
|
cindex < 7 ? 128 :
|
|
0;
|
|
buf[y * WIDTH * 3 + x * 3] = gray;
|
|
buf[y * WIDTH * 3 + x * 3 + 1] = gray;
|
|
buf[y * WIDTH * 3 + x * 3 + 2] = gray;
|
|
}
|
|
}
|
|
gdk_draw_rgb_image (drawing_area->window,
|
|
drawing_area->style->white_gc,
|
|
0, 0, WIDTH, HEIGHT, GDK_RGB_DITHER_MAX,
|
|
buf, WIDTH * 3);
|
|
#endif
|
|
}
|
|
|
|
void
|
|
new_testrgb_window (void)
|
|
{
|
|
GtkWidget *window;
|
|
GtkWidget *vbox;
|
|
GtkWidget *button;
|
|
GtkWidget *drawing_area;
|
|
|
|
window = gtk_widget_new (gtk_window_get_type (),
|
|
"GtkObject::user_data", NULL,
|
|
"GtkWindow::type", GTK_WINDOW_TOPLEVEL,
|
|
"GtkWindow::title", "testrgb",
|
|
"GtkWindow::allow_shrink", FALSE,
|
|
NULL);
|
|
gtk_signal_connect (GTK_OBJECT (window), "destroy",
|
|
(GtkSignalFunc) quit_func, NULL);
|
|
|
|
vbox = gtk_vbox_new (FALSE, 0);
|
|
|
|
drawing_area = gtk_drawing_area_new ();
|
|
|
|
gtk_widget_set_usize (drawing_area, WIDTH, HEIGHT);
|
|
gtk_box_pack_start (GTK_BOX (vbox), drawing_area, FALSE, FALSE, 0);
|
|
gtk_widget_show (drawing_area);
|
|
|
|
button = gtk_button_new_with_label ("Quit");
|
|
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
|
|
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
|
|
(GtkSignalFunc) gtk_widget_destroy,
|
|
GTK_OBJECT (window));
|
|
|
|
gtk_widget_show (button);
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
|
gtk_widget_show (vbox);
|
|
|
|
gtk_widget_show (window);
|
|
|
|
testrgb_rgb_test (drawing_area);
|
|
}
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
gtk_init (&argc, &argv);
|
|
|
|
gdk_rgb_set_verbose (TRUE);
|
|
|
|
gdk_rgb_init ();
|
|
|
|
gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
|
|
gtk_widget_set_default_visual (gdk_rgb_get_visual ());
|
|
new_testrgb_window ();
|
|
|
|
gtk_main ();
|
|
|
|
return 0;
|
|
}
|