From a4d07a64e85a1e1f59c15c6faf27e569b267473e Mon Sep 17 00:00:00 2001 From: Kevin Walzer Date: Mon, 26 Oct 2015 11:31:06 +0000 Subject: Fix for PNG rendering on OS X 10.11; thanks to Stephan Meier for patch --- macosx/tkMacOSXXStubs.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/macosx/tkMacOSXXStubs.c b/macosx/tkMacOSXXStubs.c index 0be5416..59c6a56 100644 --- a/macosx/tkMacOSXXStubs.c +++ b/macosx/tkMacOSXXStubs.c @@ -890,6 +890,7 @@ XGetImage( int format) { NSBitmapImageRep *bitmap_rep; + NSUInteger bitmap_fmt; XImage * imagePtr = NULL; char * bitmap = NULL; char * image_data=NULL; @@ -908,9 +909,10 @@ XGetImage( } bitmap_rep = BitmapRepFromDrawableRect(d, x, y,width, height); + bitmap_fmt = [bitmap_rep bitmapFormat]; if ( bitmap_rep == Nil || - [bitmap_rep bitmapFormat] != 0 || + (bitmap_fmt != 0 && bitmap_fmt != 1) || [bitmap_rep samplesPerPixel] != 4 || [bitmap_rep isPlanar] != 0 ) { TkMacOSXDbgMsg("XGetImage: Failed to construct NSBitmapRep"); @@ -921,9 +923,8 @@ XGetImage( NSImage* ns_image = [[NSImage alloc]initWithSize:image_size]; [ns_image addRepresentation:bitmap_rep]; - /* Assume premultiplied nonplanar data with 4 bytes per pixel and alpha last.*/ - if ( [bitmap_rep bitmapFormat] == 0 && - [bitmap_rep isPlanar ] == 0 && +/* Assume premultiplied nonplanar data with 4 bytes per pixel.*/ + if ( [bitmap_rep isPlanar ] == 0 && [bitmap_rep samplesPerPixel] == 4 ) { bytes_per_row = [bitmap_rep bytesPerRow]; size = bytes_per_row*height; @@ -933,18 +934,30 @@ XGetImage( bitmap = ckalloc(size); /* Oddly enough, the bitmap has the top row at the beginning, - and the pixels are in BGRA format. + and the pixels are in BGRA or ABGR format. */ - for (row=0, n=0; row