Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "tspectrumparam.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class Test_BoxFx : public TStandardRasterFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(Test_BoxFx)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterFxPort m_input;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_h;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_v;
Toshihiro Shimizu 890ddd
	TPixelParamP m_color;
Toshihiro Shimizu 890ddd
	TPointParamP m_point;
Toshihiro Shimizu 890ddd
	TSpectrumParamP m_colors;
Toshihiro Shimizu 890ddd
	TIntParamP m_int;
Toshihiro Shimizu 890ddd
	TIntEnumParamP m_enum;
Toshihiro Shimizu 890ddd
	TRangeParamP m_range;
Toshihiro Shimizu 890ddd
	TBoolParamP m_bool;
Toshihiro Shimizu 890ddd
	TStringParamP m_string;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	Test_BoxFx()
Toshihiro Shimizu 890ddd
		: m_h(30.0), m_v(30.0), m_color(TPixel32::Blue), m_range(DoublePair(100., 100.)), m_int(12), m_enum(new TIntEnumParam(0, "Color")), m_point(TPointD(0.0, 0.0)), m_bool(true), m_string(L"urka")
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_h->setValueRange(0, 100);
Toshihiro Shimizu 890ddd
		m_enum->addItem(1, "Uno");
Toshihiro Shimizu 890ddd
		m_enum->addItem(2, "Due");
Toshihiro Shimizu 890ddd
		m_enum->addItem(3, "Tre");
Toshihiro Shimizu 890ddd
		bindParam(this, "h", m_h);
Toshihiro Shimizu 890ddd
		bindParam(this, "v", m_v);
Toshihiro Shimizu 890ddd
		bindParam(this, "color", m_color);
Toshihiro Shimizu 890ddd
		bindParam(this, "Point", m_point);
Toshihiro Shimizu 890ddd
		bindParam(this, "enum", m_enum);
Toshihiro Shimizu 890ddd
		m_enum->addItem(1, "Spectrum");
Toshihiro Shimizu 890ddd
		bindParam(this, "int", m_int);
Toshihiro Shimizu 890ddd
		bindParam(this, "range", m_range);
Toshihiro Shimizu 890ddd
		bindParam(this, "bool", m_bool);
Toshihiro Shimizu 890ddd
		TSpectrum::ColorKey colors[] = {
Toshihiro Shimizu 890ddd
			TSpectrum::ColorKey(0, TPixel32::White),
Toshihiro Shimizu 890ddd
			TSpectrum::ColorKey(0.5, TPixel32::Yellow),
Toshihiro Shimizu 890ddd
			TSpectrum::ColorKey(1, TPixel32::Red)};
Toshihiro Shimizu 890ddd
		m_colors = TSpectrumParamP(tArrayCount(colors), colors);
Toshihiro Shimizu 890ddd
		bindParam(this, "spectrum", m_colors);
Toshihiro Shimizu 890ddd
		bindParam(this, "string", m_string);
Toshihiro Shimizu 890ddd
		addInputPort("Source", m_input);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~Test_BoxFx(){};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool canHandle(const TRenderSettings &info, double frame) { return false; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (!m_input.isConnected()) {
Toshihiro Shimizu 890ddd
			bBox = TRectD();
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		return m_input->doGetBBox(frame, bBox, info);
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void doCompute(TTile &tile, double frame, const TRenderSettings &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class class="" pix,="" ras=""></class>
Toshihiro Shimizu 890ddd
void doTest_Box(
Toshihiro Shimizu 890ddd
	RAS ras,
Toshihiro Shimizu 890ddd
	double h, double v,
Toshihiro Shimizu 890ddd
	TPointD pos,
Toshihiro Shimizu 890ddd
	TPixel32 &color32,
Toshihiro Shimizu 890ddd
	int my_enum, int my_int,
Toshihiro Shimizu 890ddd
	const TSpectrumT<pix> spectrum,</pix>
Toshihiro Shimizu 890ddd
	TPointD point,
Toshihiro Shimizu 890ddd
	DoublePair range,
Toshihiro Shimizu 890ddd
	bool my_bool)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int lx = ras->getLx();
Toshihiro Shimizu 890ddd
	int ly = ras->getLy();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD tmp = pos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const PIX color = PixelConverter<ras::pixel>::from(color32);</ras::pixel>
Toshihiro Shimizu 890ddd
	int j, i;
Toshihiro Shimizu 890ddd
	for (j = 0; j < ly; j++) {
Toshihiro Shimizu 890ddd
		PIX *pix = ras->pixels(j);
Toshihiro Shimizu 890ddd
		tmp.y++;
Toshihiro Shimizu 890ddd
		tmp.x = pos.x;
Toshihiro Shimizu 890ddd
		for (i = 0; i < lx; i++) {
Toshihiro Shimizu 890ddd
			if (tmp.x > 0 && tmp.x < h && tmp.y > 0 && tmp.y < v) {
Toshihiro Shimizu 890ddd
				if (my_enum && my_bool) {
Toshihiro Shimizu 890ddd
					if (tmp.x > range.first && tmp.x < range.second)
Toshihiro Shimizu 890ddd
						*pix = spectrum.getPremultipliedValue(sqrt((tmp.x - point.x) * (tmp.x - point.x) / (h * h) + (tmp.y - point.y) * (tmp.y - point.y) / (v * v)));
Toshihiro Shimizu 890ddd
					else
Toshihiro Shimizu 890ddd
						*pix = color;
Toshihiro Shimizu 890ddd
				} else
Toshihiro Shimizu 890ddd
					*pix = color;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			tmp.x++;
Toshihiro Shimizu 890ddd
			pix++;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Test_BoxFx::doCompute(TTile &tile, double frame, const TRenderSettings &ri)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_input.isConnected())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	wstring text = m_string->getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_input->compute(tile, frame, ri);
Toshihiro Shimizu 890ddd
	TPixel32 color = m_color->getValue(frame);
Toshihiro Shimizu 890ddd
	double h = m_h->getValue(frame);
Toshihiro Shimizu 890ddd
	double v = m_v->getValue(frame);
Toshihiro Shimizu 890ddd
	int my_enum = m_enum->getValue();
Toshihiro Shimizu 890ddd
	// TSpectrum spectrum = m_colors->getValue(frame);
Toshihiro Shimizu 890ddd
	int my_int = m_int->getValue();
Toshihiro Shimizu 890ddd
	TPointD point = m_point->getValue(frame);
Toshihiro Shimizu 890ddd
	DoublePair range = m_range->getValue(frame);
Toshihiro Shimizu 890ddd
	bool my_bool = m_bool->getValue();
Toshihiro Shimizu 890ddd
	if (TRaster32P raster32 = tile.getRaster())
Toshihiro Shimizu 890ddd
		doTest_Box<tpixel32, traster32p="">(</tpixel32,>
Toshihiro Shimizu 890ddd
			raster32, h, v, tile.m_pos, color, my_enum, my_int,
Toshihiro Shimizu 890ddd
			m_colors->getValue(frame), point, range, my_bool);
Toshihiro Shimizu 890ddd
	else if (TRaster64P raster64 = tile.getRaster())
Toshihiro Shimizu 890ddd
		doTest_Box<tpixel64, traster64p="">(</tpixel64,>
Toshihiro Shimizu 890ddd
			raster64, h, v, tile.m_pos, color, my_enum, my_int,
Toshihiro Shimizu 890ddd
			m_colors->getValue64(frame), point, range, my_bool);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		throw TException("Test_BoxFx: unsupported Pixel Type");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(Test_BoxFx, "test_BoxFx")
Toshihiro Shimizu 890ddd
#endif