diff options
author | culler <culler@noemail.net> | 2017-11-14 06:12:12 (GMT) |
---|---|---|
committer | culler <culler@noemail.net> | 2017-11-14 06:12:12 (GMT) |
commit | 8d7cbbd23683c3959e762c8afbc894efb2fa4077 (patch) | |
tree | 85bb4b51230a36e6aaa22197cda7746ad85696f0 | |
parent | f09366edb0e8306fb86b75d642c1f7edebeb4027 (diff) | |
download | tk-8d7cbbd23683c3959e762c8afbc894efb2fa4077.zip tk-8d7cbbd23683c3959e762c8afbc894efb2fa4077.tar.gz tk-8d7cbbd23683c3959e762c8afbc894efb2fa4077.tar.bz2 |
Implemented a more robust and transparent scheme for making
sure that iconphoto images are not blended with a black background.
FossilOrigin-Name: f73e7d222226c063d238608005411b38126d37da08db5760c0de02f7027e0475
-rw-r--r-- | macosx/tkMacOSXDraw.c | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXImage.c | 27 | ||||
-rw-r--r-- | macosx/tkMacOSXInt.h | 1 |
3 files changed, 14 insertions, 16 deletions
diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c index 3d21507..90ebd54 100644 --- a/macosx/tkMacOSXDraw.c +++ b/macosx/tkMacOSXDraw.c @@ -440,8 +440,10 @@ TkMacOSXGetNSImageWithTkImage( int height) { Pixmap pixmap = Tk_GetPixmap(display, None, width, height, 0); + MacDrawable *macDraw = (MacDrawable *) pixmap; NSImage *nsImage; + macDraw->flags |= TK_DO_NOT_BLEND; Tk_RedrawImage(image, 0, 0, width, height, pixmap, 0, 0); nsImage = CreateNSImageWithPixmap(pixmap, width, height); Tk_FreePixmap(display, pixmap); diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index 02e8c54..adcb0f5 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -160,25 +160,20 @@ XGetImage( unsigned int bytes_per_row, size, row, n, m; unsigned int scalefactor=1, scaled_height=height, scaled_width=width; NSWindow *win = TkMacOSXDrawableWindow(drawable); - TkWindow *winPtr = TkMacOSXGetTkWindow(win); + MacDrawable *macDraw = ((MacDrawable*)drawable); static enum {unknown, no, yes} has_retina = unknown; - if (win && !winPtr) { + if (macDraw->flags & TK_DO_NOT_BLEND) { /* - * If this drawable has an associated NSWindow but does not have an - * associated Tk window then it must be a dock icon. We are being - * called by TkImgPhotoDisplay because it is displaying a photoimage - * with an alpha channel, e.g. one generated from a png file, as the - * dock icon. It is asking us to create a pixmap for the rectangle - * where the image will be drawn so that it can blend the photoimage - * with its background using the alpha values. But in the case of a - * dock icon, that background will be black, not transparent as it - * should be. - * - * By returning NULL here, we force TkImgPhotoDisplay to give up on - * trying to blend, and just copy the image pixels to the screen. That - * does the right thing for a dock icon, as it happens. - */ + * When called by TkImgPhotoDisplay we are being asked to return a + * background image to be blended with the photoimage using its alpha + * channel, if it has one. Returning NULL here makes TkImgPhotoDisplay + * simply copy the image data, including the alpha channel, rather than + * do any blending. For example, when creating an iconphoto from a + * photoimage with transparency we will be passed a newly created + * pixmap filled with black pixels. These should not be blended with + * the pixels in the photoimage. + */ return NULL; } diff --git a/macosx/tkMacOSXInt.h b/macosx/tkMacOSXInt.h index 6971e26..eb280a6 100644 --- a/macosx/tkMacOSXInt.h +++ b/macosx/tkMacOSXInt.h @@ -87,6 +87,7 @@ typedef struct TkWindowPrivate MacDrawable; #define TK_IS_PIXMAP 0x20 #define TK_IS_BW_PIXMAP 0x40 #define TK_DO_NOT_DRAW 0x80 +#define TK_DO_NOT_BLEND 0x100 /* * I am reserving TK_EMBEDDED = 0x100 in the MacDrawable flags * This is defined in tk.h. We need to duplicate the TK_EMBEDDED flag in the |