diff options
author | Kevin Walzer <kw@codebykevin.com> | 2015-10-26 11:31:06 (GMT) |
---|---|---|
committer | Kevin Walzer <kw@codebykevin.com> | 2015-10-26 11:31:06 (GMT) |
commit | 9581e8b3a106c95baeb4aaa6ee485ce926448fea (patch) | |
tree | 5546ea34ac92346da4843489468c39d873bfcc28 /macosx/tkMacOSXXStubs.c | |
parent | 2eb4e1f43d5b458aa9c4a61b939655b67c499b89 (diff) | |
download | tk-9581e8b3a106c95baeb4aaa6ee485ce926448fea.zip tk-9581e8b3a106c95baeb4aaa6ee485ce926448fea.tar.gz tk-9581e8b3a106c95baeb4aaa6ee485ce926448fea.tar.bz2 |
Fix for PNG rendering on OS X 10.11; thanks to Stephan Meier for patch
Diffstat (limited to 'macosx/tkMacOSXXStubs.c')
-rw-r--r-- | macosx/tkMacOSXXStubs.c | 41 |
1 files 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<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); + } + } + } + } if (bitmap) { imagePtr = XCreateImage(display, NULL, depth, format, offset, (char*)bitmap, width, height, bitmap_pad, bytes_per_row); |