diff options
author | Kevin Walzer <kw@codebykevin.com> | 2016-07-08 01:22:02 (GMT) |
---|---|---|
committer | Kevin Walzer <kw@codebykevin.com> | 2016-07-08 01:22:02 (GMT) |
commit | 96e1dfb2816cd8f2790d1a533b7065735fd3c7bf (patch) | |
tree | f308562c2bd02d22eb4c19a874ccd2ac7915ee58 /macosx/tkMacOSXDraw.c | |
parent | 246b7967573fb202cdaa688ad24d4e4e402dd934 (diff) | |
download | tk-96e1dfb2816cd8f2790d1a533b7065735fd3c7bf.zip tk-96e1dfb2816cd8f2790d1a533b7065735fd3c7bf.tar.gz tk-96e1dfb2816cd8f2790d1a533b7065735fd3c7bf.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.c | 49 |
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); } |