From af1b34d494ee6821d45b439d5c33a7312d287bed Mon Sep 17 00:00:00 2001 From: Richard Hult Date: Thu, 30 Aug 2007 07:57:25 +0000 Subject: [PATCH] Patch from Stefan Gehn to implement copying from a pixmap, bug #348493. 2007-08-30 Richard Hult * gdk/quartz/gdkimage-quartz.c: (_gdk_quartz_image_copy_to_image): Patch from Stefan Gehn to implement copying from a pixmap, bug #348493. svn path=/trunk/; revision=18702 --- ChangeLog | 6 +++ gdk/quartz/gdkimage-quartz.c | 78 +++++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d2d1a0280..945dd498d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-08-30 Richard Hult + + * gdk/quartz/gdkimage-quartz.c: (_gdk_quartz_image_copy_to_image): + Patch from Stefan Gehn to implement copying from a pixmap, bug + #348493. + 2007-08-29 Kristian Rietveld * gtk/gtksettings.c: lower the default timeout values for diff --git a/gdk/quartz/gdkimage-quartz.c b/gdk/quartz/gdkimage-quartz.c index ed10d8abc..1d5092d32 100644 --- a/gdk/quartz/gdkimage-quartz.c +++ b/gdk/quartz/gdkimage-quartz.c @@ -49,7 +49,83 @@ _gdk_quartz_image_copy_to_image (GdkDrawable *drawable, if (GDK_IS_PIXMAP_IMPL_QUARTZ (drawable)) { - g_warning ("Copying a pixmap to an image is not implemented yet."); + GdkPixmapImplQuartz *pix_impl; + gint bytes_per_row; + guchar *data; + int x, y; + + pix_impl = GDK_PIXMAP_IMPL_QUARTZ (drawable); + data = (guchar *)(pix_impl->data); + + if (src_x + width > pix_impl->width || src_y + height > pix_impl->height) + { + g_warning ("Out of bounds copy-area for pixmap -> image conversion\n"); + return image; + } + + switch (gdk_drawable_get_depth (drawable)) + { + case 24: + bytes_per_row = pix_impl->width * 4; + for (y = 0; y < height; y++) + { + guchar *src = data + ((y + src_y) * bytes_per_row) + (src_x * 4); + + for (x = 0; x < width; x++) + { + gint32 pixel; + + /* RGB24, 4 bytes per pixel, skip first. */ + pixel = src[0] << 16 | src[1] << 8 | src[2]; + src += 4; + + gdk_image_put_pixel (image, dest_x + x, dest_y + y, pixel); + } + } + break; + + case 32: + bytes_per_row = pix_impl->width * 4; + for (y = 0; y < height; y++) + { + guchar *src = data + ((y + src_y) * bytes_per_row) + (src_x * 4); + + for (x = 0; x < width; x++) + { + gint32 pixel; + + /* ARGB32, 4 bytes per pixel. */ + pixel = src[0] << 24 | src[1] << 16 | src[2] << 8 | src[3]; + src += 4; + + gdk_image_put_pixel (image, dest_x + x, dest_y + y, pixel); + } + } + break; + + case 1: /* TODO: optimize */ + bytes_per_row = pix_impl->width; + for (y = 0; y < height; y++) + { + guchar *src = data + ((y + src_y) * bytes_per_row) + src_x; + + for (x = 0; x < width; x++) + { + gint32 pixel; + + /* 8 bits */ + pixel = src[0]; + src++; + + gdk_image_put_pixel (image, dest_x + x, dest_y + y, pixel); + } + } + break; + + default: + g_warning ("Unsupported bit depth %d\n", gdk_drawable_get_depth (drawable)); + return image; + } } else if (GDK_IS_WINDOW_IMPL_QUARTZ (drawable)) {