@@ -3685,6 +3685,30 @@ template<class A,class B> inline auto min(A a,B b)->decltype((float)a){ return (
36853685template <class A ,class B ,class C > inline auto min (A a,B b,C c)->decltype((float )a){ float fa=(float )a,fb=(float )b,fc=(float )c; return fa<fb?(fa<fc?fa:fc):(fb<fc?fb:fc); }
36863686template <class A ,class B > inline auto max (A a,B b)->decltype((float )a){ return (float )a>(float )b?(float )a:(float )b; }
36873687template <class A ,class B ,class C > inline auto max (A a,B b,C c)->decltype((float )a){ float fa=(float )a,fb=(float )b,fc=(float )c; return fa>fb?(fa>fc?fa:fc):(fb>fc?fb:fc); }
3688+ // lerpColor and blendColor as free functions
3689+ inline color lerpColor (color c1, color c2, float t) {
3690+ int r1=(c1.value >>16 )&0xFF , g1=(c1.value >>8 )&0xFF , b1=c1.value &0xFF , a1=(c1.value >>24 )&0xFF ;
3691+ int r2=(c2.value >>16 )&0xFF , g2=(c2.value >>8 )&0xFF , b2=c2.value &0xFF , a2=(c2.value >>24 )&0xFF ;
3692+ int r=(int )(r1+(r2-r1)*t), g=(int )(g1+(g2-g1)*t), b=(int )(b1+(b2-b1)*t), a=(int )(a1+(a2-a1)*t);
3693+ return colorVal (r,g,b,a);
3694+ }
3695+ inline color blendColor (color c1, color c2, int mode) {
3696+ if (mode == REPLACE ) return c2;
3697+ if (mode == BLEND ) {
3698+ float a=((c2.value >>24 )&0xFF )/255 .f ;
3699+ int r=(int )(((c1.value >>16 )&0xFF )*(1 -a)+((c2.value >>16 )&0xFF )*a);
3700+ int g=(int )(((c1.value >>8 )&0xFF )*(1 -a)+((c2.value >>8 )&0xFF )*a);
3701+ int b=(int )((c1.value &0xFF )*(1 -a)+(c2.value &0xFF )*a);
3702+ return colorVal (r,g,b,255 );
3703+ }
3704+ if (mode == ADD ) {
3705+ int r=::std::min (((c1.value >>16 )&0xFF )+((c2.value >>16 )&0xFF ),255 );
3706+ int g=::std::min (((c1.value >>8 )&0xFF )+((c2.value >>8 )&0xFF ),255 );
3707+ int b=::std::min ((c1.value &0xFF )+(c2.value &0xFF ),255 );
3708+ return colorVal (r,g,b,255 );
3709+ }
3710+ return c2; // fallback
3711+ }
36883712
36893713// image() -- mixed types, value and pointer variants
36903714// image() -- draw a PImage to screen
0 commit comments