Author: manolo
Date: 2012-09-17 02:16:25 -0700 (Mon, 17 Sep 2012)
New Revision: 9681
Log:
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.
Modified:
branches/branch-3.0/src/fltk3/cocoa.mm
Modified: branches/branch-3.0/src/fltk3/cocoa.mm
===================================================================
--- branches/branch-3.0/src/fltk3/cocoa.mm 2012-09-17 09:00:22 UTC (rev
9680)
+++ branches/branch-3.0/src/fltk3/cocoa.mm 2012-09-17 09:16:25 UTC (rev
9681)
@@ -3077,10 +3077,10 @@
return true;
}
-unsigned char *Fl_X::bitmap_from_window_rect(fltk3::Window *win, int x, int y,
int w, int h, int *bytesPerPixel)
-// delete the returned pointer after use
+static NSBitmapImageRep* rect_to_NSBitmapImageRep(fltk3::Window *win, int x,
int y, int w, int h)
+// release the returned value after use
{
- while(win->window()) {
+ while (win->window()) {
x += win->x();
y += win->y();
win = win->window();
@@ -3091,7 +3091,13 @@
// left pixel column are not read, and bitmap is read shifted by one pixel
in both directions.
// Under 10.5, we want no offset.
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(fltk3::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;
int bpp = (int)[bitmap bytesPerPlane];
int bpr = (int)[bitmap bytesPerRow];
@@ -3107,7 +3113,7 @@
memcpy(q, p, *bytesPerPixel * ww);
p += bpr;
q += w * *bytesPerPixel;
- }
+ }
}
[bitmap release];
return data;
@@ -3121,16 +3127,24 @@
CGImageRef Fl_X::CGImage_from_window_rect(fltk3::Window *win, int x, int y,
int w, int h)
// CFRelease the returned CGImageRef after use
{
- int bpp;
- unsigned char *bitmap = bitmap_from_window_rect(win, x, y, w, h, &bpp);
CGImageRef img;
- 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);
+ if (fl_mac_os_version >= 100500) {
+ NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(win, x, y, w, h);
+ img = [bitmap CGImage]; // requires Mac OS 10.5
+ CGImageRetain(img);
+ [bitmap release];
+ }
+ 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;
}
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit