• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: "Live" image preview, huge memory usage...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Live" image preview, huge memory usage...


  • Subject: Re: "Live" image preview, huge memory usage...
  • From: Jean-Nicolas Jolivet <email@hidden>
  • Date: Wed, 03 Dec 2008 03:22:29 -0500

Thanks a lot for this code Rob!

Quick question (2 actually), right now Im drawing my CIImage in a custom view... would drawing the CIImage in my view's drawRect method achieve the same (leak-free) result as your piece of code??? i.e. something simple like:

// previewImage is an NSBitmapImageRep that exists already..
- (void)drawRect:(NSRect)rect {
CIImage *outputImage = [[CIImage alloc] initWithData:[previewImage TIFFRepresentation]];

[outputImage drawInRect: NSMakeRect(0, 0, [previewImage pixelsWide], [previewImage pixelsHigh])
fromRect:NSMakeRect(0, 0, [previewImage pixelsWide], [previewImage pixelsHigh])
operation:NSCompositeSourceOver
fraction:1.0];

[outputImage release];
}



Second question; my app does batch image processing so eventually I will have to draw those CIImage offscreen.. (only for the Color Control Filter actually)... I assume I have to live with the leak??


J-N

On 3-Dec-08, at 3:10 AM, Rob Keniger wrote:


On 03/12/2008, at 5:34 PM, Jean-Nicolas Jolivet wrote:

Hmm I just found an older post that mentions a big memory leak problem when drawing CIImage offscreen.... I guess I'll have to do this differently...


Ah, you've just reminded me. There is a major leak in drawing CIImage offscreen but you can work around it by rendering to a CGImageRef in the context of the current window.

Here's the code:

//theImage is an existing NSImage
CIImage *outputImage = [CIImage imageWithData:[theImage TIFFRepresentation]];


//to draw the image processed by Core Image, we need to draw into an on-screen graphics context
//this works around a bug in CIImage where drawing in off-screen graphics contexts causes a huge memory leak


//get the current window's graphics context so that we have an on- screen context
//usually we would use any view's window but generically you can just ask for the main window
CIContext *ciContext = [[[NSApp mainWindow] graphicsContext] CIContext];
if(ciContext == nil)
{
NSLog(@"The CIContext of the main window could not be accessed.
Bailing out of the image creation process.");
return;
}


CGAffineTransform transform;
transform = CGAffineTransformMakeTranslation(0.0,[outputImage extent].size.height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
outputImage = [outputImage imageByApplyingTransform:transform];


//render the CIIimage into a CGImageRef in the on-screen context
CGImageRef cgImage = [ciContext createCGImage:outputImage fromRect: [outputImage extent]];
// Draw the CGImageRef into the current context
if (cgImage != NULL)
{
CGContextDrawImage ([[NSGraphicsContext currentContext] graphicsPort], [outputImage extent], cgImage);
CGImageRelease (cgImage);
}


--
Rob Keniger



_______________________________________________

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

Jean-Nicolas Jolivet email@hidden http://www.silverscripting.com

_______________________________________________

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


  • Follow-Ups:
    • Re: "Live" image preview, huge memory usage...
      • From: Rob Keniger <email@hidden>
References: 
 >"Live" image preview, huge memory usage... (From: Jean-Nicolas Jolivet <email@hidden>)
 >Re: "Live" image preview, huge memory usage... (From: glenn andreas <email@hidden>)
 >Re: "Live" image preview, huge memory usage... (From: Jean-Nicolas Jolivet <email@hidden>)
 >Re: "Live" image preview, huge memory usage... (From: douglas welton <email@hidden>)
 >Re: "Live" image preview, huge memory usage... (From: Jean-Nicolas Jolivet <email@hidden>)
 >Re: "Live" image preview, huge memory usage... (From: Rob Keniger <email@hidden>)
 >Re: "Live" image preview, huge memory usage... (From: Jean-Nicolas Jolivet <email@hidden>)
 >Re: "Live" image preview, huge memory usage... (From: Jean-Nicolas Jolivet <email@hidden>)
 >Re: "Live" image preview, huge memory usage... (From: Jean-Nicolas Jolivet <email@hidden>)
 >Re: "Live" image preview, huge memory usage... (From: Rob Keniger <email@hidden>)

  • Prev by Date: Re: "Live" image preview, huge memory usage...
  • Next by Date: Controlled Font Substitution
  • Previous by thread: Re: "Live" image preview, huge memory usage...
  • Next by thread: Re: "Live" image preview, huge memory usage...
  • Index(es):
    • Date
    • Thread