Use the [NSimage initWithCGImage:size:] message when possible.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9907 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy
2013-04-30 08:56:28 +00:00
parent dc21195952
commit a2d821cc2e
+13 -7
View File
@@ -2960,6 +2960,16 @@ void Fl_X::collapse() {
static NSImage *CGBitmapContextToNSImage(CGContextRef c) static NSImage *CGBitmapContextToNSImage(CGContextRef c)
// the returned NSImage is autoreleased // the returned NSImage is autoreleased
{ {
NSImage* image;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
if (fl_mac_os_version >= 100600) {
CGImageRef cgimg = CGBitmapContextCreateImage(c); // requires 10.4
image = [[NSImage alloc] initWithCGImage:cgimg size:NSZeroSize]; // requires 10.6
CFRelease(cgimg);
}
else
#endif
{
unsigned char *pdata = (unsigned char *)CGBitmapContextGetData(c); unsigned char *pdata = (unsigned char *)CGBitmapContextGetData(c);
NSBitmapImageRep *imagerep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&pdata NSBitmapImageRep *imagerep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&pdata
pixelsWide:CGBitmapContextGetWidth(c) pixelsWide:CGBitmapContextGetWidth(c)
@@ -2971,8 +2981,9 @@ static NSImage *CGBitmapContextToNSImage(CGContextRef c)
colorSpaceName:NSDeviceRGBColorSpace colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:CGBitmapContextGetBytesPerRow(c) bytesPerRow:CGBitmapContextGetBytesPerRow(c)
bitsPerPixel:CGBitmapContextGetBitsPerPixel(c)]; bitsPerPixel:CGBitmapContextGetBitsPerPixel(c)];
NSImage* image = [[NSImage alloc] initWithData: [imagerep TIFFRepresentation]]; image = [[NSImage alloc] initWithData: [imagerep TIFFRepresentation]];
[imagerep release]; [imagerep release];
}
return [image autorelease]; return [image autorelease];
} }
@@ -3275,12 +3286,7 @@ int Fl::dnd(void)
[mypasteboard setData:(NSData*)text forType:@"public.utf8-plain-text"]; [mypasteboard setData:(NSData*)text forType:@"public.utf8-plain-text"];
CFRelease(text); CFRelease(text);
Fl_Widget *w = Fl::pushed(); Fl_Widget *w = Fl::pushed();
Fl_Window *win = w->window(); Fl_Window *win = w->top_window();
if (win == NULL) {
win = (Fl_Window*)w;
} else {
while(win->window()) win = win->window();
}
NSView *myview = [Fl_X::i(win)->xid contentView]; NSView *myview = [Fl_X::i(win)->xid contentView];
NSEvent *theEvent = [NSApp currentEvent]; NSEvent *theEvent = [NSApp currentEvent];