This repository was archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathYUCIFXAA.m
executable file
·49 lines (42 loc) · 1.66 KB
/
YUCIFXAA.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
//
// YUCIFXAA.m
// Pods
//
// Created by YuAo on 2/14/16.
//
//
#import "YUCIFXAA.h"
#import "YUCIFilterConstructor.h"
@implementation YUCIFXAA
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
@autoreleasepool {
if ([CIFilter respondsToSelector:@selector(registerFilterName:constructor:classAttributes:)]) {
[CIFilter registerFilterName:NSStringFromClass([YUCIFXAA class])
constructor:[YUCIFilterConstructor constructor]
classAttributes:@{kCIAttributeFilterCategories: @[kCICategoryStillImage,kCICategoryVideo],
kCIAttributeFilterDisplayName: @"Fast Approximate Anti-Aliasing"}];
}
}
});
}
+ (CIKernel *)filterKernel {
static CIKernel *kernel;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *kernelString = [[NSString alloc] initWithContentsOfURL:[[NSBundle bundleForClass:self] URLForResource:NSStringFromClass([YUCIFXAA class]) withExtension:@"cikernel"] encoding:NSUTF8StringEncoding error:nil];
kernel = [CIKernel kernelWithString:kernelString];
});
return kernel;
}
- (CIImage *)outputImage {
if (!self.inputImage) {
return nil;
}
return [[YUCIFXAA filterKernel] applyWithExtent:self.inputImage.extent
roiCallback:^CGRect(int index, CGRect destRect) {
return CGRectInset(destRect, -8, -8); //FXAA_SPAN_MAX
} arguments:@[self.inputImage.imageByClampingToExtent]];
}
@end