diff options
38 files changed, 1315 insertions, 4033 deletions
@@ -1,3 +1,46 @@ +Sun Jul 2 12:45:50 2000 Owen Taylor <otaylor@redhat.com> + + * gdk/gdkrgb.[ch]: Add gdk_rgb_find_color() to get a pixel + value using GdkRGB functionality given GdkColormap and GdkColor. + (name not final, waiting for inspiration.) + + * gdk/gdkgc.[ch] (gdk_gc_set_rgb_fg/bg_color): New functions to + set the foreground/background of a GC using the GC's colormap + and GdkRGB. (name not final, waiting for inspiration.) + + * gdk/gdkcompat.h gdk/gdkrgb.c (gdk_rgb_get_colormap): Rename from + gdk_rgb_get_cmap(), put #define in gdkcompat.h. + + * gtk/gtkwidget.[ch] gtkcompat.h: Make visuals for + gtk_widget_get_visual(), gtk_widget_get_default_visual, etc, + purely a function of the corresponding colormap. Make + gtk_widget_set_visual(), etc, noop macros in gtkcompat.h. + + * gdk/gdkpixmap.c gdk/x11/gdkpixmap-c11.c: Rewrite + gdk_pixbuf_*create_from_xpm_* in terms of + gdk_pixbuf_new_from_xpm_data(), move into platform independent + code. + + * gdk/gdkpixbuf-render.c (gdk_pixbuf_render_to_drawable): Take + advantage of the new draw_rgb_32_image_dithalign. + + * gdk/gdkrgb.c (gdk_draw_rgb_32_image_dithalign): Added. + + * gtk/gtkgc.c (gtk_gc_new): Set the appropriate colormap + on each created GC. + + * gdk/gdkgc.[ch]: Add gdk_gc_get/set_colormap. + + * gdk/gdkgc.[ch]: Add a colormap field to the GdkGC structure + which we initialize from the drawable when the GC is created, + if the drawable has a colormap. + + * gdk/x11/gdkgc-x11.c: include string.h for memset. + + * gdk/x11/gdkinput-x11.c: include string.h for strlen, etc. + + * gtk/gtklayout.[ch]: Remove unsed configure serial member. + Sat Jul 1 16:28:32 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkevents-x11.c (gdk_event_translate): When diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index e727ad602..52006faea 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,46 @@ +Sun Jul 2 12:45:50 2000 Owen Taylor <otaylor@redhat.com> + + * gdk/gdkrgb.[ch]: Add gdk_rgb_find_color() to get a pixel + value using GdkRGB functionality given GdkColormap and GdkColor. + (name not final, waiting for inspiration.) + + * gdk/gdkgc.[ch] (gdk_gc_set_rgb_fg/bg_color): New functions to + set the foreground/background of a GC using the GC's colormap + and GdkRGB. (name not final, waiting for inspiration.) + + * gdk/gdkcompat.h gdk/gdkrgb.c (gdk_rgb_get_colormap): Rename from + gdk_rgb_get_cmap(), put #define in gdkcompat.h. + + * gtk/gtkwidget.[ch] gtkcompat.h: Make visuals for + gtk_widget_get_visual(), gtk_widget_get_default_visual, etc, + purely a function of the corresponding colormap. Make + gtk_widget_set_visual(), etc, noop macros in gtkcompat.h. + + * gdk/gdkpixmap.c gdk/x11/gdkpixmap-c11.c: Rewrite + gdk_pixbuf_*create_from_xpm_* in terms of + gdk_pixbuf_new_from_xpm_data(), move into platform independent + code. + + * gdk/gdkpixbuf-render.c (gdk_pixbuf_render_to_drawable): Take + advantage of the new draw_rgb_32_image_dithalign. + + * gdk/gdkrgb.c (gdk_draw_rgb_32_image_dithalign): Added. + + * gtk/gtkgc.c (gtk_gc_new): Set the appropriate colormap + on each created GC. + + * gdk/gdkgc.[ch]: Add gdk_gc_get/set_colormap. + + * gdk/gdkgc.[ch]: Add a colormap field to the GdkGC structure + which we initialize from the drawable when the GC is created, + if the drawable has a colormap. + + * gdk/x11/gdkgc-x11.c: include string.h for memset. + + * gdk/x11/gdkinput-x11.c: include string.h for strlen, etc. + + * gtk/gtklayout.[ch]: Remove unsed configure serial member. + Sat Jul 1 16:28:32 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkevents-x11.c (gdk_event_translate): When diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index e727ad602..52006faea 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,46 @@ +Sun Jul 2 12:45:50 2000 Owen Taylor <otaylor@redhat.com> + + * gdk/gdkrgb.[ch]: Add gdk_rgb_find_color() to get a pixel + value using GdkRGB functionality given GdkColormap and GdkColor. + (name not final, waiting for inspiration.) + + * gdk/gdkgc.[ch] (gdk_gc_set_rgb_fg/bg_color): New functions to + set the foreground/background of a GC using the GC's colormap + and GdkRGB. (name not final, waiting for inspiration.) + + * gdk/gdkcompat.h gdk/gdkrgb.c (gdk_rgb_get_colormap): Rename from + gdk_rgb_get_cmap(), put #define in gdkcompat.h. + + * gtk/gtkwidget.[ch] gtkcompat.h: Make visuals for + gtk_widget_get_visual(), gtk_widget_get_default_visual, etc, + purely a function of the corresponding colormap. Make + gtk_widget_set_visual(), etc, noop macros in gtkcompat.h. + + * gdk/gdkpixmap.c gdk/x11/gdkpixmap-c11.c: Rewrite + gdk_pixbuf_*create_from_xpm_* in terms of + gdk_pixbuf_new_from_xpm_data(), move into platform independent + code. + + * gdk/gdkpixbuf-render.c (gdk_pixbuf_render_to_drawable): Take + advantage of the new draw_rgb_32_image_dithalign. + + * gdk/gdkrgb.c (gdk_draw_rgb_32_image_dithalign): Added. + + * gtk/gtkgc.c (gtk_gc_new): Set the appropriate colormap + on each created GC. + + * gdk/gdkgc.[ch]: Add gdk_gc_get/set_colormap. + + * gdk/gdkgc.[ch]: Add a colormap field to the GdkGC structure + which we initialize from the drawable when the GC is created, + if the drawable has a colormap. + + * gdk/x11/gdkgc-x11.c: include string.h for memset. + + * gdk/x11/gdkinput-x11.c: include string.h for strlen, etc. + + * gtk/gtklayout.[ch]: Remove unsed configure serial member. + Sat Jul 1 16:28:32 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkevents-x11.c (gdk_event_translate): When diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index e727ad602..52006faea 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,46 @@ +Sun Jul 2 12:45:50 2000 Owen Taylor <otaylor@redhat.com> + + * gdk/gdkrgb.[ch]: Add gdk_rgb_find_color() to get a pixel + value using GdkRGB functionality given GdkColormap and GdkColor. + (name not final, waiting for inspiration.) + + * gdk/gdkgc.[ch] (gdk_gc_set_rgb_fg/bg_color): New functions to + set the foreground/background of a GC using the GC's colormap + and GdkRGB. (name not final, waiting for inspiration.) + + * gdk/gdkcompat.h gdk/gdkrgb.c (gdk_rgb_get_colormap): Rename from + gdk_rgb_get_cmap(), put #define in gdkcompat.h. + + * gtk/gtkwidget.[ch] gtkcompat.h: Make visuals for + gtk_widget_get_visual(), gtk_widget_get_default_visual, etc, + purely a function of the corresponding colormap. Make + gtk_widget_set_visual(), etc, noop macros in gtkcompat.h. + + * gdk/gdkpixmap.c gdk/x11/gdkpixmap-c11.c: Rewrite + gdk_pixbuf_*create_from_xpm_* in terms of + gdk_pixbuf_new_from_xpm_data(), move into platform independent + code. + + * gdk/gdkpixbuf-render.c (gdk_pixbuf_render_to_drawable): Take + advantage of the new draw_rgb_32_image_dithalign. + + * gdk/gdkrgb.c (gdk_draw_rgb_32_image_dithalign): Added. + + * gtk/gtkgc.c (gtk_gc_new): Set the appropriate colormap + on each created GC. + + * gdk/gdkgc.[ch]: Add gdk_gc_get/set_colormap. + + * gdk/gdkgc.[ch]: Add a colormap field to the GdkGC structure + which we initialize from the drawable when the GC is created, + if the drawable has a colormap. + + * gdk/x11/gdkgc-x11.c: include string.h for memset. + + * gdk/x11/gdkinput-x11.c: include string.h for strlen, etc. + + * gtk/gtklayout.[ch]: Remove unsed configure serial member. + Sat Jul 1 16:28:32 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkevents-x11.c (gdk_event_translate): When diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index e727ad602..52006faea 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,46 @@ +Sun Jul 2 12:45:50 2000 Owen Taylor <otaylor@redhat.com> + + * gdk/gdkrgb.[ch]: Add gdk_rgb_find_color() to get a pixel + value using GdkRGB functionality given GdkColormap and GdkColor. + (name not final, waiting for inspiration.) + + * gdk/gdkgc.[ch] (gdk_gc_set_rgb_fg/bg_color): New functions to + set the foreground/background of a GC using the GC's colormap + and GdkRGB. (name not final, waiting for inspiration.) + + * gdk/gdkcompat.h gdk/gdkrgb.c (gdk_rgb_get_colormap): Rename from + gdk_rgb_get_cmap(), put #define in gdkcompat.h. + + * gtk/gtkwidget.[ch] gtkcompat.h: Make visuals for + gtk_widget_get_visual(), gtk_widget_get_default_visual, etc, + purely a function of the corresponding colormap. Make + gtk_widget_set_visual(), etc, noop macros in gtkcompat.h. + + * gdk/gdkpixmap.c gdk/x11/gdkpixmap-c11.c: Rewrite + gdk_pixbuf_*create_from_xpm_* in terms of + gdk_pixbuf_new_from_xpm_data(), move into platform independent + code. + + * gdk/gdkpixbuf-render.c (gdk_pixbuf_render_to_drawable): Take + advantage of the new draw_rgb_32_image_dithalign. + + * gdk/gdkrgb.c (gdk_draw_rgb_32_image_dithalign): Added. + + * gtk/gtkgc.c (gtk_gc_new): Set the appropriate colormap + on each created GC. + + * gdk/gdkgc.[ch]: Add gdk_gc_get/set_colormap. + + * gdk/gdkgc.[ch]: Add a colormap field to the GdkGC structure + which we initialize from the drawable when the GC is created, + if the drawable has a colormap. + + * gdk/x11/gdkgc-x11.c: include string.h for memset. + + * gdk/x11/gdkinput-x11.c: include string.h for strlen, etc. + + * gtk/gtklayout.[ch]: Remove unsed configure serial member. + Sat Jul 1 16:28:32 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkevents-x11.c (gdk_event_translate): When diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index e727ad602..52006faea 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,46 @@ +Sun Jul 2 12:45:50 2000 Owen Taylor <otaylor@redhat.com> + + * gdk/gdkrgb.[ch]: Add gdk_rgb_find_color() to get a pixel + value using GdkRGB functionality given GdkColormap and GdkColor. + (name not final, waiting for inspiration.) + + * gdk/gdkgc.[ch] (gdk_gc_set_rgb_fg/bg_color): New functions to + set the foreground/background of a GC using the GC's colormap + and GdkRGB. (name not final, waiting for inspiration.) + + * gdk/gdkcompat.h gdk/gdkrgb.c (gdk_rgb_get_colormap): Rename from + gdk_rgb_get_cmap(), put #define in gdkcompat.h. + + * gtk/gtkwidget.[ch] gtkcompat.h: Make visuals for + gtk_widget_get_visual(), gtk_widget_get_default_visual, etc, + purely a function of the corresponding colormap. Make + gtk_widget_set_visual(), etc, noop macros in gtkcompat.h. + + * gdk/gdkpixmap.c gdk/x11/gdkpixmap-c11.c: Rewrite + gdk_pixbuf_*create_from_xpm_* in terms of + gdk_pixbuf_new_from_xpm_data(), move into platform independent + code. + + * gdk/gdkpixbuf-render.c (gdk_pixbuf_render_to_drawable): Take + advantage of the new draw_rgb_32_image_dithalign. + + * gdk/gdkrgb.c (gdk_draw_rgb_32_image_dithalign): Added. + + * gtk/gtkgc.c (gtk_gc_new): Set the appropriate colormap + on each created GC. + + * gdk/gdkgc.[ch]: Add gdk_gc_get/set_colormap. + + * gdk/gdkgc.[ch]: Add a colormap field to the GdkGC structure + which we initialize from the drawable when the GC is created, + if the drawable has a colormap. + + * gdk/x11/gdkgc-x11.c: include string.h for memset. + + * gdk/x11/gdkinput-x11.c: include string.h for strlen, etc. + + * gtk/gtklayout.[ch]: Remove unsed configure serial member. + Sat Jul 1 16:28:32 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkevents-x11.c (gdk_event_translate): When diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index e727ad602..52006faea 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,46 @@ +Sun Jul 2 12:45:50 2000 Owen Taylor <otaylor@redhat.com> + + * gdk/gdkrgb.[ch]: Add gdk_rgb_find_color() to get a pixel + value using GdkRGB functionality given GdkColormap and GdkColor. + (name not final, waiting for inspiration.) + + * gdk/gdkgc.[ch] (gdk_gc_set_rgb_fg/bg_color): New functions to + set the foreground/background of a GC using the GC's colormap + and GdkRGB. (name not final, waiting for inspiration.) + + * gdk/gdkcompat.h gdk/gdkrgb.c (gdk_rgb_get_colormap): Rename from + gdk_rgb_get_cmap(), put #define in gdkcompat.h. + + * gtk/gtkwidget.[ch] gtkcompat.h: Make visuals for + gtk_widget_get_visual(), gtk_widget_get_default_visual, etc, + purely a function of the corresponding colormap. Make + gtk_widget_set_visual(), etc, noop macros in gtkcompat.h. + + * gdk/gdkpixmap.c gdk/x11/gdkpixmap-c11.c: Rewrite + gdk_pixbuf_*create_from_xpm_* in terms of + gdk_pixbuf_new_from_xpm_data(), move into platform independent + code. + + * gdk/gdkpixbuf-render.c (gdk_pixbuf_render_to_drawable): Take + advantage of the new draw_rgb_32_image_dithalign. + + * gdk/gdkrgb.c (gdk_draw_rgb_32_image_dithalign): Added. + + * gtk/gtkgc.c (gtk_gc_new): Set the appropriate colormap + on each created GC. + + * gdk/gdkgc.[ch]: Add gdk_gc_get/set_colormap. + + * gdk/gdkgc.[ch]: Add a colormap field to the GdkGC structure + which we initialize from the drawable when the GC is created, + if the drawable has a colormap. + + * gdk/x11/gdkgc-x11.c: include string.h for memset. + + * gdk/x11/gdkinput-x11.c: include string.h for strlen, etc. + + * gtk/gtklayout.[ch]: Remove unsed configure serial member. + Sat Jul 1 16:28:32 2000 Owen Taylor <otaylor@redhat.com> * gdk/x11/gdkevents-x11.c (gdk_event_translate): When diff --git a/demos/testanimation.c b/demos/testanimation.c index dd2701719..9ec6c7417 100644 --- a/demos/testanimation.c +++ b/demos/testanimation.c @@ -385,7 +385,6 @@ main (int argc, char **argv) gdk_rgb_init (); gtk_widget_set_default_colormap (gdk_rgb_get_cmap ()); - gtk_widget_set_default_visual (gdk_rgb_get_visual ()); { char *tbf_readlen = getenv("TBF_READLEN"); diff --git a/demos/testpixbuf-drawable.c b/demos/testpixbuf-drawable.c index 550550bf4..7b3170520 100644 --- a/demos/testpixbuf-drawable.c +++ b/demos/testpixbuf-drawable.c @@ -83,7 +83,6 @@ int main(int argc, char **argv) gdk_rgb_init(); gtk_widget_set_default_colormap(gdk_rgb_get_cmap()); - gtk_widget_set_default_visual(gdk_rgb_get_visual()); root = GDK_ROOT_PARENT(); pixbuf = gdk_pixbuf_get_from_drawable(NULL, root, NULL, diff --git a/demos/testpixbuf.c b/demos/testpixbuf.c index 85dea5b7b..630996234 100644 --- a/demos/testpixbuf.c +++ b/demos/testpixbuf.c @@ -503,7 +503,6 @@ main (int argc, char **argv) gdk_rgb_init (); gtk_widget_set_default_colormap (gdk_rgb_get_cmap ()); - gtk_widget_set_default_visual (gdk_rgb_get_visual ()); { char *tbf_readlen = getenv("TBF_READLEN"); diff --git a/docs/Changes-1.4.txt b/docs/Changes-1.4.txt index e75a97e4a..974f51e83 100644 --- a/docs/Changes-1.4.txt +++ b/docs/Changes-1.4.txt @@ -132,9 +132,9 @@ Incompatible Changes from GTK+-1.2 to GTK+-1.4: no GDK_WINDOW_PIXMAP. You can use the GDK_IS_PIXMAP() macro to see if you have a pixmap, if you need to know that. -- GtkStyle and GtkRcStyle are now subclasses of GObject as well. - This breaks theme engines quite badly, but shouldn't affect most - other code. +- GtkStyle and GtkRcStyle are now subclasses of GObject as well. This + requires fairly extensive changes to theme engines quite badly, but + shouldn't affect most other code. - xthickness/ythickness have moved from GtkStyleClass to GtkStyle (from class to instance). This gives themes a bit more flexibility @@ -145,6 +145,44 @@ Incompatible Changes from GTK+-1.2 to GTK+-1.4: - If you were using private GDK types, they have been rearranged significantly. You shouldn't use private types. ;-) +- The visual for a widget, and also the default visual is now derived + from the colormap for the widget and the default colormap. + gtk_widget_set_visual(), gtk_widget_set_defualt_visual(), gtk_widget_push_visual() + and gtk_widget_pop_visual() now do nothing. Since the visual always + had to match that of the colormap, it is safe to simply delete + all references to these functions. + +- A number of functions in GDK have been renamed for consistency and + clarity. #defines to provide backwards compatibility have been + included, but can be disabled by defineing GDK_DISABLE_COMPAT_H. + + #define gdk_draw_pixmap gdk_draw_drawable + #define gdk_draw_bitmap gdk_draw_drawable + + #define gdk_window_get_size gdk_drawable_get_size + #define gdk_window_get_type gdk_window_get_window_type + #define gdk_window_get_colormap gdk_drawable_get_colormap + #define gdk_window_set_colormap gdk_drawable_set_colormap + #define gdk_window_get_visual gdk_drawable_get_visual + + #define gdk_window_ref gdk_drawable_ref + #define gdk_window_unref gdk_drawable_unref + #define gdk_bitmap_ref gdk_drawable_ref + #define gdk_bitmap_unref gdk_drawable_unref + #define gdk_pixmap_ref gdk_drawable_ref + #define gdk_pixmap_unref gdk_drawable_unref + + #define gdk_gc_destroy gdk_gc_unref + #define gdk_image_destroy gdk_image_unref + #define gdk_cursor_destroy gdk_cursor_unref + + (Note that g_object_ref() and g_object_unref() may be used for all of + the above.) + + #define gdk_window_copy_area(drawable,gc,x,y,source_drawable,source_x,source_y,width,height) \ + gdk_draw_pixmap(drawable,gc,source_drawable,source_x,source_y,x,y,width,height) + + #define gdk_rgb_get_cmap gdk_rgb_get_colormap + -
\ No newline at end of file diff --git a/gdk/gdkcompat.h b/gdk/gdkcompat.h index 03f692d67..182356592 100644 --- a/gdk/gdkcompat.h +++ b/gdk/gdkcompat.h @@ -6,7 +6,7 @@ extern "C" { #endif /* __cplusplus */ -/* use -DGDK_DISABLE_COMPAT_H to compile your code and asure that it +/* use -DGDK_DISABLE_COMPAT_H to compile your code and assure that it * works with future GTK+ versions as well. */ #ifndef GDK_DISABLE_COMPAT_H @@ -34,6 +34,7 @@ extern "C" { #define gdk_image_destroy gdk_image_unref #define gdk_cursor_destroy gdk_cursor_unref +#define gdk_rgb_get_cmap gdk_rgb_get_colormap #endif /* GDK_DISABLE_COMPAT_H */ diff --git a/gdk/gdkgc.c b/gdk/gdkgc.c index 099ba1cc2..8a54612e2 100644 --- a/gdk/gdkgc.c +++ b/gdk/gdkgc.c @@ -27,8 +27,14 @@ #include <string.h> #include "gdkgc.h" +#include "gdkrgb.h" #include "gdkprivate.h" +static void gdk_gc_class_init (GObjectClass *class); +static void gdk_gc_finalize (GObject *object); + +GObjectClass *parent_class; + GType gdk_gc_get_type (void) { @@ -41,7 +47,7 @@ gdk_gc_get_type (void) sizeof (GdkGCClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, - (GClassInitFunc) NULL, + (GClassInitFunc) gdk_gc_class_init, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (GdkGC), @@ -57,6 +63,14 @@ gdk_gc_get_type (void) return object_type; } +static void +gdk_gc_class_init (GObjectClass *class) +{ + parent_class = g_type_class_peek_parent (class); + + class->finalize = gdk_gc_finalize; +} + GdkGC* gdk_gc_new (GdkDrawable *drawable) { @@ -90,9 +104,24 @@ gdk_gc_new_with_values (GdkDrawable *drawable, if (values_mask & GDK_GC_TS_Y_ORIGIN) gc->ts_y_origin = values->ts_y_origin; + gc->colormap = gdk_drawable_get_colormap (drawable); + if (gc->colormap) + g_object_ref (G_OBJECT (gc->colormap)); + return gc; } +static void +gdk_gc_finalize (GObject *object) +{ + GdkGC *gc = GDK_GC (object); + + if (gc->colormap) + g_object_unref (G_OBJECT (gc->colormap)); + + parent_class->finalize (object); +} + GdkGC * gdk_gc_ref (GdkGC *gc) { @@ -323,3 +352,127 @@ gdk_gc_set_dashes (GdkGC *gc, GDK_GC_GET_CLASS (gc)->set_dashes (gc, dash_offset, dash_list, n); } + +/** + * gdk_gc_set_colormap: + * @gc: a #GdkGC + * @colormap: a #GdkColormap + * + * Sets the colormap for the GC to the given colormap. The depth + * of the colormap's visual must match the depth of the drawable + * for which the GC was created. + **/ +void +gdk_gc_set_colormap (GdkGC *gc, + GdkColormap *colormap) +{ + g_return_if_fail (GDK_IS_GC (gc)); + g_return_if_fail (GDK_IS_COLORMAP (colormap)); + + if (gc->colormap != colormap) + { + if (gc->colormap) + g_object_unref (G_OBJECT (gc->colormap)); + + gc->colormap = colormap; + g_object_ref (G_OBJECT (gc->colormap)); + } + +} + +/** + * gdk_gc_get_colormap: + * @gc: a #GdkGC + * + * Retrieves the colormap for a given GC, if it exists. + * A GC will have a colormap if the drawable for which it was created + * has a colormap, or if a colormap was set explicitely with + * gdk_gc_set_colormap. + * + * Return value: + **/ +GdkColormap * +gdk_gc_get_colormap (GdkGC *gc) +{ + g_return_val_if_fail (GDK_IS_GC (gc), NULL); + + return gc->colormap; +} + +static GdkColormap * +gdk_gc_get_colormap_warn (GdkGC *gc) +{ + GdkColormap *colormap = gdk_gc_get_colormap (gc); + if (!colormap) + { + g_warning ("gdk_gc_set_rgb_fg_color() and gdk_gc_set_rgb_bg_color() can\n" + "only be used on GC's with a colormap. A GC will have a colormap\n" + "if it is created for a drawable with a colormap, or if a\n" + "colormap has been set explicitly with gdk_gc_set_colormap.\n"); + return NULL; + } + + return colormap; +} + +/** + * gdk_gc_set_rgb_fg_color: + * @gc: a #GdkGC + * @color: an unallocated #GdkColor. + * + * Set the foreground color of a GC using an unallocated color. The + * pixel value for the color will be determined using GdkRGB. If the + * colormap for the GC has not previously been initialized for GdkRGB, + * then for pseudo-color colormaps (colormaps with a small modifiable + * number of colors), a colorcube will be allocated in the colormap. + * + * Calling this function for a GC without a colormap is an error. + **/ +void +gdk_gc_set_rgb_fg_color (GdkGC *gc, GdkColor *color) +{ + GdkColormap *cmap; + GdkColor tmp_color; + + g_return_if_fail (GDK_IS_GC (gc)); + g_return_if_fail (color != NULL); + + cmap = gdk_gc_get_colormap_warn (gc); + if (!cmap) + return; + + tmp_color = *color; + gdk_rgb_find_color (cmap, &tmp_color); + gdk_gc_set_foreground (cmap, &tmp_color); +} + +/** + * gdk_gc_set_rgb_bg_color: + * @gc: a #GdkGC + * @color: an unallocated #GdkColor. + * + * Set the background color of a GC using an unallocated color. The + * pixel value for the color will be determined using GdkRGB. If the + * colormap for the GC has not previously been initialized for GdkRGB, + * then for pseudo-color colormaps (colormaps with a small modifiable + * number of colors), a colorcube will be allocated in the colormap. + * + * Calling this function for a GC without a colormap is an error. + **/ +void +gdk_gc_set_rgb_bg_color (GdkGC *gc, GdkColor *color) +{ + GdkColormap *cmap; + GdkColor tmp_color; + + g_return_if_fail (GDK_IS_GC (gc)); + g_return_if_fail (color != NULL); + + cmap = gdk_gc_get_colormap_warn (gc); + if (!cmap) + return; + + tmp_color = *color; + gdk_rgb_find_color (cmap, &tmp_color); + gdk_gc_set_foreground (cmap, &tmp_color); +} diff --git a/gdk/gdkgc.h b/gdk/gdkgc.h index 4ae317a88..da5295472 100644 --- a/gdk/gdkgc.h +++ b/gdk/gdkgc.h @@ -166,6 +166,8 @@ struct _GdkGC gint clip_y_origin; gint ts_x_origin; gint ts_y_origin; + + GdkColormap *colormap; }; struct _GdkGCClass @@ -235,8 +237,17 @@ void gdk_gc_set_dashes (GdkGC *gc, gint dash_offset, gint8 dash_list[], gint n); -void gdk_gc_copy (GdkGC *dst_gc, - GdkGC *src_gc); +void gdk_gc_copy (GdkGC *dst_gc, + GdkGC *src_gc); + + +void gdk_gc_set_colormap (GdkGC *gc, + GdkColormap *colormap); +GdkColormap *gdk_gc_get_colormap (GdkGC *gc); +void gdk_gc_set_rgb_fg_color (GdkGC *gc, + GdkColor *color); +void gdk_gc_set_rgb_bg_color (GdkGC *gc, + GdkColor *color); #ifdef __cplusplus } diff --git a/gdk/gdkpixbuf-render.c b/gdk/gdkpixbuf-render.c index 545f91123..39bda4cc1 100644 --- a/gdk/gdkpixbuf-render.c +++ b/gdk/gdkpixbuf-render.c @@ -130,44 +130,6 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf, -/* Creates a buffer by stripping the alpha channel of a pixbuf */ -static guchar * -remove_alpha (GdkPixbuf *pixbuf, - int x, int y, - int width, int height, - int *rowstride) -{ - guchar *buf; - int xx, yy; - guchar *src, *dest; - - g_assert (pixbuf->n_channels == 4); - g_assert (pixbuf->has_alpha); - g_assert (width > 0 && height > 0); - g_assert (x >= 0 && x + width <= pixbuf->width); - g_assert (y >= 0 && y + height <= pixbuf->height); - - *rowstride = 4 * ((width * 3 + 3) / 4); - - buf = g_new (guchar, *rowstride * height); - - for (yy = 0; yy < height; yy++) - { - src = pixbuf->pixels + pixbuf->rowstride * (yy + y) + x * pixbuf->n_channels; - dest = buf + *rowstride * yy; - - for (xx = 0; xx < width; xx++) - { - *dest++ = *src++; - *dest++ = *src++; - *dest++ = *src++; - src++; - } - } - - return buf; -} - /** * gdk_pixbuf_render_to_drawable: * @pixbuf: A pixbuf. @@ -206,8 +168,8 @@ gdk_pixbuf_render_to_drawable (GdkPixbuf *pixbuf, GdkRgbDither dither, int x_dither, int y_dither) { - guchar *buf; int rowstride; + guchar *buf; g_return_if_fail (pixbuf != NULL); g_return_if_fail (pixbuf->colorspace == GDK_COLORSPACE_RGB); @@ -225,27 +187,32 @@ gdk_pixbuf_render_to_drawable (GdkPixbuf *pixbuf, return; /* This will have to be modified once we support other image types. - * Also, GdkRGB does not have gdk_draw_rgb_32_image_dithalign(), so we - * have to pack the buffer first. Sigh. */ - if (pixbuf->has_alpha) - buf = remove_alpha (pixbuf, src_x, src_y, width, height, &rowstride); - else + if (pixbuf->n_channels == 4) { buf = pixbuf->pixels + src_y * pixbuf->rowstride + src_x * 3; rowstride = pixbuf->rowstride; - } - gdk_draw_rgb_image_dithalign (drawable, gc, - dest_x, dest_y, - width, height, - dither, - buf, rowstride, - x_dither, y_dither); + gdk_draw_rgb_32_image_dithalign (drawable, gc, + dest_x, dest_y, + width, height, + dither, + buf, rowstride, + x_dither, y_dither); + } + else /* n_channels == 3 */ + { + buf = pixbuf->pixels + src_y * pixbuf->rowstride + src_x * 3; + rowstride = pixbuf->rowstride; - if (pixbuf->has_alpha) - g_free (buf); + gdk_draw_rgb_image_dithalign (drawable, gc, + dest_x, dest_y, + width, height, + dither, + buf, rowstride, + x_dither, y_dither); + } } diff --git a/gdk/gdkpixmap.c b/gdk/gdkpixmap.c index 70c825f91..96b2c6273 100644 --- a/gdk/gdkpixmap.c +++ b/gdk/gdkpixmap.c @@ -26,6 +26,7 @@ #include "gdkpixmap.h" #include "gdkinternals.h" +#include "gdkpixbuf.h" static GdkGC *gdk_pixmap_create_gc (GdkDrawable *drawable, GdkGCValues *values, @@ -409,3 +410,124 @@ gdk_pixmap_real_get_colormap (GdkDrawable *drawable) return gdk_drawable_get_colormap (((GdkPixmapObject*)drawable)->impl); } + +#define PACKED_COLOR(c) ((((c)->red & 0xff) << 8) | ((c)->green & 0xff) | ((c)->blue >> 8)) + +static GdkPixmap * +gdk_pixmap_colormap_new_from_pixbuf (GdkColormap *colormap, + GdkBitmap **mask, + GdkColor *transparent_color, + GdkPixbuf *pixbuf) +{ + GdkPixmap *pixmap; + GdkPixbuf *render_pixbuf; + GdkGC *tmp_gc; + + pixmap = gdk_pixmap_new (NULL, + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf), + gdk_colormap_get_visual (colormap)->depth); + gdk_drawable_set_colormap (pixmap, colormap); + + if (transparent_color) + { + guint32 packed_color = PACKED_COLOR (transparent_color); + render_pixbuf = gdk_pixbuf_composite_color_simple (pixbuf, + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf), + GDK_INTERP_NEAREST, + 255, 16, packed_color, packed_color); + } + else + render_pixbuf = pixbuf; + + tmp_gc = gdk_gc_new (pixmap); + gdk_pixbuf_render_to_drawable (render_pixbuf, pixmap, tmp_gc, 0, 0, 0, 0, + gdk_pixbuf_get_width (render_pixbuf), + gdk_pixbuf_get_height (render_pixbuf), + GDK_RGB_DITHER_NORMAL, 0, 0); + gdk_gc_unref (tmp_gc); + + if (render_pixbuf != pixbuf) + gdk_pixbuf_unref (render_pixbuf); + + if (mask) + gdk_pixbuf_render_pixmap_and_mask (pixbuf, NULL, mask, 128); + + return pixmap; +} + +GdkPixmap* +gdk_pixmap_colormap_create_from_xpm (GdkWindow *window, + GdkColormap *colormap, + GdkBitmap **mask, + GdkColor *transparent_color, + const gchar *filename) +{ + GdkPixbuf *pixbuf; + GdkPixmap *pixmap; + + g_return_val_if_fail (window != NULL || colormap != NULL, NULL); + g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL); + g_return_val_if_fail (colormap == NULL || GDK_IS_COLORMAP (colormap), NULL); + + if (colormap == NULL) + colormap = gdk_drawable_get_colormap (window); + + pixbuf = gdk_pixbuf_new_from_file (filename); + if (!pixbuf) + return NULL; + + pixmap = gdk_pixmap_colormap_new_from_pixbuf (colormap, mask, transparent_color, pixbuf); + gdk_pixbuf_unref (pixbuf); + + return pixmap; +} + +GdkPixmap* +gdk_pixmap_create_from_xpm (GdkWindow *window, + GdkBitmap **mask, + GdkColor *transparent_color, + const gchar *filename) +{ + return gdk_pixmap_colormap_create_from_xpm (window, NULL, mask, + transparent_color, filename); +} + +GdkPixmap* +gdk_pixmap_colormap_create_from_xpm_d (GdkWindow *window, + GdkColormap *colormap, + GdkBitmap **mask, + GdkColor *transparent_color, + gchar **data) +{ + GdkPixbuf *pixbuf; + GdkPixmap *pixmap; + + g_return_val_if_fail (window != NULL || colormap != NULL, NULL); + g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL); + g_return_val_if_fail (colormap == NULL || GDK_IS_COLORMAP (colormap), NULL); + + if (colormap == NULL) + colormap = gdk_drawable_get_colormap (window); + + pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **)data); + if (!pixbuf) + return NULL; + + pixmap = gdk_pixmap_colormap_new_from_pixbuf (colormap, mask, transparent_color, pixbuf); + gdk_pixbuf_unref (pixbuf); + + return pixmap; +} + +GdkPixmap* +gdk_pixmap_create_from_xpm_d (GdkWindow *window, + GdkBitmap **mask, + GdkColor *transparent_color, + gchar **data) +{ + return gdk_pixmap_colormap_create_from_xpm_d (window, NULL, mask, + transparent_color, data); +} + diff --git a/gdk/gdkrgb.c b/gdk/gdkrgb.c index 009b77cce..cb05cbcae 100644 --- a/gdk/gdkrgb.c +++ b/gdk/gdkrgb.c @@ -64,9 +64,10 @@ #include "gdk.h" /* For gdk_flush() */ #include "gdkrgb.h" -typedef struct _GdkRgbInfo GdkRgbInfo; +typedef struct _GdkRgbInfo GdkRgbInfo; +typedef struct _GdkRgbCmapInfo GdkRgbCmapInfo; -typedef void (*GdkRgbConvFunc) (GdkImage *image, +typedef void (*GdkRgbConvFunc) (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, @@ -174,14 +175,31 @@ struct _GdkRgbInfo guchar *colorcube; guchar *colorcube_d; + + /* We need to track LUT's for pairs of GdkRgbInfo / GdkRgbCmap, so we + * keep a list of pointers to GdkRgbCmapInfo on both structures so we + * can remove as necessary when freeing a GdkRgbInfo or GdkRgbCmap + */ + GSList *cmap_info_list; +}; + +struct _GdkRgbCmapInfo +{ + GdkRgbInfo *image_info; + GdkRgbCmap *cmap; + + guchar lut[256]; /* For 8-bit modes */ }; +static GdkRgbCmapInfo *gdk_rgb_cmap_get_info (GdkRgbCmap *cmap, GdkRgbInfo *image_info); + +static const char *gdk_rgb_key = "gdk-rgb-info"; +static GQuark gdk_rgb_quark = 0; + static gboolean gdk_rgb_install_cmap = FALSE; static gint gdk_rgb_min_colors = 5 * 5 * 5; static gboolean gdk_rgb_verbose = FALSE; -static GdkRgbInfo *image_info = NULL; - static gint gdk_rgb_cmap_fail (const char *msg, GdkColormap *cmap, gulong *pixels) { @@ -202,7 +220,8 @@ gdk_rgb_cmap_fail (const char *msg, GdkColormap *cmap, gulong *pixels) } static void -gdk_rgb_make_colorcube (gulong *pixels, gint nr, gint ng, gint nb) +gdk_rgb_make_colorcube (GdkRgbInfo *image_info, gulong *pixels, + gint nr, gint ng, gint nb) { guchar rt[16], gt[16], bt[16]; gint i; @@ -226,7 +245,8 @@ gdk_rgb_make_colorcube (gulong *pixels, gint nr, gint ng, gint nb) /* this is the colorcube suitable for dithering */ static void -gdk_rgb_make_colorcube_d (gulong *pixels, gint nr, gint ng, gint nb) +gdk_rgb_make_colorcube_d (GdkRgbInfo *image_info, gulong *pixels, + gint nr, gint ng, gint nb) { gint r, g, b; gint i; @@ -244,7 +264,8 @@ gdk_rgb_make_colorcube_d (gulong *pixels, gint nr, gint ng, gint nb) /* Try installing a color cube of the specified size. Make the colorcube and return TRUE on success */ static gint -gdk_rgb_try_colormap (gint nr, gint ng, gint nb) +gdk_rgb_try_colormap (GdkRgbInfo *image_info, gboolean force, + gint nr, gint ng, gint nb) { gint r, g, b; gint ri, gi, bi; @@ -259,10 +280,10 @@ gdk_rgb_try_colormap (gint nr, gint ng, gint nb) gint idx; gint best[256]; - if (nr * ng * nb < gdk_rgb_min_colors) + if (!force && nr * ng * nb < gdk_rgb_min_colors) return FALSE; - if (image_info->cmap_alloced) + if (image_info->cmap) cmap = image_info->cmap; else cmap = gdk_colormap_get_system (); @@ -275,34 +296,34 @@ gdk_rgb_try_colormap (gint nr, gint ng, gint nb) } #ifndef GAMMA - if (!gdk_rgb_install_cmap) - /* find color cube colors that are already present */ - for (i = 0; i < MIN (256, cmap->size); i++) - { - r = cmap->colors[i].red >> 8; - g = cmap->colors[i].green >> 8; - b = cmap->colors[i].blue >> 8; - ri = (r * (nr - 1) + 128) >> 8; - gi = (g * (ng - 1) + 128) >> 8; - bi = (b * (nb - 1) + 128) >> 8; - r0 = ri * 255 / (nr - 1); - g0 = gi * 255 / (ng - 1); - b0 = bi * 255 / (nb - 1); - idx = ((ri * nr) + gi) * nb + bi; - d2 = (r - r0) * (r - r0) + (g - g0) * (g - g0) + (b - b0) * (b - b0); - if (d2 < best[idx]) { - if (pixels[idx] < 256) - gdk_colors_free (cmap, pixels + idx, 1, 0); - else - colors_needed--; - color = cmap->colors[i]; - if (!gdk_color_alloc (cmap, &color)) - return gdk_rgb_cmap_fail ("error allocating system color\n", - cmap, pixels); - pixels[idx] = color.pixel; /* which is almost certainly i */ - best[idx] = d2; + if (cmap == gdk_colormap_get_system()) + /* find color cube colors that are already present */ + for (i = 0; i < MIN (256, cmap->size); i++) + { + r = cmap->colors[i].red >> 8; + g = cmap->colors[i].green >> 8; + b = cmap->colors[i].blue >> 8; + ri = (r * (nr - 1) + 128) >> 8; + gi = (g * (ng - 1) + 128) >> 8; + bi = (b * (nb - 1) + 128) >> 8; + r0 = ri * 255 / (nr - 1); + g0 = gi * 255 / (ng - 1); + b0 = bi * 255 / (nb - 1); + idx = ((ri * nr) + gi) * nb + bi; + d2 = (r - r0) * (r - r0) + (g - g0) * (g - g0) + (b - b0) * (b - b0); + if (d2 < best[idx]) { + if (pixels[idx] < 256) + gdk_colors_free (cmap, pixels + idx, 1, 0); + else + colors_needed--; + color = cmap->colors[i]; + if (!gdk_colormap_alloc_color (cmap, &color, FALSE, FALSE)) + return gdk_rgb_cmap_fail ("error allocating system color\n", + cmap, pixels); + pixels[idx] = color.pixel; /* which is almost certainly i */ + best[idx] = d2; + } } - } #endif if (colors_needed) @@ -336,8 +357,7 @@ gdk_rgb_try_colormap (gint nr, gint ng, gint nb) color.blue = 65535 * pow (color.blue / 65535.0, 0.5); #endif - /* This should be a raw XAllocColor call */ - if (!gdk_color_alloc (cmap, &color)) + if (!gdk_colormap_alloc_color (cmap, &color, FALSE, force)) { char tmp_str[80]; @@ -356,14 +376,14 @@ gdk_rgb_try_colormap (gint nr, gint ng, gint nb) image_info->nred_shades = nr; image_info->ngreen_shades = ng; image_info->nblue_shades = nb; - gdk_rgb_make_colorcube (pixels, nr, ng, nb); - gdk_rgb_make_colorcube_d (pixels, nr, ng, nb); + gdk_rgb_make_colorcube (image_info, pixels, nr, ng, nb); + gdk_rgb_make_colorcube_d (image_info, pixels, nr, ng, nb); return TRUE; } /* Return TRUE on success. */ static gboolean -gdk_rgb_do_colormaps (void) +gdk_rgb_do_colormaps (GdkRgbInfo *image_info, gboolean force) { static const gint sizes[][3] = { /* { 6, 7, 6 }, */ @@ -380,24 +400,25 @@ gdk_rgb_do_colormaps (void) static const gint n_sizes = sizeof(sizes) / (3 * sizeof(gint)); gint i; + /* Try the possible sizes. If the force parameter is set to TRUE + * and all larger sizes fail, force the larger size to succeed - + * this will involve allowing closest matches when allocating the + * colors + */ for (i = 0; i < n_sizes; i++) - if (gdk_rgb_try_colormap (sizes[i][0], sizes[i][1], sizes[i][2])) + if (gdk_rgb_try_colormap (image_info, + (i == n_sizes - 1 ) && force, + sizes[i][0], sizes[i][1], sizes[i][2])) return TRUE; return FALSE; } /* Make a 2 x 2 x 2 colorcube */ static void -gdk_rgb_colorcube_222 (void) +gdk_rgb_colorcube_222 (GdkRgbInfo *image_info) { int i; GdkColor color; - GdkColormap *cmap; - - if (image_info->cmap_alloced) - cmap = image_info->cmap; - else - cmap = gdk_colormap_get_system (); image_info->colorcube_d = g_new (guchar, 512); @@ -406,7 +427,7 @@ gdk_rgb_colorcube_222 (void) color.red = ((i & 4) >> 2) * 65535; color.green = ((i & 2) >> 1) * 65535; color.blue = (i & 1) * 65535; - gdk_color_alloc (cmap, &color); + gdk_colormap_alloc_color (image_info->cmap, &color, FALSE, TRUE); image_info->colorcube_d[((i & 4) << 4) | ((i & 2) << 2) | (i & 1)] = color.pixel; } } @@ -511,7 +532,7 @@ gdk_rgb_score_visual (GdkVisual *visual) return (quality << 12) | (speed << 8) | (sys << 4) | pseudo; } -static void +static GdkVisual * gdk_rgb_choose_visual (void) { GList *visuals, *tmp_list; @@ -538,13 +559,14 @@ gdk_rgb_choose_visual (void) g_list_free (visuals); - image_info->visual = best_visual; + return best_visual; } -static void gdk_rgb_select_conv (GdkImage *image); +static void gdk_rgb_select_conv (GdkRgbInfo *image_info, GdkImage *image); static void -gdk_rgb_set_gray_cmap (GdkColormap *cmap) +gdk_rgb_set_gray_cmap (GdkRgbInfo *image_info, + GdkColormap *cmap) { gint i; GdkColor color; @@ -558,7 +580,7 @@ gdk_rgb_set_gray_cmap (GdkColormap *cmap) color.red = i * 257; color.green = i * 257; color.blue = i * 257; - status = gdk_color_alloc (cmap, &color); + status = gdk_colormap_alloc_color (cmap, &color, FALSE, TRUE); pixels[i] = color.pixel; #ifdef VERBOSE g_print ("allocating pixel %d, %x %x %x, result %d\n", @@ -585,7 +607,9 @@ gdk_rgb_set_gray_cmap (GdkColormap *cmap) } static gboolean -gdk_rgb_allocate_images (gint n_images, gboolean shared) +gdk_rgb_allocate_images (GdkRgbInfo *image_info, + gint n_images, + gboolean shared) { gint i; @@ -615,150 +639,226 @@ gdk_rgb_allocate_images (gint n_images, gboolean shared) return TRUE; } -void -gdk_rgb_init (void) +static void +gdk_rgb_free_info (GdkRgbInfo *image_info) { gint i; - static const gint byte_order[1] = { 1 }; + GSList *tmp_list; - /* check endian sanity */ -#if G_BYTE_ORDER == G_BIG_ENDIAN - if (((char *)byte_order)[0] == 1) - g_error ("gdk_rgb_init: compiled for big endian, but this is a little endian machine.\n\n"); -#else - if (((char *)byte_order)[0] != 1) - g_error ("gdk_rgb_init: compiled for little endian, but this is a big endian machine.\n\n"); -#endif + + if (image_info->stage_buf) + g_free (image_info->stage_buf); + + if (image_info->gray_cmap) + gdk_rgb_cmap_free (image_info->gray_cmap); + + if (image_info->own_gc) + gdk_gc_unref (image_info->own_gc); + + for (i = 0; i < image_info->n_images; i++) + gdk_image_unref (image_info->static_image[i]); - if (image_info == NULL) + if (image_info->colorcube) + g_free (image_info->colorcube); + + if (image_info->colorcube_d) + g_free (image_info->colorcube_d); + + tmp_list = image_info->cmap_info_list; + while (tmp_list) { - image_info = g_new0 (GdkRgbInfo, 1); + GdkRgbCmapInfo *cmap_info = tmp_list->data; + cmap_info->cmap->info_list = g_slist_remove (cmap_info->cmap->info_list, cmap_info); + g_free (cmap_info); + } + g_slist_free (image_info->cmap_info_list); + + g_free (image_info); +} + +/* Create a GdkRgbInfo for the given visual/colormap pair. If colormap + * is NULL, it will be determined and stored in image_info->cmap. + * In this case, image_info->cmap will have an extra refcount which + * is owned by the caller. + */ +static GdkRgbInfo * +gdk_rgb_create_info (GdkVisual *visual, GdkColormap *colormap) +{ + GdkRgbInfo *image_info; + gint i; - image_info->visual = NULL; - image_info->cmap = NULL; + image_info = g_new0 (GdkRgbInfo, 1); - image_info->nred_shades = 6; - image_info->ngreen_shades = 6; - image_info->nblue_shades = 4; - image_info->ngray_shades = 24; - image_info->nreserved = 0; + image_info->visual = visual; + image_info->cmap = NULL; - image_info->bpp = 0; - image_info->cmap_alloced = FALSE; - image_info->gamma = 1.0; + image_info->nred_shades = 6; + image_info->ngreen_shades = 6; + image_info->nblue_shades = 4; + image_info->ngray_shades = 24; + image_info->nreserved = 0; - image_info->stage_buf = NULL; + image_info->bpp = 0; + image_info->cmap_alloced = FALSE; + image_info->gamma = 1.0; - image_info->own_gc = NULL; + image_info->stage_buf = NULL; - gdk_rgb_choose_visual (); + image_info->own_gc = NULL; - if ((image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR || - image_info->visual->type == GDK_VISUAL_STATIC_COLOR) && - image_info->visual->depth < 8 && - image_info->visual->depth >= 3) + image_info->cmap = colormap; + + if ((image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR || + image_info->visual->type == GDK_VISUAL_STATIC_COLOR) && + image_info->visual->depth < 8 && + image_info->visual->depth >= 3) + { + if (!image_info->cmap) + image_info->cmap = gdk_colormap_ref (gdk_colormap_get_system ()); + + gdk_rgb_colorcube_222 (image_info); + } + else if (image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR) + { + if (!image_info->cmap && + (gdk_rgb_install_cmap || image_info->visual != gdk_visual_get_system ())) { - image_info->cmap = gdk_colormap_get_system (); - gdk_rgb_colorcube_222 (); + image_info->cmap = gdk_colormap_new (image_info->visual, FALSE); + image_info->cmap_alloced = TRUE; } - else if (image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR) + if (!gdk_rgb_do_colormaps (image_info, image_info->cmap != NULL)) { - if (gdk_rgb_install_cmap || - image_info->visual != gdk_visual_get_system ()) - { - image_info->cmap = gdk_colormap_new (image_info->visual, FALSE); - image_info->cmap_alloced = TRUE; - } - if (!gdk_rgb_do_colormaps ()) - { - image_info->cmap = gdk_colormap_new (image_info->visual, FALSE); - image_info->cmap_alloced = TRUE; - gdk_rgb_do_colormaps (); - } - if (gdk_rgb_verbose) - g_print ("color cube: %d x %d x %d\n", - image_info->nred_shades, - image_info->ngreen_shades, - image_info->nblue_shades); - - if (!image_info->cmap_alloced) - image_info->cmap = gdk_colormap_get_system (); + image_info->cmap = gdk_colormap_new (image_info->visual, FALSE); + image_info->cmap_alloced = TRUE; + gdk_rgb_do_colormaps (image_info, TRUE); } + if (gdk_rgb_verbose) + g_print ("color cube: %d x %d x %d\n", + image_info->nred_shades, + image_info->ngreen_shades, + image_info->nblue_shades); + + if (!image_info->cmap) + image_info->cmap = gdk_colormap_ref (gdk_colormap_get_system ()); + } #ifdef ENABLE_GRAYSCALE - else if (image_info->visual->type == GDK_VISUAL_GRAYSCALE) + else if (image_info->visual->type == GDK_VISUAL_GRAYSCALE) + { + if (!image_info->cmap) { image_info->cmap = gdk_colormap_new (image_info->visual, FALSE); - gdk_rgb_set_gray_cmap (image_info->cmap); image_info->cmap_alloced = TRUE; - } + } + + gdk_rgb_set_gray_cmap (image_info, image_info->cmap); + } #endif - else + else + { + if (!image_info->cmap) { /* Always install colormap in direct color. */ if (image_info->visual->type != GDK_VISUAL_DIRECT_COLOR && image_info->visual == gdk_visual_get_system ()) - image_info->cmap = gdk_colormap_get_system (); + image_info->cmap = gdk_colormap_ref (gdk_colormap_get_system ()); else { image_info->cmap = gdk_colormap_new (image_info->visual, FALSE); image_info->cmap_alloced = TRUE; } } + } - image_info->bitmap = (image_info->visual->depth == 1); + image_info->bitmap = (image_info->visual->depth == 1); /* Try to allocate as few possible shared images */ - for (i=0; i < G_N_ELEMENTS (possible_n_images); i++) + for (i=0; i < G_N_ELEMENTS (possible_n_images); i++) + { + if (gdk_rgb_allocate_images (image_info, possible_n_images[i], TRUE)) { - if (gdk_rgb_allocate_images (possible_n_images[i], TRUE)) - { - image_info->n_images = possible_n_images[i]; - break; - } + image_info->n_images = possible_n_images[i]; + break; } + } - /* If that fails, just allocate N_REGIONS normal images */ - if (i == G_N_ELEMENTS (possible_n_images)) - { - gdk_rgb_allocate_images (N_REGIONS, FALSE); - image_info->n_images = N_REGIONS; - } + /* If that fails, just allocate N_REGIONS normal images */ + if (i == G_N_ELEMENTS (possible_n_images)) + { + gdk_rgb_allocate_images (image_info, N_REGIONS, FALSE); + image_info->n_images = N_REGIONS; + } - image_info->bpp = image_info->static_image[0]->bpp; + image_info->bpp = image_info->static_image[0]->bpp; - image_info->static_image_idx = 0; + image_info->static_image_idx = 0; - image_info->horiz_y = REGION_HEIGHT; - image_info->vert_x = REGION_WIDTH; - image_info->tile_x = REGION_WIDTH; - image_info->tile_y1 = image_info->tile_y2 = REGION_HEIGHT; + image_info->horiz_y = REGION_HEIGHT; + image_info->vert_x = REGION_WIDTH; + image_info->tile_x = REGION_WIDTH; + image_info->tile_y1 = image_info->tile_y2 = REGION_HEIGHT; - gdk_rgb_select_conv (image_info->static_image[0]); - } + gdk_rgb_select_conv (image_info, image_info->static_image[0]); + + if (!gdk_rgb_quark) + gdk_rgb_quark = g_quark_from_static_string (gdk_rgb_key); + + g_object_set_qdata_full (G_OBJECT (image_info->cmap), gdk_rgb_quark, + image_info, (GDestroyNotify)gdk_rgb_free_info); + return image_info; } -/* convert an rgb value into an X pixel code */ -gulong -gdk_rgb_xpixel_from_rgb (guint32 rgb) +void +gdk_rgb_init (void) +{ + static const gint byte_order[1] = { 1 }; + + /* check endian sanity */ +#if G_BYTE_ORDER == G_BIG_ENDIAN + if (((char *)byte_order)[0] == 1) + g_error ("gdk_rgb_init: compiled for big endian, but this is a little endian machine.\n\n"); +#else + if (((char *)byte_order)[0] != 1) + g_error ("gdk_rgb_init: compiled for little endian, but this is a big endian machine.\n\n"); +#endif +} + +static GdkRgbInfo * +gdk_rgb_get_info_from_colormap (GdkColormap *cmap) +{ + GdkRgbInfo *image_info; + + if (!gdk_rgb_quark) + gdk_rgb_quark = g_quark_from_static_string (gdk_rgb_key); + + image_info = g_object_get_qdata (G_OBJECT (cmap), gdk_rgb_quark); + if (!image_info) + image_info = gdk_rgb_create_info (gdk_colormap_get_visual (cmap), cmap); + + return image_info; +} + +static gulong +gdk_rgb_xpixel_from_rgb_internal (GdkColormap *colormap, + guint16 r, guint16 g, guint16 b) { gulong pixel = 0; + GdkRgbInfo *image_info = gdk_rgb_get_info_from_colormap (colormap); + if (image_info->bitmap) { - return ((rgb & 0xff0000) >> 16) + - ((rgb & 0xff00) >> 7) + - (rgb & 0xff) > 510; + return (r + (g << 1) + b) > 131070; } else if (image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR) - pixel = image_info->colorcube[((rgb & 0xf00000) >> 12) | - ((rgb & 0xf000) >> 8) | - ((rgb & 0xf0) >> 4)]; + pixel = image_info->colorcube[((r & 0xf000) >> 4) | + ((g & 0xf000) >> 8) | + ((b & 0xf000) >> 12)]; else if (image_info->visual->depth < 8 && image_info->visual->type == GDK_VISUAL_STATIC_COLOR) { - pixel = image_info->colorcube_d[((rgb & 0x800000) >> 17) | - ((rgb & 0x8000) >> 12) | - ((rgb & 0x80) >> 7)]; + pixel = image_info->colorcube_d[((r & 0x8000) >> 9) | + ((g & 0x8000) >> 12) | + ((b & 0x8000) >> 15)]; } else if (image_info->visual->type == GDK_VISUAL_TRUE_COLOR || image_info->visual->type == GDK_VISUAL_DIRECT_COLOR) @@ -773,29 +873,32 @@ gdk_rgb_xpixel_from_rgb (guint32 rgb) image_info->visual->blue_prec); #endif - pixel = (((((rgb & 0xff0000) >> 16) >> - (8 - image_info->visual->red_prec)) << - image_info->visual->red_shift) + - ((((rgb & 0xff00) >> 8) >> - (8 - image_info->visual->green_prec)) << - image_info->visual->green_shift) + - (((rgb & 0xff) >> - (8 - image_info->visual->blue_prec)) << - image_info->visual->blue_shift)); + pixel = (((r >> (16 - image_info->visual->red_prec)) << image_info->visual->red_shift) + + ((g >> (16 - image_info->visual->green_prec)) << image_info->visual->green_shift) + + ((b >> (16 - image_info->visual->blue_prec)) << image_info->visual->blue_shift)); } else if (image_info->visual->type == GDK_VISUAL_STATIC_GRAY || image_info->visual->type == GDK_VISUAL_GRAYSCALE) { - int gray = ((rgb & 0xff0000) >> 16) + - ((rgb & 0xff00) >> 7) + - (rgb & 0xff); - - return gray >> (10 - image_info->visual->depth); + int gray = r + g * 2 + b; + return gray >> (18 - image_info->visual->depth); } return pixel; } +/* convert an rgb value into an X pixel code */ +gulong +gdk_rgb_xpixel_from_rgb (guint32 rgb) +{ + guint32 r = rgb & 0xff0000; + guint32 g = rgb & 0xff00; + guint32 b = rgb & 0xff; + + return gdk_rgb_xpixel_from_rgb_internal (gdk_rgb_get_colormap(), + (r >> 8) + (r >> 16), g + (g >> 8), b + (b << 8)); +} + void gdk_rgb_gc_set_foreground (GdkGC *gc, guint32 rgb) { @@ -814,13 +917,20 @@ gdk_rgb_gc_set_background (GdkGC *gc, guint32 rgb) gdk_gc_set_background (gc, &color); } +void +gdk_rgb_find_color (GdkColormap *colormap, GdkColor *color) +{ + color->pixel = gdk_rgb_xpixel_from_rgb_internal (colormap, + color->red, color->green, color->blue); +} + #if G_BYTE_ORDER == G_LITTLE_ENDIAN #define HAIRY_CONVERT_8 #endif #ifdef HAIRY_CONVERT_8 static void -gdk_rgb_convert_8 (GdkImage *image, +gdk_rgb_convert_8 (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -896,7 +1006,7 @@ gdk_rgb_convert_8 (GdkImage *image, } #else static void -gdk_rgb_convert_8 (GdkImage *image, +gdk_rgb_convert_8 (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1112,7 +1222,7 @@ gdk_rgb_preprocess_dm_565 (void) } static void -gdk_rgb_convert_8_d666 (GdkImage *image, +gdk_rgb_convert_8_d666 (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1152,7 +1262,7 @@ gdk_rgb_convert_8_d666 (GdkImage *image, } static void -gdk_rgb_convert_8_d (GdkImage *image, +gdk_rgb_convert_8_d (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, @@ -1197,7 +1307,7 @@ gdk_rgb_convert_8_d (GdkImage *image, } static void -gdk_rgb_convert_8_indexed (GdkImage *image, +gdk_rgb_convert_8_indexed (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1208,8 +1318,9 @@ gdk_rgb_convert_8_indexed (GdkImage *image, guchar *bptr, *bp2; guchar c; guchar *lut; + GdkRgbCmapInfo *cmap_info = gdk_rgb_cmap_get_info (cmap, image_info); - lut = cmap->lut; + lut = cmap_info->lut; bptr = buf; bpl = image->bpl; obuf = ((guchar *)image->mem) + y0 * bpl + x0; @@ -1229,7 +1340,7 @@ gdk_rgb_convert_8_indexed (GdkImage *image, } static void -gdk_rgb_convert_gray8 (GdkImage *image, +gdk_rgb_convert_gray8 (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1261,7 +1372,7 @@ gdk_rgb_convert_gray8 (GdkImage *image, } static void -gdk_rgb_convert_gray8_gray (GdkImage *image, +gdk_rgb_convert_gray8_gray (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1296,7 +1407,7 @@ gdk_rgb_convert_gray8_gray (GdkImage *image, words (i.e. 4 24-bit pixels), does a lot of shifting and masking, then writes 2 words. */ static void -gdk_rgb_convert_565 (GdkImage *image, +gdk_rgb_convert_565 (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1393,7 +1504,7 @@ gdk_rgb_convert_565 (GdkImage *image, shifting and masking, then writes 2 words. */ static void -gdk_rgb_convert_565 (GdkImage *image, +gdk_rgb_convert_565 (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1427,7 +1538,7 @@ gdk_rgb_convert_565 (GdkImage *image, #ifdef HAIRY_CONVERT_565 static void -gdk_rgb_convert_565_gray (GdkImage *image, +gdk_rgb_convert_565_gray (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1495,7 +1606,7 @@ gdk_rgb_convert_565_gray (GdkImage *image, } #else static void -gdk_rgb_convert_565_gray (GdkImage *image, +gdk_rgb_convert_565_gray (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1526,7 +1637,7 @@ gdk_rgb_convert_565_gray (GdkImage *image, #endif static void -gdk_rgb_convert_565_br (GdkImage *image, +gdk_rgb_convert_565_br (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1565,7 +1676,7 @@ gdk_rgb_convert_565_br (GdkImage *image, in this mode. */ #ifdef HAIRY_CONVERT_565 static void -gdk_rgb_convert_565_d (GdkImage *image, +gdk_rgb_convert_565_d (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1690,7 +1801,7 @@ gdk_rgb_convert_565_d (GdkImage *image, } #else static void -gdk_rgb_convert_565_d (GdkImage *image, +gdk_rgb_convert_565_d (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1735,7 +1846,7 @@ gdk_rgb_convert_565_d (GdkImage *image, #endif static void -gdk_rgb_convert_555 (GdkImage *image, +gdk_rgb_convert_555 (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1767,7 +1878,7 @@ gdk_rgb_convert_555 (GdkImage *image, } static void -gdk_rgb_convert_555_br (GdkImage *image, +gdk_rgb_convert_555_br (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1803,7 +1914,7 @@ gdk_rgb_convert_555_br (GdkImage *image, } static void -gdk_rgb_convert_888_msb (GdkImage *image, +gdk_rgb_convert_888_msb (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1831,7 +1942,7 @@ gdk_rgb_convert_888_msb (GdkImage *image, #ifdef HAIRY_CONVERT_888 static void -gdk_rgb_convert_888_lsb (GdkImage *image, +gdk_rgb_convert_888_lsb (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1905,7 +2016,7 @@ gdk_rgb_convert_888_lsb (GdkImage *image, } #else static void -gdk_rgb_convert_888_lsb (GdkImage *image, +gdk_rgb_convert_888_lsb (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1941,7 +2052,7 @@ gdk_rgb_convert_888_lsb (GdkImage *image, /* convert 24-bit packed to 32-bit unpacked */ /* todo: optimize this */ static void -gdk_rgb_convert_0888 (GdkImage *image, +gdk_rgb_convert_0888 (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -1972,7 +2083,7 @@ gdk_rgb_convert_0888 (GdkImage *image, } static void -gdk_rgb_convert_0888_br (GdkImage *image, +gdk_rgb_convert_0888_br (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -2003,7 +2114,7 @@ gdk_rgb_convert_0888_br (GdkImage *image, } static void -gdk_rgb_convert_8880_br (GdkImage *image, +gdk_rgb_convert_8880_br (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -2036,7 +2147,7 @@ gdk_rgb_convert_8880_br (GdkImage *image, /* Generic truecolor/directcolor conversion function. Slow, but these are oddball modes. */ static void -gdk_rgb_convert_truecolor_lsb (GdkImage *image, +gdk_rgb_convert_truecolor_lsb (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, @@ -2089,7 +2200,7 @@ gdk_rgb_convert_truecolor_lsb (GdkImage *image, } static void -gdk_rgb_convert_truecolor_lsb_d (GdkImage *image, +gdk_rgb_convert_truecolor_lsb_d (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, @@ -2153,7 +2264,7 @@ gdk_rgb_convert_truecolor_lsb_d (GdkImage *image, } static void -gdk_rgb_convert_truecolor_msb (GdkImage *image, +gdk_rgb_convert_truecolor_msb (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, @@ -2206,7 +2317,7 @@ gdk_rgb_convert_truecolor_msb (GdkImage *image, } static void -gdk_rgb_convert_truecolor_msb_d (GdkImage *image, +gdk_rgb_convert_truecolor_msb_d (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, @@ -2271,7 +2382,7 @@ gdk_rgb_convert_truecolor_msb_d (GdkImage *image, /* This actually works for depths from 3 to 7 */ static void -gdk_rgb_convert_4 (GdkImage *image, +gdk_rgb_convert_4 (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, @@ -2312,7 +2423,7 @@ gdk_rgb_convert_4 (GdkImage *image, /* This actually works for depths from 3 to 7 */ static void -gdk_rgb_convert_gray4 (GdkImage *image, +gdk_rgb_convert_gray4 (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -2346,7 +2457,7 @@ gdk_rgb_convert_gray4 (GdkImage *image, } static void -gdk_rgb_convert_gray4_pack (GdkImage *image, +gdk_rgb_convert_gray4_pack (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -2396,10 +2507,10 @@ gdk_rgb_convert_gray4_pack (GdkImage *image, /* This actually works for depths from 3 to 7 */ static void -gdk_rgb_convert_gray4_d (GdkImage *image, - gint x0, gint y0, gint width, gint height, - guchar *buf, int rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) +gdk_rgb_convert_gray4_d (GdkRgbInfo *image_info, GdkImage *image, + gint x0, gint y0, gint width, gint height, + guchar *buf, int rowstride, + gint x_align, gint y_align, GdkRgbCmap *cmap) { int x, y; gint bpl; @@ -2436,7 +2547,7 @@ gdk_rgb_convert_gray4_d (GdkImage *image, } static void -gdk_rgb_convert_gray4_d_pack (GdkImage *image, +gdk_rgb_convert_gray4_d_pack (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) @@ -2495,7 +2606,7 @@ gdk_rgb_convert_gray4_d_pack (GdkImage *image, } static void -gdk_rgb_convert_1 (GdkImage *image, +gdk_rgb_convert_1 (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, @@ -2541,7 +2652,7 @@ gdk_rgb_convert_1 (GdkImage *image, /* Returns a pointer to the stage buffer. */ static guchar * -gdk_rgb_ensure_stage (void) +gdk_rgb_ensure_stage (GdkRgbInfo *image_info) { if (image_info->stage_buf == NULL) image_info->stage_buf = g_malloc (REGION_HEIGHT * STAGE_ROWSTRIDE); @@ -2550,14 +2661,15 @@ gdk_rgb_ensure_stage (void) /* This is slow. Speed me up, please. */ static void -gdk_rgb_32_to_stage (guchar *buf, gint rowstride, gint width, gint height) +gdk_rgb_32_to_stage (GdkRgbInfo *image_info, + guchar *buf, gint rowstride, gint width, gint height) { gint x, y; guchar *pi_start, *po_start; guchar *pi, *po; pi_start = buf; - po_start = gdk_rgb_ensure_stage (); + po_start = gdk_rgb_ensure_stage (image_info); for (y = 0; y < height; y++) { pi = pi_start; @@ -2577,14 +2689,14 @@ gdk_rgb_32_to_stage (guchar *buf, gint rowstride, gint width, gint height) /* Generic 32bit RGB conversion function - convert to 24bit packed, then go from there. */ static void -gdk_rgb_convert_32_generic (GdkImage *image, +gdk_rgb_convert_32_generic (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, gint rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) { - gdk_rgb_32_to_stage (buf, rowstride, width, height); + gdk_rgb_32_to_stage (image_info, buf, rowstride, width, height); - (*image_info->conv) (image, x0, y0, width, height, + (*image_info->conv) (image_info, image, x0, y0, width, height, image_info->stage_buf, STAGE_ROWSTRIDE, x_align, y_align, cmap); } @@ -2592,21 +2704,22 @@ gdk_rgb_convert_32_generic (GdkImage *image, /* Generic 32bit RGB conversion function - convert to 24bit packed, then go from there. */ static void -gdk_rgb_convert_32_generic_d (GdkImage *image, +gdk_rgb_convert_32_generic_d (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, gint rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) { - gdk_rgb_32_to_stage (buf, rowstride, width, height); + gdk_rgb_32_to_stage (image_info, buf, rowstride, width, height); - (*image_info->conv_d) (image, x0, y0, width, height, + (*image_info->conv_d) (image_info, image, x0, y0, width, height, image_info->stage_buf, STAGE_ROWSTRIDE, x_align, y_align, cmap); } /* This is slow. Speed me up, please. */ static void -gdk_rgb_gray_to_stage (guchar *buf, gint rowstride, gint width, gint height) +gdk_rgb_gray_to_stage (GdkRgbInfo *image_info, + guchar *buf, gint rowstride, gint width, gint height) { gint x, y; guchar *pi_start, *po_start; @@ -2614,7 +2727,7 @@ gdk_rgb_gray_to_stage (guchar *buf, gint rowstride, gint width, gint height) guchar gray; pi_start = buf; - po_start = gdk_rgb_ensure_stage (); + po_start = gdk_rgb_ensure_stage (image_info); for (y = 0; y < height; y++) { pi = pi_start; @@ -2634,51 +2747,51 @@ gdk_rgb_gray_to_stage (guchar *buf, gint rowstride, gint width, gint height) /* Generic gray conversion function - convert to 24bit packed, then go from there. */ static void -gdk_rgb_convert_gray_generic (GdkImage *image, +gdk_rgb_convert_gray_generic (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, gint rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) { - gdk_rgb_gray_to_stage (buf, rowstride, width, height); + gdk_rgb_gray_to_stage (image_info, buf, rowstride, width, height); - (*image_info->conv) (image, x0, y0, width, height, + (*image_info->conv) (image_info, image, x0, y0, width, height, image_info->stage_buf, STAGE_ROWSTRIDE, x_align, y_align, cmap); } static void -gdk_rgb_convert_gray_generic_d (GdkImage *image, +gdk_rgb_convert_gray_generic_d (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, gint rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) { - gdk_rgb_gray_to_stage (buf, rowstride, width, height); + gdk_rgb_gray_to_stage (image_info, buf, rowstride, width, height); - (*image_info->conv_d) (image, x0, y0, width, height, + (*image_info->conv_d) (image_info, image, x0, y0, width, height, image_info->stage_buf, STAGE_ROWSTRIDE, x_align, y_align, cmap); } /* Render grayscale using indexed method. */ static void -gdk_rgb_convert_gray_cmap (GdkImage *image, +gdk_rgb_convert_gray_cmap (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, gint rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) { - (*image_info->conv_indexed) (image, x0, y0, width, height, + (*image_info->conv_indexed) (image_info, image, x0, y0, width, height, buf, rowstride, x_align, y_align, image_info->gray_cmap); } #if 0 static void -gdk_rgb_convert_gray_cmap_d (GdkImage *image, - gint x0, gint y0, gint width, gint height, - guchar *buf, gint rowstride, - gint x_align, gint y_align, GdkRgbCmap *cmap) +gdk_rgb_convert_gray_cmap_d (GdkRgbInfo *image_info, GdkImage *image, + gint x0, gint y0, gint width, gint height, + guchar *buf, gint rowstride, + gint x_align, gint y_align, GdkRgbCmap *cmap) { - (*image_info->conv_indexed_d) (image, x0, y0, width, height, + (*image_info->conv_indexed_d) (image_info, image, x0, y0, width, height, buf, rowstride, x_align, y_align, image_info->gray_cmap); } @@ -2686,7 +2799,8 @@ gdk_rgb_convert_gray_cmap_d (GdkImage *image, /* This is slow. Speed me up, please. */ static void -gdk_rgb_indexed_to_stage (guchar *buf, gint rowstride, gint width, gint height, +gdk_rgb_indexed_to_stage (GdkRgbInfo *image_info, + guchar *buf, gint rowstride, gint width, gint height, GdkRgbCmap *cmap) { gint x, y; @@ -2695,7 +2809,7 @@ gdk_rgb_indexed_to_stage (guchar *buf, gint rowstride, gint width, gint height, gint rgb; pi_start = buf; - po_start = gdk_rgb_ensure_stage (); + po_start = gdk_rgb_ensure_stage (image_info); for (y = 0; y < height; y++) { pi = pi_start; @@ -2715,28 +2829,28 @@ gdk_rgb_indexed_to_stage (guchar *buf, gint rowstride, gint width, gint height, /* Generic gray conversion function - convert to 24bit packed, then go from there. */ static void -gdk_rgb_convert_indexed_generic (GdkImage *image, +gdk_rgb_convert_indexed_generic (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, gint rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) { - gdk_rgb_indexed_to_stage (buf, rowstride, width, height, cmap); + gdk_rgb_indexed_to_stage (image_info, buf, rowstride, width, height, cmap); - (*image_info->conv) (image, x0, y0, width, height, + (*image_info->conv) (image_info, image, x0, y0, width, height, image_info->stage_buf, STAGE_ROWSTRIDE, x_align, y_align, cmap); } static void -gdk_rgb_convert_indexed_generic_d (GdkImage *image, +gdk_rgb_convert_indexed_generic_d (GdkRgbInfo *image_info, GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, gint rowstride, gint x_align, gint y_align, GdkRgbCmap *cmap) { - gdk_rgb_indexed_to_stage (buf, rowstride, width, height, cmap); + gdk_rgb_indexed_to_stage (image_info, buf, rowstride, width, height, cmap); - (*image_info->conv_d) (image, x0, y0, width, height, + (*image_info->conv_d) (image_info, image, x0, y0, width, height, image_info->stage_buf, STAGE_ROWSTRIDE, x_align, y_align, cmap); } @@ -2744,7 +2858,7 @@ gdk_rgb_convert_indexed_generic_d (GdkImage *image, /* Select a conversion function based on the visual and a representative image. */ static void -gdk_rgb_select_conv (GdkImage *image) +gdk_rgb_select_conv (GdkRgbInfo *image_info, GdkImage *image) { GdkByteOrder byte_order; gint depth, bpp, byterev; @@ -2943,7 +3057,7 @@ static gint sincelast; #undef NO_FLUSH static gint -gdk_rgb_alloc_scratch_image (void) +gdk_rgb_alloc_scratch_image (GdkRgbInfo *image_info) { if (image_info->static_image_idx == N_REGIONS) { @@ -2969,7 +3083,8 @@ gdk_rgb_alloc_scratch_image (void) } static GdkImage * -gdk_rgb_alloc_scratch (gint width, gint height, gint *x0, gint *y0) +gdk_rgb_alloc_scratch (GdkRgbInfo *image_info, + gint width, gint height, gint *x0, gint *y0) { GdkImage *image; gint idx; @@ -2978,7 +3093,7 @@ gdk_rgb_alloc_scratch (gint width, gint height, gint *x0, gint *y0) { if (height >= (REGION_HEIGHT >> 1)) { - idx = gdk_rgb_alloc_scratch_image (); + idx = gdk_rgb_alloc_scratch_image (image_info); *x0 = 0; *y0 = 0; } @@ -2986,7 +3101,7 @@ gdk_rgb_alloc_scratch (gint width, gint height, gint *x0, gint *y0) { if (height + image_info->horiz_y > REGION_HEIGHT) { - image_info->horiz_idx = gdk_rgb_alloc_scratch_image (); + image_info->horiz_idx = gdk_rgb_alloc_scratch_image (image_info); image_info->horiz_y = 0; } idx = image_info->horiz_idx; @@ -3001,7 +3116,7 @@ gdk_rgb_alloc_scratch (gint width, gint height, gint *x0, gint *y0) { if (width + image_info->vert_x > REGION_WIDTH) { - image_info->vert_idx = gdk_rgb_alloc_scratch_image (); + image_info->vert_idx = gdk_rgb_alloc_scratch_image (image_info); image_info->vert_x = 0; } idx = image_info->vert_idx; @@ -3020,7 +3135,7 @@ gdk_rgb_alloc_scratch (gint width, gint height, gint *x0, gint *y0) } if (height + image_info->tile_y1 > REGION_HEIGHT) { - image_info->tile_idx = gdk_rgb_alloc_scratch_image (); + image_info->tile_idx = gdk_rgb_alloc_scratch_image (image_info); image_info->tile_x = 0; image_info->tile_y1 = 0; image_info->tile_y2 = 0; @@ -3043,7 +3158,8 @@ gdk_rgb_alloc_scratch (gint width, gint height, gint *x0, gint *y0) } static void -gdk_draw_rgb_image_core (GdkDrawable *drawable, +gdk_draw_rgb_image_core (GdkRgbInfo *image_info, + GdkDrawable *drawable, GdkGC *gc, gint x, gint y, @@ -3085,9 +3201,9 @@ gdk_draw_rgb_image_core (GdkDrawable *drawable, width1 = MIN (width - x0, REGION_WIDTH); buf_ptr = buf + y0 * rowstride + x0 * pixstride; - image = gdk_rgb_alloc_scratch (width1, height1, &xs0, &ys0); + image = gdk_rgb_alloc_scratch (image_info, width1, height1, &xs0, &ys0); - conv (image, xs0, ys0, width1, height1, buf_ptr, rowstride, + conv (image_info, image, xs0, ys0, width1, height1, buf_ptr, rowstride, x + x0 + xdith, y + y0 + ydith, cmap); #ifndef DONT_ACTUALLY_DRAW @@ -3098,6 +3214,34 @@ gdk_draw_rgb_image_core (GdkDrawable *drawable, } } +static GdkRgbInfo * +gdk_rgb_get_info_from_drawable (GdkDrawable *drawable) +{ + GdkColormap *cmap = gdk_drawable_get_colormap (drawable); + + if (!cmap) + { + /* This guessing is required to maintain backward compatibility, + * but would otherwise be a bad thing + */ + + gint depth = gdk_drawable_get_depth (drawable); + GdkColormap *rgb_cmap = gdk_rgb_get_colormap(); + if (depth == gdk_colormap_get_visual (rgb_cmap)->depth) + cmap = rgb_cmap; + else + { + g_warning ("The gdk_draw_*_image require the drawable argument to\n" + "have a specified colormap. All windows have a colormap,\n" + "however, pixmaps only have colormap by default if they\n" + "were created with a non-NULL window argument. Otherwise\n" + "a colormap must be set on them with gdk_drawable_set_colormap"); + return NULL; + } + } + + return gdk_rgb_get_info_from_colormap (cmap); +} void gdk_draw_rgb_image (GdkDrawable *drawable, @@ -3110,13 +3254,17 @@ gdk_draw_rgb_image (GdkDrawable *drawable, guchar *rgb_buf, gint rowstride) { + GdkRgbInfo *image_info = gdk_rgb_get_info_from_drawable (drawable); + if (!image_info) + return; + if (dith == GDK_RGB_DITHER_NONE || (dith == GDK_RGB_DITHER_NORMAL && !image_info->dith_default)) - gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, + gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, rgb_buf, 3, rowstride, image_info->conv, NULL, 0, 0); else - gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, + gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, rgb_buf, 3, rowstride, image_info->conv_d, NULL, 0, 0); } @@ -3134,13 +3282,17 @@ gdk_draw_rgb_image_dithalign (GdkDrawable *drawable, gint xdith, gint ydith) { + GdkRgbInfo *image_info = gdk_rgb_get_info_from_drawable (drawable); + if (!image_info) + return; + if (dith == GDK_RGB_DITHER_NONE || (dith == GDK_RGB_DITHER_NORMAL && !image_info->dith_default)) - gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, + gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, rgb_buf, 3, rowstride, image_info->conv, NULL, xdith, ydith); else - gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, + gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, rgb_buf, 3, rowstride, image_info->conv_d, NULL, xdith, ydith); } @@ -3156,17 +3308,49 @@ gdk_draw_rgb_32_image (GdkDrawable *drawable, guchar *buf, gint rowstride) { + GdkRgbInfo *image_info = gdk_rgb_get_info_from_drawable (drawable); + if (!image_info) + return; + if (dith == GDK_RGB_DITHER_NONE || (dith == GDK_RGB_DITHER_NORMAL && !image_info->dith_default)) - gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, + gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, buf, 4, rowstride, image_info->conv_32, NULL, 0, 0); else - gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, + gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, buf, 4, rowstride, image_info->conv_32_d, NULL, 0, 0); } +void +gdk_draw_rgb_32_image_dithalign (GdkDrawable *drawable, + GdkGC *gc, + gint x, + gint y, + gint width, + gint height, + GdkRgbDither dith, + guchar *buf, + gint rowstride, + gint xdith, + gint ydith) +{ + GdkRgbInfo *image_info = gdk_rgb_get_info_from_drawable (drawable); + if (!image_info) + return; + + if (dith == GDK_RGB_DITHER_NONE || (dith == GDK_RGB_DITHER_NORMAL && + !image_info->dith_default)) + gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, + buf, 4, rowstride, + image_info->conv_32, NULL, xdith, ydith); + else + gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, + buf, 4, rowstride, + image_info->conv_32_d, NULL, xdith, ydith); +} + static void gdk_rgb_make_gray_cmap (GdkRgbInfo *info) { @@ -3189,6 +3373,10 @@ gdk_draw_gray_image (GdkDrawable *drawable, guchar *buf, gint rowstride) { + GdkRgbInfo *image_info = gdk_rgb_get_info_from_drawable (drawable); + if (!image_info) + return; + if (image_info->bpp == 1 && image_info->gray_cmap == NULL && (image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR || @@ -3197,46 +3385,95 @@ gdk_draw_gray_image (GdkDrawable *drawable, if (dith == GDK_RGB_DITHER_NONE || (dith == GDK_RGB_DITHER_NORMAL && !image_info->dith_default)) - gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, + gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, buf, 1, rowstride, image_info->conv_gray, NULL, 0, 0); else - gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, + gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, buf, 1, rowstride, image_info->conv_gray_d, NULL, 0, 0); } -GdkRgbCmap * -gdk_rgb_cmap_new (guint32 *colors, gint n_colors) +guchar lut[256]; /* for 8-bit modes */ + +static GdkRgbCmapInfo * +gdk_rgb_cmap_get_info (GdkRgbCmap *cmap, + GdkRgbInfo *image_info) { - GdkRgbCmap *cmap; + GSList *tmp_list; + GdkRgbCmapInfo *cmap_info; int i, j; guint32 rgb; + /* We only need a LUT for pseudo-color and grayscale cmaps */ + if (image_info->bpp != 1 || + !(image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR || + image_info->visual->type == GDK_VISUAL_GRAYSCALE)) + return NULL; + + tmp_list = cmap->info_list; + + while (tmp_list) + { + cmap_info = tmp_list->data; + if (cmap_info->image_info == image_info) + return cmap_info; + } + + cmap_info = g_new (GdkRgbCmapInfo, 1); + cmap_info->image_info = image_info; + cmap_info->cmap = cmap; + + for (i = 0; i < cmap->n_colors; i++) + { + rgb = cmap->colors[i]; + j = ((rgb & 0xf00000) >> 12) | + ((rgb & 0xf000) >> 8) | + ((rgb & 0xf0) >> 4); +#ifdef VERBOSE + g_print ("%d %x %x %d\n", i, j, image_info->colorcube[j]); +#endif + cmap_info->lut[i] = image_info->colorcube[j]; + } + + cmap->info_list = g_slist_prepend (cmap->info_list, cmap_info); + image_info->cmap_info_list = g_slist_prepend (image_info->cmap_info_list, cmap_info); + + return cmap_info; +} + +GdkRgbCmap * +gdk_rgb_cmap_new (guint32 *colors, gint n_colors) +{ + GdkRgbCmap *cmap; + g_return_val_if_fail (n_colors >= 0, NULL); g_return_val_if_fail (n_colors <= 256, NULL); + cmap = g_new (GdkRgbCmap, 1); + + cmap->n_colors = n_colors; memcpy (cmap->colors, colors, n_colors * sizeof(guint32)); - if (image_info->bpp == 1 && - (image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR || - image_info->visual->type == GDK_VISUAL_GRAYSCALE)) - for (i = 0; i < n_colors; i++) - { - rgb = colors[i]; - j = ((rgb & 0xf00000) >> 12) | - ((rgb & 0xf000) >> 8) | - ((rgb & 0xf0) >> 4); -#ifdef VERBOSE - g_print ("%d %x %x %d\n", i, j, image_info->colorcube[j]); -#endif - cmap->lut[i] = image_info->colorcube[j]; - } + + cmap->info_list = NULL; + return cmap; } void gdk_rgb_cmap_free (GdkRgbCmap *cmap) { + GSList *tmp_list; + + tmp_list = cmap->info_list; + while (tmp_list) + { + GdkRgbCmapInfo *cmap_info = tmp_list->data; + cmap_info->image_info->cmap_info_list = g_slist_remove (cmap_info->image_info->cmap_info_list, cmap_info); + g_free (cmap_info); + } + g_slist_free (cmap->info_list); + g_free (cmap); } @@ -3252,33 +3489,51 @@ gdk_draw_indexed_image (GdkDrawable *drawable, gint rowstride, GdkRgbCmap *cmap) { + GdkRgbInfo *image_info = gdk_rgb_get_info_from_drawable (drawable); + if (!image_info) + return; + if (dith == GDK_RGB_DITHER_NONE || (dith == GDK_RGB_DITHER_NORMAL && !image_info->dith_default)) - gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, + gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, buf, 1, rowstride, image_info->conv_indexed, cmap, 0, 0); else - gdk_draw_rgb_image_core (drawable, gc, x, y, width, height, + gdk_draw_rgb_image_core (image_info, drawable, gc, x, y, width, height, buf, 1, rowstride, image_info->conv_indexed_d, cmap, 0, 0); } gboolean -gdk_rgb_ditherable (void) +gdk_rgb_colormap_ditherable (GdkColormap *cmap) { + GdkRgbInfo *image_info = gdk_rgb_get_info_from_colormap (cmap); + return (image_info->conv != image_info->conv_d); } +gboolean +gdk_rgb_ditherable (void) +{ + return gdk_rgb_colormap_ditherable (gdk_rgb_get_colormap ()); +} + GdkColormap * -gdk_rgb_get_cmap (void) +gdk_rgb_get_colormap (void) { - gdk_rgb_init (); - return image_info->cmap; + static GdkColormap *cmap = NULL; + + if (!cmap) + { + GdkRgbInfo *image_info = gdk_rgb_create_info (gdk_rgb_choose_visual (), NULL); + cmap = image_info->cmap; + } + + return cmap; } GdkVisual * gdk_rgb_get_visual (void) { - gdk_rgb_init (); - return image_info->visual; + return gdk_colormap_get_visual (gdk_rgb_get_colormap ()); } diff --git a/gdk/gdkrgb.h b/gdk/gdkrgb.h index a1f9b25e7..bf9e6b0ca 100644 --- a/gdk/gdkrgb.h +++ b/gdk/gdkrgb.h @@ -37,20 +37,21 @@ typedef struct _GdkRgbCmap GdkRgbCmap; struct _GdkRgbCmap { guint32 colors[256]; - guchar lut[256]; /* for 8-bit modes */ -}; - -void -gdk_rgb_init (void); + gint n_colors; -gulong -gdk_rgb_xpixel_from_rgb (guint32 rgb); + /*< private >*/ + GSList *info_list; +}; -void -gdk_rgb_gc_set_foreground (GdkGC *gc, guint32 rgb); +void gdk_rgb_init (void); -void -gdk_rgb_gc_set_background (GdkGC *gc, guint32 rgb); +gulong gdk_rgb_xpixel_from_rgb (guint32 rgb); +void gdk_rgb_gc_set_foreground (GdkGC *gc, + guint32 rgb); +void gdk_rgb_gc_set_background (GdkGC *gc, + guint32 rgb); +void gdk_rgb_find_color (GdkColormap *colormap, + GdkColor *color); typedef enum { @@ -59,91 +60,80 @@ typedef enum GDK_RGB_DITHER_MAX } GdkRgbDither; -void -gdk_draw_rgb_image (GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - gint width, - gint height, - GdkRgbDither dith, - guchar *rgb_buf, - gint rowstride); - -void -gdk_draw_rgb_image_dithalign (GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - gint width, - gint height, - GdkRgbDither dith, - guchar *rgb_buf, - gint rowstride, - gint xdith, - gint ydith); - -void -gdk_draw_rgb_32_image (GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - gint width, - gint height, - GdkRgbDither dith, - guchar *buf, - gint rowstride); - -void -gdk_draw_gray_image (GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - gint width, - gint height, - GdkRgbDither dith, - guchar *buf, - gint rowstride); - -GdkRgbCmap * -gdk_rgb_cmap_new (guint32 *colors, gint n_colors); - -void -gdk_rgb_cmap_free (GdkRgbCmap *cmap); - -void -gdk_draw_indexed_image (GdkDrawable *drawable, - GdkGC *gc, - gint x, - gint y, - gint width, - gint height, - GdkRgbDither dith, - guchar *buf, - gint rowstride, - GdkRgbCmap *cmap); - +void gdk_draw_rgb_image (GdkDrawable *drawable, + GdkGC *gc, + gint x, + gint y, + gint width, + gint height, + GdkRgbDither dith, + guchar *rgb_buf, + gint rowstride); +void gdk_draw_rgb_image_dithalign (GdkDrawable *drawable, + GdkGC *gc, + gint x, + gint y, + gint width, + gint height, + GdkRgbDither dith, + guchar *rgb_buf, + gint rowstride, + gint xdith, + gint ydith); +void gdk_draw_rgb_32_image (GdkDrawable *drawable, + GdkGC *gc, + gint x, + gint y, + gint width, + gint height, + GdkRgbDither dith, + guchar *buf, + gint rowstride); +void gdk_draw_rgb_32_image_dithalign (GdkDrawable *drawable, + GdkGC *gc, + gint x, + gint y, + gint width, + gint height, + GdkRgbDither dith, + guchar *buf, + gint rowstride, + gint xdith, + gint ydith); +void gdk_draw_gray_image (GdkDrawable *drawable, + GdkGC *gc, + gint x, + gint y, + gint width, + gint height, + GdkRgbDither dith, + guchar *buf, + gint rowstride); +void gdk_draw_indexed_image (GdkDrawable *drawable, + GdkGC *gc, + gint x, + gint y, + gint width, + gint height, + GdkRgbDither dith, + guchar *buf, + gint rowstride, + GdkRgbCmap *cmap); +GdkRgbCmap *gdk_rgb_cmap_new (guint32 *colors, + gint n_colors); +void gdk_rgb_cmap_free (GdkRgbCmap *cmap); /* Below are some functions which are primarily useful for debugging and experimentation. */ -gboolean -gdk_rgb_ditherable (void); - -void -gdk_rgb_set_verbose (gboolean verbose); +gboolean gdk_rgb_ditherable (void); +void gdk_rgb_set_verbose (gboolean verbose); /* experimental colormap stuff */ -void -gdk_rgb_set_install (gboolean install); - -void -gdk_rgb_set_min_colors (gint min_colors); - -GdkColormap * -gdk_rgb_get_cmap (void); +void gdk_rgb_set_install (gboolean install); +void gdk_rgb_set_min_colors (gint min_colors); -GdkVisual * -gdk_rgb_get_visual (void); +GdkColormap *gdk_rgb_get_colormap (void); +GdkVisual * gdk_rgb_get_visual (void); #ifdef __cplusplus } diff --git a/gdk/x11/gdkgc-x11.c b/gdk/x11/gdkgc-x11.c index 6ba305cb7..db8ba0e7d 100644 --- a/gdk/x11/gdkgc-x11.c +++ b/gdk/x11/gdkgc-x11.c @@ -1,7 +1,35 @@ +/* GDK - The GIMP Drawing Kit + * 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. + */ + +/* + * 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/. + */ + #include "gdkgc.h" #include "gdkx.h" #include "gdkregion-generic.h" +#include <string.h> + typedef enum { GDK_GC_DIRTY_CLIP = 1 << 0, GDK_GC_DIRTY_TS = 1 << 1 diff --git a/gdk/x11/gdkinput-x11.c b/gdk/x11/gdkinput-x11.c index 2709c7bd7..1e1c501e9 100644 --- a/gdk/x11/gdkinput-x11.c +++ b/gdk/x11/gdkinput-x11.c @@ -28,6 +28,8 @@ #include "gdkinternals.h" #include "gdkx.h" +#include <string.h> + /* Forward declarations */ static GdkDevicePrivate *gdk_input_device_new(XDeviceInfo *device, gint include_core); diff --git a/gdk/x11/gdkpixmap-x11.c b/gdk/x11/gdkpixmap-x11.c index b8ee30872..9bef142f3 100644 --- a/gdk/x11/gdkpixmap-x11.c +++ b/gdk/x11/gdkpixmap-x11.c @@ -268,574 +268,6 @@ gdk_pixmap_create_from_data (GdkWindow *window, return pixmap; } -static gint -gdk_pixmap_seek_string (FILE *infile, - const gchar *str, - gint skip_comments) -{ - char instr[1024]; - - while (1) - { - if (fscanf (infile, "%1023s", instr) != 1) - return FALSE; - - if (skip_comments == TRUE && strcmp (instr, "/*") == 0) - { - do - { - if (fscanf (infile, "%1023s", instr) != 1) - return FALSE; - } - while (strcmp (instr, "*/") != 0); - } - else if (strcmp (instr, str) == 0) - return TRUE; - } -} - -static gint -gdk_pixmap_seek_char (FILE *infile, - gchar c) -{ - gint b, oldb; - - while ((b = getc(infile)) != EOF) - { - if (c != b && b == '/') - { - b = getc (infile); - if (b == EOF) - return FALSE; - else if (b == '*') /* we have a comment */ - { - b = -1; - do - { - oldb = b; - b = getc (infile); - if (b == EOF) - return FALSE; - } - while (!(oldb == '*' && b == '/')); - } - } - else if (c == b) - return TRUE; - } - return FALSE; -} - -static gint -gdk_pixmap_read_string (FILE *infile, - gchar **buffer, - guint *buffer_size) -{ - gint c; - guint cnt = 0, bufsiz, ret = FALSE; - gchar *buf; - - buf = *buffer; - bufsiz = *buffer_size; - if (buf == NULL) - { - bufsiz = 10 * sizeof (gchar); - buf = g_new(gchar, bufsiz); - } - - do - c = getc (infile); - while (c != EOF && c != '"'); - - if (c != '"') - goto out; - - while ((c = getc(infile)) != EOF) - { - if (cnt == bufsiz) - { - guint new_size = bufsiz * 2; - if (new_size > bufsiz) - bufsiz = new_size; - else - goto out; - - buf = (gchar *) g_realloc (buf, bufsiz); - buf[bufsiz-1] = '\0'; - } - - if (c != '"') - buf[cnt++] = c; - else - { - buf[cnt] = 0; - ret = TRUE; - break; - } - } - - out: - buf[bufsiz-1] = '\0'; /* ensure null termination for errors */ - *buffer = buf; - *buffer_size = bufsiz; - return ret; -} - -static gchar* -gdk_pixmap_skip_whitespaces (gchar *buffer) -{ - gint32 index = 0; - - while (buffer[index] != 0 && (buffer[index] == 0x20 || buffer[index] == 0x09)) - index++; - - return &buffer[index]; -} - -static gchar* -gdk_pixmap_skip_string (gchar *buffer) -{ - gint32 index = 0; - - while (buffer[index] != 0 && buffer[index] != 0x20 && buffer[index] != 0x09) - index++; - - return &buffer[index]; -} - -/* Xlib crashed ince at a color name lengths around 125 */ -#define MAX_COLOR_LEN 120 - -static gchar* -gdk_pixmap_extract_color (gchar *buffer) -{ - gint counter, numnames; - gchar *ptr = NULL, ch, temp[128]; - gchar color[MAX_COLOR_LEN], *retcol; - gint space; - - counter = 0; - while (ptr == NULL) - { - if (buffer[counter] == 'c') - { - ch = buffer[counter + 1]; - if (ch == 0x20 || ch == 0x09) - ptr = &buffer[counter + 1]; - } - else if (buffer[counter] == 0) - return NULL; - - counter++; - } - - ptr = gdk_pixmap_skip_whitespaces (ptr); - - if (ptr[0] == 0) - return NULL; - else if (ptr[0] == '#') - { - counter = 1; - while (ptr[counter] != 0 && - ((ptr[counter] >= '0' && ptr[counter] <= '9') || - (ptr[counter] >= 'a' && ptr[counter] <= 'f') || - (ptr[counter] >= 'A' && ptr[counter] <= 'F'))) - counter++; - - retcol = g_new (gchar, counter+1); - strncpy (retcol, ptr, counter); - - retcol[counter] = 0; - - return retcol; - } - - color[0] = 0; - numnames = 0; - - space = MAX_COLOR_LEN - 1; - while (space > 0) - { - sscanf (ptr, "%127s", temp); - - if (((gint)ptr[0] == 0) || - (strcmp ("s", temp) == 0) || (strcmp ("m", temp) == 0) || - (strcmp ("g", temp) == 0) || (strcmp ("g4", temp) == 0)) - { - break; - } - else - { - if (numnames > 0) - { - space -= 1; - strcat (color, " "); - } - strncat (color, temp, space); - space -= MIN (space, strlen (temp)); - ptr = gdk_pixmap_skip_string (ptr); - ptr = gdk_pixmap_skip_whitespaces (ptr); - numnames++; - } - } - - retcol = g_strdup (color); - return retcol; -} - - -enum buffer_op -{ - op_header, - op_cmap, - op_body -}; - - -static void -gdk_xpm_destroy_notify (gpointer data) -{ - _GdkPixmapInfo *info = (_GdkPixmapInfo *)data; - GdkColor color; - int i; - - for (i=0; i<info->ncolors; i++) - { - color.pixel = info->pixels[i]; - gdk_colormap_free_colors (info->colormap, &color, 1); - } - - gdk_colormap_unref (info->colormap); - g_free (info); -} - -static GdkPixmap * -_gdk_pixmap_create_from_xpm (GdkWindow *window, - GdkColormap *colormap, - GdkBitmap **mask, - GdkColor *transparent_color, - gchar * (*get_buf) (enum buffer_op op, - gpointer handle), - gpointer handle) -{ - GdkPixmap *pixmap = NULL; - GdkImage *image = NULL; - GdkVisual *visual; - GdkGC *gc = NULL; - GdkColor tmp_color; - gint width, height, num_cols, cpp, n, ns, cnt, xcnt, ycnt, wbytes; - gchar *buffer, pixel_str[32]; - gchar *name_buf; - _GdkPixmapColor *color = NULL, *fallbackcolor = NULL; - _GdkPixmapColor *colors = NULL; - gulong index; - GHashTable *color_hash = NULL; - _GdkPixmapInfo *color_info = NULL; - - if ((window == NULL) && (colormap == NULL)) - g_warning ("Creating pixmap from xpm with NULL window and colormap"); - - if (window == NULL) - window = gdk_parent_root; - - if (colormap == NULL) - { - colormap = gdk_drawable_get_colormap (window); - visual = gdk_drawable_get_visual (window); - } - else - visual = colormap->visual; - - buffer = (*get_buf) (op_header, handle); - if (buffer == NULL) - return NULL; - - sscanf (buffer,"%d %d %d %d", &width, &height, &num_cols, &cpp); - if (cpp >= 32) - { - g_warning ("Pixmap has more than 31 characters per color\n"); - return NULL; - } - - color_hash = g_hash_table_new (g_str_hash, g_str_equal); - - if (transparent_color == NULL) - { - gdk_color_white (colormap, &tmp_color); - transparent_color = &tmp_color; - } - - /* For pseudo-color and grayscale visuals, we have to remember - * the colors we allocated, so we can free them later. - */ - if ((visual->type == GDK_VISUAL_PSEUDO_COLOR) || - (visual->type == GDK_VISUAL_GRAYSCALE)) - { - color_info = g_malloc (sizeof (_GdkPixmapInfo) + - sizeof(gulong) * (num_cols - 1)); - color_info->ncolors = num_cols; - color_info->colormap = colormap; - gdk_colormap_ref (colormap); - } - - name_buf = g_new (gchar, num_cols * (cpp+1)); - colors = g_new (_GdkPixmapColor, num_cols); - - for (cnt = 0; cnt < num_cols; cnt++) - { - gchar *color_name; - - buffer = (*get_buf) (op_cmap, handle); - if (buffer == NULL) - goto error; - - color = &colors[cnt]; - color->color_string = &name_buf [cnt * (cpp + 1)]; - strncpy (color->color_string, buffer, cpp); - color->color_string[cpp] = 0; - buffer += strlen (color->color_string); - color->transparent = FALSE; - - color_name = gdk_pixmap_extract_color (buffer); - - if (color_name == NULL || g_strcasecmp (color_name, "None") == 0 || - gdk_color_parse (color_name, &color->color) == FALSE) - { - color->color = *transparent_color; - color->transparent = TRUE; - } - - g_free (color_name); - - /* FIXME: The remaining slowness appears to happen in this - function. */ - gdk_color_alloc (colormap, &color->color); - - if (color_info) - color_info->pixels[cnt] = color->color.pixel; - - g_hash_table_insert (color_hash, color->color_string, color); - if (cnt == 0) - fallbackcolor = color; - } - - index = 0; - image = gdk_image_new (GDK_IMAGE_FASTEST, visual, width, height); - - if (mask) - { - /* The pixmap mask is just a bits pattern. - * Color 0 is used for background and 1 for foreground. - * We don't care about the colormap, we just need 0 and 1. - */ - GdkColor mask_pattern; - - *mask = gdk_pixmap_new (window, width, height, 1); - gc = gdk_gc_new (*mask); - - mask_pattern.pixel = 0; - gdk_gc_set_foreground (gc, &mask_pattern); - gdk_draw_rectangle (*mask, gc, TRUE, 0, 0, -1, -1); - - mask_pattern.pixel = 1; - gdk_gc_set_foreground (gc, &mask_pattern); - } - - wbytes = width * cpp; - for (ycnt = 0; ycnt < height; ycnt++) - { - buffer = (*get_buf) (op_body, handle); - - /* FIXME: this slows things down a little - it could be - * integrated into the strncpy below, perhaps. OTOH, strlen - * is fast. - */ - if ((buffer == NULL) || strlen (buffer) < wbytes) - continue; - - for (n = 0, cnt = 0, xcnt = 0; n < wbytes; n += cpp, xcnt++) - { - strncpy (pixel_str, &buffer[n], cpp); - pixel_str[cpp] = 0; - ns = 0; - - color = g_hash_table_lookup (color_hash, pixel_str); - - if (!color) /* screwed up XPM file */ - color = fallbackcolor; - - gdk_image_put_pixel (image, xcnt, ycnt, color->color.pixel); - - if (mask && color->transparent) - { - if (cnt < xcnt) - gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt); - cnt = xcnt + 1; - } - } - - if (mask && (cnt < xcnt)) - gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt); - } - - error: - - if (mask) - gdk_gc_unref (gc); - - if (image != NULL) - { - pixmap = gdk_pixmap_new (window, width, height, visual->depth); - - if (color_info) - gdk_drawable_set_data (pixmap, "gdk-xpm", color_info, - gdk_xpm_destroy_notify); - - gc = gdk_gc_new (pixmap); - gdk_gc_set_foreground (gc, transparent_color); - gdk_draw_image (pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); - gdk_gc_unref (gc); - gdk_image_unref (image); - } - else if (color_info) - gdk_xpm_destroy_notify (color_info); - - if (color_hash != NULL) - g_hash_table_destroy (color_hash); - - if (colors != NULL) - g_free (colors); - - if (name_buf != NULL) - g_free (name_buf); - - return pixmap; -} - - -struct file_handle -{ - FILE *infile; - gchar *buffer; - guint buffer_size; -}; - - -static gchar * -file_buffer (enum buffer_op op, gpointer handle) -{ - struct file_handle *h = handle; - - switch (op) - { - case op_header: - if (gdk_pixmap_seek_string (h->infile, "XPM", FALSE) != TRUE) - break; - - if (gdk_pixmap_seek_char (h->infile,'{') != TRUE) - break; - /* Fall through to the next gdk_pixmap_seek_char. */ - - case op_cmap: - gdk_pixmap_seek_char (h->infile, '"'); - fseek (h->infile, -1, SEEK_CUR); - /* Fall through to the gdk_pixmap_read_string. */ - - case op_body: - gdk_pixmap_read_string (h->infile, &h->buffer, &h->buffer_size); - return h->buffer; - } - return 0; -} - - -GdkPixmap* -gdk_pixmap_colormap_create_from_xpm (GdkWindow *window, - GdkColormap *colormap, - GdkBitmap **mask, - GdkColor *transparent_color, - const gchar *filename) -{ - struct file_handle h; - GdkPixmap *pixmap = NULL; - - memset (&h, 0, sizeof (h)); - h.infile = fopen (filename, "rb"); - if (h.infile != NULL) - { - pixmap = _gdk_pixmap_create_from_xpm (window, colormap, mask, - transparent_color, - file_buffer, &h); - fclose (h.infile); - g_free (h.buffer); - } - - return pixmap; -} - -GdkPixmap* -gdk_pixmap_create_from_xpm (GdkWindow *window, - GdkBitmap **mask, - GdkColor *transparent_color, - const gchar *filename) -{ - return gdk_pixmap_colormap_create_from_xpm (window, NULL, mask, - transparent_color, filename); -} - - -struct mem_handle -{ - gchar **data; - int offset; -}; - - -static gchar * -mem_buffer (enum buffer_op op, gpointer handle) -{ - struct mem_handle *h = handle; - switch (op) - { - case op_header: - case op_cmap: - case op_body: - if (h->data[h->offset]) - return h->data[h->offset ++]; - } - return 0; -} - - -GdkPixmap* -gdk_pixmap_colormap_create_from_xpm_d (GdkWindow *window, - GdkColormap *colormap, - GdkBitmap **mask, - GdkColor *transparent_color, - gchar **data) -{ - struct mem_handle h; - GdkPixmap *pixmap = NULL; - - memset (&h, 0, sizeof (h)); - h.data = data; - pixmap = _gdk_pixmap_create_from_xpm (window, colormap, mask, - transparent_color, - mem_buffer, &h); - return pixmap; -} - - -GdkPixmap* -gdk_pixmap_create_from_xpm_d (GdkWindow *window, - GdkBitmap **mask, - GdkColor *transparent_color, - gchar **data) -{ - return gdk_pixmap_colormap_create_from_xpm_d (window, NULL, mask, - transparent_color, data); -} - GdkPixmap* gdk_pixmap_foreign_new (GdkNativeWindow anid) { diff --git a/gdk/x11/gdkpoly-generic.h b/gdk/x11/gdkpoly-generic.h deleted file mode 100644 index 660c689ad..000000000 --- a/gdk/x11/gdkpoly-generic.h +++ /dev/null @@ -1,291 +0,0 @@ -/* $TOG: poly.h /main/5 1998/02/06 17:47:27 kaleb $ */ -/************************************************************************ - -Copyright 1987, 1998 The Open Group - -All Rights Reserved. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ - -/* - * This file contains a few macros to help track - * the edge of a filled object. The object is assumed - * to be filled in scanline order, and thus the - * algorithm used is an extension of Bresenham's line - * drawing algorithm which assumes that y is always the - * major axis. - * Since these pieces of code are the same for any filled shape, - * it is more convenient to gather the library in one - * place, but since these pieces of code are also in - * the inner loops of output primitives, procedure call - * overhead is out of the question. - * See the author for a derivation if needed. - */ - - -/* - * In scan converting polygons, we want to choose those pixels - * which are inside the polygon. Thus, we add .5 to the starting - * x coordinate for both left and right edges. Now we choose the - * first pixel which is inside the pgon for the left edge and the - * first pixel which is outside the pgon for the right edge. - * Draw the left pixel, but not the right. - * - * How to add .5 to the starting x coordinate: - * If the edge is moving to the right, then subtract dy from the - * error term from the general form of the algorithm. - * If the edge is moving to the left, then add dy to the error term. - * - * The reason for the difference between edges moving to the left - * and edges moving to the right is simple: If an edge is moving - * to the right, then we want the algorithm to flip immediately. - * If it is moving to the left, then we don't want it to flip until - * we traverse an entire pixel. - */ -#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \ - int dx; /* local storage */ \ -\ - /* \ - * if the edge is horizontal, then it is ignored \ - * and assumed not to be processed. Otherwise, do this stuff. \ - */ \ - if ((dy) != 0) { \ - xStart = (x1); \ - dx = (x2) - xStart; \ - if (dx < 0) { \ - m = dx / (dy); \ - m1 = m - 1; \ - incr1 = -2 * dx + 2 * (dy) * m1; \ - incr2 = -2 * dx + 2 * (dy) * m; \ - d = 2 * m * (dy) - 2 * dx - 2 * (dy); \ - } else { \ - m = dx / (dy); \ - m1 = m + 1; \ - incr1 = 2 * dx - 2 * (dy) * m1; \ - incr2 = 2 * dx - 2 * (dy) * m; \ - d = -2 * m * (dy) + 2 * dx; \ - } \ - } \ -} - -#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \ - if (m1 > 0) { \ - if (d > 0) { \ - minval += m1; \ - d += incr1; \ - } \ - else { \ - minval += m; \ - d += incr2; \ - } \ - } else {\ - if (d >= 0) { \ - minval += m1; \ - d += incr1; \ - } \ - else { \ - minval += m; \ - d += incr2; \ - } \ - } \ -} - - -/* - * This structure contains all of the information needed - * to run the bresenham algorithm. - * The variables may be hardcoded into the declarations - * instead of using this structure to make use of - * register declarations. - */ -typedef struct { - int minor_axis; /* minor axis */ - int d; /* decision variable */ - int m, m1; /* slope and slope+1 */ - int incr1, incr2; /* error increments */ -} BRESINFO; - - -#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \ - BRESINITPGON(dmaj, min1, min2, bres.minor_axis, bres.d, \ - bres.m, bres.m1, bres.incr1, bres.incr2) - -#define BRESINCRPGONSTRUCT(bres) \ - BRESINCRPGON(bres.d, bres.minor_axis, bres.m, bres.m1, bres.incr1, bres.incr2) - - - -/* - * These are the data structures needed to scan - * convert regions. Two different scan conversion - * methods are available -- the even-odd method, and - * the winding number method. - * The even-odd rule states that a point is inside - * the polygon if a ray drawn from that point in any - * direction will pass through an odd number of - * path segments. - * By the winding number rule, a point is decided - * to be inside the polygon if a ray drawn from that - * point in any direction passes through a different - * number of clockwise and counter-clockwise path - * segments. - * - * These data structures are adapted somewhat from - * the algorithm in (Foley/Van Dam) for scan converting - * polygons. - * The basic algorithm is to start at the top (smallest y) - * of the polygon, stepping down to the bottom of - * the polygon by incrementing the y coordinate. We - * keep a list of edges which the current scanline crosses, - * sorted by x. This list is called the Active Edge Table (AET) - * As we change the y-coordinate, we update each entry in - * in the active edge table to reflect the edges new xcoord. - * This list must be sorted at each scanline in case - * two edges intersect. - * We also keep a data structure known as the Edge Table (ET), - * which keeps track of all the edges which the current - * scanline has not yet reached. The ET is basically a - * list of ScanLineList structures containing a list of - * edges which are entered at a given scanline. There is one - * ScanLineList per scanline at which an edge is entered. - * When we enter a new edge, we move it from the ET to the AET. - * - * From the AET, we can implement the even-odd rule as in - * (Foley/Van Dam). - * The winding number rule is a little trickier. We also - * keep the EdgeTableEntries in the AET linked by the - * nextWETE (winding EdgeTableEntry) link. This allows - * the edges to be linked just as before for updating - * purposes, but only uses the edges linked by the nextWETE - * link as edges representing spans of the polygon to - * drawn (as with the even-odd rule). - */ - -/* - * for the winding number rule - */ -#define CLOCKWISE 1 -#define COUNTERCLOCKWISE -1 - -typedef struct _EdgeTableEntry { - int ymax; /* ycoord at which we exit this edge. */ - BRESINFO bres; /* Bresenham info to run the edge */ - struct _EdgeTableEntry *next; /* next in the list */ - struct _EdgeTableEntry *back; /* for insertion sort */ - struct _EdgeTableEntry *nextWETE; /* for winding num rule */ - int ClockWise; /* flag for winding number rule */ -} EdgeTableEntry; - - -typedef struct _ScanLineList{ - int scanline; /* the scanline represented */ - EdgeTableEntry *edgelist; /* header node */ - struct _ScanLineList *next; /* next in the list */ -} ScanLineList; - - -typedef struct { - int ymax; /* ymax for the polygon */ - int ymin; /* ymin for the polygon */ - ScanLineList scanlines; /* header node */ -} EdgeTable; - - -/* - * Here is a struct to help with storage allocation - * so we can allocate a big chunk at a time, and then take - * pieces from this heap when we need to. - */ -#define SLLSPERBLOCK 25 - -typedef struct _ScanLineListBlock { - ScanLineList SLLs[SLLSPERBLOCK]; - struct _ScanLineListBlock *next; -} ScanLineListBlock; - - - -/* - * - * a few macros for the inner loops of the fill code where - * performance considerations don't allow a procedure call. - * - * Evaluate the given edge at the given scanline. - * If the edge has expired, then we leave it and fix up - * the active edge table; otherwise, we increment the - * x value to be ready for the next scanline. - * The winding number rule is in effect, so we must notify - * the caller when the edge has been removed so he - * can reorder the Winding Active Edge Table. - */ -#define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \ - if (pAET->ymax == y) { /* leaving this edge */ \ - pPrevAET->next = pAET->next; \ - pAET = pPrevAET->next; \ - fixWAET = 1; \ - if (pAET) \ - pAET->back = pPrevAET; \ - } \ - else { \ - BRESINCRPGONSTRUCT(pAET->bres); \ - pPrevAET = pAET; \ - pAET = pAET->next; \ - } \ -} - - -/* - * Evaluate the given edge at the given scanline. - * If the edge has expired, then we leave it and fix up - * the active edge table; otherwise, we increment the - * x value to be ready for the next scanline. - * The even-odd rule is in effect. - */ -#define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \ - if (pAET->ymax == y) { /* leaving this edge */ \ - pPrevAET->next = pAET->next; \ - pAET = pPrevAET->next; \ - if (pAET) \ - pAET->back = pPrevAET; \ - } \ - else { \ - BRESINCRPGONSTRUCT(pAET->bres); \ - pPrevAET = pAET; \ - pAET = pAET->next; \ - } \ -} diff --git a/gdk/x11/gdkpolyreg-generic.c b/gdk/x11/gdkpolyreg-generic.c deleted file mode 100644 index b98bd5641..000000000 --- a/gdk/x11/gdkpolyreg-generic.c +++ /dev/null @@ -1,616 +0,0 @@ -/* $TOG: PolyReg.c /main/15 1998/02/06 17:47:08 kaleb $ */ -/************************************************************************ - -Copyright 1987, 1998 The Open Group - -All Rights Reserved. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ -/* $XFree86: xc/lib/X11/PolyReg.c,v 1.4 1998/10/03 08:41:21 dawes Exp $ */ - -#define LARGE_COORDINATE 1000000 -#define SMALL_COORDINATE -LARGE_COORDINATE - -#include <gdkregion.h> -#include "gdkregion-generic.h" -#include "gdkpoly-generic.h" - -/* - * InsertEdgeInET - * - * Insert the given edge into the edge table. - * First we must find the correct bucket in the - * Edge table, then find the right slot in the - * bucket. Finally, we can insert it. - * - */ -static void -InsertEdgeInET(ET, ETE, scanline, SLLBlock, iSLLBlock) - EdgeTable *ET; - EdgeTableEntry *ETE; - int scanline; - ScanLineListBlock **SLLBlock; - int *iSLLBlock; -{ - EdgeTableEntry *start, *prev; - ScanLineList *pSLL, *pPrevSLL; - ScanLineListBlock *tmpSLLBlock; - - /* - * find the right bucket to put the edge into - */ - pPrevSLL = &ET->scanlines; - pSLL = pPrevSLL->next; - while (pSLL && (pSLL->scanline < scanline)) - { - pPrevSLL = pSLL; - pSLL = pSLL->next; - } - - /* - * reassign pSLL (pointer to ScanLineList) if necessary - */ - if ((!pSLL) || (pSLL->scanline > scanline)) - { - if (*iSLLBlock > SLLSPERBLOCK-1) - { - tmpSLLBlock = - (ScanLineListBlock *)g_malloc(sizeof(ScanLineListBlock)); - (*SLLBlock)->next = tmpSLLBlock; - tmpSLLBlock->next = (ScanLineListBlock *)NULL; - *SLLBlock = tmpSLLBlock; - *iSLLBlock = 0; - } - pSLL = &((*SLLBlock)->SLLs[(*iSLLBlock)++]); - - pSLL->next = pPrevSLL->next; - pSLL->edgelist = (EdgeTableEntry *)NULL; - pPrevSLL->next = pSLL; - } - pSLL->scanline = scanline; - - /* - * now insert the edge in the right bucket - */ - prev = (EdgeTableEntry *)NULL; - start = pSLL->edgelist; - while (start && (start->bres.minor_axis < ETE->bres.minor_axis)) - { - prev = start; - start = start->next; - } - ETE->next = start; - - if (prev) - prev->next = ETE; - else - pSLL->edgelist = ETE; -} - -/* - * CreateEdgeTable - * - * This routine creates the edge table for - * scan converting polygons. - * The Edge Table (ET) looks like: - * - * EdgeTable - * -------- - * | ymax | ScanLineLists - * |scanline|-->------------>-------------->... - * -------- |scanline| |scanline| - * |edgelist| |edgelist| - * --------- --------- - * | | - * | | - * V V - * list of ETEs list of ETEs - * - * where ETE is an EdgeTableEntry data structure, - * and there is one ScanLineList per scanline at - * which an edge is initially entered. - * - */ - -static void -CreateETandAET(count, pts, ET, AET, pETEs, pSLLBlock) - int count; - GdkPoint *pts; - EdgeTable *ET; - EdgeTableEntry *AET; - EdgeTableEntry *pETEs; - ScanLineListBlock *pSLLBlock; -{ - GdkPoint *top, *bottom; - GdkPoint *PrevPt, *CurrPt; - int iSLLBlock = 0; - int dy; - - if (count < 2) return; - - /* - * initialize the Active Edge Table - */ - AET->next = (EdgeTableEntry *)NULL; - AET->back = (EdgeTableEntry *)NULL; - AET->nextWETE = (EdgeTableEntry *)NULL; - AET->bres.minor_axis = SMALL_COORDINATE; - - /* - * initialize the Edge Table. - */ - ET->scanlines.next = (ScanLineList *)NULL; - ET->ymax = SMALL_COORDINATE; - ET->ymin = LARGE_COORDINATE; - pSLLBlock->next = (ScanLineListBlock *)NULL; - - PrevPt = &pts[count-1]; - - /* - * for each vertex in the array of points. - * In this loop we are dealing with two vertices at - * a time -- these make up one edge of the polygon. - */ - while (count--) - { - CurrPt = pts++; - - /* - * find out which point is above and which is below. - */ - if (PrevPt->y > CurrPt->y) - { - bottom = PrevPt, top = CurrPt; - pETEs->ClockWise = 0; - } - else - { - bottom = CurrPt, top = PrevPt; - pETEs->ClockWise = 1; - } - - /* - * don't add horizontal edges to the Edge table. - */ - if (bottom->y != top->y) - { - pETEs->ymax = bottom->y-1; /* -1 so we don't get last scanline */ - - /* - * initialize integer edge algorithm - */ - dy = bottom->y - top->y; - BRESINITPGONSTRUCT(dy, top->x, bottom->x, pETEs->bres); - - InsertEdgeInET(ET, pETEs, top->y, &pSLLBlock, &iSLLBlock); - - if (PrevPt->y > ET->ymax) - ET->ymax = PrevPt->y; - if (PrevPt->y < ET->ymin) - ET->ymin = PrevPt->y; - pETEs++; - } - - PrevPt = CurrPt; - } -} - -/* - * loadAET - * - * This routine moves EdgeTableEntries from the - * EdgeTable into the Active Edge Table, - * leaving them sorted by smaller x coordinate. - * - */ - -static void -loadAET(AET, ETEs) - EdgeTableEntry *AET, *ETEs; -{ - EdgeTableEntry *pPrevAET; - EdgeTableEntry *tmp; - - pPrevAET = AET; - AET = AET->next; - while (ETEs) - { - while (AET && (AET->bres.minor_axis < ETEs->bres.minor_axis)) - { - pPrevAET = AET; - AET = AET->next; - } - tmp = ETEs->next; - ETEs->next = AET; - if (AET) - AET->back = ETEs; - ETEs->back = pPrevAET; - pPrevAET->next = ETEs; - pPrevAET = ETEs; - - ETEs = tmp; - } -} - -/* - * computeWAET - * - * This routine links the AET by the - * nextWETE (winding EdgeTableEntry) link for - * use by the winding number rule. The final - * Active Edge Table (AET) might look something - * like: - * - * AET - * ---------- --------- --------- - * |ymax | |ymax | |ymax | - * | ... | |... | |... | - * |next |->|next |->|next |->... - * |nextWETE| |nextWETE| |nextWETE| - * --------- --------- ^-------- - * | | | - * V-------------------> V---> ... - * - */ -static void -computeWAET(AET) - EdgeTableEntry *AET; -{ - EdgeTableEntry *pWETE; - int inside = 1; - int isInside = 0; - - AET->nextWETE = (EdgeTableEntry *)NULL; - pWETE = AET; - AET = AET->next; - while (AET) - { - if (AET->ClockWise) - isInside++; - else - isInside--; - - if ((!inside && !isInside) || - ( inside && isInside)) - { - pWETE->nextWETE = AET; - pWETE = AET; - inside = !inside; - } - AET = AET->next; - } - pWETE->nextWETE = (EdgeTableEntry *)NULL; -} - -/* - * InsertionSort - * - * Just a simple insertion sort using - * pointers and back pointers to sort the Active - * Edge Table. - * - */ - -static int -InsertionSort(AET) - EdgeTableEntry *AET; -{ - EdgeTableEntry *pETEchase; - EdgeTableEntry *pETEinsert; - EdgeTableEntry *pETEchaseBackTMP; - int changed = 0; - - AET = AET->next; - while (AET) - { - pETEinsert = AET; - pETEchase = AET; - while (pETEchase->back->bres.minor_axis > AET->bres.minor_axis) - pETEchase = pETEchase->back; - - AET = AET->next; - if (pETEchase != pETEinsert) - { - pETEchaseBackTMP = pETEchase->back; - pETEinsert->back->next = AET; - if (AET) - AET->back = pETEinsert->back; - pETEinsert->next = pETEchase; - pETEchase->back->next = pETEinsert; - pETEchase->back = pETEinsert; - pETEinsert->back = pETEchaseBackTMP; - changed = 1; - } - } - return(changed); -} - -/* - * Clean up our act. - */ -static void -FreeStorage(pSLLBlock) - ScanLineListBlock *pSLLBlock; -{ - ScanLineListBlock *tmpSLLBlock; - - while (pSLLBlock) - { - tmpSLLBlock = pSLLBlock->next; - g_free (pSLLBlock); - pSLLBlock = tmpSLLBlock; - } -} - -/* - * Create an array of rectangles from a list of points. - * If indeed these things (POINTS, RECTS) are the same, - * then this proc is still needed, because it allocates - * storage for the array, which was allocated on the - * stack by the calling procedure. - * - */ -static int PtsToRegion(numFullPtBlocks, iCurPtBlock, FirstPtBlock, reg) - int numFullPtBlocks, iCurPtBlock; - POINTBLOCK *FirstPtBlock; - GdkRegion *reg; -{ - GdkRegionBox *rects; - GdkPoint *pts; - POINTBLOCK *CurPtBlock; - int i; - GdkRegionBox *extents; - int numRects; - - extents = ®->extents; - - numRects = ((numFullPtBlocks * NUMPTSTOBUFFER) + iCurPtBlock) >> 1; - - reg->rects = g_renew (GdkRegionBox, reg->rects, numRects); - - reg->size = numRects; - CurPtBlock = FirstPtBlock; - rects = reg->rects - 1; - numRects = 0; - extents->x1 = G_MAXSHORT, extents->x2 = G_MINSHORT; - - for ( ; numFullPtBlocks >= 0; numFullPtBlocks--) { - /* the loop uses 2 points per iteration */ - i = NUMPTSTOBUFFER >> 1; - if (!numFullPtBlocks) - i = iCurPtBlock >> 1; - for (pts = CurPtBlock->pts; i--; pts += 2) { - if (pts->x == pts[1].x) - continue; - if (numRects && pts->x == rects->x1 && pts->y == rects->y2 && - pts[1].x == rects->x2 && - (numRects == 1 || rects[-1].y1 != rects->y1) && - (i && pts[2].y > pts[1].y)) { - rects->y2 = pts[1].y + 1; - continue; - } - numRects++; - rects++; - rects->x1 = pts->x; rects->y1 = pts->y; - rects->x2 = pts[1].x; rects->y2 = pts[1].y + 1; - if (rects->x1 < extents->x1) - extents->x1 = rects->x1; - if (rects->x2 > extents->x2) - extents->x2 = rects->x2; - } - CurPtBlock = CurPtBlock->next; - } - - if (numRects) { - extents->y1 = reg->rects->y1; - extents->y2 = rects->y2; - } else { - extents->x1 = 0; - extents->y1 = 0; - extents->x2 = 0; - extents->y2 = 0; - } - reg->numRects = numRects; - - return(TRUE); -} - -/* - * polytoregion - * - * Scan converts a polygon by returning a run-length - * encoding of the resultant bitmap -- the run-length - * encoding is in the form of an array of rectangles. - */ -GdkRegion * -gdk_region_polygon(GdkPoint *Pts, gint Count, GdkFillRule rule) -{ - GdkRegion *region; - EdgeTableEntry *pAET; /* Active Edge Table */ - int y; /* current scanline */ - int iPts = 0; /* number of pts in buffer */ - EdgeTableEntry *pWETE; /* Winding Edge Table Entry*/ - ScanLineList *pSLL; /* current scanLineList */ - GdkPoint *pts; /* output buffer */ - EdgeTableEntry *pPrevAET; /* ptr to previous AET */ - EdgeTable ET; /* header node for ET */ - EdgeTableEntry AET; /* header node for AET */ - EdgeTableEntry *pETEs; /* EdgeTableEntries pool */ - ScanLineListBlock SLLBlock; /* header for scanlinelist */ - int fixWAET = FALSE; - POINTBLOCK FirstPtBlock, *curPtBlock; /* PtBlock buffers */ - POINTBLOCK *tmpPtBlock; - int numFullPtBlocks = 0; - - region = gdk_region_new (); - - /* special case a rectangle */ - pts = Pts; - if (((Count == 4) || - ((Count == 5) && (pts[4].x == pts[0].x) && (pts[4].y == pts[0].y))) && - (((pts[0].y == pts[1].y) && - (pts[1].x == pts[2].x) && - (pts[2].y == pts[3].y) && - (pts[3].x == pts[0].x)) || - ((pts[0].x == pts[1].x) && - (pts[1].y == pts[2].y) && - (pts[2].x == pts[3].x) && - (pts[3].y == pts[0].y)))) { - region->extents.x1 = MIN(pts[0].x, pts[2].x); - region->extents.y1 = MIN(pts[0].y, pts[2].y); - region->extents.x2 = MAX(pts[0].x, pts[2].x); - region->extents.y2 = MAX(pts[0].y, pts[2].y); - if ((region->extents.x1 != region->extents.x2) && - (region->extents.y1 != region->extents.y2)) { - region->numRects = 1; - *(region->rects) = region->extents; - } - return(region); - } - - pETEs = g_new (EdgeTableEntry, Count); - - pts = FirstPtBlock.pts; - CreateETandAET(Count, Pts, &ET, &AET, pETEs, &SLLBlock); - pSLL = ET.scanlines.next; - curPtBlock = &FirstPtBlock; - - if (rule == GDK_EVEN_ODD_RULE) { - /* - * for each scanline - */ - for (y = ET.ymin; y < ET.ymax; y++) { - /* - * Add a new edge to the active edge table when we - * get to the next edge. - */ - if (pSLL != NULL && y == pSLL->scanline) { - loadAET(&AET, pSLL->edgelist); - pSLL = pSLL->next; - } - pPrevAET = &AET; - pAET = AET.next; - - /* - * for each active edge - */ - while (pAET) { - pts->x = pAET->bres.minor_axis, pts->y = y; - pts++, iPts++; - - /* - * send out the buffer - */ - if (iPts == NUMPTSTOBUFFER) { - tmpPtBlock = (POINTBLOCK *)g_malloc(sizeof(POINTBLOCK)); - curPtBlock->next = tmpPtBlock; - curPtBlock = tmpPtBlock; - pts = curPtBlock->pts; - numFullPtBlocks++; - iPts = 0; - } - EVALUATEEDGEEVENODD(pAET, pPrevAET, y); - } - (void) InsertionSort(&AET); - } - } - else { - /* - * for each scanline - */ - for (y = ET.ymin; y < ET.ymax; y++) { - /* - * Add a new edge to the active edge table when we - * get to the next edge. - */ - if (pSLL != NULL && y == pSLL->scanline) { - loadAET(&AET, pSLL->edgelist); - computeWAET(&AET); - pSLL = pSLL->next; - } - pPrevAET = &AET; - pAET = AET.next; - pWETE = pAET; - - /* - * for each active edge - */ - while (pAET) { - /* - * add to the buffer only those edges that - * are in the Winding active edge table. - */ - if (pWETE == pAET) { - pts->x = pAET->bres.minor_axis, pts->y = y; - pts++, iPts++; - - /* - * send out the buffer - */ - if (iPts == NUMPTSTOBUFFER) { - tmpPtBlock = (POINTBLOCK *)g_malloc(sizeof(POINTBLOCK)); - curPtBlock->next = tmpPtBlock; - curPtBlock = tmpPtBlock; - pts = curPtBlock->pts; - numFullPtBlocks++; iPts = 0; - } - pWETE = pWETE->nextWETE; - } - EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET); - } - - /* - * recompute the winding active edge table if - * we just resorted or have exited an edge. - */ - if (InsertionSort(&AET) || fixWAET) { - computeWAET(&AET); - fixWAET = FALSE; - } - } - } - FreeStorage(SLLBlock.next); - (void) PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, region); - for (curPtBlock = FirstPtBlock.next; --numFullPtBlocks >= 0;) { - tmpPtBlock = curPtBlock->next; - g_free (curPtBlock); - curPtBlock = tmpPtBlock; - } - g_free (pETEs); - return(region); -} diff --git a/gdk/x11/gdkregion-generic.c b/gdk/x11/gdkregion-generic.c deleted file mode 100644 index 1140ce042..000000000 --- a/gdk/x11/gdkregion-generic.c +++ /dev/null @@ -1,1505 +0,0 @@ -/* $TOG: Region.c /main/31 1998/02/06 17:50:22 kaleb $ */ -/************************************************************************ - -Copyright 1987, 1988, 1998 The Open Group - -All Rights Reserved. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ -/* $XFree86: xc/lib/X11/Region.c,v 1.5 1999/05/09 10:50:01 dawes Exp $ */ -/* - * The functions in this file implement the Region abstraction, similar to one - * used in the X11 sample server. A Region is simply an area, as the name - * implies, and is implemented as a "y-x-banded" array of rectangles. To - * explain: Each Region is made up of a certain number of rectangles sorted - * by y coordinate first, and then by x coordinate. - * - * Furthermore, the rectangles are banded such that every rectangle with a - * given upper-left y coordinate (y1) will have the same lower-right y - * coordinate (y2) and vice versa. If a rectangle has scanlines in a band, it - * will span the entire vertical distance of the band. This means that some - * areas that could be merged into a taller rectangle will be represented as - * several shorter rectangles to account for shorter rectangles to its left - * or right but within its "vertical scope". - * - * An added constraint on the rectangles is that they must cover as much - * horizontal area as possible. E.g. no two rectangles in a band are allowed - * to touch. - * - * Whenever possible, bands will be merged together to cover a greater vertical - * distance (and thus reduce the number of rectangles). Two bands can be merged - * only if the bottom of one touches the top of the other and they have - * rectangles in the same places (of the same width, of course). This maintains - * the y-x-banding that's so nice to have... - */ - -#include <gdkregion.h> -#include "gdkregion-generic.h" - -#ifdef DEBUG -#include <stdio.h> -#define assert(expr) {if (!(expr)) fprintf(stderr,\ -"Assertion failed file %s, line %d: expr\n", __FILE__, __LINE__); } -#else -#define assert(expr) -#endif - -typedef void (*overlapFunc) (GdkRegion *pReg, - GdkRegionBox *r1, - GdkRegionBox *r1End, - GdkRegionBox *r2, - GdkRegionBox *r2End, - gint y1, - gint y2); -typedef void (*nonOverlapFunc) (GdkRegion *pReg, - GdkRegionBox *r, - GdkRegionBox *rEnd, - gint y1, - gint y2); - -static void miRegionCopy (GdkRegion *dstrgn, - GdkRegion *rgn); -static void miRegionOp (GdkRegion *newReg, - GdkRegion *reg1, - GdkRegion *reg2, - overlapFunc overlapFn, - nonOverlapFunc nonOverlap1Fn, - nonOverlapFunc nonOverlap2Fn); - -/* Create a new empty region */ - -GdkRegion * -gdk_region_new () -{ - GdkRegion *temp; - - temp = g_new (GdkRegion, 1); - temp->rects = g_new (GdkRegionBox, 1); - - temp->numRects = 0; - temp->extents.x1 = 0; - temp->extents.y1 = 0; - temp->extents.x2 = 0; - temp->extents.y2 = 0; - temp->size = 1; - - return temp; -} - -GdkRegion * -gdk_region_rectangle (GdkRectangle *rectangle) -{ - GdkRegion *temp; - - if (rectangle->width <= 0 || rectangle->height <= 0) - return gdk_region_new(); - - temp = g_new (GdkRegion, 1); - temp->rects = g_new (GdkRegionBox, 1); - - temp->numRects = 1; - temp->extents.x1 = temp->rects[0].x1 = rectangle->x; - temp->extents.y1 = temp->rects[0].y1 = rectangle->y; - temp->extents.x2 = temp->rects[0].x2 = rectangle->x + rectangle->width; - temp->extents.y2 = temp->rects[0].y2 = rectangle->y + rectangle->height; - temp->size = 1; - - return temp; -} - -GdkRegion * -gdk_region_copy (GdkRegion *region) -{ - GdkRegion *temp; - - temp = g_new (GdkRegion, 1); - temp->rects = g_new (GdkRegionBox, region->numRects); - - temp->numRects = region->numRects; - temp->extents = region->extents; - temp->size = region->numRects; - - memcpy (temp->rects, region->rects, region->numRects * sizeof (GdkRegionBox)); - - return temp; -} - -void -gdk_region_get_clipbox (GdkRegion *r, GdkRectangle *rect) -{ - rect->x = r->extents.x1; - rect->y = r->extents.y1; - rect->width = r->extents.x2 - r->extents.x1; - rect->height = r->extents.y2 - r->extents.y1; -} - -void -gdk_region_union_with_rect (GdkRegion *region, - GdkRectangle *rect) -{ - GdkRegion tmp_region; - - if (!rect->width || !rect->height) - return; - - tmp_region.rects = &tmp_region.extents; - tmp_region.numRects = 1; - tmp_region.extents.x1 = rect->x; - tmp_region.extents.y1 = rect->y; - tmp_region.extents.x2 = rect->x + rect->width; - tmp_region.extents.y2 = rect->y + rect->height; - tmp_region.size = 1; - - gdk_region_union (region, &tmp_region); -} - -/*- - *----------------------------------------------------------------------- - * miSetExtents -- - * Reset the extents of a region to what they should be. Called by - * miSubtract and miIntersect b/c they can't figure it out along the - * way or do so easily, as miUnion can. - * - * Results: - * None. - * - * Side Effects: - * The region's 'extents' structure is overwritten. - * - *----------------------------------------------------------------------- - */ -static void -miSetExtents (GdkRegion *pReg) -{ - GdkRegionBox *pBox, *pBoxEnd, *pExtents; - - if (pReg->numRects == 0) - { - pReg->extents.x1 = 0; - pReg->extents.y1 = 0; - pReg->extents.x2 = 0; - pReg->extents.y2 = 0; - return; - } - - pExtents = &pReg->extents; - pBox = pReg->rects; - pBoxEnd = &pBox[pReg->numRects - 1]; - - /* - * Since pBox is the first rectangle in the region, it must have the - * smallest y1 and since pBoxEnd is the last rectangle in the region, - * it must have the largest y2, because of banding. Initialize x1 and - * x2 from pBox and pBoxEnd, resp., as good things to initialize them - * to... - */ - pExtents->x1 = pBox->x1; - pExtents->y1 = pBox->y1; - pExtents->x2 = pBoxEnd->x2; - pExtents->y2 = pBoxEnd->y2; - - assert(pExtents->y1 < pExtents->y2); - while (pBox <= pBoxEnd) - { - if (pBox->x1 < pExtents->x1) - { - pExtents->x1 = pBox->x1; - } - if (pBox->x2 > pExtents->x2) - { - pExtents->x2 = pBox->x2; - } - pBox++; - } - assert(pExtents->x1 < pExtents->x2); -} - -void -gdk_region_destroy (GdkRegion *r) -{ - g_free (r->rects); - g_free (r); -} - - -/* TranslateRegion(pRegion, x, y) - translates in place - added by raymond -*/ - -void -gdk_region_offset (GdkRegion *region, - gint x, - gint y) -{ - int nbox; - GdkRegionBox *pbox; - - pbox = region->rects; - nbox = region->numRects; - - while(nbox--) - { - pbox->x1 += x; - pbox->x2 += x; - pbox->y1 += y; - pbox->y2 += y; - pbox++; - } - region->extents.x1 += x; - region->extents.x2 += x; - region->extents.y1 += y; - region->extents.y2 += y; -} - -/* - Utility procedure Compress: - Replace r by the region r', where - p in r' iff (Quantifer m <= dx) (p + m in r), and - Quantifier is Exists if grow is TRUE, For all if grow is FALSE, and - (x,y) + m = (x+m,y) if xdir is TRUE; (x,y+m) if xdir is FALSE. - - Thus, if xdir is TRUE and grow is FALSE, r is replaced by the region - of all points p such that p and the next dx points on the same - horizontal scan line are all in r. We do this using by noting - that p is the head of a run of length 2^i + k iff p is the head - of a run of length 2^i and p+2^i is the head of a run of length - k. Thus, the loop invariant: s contains the region corresponding - to the runs of length shift. r contains the region corresponding - to the runs of length 1 + dxo & (shift-1), where dxo is the original - value of dx. dx = dxo & ~(shift-1). As parameters, s and t are - scratch regions, so that we don't have to allocate them on every - call. -*/ - -#define ZOpRegion(a,b) if (grow) gdk_region_union (a, b); \ - else gdk_region_intersect (a,b) -#define ZShiftRegion(a,b) if (xdir) gdk_region_offset (a,b,0); \ - else gdk_region_offset (a,0,b) - -static void -Compress(GdkRegion *r, - GdkRegion *s, - GdkRegion *t, - guint dx, - int xdir, - int grow) -{ - guint shift = 1; - - miRegionCopy (s, r); - while (dx) - { - if (dx & shift) - { - ZShiftRegion(r, -(int)shift); - ZOpRegion(r, s); - dx -= shift; - if (!dx) break; - } - miRegionCopy (t, s); - ZShiftRegion(s, -(int)shift); - ZOpRegion(s, t); - shift <<= 1; - } -} - -#undef ZOpRegion -#undef ZShiftRegion -#undef ZCopyRegion - -void -gdk_region_shrink (GdkRegion *r, - int dx, - int dy) -{ - GdkRegion *s, *t; - int grow; - - if (!dx && !dy) - return; - - s = gdk_region_new (); - t = gdk_region_new (); - - grow = (dx < 0); - if (grow) - dx = -dx; - if (dx) - Compress(r, s, t, (unsigned) 2*dx, TRUE, grow); - - grow = (dy < 0); - if (grow) - dy = -dy; - if (dy) - Compress(r, s, t, (unsigned) 2*dy, FALSE, grow); - - gdk_region_offset (r, dx, dy); - gdk_region_destroy (s); - gdk_region_destroy (t); -} - - -/*====================================================================== - * Region Intersection - *====================================================================*/ -/*- - *----------------------------------------------------------------------- - * miIntersectO -- - * Handle an overlapping band for miIntersect. - * - * Results: - * None. - * - * Side Effects: - * Rectangles may be added to the region. - * - *----------------------------------------------------------------------- - */ -/* static void*/ -static void -miIntersectO (GdkRegion *pReg, - GdkRegionBox *r1, - GdkRegionBox *r1End, - GdkRegionBox *r2, - GdkRegionBox *r2End, - gint y1, - gint y2) -{ - int x1; - int x2; - GdkRegionBox *pNextRect; - - pNextRect = &pReg->rects[pReg->numRects]; - - while ((r1 != r1End) && (r2 != r2End)) - { - x1 = MAX (r1->x1,r2->x1); - x2 = MIN (r1->x2,r2->x2); - - /* - * If there's any overlap between the two rectangles, add that - * overlap to the new region. - * There's no need to check for subsumption because the only way - * such a need could arise is if some region has two rectangles - * right next to each other. Since that should never happen... - */ - if (x1 < x2) - { - assert (y1<y2); - - MEMCHECK (pReg, pNextRect, pReg->rects); - pNextRect->x1 = x1; - pNextRect->y1 = y1; - pNextRect->x2 = x2; - pNextRect->y2 = y2; - pReg->numRects += 1; - pNextRect++; - assert (pReg->numRects <= pReg->size); - } - - /* - * Need to advance the pointers. Shift the one that extends - * to the right the least, since the other still has a chance to - * overlap with that region's next rectangle, if you see what I mean. - */ - if (r1->x2 < r2->x2) - { - r1++; - } - else if (r2->x2 < r1->x2) - { - r2++; - } - else - { - r1++; - r2++; - } - } -} - -void -gdk_region_intersect (GdkRegion *region, - GdkRegion *other) -{ - /* check for trivial reject */ - if ((!(region->numRects)) || (!(other->numRects)) || - (!EXTENTCHECK(®ion->extents, &other->extents))) - region->numRects = 0; - else - miRegionOp (region, region, other, - miIntersectO, (nonOverlapFunc) NULL, (nonOverlapFunc) NULL); - - /* - * Can't alter region's extents before miRegionOp depends on the - * extents of the regions being unchanged. Besides, this way there's - * no checking against rectangles that will be nuked due to - * coalescing, so we have to examine fewer rectangles. - */ - miSetExtents(region); -} - -static void -miRegionCopy(GdkRegion *dstrgn, GdkRegion *rgn) -{ - if (dstrgn != rgn) /* don't want to copy to itself */ - { - if (dstrgn->size < rgn->numRects) - { - dstrgn->rects = g_renew (GdkRegionBox, dstrgn->rects, rgn->numRects); - dstrgn->size = rgn->numRects; - } - dstrgn->numRects = rgn->numRects; - dstrgn->extents.x1 = rgn->extents.x1; - dstrgn->extents.y1 = rgn->extents.y1; - dstrgn->extents.x2 = rgn->extents.x2; - dstrgn->extents.y2 = rgn->extents.y2; - - memcpy (dstrgn->rects, rgn->rects, rgn->numRects * sizeof (GdkRegionBox)); - } -} - - -/*====================================================================== - * Generic Region Operator - *====================================================================*/ - -/*- - *----------------------------------------------------------------------- - * miCoalesce -- - * Attempt to merge the boxes in the current band with those in the - * previous one. Used only by miRegionOp. - * - * Results: - * The new index for the previous band. - * - * Side Effects: - * If coalescing takes place: - * - rectangles in the previous band will have their y2 fields - * altered. - * - pReg->numRects will be decreased. - * - *----------------------------------------------------------------------- - */ -/* static int*/ -static int -miCoalesce (GdkRegion *pReg, /* Region to coalesce */ - gint prevStart, /* Index of start of previous band */ - gint curStart) /* Index of start of current band */ -{ - GdkRegionBox *pPrevBox; /* Current box in previous band */ - GdkRegionBox *pCurBox; /* Current box in current band */ - GdkRegionBox *pRegEnd; /* End of region */ - int curNumRects; /* Number of rectangles in current - * band */ - int prevNumRects; /* Number of rectangles in previous - * band */ - int bandY1; /* Y1 coordinate for current band */ - - pRegEnd = &pReg->rects[pReg->numRects]; - - pPrevBox = &pReg->rects[prevStart]; - prevNumRects = curStart - prevStart; - - /* - * Figure out how many rectangles are in the current band. Have to do - * this because multiple bands could have been added in miRegionOp - * at the end when one region has been exhausted. - */ - pCurBox = &pReg->rects[curStart]; - bandY1 = pCurBox->y1; - for (curNumRects = 0; - (pCurBox != pRegEnd) && (pCurBox->y1 == bandY1); - curNumRects++) - { - pCurBox++; - } - - if (pCurBox != pRegEnd) - { - /* - * If more than one band was added, we have to find the start - * of the last band added so the next coalescing job can start - * at the right place... (given when multiple bands are added, - * this may be pointless -- see above). - */ - pRegEnd--; - while (pRegEnd[-1].y1 == pRegEnd->y1) - { - pRegEnd--; - } - curStart = pRegEnd - pReg->rects; - pRegEnd = pReg->rects + pReg->numRects; - } - - if ((curNumRects == prevNumRects) && (curNumRects != 0)) { - pCurBox -= curNumRects; - /* - * The bands may only be coalesced if the bottom of the previous - * matches the top scanline of the current. - */ - if (pPrevBox->y2 == pCurBox->y1) - { - /* - * Make sure the bands have boxes in the same places. This - * assumes that boxes have been added in such a way that they - * cover the most area possible. I.e. two boxes in a band must - * have some horizontal space between them. - */ - do - { - if ((pPrevBox->x1 != pCurBox->x1) || - (pPrevBox->x2 != pCurBox->x2)) - { - /* - * The bands don't line up so they can't be coalesced. - */ - return (curStart); - } - pPrevBox++; - pCurBox++; - prevNumRects -= 1; - } while (prevNumRects != 0); - - pReg->numRects -= curNumRects; - pCurBox -= curNumRects; - pPrevBox -= curNumRects; - - /* - * The bands may be merged, so set the bottom y of each box - * in the previous band to that of the corresponding box in - * the current band. - */ - do - { - pPrevBox->y2 = pCurBox->y2; - pPrevBox++; - pCurBox++; - curNumRects -= 1; - } - while (curNumRects != 0); - - /* - * If only one band was added to the region, we have to backup - * curStart to the start of the previous band. - * - * If more than one band was added to the region, copy the - * other bands down. The assumption here is that the other bands - * came from the same region as the current one and no further - * coalescing can be done on them since it's all been done - * already... curStart is already in the right place. - */ - if (pCurBox == pRegEnd) - { - curStart = prevStart; - } - else - { - do - { - *pPrevBox++ = *pCurBox++; - } - while (pCurBox != pRegEnd); - } - - } - } - return curStart; -} - -/*- - *----------------------------------------------------------------------- - * miRegionOp -- - * Apply an operation to two regions. Called by miUnion, miInverse, - * miSubtract, miIntersect... - * - * Results: - * None. - * - * Side Effects: - * The new region is overwritten. - * - * Notes: - * The idea behind this function is to view the two regions as sets. - * Together they cover a rectangle of area that this function divides - * into horizontal bands where points are covered only by one region - * or by both. For the first case, the nonOverlapFunc is called with - * each the band and the band's upper and lower extents. For the - * second, the overlapFunc is called to process the entire band. It - * is responsible for clipping the rectangles in the band, though - * this function provides the boundaries. - * At the end of each band, the new region is coalesced, if possible, - * to reduce the number of rectangles in the region. - * - *----------------------------------------------------------------------- - */ -/* static void*/ -static void -miRegionOp(GdkRegion *newReg, - GdkRegion *reg1, - GdkRegion *reg2, - overlapFunc overlapFn, /* Function to call for over- - * lapping bands */ - nonOverlapFunc nonOverlap1Fn, /* Function to call for non- - * overlapping bands in region - * 1 */ - nonOverlapFunc nonOverlap2Fn) /* Function to call for non- - * overlapping bands in region - * 2 */ -{ - GdkRegionBox *r1; /* Pointer into first region */ - GdkRegionBox *r2; /* Pointer into 2d region */ - GdkRegionBox *r1End; /* End of 1st region */ - GdkRegionBox *r2End; /* End of 2d region */ - int ybot; /* Bottom of intersection */ - int ytop; /* Top of intersection */ - GdkRegionBox *oldRects; /* Old rects for newReg */ - int prevBand; /* Index of start of - * previous band in newReg */ - int curBand; /* Index of start of current - * band in newReg */ - GdkRegionBox *r1BandEnd; /* End of current band in r1 */ - GdkRegionBox *r2BandEnd; /* End of current band in r2 */ - int top; /* Top of non-overlapping - * band */ - int bot; /* Bottom of non-overlapping - * band */ - - /* - * Initialization: - * set r1, r2, r1End and r2End appropriately, preserve the important - * parts of the destination region until the end in case it's one of - * the two source regions, then mark the "new" region empty, allocating - * another array of rectangles for it to use. - */ - r1 = reg1->rects; - r2 = reg2->rects; - r1End = r1 + reg1->numRects; - r2End = r2 + reg2->numRects; - - oldRects = newReg->rects; - - EMPTY_REGION(newReg); - - /* - * Allocate a reasonable number of rectangles for the new region. The idea - * is to allocate enough so the individual functions don't need to - * reallocate and copy the array, which is time consuming, yet we don't - * have to worry about using too much memory. I hope to be able to - * nuke the Xrealloc() at the end of this function eventually. - */ - newReg->size = MAX (reg1->numRects, reg2->numRects) * 2; - newReg->rects = g_new (GdkRegionBox, newReg->size); - - /* - * Initialize ybot and ytop. - * In the upcoming loop, ybot and ytop serve different functions depending - * on whether the band being handled is an overlapping or non-overlapping - * band. - * In the case of a non-overlapping band (only one of the regions - * has points in the band), ybot is the bottom of the most recent - * intersection and thus clips the top of the rectangles in that band. - * ytop is the top of the next intersection between the two regions and - * serves to clip the bottom of the rectangles in the current band. - * For an overlapping band (where the two regions intersect), ytop clips - * the top of the rectangles of both regions and ybot clips the bottoms. - */ - if (reg1->extents.y1 < reg2->extents.y1) - ybot = reg1->extents.y1; - else - ybot = reg2->extents.y1; - - /* - * prevBand serves to mark the start of the previous band so rectangles - * can be coalesced into larger rectangles. qv. miCoalesce, above. - * In the beginning, there is no previous band, so prevBand == curBand - * (curBand is set later on, of course, but the first band will always - * start at index 0). prevBand and curBand must be indices because of - * the possible expansion, and resultant moving, of the new region's - * array of rectangles. - */ - prevBand = 0; - - do - { - curBand = newReg->numRects; - - /* - * This algorithm proceeds one source-band (as opposed to a - * destination band, which is determined by where the two regions - * intersect) at a time. r1BandEnd and r2BandEnd serve to mark the - * rectangle after the last one in the current band for their - * respective regions. - */ - r1BandEnd = r1; - while ((r1BandEnd != r1End) && (r1BandEnd->y1 == r1->y1)) - { - r1BandEnd++; - } - - r2BandEnd = r2; - while ((r2BandEnd != r2End) && (r2BandEnd->y1 == r2->y1)) - { - r2BandEnd++; - } - - /* - * First handle the band that doesn't intersect, if any. - * - * Note that attention is restricted to one band in the - * non-intersecting region at once, so if a region has n - * bands between the current position and the next place it overlaps - * the other, this entire loop will be passed through n times. - */ - if (r1->y1 < r2->y1) - { - top = MAX (r1->y1,ybot); - bot = MIN (r1->y2,r2->y1); - - if ((top != bot) && (nonOverlap1Fn != (void (*)())NULL)) - { - (* nonOverlap1Fn) (newReg, r1, r1BandEnd, top, bot); - } - - ytop = r2->y1; - } - else if (r2->y1 < r1->y1) - { - top = MAX (r2->y1,ybot); - bot = MIN (r2->y2,r1->y1); - - if ((top != bot) && (nonOverlap2Fn != (void (*)())NULL)) - { - (* nonOverlap2Fn) (newReg, r2, r2BandEnd, top, bot); - } - - ytop = r1->y1; - } - else - { - ytop = r1->y1; - } - - /* - * If any rectangles got added to the region, try and coalesce them - * with rectangles from the previous band. Note we could just do - * this test in miCoalesce, but some machines incur a not - * inconsiderable cost for function calls, so... - */ - if (newReg->numRects != curBand) - { - prevBand = miCoalesce (newReg, prevBand, curBand); - } - - /* - * Now see if we've hit an intersecting band. The two bands only - * intersect if ybot > ytop - */ - ybot = MIN (r1->y2, r2->y2); - curBand = newReg->numRects; - if (ybot > ytop) - { - (* overlapFn) (newReg, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot); - - } - - if (newReg->numRects != curBand) - { - prevBand = miCoalesce (newReg, prevBand, curBand); - } - - /* - * If we've finished with a band (y2 == ybot) we skip forward - * in the region to the next band. - */ - if (r1->y2 == ybot) - { - r1 = r1BandEnd; - } - if (r2->y2 == ybot) - { - r2 = r2BandEnd; - } - } while ((r1 != r1End) && (r2 != r2End)); - - /* - * Deal with whichever region still has rectangles left. - */ - curBand = newReg->numRects; - if (r1 != r1End) - { - if (nonOverlap1Fn != (nonOverlapFunc )NULL) - { - do - { - r1BandEnd = r1; - while ((r1BandEnd < r1End) && (r1BandEnd->y1 == r1->y1)) - { - r1BandEnd++; - } - (* nonOverlap1Fn) (newReg, r1, r1BandEnd, - MAX (r1->y1,ybot), r1->y2); - r1 = r1BandEnd; - } while (r1 != r1End); - } - } - else if ((r2 != r2End) && (nonOverlap2Fn != (nonOverlapFunc) NULL)) - { - do - { - r2BandEnd = r2; - while ((r2BandEnd < r2End) && (r2BandEnd->y1 == r2->y1)) - { - r2BandEnd++; - } - (* nonOverlap2Fn) (newReg, r2, r2BandEnd, - MAX (r2->y1,ybot), r2->y2); - r2 = r2BandEnd; - } while (r2 != r2End); - } - - if (newReg->numRects != curBand) - { - (void) miCoalesce (newReg, prevBand, curBand); - } - - /* - * A bit of cleanup. To keep regions from growing without bound, - * we shrink the array of rectangles to match the new number of - * rectangles in the region. This never goes to 0, however... - * - * Only do this stuff if the number of rectangles allocated is more than - * twice the number of rectangles in the region (a simple optimization...). - */ - if (newReg->numRects < (newReg->size >> 1)) - { - if (REGION_NOT_EMPTY (newReg)) - { - newReg->size = newReg->numRects; - newReg->rects = g_renew (GdkRegionBox, newReg->rects, newReg->size); - } - else - { - /* - * No point in doing the extra work involved in an Xrealloc if - * the region is empty - */ - newReg->size = 1; - g_free (newReg->rects); - newReg->rects = g_new (GdkRegionBox, 1); - } - } - g_free (oldRects); -} - - -/*====================================================================== - * Region Union - *====================================================================*/ - -/*- - *----------------------------------------------------------------------- - * miUnionNonO -- - * Handle a non-overlapping band for the union operation. Just - * Adds the rectangles into the region. Doesn't have to check for - * subsumption or anything. - * - * Results: - * None. - * - * Side Effects: - * pReg->numRects is incremented and the final rectangles overwritten - * with the rectangles we're passed. - * - *----------------------------------------------------------------------- - */ -static void -miUnionNonO (GdkRegion *pReg, - GdkRegionBox *r, - GdkRegionBox *rEnd, - gint y1, - gint y2) -{ - GdkRegionBox *pNextRect; - - pNextRect = &pReg->rects[pReg->numRects]; - - assert(y1 < y2); - - while (r != rEnd) - { - assert(r->x1 < r->x2); - MEMCHECK(pReg, pNextRect, pReg->rects); - pNextRect->x1 = r->x1; - pNextRect->y1 = y1; - pNextRect->x2 = r->x2; - pNextRect->y2 = y2; - pReg->numRects += 1; - pNextRect++; - - assert(pReg->numRects<=pReg->size); - r++; - } -} - - -/*- - *----------------------------------------------------------------------- - * miUnionO -- - * Handle an overlapping band for the union operation. Picks the - * left-most rectangle each time and merges it into the region. - * - * Results: - * None. - * - * Side Effects: - * Rectangles are overwritten in pReg->rects and pReg->numRects will - * be changed. - * - *----------------------------------------------------------------------- - */ - -/* static void*/ -static void -miUnionO (GdkRegion *pReg, - GdkRegionBox *r1, - GdkRegionBox *r1End, - GdkRegionBox *r2, - GdkRegionBox *r2End, - gint y1, - gint y2) -{ - GdkRegionBox * pNextRect; - - pNextRect = &pReg->rects[pReg->numRects]; - -#define MERGERECT(r) \ - if ((pReg->numRects != 0) && \ - (pNextRect[-1].y1 == y1) && \ - (pNextRect[-1].y2 == y2) && \ - (pNextRect[-1].x2 >= r->x1)) \ - { \ - if (pNextRect[-1].x2 < r->x2) \ - { \ - pNextRect[-1].x2 = r->x2; \ - assert(pNextRect[-1].x1<pNextRect[-1].x2); \ - } \ - } \ - else \ - { \ - MEMCHECK(pReg, pNextRect, pReg->rects); \ - pNextRect->y1 = y1; \ - pNextRect->y2 = y2; \ - pNextRect->x1 = r->x1; \ - pNextRect->x2 = r->x2; \ - pReg->numRects += 1; \ - pNextRect += 1; \ - } \ - assert(pReg->numRects<=pReg->size); \ - r++; - - assert (y1<y2); - while ((r1 != r1End) && (r2 != r2End)) - { - if (r1->x1 < r2->x1) - { - MERGERECT(r1); - } - else - { - MERGERECT(r2); - } - } - - if (r1 != r1End) - { - do - { - MERGERECT(r1); - } while (r1 != r1End); - } - else while (r2 != r2End) - { - MERGERECT(r2); - } -} - -void -gdk_region_union (GdkRegion *region, - GdkRegion *other) -{ - /* checks all the simple cases */ - - /* - * region and other are the same or other is empty - */ - if ((region == other) || (!(other->numRects))) - return; - - /* - * region is empty - */ - if (!(region->numRects)) - { - miRegionCopy (region, other); - return; - } - - /* - * region completely subsumes otehr - */ - if ((region->numRects == 1) && - (region->extents.x1 <= other->extents.x1) && - (region->extents.y1 <= other->extents.y1) && - (region->extents.x2 >= other->extents.x2) && - (region->extents.y2 >= other->extents.y2)) - return; - - /* - * other completely subsumes region - */ - if ((other->numRects == 1) && - (other->extents.x1 <= region->extents.x1) && - (other->extents.y1 <= region->extents.y1) && - (other->extents.x2 >= region->extents.x2) && - (other->extents.y2 >= region->extents.y2)) - { - miRegionCopy(region, other); - return; - } - - miRegionOp (region, region, other, miUnionO, - miUnionNonO, miUnionNonO); - - region->extents.x1 = MIN (region->extents.x1, other->extents.x1); - region->extents.y1 = MIN (region->extents.y1, other->extents.y1); - region->extents.x2 = MAX (region->extents.x2, other->extents.x2); - region->extents.y2 = MAX (region->extents.y2, other->extents.y2); -} - - -/*====================================================================== - * Region Subtraction - *====================================================================*/ - -/*- - *----------------------------------------------------------------------- - * miSubtractNonO -- - * Deal with non-overlapping band for subtraction. Any parts from - * region 2 we discard. Anything from region 1 we add to the region. - * - * Results: - * None. - * - * Side Effects: - * pReg may be affected. - * - *----------------------------------------------------------------------- - */ -/* static void*/ -static void -miSubtractNonO1 (GdkRegion *pReg, - GdkRegionBox *r, - GdkRegionBox *rEnd, - gint y1, - gint y2) -{ - GdkRegionBox * pNextRect; - - pNextRect = &pReg->rects[pReg->numRects]; - - assert(y1<y2); - - while (r != rEnd) - { - assert (r->x1<r->x2); - MEMCHECK (pReg, pNextRect, pReg->rects); - pNextRect->x1 = r->x1; - pNextRect->y1 = y1; - pNextRect->x2 = r->x2; - pNextRect->y2 = y2; - pReg->numRects += 1; - pNextRect++; - - assert (pReg->numRects <= pReg->size); - - r++; - } -} - -/*- - *----------------------------------------------------------------------- - * miSubtractO -- - * Overlapping band subtraction. x1 is the left-most point not yet - * checked. - * - * Results: - * None. - * - * Side Effects: - * pReg may have rectangles added to it. - * - *----------------------------------------------------------------------- - */ -/* static void*/ -static void -miSubtractO (GdkRegion *pReg, - GdkRegionBox *r1, - GdkRegionBox *r1End, - GdkRegionBox *r2, - GdkRegionBox *r2End, - gint y1, - gint y2) -{ - GdkRegionBox * pNextRect; - int x1; - - x1 = r1->x1; - - assert(y1<y2); - pNextRect = &pReg->rects[pReg->numRects]; - - while ((r1 != r1End) && (r2 != r2End)) - { - if (r2->x2 <= x1) - { - /* - * Subtrahend missed the boat: go to next subtrahend. - */ - r2++; - } - else if (r2->x1 <= x1) - { - /* - * Subtrahend preceeds minuend: nuke left edge of minuend. - */ - x1 = r2->x2; - if (x1 >= r1->x2) - { - /* - * Minuend completely covered: advance to next minuend and - * reset left fence to edge of new minuend. - */ - r1++; - if (r1 != r1End) - x1 = r1->x1; - } - else - { - /* - * Subtrahend now used up since it doesn't extend beyond - * minuend - */ - r2++; - } - } - else if (r2->x1 < r1->x2) - { - /* - * Left part of subtrahend covers part of minuend: add uncovered - * part of minuend to region and skip to next subtrahend. - */ - assert(x1<r2->x1); - MEMCHECK(pReg, pNextRect, pReg->rects); - pNextRect->x1 = x1; - pNextRect->y1 = y1; - pNextRect->x2 = r2->x1; - pNextRect->y2 = y2; - pReg->numRects += 1; - pNextRect++; - - assert(pReg->numRects<=pReg->size); - - x1 = r2->x2; - if (x1 >= r1->x2) - { - /* - * Minuend used up: advance to new... - */ - r1++; - if (r1 != r1End) - x1 = r1->x1; - } - else - { - /* - * Subtrahend used up - */ - r2++; - } - } - else - { - /* - * Minuend used up: add any remaining piece before advancing. - */ - if (r1->x2 > x1) - { - MEMCHECK(pReg, pNextRect, pReg->rects); - pNextRect->x1 = x1; - pNextRect->y1 = y1; - pNextRect->x2 = r1->x2; - pNextRect->y2 = y2; - pReg->numRects += 1; - pNextRect++; - assert(pReg->numRects<=pReg->size); - } - r1++; - x1 = r1->x1; - } - } - - /* - * Add remaining minuend rectangles to region. - */ - while (r1 != r1End) - { - assert(x1<r1->x2); - MEMCHECK(pReg, pNextRect, pReg->rects); - pNextRect->x1 = x1; - pNextRect->y1 = y1; - pNextRect->x2 = r1->x2; - pNextRect->y2 = y2; - pReg->numRects += 1; - pNextRect++; - - assert(pReg->numRects<=pReg->size); - - r1++; - if (r1 != r1End) - { - x1 = r1->x1; - } - } -} - -/*- - *----------------------------------------------------------------------- - * gdk_region_subtract -- - * Subtract other from region and leave the result in region. - * - * Results: - * TRUE. - * - * Side Effects: - * region is overwritten. - * - *----------------------------------------------------------------------- - */ - -void -gdk_region_subtract (GdkRegion *region, - GdkRegion *other) -{ - /* check for trivial reject */ - if ((!(region->numRects)) || (!(other->numRects)) || - (!EXTENTCHECK(®ion->extents, &other->extents))) - return; - - miRegionOp (region, region, other, miSubtractO, - miSubtractNonO1, (nonOverlapFunc) NULL); - - /* - * Can't alter region's extents before we call miRegionOp because miRegionOp - * depends on the extents of those regions being the unaltered. Besides, this - * way there's no checking against rectangles that will be nuked - * due to coalescing, so we have to examine fewer rectangles. - */ - miSetExtents (region); -} - -void -gdk_region_xor (GdkRegion *sra, - GdkRegion *srb) -{ - GdkRegion *trb; - - trb = gdk_region_copy (srb); - - gdk_region_subtract (trb, sra); - gdk_region_subtract (sra, srb); - - gdk_region_union (sra,trb); - - gdk_region_destroy (trb); -} - -/* - * Check to see if the region is empty. Assumes a region is passed - * as a parameter - */ -gboolean -gdk_region_empty (GdkRegion *r) -{ - if (r->numRects == 0) - return TRUE; - else - return FALSE; -} - -/* - * Check to see if two regions are equal - */ -gboolean -gdk_region_equal (GdkRegion *r1, - GdkRegion *r2) -{ - int i; - - if (r1->numRects != r2->numRects) return FALSE; - else if (r1->numRects == 0) return TRUE; - else if (r1->extents.x1 != r2->extents.x1) return FALSE; - else if (r1->extents.x2 != r2->extents.x2) return FALSE; - else if (r1->extents.y1 != r2->extents.y1) return FALSE; - else if (r1->extents.y2 != r2->extents.y2) return FALSE; - else - for(i=0; i < r1->numRects; i++ ) - { - if (r1->rects[i].x1 != r2->rects[i].x1) return FALSE; - else if (r1->rects[i].x2 != r2->rects[i].x2) return FALSE; - else if (r1->rects[i].y1 != r2->rects[i].y1) return FALSE; - else if (r1->rects[i].y2 != r2->rects[i].y2) return FALSE; - } - return TRUE; -} - -gboolean -gdk_region_point_in (GdkRegion *region, - int x, - int y) -{ - int i; - - if (region->numRects == 0) - return FALSE; - if (!INBOX(region->extents, x, y)) - return FALSE; - for (i=0; i<region->numRects; i++) - { - if (INBOX (region->rects[i], x, y)) - return TRUE; - } - return FALSE; -} - -GdkOverlapType -gdk_region_rect_in (GdkRegion *region, - GdkRectangle *rectangle) -{ - GdkRegionBox *pbox; - GdkRegionBox *pboxEnd; - GdkRegionBox rect; - GdkRegionBox *prect = ▭ - gboolean partIn, partOut; - - gint rx = rectangle->x; - gint ry = rectangle->y; - - prect->x1 = rx; - prect->y1 = ry; - prect->x2 = rx + rectangle->width; - prect->y2 = ry + rectangle->height; - - /* this is (just) a useful optimization */ - if ((region->numRects == 0) || !EXTENTCHECK (®ion->extents, prect)) - return GDK_OVERLAP_RECTANGLE_OUT; - - partOut = FALSE; - partIn = FALSE; - - /* can stop when both partOut and partIn are TRUE, or we reach prect->y2 */ - for (pbox = region->rects, pboxEnd = pbox + region->numRects; - pbox < pboxEnd; - pbox++) - { - - if (pbox->y2 <= ry) - continue; /* getting up to speed or skipping remainder of band */ - - if (pbox->y1 > ry) - { - partOut = TRUE; /* missed part of rectangle above */ - if (partIn || (pbox->y1 >= prect->y2)) - break; - ry = pbox->y1; /* x guaranteed to be == prect->x1 */ - } - - if (pbox->x2 <= rx) - continue; /* not far enough over yet */ - - if (pbox->x1 > rx) - { - partOut = TRUE; /* missed part of rectangle to left */ - if (partIn) - break; - } - - if (pbox->x1 < prect->x2) - { - partIn = TRUE; /* definitely overlap */ - if (partOut) - break; - } - - if (pbox->x2 >= prect->x2) - { - ry = pbox->y2; /* finished with this band */ - if (ry >= prect->y2) - break; - rx = prect->x1; /* reset x out to left again */ - } - else - { - /* - * Because boxes in a band are maximal width, if the first box - * to overlap the rectangle doesn't completely cover it in that - * band, the rectangle must be partially out, since some of it - * will be uncovered in that band. partIn will have been set true - * by now... - */ - break; - } - - } - - return (partIn ? - ((ry < prect->y2) ? - GDK_OVERLAP_RECTANGLE_PART : GDK_OVERLAP_RECTANGLE_IN) : - GDK_OVERLAP_RECTANGLE_OUT); -} diff --git a/gdk/x11/gdkregion-generic.h b/gdk/x11/gdkregion-generic.h deleted file mode 100644 index 659d44eb4..000000000 --- a/gdk/x11/gdkregion-generic.h +++ /dev/null @@ -1,167 +0,0 @@ -/* $TOG: region.h /main/9 1998/02/06 17:50:30 kaleb $ */ -/************************************************************************ - -Copyright 1987, 1998 The Open Group - -All Rights Reserved. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the name of Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ - -#ifndef __GDK_REGION_GENERIC_H__ -#define __GDK_REGION_GENERIC_H__ - -typedef struct _GdkRegionBox GdkRegionBox; - -struct _GdkRegionBox -{ - int x1, x2, y1, y2; -}; - -/* - * clip region - */ - -struct _GdkRegion -{ - long size; - long numRects; - GdkRegionBox *rects; - GdkRegionBox extents; -}; - -/* 1 if two BOXs overlap. - * 0 if two BOXs do not overlap. - * Remember, x2 and y2 are not in the region - */ -#define EXTENTCHECK(r1, r2) \ - ((r1)->x2 > (r2)->x1 && \ - (r1)->x1 < (r2)->x2 && \ - (r1)->y2 > (r2)->y1 && \ - (r1)->y1 < (r2)->y2) - -/* - * update region extents - */ -#define EXTENTS(r,idRect){\ - if((r)->x1 < (idRect)->extents.x1)\ - (idRect)->extents.x1 = (r)->x1;\ - if((r)->y1 < (idRect)->extents.y1)\ - (idRect)->extents.y1 = (r)->y1;\ - if((r)->x2 > (idRect)->extents.x2)\ - (idRect)->extents.x2 = (r)->x2;\ - if((r)->y2 > (idRect)->extents.y2)\ - (idRect)->extents.y2 = (r)->y2;\ - } - -/* - * Check to see if there is enough memory in the present region. - */ -#define MEMCHECK(reg, rect, firstrect){ \ - if ((reg)->numRects >= ((reg)->size - 1)) { \ - (firstrect) = g_renew (GdkRegionBox, (firstrect), 2 * (reg)->size); \ - (reg)->size *= 2; \ - (rect) = &(firstrect)[(reg)->numRects]; \ - } \ - } - -/* this routine checks to see if the previous rectangle is the same - * or subsumes the new rectangle to add. - */ - -#define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\ - (!(((Reg)->numRects > 0)&&\ - ((R-1)->y1 == (Ry1)) &&\ - ((R-1)->y2 == (Ry2)) &&\ - ((R-1)->x1 <= (Rx1)) &&\ - ((R-1)->x2 >= (Rx2)))) - -/* add a rectangle to the given Region */ -#define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\ - if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\ - CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\ - (r)->x1 = (rx1);\ - (r)->y1 = (ry1);\ - (r)->x2 = (rx2);\ - (r)->y2 = (ry2);\ - EXTENTS((r), (reg));\ - (reg)->numRects++;\ - (r)++;\ - }\ - } - - - -/* add a rectangle to the given Region */ -#define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\ - if ((rx1 < rx2) && (ry1 < ry2) &&\ - CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\ - (r)->x1 = (rx1);\ - (r)->y1 = (ry1);\ - (r)->x2 = (rx2);\ - (r)->y2 = (ry2);\ - (reg)->numRects++;\ - (r)++;\ - }\ - } - -#define EMPTY_REGION(pReg) pReg->numRects = 0 - -#define REGION_NOT_EMPTY(pReg) pReg->numRects - -#define INBOX(r, x, y) \ - ( ( ((r).x2 > x)) && \ - ( ((r).x1 <= x)) && \ - ( ((r).y2 > y)) && \ - ( ((r).y1 <= y)) ) - -/* - * number of points to buffer before sending them off - * to scanlines() : Must be an even number - */ -#define NUMPTSTOBUFFER 200 - -/* - * used to allocate buffers for points and link - * the buffers together - */ -typedef struct _POINTBLOCK { - GdkPoint pts[NUMPTSTOBUFFER]; - struct _POINTBLOCK *next; -} POINTBLOCK; - -#endif /* __GDK_REGION_GENERIC_H__ */ diff --git a/gdk/x11/gdkregion-x11.c b/gdk/x11/gdkregion-x11.c deleted file mode 100644 index 58192fdb0..000000000 --- a/gdk/x11/gdkregion-x11.c +++ /dev/null @@ -1,324 +0,0 @@ -/* GDK - The GIMP Drawing Kit - * 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. - */ - -/* - * 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/. - */ - -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include "gdkprivate-x11.h" - -GdkRegion* -gdk_region_new (void) -{ - GdkRegionPrivate *private; - GdkRegion *region; - Region xregion; - - xregion = XCreateRegion(); - private = g_new (GdkRegionPrivate, 1); - private->xregion = xregion; - region = (GdkRegion*) private; - region->user_data = NULL; - - return region; -} - -void -gdk_region_destroy (GdkRegion *region) -{ - GdkRegionPrivate *private; - - g_return_if_fail (region != NULL); - - private = (GdkRegionPrivate *) region; - XDestroyRegion (private->xregion); - - g_free (private); -} - -gboolean -gdk_region_empty (GdkRegion *region) -{ - GdkRegionPrivate *private; - - g_return_val_if_fail (region != NULL, 0); - - private = (GdkRegionPrivate *) region; - - return XEmptyRegion (private->xregion); -} - -gboolean -gdk_region_equal (GdkRegion *region1, - GdkRegion *region2) -{ - GdkRegionPrivate *private1; - GdkRegionPrivate *private2; - - g_return_val_if_fail (region1 != NULL, 0); - g_return_val_if_fail (region2 != NULL, 0); - - private1 = (GdkRegionPrivate *) region1; - private2 = (GdkRegionPrivate *) region2; - - return XEqualRegion (private1->xregion, private2->xregion); -} - -void -gdk_region_get_clipbox(GdkRegion *region, - GdkRectangle *rectangle) -{ - GdkRegionPrivate *rp; - XRectangle r; - - g_return_if_fail(region != NULL); - g_return_if_fail(rectangle != NULL); - - rp = (GdkRegionPrivate *)region; - XClipBox(rp->xregion, &r); - - rectangle->x = r.x; - rectangle->y = r.y; - rectangle->width = r.width; - rectangle->height = r.height; -} - -gboolean -gdk_region_point_in (GdkRegion *region, - gint x, - gint y) -{ - GdkRegionPrivate *private; - - g_return_val_if_fail (region != NULL, 0); - - private = (GdkRegionPrivate *) region; - - return XPointInRegion (private->xregion, x, y); -} - -GdkOverlapType -gdk_region_rect_in (GdkRegion *region, - GdkRectangle *rect) -{ - GdkRegionPrivate *private; - int res; - - g_return_val_if_fail (region != NULL, 0); - - private = (GdkRegionPrivate *) region; - - res = XRectInRegion (private->xregion, rect->x, rect->y, rect->width, rect->height); - - switch (res) - { - case RectangleIn: return GDK_OVERLAP_RECTANGLE_IN; - case RectangleOut: return GDK_OVERLAP_RECTANGLE_OUT; - case RectanglePart: return GDK_OVERLAP_RECTANGLE_PART; - } - - return GDK_OVERLAP_RECTANGLE_OUT; /*what else ? */ -} - -GdkRegion * -gdk_region_polygon (GdkPoint *points, - gint npoints, - GdkFillRule fill_rule) -{ - GdkRegionPrivate *private; - GdkRegion *region; - Region xregion; - gint xfill_rule = EvenOddRule; - - g_return_val_if_fail (points != NULL, NULL); - g_return_val_if_fail (npoints != 0, NULL); /* maybe we should check for at least three points */ - - switch (fill_rule) - { - case GDK_EVEN_ODD_RULE: - xfill_rule = EvenOddRule; - break; - - case GDK_WINDING_RULE: - xfill_rule = WindingRule; - break; - } - - xregion = XPolygonRegion ((XPoint *) points, npoints, xfill_rule); - private = g_new (GdkRegionPrivate, 1); - private->xregion = xregion; - region = (GdkRegion *) private; - region->user_data = NULL; - - return region; -} - -void -gdk_region_offset (GdkRegion *region, - gint dx, - gint dy) -{ - GdkRegionPrivate *private; - - g_return_if_fail (region != NULL); - - private = (GdkRegionPrivate *) region; - - XOffsetRegion (private->xregion, dx, dy); -} - -void -gdk_region_shrink (GdkRegion *region, - gint dx, - gint dy) -{ - GdkRegionPrivate *private; - - g_return_if_fail (region != NULL); - - private = (GdkRegionPrivate *) region; - - XShrinkRegion (private->xregion, dx, dy); -} - -GdkRegion* -gdk_region_union_with_rect (GdkRegion *region, - GdkRectangle *rect) -{ - GdkRegionPrivate *private; - GdkRegion *res; - GdkRegionPrivate *res_private; - XRectangle xrect; - - g_return_val_if_fail (region != NULL, NULL); - - private = (GdkRegionPrivate *) region; - - xrect.x = rect->x; - xrect.y = rect->y; - xrect.width = rect->width; - xrect.height = rect->height; - - res = gdk_region_new (); - res_private = (GdkRegionPrivate *) res; - - XUnionRectWithRegion (&xrect, private->xregion, res_private->xregion); - - return res; -} - -GdkRegion* -gdk_regions_intersect (GdkRegion *source1, - GdkRegion *source2) -{ - GdkRegionPrivate *private1; - GdkRegionPrivate *private2; - GdkRegion *res; - GdkRegionPrivate *res_private; - - g_return_val_if_fail (source1 != NULL, NULL); - g_return_val_if_fail (source2 != NULL, NULL); - - private1 = (GdkRegionPrivate *) source1; - private2 = (GdkRegionPrivate *) source2; - - res = gdk_region_new (); - res_private = (GdkRegionPrivate *) res; - - XIntersectRegion (private1->xregion, private2->xregion, res_private->xregion); - - return res; -} - -GdkRegion* -gdk_regions_union (GdkRegion *source1, - GdkRegion *source2) -{ - GdkRegionPrivate *private1; - GdkRegionPrivate *private2; - GdkRegion *res; - GdkRegionPrivate *res_private; - - g_return_val_if_fail (source1 != NULL, NULL); - g_return_val_if_fail (source2 != NULL, NULL); - - private1 = (GdkRegionPrivate *) source1; - private2 = (GdkRegionPrivate *) source2; - - res = gdk_region_new (); - res_private = (GdkRegionPrivate *) res; - - XUnionRegion (private1->xregion, private2->xregion, res_private->xregion); - - return res; -} - -GdkRegion* -gdk_regions_subtract (GdkRegion *source1, - GdkRegion *source2) -{ - GdkRegionPrivate *private1; - GdkRegionPrivate *private2; - GdkRegion *res; - GdkRegionPrivate *res_private; - - g_return_val_if_fail (source1 != NULL, NULL); - g_return_val_if_fail (source2 != NULL, NULL); - - private1 = (GdkRegionPrivate *) source1; - private2 = (GdkRegionPrivate *) source2; - - res = gdk_region_new (); - res_private = (GdkRegionPrivate *) res; - - XSubtractRegion (private1->xregion, private2->xregion, res_private->xregion); - - return res; -} - -GdkRegion* -gdk_regions_xor (GdkRegion *source1, - GdkRegion *source2) -{ - GdkRegionPrivate *private1; - GdkRegionPrivate *private2; - GdkRegion *res; - GdkRegionPrivate *res_private; - - g_return_val_if_fail (source1 != NULL, NULL); - g_return_val_if_fail (source2 != NULL, NULL); - - private1 = (GdkRegionPrivate *) source1; - private2 = (GdkRegionPrivate *) source2; - - res = gdk_region_new (); - res_private = (GdkRegionPrivate *) res; - - XXorRegion (private1->xregion, private2->xregion, res_private->xregion); - - return res; -} - - - diff --git a/gtk/gtkcolorsel.c b/gtk/gtkcolorsel.c index 26d34078e..61f28f8e9 100644 --- a/gtk/gtkcolorsel.c +++ b/gtk/gtkcolorsel.c @@ -488,9 +488,6 @@ color_sample_new (GtkColorSelection *colorsel) priv = colorsel->private_data; - gtk_widget_push_visual(gdk_rgb_get_visual()); - gtk_widget_push_colormap(gdk_rgb_get_cmap()); - priv->sample_area = gtk_hbox_new (FALSE, 0); priv->old_sample = gtk_drawing_area_new (); priv->cur_sample = gtk_drawing_area_new (); @@ -499,8 +496,6 @@ color_sample_new (GtkColorSelection *colorsel) TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (priv->sample_area), priv->cur_sample, TRUE, TRUE, 0); - gtk_widget_pop_visual(); - gtk_widget_pop_colormap(); gtk_signal_connect(GTK_OBJECT (priv->old_sample), "expose_event", GTK_SIGNAL_FUNC (color_old_sample_expose), diff --git a/gtk/gtkcolorseldialog.c b/gtk/gtkcolorseldialog.c index d1fd6480a..92f1280ca 100644 --- a/gtk/gtkcolorseldialog.c +++ b/gtk/gtkcolorseldialog.c @@ -81,10 +81,7 @@ gtk_color_selection_dialog_init (GtkColorSelectionDialog *colorseldiag) { GtkWidget *action_area_button_box, *frame; - gtk_widget_set_visual (GTK_WIDGET (colorseldiag), gdk_rgb_get_visual ()); gtk_widget_set_colormap (GTK_WIDGET (colorseldiag), gdk_rgb_get_cmap ()); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); gtk_widget_push_colormap (gdk_rgb_get_cmap ()); frame = gtk_frame_new (NULL); @@ -122,7 +119,6 @@ gtk_color_selection_dialog_init (GtkColorSelectionDialog *colorseldiag) gtk_widget_show (colorseldiag->help_button); gtk_widget_pop_colormap (); - gtk_widget_pop_visual (); } GtkWidget* diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c index 0cd1bf863..5f21feff8 100644 --- a/gtk/gtkdnd.c +++ b/gtk/gtkdnd.c @@ -1993,14 +1993,12 @@ gtk_drag_set_icon_pixmap (GdkDragContext *context, gdk_window_get_size (pixmap, &width, &height); - gtk_widget_push_visual (gdk_colormap_get_visual (colormap)); gtk_widget_push_colormap (colormap); window = gtk_window_new (GTK_WINDOW_POPUP); gtk_widget_set_events (window, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE); - gtk_widget_pop_visual (); gtk_widget_pop_colormap (); gtk_widget_set_usize (window, width, height); diff --git a/gtk/gtkgc.c b/gtk/gtkgc.c index 869224025..d001c39da 100644 --- a/gtk/gtkgc.c +++ b/gtk/gtkgc.c @@ -157,6 +157,7 @@ gtk_gc_new (gpointer key) } gc = gdk_gc_new_with_values (drawable->drawable, &keyval->values, keyval->mask); + gdk_gc_set_colormap (gc, keyval->colormap); return (gpointer) gc; } diff --git a/gtk/gtklayout.c b/gtk/gtklayout.c index 499ea186d..f82451941 100644 --- a/gtk/gtklayout.c +++ b/gtk/gtklayout.c @@ -417,7 +417,6 @@ gtk_layout_init (GtkLayout *layout) layout->bin_window = NULL; - layout->configure_serial = 0; layout->scroll_x = 0; layout->scroll_y = 0; layout->visibility = GDK_VISIBILITY_PARTIAL; diff --git a/gtk/gtklayout.h b/gtk/gtklayout.h index 0cf7a12e4..95a338238 100644 --- a/gtk/gtklayout.h +++ b/gtk/gtklayout.h @@ -68,7 +68,6 @@ struct _GtkLayout { GdkWindow *bin_window; GdkVisibilityState visibility; - gulong configure_serial; gint scroll_x; gint scroll_y; diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index e67d3297c..d85872d39 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -188,11 +188,9 @@ static guint widget_signals[LAST_SIGNAL] = { 0 }; static GMemChunk *aux_info_mem_chunk = NULL; static GdkColormap *default_colormap = NULL; -static GdkVisual *default_visual = NULL; static GtkStyle *gtk_default_style = NULL; static GSList *colormap_stack = NULL; -static GSList *visual_stack = NULL; static GSList *style_stack = NULL; static guint composite_child_stack = 0; @@ -208,7 +206,6 @@ static const gchar *saved_default_style_key = "gtk-saved-default-style"; static guint saved_default_style_key_id = 0; static const gchar *shape_info_key = "gtk-shape-info"; static const gchar *colormap_key = "gtk-colormap"; -static const gchar *visual_key = "gtk-visual"; static const gchar *rc_style_key = "gtk-rc-style"; static guint rc_style_key_id = 0; @@ -1005,7 +1002,6 @@ static void gtk_widget_init (GtkWidget *widget) { GdkColormap *colormap; - GdkVisual *visual; GTK_PRIVATE_FLAGS (widget) = 0; widget->state = GTK_STATE_NORMAL; @@ -1030,13 +1026,9 @@ gtk_widget_init (GtkWidget *widget) gtk_style_ref (widget->style); colormap = gtk_widget_peek_colormap (); - visual = gtk_widget_peek_visual (); if (colormap != gtk_widget_get_default_colormap ()) gtk_widget_set_colormap (widget, colormap); - - if (visual != gtk_widget_get_default_visual ()) - gtk_widget_set_visual (widget, visual); } /***************************************** @@ -3585,24 +3577,9 @@ gtk_widget_get_colormap (GtkWidget *widget) GdkVisual* gtk_widget_get_visual (GtkWidget *widget) { - GdkVisual *visual; - - g_return_val_if_fail (widget != NULL, NULL); g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - - if (widget->window) - { - visual = gdk_window_get_visual (widget->window); - /* If window was destroyed previously, we'll get NULL here */ - if (visual) - return visual; - } - - visual = gtk_object_get_data (GTK_OBJECT (widget), visual_key); - if (visual) - return visual; - return gtk_widget_get_default_visual (); + return gdk_colormap_get_visual (gtk_widget_get_colormap (widget)); } /***************************************** @@ -3634,31 +3611,6 @@ gtk_widget_set_colormap (GtkWidget *widget, GdkColormap *colormap) } /***************************************** - * gtk_widget_set_visual: - * Set the colormap for the widget to the given - * value. Widget must not have been previously - * realized. This probably should only be used - * from an init() function. - * arguments: - * widget: - * visual: - * results: - *****************************************/ - -void -gtk_widget_set_visual (GtkWidget *widget, GdkVisual *visual) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (!GTK_WIDGET_REALIZED (widget)); - g_return_if_fail (visual != NULL); - - gtk_object_set_data (GTK_OBJECT (widget), - visual_key, - visual); -} - -/***************************************** * gtk_widget_get_events: * * arguments: @@ -3828,22 +3780,6 @@ gtk_widget_push_colormap (GdkColormap *cmap) } /***************************************** - * gtk_widget_push_visual: - * - * arguments: - * - * results: - *****************************************/ - -void -gtk_widget_push_visual (GdkVisual *visual) -{ - g_return_if_fail (visual != NULL); - - visual_stack = g_slist_prepend (visual_stack, visual); -} - -/***************************************** * gtk_widget_pop_colormap: * * arguments: @@ -3865,27 +3801,6 @@ gtk_widget_pop_colormap (void) } /***************************************** - * gtk_widget_pop_visual: - * - * arguments: - * - * results: - *****************************************/ - -void -gtk_widget_pop_visual (void) -{ - GSList *tmp; - - if (visual_stack) - { - tmp = visual_stack; - visual_stack = visual_stack->next; - g_slist_free_1 (tmp); - } -} - -/***************************************** * gtk_widget_set_default_colormap: * * arguments: @@ -3907,20 +3822,6 @@ gtk_widget_set_default_colormap (GdkColormap *colormap) } /***************************************** - * gtk_widget_set_default_visual: - * - * arguments: - * - * results: - *****************************************/ - -void -gtk_widget_set_default_visual (GdkVisual *visual) -{ - default_visual = visual; -} - -/***************************************** * gtk_widget_get_default_colormap: * * arguments: @@ -3948,10 +3849,7 @@ gtk_widget_get_default_colormap (void) GdkVisual* gtk_widget_get_default_visual (void) { - if (!default_visual) - default_visual = gdk_visual_get_system (); - - return default_visual; + return gdk_colormap_get_visual (gtk_widget_get_default_colormap ()); } /** @@ -4304,9 +4202,7 @@ gtk_widget_peek_colormap (void) static GdkVisual* gtk_widget_peek_visual (void) { - if (visual_stack) - return (GdkVisual*) visual_stack->data; - return gtk_widget_get_default_visual (); + return gdk_colormap_get_visual (gtk_widget_peek_colormap ()); } static void diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index 8fae055e3..ee2dbd4a7 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -548,9 +548,6 @@ GdkVisual* gtk_widget_get_visual (GtkWidget *widget); */ void gtk_widget_set_colormap (GtkWidget *widget, GdkColormap *colormap); -void gtk_widget_set_visual (GtkWidget *widget, - GdkVisual *visual); - gint gtk_widget_get_events (GtkWidget *widget); void gtk_widget_get_pointer (GtkWidget *widget, @@ -595,18 +592,15 @@ void gtk_widget_reset_rc_styles (GtkWidget *widget); */ void gtk_widget_push_style (GtkStyle *style); void gtk_widget_push_colormap (GdkColormap *cmap); -void gtk_widget_push_visual (GdkVisual *visual); void gtk_widget_push_composite_child (void); void gtk_widget_pop_composite_child (void); void gtk_widget_pop_style (void); void gtk_widget_pop_colormap (void); -void gtk_widget_pop_visual (void); /* Set certain default values to be used at widget creation time. */ void gtk_widget_set_default_style (GtkStyle *style); void gtk_widget_set_default_colormap (GdkColormap *colormap); -void gtk_widget_set_default_visual (GdkVisual *visual); GtkStyle* gtk_widget_get_default_style (void); GdkColormap* gtk_widget_get_default_colormap (void); GdkVisual* gtk_widget_get_default_visual (void); diff --git a/gtk/testgtk.c b/gtk/testgtk.c index 4c8fd24e5..d16a659a2 100644 --- a/gtk/testgtk.c +++ b/gtk/testgtk.c @@ -7437,11 +7437,9 @@ create_color_preview (void) if (!window) { - gtk_widget_push_visual (gdk_rgb_get_visual ()); gtk_widget_push_colormap (gdk_rgb_get_cmap ()); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_pop_colormap (); - gtk_widget_pop_visual (); gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC(color_preview_destroy), @@ -8647,6 +8645,13 @@ create_main_window (void) gtk_widget_show_all (window); } +void +pixbuf_init () +{ + if (file_exists ("../gdk-pixbuf/.libs/libpixbufloader-pnm.so")) + putenv ("GDK_PIXBUF_MODULEDIR=../gdk-pixbuf/.libs"); +} + int main (int argc, char *argv[]) { @@ -8654,6 +8659,7 @@ main (int argc, char *argv[]) srand (time (NULL)); + pixbuf_init (); gtk_set_locale (); /* Check to see if we are being run from the correct diff --git a/gtk/testrgb.c b/gtk/testrgb.c index c629598be..3721a6cd6 100644 --- a/gtk/testrgb.c +++ b/gtk/testrgb.c @@ -46,8 +46,8 @@ quit_func (GtkWidget *widget, gpointer dummy) gtk_main_quit (); } -#define WIDTH 320 -#define HEIGHT 200 +#define WIDTH 640 +#define HEIGHT 400 #define NUM_ITERS 100 static void @@ -284,7 +284,6 @@ main (int argc, char **argv) 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 (); diff --git a/tests/testgtk.c b/tests/testgtk.c index 4c8fd24e5..d16a659a2 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -7437,11 +7437,9 @@ create_color_preview (void) if (!window) { - gtk_widget_push_visual (gdk_rgb_get_visual ()); gtk_widget_push_colormap (gdk_rgb_get_cmap ()); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_pop_colormap (); - gtk_widget_pop_visual (); gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC(color_preview_destroy), @@ -8647,6 +8645,13 @@ create_main_window (void) gtk_widget_show_all (window); } +void +pixbuf_init () +{ + if (file_exists ("../gdk-pixbuf/.libs/libpixbufloader-pnm.so")) + putenv ("GDK_PIXBUF_MODULEDIR=../gdk-pixbuf/.libs"); +} + int main (int argc, char *argv[]) { @@ -8654,6 +8659,7 @@ main (int argc, char *argv[]) srand (time (NULL)); + pixbuf_init (); gtk_set_locale (); /* Check to see if we are being run from the correct diff --git a/tests/testrgb.c b/tests/testrgb.c index c629598be..3721a6cd6 100644 --- a/tests/testrgb.c +++ b/tests/testrgb.c @@ -46,8 +46,8 @@ quit_func (GtkWidget *widget, gpointer dummy) gtk_main_quit (); } -#define WIDTH 320 -#define HEIGHT 200 +#define WIDTH 640 +#define HEIGHT 400 #define NUM_ITERS 100 static void @@ -284,7 +284,6 @@ main (int argc, char **argv) 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 (); |