Re: GdkBitmap from black & white .png file
On Thu, 2009-02-05 at 16:20 +, gtk-app-devel-list-requ...@gnome.org wrote: > There are functions to convert a PNG with transparency (alpha component) > to a GdkBitmap according to a threshold. See > gdk_pixbuf_render_threshold_alpha() > http://library.gnome.org/devel/gdk/stable/gdk-Pixbufs.html#gdk-pixbuf-render-threshold-alpha > Thank you for this - I have now taken the this approach - adding an alpha channel to a pixbuf created from the .png and then going to xbm format and finally to the GdkBitmap. Richard Shann ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GdkBitmap from black & white .png file
Le samedi 31 janvier 2009 à 20:11 +, Richard Shann a écrit : > The Gdk functions to create bitmaps from data require xbm or xpm data. > (For example gdk_bitmap_create_from_data ()). Why do I not see anything > to create a bitmap from a (b&w) .png image? There are functions to convert a PNG with transparency (alpha component) to a GdkBitmap according to a threshold. See gdk_pixbuf_render_threshold_alpha() http://library.gnome.org/devel/gdk/stable/gdk-Pixbufs.html#gdk-pixbuf-render-threshold-alpha BTW, here is a function (not tested) adapted from some code I wrote, which should create a GdkBitmap from a GdkPixbuf according to your black and white PNG. Feel free to test and fix it. /* * Author: Yann Droneaud * */ GdkBitmap * my_gdk_bitmap_new_from_pixbuf_non_alpha(GdkDrawable *drawable, GdkPixbuf *pixbuf) { int width; int height; int rowstride; guchar *pixels; guint32 pixel; gchar *bitmap_data; int bitmap_rowstride; GdkBitmap *bitmap; g_assert(pixbuf != NULL); g_assert(gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB); g_assert(gdk_pixbuf_get_bits_per_sample(pixbuf) == 8); g_assert(gdk_pixbuf_get_has_alpha(pixbuf)); g_assert(gdk_pixbuf_get_n_channels(pixbuf) == 4); width = gdk_pixbuf_get_width(pixbuf); height = gdk_pixbuf_get_height(pixbuf); rowstride = gdk_pixbuf_get_rowstride(pixbuf); pixels = gdk_pixbuf_get_pixels(pixbuf); /* round to byte boundary */ bitmap_rowbytes = (width + 7) / 8; /* allocate a *cleared* buffer for the bitmap data */ bitmap_data = (gchar *) g_malloc0(bitmap_rowbytes * height); g_assert(bitmap_data != NULL); for(y = 0; y < height; y++) { for(x = 0; x < width; x++) { /* WARNING: use 4 components, 8 bits per component */ pixel = * (guint32 *) &pixels[(y * rowbytes) + (x * 4)]; /* remove alpha component * WARNING: beware of endianess */ pixel &= (guint32) 0xff00UL; /* if not black, it should be white */ if (pixel != (guint32)0UL) { bitmap_data[(y * bitmap_rowbytes) + (x / 8)] |= 1 << (x % 8); } } } bitmap = gdk_bitmap_create_from_data(drawable, bitmap_data, width, height); g_free(bitmap_data); return bitmap; } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
GdkBitmap from black & white .png file
The Gdk functions to create bitmaps from data require xbm or xpm data. (For example gdk_bitmap_create_from_data ()). Why do I not see anything to create a bitmap from a (b&w) .png image? I've used the pixbuf library before, using gdk_draw_pixbuf() but the program I am working on uses a GdkBitmap * mask to draw in the following fashion: gdk_gc_set_clip_mask (gc, mask); gdk_gc_set_clip_origin (gc, x, y); gdk_draw_rectangle (pixmap, gc, TRUE, x, y, width, height); gdk_gc_set_clip_mask (gc, NULL); /* Removes clip mask */ I don't understand the issues here; I want the application to let the user select a (small) rectangular area in the .png image for use in as the GdkBitmap *mask in the above code. Anyone with a wider view on this stuff? Help would be much appreciated! Richard Shann ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list