/* === S Y N F I G ========================================================= */
/*! \file shade.cpp
-** \brief Template Header
+** \brief Implementation of the "Shade" layer
**
** $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
/*#define TYPE_BOX 0
#define TYPE_FASTGUASSIAN 1
-#define TYPE_FASTGAUSSIAN 1
#define TYPE_CROSS 2
-#define TYPE_GUASSIAN 3
#define TYPE_GAUSSIAN 3
#define TYPE_DISC 4
*/
SYNFIG_LAYER_INIT(Layer_Shade);
SYNFIG_LAYER_SET_NAME(Layer_Shade,"shade");
-SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Shade,_("Shade"));
-SYNFIG_LAYER_SET_CATEGORY(Layer_Shade,_("Stylize"));
+SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Shade,N_("Shade"));
+SYNFIG_LAYER_SET_CATEGORY(Layer_Shade,N_("Stylize"));
SYNFIG_LAYER_SET_VERSION(Layer_Shade,"0.2");
SYNFIG_LAYER_SET_CVS_ID(Layer_Shade,"$Id$");
size(0.1,0.1),
type(Blur::FASTGAUSSIAN),
color(Color::black()),
- offset(0.2,-0.2),
+ origin(0.2,-0.2),
invert(false)
{
}
{
IMPORT_PLUS(size,clamp(size));
IMPORT(type);
- IMPORT(color);
- IMPORT(offset);
+ IMPORT_PLUS(color, { if (color.get_a() == 0) { if (converted_blend_) {
+ set_blend_method(Color::BLEND_ALPHA_OVER);
+ color.set_a(1); } else transparent_color_ = true; } });
+ IMPORT(origin);
IMPORT(invert);
+ IMPORT_AS(origin,"offset");
+
return Layer_Composite::set_param(param,value);
}
EXPORT(size);
EXPORT(type);
EXPORT(color);
- EXPORT(offset);
+ EXPORT(origin);
EXPORT(invert);
EXPORT_NAME();
Color shade(color);
if(!invert)
- shade.set_a(context.get_color(blurpos-offset).get_a());
+ shade.set_a(context.get_color(blurpos-origin).get_a());
else
- shade.set_a(1.0f-context.get_color(blurpos-offset).get_a());
+ shade.set_a(1.0f-context.get_color(blurpos-origin).get_a());
return Color::blend(shade,context.get_color(pos),get_amount(),get_blend_method());
}
int halfsizex = (int) (abs(size[0]*.5/pw) + 3),
halfsizey = (int) (abs(size[1]*.5/ph) + 3);
- int offset_u(-round_to_int(offset[0]/pw)),offset_v(-round_to_int(offset[1]/ph));
+ int origin_u(-round_to_int(origin[0]/pw)),origin_v(-round_to_int(origin[1]/ph));
- int offset_w(w+abs(offset_u)),offset_h(h+abs(offset_v));
+ int origin_w(w+abs(origin_u)),origin_h(h+abs(origin_v));
workdesc.set_subwindow(
- offset_u<0?offset_u:0,
- offset_v<0?offset_v:0,
- (offset_u>0?offset_u:0)+w,
- (offset_v>0?offset_v:0)+h
+ origin_u<0?origin_u:0,
+ origin_v<0?origin_v:0,
+ (origin_u>0?origin_u:0)+w,
+ (origin_v>0?origin_v:0)+h
);
- /*
- if(quality >=10)
+ if(quality >= 10)
{
halfsizex=1;
halfsizey=1;
- }else
- */
- if(quality == 9)
+ }
+ else if (quality == 9)
{
halfsizex/=4;
halfsizey/=4;
case Blur::BOX:
case Blur::CROSS:
{
- workdesc.set_subwindow(-max(1,halfsizex),-max(1,halfsizey),offset_w+2*max(1,halfsizex),offset_h+2*max(1,halfsizey));
+ workdesc.set_subwindow(-max(1,halfsizex),-max(1,halfsizey),origin_w+2*max(1,halfsizex),origin_h+2*max(1,halfsizey));
break;
}
case Blur::FASTGAUSSIAN:
halfsizex*=2;
halfsizey*=2;
}
- workdesc.set_subwindow(-max(1,halfsizex),-max(1,halfsizey),offset_w+2*max(1,halfsizex),offset_h+2*max(1,halfsizey));
+ workdesc.set_subwindow(-max(1,halfsizex),-max(1,halfsizey),origin_w+2*max(1,halfsizex),origin_h+2*max(1,halfsizey));
break;
}
case Blur::GAUSSIAN:
halfsizex = (halfsizex + 1)/2;
halfsizey = (halfsizey + 1)/2;
- workdesc.set_subwindow( -halfsizex, -halfsizey, offset_w+2*halfsizex, offset_h+2*halfsizey );
+ workdesc.set_subwindow( -halfsizex, -halfsizey, origin_w+2*halfsizex, origin_h+2*halfsizey );
break;
}
//be sure the surface is of the correct size
surface->set_wh(renddesc.get_w(),renddesc.get_h());
- int u = halfsizex-(offset_u<0?offset_u:0), v = halfsizey-(offset_v<0?offset_v:0);
+ int u = halfsizex-(origin_u<0?origin_u:0), v = halfsizey-(origin_v<0?origin_v:0);
for(y=0;y<renddesc.get_h();y++,v++)
{
- u = halfsizex-(offset_u<0?offset_u:0);
+ u = halfsizex-(origin_u<0?origin_u:0);
for(x=0;x<renddesc.get_w();x++,u++)
{
Color a(color);
if(!invert)
- a.set_a(blurred.linear_sample(offset_u+(float)u,offset_v+(float)v));
+ a.set_a(blurred.linear_sample(origin_u+(float)u,origin_v+(float)v));
else
- a.set_a(1.0f-blurred.linear_sample(offset_u+(float)u,offset_v+(float)v));
+ a.set_a(1.0f-blurred.linear_sample(origin_u+(float)u,origin_v+(float)v));
if(a.get_a() || get_blend_method()==Color::BLEND_STRAIGHT)
{
Blur(size,type,&stagetwo)(blurred,workdesc.get_br()-workdesc.get_tl(),blurred);
- int u = halfsizex-(offset_u<0?offset_u:0), v = halfsizey-(offset_v<0?offset_v:0);
+ int u = halfsizex-(origin_u<0?origin_u:0), v = halfsizey-(origin_v<0?origin_v:0);
for(y=0;y<renddesc.get_h();y++,v++)
{
- u = halfsizex-(offset_u<0?offset_u:0);
+ u = halfsizex-(origin_u<0?origin_u:0);
for(x=0;x<renddesc.get_w();x++,u++)
{
Color a(color);
if(!invert)
- a.set_a(blurred.linear_sample(((float)offset_u+(float)u)/(float)fw,((float)offset_v+(float)v)/(float)fh));
+ a.set_a(blurred.linear_sample(((float)origin_u+(float)u)/(float)fw,((float)origin_v+(float)v)/(float)fh));
else
- a.set_a(1.0f-blurred.linear_sample(((float)offset_u+(float)u)/fw,((float)offset_v+(float)v)/(float)fh));
+ a.set_a(1.0f-blurred.linear_sample(((float)origin_u+(float)u)/fw,((float)origin_v+(float)v)/(float)fh));
if(a.get_a() || get_blend_method()==Color::BLEND_STRAIGHT)
{
ret.push_back(ParamDesc("color")
.set_local_name(_("Color"))
);
- ret.push_back(ParamDesc("offset")
- .set_local_name(_("Offset"))
+ ret.push_back(ParamDesc("origin")
+ .set_local_name(_("Origin"))
);
ret.push_back(ParamDesc("size")
.set_local_name(_("Size"))
.set_description(_("Size of Shade"))
.set_is_distance()
- .set_origin("offset")
+ .set_origin("origin")
);
ret.push_back(ParamDesc("type")
.set_local_name(_("Type"))
if(Color::is_onto(get_blend_method()))
return under;
- Rect bounds((under+offset).expand_x(size[0]).expand_y(size[1]));
+ Rect bounds((under+origin).expand_x(size[0]).expand_y(size[1]));
if(is_solid_color())
return bounds;