mirror of
https://github.com/fltk/fltk.git
synced 2026-06-01 06:14:28 +08:00
Fix for bug described in fltk.development "fl_scroll not copying all channels on OS X"
http://www.fltk.org/newsgroups.php?s13117+gfltk.development+v13134+T0 Sending the CGImage message to an NSBitmapImageRep object seems to be the solution when Mac OS X >=10.5. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9680 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+27
-13
@@ -3315,10 +3315,10 @@ int Fl::dnd(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel)
|
static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y, int w, int h)
|
||||||
// delete[] the returned pointer after use
|
// release the returned value after use
|
||||||
{
|
{
|
||||||
while(win->window()) {
|
while (win->window()) {
|
||||||
x += win->x();
|
x += win->x();
|
||||||
y += win->y();
|
y += win->y();
|
||||||
win = win->window();
|
win = win->window();
|
||||||
@@ -3329,7 +3329,13 @@ unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w
|
|||||||
// left pixel column are not read, and bitmap is read shifted by one pixel in both directions.
|
// left pixel column are not read, and bitmap is read shifted by one pixel in both directions.
|
||||||
// Under 10.5, we want no offset.
|
// Under 10.5, we want no offset.
|
||||||
NSRect rect = NSMakeRect(x - epsilon, y - epsilon, w, h);
|
NSRect rect = NSMakeRect(x - epsilon, y - epsilon, w, h);
|
||||||
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:rect];
|
return [[NSBitmapImageRep alloc] initWithFocusedViewRect:rect];
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel)
|
||||||
|
// delete[] the returned pointer after use
|
||||||
|
{
|
||||||
|
NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(win, x, y, w, h);
|
||||||
*bytesPerPixel = [bitmap bitsPerPixel]/8;
|
*bytesPerPixel = [bitmap bitsPerPixel]/8;
|
||||||
int bpp = (int)[bitmap bytesPerPlane];
|
int bpp = (int)[bitmap bytesPerPlane];
|
||||||
int bpr = (int)[bitmap bytesPerRow];
|
int bpr = (int)[bitmap bytesPerRow];
|
||||||
@@ -3359,16 +3365,24 @@ static void imgProviderReleaseData (void *info, const void *data, size_t size)
|
|||||||
CGImageRef Fl_X::CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h)
|
CGImageRef Fl_X::CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h)
|
||||||
// CFRelease the returned CGImageRef after use
|
// CFRelease the returned CGImageRef after use
|
||||||
{
|
{
|
||||||
int bpp;
|
|
||||||
unsigned char *bitmap = bitmap_from_window_rect(win, x, y, w, h, &bpp);
|
|
||||||
CGImageRef img;
|
CGImageRef img;
|
||||||
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
|
if (fl_mac_os_version >= 100500) {
|
||||||
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, bitmap, w*h*bpp, imgProviderReleaseData);
|
NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(win, x, y, w, h);
|
||||||
img = CGImageCreate(w, h, 8, 8*bpp, w*bpp, lut,
|
img = [bitmap CGImage]; // requires Mac OS 10.5
|
||||||
bpp == 3 ? kCGImageAlphaNone : kCGImageAlphaLast,
|
CGImageRetain(img);
|
||||||
provider, NULL, false, kCGRenderingIntentDefault);
|
[bitmap release];
|
||||||
CGColorSpaceRelease(lut);
|
}
|
||||||
CGDataProviderRelease(provider);
|
else {
|
||||||
|
int bpp;
|
||||||
|
unsigned char *bitmap = bitmap_from_window_rect(win, x, y, w, h, &bpp);
|
||||||
|
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
|
||||||
|
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, bitmap, w*h*bpp, imgProviderReleaseData);
|
||||||
|
img = CGImageCreate(w, h, 8, 8*bpp, w*bpp, lut,
|
||||||
|
bpp == 3 ? kCGImageAlphaNone : kCGImageAlphaLast,
|
||||||
|
provider, NULL, false, kCGRenderingIntentDefault);
|
||||||
|
CGColorSpaceRelease(lut);
|
||||||
|
CGDataProviderRelease(provider);
|
||||||
|
}
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user