diff options
author | Kevin Walzer <kw@codebykevin.com> | 2015-10-26 11:23:46 (GMT) |
---|---|---|
committer | Kevin Walzer <kw@codebykevin.com> | 2015-10-26 11:23:46 (GMT) |
commit | 59b3eec3567e7cea0ab68d0ce47b667957fea948 (patch) | |
tree | dbee9cbf72a8a3c85d609b425aa0be5929ac7e4d /macosx | |
parent | ef8ab473dbad8f68b0f5ee7dd51202ee2ca02191 (diff) | |
download | tk-59b3eec3567e7cea0ab68d0ce47b667957fea948.zip tk-59b3eec3567e7cea0ab68d0ce47b667957fea948.tar.gz tk-59b3eec3567e7cea0ab68d0ce47b667957fea948.tar.bz2 |
Fix for PNG rendering on OS X 10.11; thanks to Stephan Meier for patch
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/tkMacOSXXStubs.c | 36 |
1 files 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<height; row++, n+=bytes_per_row) { - for (m=n; m<n+bytes_per_row; m+=4) { - *(bitmap+m) = *(image_data+m+2); - *(bitmap+m+1) = *(image_data+m+1); - *(bitmap+m+2) = *(image_data+m); - *(bitmap+m+3) = *(image_data+m+3); + if (bitmap_fmt == 0) { + /* BGRA */ + for (row=0, n=0; row<height; row++, n+=bytes_per_row) { + for (m=n; m<n+bytes_per_row; m+=4) { + *(bitmap+m) = *(image_data+m+2); + *(bitmap+m+1) = *(image_data+m+1); + *(bitmap+m+2) = *(image_data+m); + *(bitmap+m+3) = *(image_data+m+3); + } + } + } else { + /* ABGR */ + for (row=0, n=0; row<height; row++, n+=bytes_per_row) { + for (m=n; m<n+bytes_per_row; m+=4) { + *(bitmap+m) = *(image_data+m+3); + *(bitmap+m+1) = *(image_data+m+2); + *(bitmap+m+2) = *(image_data+m+1); + *(bitmap+m+3) = *(image_data+m); + } } } } |