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 pathYUCISkyGenerator.m
executable file
·78 lines (67 loc) · 2.34 KB
/
YUCISkyGenerator.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// YUCISkyGenerator.m
// Pods
//
// Created by YuAo on 3/15/16.
//
//
#import "YUCISkyGenerator.h"
#import "YUCIFilterConstructor.h"
@implementation YUCISkyGenerator
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
@autoreleasepool {
if ([CIFilter respondsToSelector:@selector(registerFilterName:constructor:classAttributes:)]) {
[CIFilter registerFilterName:NSStringFromClass([YUCISkyGenerator class])
constructor:[YUCIFilterConstructor constructor]
classAttributes:@{kCIAttributeFilterCategories: @[kCICategoryStillImage,kCICategoryVideo,kCICategoryGenerator],
kCIAttributeFilterDisplayName: @"Sky Generator"}];
}
}
});
}
+ (CIColorKernel *)filterKernel {
static CIColorKernel *kernel;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *kernelString = [[NSString alloc] initWithContentsOfURL:[[NSBundle bundleForClass:self] URLForResource:NSStringFromClass([YUCISkyGenerator class]) withExtension:@"cikernel"] encoding:NSUTF8StringEncoding error:nil];
kernel = [CIColorKernel kernelWithString:kernelString];
});
return kernel;
}
- (CIVector *)inputExtent {
if (!_inputExtent) {
_inputExtent = [CIVector vectorWithCGRect:CGRectMake(0, 0, 640, 480)];
}
return _inputExtent;
}
- (CIVector *)inputViewPointOffset {
if (!_inputViewPointOffset) {
_inputViewPointOffset = [CIVector vectorWithX:0 Y:0.9];
}
return _inputViewPointOffset;
}
- (CIVector *)inputSunPosition {
if (!_inputSunPosition) {
_inputSunPosition = [CIVector vectorWithX:0 Y:0.1 Z:-1.0];
}
return _inputSunPosition;
}
- (NSNumber *)inputSunIntensity {
if (!_inputSunIntensity) {
_inputSunIntensity = @30;
}
return _inputSunIntensity;
}
- (void)setDefaults {
self.inputExtent = nil;
self.inputViewPointOffset = nil;
self.inputSunPosition = nil;
self.inputSunIntensity = nil;
}
- (CIImage *)outputImage {
return [[YUCISkyGenerator filterKernel] applyWithExtent:self.inputExtent.CGRectValue
arguments:@[self.inputExtent,self.inputViewPointOffset,self.inputSunPosition,self.inputSunIntensity]];
}
@end