diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-03-02 12:58:33 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-03-02 12:58:33 (GMT) |
commit | bb096f3cd77b4f603783bda15ad76eca335f185d (patch) | |
tree | 10abf14f24e070c989c3d5b02ebe914bbf464655 /macosx/tkMacOSXImage.c | |
parent | ab53264f81aa19db3d154d1a21b4d233c71634ef (diff) | |
parent | e09be91bbab4de3be2f23c5ba57fbdd242942313 (diff) | |
download | tk-bb096f3cd77b4f603783bda15ad76eca335f185d.zip tk-bb096f3cd77b4f603783bda15ad76eca335f185d.tar.gz tk-bb096f3cd77b4f603783bda15ad76eca335f185d.tar.bz2 |
Merge 8.7
Diffstat (limited to 'macosx/tkMacOSXImage.c')
-rw-r--r-- | macosx/tkMacOSXImage.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index 20abdcd..db56d52 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -145,25 +145,28 @@ TkMacOSXCreateCGImageWithXImage( bitsPerComponent = 1; bitsPerPixel = 1; - if (image->bitmap_bit_order != MSBFirst) { - char *srcPtr = image->data + image->xoffset; - char *endPtr = srcPtr + len; - char *destPtr = (data = (char *)ckalloc(len)); + data = (char *)ckalloc(len); + if (data) { + if (image->bitmap_bit_order != MSBFirst) { + char *srcPtr = image->data + image->xoffset; + char *endPtr = srcPtr + len; + char *destPtr = data; - while (srcPtr < endPtr) { - *destPtr++ = xBitReverseTable[(unsigned char)(*(srcPtr++))]; + while (srcPtr < endPtr) { + *destPtr++ = xBitReverseTable[(unsigned char)(*(srcPtr++))]; + } + } else { + memcpy(data, image->data + image->xoffset, len); } - } else { - data = (char *)memcpy(ckalloc(len), image->data + image->xoffset, len); - } - if (data) { provider = CGDataProviderCreateWithData(data, data, len, releaseData); - } - if (provider) { + if (!provider) { + ckfree(data); + } img = CGImageMaskCreate(image->width, image->height, bitsPerComponent, bitsPerPixel, image->bytes_per_line, provider, decode, 0); + CGDataProviderRelease(provider); } } else if ((image->format == ZPixmap) && (image->bits_per_pixel == 32)) { @@ -171,8 +174,6 @@ TkMacOSXCreateCGImageWithXImage( * Color image */ - CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); - if (image->width == 0 && image->height == 0) { /* @@ -181,19 +182,22 @@ TkMacOSXCreateCGImageWithXImage( return NULL; } + CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); bitsPerComponent = 8; bitsPerPixel = 32; bitmapInfo = kCGBitmapByteOrder32Big | alphaInfo; - data = (char *)memcpy(ckalloc(len), image->data + image->xoffset, len); + data = (char *)ckalloc(len); if (data) { + memcpy(data, image->data + image->xoffset, len); provider = CGDataProviderCreateWithData(data, data, len, releaseData); - } - if (provider) { + if (!provider) { + ckfree(data); + } img = CGImageCreate(image->width, image->height, bitsPerComponent, bitsPerPixel, image->bytes_per_line, colorspace, bitmapInfo, provider, decode, 0, kCGRenderingIntentDefault); - CFRelease(provider); + CGDataProviderRelease(provider); } if (colorspace) { CFRelease(colorspace); @@ -636,6 +640,7 @@ CreateCGImageFromDrawableRect( CGImageRef cg_image = NULL, result = NULL; if (mac_drawable->flags & TK_IS_PIXMAP) { cg_context = TkMacOSXGetCGContextForDrawable(drawable); + CGContextRetain(cg_context); } else { NSView *view = TkMacOSXGetNSViewForDrawable(mac_drawable); if (view == nil) { |