Author: Carlos Lopez <genet...@gmail.com>
Date:   Tue Apr 16 20:26:19 2013 +0200

Fix blend method DARKEN for CairoColor.

---

 synfig-core/src/synfig/cairo_operators.cpp |    3 ++-
 synfig-core/src/synfig/color.cpp           |   20 ++++++++++----------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/synfig-core/src/synfig/cairo_operators.cpp 
b/synfig-core/src/synfig/cairo_operators.cpp
index f777e40..0c5f535 100644
--- a/synfig-core/src/synfig/cairo_operators.cpp
+++ b/synfig-core/src/synfig/cairo_operators.cpp
@@ -279,7 +279,8 @@ void cairo_paint_with_alpha_operator(cairo_t* acr, float 
alpha, Color::BlendMeth
                        for(int y=0;y<h;y++)
                                for(int x=0;x<w;x++)
                                {
-                                       
cdest[h0+y][w0+x]=CairoColor::blend(csource[y][x], cdest[h0+y][w0+x], alpha,    
method);
+                                       CairoColor 
ret=CairoColor::blend(csource[y][x].demult_alpha(), cdest[h0+y][w0+x], alpha,   
     method);
+                                       cdest[h0+y][w0+x]=ret.premult_alpha();
                                }
                        csource.unmap_cairo_image();
                        cdest.unmap_cairo_image();
diff --git a/synfig-core/src/synfig/color.cpp b/synfig-core/src/synfig/color.cpp
index 2323c9e..b88dad5 100644
--- a/synfig-core/src/synfig/color.cpp
+++ b/synfig-core/src/synfig/color.cpp
@@ -456,10 +456,11 @@ blendfunc_BRIGHTEN(CairoColor &a, CairoColor &b, float 
amount)
        gb=b.get_g();
        bb=b.get_b();
        ab=b.get_a();
-
-       const int raab(ra*aa*amount/255.0);
-       const int gaab(ga*aa*amount/255.0);
-       const int baab(ba*aa*amount/255.0);
+       
+       const float alpha = aa*amount/255.0;
+       const int raab(ra*alpha);
+       const int gaab(ga*alpha);
+       const int baab(ba*alpha);
        
        if(rb<raab)
                rc=raab;
@@ -520,22 +521,21 @@ blendfunc_DARKEN(CairoColor &a, CairoColor &b, float 
amount)
        bb=b.get_b();
        ab=b.get_a();
        
-       const int ab255=ab*255;
-       const int abaa=ab*aa;
-       
-       int rcompare=(amount*(ra*ab-abaa)+ab255)/255;
+       const float alpha=aa*amount/255.0;
+
+       int rcompare=(ra-255)*alpha+255;
        if(rb > rcompare)
                rc=rcompare;
        else
                rc=rb;
                
-       int gcompare=(amount*(ga*ab-abaa)+ab255)/255;
+       int gcompare=(ga-255)*alpha+255;
        if(gb > gcompare)
                gc=gcompare;
        else
                gc=gb;
 
-       int bcompare=(amount*(ba*ab-abaa)+ab255)/255;
+       int bcompare=(ba-255)*alpha+255;
        if(bb > bcompare)
                bc=bcompare;
        else


------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Synfig-devl mailing list
Synfig-devl@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to