forked from gnachman/iTerm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSImage+CoreImage.m
53 lines (43 loc) · 1.35 KB
/
NSImage+CoreImage.m
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
53
// From http://www.cocoadev.com/index.pl?NSImageCategory
//
// NSImage+CoreImage.m
// iTerm2
#import "NSImage+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