/* Copyright (C) 2009 Nasca Octavian Paul Author: Nasca Octavian Paul This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. 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 (version 2) for more details. You should have received a copy of the GNU General Public License (version 2) along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include "FreeEdit.h" #include #ifdef HAVE_PS_FREE_EDIT FreeEdit::FreeEdit(){ enabled=false; smooth=0.0; interp_mode=LINEAR; npos=FREE_EDIT_MAX_POINTS; pos=new FreeEditPos[npos]; for (int i=0;i posx(npos_used); std::vector posy(npos_used); int k=0; for (int i=0;iposx[p2])&&(p21e-5) x0=(x-px1)/diffx; if (interp_mode==COSINE) x0=(1.0f-cos(x0*(float)M_PI))*0.5f; REALTYPE y=y=posy[p1]*(1.0f-x0)+posy[p2]*x0; data[i]=y; }; //smooth the curve if (smooth>0.01){ const int max_times=4; REALTYPE a=exp(log(0.25f)/(smooth*smooth*datasize*0.25f)); if ((a<=0.0f)||(a>=1.0f)) return; a=pow(a,max_times); for (k=0;k=0;i--) data[i]=data[i]*(1.0f-a)+data[i+1]*a; }; }; if (real_values){ for (int i=0;i1.0) x=1.0; REALTYPE rx=x*curve.size; REALTYPE rxh=floor(rx); int k=(int)rxh; REALTYPE rxl=rx-rxh; if (k<0) k=0; if (k>(curve.size-1)) k=curve.size-1; int k1=k+1; if (k1>(curve.size-1)) k1=curve.size-1; return curve.data[k]*(1.0f-rxl)+curve.data[k1]*rxl; }; /* void FreeEdit::add2XML(XMLwrapper *xml){ xml->addparbool("enabled",enabled); xml->addparreal("smooth",smooth); xml->addpar("interp_mode",interp_mode); xml->beginbranch("POINTS"); for (int i=0;ibeginbranch("POINT",i); xml->addparbool("enabled",pos[i].enabled); xml->addparreal("x",pos[i].x); xml->addparreal("y",pos[i].y); xml->endbranch(); }; xml->endbranch(); xml->beginbranch("EXTREME_X"); extreme_x.add2XML(xml); xml->endbranch(); xml->beginbranch("EXTREME_Y"); extreme_y.add2XML(xml); xml->endbranch(); }; void FreeEdit::getfromXML(XMLwrapper *xml){ enabled=xml->getparbool("enabled",enabled); smooth=xml->getparreal("smooth",smooth); interp_mode=(INTERP_MODE)xml->getpar("interp_mode",interp_mode,0,1); if (xml->enterbranch("POINTS")){ for (int i=0;ienterbranch("POINT",i)){ pos[i].enabled=xml->getparbool("enabled",pos[i].enabled); pos[i].x=xml->getparreal("x",pos[i].x); pos[i].y=xml->getparreal("y",pos[i].y); xml->exitbranch(); }; }; xml->exitbranch(); }; if (xml->enterbranch("EXTREME_X")){ extreme_x.getfromXML(xml); xml->exitbranch(); }; if (xml->enterbranch("EXTREME_Y")){ extreme_y.getfromXML(xml); xml->exitbranch(); }; update_curve(); }; */ #endif