Remove .gitignore do nothing is ignored.
[synfig.git] / synfig-core / trunk / src / modules / lyr_std / bevel.cpp
index 16a331f..dacf270 100644 (file)
@@ -1,20 +1,21 @@
-/* === S I N F G =========================================================== */
-/*!    \file shade.cpp
-**     \brief Template Header
+/* === S Y N F I G ========================================================= */
+/*!    \file bevel.cpp
+**     \brief Implementation of the "Bevel" layer
 **
-**     $Id: bevel.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $
+**     $Id$
 **
 **     \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
 */
 /* ========================================================================= */
 
 #include "bevel.h"
 
-#include <sinfg/string.h>
-#include <sinfg/time.h>
-#include <sinfg/context.h>
-#include <sinfg/paramdesc.h>
-#include <sinfg/renddesc.h>
-#include <sinfg/surface.h>
-#include <sinfg/value.h>
-#include <sinfg/valuenode.h>
-#include <sinfg/segment.h>
+#include <synfig/string.h>
+#include <synfig/time.h>
+#include <synfig/context.h>
+#include <synfig/paramdesc.h>
+#include <synfig/renddesc.h>
+#include <synfig/surface.h>
+#include <synfig/value.h>
+#include <synfig/valuenode.h>
+#include <synfig/segment.h>
 
 #include <cstring>
 #include <ETL/pen>
@@ -46,7 +47,7 @@
 
 #endif
 
-using namespace sinfg;
+using namespace synfig;
 using namespace etl;
 using namespace std;
 
@@ -61,16 +62,16 @@ using namespace std;
 
 /* -- G L O B A L S --------------------------------------------------------- */
 
-SINFG_LAYER_INIT(Layer_Bevel);
-SINFG_LAYER_SET_NAME(Layer_Bevel,"bevel");
-SINFG_LAYER_SET_LOCAL_NAME(Layer_Bevel,_("Bevel"));
-SINFG_LAYER_SET_CATEGORY(Layer_Bevel,_("Stylize"));
-SINFG_LAYER_SET_VERSION(Layer_Bevel,"0.2");
-SINFG_LAYER_SET_CVS_ID(Layer_Bevel,"$Id: bevel.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $");
+SYNFIG_LAYER_INIT(Layer_Bevel);
+SYNFIG_LAYER_SET_NAME(Layer_Bevel,"bevel");
+SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Bevel,N_("Bevel"));
+SYNFIG_LAYER_SET_CATEGORY(Layer_Bevel,N_("Stylize"));
+SYNFIG_LAYER_SET_VERSION(Layer_Bevel,"0.2");
+SYNFIG_LAYER_SET_CVS_ID(Layer_Bevel,"$Id$");
 
 /* -- F U N C T I O N S ----------------------------------------------------- */
 
-inline void clamp(sinfg::Vector &v)
+inline void clamp(synfig::Vector &v)
 {
        if(v[0]<0.0)v[0]=0.0;
        if(v[1]<0.0)v[1]=0.0;
@@ -111,7 +112,7 @@ Layer_Bevel::set_param(const String &param, const ValueBase &value)
        IMPORT(type);
        IMPORT(use_luma);
        IMPORT(solid);
-       
+
        return Layer_Composite::set_param(param,value);
 }
 
@@ -126,11 +127,11 @@ Layer_Bevel::get_param(const String &param)const
        EXPORT(angle);
        EXPORT(use_luma);
        EXPORT(solid);
-       
+
        EXPORT_NAME();
        EXPORT_VERSION();
-               
-       return Layer_Composite::get_param(param);       
+
+       return Layer_Composite::get_param(param);
 }
 
 Color
@@ -141,18 +142,18 @@ Layer_Bevel::get_color(Context context, const Point &pos)const
 
        if(get_amount()==0.0)
                return context.get_color(pos);
-       
+
        Color shade;
 
        Real hi_alpha(1.0f-context.get_color(blurpos+offset).get_a());
        Real lo_alpha(1.0f-context.get_color(blurpos-offset).get_a());
-       
+
        Real shade_alpha(hi_alpha-lo_alpha);
        if(shade_alpha>0)
                shade=color1,shade.set_a(shade_alpha);
-       else    
+       else
                shade=color2,shade.set_a(-shade_alpha);
-       
+
        return Color::blend(shade,context.get_color(pos),get_amount(),get_blend_method());
 }
 
