-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sharpen.pbk
92 lines (79 loc) · 2.65 KB
/
Sharpen.pbk
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
<languageVersion : 1.0;>
kernel Sharpen
< namespace : "Sharpen";
vendor : "Paperless Post";
version : 1;
>
{
input image4 src;
output pixel4 dst;
parameter float4 bBox
<
minValue:float4(0.0,0.0,0.0,0.0);
maxValue:float4(1000.0,1000.0,1000.0,1000.0);
defaultValue:float4(0.0,600.0,0.0,400.0);
>;
//0 - regular
//1 - circular
parameter int mode
<
minValue:int(0);
maxValue:int(1);
defaultValue:int(0);
>;
parameter float2 center
<
minValue:float2(-2.0,-2.0);
maxValue:float2(2.0,2.0);
defaultValue:float2(0.5,0.5);
>;
parameter float strength
<
minValue:float(0.0);
maxValue:float(4.0);
defaultValue:float(0.5);
>;
parameter float size
<
minValue:float(0.1);
maxValue:float(2);
defaultValue:float(1);
>;
parameter float exponent
<
minValue:float(-10.0);
maxValue:float(10.0);
defaultValue:float(0.0);
>;
parameter float factor
<
minValue:float(-10.0);
maxValue:float(10.0);
defaultValue:float(0.0);
>;
void
evaluatePixel()
{
float2 pos = outCoord();
float sharpenFactor = 1.0;
if(mode == 1){
float2 centerPos = float2(mix(bBox[0],bBox[1],center[0]),mix(bBox[2],bBox[3],center[1]));
float dist = distance(centerPos,pos);
dist = dist * (1.0/size);
dist = dist/distance(centerPos,float2(bBox[0],bBox[3])); // normalize the distance between 0 and 1
sharpenFactor = factor * pow(dist,exponent); // used to colorize darken areas
}
dst = sampleNearest(src, float2(pos.x-1.0,pos.y-1.0));
dst += sampleNearest(src, float2(pos.x,pos.y-1.0));
dst += sampleNearest(src, float2(pos.x+1.0,pos.y-1.0));
dst += sampleNearest(src, float2(pos.x-1.0,pos.y));
dst += sampleNearest(src, float2(pos.x+1.0,pos.y));
dst += sampleNearest(src, float2(pos.x-1.0,pos.y+1.0));
dst += sampleNearest(src, float2(pos.x,pos.y+1.0));
dst += sampleNearest(src, float2(pos.x+1.0,pos.y+1.0));
dst/=8.0; // the average color of the surrounding pixels
float4 diff = sampleNearest(src, pos) - dst; // the difference between the average and current color
dst = sampleNearest(src, pos) + diff; // the sum of the difference and the current color
dst = mix(sampleNearest(src, pos),dst,strength * sharpenFactor);
}
}