From 59b3eec3567e7cea0ab68d0ce47b667957fea948 Mon Sep 17 00:00:00 2001 From: Kevin Walzer Date: Mon, 26 Oct 2015 11:23:46 +0000 Subject: Fix for PNG rendering on OS X 10.11; thanks to Stephan Meier for patch --- macosx/tkMacOSXXStubs.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/macosx/tkMacOSXXStubs.c b/macosx/tkMacOSXXStubs.c index e03260f..a5f1c60 100644 --- a/macosx/tkMacOSXXStubs.c +++ b/macosx/tkMacOSXXStubs.c @@ -863,6 +863,7 @@ XGetImage( int format) { NSBitmapImageRep *bitmap_rep; + NSUInteger bitmap_fmt; XImage * imagePtr = NULL; char * bitmap = NULL; char * image_data=NULL; @@ -881,9 +882,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"); @@ -894,9 +896,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; @@ -906,14 +907,27 @@ 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