3 * Copyright (C) 2005 Imendio AB
4 * Copyright (C) 2010 Kristian Rietveld <kris@gtk.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 #include <AppKit/AppKit.h>
26 #include <gdkquartzutils.h>
27 #include "gdkprivate-quartz.h"
30 gdk_quartz_pixbuf_to_ns_image_libgtk_only (GdkPixbuf *pixbuf)
32 NSBitmapImageRep *bitmap_rep;
36 has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
38 /* Create a bitmap image rep */
39 bitmap_rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
40 pixelsWide:gdk_pixbuf_get_width (pixbuf)
41 pixelsHigh:gdk_pixbuf_get_height (pixbuf)
42 bitsPerSample:8 samplesPerPixel:has_alpha ? 4 : 3
43 hasAlpha:has_alpha isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
44 bytesPerRow:0 bitsPerPixel:0];
47 /* Add pixel data to bitmap rep */
49 int src_stride, dst_stride;
52 src_stride = gdk_pixbuf_get_rowstride (pixbuf);
53 dst_stride = [bitmap_rep bytesPerRow];
55 for (y = 0; y < gdk_pixbuf_get_height (pixbuf); y++)
57 src = gdk_pixbuf_get_pixels (pixbuf) + y * src_stride;
58 dst = [bitmap_rep bitmapData] + y * dst_stride;
60 for (x = 0; x < gdk_pixbuf_get_width (pixbuf); x++)
64 guchar red, green, blue, alpha;
71 *dst++ = (red * alpha) / 255;
72 *dst++ = (green * alpha) / 255;
73 *dst++ = (blue * alpha) / 255;
86 image = [[NSImage alloc] init];
87 [image addRepresentation:bitmap_rep];
95 gdk_quartz_event_get_nsevent (GdkEvent *event)
97 /* FIXME: If the event here is unallocated, we crash. */
98 return ((GdkEventPrivate *) event)->windowing_data;