Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tbasefx.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tdoubleparam.h"
Toshihiro Shimizu 890ddd
#include "tnotanimatableparam.h"
Toshihiro Shimizu 890ddd
#include "trasterfx.h"
Toshihiro Shimizu 890ddd
#include "tflash.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#define ALLOW_SHEAR
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TGeometryFx::TGeometryFx()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setName(L"Geometry");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TGeometryFx::compute(TFlash &flash, int frame)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	flash.multMatrix(getPlacement(frame));
Toshihiro Shimizu 890ddd
	TRasterFx::compute(flash, frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TGeometryFx::doCompute(
Toshihiro Shimizu 890ddd
	TTile &tile,
Toshihiro Shimizu 890ddd
	double frame,
Toshihiro Shimizu 890ddd
	const TRenderSettings &ri)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRasterFxPort *input = dynamic_cast<trasterfxport *="">(getInputPort(0));</trasterfxport>
Toshihiro Shimizu 890ddd
	assert(input);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!input->isConnected())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!getActiveTimeRegion().contains(frame)) {
Toshihiro Shimizu 890ddd
		TRasterFxP(input->getFx())->compute(tile, frame, ri);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!TRaster32P(tile.getRaster()) && !TRaster64P(tile.getRaster()))
Toshihiro Shimizu 890ddd
		throw TException("AffineFx unsupported pixel type");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TAffine aff1 = getPlacement(frame);
Toshihiro Shimizu 890ddd
	TRenderSettings ri2(ri);
Toshihiro Shimizu 890ddd
	ri2.m_affine = ri2.m_affine * aff1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterFxP src = getInputPort("source")->getFx();
Toshihiro Shimizu 890ddd
	src->compute(tile, frame, ri2);
Toshihiro Shimizu 890ddd
	return;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TGeometryFx::doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRasterFxPort *input = dynamic_cast<trasterfxport *="">(getInputPort(0));</trasterfxport>
