Added copyright lines for files I've edited this year.
[synfig.git] / synfig-core / trunk / src / modules / mod_filter / blur.cpp
index 4832791..e5104b0 100644 (file)
@@ -1,11 +1,12 @@
 /* === S Y N F I G ========================================================= */
-/*!    \file blur.cpp
-**     \brief Template Header
+/*!    \file mod_filter/blur.cpp
+**     \brief Implementation of the "Blur" layer
 **
-**     $Id: blur.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $
+**     $Id$
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2008 Chris Moore
 **
 **     This package is free software; you can redistribute it and/or
 **     modify it under the terms of the GNU General Public License as
@@ -63,10 +64,10 @@ using namespace std;
 
 SYNFIG_LAYER_INIT(Blur_Layer);
 SYNFIG_LAYER_SET_NAME(Blur_Layer,"blur");
-SYNFIG_LAYER_SET_LOCAL_NAME(Blur_Layer,_("Blur"));
-SYNFIG_LAYER_SET_CATEGORY(Blur_Layer,_("Blurs"));
+SYNFIG_LAYER_SET_LOCAL_NAME(Blur_Layer,N_("Blur"));
+SYNFIG_LAYER_SET_CATEGORY(Blur_Layer,N_("Blurs"));
 SYNFIG_LAYER_SET_VERSION(Blur_Layer,"0.2");
-SYNFIG_LAYER_SET_CVS_ID(Blur_Layer,"$Id: blur.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $");
+SYNFIG_LAYER_SET_CVS_ID(Blur_Layer,"$Id$");
 
 /* -- F U N C T I O N S ----------------------------------------------------- */
 
@@ -97,18 +98,18 @@ Blur_Layer::get_param(const String &param)const
 {
        EXPORT(size);
        EXPORT(type);
-       
+
        EXPORT_NAME();
        EXPORT_VERSION();
-               
-       return Layer_Composite::get_param(param);       
+
+       return Layer_Composite::get_param(param);
 }
 
 Color
 Blur_Layer::get_color(Context context, const Point &pos)const
 {
        Point blurpos = Blur(size,type)(pos);
-       
+
        if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
                return context.get_color(blurpos);
 
@@ -121,44 +122,48 @@ Blur_Layer::get_color(Context context, const Point &pos)const
 bool
 Blur_Layer::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
 {
-       int x,y;
+       // don't do anything at quality 10
+       if (quality == 10)
+               return context.accelerated_render(surface,quality,renddesc,cb);
+
+       // 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();
-       
+
        RendDesc        workdesc(renddesc);
        Surface         worksurface,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);
-               
+
        //expand by 1/2 size in each direction on either side
        switch(type)
        {
@@ -184,7 +189,7 @@ Blur_Layer::accelerated_render(Context context,Surface *surface,int quality, con
                #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;
 
@@ -194,21 +199,21 @@ Blur_Layer::accelerated_render(Context context,Surface *surface,int quality, con
                        halfsizex = (halfsizex + 1)/2;
                        halfsizey = (halfsizey + 1)/2;
                        workdesc.set_subwindow( -halfsizex, -halfsizey, w+2*halfsizex, h+2*halfsizey );
-                                               
+
                        break;
                }
        }
-       
+
        //render the background onto the expanded surface
        if(!context.accelerated_render(&worksurface,quality,workdesc,&stageone))
                return false;
 
        //blur the image
        Blur(size,type,&stagetwo)(worksurface,workdesc.get_br()-workdesc.get_tl(),blurred);
-       
+
        //be sure the surface is of the correct size
        surface->set_wh(renddesc.get_w(),renddesc.get_h());
-       
+
        {
                Surface::pen pen(surface->begin());
                worksurface.blit_to(pen,halfsizex,halfsizey,renddesc.get_w(),renddesc.get_h());
@@ -224,10 +229,10 @@ Blur_Layer::accelerated_render(Context context,Surface *surface,int quality, con
                //if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
                return false;
        }
-               
+
        return true;
 }
-       
+
 Layer::Vocab
 Blur_Layer::get_param_vocab(void)const
 {
@@ -247,7 +252,7 @@ Blur_Layer::get_param_vocab(void)const
                .add_enum_value(Blur::GAUSSIAN,"gaussian",_("Gaussian Blur"))
                .add_enum_value(Blur::DISC,"disc",_("Disc Blur"))
        );
-       
+
        return ret;
 }
 
@@ -258,6 +263,6 @@ Blur_Layer::get_full_bounding_rect(Context context)const
                return context.get_full_bounding_rect();
 
        Rect bounds(context.get_full_bounding_rect().expand_x(size[0]).expand_y(size[1]));
-       
+
        return bounds;
 }