1999-10-07 05:11:27 +00:00
|
|
|
/*
|
|
|
|
* creates an ArtPixBuf from a Drawable
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Cody Russell <bratsche@dfw.net>
|
|
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <gmodule.h>
|
|
|
|
#include "gdk-pixbuf.h"
|
1999-10-07 06:22:21 +00:00
|
|
|
#include "gdk-pixbuf-drawable.h"
|
1999-10-07 05:11:27 +00:00
|
|
|
|
|
|
|
/* private function */
|
|
|
|
|
1999-10-07 18:20:16 +00:00
|
|
|
static GdkPixBuf *
|
|
|
|
gdk_pixbuf_from_drawable_core (GdkWindow *window,
|
1999-10-07 05:11:27 +00:00
|
|
|
gint x, gint y,
|
|
|
|
gint width, gint height,
|
|
|
|
gint with_alpha)
|
|
|
|
{
|
|
|
|
GdkImage *image;
|
|
|
|
ArtPixBuf *pixbuf;
|
|
|
|
GdkColormap *colormap;
|
|
|
|
art_u8 *buff;
|
|
|
|
art_u8 *pixels;
|
|
|
|
gulong pixel;
|
|
|
|
gint rowstride;
|
|
|
|
art_u8 r, g, b;
|
|
|
|
gint xx, yy;
|
|
|
|
gint fatness;
|
|
|
|
|
|
|
|
g_return_val_if_fail (window != NULL, NULL);
|
|
|
|
|
|
|
|
image = gdk_image_get (window, x, y, width, height);
|
|
|
|
colormap = gdk_rgb_get_cmap ();
|
|
|
|
|
|
|
|
fatness = with_alpha ? 4 : 3;
|
|
|
|
rowstride = width * fatness;
|
|
|
|
|
|
|
|
buff = art_alloc (rowstride * height);
|
|
|
|
pixels = buff;
|
|
|
|
|
|
|
|
switch (image->depth)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
case 8:
|
|
|
|
for (yy = 0; yy < height; yy++)
|
|
|
|
{
|
|
|
|
for (xx = 0; xx < width; xx++)
|
|
|
|
{
|
|
|
|
pixel = gdk_image_get_pixel (image, xx, yy);
|
|
|
|
pixels[0] = colormap->colors[pixel].red;
|
|
|
|
pixels[1] = colormap->colors[pixel].green;
|
|
|
|
pixels[2] = colormap->colors[pixel].blue;
|
|
|
|
if (with_alpha)
|
|
|
|
pixels[3] = 0;
|
|
|
|
pixels += fatness;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 16:
|
|
|
|
case 15:
|
|
|
|
for (yy = 0; yy < height; yy++)
|
|
|
|
{
|
|
|
|
for (xx = 0; xx < width; xx++)
|
|
|
|
{
|
|
|
|
pixel = gdk_image_get_pixel (image, xx, yy);
|
|
|
|
r = (pixel >> 8) & 0xf8;
|
|
|
|
g = (pixel >> 3) & 0xfc;
|
|
|
|
b = (pixel << 3) & 0xf8;
|
|
|
|
pixels[0] = r;
|
|
|
|
pixels[1] = g;
|
|
|
|
pixels[2] = b;
|
|
|
|
if (with_alpha)
|
|
|
|
pixels[3] = 0; /* GdkImages don't have alpha =) */
|
|
|
|
pixels += fatness;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 24:
|
|
|
|
case 32:
|
|
|
|
for (yy = 0; yy < height; yy++)
|
|
|
|
{
|
|
|
|
for (xx = 0; xx < width; xx++)
|
|
|
|
{
|
|
|
|
pixel = gdk_image_get_pixel (image, xx, yy);
|
|
|
|
r = (pixel >> 16) & 0xff;
|
|
|
|
g = (pixel >> 8) & 0xff;
|
|
|
|
b = pixel & 0xff;
|
|
|
|
pixels[0] = r;
|
|
|
|
pixels[1] = g;
|
|
|
|
pixels[2] = b;
|
|
|
|
if (with_alpha)
|
|
|
|
pixels[3] = 0; /* GdkImages don't have alpha.. */
|
|
|
|
pixels += fatness;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_error ("art_pixbuf_from_drawable_core (): Unknown depth.");
|
|
|
|
}
|
|
|
|
|
1999-10-07 18:20:16 +00:00
|
|
|
art_pixbuf = with_alpha ? art_pixbuf_new_rgba (buff, width, height, rowstride) :
|
1999-10-07 05:11:27 +00:00
|
|
|
art_pixbuf_new_rgb (buff, width, height, rowstride);
|
1999-10-07 18:20:16 +00:00
|
|
|
|
|
|
|
return gdk_pixbuf_new(art_pixbuf, NULL);
|
1999-10-07 05:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Public functions */
|
|
|
|
|
1999-10-07 18:20:16 +00:00
|
|
|
GdkPixBuf *
|
|
|
|
gdk_pixbuf_rgb_from_drawable (GdkWindow *window,
|
1999-10-07 05:11:27 +00:00
|
|
|
gint x, gint y,
|
|
|
|
gint width, gint height)
|
|
|
|
{
|
1999-10-07 18:20:16 +00:00
|
|
|
return gdk_pixbuf_from_drawable_core (window, x, y, width, height, 0);
|
1999-10-07 05:11:27 +00:00
|
|
|
}
|
|
|
|
|
1999-10-07 18:20:16 +00:00
|
|
|
GdkPixBuf *
|
|
|
|
gdk_pixbuf_rgba_from_drawable (GdkWindow *window,
|
1999-10-07 05:11:27 +00:00
|
|
|
gint x, gint y,
|
|
|
|
gint width, gint height)
|
|
|
|
{
|
1999-10-07 18:20:16 +00:00
|
|
|
return gdk_pixbuf_from_drawable_core (window, x, y, width, height, 1);
|
1999-10-07 05:11:27 +00:00
|
|
|
}
|