Initialise depth before using it.
[synfig.git] / synfig-core / trunk / src / synfig / blur.cpp
index 3d22fc8..2b481f0 100644 (file)
@@ -1,20 +1,21 @@
-/* === S I N F G =========================================================== */
+/* === S Y N F I G ========================================================= */
 /*!    \file blur.cpp
 **     \brief Blur Implementation File
 **
 **     $Id: blur.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
 **
 **     \legal
-**     Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
 **
-**     This software and associated documentation
-**     are CONFIDENTIAL and PROPRIETARY property of
-**     the above-mentioned copyright holder.
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
 **
-**     You may not copy, print, publish, or in any
-**     other way distribute this software without
-**     a prior written agreement with
-**     the copyright holder.
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
 **     \endlegal
 */
 /* ========================================================================= */
@@ -28,8 +29,8 @@
 #      include <config.h>
 #endif
 
-#include <sinfg/general.h>
-#include <sinfg/surface.h>
+#include <synfig/general.h>
+#include <synfig/surface.h>
 
 #include "blur.h"
 
@@ -46,7 +47,7 @@
 
 using namespace std;
 using namespace etl;
-using namespace sinfg;
+using namespace synfig;
 
 /* === M A C R O S ========================================================= */
 
@@ -113,7 +114,7 @@ Point Blur::operator ()(const Point &pos) const
        return blurpos;
 }
 
-Point Blur::operator ()(sinfg::Real x, sinfg::Real y) const
+Point Blur::operator ()(synfig::Real x, synfig::Real y) const
 {
        return (*this)(Point(x,y));
 }
