Author: Carlos Lopez <[email protected]>
Date:   Fri Nov 23 20:24:43 2012 +0100

Cairo Operators: Add support for blend mode ALPHA_BRIGHTEN using a custom blend 
function.

---

 synfig-core/src/synfig/cairo_operators.cpp |    2 +-
 synfig-core/src/synfig/color.cpp           |   43 ++++++++++++++++++++++++++--
 2 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/synfig-core/src/synfig/cairo_operators.cpp 
b/synfig-core/src/synfig/cairo_operators.cpp
index 24feba4..985a0e4 100644
--- a/synfig-core/src/synfig/cairo_operators.cpp
+++ b/synfig-core/src/synfig/cairo_operators.cpp
@@ -236,6 +236,7 @@ void cairo_paint_with_alpha_operator(cairo_t* acr, float 
alpha, Color::BlendMeth
                case Color::BLEND_DIFFERENCE:
                case Color::BLEND_DIVIDE:
                case Color::BLEND_ALPHA_DARKEN:
+               case Color::BLEND_ALPHA_BRIGHTEN:
                {
                        cairo_push_group(cr);
                        cairo_paint(cr);
@@ -278,7 +279,6 @@ void cairo_paint_with_alpha_operator(cairo_t* acr, float 
alpha, Color::BlendMeth
                        break;
                }
                case Color::BLEND_COLOR:
-               case Color::BLEND_ALPHA_BRIGHTEN:
                default:
                {
                        cairo_push_group(cr);
diff --git a/synfig-core/src/synfig/color.cpp b/synfig-core/src/synfig/color.cpp
index 71f246b..c4b199c 100644
--- a/synfig-core/src/synfig/color.cpp
+++ b/synfig-core/src/synfig/color.cpp
@@ -628,6 +628,45 @@ blendfunc_ALPHA_BRIGHTEN(C &a,C &b,float amount)
        return b;
 }
 
+//Specialization for CairoColor
+template <>
+static CairoColor
+blendfunc_ALPHA_BRIGHTEN(CairoColor &a, CairoColor &b, float amount)
+{
+       // \todo can this be right, multiplying amount by *b*'s alpha?
+       // compare with blendfunc_BRIGHTEN where it is multiplied by *a*'s
+       //if(a.get_a() < b.get_a()*amount)
+       //      return a.set_a(a.get_a()*amount);
+       //return b;
+       unsigned char ra, ga, ba, aa;
+       unsigned char rb, gb, bb, ab;
+       unsigned char rc, gc, bc, ac;
+       
+       ra=a.get_r();
+       ga=a.get_g();
+       ba=a.get_b();
+       aa=a.get_a();
+       
+       rb=b.get_r();
+       gb=b.get_g();
+       bb=b.get_b();
+       ab=b.get_a();
+       
+       ac=aa*amount;
+       if(aa < ab*amount)
+       {
+               float acaa=(aa*amount)/aa;
+               rc=ra*acaa;
+               gc=ga*acaa;
+               bc=ba*acaa;
+               return CairoColor(rc, gc, bc, ac);
+       }
+       else
+               return b;
+       
+       
+}
+
 template <class C>
 static C
 blendfunc_ALPHA_DARKEN(C &a,C &b,float amount)
@@ -655,7 +694,7 @@ blendfunc_ALPHA_DARKEN(CairoColor &a, CairoColor &b, float 
amount)
        gb=b.get_g();
        bb=b.get_b();
        ab=b.get_a();
-
+       
        ac=aa*amount;
        if(ac > ab)
        {
@@ -667,8 +706,6 @@ blendfunc_ALPHA_DARKEN(CairoColor &a, CairoColor &b, float 
amount)
        }
        else
                return b;
-       
-
 }
 
 


------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Synfig-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to