Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
#pragma warning(disable : 4996)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ttzpimagefx.h"
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "trasterfx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
class BlendTzFx : public TStandardRasterFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(BlendTzFx)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterFxPort m_input;
Toshihiro Shimizu 890ddd
	TStringParamP m_colorIndex;
Toshihiro Shimizu 890ddd
	TBoolParamP m_noBlending;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_amount;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_smoothness;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	BlendTzFx() : m_colorIndex(L"1,2,3"), m_noBlending(false), m_amount(10), m_smoothness(10)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_amount->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
		bindParam(this, "Color_Index", m_colorIndex);
Toshihiro Shimizu 890ddd
		bindParam(this, "Amount", m_amount);
Toshihiro Shimizu 890ddd
		bindParam(this, "Smoothness", m_smoothness);
Toshihiro Shimizu 890ddd
		bindParam(this, "noBlending", m_noBlending);
Toshihiro Shimizu 890ddd
		addInputPort("Source", m_input);
Toshihiro Shimizu 890ddd
		m_amount->setValueRange(0, std::numeric_limits<double>::max());</double>
Toshihiro Shimizu 890ddd
		m_smoothness->setValueRange(0, std::numeric_limits<double>::max());</double>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~BlendTzFx()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void transform(double frame,
Toshihiro Shimizu 890ddd
				   int port,
Toshihiro Shimizu 890ddd
				   const TRectD &rectOnOutput,
Toshihiro Shimizu 890ddd
				   const TRenderSettings &infoOnOutput,
Toshihiro Shimizu 890ddd
				   TRectD &rectOnInput,
Toshihiro Shimizu 890ddd
				   TRenderSettings &infoOnInput);
Toshihiro Shimizu 890ddd
	void doCompute(TTile &tile, double frame, const TRenderSettings &ri);
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
			//Build the render data
Toshihiro Shimizu 890ddd
			TRenderSettings info2(info);
Toshihiro Shimizu 890ddd
			buildBlendData(info2, frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			return m_input->doGetBBox(frame, bBox, info2);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			bBox = TRectD();
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool canHandle(const TRenderSettings &info, double frame)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool allowUserCacheOnPort(int port) { return false; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	void getValues(const char *argv[], int argc, double frame)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		double values[6];
Toshihiro Shimizu 890ddd
		values[2] = m_smoothness->getValue(frame);
Toshihiro Shimizu 890ddd
		values[3] = m_amount->getValue(frame) * 0.5;
Toshihiro Shimizu 890ddd
		values[4] = m_noBlending->getValue() ? 1.0 : 0.0;
Toshihiro Shimizu 890ddd
		convertParam(values, argv, argc);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	//----------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	char *strsave(const char *t)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		char *s;
Toshihiro Shimizu 890ddd
		s = (char *)malloc(strlen(t) + 1);
Toshihiro Shimizu 890ddd
		strcpy(s, t);
Toshihiro Shimizu 890ddd
		return s;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//-----------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void convertParam(double param[], const char *cParam[], int cParamLen)
Toshihiro Shimizu 890ddd
	{
Shinya Kitaoka 3bfa54
		std::string app;
Toshihiro Shimizu 890ddd
		for (int i = 2; i < cParamLen - 1; i++) {
Shinya Kitaoka 9eb50d
			app = std::to_string(param[i]);
Toshihiro Shimizu 890ddd
			cParam[i] = strsave(app.c_str());
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//-------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getBorder(int argc, int shrink, double frame)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		double blendSize;
Toshihiro Shimizu 890ddd
		int defaultBorder = 5;
Toshihiro Shimizu 890ddd
		if (argc != 6)
Toshihiro Shimizu 890ddd
			return defaultBorder;
Toshihiro Shimizu 890ddd
		blendSize = m_amount->getValue(frame) * 0.5;
Toshihiro Shimizu 890ddd
		if (shrink > 0)
Toshihiro Shimizu 890ddd
			blendSize = blendSize / (double)shrink;
Toshihiro Shimizu 890ddd
		//if (blendcmapImgDpi>0.0 )
Toshihiro Shimizu 890ddd
		//	blendSize*=(blendcmapImgDpi*0.01);
Toshihiro Shimizu 890ddd
		return (int)blendSize + 1 + defaultBorder;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//-------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void buildBlendData(TRenderSettings &ri, double frame)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		int shrink = tround((ri.m_shrinkX + ri.m_shrinkY) / 2.0);
Toshihiro Shimizu 890ddd
		int argc = 6;
Toshihiro Shimizu 890ddd
		const char *argv[6];
Shinya Kitaoka 9eb50d
		argv[0] = strsave(::to_string(m_colorIndex->getValue()).c_str());
Toshihiro Shimizu 890ddd
		argv[1] = argv[0];
Toshihiro Shimizu 890ddd
		argv[5] = "1";
Toshihiro Shimizu 890ddd
		getValues(argv, argc, frame);
Toshihiro Shimizu 890ddd
		SandorFxRenderData *blendData = new SandorFxRenderData(BlendTz, argc, argv, 0, shrink);
Toshihiro Shimizu 890ddd
		BlendTzParams ¶ms = blendData->m_blendParams;
Toshihiro Shimizu 890ddd
		params.m_amount = m_amount->getValue(frame) * 0.5;
Toshihiro Shimizu 890ddd
		params.m_colorIndex = m_colorIndex->getValue();
Toshihiro Shimizu 890ddd
		params.m_smoothness = m_smoothness->getValue(frame);
Toshihiro Shimizu 890ddd
		params.m_noBlending = m_noBlending->getValue();
Toshihiro Shimizu 890ddd
		ri.m_data.push_back(blendData);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(BlendTzFx, "blendTzFx")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void BlendTzFx::transform(double frame,
Toshihiro Shimizu 890ddd
						  int port,
Toshihiro Shimizu 890ddd
						  const TRectD &rectOnOutput,
Toshihiro Shimizu 890ddd
						  const TRenderSettings &infoOnOutput,
Toshihiro Shimizu 890ddd
						  TRectD &rectOnInput,
Toshihiro Shimizu 890ddd
						  TRenderSettings &infoOnInput)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	rectOnInput = rectOnOutput;
Toshihiro Shimizu 890ddd
	infoOnInput = infoOnOutput;
Toshihiro Shimizu 890ddd
	infoOnInput.m_userCachable = false;
Toshihiro Shimizu 890ddd
	buildBlendData(infoOnInput, frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void BlendTzFx::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
Toshihiro Shimizu 890ddd
	TRenderSettings ri2(ri);
Toshihiro Shimizu 890ddd
	buildBlendData(ri2, frame);
Toshihiro Shimizu 890ddd
	ri2.m_userCachable = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_input->compute(tile, frame, ri2);
Toshihiro Shimizu 890ddd
}