summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXDraw.c
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2016-07-08 01:21:02 (GMT)
committerKevin Walzer <kw@codebykevin.com>2016-07-08 01:21:02 (GMT)
commitc32ea9203392ec7c24b873842e0d0d84b66830cc (patch)
tree3fc26b593439bf9ae9f141acb2196a545405854e /macosx/tkMacOSXDraw.c
parent3ff177d9afa1b11b8c17918825f3265fb4e5dbab (diff)
downloadtk-c32ea9203392ec7c24b873842e0d0d84b66830cc.zip
tk-c32ea9203392ec7c24b873842e0d0d84b66830cc.tar.gz
tk-c32ea9203392ec7c24b873842e0d0d84b66830cc.tar.bz2
Fix for bitmap distortion on Mac OS; thanks to Marc Culler for patch
Diffstat (limited to 'macosx/tkMacOSXDraw.c')
-rw-r--r--macosx/tkMacOSXDraw.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c
index 6a0b409..d9b909b 100644
--- a/macosx/tkMacOSXDraw.c
+++ b/macosx/tkMacOSXDraw.c
@@ -314,29 +314,35 @@ XCopyPlane(
TkpClipMask *clipPtr = (TkpClipMask *) gc->clip_mask;
unsigned long imageBackground = gc->background;
if (clipPtr && clipPtr->type == TKP_CLIP_PIXMAP){
- CGImageRef mask = TkMacOSXCreateCGImageWithDrawable(clipPtr->value.pixmap);
- CGRect rect = CGRectMake(dest_x, dest_y, width, height);
- rect = CGRectOffset(rect, dstDraw->xOff, dstDraw->yOff);
- CGContextSaveGState(context);
- /* Move the origin of the destination to top left. */
- CGContextTranslateCTM(context, 0, rect.origin.y + CGRectGetMaxY(rect));
- CGContextScaleCTM(context, 1, -1);
- /* Fill with the background color, clipping to the mask. */
- CGContextClipToMask(context, rect, mask);
- TkMacOSXSetColorInContext(gc, gc->background, dc.context);
- CGContextFillRect(dc.context, rect);
- /* Fill with the foreground color, clipping to the intersection of img and mask. */
- CGContextClipToMask(context, rect, img);
- TkMacOSXSetColorInContext(gc, gc->foreground, context);
- CGContextFillRect(context, rect);
- CGContextRestoreGState(context);
- CGImageRelease(mask);
- CGImageRelease(img);
+ CGRect srcRect = CGRectMake(src_x, src_y, width, height);
+ CGImageRef mask = TkMacOSXCreateCGImageWithDrawable(clipPtr->value.pixmap);
+ CGImageRef submask = CGImageCreateWithImageInRect(img, srcRect);
+ CGRect rect = CGRectMake(dest_x, dest_y, width, height);
+ rect = CGRectOffset(rect, dstDraw->xOff, dstDraw->yOff);
+ CGContextSaveGState(context);
+ /* Move the origin of the destination to top left. */
+ CGContextTranslateCTM(context, 0, rect.origin.y + CGRectGetMaxY(rect));
+ CGContextScaleCTM(context, 1, -1);
+ /* Fill with the background color, clipping to the mask. */
+ CGContextClipToMask(context, rect, submask);
+ TkMacOSXSetColorInContext(gc, gc->background, dc.context);
+ CGContextFillRect(context, rect);
+ /* Fill with the foreground color, clipping to the
+ intersection of img and mask. */
+ CGImageRef subimage = CGImageCreateWithImageInRect(img, srcRect);
+ CGContextClipToMask(context, rect, subimage);
+ TkMacOSXSetColorInContext(gc, gc->foreground, context);
+ CGContextFillRect(context, rect);
+ CGContextRestoreGState(context);
+ CGImageRelease(img);
+ CGImageRelease(mask);
+ CGImageRelease(submask);
+ CGImageRelease(subimage);
} else {
DrawCGImage(dst, gc, dc.context, img, gc->foreground, imageBackground,
CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height),
- CGRectMake(src_x, src_y, width, height),
- CGRectMake(dest_x, dest_y, width, height));
+ CGRectMake(src_x, src_y, width, height),
+ CGRectMake(dest_x, dest_y, width, height));
CGImageRelease(img);
}
} else { /* no image */
@@ -786,9 +792,6 @@ DrawCGImage(
CGContextDrawImage(context, dstBounds, image);
CGContextRestoreGState(context);
#endif /* TK_MAC_DEBUG_IMAGE_DRAWING */
- /*if (CGImageIsMask(image)) {
- CGContextRestoreGState(context);
- }*/
if (subImage) {
CFRelease(subImage);
}