Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "tspectrumparam.h"
Toshihiro Shimizu 890ddd
#include "tparamuiconcept.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DiamondGradientFx : public TStandardZeraryFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(DiamondGradientFx)
Toshihiro Shimizu 890ddd
	TSpectrumParamP m_colors;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_size;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	DiamondGradientFx()
Toshihiro Shimizu 890ddd
		: m_size(100.0)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TSpectrum::ColorKey colors[] = {
Toshihiro Shimizu 890ddd
			TSpectrum::ColorKey(0, TPixel32::White),
Toshihiro Shimizu 890ddd
			TSpectrum::ColorKey(0.2, TPixel32::Yellow),
Toshihiro Shimizu 890ddd
			TSpectrum::ColorKey(0.4, TPixel32::Blue),
Toshihiro Shimizu 890ddd
			TSpectrum::ColorKey(0.6, TPixel32::Green),
Toshihiro Shimizu 890ddd
			TSpectrum::ColorKey(0.8, TPixel32::Magenta),
Toshihiro Shimizu 890ddd
			TSpectrum::ColorKey(1, TPixel32::Red)};
Toshihiro Shimizu 890ddd
		m_colors = TSpectrumParamP(tArrayCount(colors), colors);
Toshihiro Shimizu 890ddd
		m_size->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
		bindParam(this, "colors", m_colors);
Toshihiro Shimizu 890ddd
		bindParam(this, "size", m_size);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	~DiamondGradientFx(){};
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;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
	void doCompute(TTile &tile, double frame, const TRenderSettings &ri);
Toshihiro Shimizu 890ddd
	bool canHandle(const TRenderSettings &info, double frame) { return false; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void getParamUIs(TParamUIConcept *&concepts, int &length)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		concepts = new TParamUIConcept[length = 1];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		concepts[0].m_type = TParamUIConcept::RADIUS;
Toshihiro Shimizu 890ddd
		concepts[0].m_label = "Size";
Toshihiro Shimizu 890ddd
		concepts[0].m_params.push_back(m_size);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixel=""></typename>
Toshihiro Shimizu 890ddd
void doDiamondGradient(const TRasterPT<pixel> &ras, const TSpectrumT<pixel> &spectrum, TPointD &tilepos, double size)</pixel></pixel>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	PIXEL outpixel = spectrum.getPremultipliedValue(1.);
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
		double fy = fabs(pos.y) / size;
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 s;
Toshihiro Shimizu 890ddd
			double fx = fabs(pos.x) / size;
Toshihiro Shimizu 890ddd
			if ((fx * fy) < 1) {
Toshihiro Shimizu 890ddd
				s = fx * fy;
Toshihiro Shimizu 890ddd
				*pix++ = spectrum.getPremultipliedValue(s);
Toshihiro Shimizu 890ddd
			} else
Toshihiro Shimizu 890ddd
				*pix++ = outpixel;
Toshihiro Shimizu 890ddd
			pos.x += 1.0;
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 DiamondGradientFx::doCompute(TTile &tile, double frame, const TRenderSettings &ri)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double size = m_size->getValue(frame) * ri.m_affine.a11 / ri.m_shrinkX;
Toshihiro Shimizu 890ddd
	TPointD pos = tile.m_pos;
Toshihiro Shimizu 890ddd
	if (TRaster32P raster32 = tile.getRaster())
Toshihiro Shimizu 890ddd
		doDiamondGradient<tpixel32>(</tpixel32>
Toshihiro Shimizu 890ddd
			raster32,
Toshihiro Shimizu 890ddd
			m_colors->getValue(frame),
Toshihiro Shimizu 890ddd
			pos, size);
Toshihiro Shimizu 890ddd
	else if (TRaster64P raster64 = tile.getRaster())
Toshihiro Shimizu 890ddd
		doDiamondGradient<tpixel64>(</tpixel64>
Toshihiro Shimizu 890ddd
			raster64,
Toshihiro Shimizu 890ddd
			m_colors->getValue64(frame),
Toshihiro Shimizu 890ddd
			pos, size);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		throw TException("DiamondGradientFx: unsupported Pixel Type");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(DiamondGradientFx, "diamondGradientFx");