diff options
| author | Manolo Gouy <Manolo> | 2015-07-13 20:43:13 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2015-07-13 20:43:13 +0000 |
| commit | 3283aacf9864201fce65d7122730652e67b11304 (patch) | |
| tree | d4721e07e2fd1f1eb83c880614c1bb6c35c55855 /src | |
| parent | 449e15eceeeb0ee873018464e4c38abd4eb2113e (diff) | |
Prepare for Mac OS 10.11 "El Capitan"
Screen captures produce ARGB data (instead of RGBA until 10.10)
so access to the raw image data takes now this into account.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10789 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_cocoa.mm | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index eef06f753..dee4e1fea 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -50,6 +50,7 @@ extern "C" { #include <math.h> #include <limits.h> #include <dlfcn.h> +#include <string.h> #import <Cocoa/Cocoa.h> @@ -1719,9 +1720,11 @@ void fl_open_display() { selector:@selector(anyWindowWillClose:) name:NSWindowWillCloseNotification object:nil]; - // necessary for secondary pthreads to be allowed to use cocoa, - // especially to create an NSAutoreleasePool. - [NSThread detachNewThreadSelector:nil toTarget:nil withObject:nil]; + if (![NSThread isMultiThreaded]) { + // necessary for secondary pthreads to be allowed to use cocoa, + // especially to create an NSAutoreleasePool. + [NSThread detachNewThreadSelector:nil toTarget:nil withObject:nil]; + } } } @@ -4216,6 +4219,18 @@ static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y, NSBitmapImageRep *childbitmap = rect_to_NSBitmapImageRep(sub, clip.origin.x - sub->x(), win->h() - clip.origin.y - sub->y() - clip.size.height, clip.size.width, clip.size.height); if (childbitmap) { + if ( ([bitmap bitmapFormat] & NSAlphaFirstBitmapFormat) && !([childbitmap bitmapFormat] & NSAlphaFirstBitmapFormat) ) { + // bitmap is ARGB and childbitmap is RGBA --> convert childbitmap to ARGB too + uchar *b = [childbitmap bitmapData]; + for (int i = 0; i < [childbitmap pixelsHigh]; i++) { + for (int j = 0; j < [childbitmap pixelsWide]; j++) { + uchar A = *(b+3); + memmove(b+1, b, 3); + *b = A; + b += 4; + } + } + } // if bitmap is high res and childbitmap is not, childbitmap must be rescaled if ([bitmap pixelsWide] > w && [childbitmap pixelsWide] == clip.size.width) childbitmap = scale_nsbitmapimagerep(childbitmap, 2); write_bitmap_inside(bitmap, w, childbitmap, @@ -4241,6 +4256,17 @@ unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w int bpr = (int)[bitmap bytesPerRow]; int hh = bpp/bpr; // sometimes hh = h-1 for unclear reason, and hh = 2*h with retina int ww = bpr/(*bytesPerPixel); // sometimes ww = w-1, and ww = 2*w with retina + if ([bitmap bitmapFormat] & NSAlphaFirstBitmapFormat) { // imagerep is ARGB --> convert it to RGBA + uchar *b = [bitmap bitmapData]; + for (int i = 0; i < hh; i++) { + for (int j = 0; j < ww; j++) { + uchar A = *b; + memmove(b, b+1, 3); + *(b+3) = A; + b += 4; + } + } + } unsigned char *data; if (ww > w) { // with a retina display Fl_RGB_Image *rgb = new Fl_RGB_Image([bitmap bitmapData], ww, hh, 4); |