Toshihiro Shimizu 890ddd
	assert(input);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (input->isConnected()) {
Toshihiro Shimizu 890ddd
		TRasterFxP fx = input->getFx();
Toshihiro Shimizu 890ddd
		assert(fx);
Toshihiro Shimizu 890ddd
		bool ret = fx->doGetBBox(frame, bBox, info);
Toshihiro Shimizu 890ddd
		if (getActiveTimeRegion().contains(frame))
Toshihiro Shimizu 890ddd
			bBox = getPlacement(frame) * bBox;
Toshihiro Shimizu 890ddd
		return ret;
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		bBox = TRectD();
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
string TGeometryFx::getAlias(double frame, const TRenderSettings &info) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TGeometryFx *tthis = const_cast<tgeometryfx *="">(this);</tgeometryfx>
Toshihiro Shimizu 890ddd
	TAffine affine = tthis->getPlacement(frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	string alias = getFxType();
Toshihiro Shimizu 890ddd
	alias += "[";
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// alias degli effetti connessi alle porte di input separati da virgole
Toshihiro Shimizu 890ddd
	// una porta non connessa da luogo a un alias vuoto (stringa vuota)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int i = 0; i < getInputPortCount(); ++i) {
Toshihiro Shimizu 890ddd
		TFxPort *port = getInputPort(i);
Toshihiro Shimizu 890ddd
		if (port->isConnected()) {
Toshihiro Shimizu 890ddd
			TRasterFxP ifx = port->getFx();
Toshihiro Shimizu 890ddd
			assert(ifx);
Toshihiro Shimizu 890ddd
			alias += ifx->getAlias(frame, info);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		alias += ",";
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return alias +
Toshihiro Shimizu 890ddd
		   (areAlmostEqual(affine.a11, 0) ? "0" : ::toString(affine.a11, 5)) + "," +
Toshihiro Shimizu 890ddd
		   (areAlmostEqual(affine.a12, 0) ? "0" : ::toString(affine.a12, 5)) + "," +
Toshihiro Shimizu 890ddd
		   (areAlmostEqual(affine.a13, 0) ? "0" : ::toString(affine.a13, 5)) + "," +
Toshihiro Shimizu 890ddd
		   (areAlmostEqual(affine.a21, 0) ? "0" : ::toString(affine.a21, 5)) + "," +
Toshihiro Shimizu 890ddd
		   (areAlmostEqual(affine.a22, 0) ? "0" : ::toString(affine.a22, 5)) + "," +
Toshihiro Shimizu 890ddd
		   (areAlmostEqual(affine.a23, 0) ? "0" : ::toString(affine.a23, 5)) + "]";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TGeometryFx::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
	TAffine aff = getPlacement(frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	infoOnInput = infoOnOutput;
Toshihiro Shimizu 890ddd
	infoOnInput.m_affine = infoOnInput.m_affine * aff;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
NaAffineFx::NaAffineFx(bool isDpiAffine)
Toshihiro Shimizu 890ddd
	: m_aff(TAffine()), m_isDpiAffine(isDpiAffine)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	addInputPort("source", m_port);
Toshihiro Shimizu 890ddd
	setName(L"Geometry-NaAffineFx");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFx *NaAffineFx::clone(bool recursive) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	NaAffineFx *clonedFx = dynamic_cast<naaffinefx *="">(TFx::clone(recursive));</naaffinefx>
Toshihiro Shimizu 890ddd
	assert(clonedFx);
Toshihiro Shimizu 890ddd
	clonedFx->m_aff = m_aff;
Toshihiro Shimizu 890ddd
	clonedFx->m_isDpiAffine = m_isDpiAffine;
Toshihiro Shimizu 890ddd
	return clonedFx;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void NaAffineFx::compute(TFlash &flash, int frame)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TGeometryFx::compute(flash, frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRasterFx::compute(TFlash &flash, int frame)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (int i = getInputPortCount() - 1; i >= 0; i--) {
Toshihiro Shimizu 890ddd
		TFxPort *port = getInputPort(i);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (port->isConnected() && !port->isaControlPort()) {
Toshihiro Shimizu 890ddd
			flash.pushMatrix();
Toshihiro Shimizu 890ddd
			((TRasterFxP)(port->getFx()))->compute(flash, frame);
Toshihiro Shimizu 890ddd
			flash.popMatrix();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_IDENTIFIER_IS_HIDDEN(NaAffineFx, "naAffineFx")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
//  Geometric Fx
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class InvertFx : public TBaseRasterFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_DECLARATION(InvertFx)
Toshihiro Shimizu 890ddd
	TRasterFxPort m_input;
Toshihiro Shimizu 890ddd
	TBoolParamP m_redChan, m_greenChan, m_blueChan, m_alphaChan;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	InvertFx() : m_redChan(true), m_greenChan(true), m_blueChan(true), m_alphaChan(false)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		addInputPort("source", m_input);
Toshihiro Shimizu 890ddd
		//   bindParam(this, "red_channel"  , m_redChan);
Toshihiro Shimizu 890ddd
		//   bindParam(this, "green_channel", m_greenChan);
Toshihiro Shimizu 890ddd
		//   bindParam(this, "blue_channel" , m_blueChan);
Toshihiro Shimizu 890ddd
		//   bindParam(this, "alpha_channel", m_alphaChan);
Toshihiro Shimizu 890ddd
		setName(L"InvertFx");
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~InvertFx(){};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool canHandle(const TRenderSettings &info, double frame) { return true; }
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
			bool ret = m_input->doGetBBox(frame, bBox, info);
Toshihiro Shimizu 890ddd
			return ret;
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
	void 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
		m_input->compute(tile, frame, ri);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRop::invert(tile.getRaster(), m_redChan->getValue(), m_greenChan->getValue(), m_blueChan->getValue(), m_alphaChan->getValue());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
//  Video Fx
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Geometric
Toshihiro Shimizu 890ddd
//FX_IDENTIFIER(ScaleFx,       "scaleFx")
Toshihiro Shimizu 890ddd
//FX_IDENTIFIER(MoveFx,        "moveFx")
Toshihiro Shimizu 890ddd
//FX_IDENTIFIER(AffineFx,      "affineFx")
Toshihiro Shimizu 890ddd
//FX_IDENTIFIER(CropFx,        "cropFx")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Color
Toshihiro Shimizu 890ddd
FX_IDENTIFIER(InvertFx, "invertFx")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Video
Toshihiro Shimizu 890ddd
//FX_IDENTIFIER(FieldFx,       "fieldFx")
Toshihiro Shimizu 890ddd
//FX_IDENTIFIER(SwapFieldsFx,  "swapFieldsFx")
Toshihiro Shimizu 890ddd
//FX_IDENTIFIER(DeInterlaceFx, "deInterlaceFx")
Toshihiro Shimizu 890ddd
//FX_IDENTIFIER(InterlaceFx,   "interlaceFx")