Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "traster.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tspectrumparam.h"
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void doComputeRadialT(TRasterPT<t> ras, TPointD posTrasf, const TSpectrumT<t> &spectrum,</t></t>
Toshihiro Shimizu 890ddd
					  double period, double count, double cycle, const TAffine &aff)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int j;
Toshihiro Shimizu 890ddd
	double maxRadius = period * count;
Toshihiro Shimizu 890ddd
	double freq = 1.0 / period;
Toshihiro Shimizu 890ddd
	ras->lock();
Toshihiro Shimizu 890ddd
	for (j = 0; j < ras->getLy(); j++) {
Toshihiro Shimizu 890ddd
		TPointD posAux = posTrasf;
Toshihiro Shimizu 890ddd
		T *pix = ras->pixels(j);
Toshihiro Shimizu 890ddd
		T *endPix = pix + ras->getLx();
Toshihiro Shimizu 890ddd
		while (pix < endPix) {
Toshihiro Shimizu 890ddd
			double radius = norm(posAux);
Toshihiro Shimizu 890ddd
			double t = 1;
Toshihiro Shimizu 890ddd
			if (radius < maxRadius) {
Toshihiro Shimizu 890ddd
				t = (radius + cycle) * freq;
Toshihiro Shimizu 890ddd
				t -= floor(t);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			//double polinomfactor=(-2*t+3)*(t*t);
Toshihiro Shimizu 890ddd
			*pix++ = spectrum.getPremultipliedValue(t);
Toshihiro Shimizu 890ddd
			posAux.x += aff.a11;
Toshihiro Shimizu 890ddd
			posAux.y += aff.a21;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		posTrasf.x += aff.a12;
Toshihiro Shimizu 890ddd
		posTrasf.y += aff.a22;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void multiRadial(
Toshihiro Shimizu 890ddd
	const TRasterP &ras,
Toshihiro Shimizu 890ddd
	TPointD posTrasf,
Toshihiro Shimizu 890ddd
	const TSpectrumParamP colors,
Toshihiro Shimizu 890ddd
	double period,
Toshihiro Shimizu 890ddd
	double count,
Toshihiro Shimizu 890ddd
	double cycle,
Toshihiro Shimizu 890ddd
	const TAffine &aff,
Toshihiro Shimizu 890ddd
	double frame)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if ((TRaster32P)ras)
Toshihiro Shimizu 890ddd
		doComputeRadialT<tpixel32>(ras, posTrasf, colors->getValue(frame), period, count, cycle, aff);</tpixel32>
Toshihiro Shimizu 890ddd
	else if ((TRaster64P)ras)
Toshihiro Shimizu 890ddd
		doComputeRadialT<tpixel64>(ras, posTrasf, colors->getValue64(frame), period, count, cycle, aff);</tpixel64>
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		throw TException("MultiRadialGradientFx: unsupported Pixel Type");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void doComputeLinearT(TRasterPT<t> ras, TPointD posTrasf, const TSpectrumT<t> &spectrum,</t></t>
Toshihiro Shimizu 890ddd
					  double period, double count, double w_amplitude, double w_freq, double w_phase, double cycle, const TAffine &aff)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double shift = 0;
Toshihiro Shimizu 890ddd
	double maxRadius = period * count / 2.;
Toshihiro Shimizu 890ddd
	double freq = 1.0 / period;
Toshihiro Shimizu 890ddd
	int j;
Toshihiro Shimizu 890ddd
	ras->lock();
Toshihiro Shimizu 890ddd
	for (j = 0; j < ras->getLy(); j++) {
Toshihiro Shimizu 890ddd
		TPointD posAux = posTrasf;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//TPointD pos = tile.m_pos;
Toshihiro Shimizu 890ddd
		//pos.y += j;
Toshihiro Shimizu 890ddd
		T *pix = ras->pixels(j);
Toshihiro Shimizu 890ddd
		T *endPix = pix + ras->getLx();
Toshihiro Shimizu 890ddd
		while (pix < endPix) {
Toshihiro Shimizu 890ddd
			if (w_amplitude)
Toshihiro Shimizu 890ddd
				shift = w_amplitude * sin(w_freq * posAux.y + w_phase);
Toshihiro Shimizu 890ddd
			double radius = posAux.x + shift;
Toshihiro Shimizu 890ddd
			double t = 1;
Toshihiro Shimizu 890ddd
			if (fabs(radius) < maxRadius) {
Toshihiro Shimizu 890ddd
				t = (radius + maxRadius + cycle) * freq;
Toshihiro Shimizu 890ddd
				t -= floor(t);
Toshihiro Shimizu 890ddd
			} else if (radius < 0)
Toshihiro Shimizu 890ddd
				t = 0;
Toshihiro Shimizu 890ddd
			double polinomfactor = (-2 * t + 3) * (t * t);
Toshihiro Shimizu 890ddd
			//pos.x += 1.0;
Toshihiro Shimizu 890ddd
			*pix++ = spectrum.getPremultipliedValue(polinomfactor);
Toshihiro Shimizu 890ddd
			posAux.x += aff.a11;
Toshihiro Shimizu 890ddd
			posAux.y += aff.a21;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		posTrasf.x += aff.a12;
Toshihiro Shimizu 890ddd
		posTrasf.y += aff.a22;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void multiLinear(
Toshihiro Shimizu 890ddd
	const TRasterP &ras,
Toshihiro Shimizu 890ddd
	TPointD posTrasf,
Toshihiro Shimizu 890ddd
	const TSpectrumParamP colors,
Toshihiro Shimizu 890ddd
	double period,
Toshihiro Shimizu 890ddd
	double count,
Toshihiro Shimizu 890ddd
	double amplitude,
Toshihiro Shimizu 890ddd
	double freq,
Toshihiro Shimizu 890ddd
	double phase,
Toshihiro Shimizu 890ddd
	double cycle,
Toshihiro Shimizu 890ddd
	const TAffine &aff,
Toshihiro Shimizu 890ddd
	double frame)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if ((TRaster32P)ras)
Toshihiro Shimizu 890ddd
		doComputeLinearT<tpixel32>(</tpixel32>
Toshihiro Shimizu 890ddd
			ras, posTrasf,
Toshihiro Shimizu 890ddd
			colors->getValue(frame),
Toshihiro Shimizu 890ddd
			period, count, amplitude, freq, phase, cycle, aff);
Toshihiro Shimizu 890ddd
	else if ((TRaster64P)ras)
Toshihiro Shimizu 890ddd
		doComputeLinearT<tpixel64>(</tpixel64>
Toshihiro Shimizu 890ddd
			ras, posTrasf,
Toshihiro Shimizu 890ddd
			colors->getValue64(frame),
Toshihiro Shimizu 890ddd
			period, count, amplitude, freq, phase, cycle, aff);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		throw TException("MultiLinearGradientFx: unsupported Pixel Type");
Toshihiro Shimizu 890ddd
}