-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpb_rgblend.lua
executable file
·118 lines (104 loc) · 3.67 KB
/
pb_rgblend.lua
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
return {init=function(_,_,_,_,_,_)
local MATH_MIN = math.min
local MATH_MAX = math.max
local function blend_alpha_alphamultiply(d_r,d_g,d_b,d_a,s_r,s_g,s_b,s_a)
return d_r * (1-s_a) + s_r*s_a,
d_g * (1-s_a) + s_g*s_a,
d_b * (1-s_a) + s_b*s_a,
d_a * (1-s_a) + s_a
end
local function blend_alpha_premultiplied(d_r,d_g,d_b,d_a,s_r,s_g,s_b,s_a)
return d_r * (1-s_a) + s_r,
d_g * (1-s_a) + s_g,
d_b * (1-s_a) + s_b,
d_a * (1-s_a) + s_a
end
local function blend_add_alphamultiply(d_r,d_g,d_b,d_a,s_r,s_g,s_b,s_a)
return d_r + (s_r*s_a),
d_g + (s_g*s_a),
d_b + (s_b*s_a),
d_a
end
local function blend_add_premultiplied(d_r,d_g,d_b,d_a,s_r,s_g,s_b,s_a)
return d_r+s_r,
d_g+s_g,
d_b+s_b,
d_a
end
local function blend_subtract_alphamultiply(d_r,d_g,d_b,d_a,s_r,s_g,s_b,s_a)
return d_r - (s_r*s_a),
d_g - (s_g*s_a),
d_b - (s_b*s_a),
d_a
end
local function blend_subtract_premultiplied(d_r,d_g,d_b,d_a,s_r,s_g,s_b,s_a)
return d_r-s_r,
d_g-s_g,
d_b-s_b,
d_a
end
local function blend_replace_alphamultiply(d_r,d_g,d_b,d_a,s_r,s_g,s_b,s_a)
return s_r*s_a,
s_g*s_a,
s_b*s_a,
d_a
end
local function blend_replace_premultiplied(d_r,d_g,d_b,d_a,s_r,s_g,s_b,s_a)
return s_r,s_g,s_b,d_a
end
local function blend_multiply_alphamultiply(d_r,d_g,d_b,d_a,s_r,s_g,s_b,s_a)
return s_r*d_r,
s_g*d_g,
s_b*d_b,
s_a*d_a
end
local function blend_lighten_alphamultiply(d_r,d_g,d_b,d_a,s_r,s_g,s_b,s_a)
return MATH_MAX(s_r,d_r),
MATH_MAX(s_g,d_g),
MATH_MAX(s_b,d_b),
MATH_MAX(s_a,d_a)
end
local function blend_darken_alphamultiply(d_r,d_g,d_b,d_a,s_r,s_g,s_b,s_a)
return MATH_MIN(s_r,d_r),
MATH_MIN(s_g,d_g),
MATH_MIN(s_b,d_b),
MATH_MIN(s_a,d_a)
end
local function blend_screen_alphamultiply(dR,dG,dB,dA,sR,sG,sB,sA)
return dR * (1-sR) + (sR*sA),
dG * (1-sG) + (sG*sA),
dB * (1-sB) + (sB*sA),
dA * (1-sA) + sA
end
local function blend_screen_premultiplied(d_r,d_g,d_b,d_a,s_r,s_g,s_b,s_a)
return d_r * (1-s_r) + s_r,
d_g * (1-s_g) + s_g,
d_b * (1-s_b) + s_b,
d_a * (1-s_a) + s_a
end
return {rgblend={
alphamultiply = {
alpha = blend_alpha_alphamultiply,
add = blend_add_alphamultiply,
subtract = blend_subtract_alphamultiply,
replace = blend_replace_alphamultiply,
multiply = blend_multiply_alphamultiply,
lighten = blend_lighten_alphamultiply,
darken = blend_darken_alphamultiply,
screen = blend_screen_alphamultiply
},
premultiplied = {
alpha = blend_alpha_premultiplied,
add = blend_add_premultiplied,
subtract = blend_subtract_premultiplied,
replace = blend_replace_premultiplied,
screen = blend_screen_premultiplied
}
}},{}
end,
id = "PB_MODULE:rgblend",
name = "PB_RGBBlend",
author = "9551",
contact = "https://devvie.cc/contact",
report_msg = "\n__name: module error, report issues at\n-> __contact"
}