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
+25 -19
View File
@@ -2960,19 +2960,30 @@ void Fl_X::collapse() {
static NSImage *CGBitmapContextToNSImage(CGContextRef c)
// the returned NSImage is autoreleased
{
unsigned char *pdata = (unsigned char *)CGBitmapContextGetData(c);
NSBitmapImageRep *imagerep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&pdata
pixelsWide:CGBitmapContextGetWidth(c)
pixelsHigh:CGBitmapContextGetHeight(c)
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:CGBitmapContextGetBytesPerRow(c)
bitsPerPixel:CGBitmapContextGetBitsPerPixel(c)];
NSImage* image = [[NSImage alloc] initWithData: [imagerep TIFFRepresentation]];
[imagerep release];
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);
NSBitmapImageRep *imagerep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&pdata
pixelsWide:CGBitmapContextGetWidth(c)
pixelsHigh:CGBitmapContextGetHeight(c)
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:CGBitmapContextGetBytesPerRow(c)
bitsPerPixel:CGBitmapContextGetBitsPerPixel(c)];
image = [[NSImage alloc] initWithData: [imagerep TIFFRepresentation]];
[imagerep release];
}
return [image autorelease];
}
@@ -3275,12 +3286,7 @@ int Fl::dnd(void)
[mypasteboard setData:(NSData*)text forType:@"public.utf8-plain-text"];
CFRelease(text);
Fl_Widget *w = Fl::pushed();
Fl_Window *win = w->window();
if (win == NULL) {
win = (Fl_Window*)w;
} else {
while(win->window()) win = win->window();
}
Fl_Window *win = w->top_window();
NSView *myview = [Fl_X::i(win)->xid contentView];
NSEvent *theEvent = [NSApp currentEvent];