Re: bitmap caching issue (was: settings to build for 10.5 on 10.6?)
Re: bitmap caching issue (was: settings to build for 10.5 on 10.6?)
- Subject: Re: bitmap caching issue (was: settings to build for 10.5 on 10.6?)
- From: Ken Ferry <email@hidden>
- Date: Sun, 20 Sep 2009 16:21:37 -0700
On Sun, Sep 20, 2009 at 3:22 PM, Rob Keniger <email@hidden> wrote:
>
> On 21/09/2009, at 7:22 AM, Ken Ferry wrote:
>
> Well, yes, but copying the data out one way or another is probably safer.
>> :-)
>>
>> Once you've passed a CGImage to some other API, you really don't know how
>> long it'll survive, so it's hard to say when it would be safe to release
>> the
>> NSBitmapImageRep.
>>
>
>
> So would this be acceptable on 10.5/GC?
>
> @implementation NSBitmapImageRep (Additions)
> - (CGImageRef)safeCGImage
> {
> CGImageRef cgImage = [self CGImage];
> return (CGImageRef) CFMakeCollectable(CGImageCreateCopy(cgImage));
> }
> @end
>
>
Ah, I forgot about CGImageCreateCopy.
No, as noted in the header,
/* Return a copy of `image'. Only the image structure itself is copied; the
underlying data is not. */
I'm not sure when you _would_ want to use CGImageCreateCopy, actually.
This would do it, I think:
@implementation NSBitmapImageRep (SafeCGImage)
- (CGImageRef)safeCGImage
{
CGImageRef safeCGImage;
if ([self respondsToSelector:@selector(CGImageForProposedRect:context:
hints:)]) {
safeCGImage = [self CGImageForProposedRect:NULL context:nil hints:
nil];
} else {
CGImageRef unsafeCGImage = [self CGImage];
CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider
(unsafeCGImage));
CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData
(data);
safeCGImage = CGImageCreate(CGImageGetWidth(unsafeCGImage),
CGImageGetHeight(unsafeCGImage),
CGImageGetBitsPerComponent
(unsafeCGImage),
CGImageGetBitsPerPixel(unsafeCGImage),
CGImageGetBytesPerRow(unsafeCGImage),
CGImageGetColorSpace(unsafeCGImage),
CGImageGetBitmapInfo(unsafeCGImage),
dataProvider,
CGImageGetDecode(unsafeCGImage),
CGImageGetShouldInterpolate
(unsafeCGImage),
CGImageGetRenderingIntent
(unsafeCGImage));
safeCGImage = (CGImageRef)[NSMakeCollectable(safeCGImage)
autorelease];
CFRelease(dataProvider);
CFRelease(data);
}
return safeCGImage;
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden