diff options
author | Kevin Walzer <kw@codebykevin.com> | 2016-07-15 10:46:56 (GMT) |
---|---|---|
committer | Kevin Walzer <kw@codebykevin.com> | 2016-07-15 10:46:56 (GMT) |
commit | f7cecfb824dbdba8aed41a87869ce3329b5d7ffa (patch) | |
tree | 5136088d70a7fe010e59b99288f068d4770107b6 /generic | |
parent | 4037f07a53599f2371c0d64a939d356fbe72a67f (diff) | |
download | tk-f7cecfb824dbdba8aed41a87869ce3329b5d7ffa.zip tk-f7cecfb824dbdba8aed41a87869ce3329b5d7ffa.tar.gz tk-f7cecfb824dbdba8aed41a87869ce3329b5d7ffa.tar.bz2 |
Fix for image/alpha rendering under hidpi/Retina displays on Mac OS; thanks to Marc Culler for assistance
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tkImgPhInstance.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/generic/tkImgPhInstance.c b/generic/tkImgPhInstance.c index 666a9b0..bd152f2 100644 --- a/generic/tkImgPhInstance.c +++ b/generic/tkImgPhInstance.c @@ -404,6 +404,9 @@ TkImgPhotoGet( * * Note that Win32 pre-defines those operations that we really need. * + * Note that on MacOS, if the background comes from a Retina display + * then it will be twice as wide and twice as high as the photoimage. + * *---------------------------------------------------------------------- */ @@ -433,7 +436,16 @@ BlendComplexAlpha( unsigned long pixel; unsigned char r, g, b, alpha, unalpha, *masterPtr; unsigned char *alphaAr = iPtr->masterPtr->pix32; - +#if defined(MAC_OSX_TK) + /* Background "pixels" are actually 2^pp x 2^pp blocks of subpixels. Each + * block gets blended with the color of one image pixel. Since we iterate + * over the background subpixels, we reset the width and height to the + * subpixel dimensions of the background image we are using. + */ + int pp = bgImg->pixelpower; + width = width << pp; + height = height << pp; +#endif /* * This blending is an integer version of the Source-Over compositing rule * (see Porter&Duff, "Compositing Digital Images", proceedings of SIGGRAPH @@ -532,9 +544,16 @@ BlendComplexAlpha( #endif /* !_WIN32 && !MAC_OSX_TK */ for (y = 0; y < height; y++) { +# if !defined(MAC_OSX_TK) line = (y + yOffset) * iPtr->masterPtr->width; for (x = 0; x < width; x++) { masterPtr = alphaAr + ((line + x + xOffset) * 4); +#else + /* Repeat each image row and column 2^pp times. */ + line = ((y>>pp) + yOffset) * iPtr->masterPtr->width; + for (x = 0; x < width; x++) { + masterPtr = alphaAr + ((line + (x>>pp) + xOffset) * 4); +#endif alpha = masterPtr[3]; /* @@ -635,7 +654,9 @@ TkImgPhotoDisplay( (unsigned int)width, (unsigned int)height, AllPlanes, ZPixmap); if (bgImg == NULL) { Tk_DeleteErrorHandler(handler); - /* We failed to get the image so draw without blending alpha. It's the best we can do */ + /* We failed to get the image, so draw without blending alpha. + * It's the best we can do. + */ goto fallBack; } |