Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
//#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
#include "trasterfx.h"
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TargetSpotFx : public TStandardZeraryFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(TargetSpotFx)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDoubleParamP m_z;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_angle;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_decay;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_sizex;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_sizey;
Toshihiro Shimizu 890ddd
	TPixelParamP m_color;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TargetSpotFx()
Toshihiro Shimizu 890ddd
		: m_z(100) //args, "Z")
Toshihiro Shimizu 890ddd
		  ,
Toshihiro Shimizu 890ddd
		  m_angle(10) // args, "Angle")
Toshihiro Shimizu 890ddd
		  ,
Toshihiro Shimizu 890ddd
		  m_decay(.01) // args, "Angle")
Toshihiro Shimizu 890ddd
		  ,
Toshihiro Shimizu 890ddd
		  m_sizex(1) // args, "SizeX")
Toshihiro Shimizu 890ddd
		  ,
Toshihiro Shimizu 890ddd
		  m_sizey(1) // args, "sizeY")
Toshihiro Shimizu 890ddd
		  ,
Toshihiro Shimizu 890ddd
		  m_color(TPixel::White) //args, "Color")
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		bindParam(this, "z", m_z);
Toshihiro Shimizu 890ddd
		bindParam(this, "angle", m_angle);
Toshihiro Shimizu 890ddd
		bindParam(this, "decay", m_decay);
Toshihiro Shimizu 890ddd
		bindParam(this, "sizeX", m_sizex);
Toshihiro Shimizu 890ddd
		bindParam(this, "sizeY", m_sizey);
Toshihiro Shimizu 890ddd
		bindParam(this, "color", m_color);
Toshihiro Shimizu 890ddd
		m_decay->setValueRange(0.0, 1.0);
Toshihiro Shimizu 890ddd
		m_sizex->setValueRange(0, (std::numeric_limits<double>::max)());</double>
Toshihiro Shimizu 890ddd
		m_sizey->setValueRange(0, (std::numeric_limits<double>::max)());</double>
Toshihiro Shimizu 890ddd
		m_z->setValueRange(0, (std::numeric_limits<double>::max)());</double>
Toshihiro Shimizu 890ddd
		m_angle->setMeasureName("angle");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	~TargetSpotFx(){};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool doGetBBox(double, TRectD &bBox, const TRenderSettings &info)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		bBox = TConsts::infiniteRectD;
Toshihiro Shimizu 890ddd
		return true; // si potrebbe/dovrebbe fare meglio
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void doCompute(TTile &tile, double frame, const TRenderSettings &ri);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool canHandle(const TRenderSettings &info, double frame) { return false; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixel=""></typename>
Toshihiro Shimizu 890ddd
void doTargetSpot(const TRasterPT<pixel> &ras, TPixel32 m_color0, double sizex, double sizey, double angle,</pixel>
Toshihiro Shimizu 890ddd
				  double decay, double z, TPointD tilepos)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	PIXEL color1 = PIXEL::Black;
Toshihiro Shimizu 890ddd
	PIXEL color0 = PixelConverter<pixel>::from(m_color0);</pixel>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double normx = 1 / sizex;
Toshihiro Shimizu 890ddd
	double normy = 1 / sizey;
Toshihiro Shimizu 890ddd
	double reference = 5 * z;
Toshihiro Shimizu 890ddd
	angle = (TConsts::pi * angle) / 180;
Toshihiro Shimizu 890ddd
	double ttan;
Toshihiro Shimizu 890ddd
	ttan = tan(angle);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int j;
Toshihiro Shimizu 890ddd
	ras->lock();
Toshihiro Shimizu 890ddd
	for (j = 0; j < ras->getLy(); j++) {
Toshihiro Shimizu 890ddd
		TPointD pos = tilepos;
Toshihiro Shimizu 890ddd
		pos.y += j;
Toshihiro Shimizu 890ddd
		PIXEL *pix = ras->pixels(j);
Toshihiro Shimizu 890ddd
		PIXEL *endPix = pix + ras->getLx();
Toshihiro Shimizu 890ddd
		while (pix < endPix) {
Toshihiro Shimizu 890ddd
			double dist, norm;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			pos.x += 1.0;
Toshihiro Shimizu 890ddd
			const double ztmp(-ttan * pos.x + z);
Toshihiro Shimizu 890ddd
			const double zz(ztmp * ztmp);
Toshihiro Shimizu 890ddd
			const double distxy(pos.x * pos.x * normx + pos.y * pos.y * normy);
Toshihiro Shimizu 890ddd
			dist = distxy - zz;
Toshihiro Shimizu 890ddd
			norm = sqrt(distxy + zz);
Toshihiro Shimizu 890ddd
			if (norm < 0)
Toshihiro Shimizu 890ddd
				norm *= -1;
Toshihiro Shimizu 890ddd
			if (dist < 0 && (-ttan * pos.x + z) > 0) {
Toshihiro Shimizu 890ddd
				*pix++ = blend(color0, color1, norm * decay > 1 ? 1 : (norm * decay < 0 ? 0 : norm * decay));
Toshihiro Shimizu 890ddd
			} else if (dist < reference && ztmp > 0) {
Toshihiro Shimizu 890ddd
				PIXEL tmp = blend(color0, color1, norm * decay > 1 ? 1 : (norm * decay < 0 ? 0 : norm * decay));
Toshihiro Shimizu 890ddd
				*pix++ = blend(tmp, color1, dist / (reference));
Toshihiro Shimizu 890ddd
			} else
Toshihiro Shimizu 890ddd
				*pix++ = color1;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TargetSpotFx::doCompute(TTile &tile, double frame, const TRenderSettings &ri)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double z = m_z->getValue(frame) * ri.m_affine.a11;
Toshihiro Shimizu 890ddd
	double angle = m_angle->getValue(frame);
Toshihiro Shimizu 890ddd
	double sizex = m_sizex->getValue(frame) / (ri.m_shrinkX * ri.m_shrinkX);
Toshihiro Shimizu 890ddd
	double sizey = m_sizey->getValue(frame) / (ri.m_shrinkX * ri.m_shrinkX);
Toshihiro Shimizu 890ddd
	const TPixel32 m_color0 = m_color->getPremultipliedValue(frame);
Toshihiro Shimizu 890ddd
	double decay = m_decay->getValue(frame) / 100;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD pos = tile.m_pos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P raster32 = tile.getRaster();
Toshihiro Shimizu 890ddd
	if (raster32)
Toshihiro Shimizu 890ddd
		doTargetSpot<tpixel32>(raster32, m_color0, sizex, sizey, angle, decay, z, pos);</tpixel32>
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		TRaster64P raster64 = tile.getRaster();
Toshihiro Shimizu 890ddd
		if (raster64)
Toshihiro Shimizu 890ddd
			doTargetSpot<tpixel64>(raster64, m_color0, sizex, sizey, angle, decay, z, pos);</tpixel64>
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			throw TException("Brightness&Contrast: unsupported Pixel Type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(TargetSpotFx, "targetSpotFx")