From 95613b946d210a097b1b17ad4e08630df72c38fa Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 29 Nov 2021 11:28:40 +0000 Subject: Fix [4ac9d2cfd6]: CGImageFromDrawableRect() not using mac_drawable offsets --- macosx/tkMacOSXImage.c | 1 + 1 file changed, 1 insertion(+) diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index f256d7a..11d42ae 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -656,6 +656,7 @@ CreateCGImageFromDrawableRect( cg_image = CGBitmapContextCreateImage((CGContextRef) cg_context); } } else { + image_rect = CGRectOffset(image_rect, mac_drawable->xOff, mac_drawable->yOff); NSView *view = TkMacOSXGetNSViewForDrawable(mac_drawable); if (view == nil) { TkMacOSXDbgMsg("Invalid source drawable"); -- cgit v0.12 From 1e35e4619b689d0a8bbe6c688302cdcdb025021f Mon Sep 17 00:00:00 2001 From: marc_culler Date: Mon, 29 Nov 2021 16:51:05 +0000 Subject: Remove unnecessary ckalloc. Apple will handle it for us. --- macosx/tkMacOSXImage.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index 11d42ae..60db7d0 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -649,7 +649,6 @@ CreateCGImageFromDrawableRect( CGContextRef cg_context = NULL; CGRect image_rect = CGRectMake(x, y, width, height); CGImageRef cg_image = NULL, result = NULL; - unsigned char *imageData = NULL; if (mac_drawable->flags & TK_IS_PIXMAP) { cg_context = TkMacOSXGetCGContextForDrawable(drawable); if (cg_context) { @@ -667,9 +666,8 @@ CreateCGImageFromDrawableRect( NSUInteger bytesPerPixel = 4, bytesPerRow = bytesPerPixel * view_width, bitsPerComponent = 8; - imageData = ckalloc(view_height * bytesPerRow); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); - cg_context = CGBitmapContextCreate(imageData, view_width, view_height, + cg_context = CGBitmapContextCreate(NULL, view_width, view_height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); @@ -684,7 +682,6 @@ CreateCGImageFromDrawableRect( result = CGImageCreateWithImageInRect(cg_image, image_rect); CGImageRelease(cg_image); } - ckfree(imageData); return result; } -- cgit v0.12 From 4d40e8232d157fc0274a4b44e7946dcbc4840063 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Mon, 29 Nov 2021 17:20:09 +0000 Subject: Don't call CGBitmapContextCreateImage twice for pixmaps. Make the rectangle once and for all. --- macosx/tkMacOSXImage.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index 60db7d0..c952dce 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -647,15 +647,10 @@ CreateCGImageFromDrawableRect( { MacDrawable *mac_drawable = (MacDrawable *)drawable; CGContextRef cg_context = NULL; - CGRect image_rect = CGRectMake(x, y, width, height); CGImageRef cg_image = NULL, result = NULL; if (mac_drawable->flags & TK_IS_PIXMAP) { cg_context = TkMacOSXGetCGContextForDrawable(drawable); - if (cg_context) { - cg_image = CGBitmapContextCreateImage((CGContextRef) cg_context); - } } else { - image_rect = CGRectOffset(image_rect, mac_drawable->xOff, mac_drawable->yOff); NSView *view = TkMacOSXGetNSViewForDrawable(mac_drawable); if (view == nil) { TkMacOSXDbgMsg("Invalid source drawable"); @@ -679,7 +674,9 @@ CreateCGImageFromDrawableRect( CGContextRelease(cg_context); } if (cg_image) { - result = CGImageCreateWithImageInRect(cg_image, image_rect); + CGRect rect = CGRectMake(x + mac_drawable->xOff, y+ mac_drawable->yOff, + width, height); + result = CGImageCreateWithImageInRect(cg_image, rect); CGImageRelease(cg_image); } return result; -- cgit v0.12 From 94be183ea4cb36a60a1fca62b86069742a9878e3 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Mon, 29 Nov 2021 17:33:25 +0000 Subject: Add missing space. --- macosx/tkMacOSXImage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index c952dce..9a1ea45 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -674,7 +674,7 @@ CreateCGImageFromDrawableRect( CGContextRelease(cg_context); } if (cg_image) { - CGRect rect = CGRectMake(x + mac_drawable->xOff, y+ mac_drawable->yOff, + CGRect rect = CGRectMake(x + mac_drawable->xOff, y + mac_drawable->yOff, width, height); result = CGImageCreateWithImageInRect(cg_image, rect); CGImageRelease(cg_image); -- cgit v0.12