Toshihiro Shimizu 890ddd
#include <stdio.h></stdio.h>
Toshihiro Shimizu 890ddd
#include <toonz_plugin.h></toonz_plugin.h>
Toshihiro Shimizu 890ddd
#include <toonz_hostif.h></toonz_hostif.h>
Toshihiro Shimizu 890ddd
#include <memory></memory>
Toshihiro Shimizu 890ddd
#include <cmath></cmath>
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
#include "pixelop.hpp"
Toshihiro Shimizu 890ddd
roentgen edd579
#include <utils rect.hpp=""></utils>
Toshihiro Shimizu 890ddd
#include <utils interf_holder.hpp=""></utils>
Toshihiro Shimizu 890ddd
#include <utils param_traits.hpp=""></utils>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef _MSC_VER
Toshihiro Shimizu 890ddd
//	Visual Studio is not supported __restrict for reference
Toshihiro Shimizu 890ddd
#define RESTRICT
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define RESTRICT __restrict
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
extern "C" {
Toshihiro Shimizu 890ddd
TOONZ_EXPORT int toonz_plugin_init(toonz::host_interface_t *hostif);
Toshihiro Shimizu 890ddd
TOONZ_EXPORT void toonz_plugin_exit();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
toonz::host_interface_t *ifactory_ = NULL;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int toonz_plugin_init(toonz::host_interface_t *hostif)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("toonz_plugin_init()\n");
Toshihiro Shimizu 890ddd
	ifactory_ = hostif;
Toshihiro Shimizu 890ddd
	return TOONZ_OK;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void toonz_plugin_exit()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("toonz_plugin_exit()\n");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToonzRect conv2rect(toonz::rect_t &&r)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return ToonzRect(r.x0, r.y0, r.x1, r.y1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
toonz::rect_t conv2rect(ToonzRect &&r)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return toonz::rect_t{r.x0, r.y0, r.x1, r.y1};
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ToonzRect conv2rect(const toonz::rect_t &r)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return ToonzRect(r.x0, r.y0, r.x1, r.y1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
toonz::rect_t conv2rect(const ToonzRect &r)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return toonz::rect_t{r.x0, r.y0, r.x1, r.y1};
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename t=""></typename>
Toshihiro Shimizu 890ddd
void dump_value(const T &v)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("value: type:%s {%d}\n", typeid(T).name(), v);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void dump_value<toonz_param_traits_double_t::iovaluetype>(const toonz_param_traits_double_t::iovaluetype &v)</toonz_param_traits_double_t::iovaluetype>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("value: type:%s {%g}\n", typeid(toonz_param_traits_double_t::iovaluetype).name(), v);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void dump_value<toonz_param_traits_range_t::iovaluetype>(const toonz_param_traits_range_t::iovaluetype &v)</toonz_param_traits_range_t::iovaluetype>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("value: type:%s {%g, %g}\n", typeid(toonz_param_traits_range_t::iovaluetype).name(), v.a, v.b);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void dump_value<toonz_param_traits_point_t::iovaluetype>(const toonz_param_traits_point_t::iovaluetype &v)</toonz_param_traits_point_t::iovaluetype>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("value: type:%s {%g, %g}\n", typeid(toonz_param_traits_point_t::iovaluetype).name(), v.x, v.y);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void dump_value<toonz_param_traits_color_t::iovaluetype>(const toonz_param_traits_color_t::iovaluetype &v)</toonz_param_traits_color_t::iovaluetype>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("value: type:%s {%d, %d, %d, %d}\n", typeid(toonz_param_traits_color_t::iovaluetype).name(), v.c0, v.c1, v.c2, v.m);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void dump_value<toonz_param_traits_spectrum_t::iovaluetype>(const toonz_param_traits_spectrum_t::iovaluetype &v)</toonz_param_traits_spectrum_t::iovaluetype>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("value: type:%s {%g, %g, %g, %g, %g}\n", typeid(toonz_param_traits_spectrum_t::iovaluetype).name(), v.w, v.c0, v.c1, v.c2, v.m);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void dump_value<toonz_param_traits_tonecurve_t::iovaluetype>(const toonz_param_traits_tonecurve_t::iovaluetype &v)</toonz_param_traits_tonecurve_t::iovaluetype>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("value: type:%s {%g, %g, %d, %d}\n", typeid(toonz_param_traits_tonecurve_t::iovaluetype).name(), v.x, v.y, v.channel, v.interp);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename t=""></typename>
Toshihiro Shimizu 890ddd
bool get_and_check(toonz::node_handle_t node, const char *nm, double frame, double opt = 0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	auto nodeif = grab_interf<toonz::node_interface_t>(TOONZ_UUID_NODE);</toonz::node_interface_t>
Toshihiro Shimizu 890ddd
	auto pif = grab_interf<toonz::param_interface_t>(TOONZ_UUID_PARAM);</toonz::param_interface_t>
Toshihiro Shimizu 890ddd
	toonz_param_handle_t p1;
Toshihiro Shimizu 890ddd
	int ret;
Toshihiro Shimizu 890ddd
	ret = nodeif->get_param(node, nm, &p1);
Toshihiro Shimizu 890ddd
	printf("get_param(%s): ret:%d\n", nm, ret);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int type = 0;
Toshihiro Shimizu 890ddd
	int cnt = 0;
Toshihiro Shimizu 890ddd
	pif->get_type(p1, frame, &type, &cnt);
Toshihiro Shimizu 890ddd
	printf("parameter(ret:%d): name:%s (type:%d count:%d) expect:(type:%d) typesize:%ld\n", ret, nm, type, cnt, T::E, sizeof(typename T::iovaluetype));
Toshihiro Shimizu 890ddd
	if (type != T::E)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	typename T::iovaluetype v;
Toshihiro Shimizu 890ddd
	ret = pif->get_value(p1, frame, &cnt, &v);
Toshihiro Shimizu 890ddd
	printf("get_value: ret:%d count:%d\n", ret, cnt);
Toshihiro Shimizu 890ddd
	dump_value<typename t::iovaluetype="">(v);</typename>
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
bool get_and_check<toonz_param_traits_string_t>(toonz::node_handle_t node, const char *nm, double frame, double opt)</toonz_param_traits_string_t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	auto nodeif = grab_interf<toonz::node_interface_t>(TOONZ_UUID_NODE);</toonz::node_interface_t>
Toshihiro Shimizu 890ddd
	auto pif = grab_interf<toonz::param_interface_t>(TOONZ_UUID_PARAM);</toonz::param_interface_t>
Toshihiro Shimizu 890ddd
	toonz_param_handle_t p1;
Toshihiro Shimizu 890ddd
	int ret;
Toshihiro Shimizu 890ddd
	ret = nodeif->get_param(node, nm, &p1);
Toshihiro Shimizu 890ddd
	printf("get_param(%s): ret:%d\n", nm, ret);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int type = 0;
Toshihiro Shimizu 890ddd
	int cnt = 0;
Toshihiro Shimizu 890ddd
	ret = pif->get_type(p1, frame, &type, &cnt);
Toshihiro Shimizu 890ddd
	printf("parameter(ret:%d): name:%s (type:%d count:%d) expect:(type:%d) typesize:-\n", ret, nm, type, cnt, toonz_param_traits_string_t::E);
Toshihiro Shimizu 890ddd
	if (type != toonz_param_traits_string_t::E)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<toonz_param_traits_string_t::iovaluetype> v(cnt);</toonz_param_traits_string_t::iovaluetype>
Toshihiro Shimizu 890ddd
	ret = pif->get_value(p1, frame, &cnt, v.data());
Toshihiro Shimizu 890ddd
	printf("get_value: ret:%d count:%d\n", ret, cnt);
Toshihiro Shimizu 890ddd
	//dump_value< toonz_param_traits_string_t::iovaluetype* >(v);
Toshihiro Shimizu 890ddd
	printf("value: type:%s {%s}\n", typeid(toonz_param_traits_string_t::iovaluetype).name(), v.begin());
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
bool get_and_check<toonz_param_traits_spectrum_t>(toonz::node_handle_t node, const char *nm, double frame, double opt)</toonz_param_traits_spectrum_t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	auto nodeif = grab_interf<toonz::node_interface_t>(TOONZ_UUID_NODE);</toonz::node_interface_t>
Toshihiro Shimizu 890ddd
	auto pif = grab_interf<toonz::param_interface_t>(TOONZ_UUID_PARAM);</toonz::param_interface_t>
Toshihiro Shimizu 890ddd
	toonz_param_handle_t p1;
Toshihiro Shimizu 890ddd
	int ret;
Toshihiro Shimizu 890ddd
	ret = nodeif->get_param(node, nm, &p1);
Toshihiro Shimizu 890ddd
	printf("get_param(%s): ret:%d\n", nm, ret);
Toshihiro Shimizu 890ddd
	int type = 0;
Toshihiro Shimizu 890ddd
	int cnt = 0;
Toshihiro Shimizu 890ddd
	ret = pif->get_type(p1, frame, &type, &cnt);
Toshihiro Shimizu 890ddd
	printf("parameter(ret:%d): name:%s (type:%d count:%d) expect:(type:%d) typesize:-\n", ret, nm, type, cnt, toonz_param_traits_spectrum_t::E);
Toshihiro Shimizu 890ddd
	if (type != toonz_param_traits_spectrum_t::E)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	toonz_param_traits_spectrum_t::iovaluetype v;
Toshihiro Shimizu 890ddd
	v.w = opt;
Toshihiro Shimizu 890ddd
	ret = pif->get_value(p1, frame, &cnt, &v);
Toshihiro Shimizu 890ddd
	printf("get_value: ret:%d count:%d\n", ret, cnt);
Toshihiro Shimizu 890ddd
	dump_value<toonz_param_traits_spectrum_t::iovaluetype>(v);</toonz_param_traits_spectrum_t::iovaluetype>
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
bool get_and_check<toonz_param_traits_tonecurve_t>(toonz::node_handle_t node, const char *nm, double frame, double opt)</toonz_param_traits_tonecurve_t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	auto nodeif = grab_interf<toonz::node_interface_t>(TOONZ_UUID_NODE);</toonz::node_interface_t>
Toshihiro Shimizu 890ddd
	auto pif = grab_interf<toonz::param_interface_t>(TOONZ_UUID_PARAM);</toonz::param_interface_t>
Toshihiro Shimizu 890ddd
	toonz_param_handle_t p1;
Toshihiro Shimizu 890ddd
	int ret;
Toshihiro Shimizu 890ddd
	ret = nodeif->get_param(node, nm, &p1);
Toshihiro Shimizu 890ddd
	printf("get_param(%s): ret:%d\n", nm, ret);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int type = 0;
Toshihiro Shimizu 890ddd
	int cnt = 0;
Toshihiro Shimizu 890ddd
	ret = pif->get_type(p1, frame, &type, &cnt);
Toshihiro Shimizu 890ddd
	printf("parameter)(ret:%d): name:%s (type:%d count:%d) expect:(type:%d) sz:-\n", ret, nm, type, cnt, toonz_param_traits_tonecurve_t::E);
Toshihiro Shimizu 890ddd
	if (type != toonz_param_traits_tonecurve_t::E)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<toonz_param_traits_tonecurve_t::iovaluetype> v(cnt);</toonz_param_traits_tonecurve_t::iovaluetype>
Toshihiro Shimizu 890ddd
	ret = pif->get_value(p1, frame, &cnt, v.data());
Toshihiro Shimizu 890ddd
	printf("get_value: ret:%d count:%d\n", ret, cnt);
Toshihiro Shimizu 890ddd
	for (int i = 0; i < cnt; i++) {
Toshihiro Shimizu 890ddd
		dump_value<toonz_param_traits_tonecurve_t::iovaluetype>(v[i]);</toonz_param_traits_tonecurve_t::iovaluetype>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_compute(toonz::node_handle_t node, const toonz::rendering_setting_t *rs, double frame, toonz::tile_handle_t tile)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("do_compute(): node:%p tile:%p frame:%g\n", node, tile, frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	toonz::port_handle_t port = nullptr;
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		auto nodeif = grab_interf<toonz::node_interface_t>(TOONZ_UUID_NODE);</toonz::node_interface_t>
Toshihiro Shimizu 890ddd
		if (nodeif) {
Toshihiro Shimizu 890ddd
			int ret = nodeif->get_input_port(node, "IPort", &port);
Toshihiro Shimizu 890ddd
			if (ret)
Toshihiro Shimizu 890ddd
				printf("do_compute(): get_input_port: ret:%d\n", ret);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// test
Toshihiro Shimizu 890ddd
			get_and_check<toonz_param_traits_double_t>(node, "first", frame);</toonz_param_traits_double_t>
Toshihiro Shimizu 890ddd
			get_and_check<toonz_param_traits_range_t>(node, "second", frame);</toonz_param_traits_range_t>
Toshihiro Shimizu 890ddd
			get_and_check<toonz_param_traits_color_t>(node, "third", frame);</toonz_param_traits_color_t>
Toshihiro Shimizu 890ddd
			get_and_check<toonz_param_traits_point_t>(node, "fourth", frame);</toonz_param_traits_point_t>
Toshihiro Shimizu 890ddd
			get_and_check<toonz_param_traits_enum_t>(node, "fifth", frame);</toonz_param_traits_enum_t>
Toshihiro Shimizu 890ddd
			get_and_check<toonz_param_traits_int_t>(node, "sixth", frame);</toonz_param_traits_int_t>
Toshihiro Shimizu 890ddd
			get_and_check<toonz_param_traits_bool_t>(node, "seventh", frame);</toonz_param_traits_bool_t>
Toshihiro Shimizu 890ddd
			get_and_check<toonz_param_traits_string_t>(node, "eighth", frame);</toonz_param_traits_string_t>
Toshihiro Shimizu 890ddd
			get_and_check<toonz_param_traits_spectrum_t>(node, "ninth", frame, 0.5);</toonz_param_traits_spectrum_t>
Toshihiro Shimizu 890ddd
			get_and_check<toonz_param_traits_tonecurve_t>(node, "tenth", frame);</toonz_param_traits_tonecurve_t>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			get_and_check<toonz_param_traits_tonecurve_t>(node, "unknown", frame);</toonz_param_traits_tonecurve_t>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			toonz::param_handle_t str;
Toshihiro Shimizu 890ddd
			nodeif->get_param(node, "eighth", &str);
Toshihiro Shimizu 890ddd
			toonz::param_handle_t notstr;
Toshihiro Shimizu 890ddd
			nodeif->get_param(node, "seventh", ¬str);
Toshihiro Shimizu 890ddd
			toonz::param_handle_t spec;
Toshihiro Shimizu 890ddd
			nodeif->get_param(node, "ninth", &spec);
Toshihiro Shimizu 890ddd
			auto pif = grab_interf<toonz::param_interface_t>(TOONZ_UUID_PARAM);</toonz::param_interface_t>
Toshihiro Shimizu 890ddd
			if (pif) {
Toshihiro Shimizu 890ddd
				int t, l;
Toshihiro Shimizu 890ddd
				pif->get_type(str, frame, &t, &l);
Toshihiro Shimizu 890ddd
				int sz;
Toshihiro Shimizu 890ddd
				std::vector<char> shortage_buf(l / 2 + 1);</char>
Toshihiro Shimizu 890ddd
				int ret = pif->get_string_value(str, &sz, l / 2 + 1, shortage_buf.data());
Toshihiro Shimizu 890ddd
				printf("get_string_value(string): {%s} (length:%d) ret:%d\n", shortage_buf.data(), sz, ret);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				ret = pif->get_string_value(notstr, &sz, l / 2 + 1, shortage_buf.data()); // must be error
Toshihiro Shimizu 890ddd
				printf("get_string_value(not string): sz:%d ret:%d\n", sz, ret);		  // size must be not changed
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				pif->get_type(spec, frame, &t, &l);
Toshihiro Shimizu 890ddd
				toonz_param_spectrum_t spc;
Toshihiro Shimizu 890ddd
				ret = pif->get_spectrum_value(spec, frame, 0, &spc);
Toshihiro Shimizu 890ddd
				printf("get_spectrum_value(spec): ret:%d\n", ret);
Toshihiro Shimizu 890ddd
				dump_value(spc);
Toshihiro Shimizu 890ddd
				ret = pif->get_spectrum_value(str, frame, 0, &spc);
Toshihiro Shimizu 890ddd
				printf("get_spectrum_value(str): ret:%d\n", ret); // must be error
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int blur = 1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	auto tileif = grab_interf<toonz::tile_interface_t>(TOONZ_UUID_TILE);</toonz::tile_interface_t>
Toshihiro Shimizu 890ddd
	auto portif = grab_interf<toonz::port_interface_t>(TOONZ_UUID_PORT);</toonz::port_interface_t>
Toshihiro Shimizu 890ddd
	if (port && tileif && portif) {
Toshihiro Shimizu 890ddd
		toonz::fxnode_handle_t fx;
Toshihiro Shimizu 890ddd
		portif->get_fx(port, &fx);
Toshihiro Shimizu 890ddd
		auto fxif = grab_interf<toonz::fxnode_interface_t>(TOONZ_UUID_FXNODE);</toonz::fxnode_interface_t>
Toshihiro Shimizu 890ddd
		if (fxif) {
Toshihiro Shimizu 890ddd
			/* evaluate upstream's flow */
Toshihiro Shimizu 890ddd
			toonz::rect_t rect;
Toshihiro Shimizu 890ddd
			tileif->get_rectangle(tile, &rect);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			toonz::rect_t inRect = conv2rect(conv2rect(rect).enlarge(blur, blur));
Toshihiro Shimizu 890ddd
			toonz::tile_handle_t result = nullptr;
Toshihiro Shimizu 890ddd
			tileif->create(&result);
Toshihiro Shimizu 890ddd
			fxif->compute_to_tile(fx, rs, frame, &inRect, tile, result);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			/* evaluate the fx */
Toshihiro Shimizu 890ddd
			int x = rect.x0;
Toshihiro Shimizu 890ddd
			int y = rect.y0;
Toshihiro Shimizu 890ddd
			int lx = rect.x1 - rect.x0;
Toshihiro Shimizu 890ddd
			int ly = rect.y1 - rect.y0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			int sstride, dstride;
Toshihiro Shimizu 890ddd
			tileif->get_raw_stride(result, &sstride);
Toshihiro Shimizu 890ddd
			tileif->get_raw_stride(tile, &dstride);
Toshihiro Shimizu 890ddd
			int selement_type, delement_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			tileif->get_element_type(result, &delement_type);
Toshihiro Shimizu 890ddd
			tileif->get_element_type(tile, &selement_type);
Toshihiro Shimizu 890ddd
			uint8_t *saddr, *daddr;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			tileif->get_raw_address_unsafe(result, reinterpret_cast<void **="">(&saddr));</void>
Toshihiro Shimizu 890ddd
			tileif->get_raw_address_unsafe(tile, reinterpret_cast<void **="">(&daddr));</void>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			printf("%f %f %f %f\n", rect.x0, rect.y0, rect.x1, rect.y1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			printf("-+ x:%d y:%d lx:%d ly:%d\n", x, y, lx, ly);
Toshihiro Shimizu 890ddd
			printf(" + src tile: addr:%p stride:%d type:%d\n", saddr, sstride, selement_type);
Toshihiro Shimizu 890ddd
			printf(" + dst tile: addr:%p stride:%d type:%d\n", daddr, dstride, delement_type);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// need compatibility check for formats
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			hv_kernel<uint8_t, 4="">(daddr, saddr + sstride + 4, lx, ly, dstride, sstride, [](uint8_t v[4], const uint8_t *p, int stride, int xinbytes, int yinbytes) {</uint8_t,>
Toshihiro Shimizu 890ddd
				uint32_t l00 = *reinterpret_cast<const *="" uint32_t="">(p + -stride - 4);</const>
Toshihiro Shimizu 890ddd
				uint32_t l10 = *reinterpret_cast<const *="" uint32_t="">(p + -stride);</const>
Toshihiro Shimizu 890ddd
				uint32_t l20 = *reinterpret_cast<const *="" uint32_t="">(p + -stride + 4);</const>
Toshihiro Shimizu 890ddd
				uint32_t l01 = *reinterpret_cast<const *="" uint32_t="">(p - 4);</const>
Toshihiro Shimizu 890ddd
				uint32_t l11 = *reinterpret_cast<const *="" uint32_t="">(p);</const>
Toshihiro Shimizu 890ddd
				uint32_t l21 = *reinterpret_cast<const *="" uint32_t="">(p + 4);</const>
Toshihiro Shimizu 890ddd
				uint32_t l02 = *reinterpret_cast<const *="" uint32_t="">(p + stride - 4);</const>
Toshihiro Shimizu 890ddd
				uint32_t l12 = *reinterpret_cast<const *="" uint32_t="">(p + stride);</const>
Toshihiro Shimizu 890ddd
				uint32_t l22 = *reinterpret_cast<const *="" uint32_t="">(p + stride + 4);</const>
Toshihiro Shimizu 890ddd
				uint32_t r = 0, g = 0, b = 0, m = 0;
Toshihiro Shimizu 890ddd
				//printf("col:0x%08x [%d, %d]\n", l11, xinbytes, yinbytes);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				/* TODO:
Toshihiro Shimizu 890ddd
						toonz の TPixel は char r, g, b, m; のように持っているのでそのまま uin32_t だとエンディアンが変わる.
Toshihiro Shimizu 890ddd
						toonz ビルド時の configuration はコンパイル時に参照できるようにしておくべきだ.
Toshihiro Shimizu 890ddd
						*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				m += ((l00 >> 24) & 0xff);
Toshihiro Shimizu 890ddd
				m += ((l10 >> 24) & 0xff);
Toshihiro Shimizu 890ddd
				m += ((l20 >> 24) & 0xff);
Toshihiro Shimizu 890ddd
				m += ((l01 >> 24) & 0xff);
Toshihiro Shimizu 890ddd
				m += ((l11 >> 24) & 0xff);
Toshihiro Shimizu 890ddd
				m += ((l21 >> 24) & 0xff);
Toshihiro Shimizu 890ddd
				m += ((l02 >> 24) & 0xff);
Toshihiro Shimizu 890ddd
				m += ((l12 >> 24) & 0xff);
Toshihiro Shimizu 890ddd
				m += ((l22 >> 24) & 0xff);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				b += ((l00 >> 16) & 0xff);
Toshihiro Shimizu 890ddd
				b += ((l10 >> 16) & 0xff);
Toshihiro Shimizu 890ddd
				b += ((l20 >> 16) & 0xff);
Toshihiro Shimizu 890ddd
				b += ((l01 >> 16) & 0xff);
Toshihiro Shimizu 890ddd
				b += ((l11 >> 16) & 0xff);
Toshihiro Shimizu 890ddd
				b += ((l21 >> 16) & 0xff);
Toshihiro Shimizu 890ddd
				b += ((l02 >> 16) & 0xff);
Toshihiro Shimizu 890ddd
				b += ((l12 >> 16) & 0xff);
Toshihiro Shimizu 890ddd
				b += ((l22 >> 16) & 0xff);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				g += ((l00 >> 8) & 0xff);
Toshihiro Shimizu 890ddd
				g += ((l10 >> 8) & 0xff);
Toshihiro Shimizu 890ddd
				g += ((l20 >> 8) & 0xff);
Toshihiro Shimizu 890ddd
				g += ((l01 >> 8) & 0xff);
Toshihiro Shimizu 890ddd
				g += ((l11 >> 8) & 0xff);
Toshihiro Shimizu 890ddd
				g += ((l21 >> 8) & 0xff);
Toshihiro Shimizu 890ddd
				g += ((l02 >> 8) & 0xff);
Toshihiro Shimizu 890ddd
				g += ((l12 >> 8) & 0xff);
Toshihiro Shimizu 890ddd
				g += ((l22 >> 8) & 0xff);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				r += ((l00 >> 0) & 0xff);
Toshihiro Shimizu 890ddd
				r += ((l10 >> 0) & 0xff);
Toshihiro Shimizu 890ddd
				r += ((l20 >> 0) & 0xff);
Toshihiro Shimizu 890ddd
				r += ((l01 >> 0) & 0xff);
Toshihiro Shimizu 890ddd
				r += ((l11 >> 0) & 0xff);
Toshihiro Shimizu 890ddd
				r += ((l21 >> 0) & 0xff);
Toshihiro Shimizu 890ddd
				r += ((l02 >> 0) & 0xff);
Toshihiro Shimizu 890ddd
				r += ((l12 >> 0) & 0xff);
Toshihiro Shimizu 890ddd
				r += ((l22 >> 0) & 0xff);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				v[0] = static_cast<uint8_t>(r / 9);</uint8_t>
Toshihiro Shimizu 890ddd
				v[1] = static_cast<uint8_t>(g / 9);</uint8_t>
Toshihiro Shimizu 890ddd
				v[2] = static_cast<uint8_t>(b / 9);</uint8_t>
Toshihiro Shimizu 890ddd
				v[3] = static_cast<uint8_t>(m / 9);</uint8_t>
Toshihiro Shimizu 890ddd
			});
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int do_get_bbox(toonz::node_handle_t node, const toonz::rendering_setting_t *rs, double frame, toonz::rect_t *rect)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("do_get_bbox(): node:%p\n", node);
Toshihiro Shimizu 890ddd
	bool modified = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	toonz::port_handle_t port = nullptr;
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		auto nodeif = grab_interf<toonz::node_interface_t>(TOONZ_UUID_NODE);</toonz::node_interface_t>
Toshihiro Shimizu 890ddd
		if (nodeif) {
Toshihiro Shimizu 890ddd
			int ret = nodeif->get_input_port(node, "IPort", &port);
Toshihiro Shimizu 890ddd
			printf("do_get_bbox(): get_input_port:%d\n", ret);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	auto portif = grab_interf<toonz::port_interface_t>(TOONZ_UUID_PORT);</toonz::port_interface_t>
Toshihiro Shimizu 890ddd
	if (port && portif) {
Toshihiro Shimizu 890ddd
		int con = 0;
Toshihiro Shimizu 890ddd
		portif->is_connected(port, &con);
Toshihiro Shimizu 890ddd
		if (con) {
Toshihiro Shimizu 890ddd
			toonz::fxnode_handle_t fx;
Toshihiro Shimizu 890ddd
			portif->get_fx(port, &fx);
Toshihiro Shimizu 890ddd
			auto fxif = grab_interf<toonz::fxnode_interface_t>(TOONZ_UUID_FXNODE);</toonz::fxnode_interface_t>
Toshihiro Shimizu 890ddd
			if (fxif) {
Toshihiro Shimizu 890ddd
				int ret = 0;
Toshihiro Shimizu 890ddd
				/* この引数の順番つらいなぁ, fx, rs, frame, rect の順だよね */
Toshihiro Shimizu 890ddd
				fxif->get_bbox(fx, rs, frame, rect, &ret);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				/* 画素単位の値を現在の座標系に合わせる */
Toshihiro Shimizu 890ddd
				toonz::affine_t a = rs->affine;
Toshihiro Shimizu 890ddd
				double det = a.a11 * a.a22 - a.a12 * a.a21;
Toshihiro Shimizu 890ddd
				double scale = sqrt(fabs(det));
Toshihiro Shimizu 890ddd
				double blur = 1.0 / scale;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				ToonzRect r = conv2rect(*rect);
Toshihiro Shimizu 890ddd
				r = r.enlarge(blur, blur);
Toshihiro Shimizu 890ddd
				*rect = conv2rect(std::move(r));
Toshihiro Shimizu 890ddd
				modified = true;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return modified;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
param_desc_t params0_[] = {
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_double_t>("first", "1st", {1.0 /* default */, -1.0 /* min */, 1.0 /* max */}, "description of the first param"),</traits_double_t>
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_range_t>("second", "2nd", {{48.0, 64.0} /* default */, {0.0, 180.0} /* min-max */}),</traits_range_t>
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_color_t>("third", "3rd", {0xff, 0xff, 0xff, 0xff} /* white */),</traits_color_t>
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_point_t>("fourth", "4th", {{64, -64} /* default */, {-200, 200} /* min */, {-200, +200} /* max */}),</traits_point_t>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
const char *strtbl_[] = {"tokyo", "osaka", "nagoya"};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
param_desc_t params1_[] = {
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_enum_t>("fifth", "5th", {2, 3, strtbl_}),</traits_enum_t>
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_int_t>("sixth", "6th", {2, -10, 10}, "this is integer"),</traits_int_t>
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_bool_t>("seventh", "7th", {1}),</traits_bool_t>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
toonz_param_traits_spectrum_t::valuetype points_[] = {{0.0, 1.0, 0.0, 0.0, 1.0},
Toshihiro Shimizu 890ddd
													  {0.5, 0.5, 0.0, 0.5, 1.0},
Toshihiro Shimizu 890ddd
													  {1.0, 0.0, 0.0, 0.5, 1.0}};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
param_desc_t params2_[] = {
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_string_t>("eighth", "8th", {"this is sample message"}),</traits_string_t>
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_spectrum_t>("ninth", "9th", {0.1, 3, points_}),</traits_spectrum_t>
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_tonecurve_t>("tenth", "10th", {/* tonecurve has no default */}),</traits_tonecurve_t>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
toonz_param_group_t groups0_[] = {
Toshihiro Shimizu 890ddd
	param_group_ctor("Group1", sizeof(params0_) / sizeof(param_desc_t), params0_),
Toshihiro Shimizu 890ddd
	param_group_ctor("Group2", sizeof(params1_) / sizeof(param_desc_t), params1_),
Toshihiro Shimizu 890ddd
	param_group_ctor("Group3", sizeof(params2_) / sizeof(param_desc_t), params2_),
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
toonz_param_page_t pages_[] = {
Toshihiro Shimizu 890ddd
	param_page_ctor("Properties", sizeof(groups0_) / sizeof(toonz_param_group_t), groups0_),
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int node_setup(toonz::node_handle_t node)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("blur: setup(): node:%p\n", node);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	auto setup = grab_interf<toonz::setup_interface_t>(TOONZ_UUID_SETUP);</toonz::setup_interface_t>
Toshihiro Shimizu 890ddd
	if (setup) {
Toshihiro Shimizu 890ddd
		int errcode = 0;
Toshihiro Shimizu 890ddd
		void *entry = NULL;
Toshihiro Shimizu 890ddd
		int ret = setup->set_parameter_pages_with_error(node, sizeof(pages_) / sizeof(toonz_param_page_t), pages_, &errcode, &entry);
Toshihiro Shimizu 890ddd
		if (ret) {
Toshihiro Shimizu 890ddd
			printf("setup error:0x%x reason:0x%x entry:%p\n", ret, errcode, entry);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		setup->add_input_port(node, "IPort", TOONZ_PORT_TYPE_RASTER);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int node_create(toonz::node_handle_t node)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("blur: create(): node:%p\n", node);
Toshihiro Shimizu 890ddd
	return TOONZ_OK;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int node_destroy(toonz::node_handle_t node)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("destroy():node:%p\n", node);
Toshihiro Shimizu 890ddd
	return TOONZ_OK;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int can_handle(toonz_node_handle_t node, const toonz_rendering_setting_t *rs, double frame)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("%s:\n", __FUNCTION__);
Toshihiro Shimizu 890ddd
	return TOONZ_OK;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
size_t get_memory_requirement(toonz_node_handle_t node, const toonz_rendering_setting_t *rs, double frame, const toonz_rect_t *rect)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("%s:\n", __FUNCTION__);
Toshihiro Shimizu 890ddd
	return TOONZ_OK;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void on_new_frame(toonz_node_handle_t node, const toonz_rendering_setting_t *rs, double frame)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("%s:\n", __FUNCTION__);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void on_end_frame(toonz_node_handle_t node, const toonz_rendering_setting_t *rs, double frame)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("%s:\n", __FUNCTION__);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
toonz_nodal_rasterfx_handler_t_ toonz_plugin_node_handler =
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		{1, 0},					//	ver
Toshihiro Shimizu 890ddd
		do_compute,				//	do_compute
Toshihiro Shimizu 890ddd
		do_get_bbox,			//	do_get_bbox
Toshihiro Shimizu 890ddd
		can_handle,				//	can_handle
Toshihiro Shimizu 890ddd
		get_memory_requirement, //	get_memory_requirement
Toshihiro Shimizu 890ddd
		on_new_frame,			//	on_new_frame
Toshihiro Shimizu 890ddd
		on_end_frame,			//	on_end_frame
Toshihiro Shimizu 890ddd
		node_create,			//	create
Toshihiro Shimizu 890ddd
		node_destroy,			//	destroy
Toshihiro Shimizu 890ddd
		node_setup};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
extern "C" {
Toshihiro Shimizu 890ddd
TOONZ_PLUGIN_PROBE_BEGIN(TOONZ_IF_VER(1, 0))
Toshihiro Shimizu 890ddd
TOONZ_PLUGIN_PROBE_DEFINE(TOONZ_PLUGIN_VER(1, 0), "blur-plugin" /* name */, "dwango" /* vendor */, "libblur.plugin" /* identifier */, "a blur plugin for test", "http://dwango.co.jp/", TOONZ_PLUGIN_CLASS_POSTPROCESS_SLAB, &toonz_plugin_node_handler)
Toshihiro Shimizu 890ddd
TOONZ_PLUGIN_PROBE_END;
Toshihiro Shimizu 890ddd
}