Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Using Your Own Custom Filter

The procedure for using your own custom filter is the same as the procedure for using any filter provided by Core Image except that you must initialize the filter class. You initialize the haze removal filter class created in the last section with this line of code:

[MyHazeFilter class];

Listing 3-8 shows how to use the haze removal filter. Note the similarity between this code and the code discussed in “Processing an Image.”

Note: If you’ve packaged your filter as an image unit, you need to load it. See “Using Core Image Filters” for details.

Listing 3-8  Using your own custom filter

- (void)drawRect: (NSRect)rect
{
    CGRect  cg = CGRectMake(NSMinX(rect), NSMinY(rect),
                            NSWidth(rect), NSHeight(rect));
    CIContext *context = [[NSGraphicsContext currentContext] CIContext];
 
    if(filter == nil)
    {
        NSURL       *url;
 
        [MyHazeFilter class];
 
        url = [NSURL fileURLWithPath: [[NSBundle mainBundle]
                    pathForResource: @"CraterLake"  ofType: @"jpg"]];
        filter   = [CIFilter filterWithName: @"MyHazeRemover"
                    keysAndValues: @"inputImage",
                    [CIImage imageWithContentsOfURL: url],
                     @"inputColor",
                    [CIColor colorWithRed:0.7 green:0.9 blue:1],
                    nil];
        [filter retain];
    }
 
    [filter setValue: [NSNumber numberWithFloat: distance]
        forKey: @"inputDistance"];
    [filter setValue: [NSNumber numberWithFloat: slope]
        forKey: @"inputSlope"];
 
    [context drawImage: [filter valueForKey: @"outputImage"]
        atPoint: cg.origin  fromRect: cg];
}


< Previous PageNext Page > Hide TOC


Last updated: 2008-06-09




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice