Author: Carlos Lopez <[email protected]>
Date:   Fri Nov 23 19:40:03 2012 +0100

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

---

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

diff --git a/synfig-core/src/synfig/cairo_operators.cpp 
b/synfig-core/src/synfig/cairo_operators.cpp
index 21a4c06..b5e2816 100644
--- a/synfig-core/src/synfig/cairo_operators.cpp
+++ b/synfig-core/src/synfig/cairo_operators.cpp
@@ -233,6 +233,7 @@ void cairo_paint_with_alpha_operator(cairo_t* acr, float 
alpha, Color::BlendMeth
                }
                case Color::BLEND_ADD:
                case Color::BLEND_SUBTRACT:
+               case Color::BLEND_DIFFERENCE:
                case Color::BLEND_DIVIDE:
                {
                        cairo_push_group(cr);
@@ -275,7 +276,6 @@ void cairo_paint_with_alpha_operator(cairo_t* acr, float 
alpha, Color::BlendMeth
                        cairo_pattern_destroy(pattern);
                        break;
                }
-               case Color::BLEND_DIFFERENCE:
                case Color::BLEND_COLOR:
                case Color::BLEND_ALPHA_BRIGHTEN:
                case Color::BLEND_ALPHA_DARKEN:
diff --git a/synfig-core/src/synfig/color.cpp b/synfig-core/src/synfig/color.cpp
index 3f2e808..c39c95b 100644
--- a/synfig-core/src/synfig/color.cpp
+++ b/synfig-core/src/synfig/color.cpp
@@ -462,6 +462,38 @@ blendfunc_DIFFERENCE(C &a,C &b,float amount)
        return b;
 }
 
+//Specialization for CairoColor
+template <>
+static CairoColor
+blendfunc_DIFFERENCE(CairoColor &a, CairoColor &b, float amount)
+{
+       int ra, ga, ba, aa;
+       int rb, gb, bb, ab;
+       int 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();
+       
+       int aba=ab*amount;
+       
+       rc=abs(rb-(ra*aba)/255);
+       gc=abs(gb-(ga*aba)/255);
+       bc=abs(bb-(ba*aba)/255);
+       ac=ab;
+       
+       return CairoColor(rc, gc, bc, ac);
+}
+
+
+
+
 template <class C>
 static C
 blendfunc_MULTIPLY(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