Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 52 lines (42 sloc) 1.397 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
// From http://www.cocoadev.com/index.pl?NSImageCategory
//
// NSImage+CoreImage.m
// iTerm2

#import "NSImage+CoreImage.h"
#import "NSBitmapImageRep+CoreImage.h"

@implementation NSImage (CoreImage)
- (void)drawAtPoint: (NSPoint)point fromRect: (NSRect)fromRect coreImageFilter: (NSString *)filterName arguments: (NSDictionary *)arguments {
    NSAutoreleasePool *pool;
    NSBitmapImageRep *rep;

    pool = [[NSAutoreleasePool alloc] init];

    if (filterName) {
        rep = [self bitmapImageRepresentation];
        [rep drawAtPoint:point
                fromRect:fromRect
         coreImageFilter:filterName
               arguments:arguments];
    } else {
        /* bypass core image if no filter is specified */
        [self drawAtPoint:point
                 fromRect:fromRect
                operation:NSCompositeSourceOver
                 fraction:1.0f];
    }

    [pool release];
}

- (NSBitmapImageRep *)bitmapImageRepresentation {
    NSImageRep *rep;
    NSEnumerator *e;
    Class bitmapImageRep;

    bitmapImageRep = [NSBitmapImageRep class];
    e = [[self representations] objectEnumerator];
    while ((rep = [e nextObject]) != nil) {
        if ([rep isKindOfClass: bitmapImageRep])
            break;
        rep = nil;
    }

    if (!rep)
        rep = [NSBitmapImageRep imageRepWithData: [self TIFFRepresentation]];

    return (NSBitmapImageRep *)rep;
}

@end
Something went wrong with that request. Please try again.