X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftags%2Fstable%2Fsrc%2Fmodules%2Fmod_filter%2Fblur.cpp;h=e5104b01e98222e7458dfe225cc3b6ebefd8c63d;hb=47fce282611fbba1044921d22ca887f9b53ad91a;hp=c9cabd2eabcaafd38d2393c273b8effa8c7e8e29;hpb=46036a57bc1ab5583c5d5c2188e8c52d7682d9d5;p=synfig.git diff --git a/synfig-core/tags/stable/src/modules/mod_filter/blur.cpp b/synfig-core/tags/stable/src/modules/mod_filter/blur.cpp index c9cabd2..e5104b0 100644 --- a/synfig-core/tags/stable/src/modules/mod_filter/blur.cpp +++ b/synfig-core/tags/stable/src/modules/mod_filter/blur.cpp @@ -1,20 +1,22 @@ -/* === S I N F G =========================================================== */ -/*! \file blur.cpp -** \brief Template Header +/* === S Y N F I G ========================================================= */ +/*! \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 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2008 Chris Moore ** -** 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 */ /* ========================================================================= */ @@ -30,22 +32,22 @@ #include "blur.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #endif -using namespace sinfg; +using namespace synfig; using namespace etl; using namespace std; @@ -60,16 +62,16 @@ using namespace std; /* -- G L O B A L S --------------------------------------------------------- */ -SINFG_LAYER_INIT(Blur_Layer); -SINFG_LAYER_SET_NAME(Blur_Layer,"blur"); -SINFG_LAYER_SET_LOCAL_NAME(Blur_Layer,_("Blur")); -SINFG_LAYER_SET_CATEGORY(Blur_Layer,_("Blurs")); -SINFG_LAYER_SET_VERSION(Blur_Layer,"0.2"); -SINFG_LAYER_SET_CVS_ID(Blur_Layer,"$Id: blur.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $"); +SYNFIG_LAYER_INIT(Blur_Layer); +SYNFIG_LAYER_SET_NAME(Blur_Layer,"blur"); +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$"); /* -- 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; @@ -96,18 +98,18 @@ Blur_Layer::get_param(const String ¶m)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); @@ -120,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) { @@ -183,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; @@ -193,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()); @@ -223,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 { @@ -246,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; } @@ -257,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; }