2 * creates an ArtPixBuf from a Drawable
5 * Cody Russell <bratsche@dfw.net>
12 #include "gdk-pixbuf.h"
13 #include "gdk-pixbuf-drawable.h"
15 /* private function */
18 art_pixbuf_from_drawable_core (GdkWindow *window,
20 gint width, gint height,
25 GdkColormap *colormap;
34 g_return_val_if_fail (window != NULL, NULL);
36 image = gdk_image_get (window, x, y, width, height);
37 colormap = gdk_rgb_get_cmap ();
39 fatness = with_alpha ? 4 : 3;
40 rowstride = width * fatness;
42 buff = art_alloc (rowstride * height);
56 for (yy = 0; yy < height; yy++)
58 for (xx = 0; xx < width; xx++)
60 pixel = gdk_image_get_pixel (image, xx, yy);
61 pixels[0] = colormap->colors[pixel].red;
62 pixels[1] = colormap->colors[pixel].green;
63 pixels[2] = colormap->colors[pixel].blue;
74 for (yy = 0; yy < height; yy++)
76 for (xx = 0; xx < width; xx++)
78 pixel = gdk_image_get_pixel (image, xx, yy);
79 r = (pixel >> 8) & 0xf8;
80 g = (pixel >> 3) & 0xfc;
81 b = (pixel << 3) & 0xf8;
86 pixels[3] = 0; /* GdkImages don't have alpha =) */
94 for (yy = 0; yy < height; yy++)
96 for (xx = 0; xx < width; xx++)
98 pixel = gdk_image_get_pixel (image, xx, yy);
99 r = (pixel >> 16) & 0xff;
100 g = (pixel >> 8) & 0xff;
106 pixels[3] = 0; /* GdkImages don't have alpha.. */
113 g_error ("art_pixbuf_from_drawable_core (): Unknown depth.");
116 return with_alpha ? art_pixbuf_new_rgba (buff, width, height, rowstride) :
117 art_pixbuf_new_rgb (buff, width, height, rowstride);
120 /* Public functions */
123 art_pixbuf_rgb_from_drawable (GdkWindow *window,
125 gint width, gint height)
127 return art_pixbuf_from_drawable_core (window, x, y, width, height, 0);
131 art_pixbuf_rgba_from_drawable (GdkWindow *window,
133 gint width, gint height)
135 return art_pixbuf_from_drawable_core (window, x, y, width, height, 1);