diff options
author | Owen Taylor <otaylor@redhat.com> | 2000-07-02 17:03:21 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2000-07-02 17:03:21 +0000 |
commit | 4f1ccca5940937ca184c331e035c71ef84675193 (patch) | |
tree | 686f66036477376e3d6038eb75bd8b4943ec1459 /gdk/gdkpixmap.c | |
parent | 7164c0acb138778fb973b0b48a70ff53d4a6e9b9 (diff) | |
download | gtk+-4f1ccca5940937ca184c331e035c71ef84675193.tar.gz |
Add gdk_rgb_find_color() to get a pixel value using GdkRGB functionality
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.
Diffstat (limited to 'gdk/gdkpixmap.c')
-rw-r--r-- | gdk/gdkpixmap.c | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/gdk/gdkpixmap.c b/gdk/gdkpixmap.c index 70c825f915..96b2c62732 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); +} + |