@@ -469,7 +470,7 @@ bool Blur::operator ()(const Surface &surface,
        
        Surface worksurface(w,h);
        
-       //sinfg::info("Blur: check surface = %s", surface_valid(surface)?"true":"false");
+       //synfig::info("Blur: check surface = %s", surface_valid(surface)?"true":"false");
        
        // Premultiply the alpha
        for(y=0;y<h;y++)
@@ -555,7 +556,7 @@ bool Blur::operator ()(const Surface &surface,
        case Blur::BOX: // B O X -------------------------------------------------------
                {
                        //horizontal part
-                       //sinfg::info("Blur: Starting Box blur (surface valid %d)", (int)surface_valid(worksurface));
+                       //synfig::info("Blur: Starting Box blur (surface valid %d)", (int)surface_valid(worksurface));
                        
                        Surface temp_surface;
                        temp_surface.set_wh(w,h);
@@ -565,11 +566,11 @@ bool Blur::operator ()(const Surface &surface,
                                int length = halfsizex;
                                length=std::max(1,length);
                                
-                               //sinfg::info("Blur: hbox blur work -> temp %d", length);
+                               //synfig::info("Blur: hbox blur work -> temp %d", length);
                                etl::hbox_blur(worksurface.begin(),worksurface.end(),length,temp_surface.begin());
                        }
                        else temp_surface = worksurface;
-                       //sinfg::info("Blur: hbox finished");
+                       //synfig::info("Blur: hbox finished");
                        
                        //vertical part
                        //Surface temp_surface2;
@@ -580,11 +581,11 @@ bool Blur::operator ()(const Surface &surface,
                                int length = halfsizey;
                                length = std::max(1,length);
                                
-                               //sinfg::info("Blur: vbox blur temp -> work %d",length);
+                               //synfig::info("Blur: vbox blur temp -> work %d",length);
                                etl::vbox_blur(temp_surface.begin(),temp_surface.end(),length,worksurface.begin());
                        }
                        else worksurface = temp_surface;
-                       //sinfg::info("Blur: vbox finished");
+                       //synfig::info("Blur: vbox finished");
                        
                        //blend with the original surface
                        /*int x,y;
@@ -616,24 +617,24 @@ bool Blur::operator ()(const Surface &surface,
                        //horizontal part
                        if(size[0])
                        {
-                               int length=(int)(abs((float)w/(resolution[0]))*size[0]*0.5+1);
-                               length=std::max(1,length);
+                               Real length=abs((float)w/(resolution[0]))*size[0]*0.5+1;
+                               length=std::max(1.0,length);
                                
                                //two box blurs produces: 1 2 1
-                               etl::hbox_blur(worksurface.begin(),w,h,length*3/4,temp_surface.begin());
-                               etl::hbox_blur(temp_surface.begin(),w,h,length*3/4,worksurface.begin());
+                               etl::hbox_blur(worksurface.begin(),w,h,(int)(length*3/4),temp_surface.begin());
+                               etl::hbox_blur(temp_surface.begin(),w,h,(int)(length*3/4),worksurface.begin());
                        }
                        //else temp_surface2=worksurface;
                        
                        //vertical part
                        if(size[1])
                        {
-                               int length=(int)(abs((float)h/(resolution[1]))*size[1]*0.5+1);
-                               length=std::max(1,length);
+                               Real length=abs((float)h/(resolution[1]))*size[1]*0.5+1;
+                               length=std::max(1.0,length);
                                
                                //two box blurs produces: 1 2 1 on the horizontal 1 2 1
-                               etl::vbox_blur(worksurface.begin(),w,h,length*3/4,temp_surface.begin());
-                               etl::vbox_blur(temp_surface.begin(),w,h,length*3/4,worksurface.begin());
+                               etl::vbox_blur(worksurface.begin(),w,h,(int)(length*3/4),temp_surface.begin());
+                               etl::vbox_blur(temp_surface.begin(),w,h,(int)(length*3/4),worksurface.begin());
                        }
                        //else temp_surface2=temp_surface2;
        
@@ -702,7 +703,7 @@ bool Blur::operator ()(const Surface &surface,
                        Surface temp_surface;
                        Surface *gauss_surface;
                        
-                       //sinfg::warning("Didn't crash yet b1");
+                       //synfig::warning("Didn't crash yet b1");
                        
                        //if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
                                gauss_surface = &worksurface;
@@ -736,7 +737,7 @@ bool Blur::operator ()(const Surface &surface,
                        memset(SC0,0,(w+2)*sizeof(Color));
                        memset(SC0,0,(w+2)*sizeof(Color));
 
-                       //sinfg::warning("Didn't crash yet b2");
+                       //synfig::warning("Didn't crash yet b2");
                        //int i = 0;
                        
                        while(bw&&bh)
@@ -761,7 +762,7 @@ bool Blur::operator ()(const Surface &surface,
                                        bw--,bh--;
                                }
                                
-                               //sinfg::warning("Didn't crash yet bi - %d",i++);
+                               //synfig::warning("Didn't crash yet bi - %d",i++);
                        }
                        while(bw)
                        {
@@ -777,7 +778,7 @@ bool Blur::operator ()(const Surface &surface,
                                        GuassianBlur_2x1(*gauss_surface);
                                        bw--;
                                }
-                               //sinfg::warning("Didn't crash yet bi - %d",i++);
+                               //synfig::warning("Didn't crash yet bi - %d",i++);
                        }
                        while(bh)
                        {
@@ -793,7 +794,7 @@ bool Blur::operator ()(const Surface &surface,
                                        GuassianBlur_1x2(*gauss_surface);
                                        bh--;
                                }
-                               //sinfg::warning("Didn't crash yet bi - %d",i++);
+                               //synfig::warning("Didn't crash yet bi - %d",i++);
                        }
 
                        delete [] SC0;
@@ -808,7 +809,7 @@ bool Blur::operator ()(const Surface &surface,
                                        for(x=0;x<renddesc.get_w();x++)
                                                worksurface[y][x]=Color::blend(temp_surface[y][x],worksurface[y][x],get_amount(),get_blend_method());
                        }*/
-                       //sinfg::warning("Didn't crash yet b end",i++);
+                       //synfig::warning("Didn't crash yet b end",i++);
                }
                break;
 
@@ -992,24 +993,24 @@ bool Blur::operator ()(const surface<float> &surface,
                        //horizontal part
                        if(size[0])
                        {
-                               int length=(int)(abs((float)w/(resolution[0]))*size[0]*0.5+1);
-                               length=std::max(1,length);
+                               Real length=abs((float)w/(resolution[0]))*size[0]*0.5+1;
+                               length=std::max(1.0,length);
                                
                                //two box blurs produces: 1 2 1
-                               etl::hbox_blur(worksurface.begin(),w,h,length*3/4,temp_surface.begin());
-                               etl::hbox_blur(temp_surface.begin(),w,h,length*3/4,worksurface.begin());
+                               etl::hbox_blur(worksurface.begin(),w,h,(int)(length*3/4),temp_surface.begin());
+                               etl::hbox_blur(temp_surface.begin(),w,h,(int)(length*3/4),worksurface.begin());
                        }
                        //else temp_surface2=worksurface;
                        
                        //vertical part
                        if(size[1])
                        {
-                               int length=(int)(abs((float)h/(resolution[1]))*size[1]*0.5+1);
-                               length=std::max(1,length);
+                               Real length=abs((float)h/(resolution[1]))*size[1]*0.5+1;
+                               length=std::max(1.0,length);
                                
                                //two box blurs produces: 1 2 1 on the horizontal 1 2 1
-                               etl::vbox_blur(worksurface.begin(),w,h,length*3/4,temp_surface.begin());
-                               etl::vbox_blur(temp_surface.begin(),w,h,length*3/4,worksurface.begin());
+                               etl::vbox_blur(worksurface.begin(),w,h,(int)(length*3/4),temp_surface.begin());
+                               etl::vbox_blur(temp_surface.begin(),w,h,(int)(length*3/4),worksurface.begin());
                        }
                        //else temp_surface2=temp_surface2;