Re: Best way to save a CIImage to disk
Re: Best way to save a CIImage to disk
- Subject: Re: Best way to save a CIImage to disk
- From: Sandy McGuffog <email@hidden>
- Date: Tue, 5 May 2009 20:19:31 +1000
I also had (have actually) this problem. The issue appears to be that
CoreImage seems to do its own caching. If you watch the retain counts
on the underlying image data that you pass to CoreImage, it leave
retains in place for a long time. Under testing, when I repeatedly
passed an image with the same underlying data to CoreImage, the retain
count went to 31, then stayed at 31, which to me indicates some kind
of a caching mechanism. Even more interesting, this occurs even if the
calls are wrapped in a autorelease pool(!). If you pass different
images however, releases occur more often - it looks like CoreImage
does some kind of monitoring of memory, and adjusts its behavior
accordingly.
Sandy
I have not found any way to change this behavior.
On 05 May 2009, at 2:12 PM, Michael Ash wrote:
On Mon, May 4, 2009 at 4:58 PM, Jan-Willem Buurlage
<email@hidden> wrote:
I'm running a CIImage through some CIFilters, and I want to save the
returned CIImage to disk. Everything is very fast up until the
point where I
try to actually save the image. I first create an NSBitmapImageRep
with my
CIImage, get the needed NSData from that object, and then save it
to disk.
Not only is this incredibly slow, Instrument shows that the memory
gets
filled up extremely fast as well. In fact, when I input a couple
dozen files
into my program it takes longer and longer for it to process them,
and
eventually the application just freezes.
Here's the relevant code:
for(NSString* file in fileArray) {
.....
//filter the image
CIImage* result = [self filterImage:source];
//saving to disk
NSBitmapImageRep* rep = [[NSBitmapImageRep alloc]
initWithCIImage:result];
NSData* PNGData = [rep representationUsingType:NSPNGFileType
properties:nil];
[PNGData writeToFile:targetPath atomatically:NO];
....
}
Obviously there must be some better way to do this. And why does my
memory
fill up? The leak must be in these couple of lines. If anyone can
help me
towards the direction I should look in that would be very much
appreciated.
Memory is filling up because of autoreleased objects created during
processing. Add an autorelease pool around your code inside your loop.
Everything is fast until you save the image because CoreImage is built
on lazy evaluation. When you apply filters and such, CoreImage doesn't
actually do any processing. All it does is build a pipeline. It's only
when you actually request the image data in some way, for example by
drawing it or by converting it to an NSBitmapImageRep, that CoreImage
actually does all the image processing and rendering. This code is
slow because that's where all the real work is actually being done.
You can't fix that unless you somehow lighten the load on CoreImage.
Mike
_______________________________________________
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
_______________________________________________
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