26 #ifndef __SYNFIG_COLOR_COLORBLENDINGFUNCTIONS_H
27 #define __SYNFIG_COLOR_COLORBLENDINGFUNCTIONS_H
29 #define COLOR_EPSILON (0.000001f)
43 float a_src=src.
get_a()*amount;
44 float a_dest=dest.get_a();
45 const float one(C::ceil);
54 dest=src + dest*(one-a_src);
56 a_dest=a_src + a_dest*(one-a_src);
68 assert(dest.is_valid());
83 float a_out((src.get_a()-bg.get_a())*amount+bg.get_a());
89 out=((src*src.get_a()-bg*bg.get_a())*amount+bg*bg.get_a())/a_out;
95 assert(out.is_valid());
102 float alpha(b.get_a());
103 const float one(C::ceil);
110 a.
set_a(a.get_a()*b.get_a());
117 const float alpha(a.get_a()*amount);
119 if(b.get_r()<a.get_r()*alpha)
120 b.
set_r(a.get_r()*alpha);
122 if(b.get_g()<a.get_g()*alpha)
123 b.
set_g(a.get_g()*alpha);
125 if(b.get_b()<a.get_b()*alpha)
126 b.
set_b(a.get_b()*alpha);
134 const float alpha(a.get_a()*amount);
135 const float one(C::ceil);
137 if(b.get_r()>(a.get_r()-one)*alpha+one)
138 b.set_r((a.get_r()-one)*alpha+one);
140 if(b.get_g()>(a.get_g()-one)*alpha+one)
141 b.set_g((a.get_g()-one)*alpha+one);
143 if(b.get_b()>(a.get_b()-one)*alpha+one)
144 b.set_b((a.get_b()-one)*alpha+one);
153 const float alpha(a.get_a()*amount);
155 b.
set_r(b.get_r()+a.get_r()*alpha);
156 b.
set_g(b.get_g()+a.get_g()*alpha);
157 b.
set_b(b.get_b()+a.get_b()*alpha);
165 const float alpha(a.get_a()*amount);
167 b.
set_r(b.get_r()-a.get_r()*alpha);
168 b.
set_g(b.get_g()-a.get_g()*alpha);
169 b.
set_b(b.get_b()-a.get_b()*alpha);
177 const float alpha(a.get_a()*amount);
189 if(amount<0) a=~a, amount=-amount;
192 b.set_r(((b.get_r()*a.get_r())-b.get_r())*(amount)+b.get_r());
193 b.set_g(((b.get_g()*a.get_g())-b.get_g())*(amount)+b.get_g());
194 b.set_b(((b.get_b()*a.get_b())-b.get_b())*(amount)+b.get_b());
208 b.set_r(((b.get_r()/(a.get_r()+
COLOR_EPSILON))-b.get_r())*(amount)+b.get_r());
209 b.set_g(((b.get_g()/(a.get_g()+
COLOR_EPSILON))-b.get_g())*(amount)+b.get_g());
210 b.set_b(((b.get_b()/(a.get_b()+
COLOR_EPSILON))-b.get_b())*(amount)+b.get_b());
219 temp.set_uv(a.get_u(),a.get_v());
220 return (temp-b)*amount*a.get_a()+b;
227 temp.set_hue(a.get_hue());
228 return (temp-b)*amount*a.get_a()+b;
235 temp.set_s(a.get_s());
236 return (temp-b)*amount*a.get_a()+b;
243 temp.set_y(a.get_y());
244 return (temp-b)*amount*a.get_a()+b;
253 a.
set_a(a.get_a()*amount);
262 if(a.get_a() < b.get_a()*amount)
263 return a.
set_a(a.get_a()*amount);
270 if(a.get_a()*amount > b.get_a())
271 return a.
set_a(a.get_a()*amount);
278 const float one(C::ceil);
279 if(amount<0) a=~a, amount=-amount;
281 a.set_r(one-(one-a.get_r())*(one-b.get_r()));
282 a.set_g(one-(one-a.get_g())*(one-b.get_g()));
283 a.set_b(one-(one-a.get_b())*(one-b.get_b()));
291 const float one(C::ceil);
292 if(amount<0) a=~a, amount=-amount;
295 rm.set_r(b.get_r()*a.get_r());
296 rm.set_g(b.get_g()*a.get_g());
297 rm.set_b(b.get_b()*a.get_b());
300 rs.set_r(one-(one-a.get_r())*(one-b.get_r()));
301 rs.set_g(one-(one-a.get_g())*(one-b.get_g()));
302 rs.set_b(one-(one-a.get_b())*(one-b.get_b()));
306 ret.set_r(a.get_r()*rs.get_r() + (one-a.get_r())*rm.get_r());
307 ret.set_g(a.get_g()*rs.get_g() + (one-a.get_g())*rm.get_g());
308 ret.set_b(a.get_b()*rs.get_b() + (one-a.get_b())*rm.get_b());
317 const float one(C::ceil);
318 const float half((one-C::floor)/2);
319 if(amount<0) a=~a, amount=-amount;
321 if(a.get_r()>half) a.set_r(one-(one-(a.get_r()*2*one-one))*(one-b.get_r()));
322 else a.set_r(b.get_r()*(a.get_r()*2*one));
323 if(a.get_g()>half) a.set_g(one-(one-(a.get_g()*2*one-one))*(one-b.get_g()));
324 else a.set_g(b.get_g()*(a.get_g()*2*one));
325 if(a.get_b()>half) a.set_b(one-(one-(a.get_b()*2*one-one))*(one-b.get_b()));
326 else a.set_b(b.get_b()*(a.get_b()*2*one));
334 const float one(C::ceil);
338 rm.set_a((one-a.get_a())*b.get_a());
346 #endif // __SYNFIG_COLOR_COLORBLENDINGFUNCTIONS_H