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

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

---

 synfig-core/src/synfig/cairo_operators.cpp |    2 +-
 synfig-core/src/synfig/color.cpp           |   35 ++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/synfig-core/src/synfig/cairo_operators.cpp 
b/synfig-core/src/synfig/cairo_operators.cpp
index b5e2816..24feba4 100644
--- a/synfig-core/src/synfig/cairo_operators.cpp
+++ b/synfig-core/src/synfig/cairo_operators.cpp
@@ -235,6 +235,7 @@ void cairo_paint_with_alpha_operator(cairo_t* acr, float 
alpha, Color::BlendMeth
                case Color::BLEND_SUBTRACT:
                case Color::BLEND_DIFFERENCE:
                case Color::BLEND_DIVIDE:
+               case Color::BLEND_ALPHA_DARKEN:
                {
                        cairo_push_group(cr);
                        cairo_paint(cr);
@@ -278,7 +279,6 @@ void cairo_paint_with_alpha_operator(cairo_t* acr, float 
alpha, Color::BlendMeth
                }
                case Color::BLEND_COLOR:
                case Color::BLEND_ALPHA_BRIGHTEN:
-               case Color::BLEND_ALPHA_DARKEN:
                default:
                {
                        cairo_push_group(cr);
diff --git a/synfig-core/src/synfig/color.cpp b/synfig-core/src/synfig/color.cpp
index c39c95b..71f246b 100644
--- a/synfig-core/src/synfig/color.cpp
+++ b/synfig-core/src/synfig/color.cpp
@@ -637,6 +637,41 @@ blendfunc_ALPHA_DARKEN(C &a,C &b,float amount)
        return b;
 }
 
+//Specialization for CairoColor
+template <>
+static CairoColor
+blendfunc_ALPHA_DARKEN(CairoColor &a, CairoColor &b, float amount)
+{
+       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(ac > ab)
+       {
+               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_SCREEN(C &a,C &b,float amount)


------------------------------------------------------------------------------
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