tahoma2d/toonz/sources/stdfx/externalpalettefx.cpp

152 lines
4.2 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "stdfx.h"
#include "ttzpimagefx.h"
#include "toonz/tcolumnfx.h"
#include "toonz/txshcolumn.h"
#include "toonz/txshcell.h"
#include "toonz/txshsimplelevel.h"
#include "toonz/txshpalettelevel.h"
//===================================================================
2016-06-15 18:43:10 +12:00
class ExternalPaletteFx : public TStandardRasterFx {
FX_PLUGIN_DECLARATION(ExternalPaletteFx)
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRasterFxPort m_input;
TRasterFxPort m_expalette;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ExternalPaletteFx()
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
{
addInputPort("Source", m_input);
addInputPort("Palette", m_expalette);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
~ExternalPaletteFx(){};
2016-03-19 06:57:51 +13:00
2016-06-20 14:23:05 +12:00
bool doGetBBox(double frame, TRectD &bBox,
const TRenderSettings &info) override {
2016-06-15 18:43:10 +12:00
if (m_input.isConnected()) {
bool ret = m_input->doGetBBox(frame, bBox, info);
return ret;
} else {
bBox = TRectD();
return false;
}
}
2016-03-19 06:57:51 +13:00
2016-06-20 14:23:05 +12:00
std::string getAlias(double frame,
const TRenderSettings &info) const override;
2016-03-19 06:57:51 +13:00
2016-06-20 14:23:05 +12:00
void doDryCompute(TRectD &rect, double frame,
const TRenderSettings &info) override;
2016-06-19 20:06:29 +12:00
void doCompute(TTile &tile, double frame, const TRenderSettings &ri) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
bool allowUserCacheOnPort(int port) override { return false; }
2016-03-19 06:57:51 +13:00
2016-06-20 14:23:05 +12:00
bool canHandle(const TRenderSettings &info, double frame) override {
return true;
}
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
namespace {
TPalette *getPalette(TXshColumn *column, int frame) {
TXshCellColumn *cellColumn = dynamic_cast<TXshCellColumn *>(column);
if (!cellColumn) return 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TXshCell cell = cellColumn->getCell(frame);
if (cell.isEmpty()) return 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TXshPaletteLevel *pl = cell.m_level->getPaletteLevel();
if (pl) return pl->getPalette();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TXshSimpleLevel *sl = cell.m_level->getSimpleLevel();
if (sl) return sl->getPalette();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return 0;
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
TPalette *getPalette(TFx *fx, double frame) {
if (!fx) return 0;
int branches;
branches = fx->getInputPortCount();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (branches == 1) return getPalette(fx->getInputPort(0)->getFx(), frame);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (branches > 1) return 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (TColumnFx *columnFx = dynamic_cast<TColumnFx *>(fx))
return getPalette(columnFx->getXshColumn(), (int)frame);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return 0;
2016-03-19 06:57:51 +13:00
}
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
std::string ExternalPaletteFx::getAlias(double frame,
const TRenderSettings &info) const {
std::string alias(TRasterFx::getAlias(frame, info));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (m_expalette.isConnected()) {
TFx *fx = m_expalette.getFx();
TPaletteP plt(getPalette(fx, frame));
if (plt && plt->isAnimated()) alias += std::to_string(frame);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return alias;
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void ExternalPaletteFx::doDryCompute(TRectD &rect, double frame,
const TRenderSettings &ri) {
if (!m_input.isConnected()) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (m_expalette.isConnected()) {
TFx *fx = m_expalette.getFx();
std::string pltAlias = m_expalette->getAlias(frame, ri);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPaletteP palette(getPalette(fx, frame));
if (palette && palette->isAnimated()) pltAlias += std::to_string(frame);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRenderSettings ri2(ri);
ExternalPaletteFxRenderData *data =
new ExternalPaletteFxRenderData(palette, pltAlias);
ri2.m_data.push_back(data);
ri2.m_userCachable = false;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_input->dryCompute(rect, frame, ri2);
} else
m_input->dryCompute(rect, frame, ri);
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void ExternalPaletteFx::doCompute(TTile &tile, double frame,
const TRenderSettings &ri) {
if (!m_input.isConnected()) return;
if (m_expalette.isConnected()) {
TFx *fx = m_expalette.getFx();
std::string pltAlias = m_expalette->getAlias(frame, ri);
TPaletteP palette(getPalette(fx, frame));
if (palette && palette->isAnimated()) pltAlias += std::to_string(frame);
TRenderSettings ri2(ri);
ExternalPaletteFxRenderData *data =
new ExternalPaletteFxRenderData(palette, pltAlias);
ri2.m_data.push_back(data);
m_input->compute(tile, frame, ri2);
} else
m_input->compute(tile, frame, ri);
2016-03-19 06:57:51 +13:00
}
FX_PLUGIN_IDENTIFIER(ExternalPaletteFx, "externalPaletteFx");