/* edgeglow.cpp * Copyright (C) 2008 Salsaman (salsaman@gmail.com) * This file is a Frei0r plugin. * * This program 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. * * This program 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. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "frei0r.hpp" #include "frei0r/math.h" #include class edgeglow : public frei0r::filter { public: double lthresh; double lupscale; double lredscale; edgeglow(unsigned int width, unsigned int height) { lthresh = 0.0; lupscale = 0.0; lredscale = 0.0; register_param(lthresh, "lthresh", "threshold for edge lightening"); register_param(lupscale, "lupscale", "multiplier for upscaling edge brightness"); register_param(lredscale, "lredscale", "multiplier for downscaling non-edge brightness"); } virtual void update(double time, uint32_t* out, const uint32_t* in) { std::copy(in, in + width*height, out); for (unsigned int y=1; ymax) max=G; if (B>max) max=B; unsigned char min=R; if (Gmax) max=G; if (B>max) max=B; min=R; if (G(lt=lthresh*255.)) { // if lightness > threshold, we add it to the lightness of the original l=CLAMP0255((int32_t)((float)l*lupscale+((float)max+(float)min)/2.)); } // otherwise reduce else if (lredscale>0.) { l=((float)max+(float)min)/2.*(1.-lredscale); } if (lredscale>0.||l>lt) { if (max==min) { h=0; s=0.; } else { if (max==R) { h=(unsigned int)(60.*((float)G-(float)B)/((float)max-(float)min)); if (G1.) tr-=1.; if (tb<0.) tb+=1.; if (tr<1./6.) g[0]=CLAMP0255(p+((q-p)*6.*tr)); else if (tr<0.5) g[0]=CLAMP0255((int32_t)q); else if (tr<2./3.) g[0]=CLAMP0255(p+((q-p)*6.*(2./3.-tr))); else g[0]=CLAMP0255((int32_t)p); if (tg<1./6.) g[1]=CLAMP0255(p+((q-p)*6.*tg)); else if (tg<0.5) g[1]=CLAMP0255((int32_t)q); else if (tg<2./3.) g[1]=CLAMP0255(p+((q-p)*6.*(2./3.-tg))); else g[1]=CLAMP0255((int32_t)p); if (tb<1./6.) g[2]=CLAMP0255(p+((q-p)*6.*tb)); else if (tb<0.5) g[2]=CLAMP0255((int32_t)q); else if (tb<2./3.) g[2]=CLAMP0255(p+((q-p)*6.*(2./3.-tb))); else g[2]=CLAMP0255((int32_t)p); } else { g[0]=p5[0]; g[1]=p5[1]; g[2]=p5[2]; } } } } }; frei0r::construct plugin("Edgeglow", "Edgeglow filter", "Salsaman", 0,3, F0R_COLOR_MODEL_RGBA8888);