FROM : slasktrattenator
DATE : Mon Mar 10 21:03:19 2008
I narrowed this down by removing the filters, and the leak is still
there. And what a leak! Everytime I draw the view the memory usage
increases with the size of the drawn image. Yet this exact same code
is used in the Core Image Programming Guide. So I figure it's a bug in
Core Image. But how can I avoid it?
- (void) drawRect:(NSRect)rect
{
CIImage *image = [CIImage imageWithData:[[self image]
TIFFRepresentation]];
if (image !=nil) {
CGRect cg;
CIContext *context = [[NSGraphicsContext
currentContext] CIContext];
cg = CGRectMake(NSMinX(rect), NSMinY(rect),
NSWidth(rect), NSHeight(rect));
[context drawImage:image
atPoint:cg.origin
fromRect:cg];
}
}
On Mon, Mar 10, 2008 at 5:33 PM, <<email_removed>> wrote:
> Hi,
>
> I'm applying a Core Image filter to an image in a NSImageView
> subclass. The drawing works fine, except it leaks memory, not sure
> why. This is my drawRect method. Anything wrong with it? Thanks.
>
>
> - (void) drawRect:(NSRect)rect
> {
>
> [[self image] setFlipped:YES];
> CIImage *image = [CIImage imageWithData:[[self image] TIFFRepresentation]];
> if (image !=nil) {
> CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
> [filter setDefaults];
> [filter setValue: image forKey: @"inputImage"];
> [filter setValue: [NSNumber numberWithFloat:0.7] forKey: @"inputRadius"];
> image = [filter valueForKey: @"outputImage"];
>
> filter = [CIFilter filterWithName:@"CIPerspectiveTransform"];
> [filter setDefaults];
> [filter setValue: image forKey: @"inputImage"];
> [filter setValue:[CIVector vectorWithX:NSMinX(rect) Y:NSMinY(rect) +
> bLeft ] forKey:@"inputBottomLeft"];
> [filter setValue:[CIVector vectorWithX:NSMaxX(rect) Y:NSMinY(rect) +
> bRight ] forKey:@"inputBottomRight"];
> [filter setValue:[CIVector vectorWithX:NSMinX(rect) Y:NSMaxY(rect) +
> tLeft ] forKey:@"inputTopLeft"];
> [filter setValue:[CIVector vectorWithX:NSMaxX(rect) Y:NSMaxY(rect) +
> tRight ] forKey:@"inputTopRight"];
> image = [filter valueForKey: @"outputImage"];
>
> CGRect cg;
> CIContext *context = [[NSGraphicsContext currentContext] CIContext];
> cg = CGRectMake(NSMinX(rect), NSMinY(rect), NSWidth(rect), NSHeight(rect));
> [context drawImage:image
> atPoint:cg.origin
> fromRect:cg];
>
> }
> }
>
DATE : Mon Mar 10 21:03:19 2008
I narrowed this down by removing the filters, and the leak is still
there. And what a leak! Everytime I draw the view the memory usage
increases with the size of the drawn image. Yet this exact same code
is used in the Core Image Programming Guide. So I figure it's a bug in
Core Image. But how can I avoid it?
- (void) drawRect:(NSRect)rect
{
CIImage *image = [CIImage imageWithData:[[self image]
TIFFRepresentation]];
if (image !=nil) {
CGRect cg;
CIContext *context = [[NSGraphicsContext
currentContext] CIContext];
cg = CGRectMake(NSMinX(rect), NSMinY(rect),
NSWidth(rect), NSHeight(rect));
[context drawImage:image
atPoint:cg.origin
fromRect:cg];
}
}
On Mon, Mar 10, 2008 at 5:33 PM, <<email_removed>> wrote:
> Hi,
>
> I'm applying a Core Image filter to an image in a NSImageView
> subclass. The drawing works fine, except it leaks memory, not sure
> why. This is my drawRect method. Anything wrong with it? Thanks.
>
>
> - (void) drawRect:(NSRect)rect
> {
>
> [[self image] setFlipped:YES];
> CIImage *image = [CIImage imageWithData:[[self image] TIFFRepresentation]];
> if (image !=nil) {
> CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
> [filter setDefaults];
> [filter setValue: image forKey: @"inputImage"];
> [filter setValue: [NSNumber numberWithFloat:0.7] forKey: @"inputRadius"];
> image = [filter valueForKey: @"outputImage"];
>
> filter = [CIFilter filterWithName:@"CIPerspectiveTransform"];
> [filter setDefaults];
> [filter setValue: image forKey: @"inputImage"];
> [filter setValue:[CIVector vectorWithX:NSMinX(rect) Y:NSMinY(rect) +
> bLeft ] forKey:@"inputBottomLeft"];
> [filter setValue:[CIVector vectorWithX:NSMaxX(rect) Y:NSMinY(rect) +
> bRight ] forKey:@"inputBottomRight"];
> [filter setValue:[CIVector vectorWithX:NSMinX(rect) Y:NSMaxY(rect) +
> tLeft ] forKey:@"inputTopLeft"];
> [filter setValue:[CIVector vectorWithX:NSMaxX(rect) Y:NSMaxY(rect) +
> tRight ] forKey:@"inputTopRight"];
> image = [filter valueForKey: @"outputImage"];
>
> CGRect cg;
> CIContext *context = [[NSGraphicsContext currentContext] CIContext];
> cg = CGRectMake(NSMinX(rect), NSMinY(rect), NSWidth(rect), NSHeight(rect));
> [context drawImage:image
> atPoint:cg.origin
> fromRect:cg];
>
> }
> }
>
| Related mails | Author | Date |
|---|---|---|
| slasktrattenator | Mar 10, 17:33 | |
| slasktrattenator | Mar 10, 21:03 | |
| Gary L. Wade | Mar 10, 21:21 | |
| Brady Duga | Mar 10, 21:34 | |
| slasktrattenator | Mar 10, 21:58 | |
| Gorazd Krosl | Mar 10, 22:02 | |
| Rob Keniger | Mar 11, 04:46 | |
| slasktrattenator | Mar 11, 11:53 |






Cocoa mail archive

