/* === 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 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
*/
/* ========================================================================= */
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 ----------------------------------------------------- */
{
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);
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)
{
#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;
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());
//if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
return false;
}
-
+
return true;
}
-
+
Layer::Vocab
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;
}
return context.get_full_bounding_rect();
Rect bounds(context.get_full_bounding_rect().expand_x(size[0]).expand_y(size[1]));
-
+
return bounds;
}