developer
2023-05-20 e12c7b4c22df631ebdcd16b2f98fbef8f738f92f
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#import "GPUImageSmoothToonFilter.h"
#import "GPUImageGaussianBlurFilter.h"
#import "GPUImageToonFilter.h"
 
@implementation GPUImageSmoothToonFilter
 
@synthesize threshold;
@synthesize blurRadiusInPixels;
@synthesize quantizationLevels;
@synthesize texelWidth;
@synthesize texelHeight;
 
- (id)init;
{
    if (!(self = [super init]))
    {
        return nil;
    }
    
    // First pass: apply a variable Gaussian blur
    blurFilter = [[GPUImageGaussianBlurFilter alloc] init];
    [self addFilter:blurFilter];
    
    // Second pass: run the Sobel edge detection on this blurred image, along with a posterization effect
    toonFilter = [[GPUImageToonFilter alloc] init];
    [self addFilter:toonFilter];
    
    // Texture location 0 needs to be the sharp image for both the blur and the second stage processing
    [blurFilter addTarget:toonFilter];
    
    self.initialFilters = [NSArray arrayWithObject:blurFilter];
    self.terminalFilter = toonFilter;
    
    self.blurRadiusInPixels = 2.0;
    self.threshold = 0.2;
    self.quantizationLevels = 10.0;
    
    return self;
}
 
#pragma mark -
#pragma mark Accessors
 
- (void)setBlurRadiusInPixels:(CGFloat)newValue;
{
    blurFilter.blurRadiusInPixels = newValue;
}
 
- (CGFloat)blurRadiusInPixels;
{
    return blurFilter.blurRadiusInPixels;
}
 
- (void)setTexelWidth:(CGFloat)newValue;
{
    toonFilter.texelWidth = newValue;
}
 
- (CGFloat)texelWidth;
{
    return toonFilter.texelWidth;
}
 
- (void)setTexelHeight:(CGFloat)newValue;
{
    toonFilter.texelHeight = newValue;
}
 
- (CGFloat)texelHeight;
{
    return toonFilter.texelHeight;
}
 
- (void)setThreshold:(CGFloat)newValue;
{
    toonFilter.threshold = newValue;
}
 
- (CGFloat)threshold;
{
    return toonFilter.threshold;
}
 
- (void)setQuantizationLevels:(CGFloat)newValue;
{
    toonFilter.quantizationLevels = newValue;
}
 
- (CGFloat)quantizationLevels;
{
    return toonFilter.quantizationLevels;
}
 
@end