Toshihiro Shimizu 890ddd
#include "plugin_fxnode_interface.h"
Toshihiro Shimizu 890ddd
#include "plugin_utilities.h"
Toshihiro Shimizu 890ddd
#include "trasterfx.h"
Toshihiro Shimizu 890ddd
#include <functional></functional>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
static const TRenderSettings &restore_render_settings(const toonz_rendering_setting_t *src)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return *reinterpret_cast<const *="" trendersettings="">(src->context);</const>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int fxnode_compute_to_tile(toonz_fxnode_handle_t fxnode, const toonz_rendering_setting_t *rendering_setting, double frame, const toonz_rect_t *rect, toonz_tile_handle_t intile, toonz_tile_handle_t tile)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!fxnode || !rendering_setting || !rect || !tile)
Toshihiro Shimizu 890ddd
		return TOONZ_ERROR_NULL; // inval
Toshihiro Shimizu 890ddd
	TRasterFx *trasterfx = dynamic_cast<trasterfx *="">(reinterpret_cast<tfx *="">(fxnode));</tfx></trasterfx>
Toshihiro Shimizu 890ddd
	if (!trasterfx)
Toshihiro Shimizu 890ddd
		return TOONZ_ERROR_INVALID_HANDLE;
Toshihiro Shimizu 890ddd
	const TRenderSettings renderSettings = restore_render_settings(rendering_setting);
Toshihiro Shimizu 890ddd
	TTile *t = reinterpret_cast<ttile *="">(tile);</ttile>
Toshihiro Shimizu 890ddd
	TTile *i = reinterpret_cast<ttile *="">(intile);</ttile>
Toshihiro Shimizu 890ddd
	TRasterP raster;
Toshihiro Shimizu 890ddd
	if (i)
Toshihiro Shimizu 890ddd
		raster = i->getRaster();
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		raster = 0;
Toshihiro Shimizu 890ddd
	TPointD pos(rect->x0, rect->y0);
Toshihiro Shimizu 890ddd
	TDimension dim(rect->x1 - rect->x0, rect->y1 - rect->y0);
Toshihiro Shimizu 890ddd
	trasterfx->allocateAndCompute(*t, pos, dim, raster, frame, renderSettings);
Toshihiro Shimizu 890ddd
	return TOONZ_OK;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct fxnode_dipatch {
Toshihiro Shimizu 890ddd
	int operator()(toonz_fxnode_handle_t fxnode, const toonz_rendering_setting_t *rs, toonz_rect_t *rect, int *ret, std::function<int(trasterfx &)="" &,="" *,="" const="" trectd="" trendersettings=""> f)</int(trasterfx>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		using namespace plugin::utils;
Toshihiro Shimizu 890ddd
		TRasterFx *trasterfx = dynamic_cast<trasterfx *="">(reinterpret_cast<tfx *="">(fxnode));</tfx></trasterfx>
Toshihiro Shimizu 890ddd
		if (!trasterfx)
Toshihiro Shimizu 890ddd
			return TOONZ_ERROR_INVALID_HANDLE;
Toshihiro Shimizu 890ddd
		const TRenderSettings &renderSettings = restore_render_settings(rs);
Toshihiro Shimizu 890ddd
		TRectD rc = restore_rect(rect);
Toshihiro Shimizu 890ddd
		*ret = f(trasterfx, renderSettings, rc);
Toshihiro Shimizu 890ddd
		copy_rect(rect, rc);
Toshihiro Shimizu 890ddd
		return TOONZ_OK;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int fxnode_get_bbox(toonz_fxnode_handle_t fxnode, const toonz_rendering_setting_t *rendering_setting, double frame, toonz_rect_t *iorect, int *ret)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	fxnode_dipatch disp;
Toshihiro Shimizu 890ddd
	return disp(fxnode, rendering_setting, iorect, ret, [&](TRasterFx *fx, const TRenderSettings &rs, TRectD &rect) {
Toshihiro Shimizu 890ddd
		return fx->getBBox(frame, rect, rs);
Toshihiro Shimizu 890ddd
	});
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int fxnode_can_handle(toonz_fxnode_handle_t fxnode, const toonz_rendering_setting_t *rendering_setting, double frame, int *ret)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRasterFx *trasterfx = dynamic_cast<trasterfx *="">(reinterpret_cast<tfx *="">(fxnode));</tfx></trasterfx>
Toshihiro Shimizu 890ddd
	if (!trasterfx) {
Toshihiro Shimizu 890ddd
		return TOONZ_ERROR_INVALID_HANDLE;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	const TRenderSettings &renderSettings = restore_render_settings(rendering_setting);
Toshihiro Shimizu 890ddd
	*ret = trasterfx->canHandle(renderSettings, frame);
Toshihiro Shimizu 890ddd
	return TOONZ_OK;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int fxnode_get_input_port_count(toonz_fxnode_handle_t fxnode, int *count)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!fxnode) {
Toshihiro Shimizu 890ddd
		return TOONZ_ERROR_INVALID_HANDLE;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TFx *tfx = reinterpret_cast<tfx *="">(fxnode);</tfx>
Toshihiro Shimizu 890ddd
	*count = tfx->getInputPortCount();
Toshihiro Shimizu 890ddd
	return TOONZ_OK;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int fxnode_get_input_port(toonz_fxnode_handle_t fxnode, int index, toonz_port_handle_t *port)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!fxnode) {
Toshihiro Shimizu 890ddd
		return TOONZ_ERROR_INVALID_HANDLE;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TFx *tfx = reinterpret_cast<tfx *="">(fxnode);</tfx>
Toshihiro Shimizu 890ddd
	toonz_port_handle_t p = nullptr;
Toshihiro Shimizu 890ddd
	p = tfx->getInputPort(index);
Toshihiro Shimizu 890ddd
	if (!p)
Toshihiro Shimizu 890ddd
		return TOONZ_ERROR_NOT_FOUND;
Toshihiro Shimizu 890ddd
	*port = p;
Toshihiro Shimizu 890ddd
	return TOONZ_OK;
Toshihiro Shimizu 890ddd
}