Mac OS: handle possible NULL return after screen capture attempt.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10078 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2014-01-22 20:39:21 +00:00
parent 4d5e10097e
commit 4eee9f1f63
3 changed files with 10 additions and 5 deletions

View File

@ -3351,6 +3351,7 @@ unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w
*/
{
NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(win, x, y, w, h);
if (bitmap == nil) return NULL;
*bytesPerPixel = [bitmap bitsPerPixel]/8;
int bpp = (int)[bitmap bytesPerPlane];
int bpr = (int)[bitmap bytesPerRow];
@ -3388,6 +3389,7 @@ CGImageRef Fl_X::CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, i
else {
int bpp;
unsigned char *bitmap = bitmap_from_window_rect(win, x, y, w, h, &bpp);
if (!bitmap) return NULL;
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, bitmap, w*h*bpp, imgProviderReleaseData);
img = CGImageCreate(w, h, 8, 8*bpp, w*bpp, lut,

View File

@ -45,6 +45,7 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate
Fl_Window *window = Fl_Window::current();
while(window->window()) window = window->window();
base = Fl_X::bitmap_from_window_rect(window,x,y,w,h,&delta);
if (!base) return NULL;
rowBytes = delta*w;
x = y = 0;
}

View File

@ -143,11 +143,13 @@ void fl_scroll(int X, int Y, int W, int H, int dx, int dy,
#elif defined(__APPLE_QUARTZ__)
CGImageRef img = Fl_X::CGImage_from_window_rect(Fl_Window::current(), src_x, src_y, src_w, src_h);
CGRect rect = { { dest_x, dest_y }, { src_w, src_h } };
Fl_X::q_begin_image(rect, 0, 0, src_w, src_h);
CGContextDrawImage(fl_gc, rect, img);
Fl_X::q_end_image();
CFRelease(img);
if (img) {
CGRect rect = { { dest_x, dest_y }, { src_w, src_h } };
Fl_X::q_begin_image(rect, 0, 0, src_w, src_h);
CGContextDrawImage(fl_gc, rect, img);
Fl_X::q_end_image();
CFRelease(img);
}
#else
# error unsupported platform
#endif