Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "ttzpimagefx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfx.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshcell.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshpalettelevel.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ExternalPaletteFx : public TStandardRasterFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(ExternalPaletteFx)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterFxPort m_input;
Toshihiro Shimizu 890ddd
	TRasterFxPort m_expalette;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ExternalPaletteFx()
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		addInputPort("Source", m_input);
Toshihiro Shimizu 890ddd
		addInputPort("Palette", m_expalette);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~ExternalPaletteFx(){};
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
Shinya Kitaoka 3bfa54
	std::string getAlias(double frame, const TRenderSettings &info) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void doDryCompute(TRectD &rect, double frame, const TRenderSettings &info);
Toshihiro Shimizu 890ddd
	void doCompute(TTile &tile, double frame, const TRenderSettings &ri);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool allowUserCacheOnPort(int port) { return false; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool canHandle(const TRenderSettings &info, double frame) { return true; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
TPalette *getPalette(TXshColumn *column, int frame)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXshCellColumn *cellColumn = dynamic_cast<txshcellcolumn *="">(column);</txshcellcolumn>
Toshihiro Shimizu 890ddd
	if (!cellColumn)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TXshCell cell = cellColumn->getCell(frame);
Toshihiro Shimizu 890ddd
	if (cell.isEmpty())
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TXshPaletteLevel *pl = cell.m_level->getPaletteLevel();
Toshihiro Shimizu 890ddd
	if (pl)
Toshihiro Shimizu 890ddd
		return pl->getPalette();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TXshSimpleLevel *sl = cell.m_level->getSimpleLevel();
Toshihiro Shimizu 890ddd
	if (sl)
Toshihiro Shimizu 890ddd
		return sl->getPalette();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPalette *getPalette(TFx *fx, double frame)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!fx)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	int branches;
Toshihiro Shimizu 890ddd
	branches = fx->getInputPortCount();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (branches == 1)
Toshihiro Shimizu 890ddd
		return getPalette(fx->getInputPort(0)->getFx(), frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (branches > 1)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TColumnFx *columnFx = dynamic_cast<tcolumnfx *="">(fx))</tcolumnfx>
Toshihiro Shimizu 890ddd
		return getPalette(columnFx->getXshColumn(), (int)frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
std::string ExternalPaletteFx::getAlias(double frame, const TRenderSettings &info) const
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::string alias(TRasterFx::getAlias(frame, info));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_expalette.isConnected()) {
Toshihiro Shimizu 890ddd
		TFx *fx = m_expalette.getFx();
Toshihiro Shimizu 890ddd
		TPaletteP plt(getPalette(fx, frame));
Toshihiro Shimizu 890ddd
		if (plt && plt->isAnimated())
Shinya Kitaoka 9eb50d
			alias += std::to_string(frame);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return alias;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ExternalPaletteFx::doDryCompute(TRectD &rect, 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
	if (m_expalette.isConnected()) {
Toshihiro Shimizu 890ddd
		TFx *fx = m_expalette.getFx();
Shinya Kitaoka 3bfa54
		std::string pltAlias = m_expalette->getAlias(frame, ri);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TPaletteP palette(getPalette(fx, frame));
Toshihiro Shimizu 890ddd
		if (palette && palette->isAnimated())
Shinya Kitaoka 9eb50d
			pltAlias += std::to_string(frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRenderSettings ri2(ri);
Toshihiro Shimizu 890ddd
		ExternalPaletteFxRenderData *data =
Toshihiro Shimizu 890ddd
			new ExternalPaletteFxRenderData(palette, pltAlias);
Toshihiro Shimizu 890ddd
		ri2.m_data.push_back(data);
Toshihiro Shimizu 890ddd
		ri2.m_userCachable = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_input->dryCompute(rect, frame, ri2);
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		m_input->dryCompute(rect, frame, ri);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ExternalPaletteFx::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
	if (m_expalette.isConnected()) {
Toshihiro Shimizu 890ddd
		TFx *fx = m_expalette.getFx();
Shinya Kitaoka 3bfa54
		std::string pltAlias = m_expalette->getAlias(frame, ri);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TPaletteP palette(getPalette(fx, frame));
Toshihiro Shimizu 890ddd
		if (palette && palette->isAnimated())
Shinya Kitaoka 9eb50d
			pltAlias += std::to_string(frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRenderSettings ri2(ri);
Toshihiro Shimizu 890ddd
		ExternalPaletteFxRenderData *data =
Toshihiro Shimizu 890ddd
			new ExternalPaletteFxRenderData(palette, pltAlias);
Toshihiro Shimizu 890ddd
		ri2.m_data.push_back(data);
Toshihiro Shimizu 890ddd
		m_input->compute(tile, frame, ri2);
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		m_input->compute(tile, frame, ri);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(ExternalPaletteFx, "externalPaletteFx");