summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2017-11-07 17:01:20 +0000
committerManolo Gouy <Manolo>2017-11-07 17:01:20 +0000
commit9aaf6df90c52755ae65a9f17a60334cb6bcf76ba (patch)
tree9a831d26a6bcfe2593bb4972bb5c5fd71d39c453
parent660f4160af4d5a3894c40a75281cf59351bfe09c (diff)
MacOS: fix capture of window titlebar under MacOS 10.13 "High Sierra"
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12547 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--src/Fl_cocoa.mm16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 85f8e8e4e..dfdbff8e1 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -4335,9 +4335,25 @@ void Fl_Cocoa_Window_Driver::capture_titlebar_and_borders(Fl_Shared_Image*& top,
uchar *rgba = new uchar[4 * w() * htop * 4];
CGContextRef auxgc = CGBitmapContextCreate(rgba, 2 * w(), 2 * htop, 8, 8 * w(), cspace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(cspace);
+ memset(rgba, 0xff, 4 * w() * htop * 4); // initialize to opaque white
CGContextScaleCTM(auxgc, 2, 2);
if (layer) {
Fl_Cocoa_Window_Driver::draw_layer_to_context(layer, auxgc, w(), htop);
+ if (fl_mac_os_version >= 101300) {
+ // drawn layer is left transparent and alpha-premultiplied: demultiply it and set it opaque.
+ uchar *p = rgba;
+ uchar *last = rgba + 4 * w() * htop * 4;
+ while (p < last) {
+ uchar q = *(p+3);
+ if (q) {
+ float m = 255./q;
+ *p++ *= m;
+ *p++ *= m;
+ *p++ *= m;
+ *p++ = 0xff;
+ } else p += 4;
+ }
+ }
} else {
CGImageRef img = CGImage_from_window_rect(0, -htop, w(), htop);
CGContextSaveGState(auxgc);