@@ -162,39 +163,39 @@ Layer_Bevel::accelerated_render(Context context,Surface *surface,int quality, co
        int x,y;
        SuperCallback stageone(cb,0,5000,10000);
        SuperCallback stagetwo(cb,5000,10000,10000);
-       
+
        const int       w = renddesc.get_w(),
                                h = renddesc.get_h();
        const Real      pw = renddesc.get_pw(),
                                ph = renddesc.get_ph();
        const Vector size(softness,softness);
-       
+
        RendDesc        workdesc(renddesc);
        Surface         worksurface;
        etl::surface<float> blurred;
-       
+
        //callbacks depend on how long the blur takes
        if(size[0] || size[1])
        {
                if(type == Blur::DISC)
                {
                        stageone = SuperCallback(cb,0,5000,10000);
-                       stagetwo = SuperCallback(cb,5000,10000,10000);  
+                       stagetwo = SuperCallback(cb,5000,10000,10000);
                }
                else
                {
                        stageone = SuperCallback(cb,0,9000,10000);
-                       stagetwo = SuperCallback(cb,9000,10000,10000);  
+                       stagetwo = SuperCallback(cb,9000,10000,10000);
                }
        }
        else
        {
                stageone = SuperCallback(cb,0,9999,10000);
-               stagetwo = SuperCallback(cb,9999,10000,10000);  
+               stagetwo = SuperCallback(cb,9999,10000,10000);
        }
-       
+
        //expand the working surface to accommodate the blur
-       
+
        //the expanded size = 1/2 the size in each direction rounded up
        int     halfsizex = (int) (abs(size[0]*.5/pw) + 3),
                halfsizey = (int) (abs(size[1]*.5/ph) + 3);
@@ -208,7 +209,7 @@ Layer_Bevel::accelerated_render(Context context,Surface *surface,int quality, co
                w+abs(offset_u),
                h+abs(offset_v)
        );
-       
+
        //expand by 1/2 size in each direction on either side
        switch(type)
        {
@@ -234,7 +235,7 @@ Layer_Bevel::accelerated_render(Context context,Surface *surface,int quality, co
                #define GAUSSIAN_ADJUSTMENT             (0.05)
                        Real    pw = (Real)workdesc.get_w()/(workdesc.get_br()[0]-workdesc.get_tl()[0]);
                        Real    ph = (Real)workdesc.get_h()/(workdesc.get_br()[1]-workdesc.get_tl()[1]);
-                       
+
                        pw=pw*pw;
                        ph=ph*ph;
 
@@ -244,11 +245,11 @@ Layer_Bevel::accelerated_render(Context context,Surface *surface,int quality, co
                        halfsizex = (halfsizex + 1)/2;
                        halfsizey = (halfsizey + 1)/2;
                        workdesc.set_subwindow( -halfsizex, -halfsizey, offset_w+2*halfsizex, offset_h+2*halfsizey );
-                                               
+
                        break;
                }
        }
-       
+
        //render the background onto the expanded surface
        if(!context.accelerated_render(&worksurface,quality,workdesc,&stageone))
                return false;
@@ -277,7 +278,7 @@ Layer_Bevel::accelerated_render(Context context,Surface *surface,int quality, co
 
        //be sure the surface is of the correct size
        surface->set_wh(renddesc.get_w(),renddesc.get_h());
-       
+
        int u = halfsizex+abs(offset_u), v = halfsizey+abs(offset_v);
        for(y=0;y<renddesc.get_h();y++,v++)
        {
@@ -323,12 +324,12 @@ Layer_Bevel::accelerated_render(Context context,Surface *surface,int quality, co
                                alpha/=2;
                                if(alpha>0)
                                        shade=color1,shade.set_a(shade.get_a()*alpha);
-                               else    
+                               else
                                        shade=color2,shade.set_a(shade.get_a()*-alpha);
                        }
-                               
 
-                                               
+
+
                        if(shade.get_a())
                        {
                                (*surface)[y][x]=Color::blend(shade,worksurface[v][u],get_amount(),get_blend_method());
@@ -336,16 +337,16 @@ Layer_Bevel::accelerated_render(Context context,Surface *surface,int quality, co
                        else (*surface)[y][x] = worksurface[v][u];
                }
        }
-       
+
        if(cb && !cb->amount_complete(10000,10000))
        {
                //if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
                return false;
        }
-               
+
        return true;
 }
-       
+
 Layer::Vocab
 Layer_Bevel::get_param_vocab(void)const
 {
@@ -385,7 +386,7 @@ Layer_Bevel::get_param_vocab(void)const
        ret.push_back(ParamDesc("solid")
                .set_local_name(_("Solid"))
        );
-               
+
        return ret;
 }
 
@@ -403,6 +404,6 @@ Layer_Bevel::get_full_bounding_rect(Context context)const
        Rect bounds(under.expand(softness));
        bounds.expand_x(abs(depth));
        bounds.expand_y(abs(depth));
-               
+
        return bounds;
 }