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: Michael Ash <email@hidden>
- Date: Tue, 5 May 2009 00:12:08 -0400
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