quartz: move utils to gdkutils-quartz.c

This commit is contained in:
Kristian Rietveld
2010-12-23 13:14:49 +01:00
parent f15934bd66
commit fb8717f722
4 changed files with 101 additions and 78 deletions

View File

@ -250,70 +250,6 @@ _gdk_quartz_display_get_cursor_for_type (GdkDisplay *display,
return gdk_quartz_cursor_new_from_nscursor (nscursor, cursor_type);
}
static NSImage *
_gdk_quartz_pixbuf_to_ns_image (GdkPixbuf *pixbuf)
{
NSBitmapImageRep *bitmap_rep;
NSImage *image;
gboolean has_alpha;
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
/* Create a bitmap image rep */
bitmap_rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:gdk_pixbuf_get_width (pixbuf)
pixelsHigh:gdk_pixbuf_get_height (pixbuf)
bitsPerSample:8 samplesPerPixel:has_alpha ? 4 : 3
hasAlpha:has_alpha isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:0 bitsPerPixel:0];
{
/* Add pixel data to bitmap rep */
guchar *src, *dst;
int src_stride, dst_stride;
int x, y;
src_stride = gdk_pixbuf_get_rowstride (pixbuf);
dst_stride = [bitmap_rep bytesPerRow];
for (y = 0; y < gdk_pixbuf_get_height (pixbuf); y++)
{
src = gdk_pixbuf_get_pixels (pixbuf) + y * src_stride;
dst = [bitmap_rep bitmapData] + y * dst_stride;
for (x = 0; x < gdk_pixbuf_get_width (pixbuf); x++)
{
if (has_alpha)
{
guchar red, green, blue, alpha;
red = *src++;
green = *src++;
blue = *src++;
alpha = *src++;
*dst++ = (red * alpha) / 255;
*dst++ = (green * alpha) / 255;
*dst++ = (blue * alpha) / 255;
*dst++ = alpha;
}
else
{
*dst++ = *src++;
*dst++ = *src++;
*dst++ = *src++;
}
}
}
}
image = [[NSImage alloc] init];
[image addRepresentation:bitmap_rep];
[bitmap_rep release];
[image autorelease];
return image;
}
GdkCursor *
_gdk_quartz_display_get_cursor_for_pixbuf (GdkDisplay *display,
@ -330,7 +266,7 @@ _gdk_quartz_display_get_cursor_for_pixbuf (GdkDisplay *display,
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
image = _gdk_quartz_pixbuf_to_ns_image (pixbuf);
image = gdk_quartz_pixbuf_to_ns_image_libgtk_only (pixbuf);
nscursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(x, y)];
cursor = gdk_quartz_cursor_new_from_nscursor (nscursor, GDK_CURSOR_IS_PIXMAP);
@ -432,9 +368,3 @@ gdk_quartz_cursor_get_image (GdkCursor *cursor)
/* FIXME: Implement */
return NULL;
}
NSImage *
gdk_quartz_pixbuf_to_ns_image_libgtk_only (GdkPixbuf *pixbuf)
{
return _gdk_quartz_pixbuf_to_ns_image (pixbuf);
}