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 <limits></limits>
roentgen edd579
#include <utils rect.hpp=""></utils>
roentgen edd579
#include <utils affine.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 void toonz_plugin_probe(toonz_plugin_probe_t **begin, toonz_plugin_probe_t **end);
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
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
	auto tileif = grab_interf<toonz::tile_interface_t>(TOONZ_UUID_TILE);</toonz::tile_interface_t>
Toshihiro Shimizu 890ddd
	if (tileif) {
Toshihiro Shimizu 890ddd
		toonz::rect_t rect;
Toshihiro Shimizu 890ddd
		tileif->get_rectangle(tile, &rect);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/* evaluate the fx */
Toshihiro Shimizu 890ddd
		int lx = rect.x1 - rect.x0;
Toshihiro Shimizu 890ddd
		int ly = rect.y1 - rect.y0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		ToonzAffine mat(rs->affine);
Toshihiro Shimizu 890ddd
		ToonzAffine invmat = mat.inv();
Toshihiro Shimizu 890ddd
		ToonzPoint p = invmat * ToonzPoint(rect.x0, rect.y0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int dstride = 0;
Toshihiro Shimizu 890ddd
		tileif->get_raw_stride(tile, &dstride);
Toshihiro Shimizu 890ddd
		int delement_type = 0;
Toshihiro Shimizu 890ddd
		tileif->get_element_type(tile, &delement_type);
Toshihiro Shimizu 890ddd
		uint8_t *daddr = NULL;
Toshihiro Shimizu 890ddd
		tileif->get_raw_address_unsafe(tile, reinterpret_cast<void **="">(&daddr));</void>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		printf("-+ lx:%d ly:%d\n", lx, ly);
Toshihiro Shimizu 890ddd
		printf("-+ px:%g py:%g\n", p.x, p.y);
Toshihiro Shimizu 890ddd
		printf(" + dst rect(%g, %g, %g, %g)\n", rect.x0, rect.y0, rect.x1, rect.y1);
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
		for (int i = 0; i < ly; i++) {
Toshihiro Shimizu 890ddd
			uint32_t *ptr = reinterpret_cast<uint32_t *="">(daddr + i * dstride);</uint32_t>
Toshihiro Shimizu 890ddd
			/* [rx, ry] は effect の面内を描くベクトル. 半径 r 円の中心が [0, 0] で、 [-lx/2, -ly/2]-[lx/2, ly/2]
Toshihiro Shimizu 890ddd
			   [j, i] は dst のスキャンラインのベクトルで [0, 0]-[lx, ly] */
Toshihiro Shimizu 890ddd
			double rx = p.x;
Toshihiro Shimizu 890ddd
			double ry = p.y;
Toshihiro Shimizu 890ddd
			for (int j = 0; j < lx; j++) {
Toshihiro Shimizu 890ddd
				double r = std::sqrt(rx * rx + ry * ry);
Toshihiro Shimizu 890ddd
				double k = 0;
Toshihiro Shimizu 890ddd
				if (r < 64)
Toshihiro Shimizu 890ddd
					k = 1;
Toshihiro Shimizu 890ddd
				uint8_t c = (uint8_t)(k * 255);
Toshihiro Shimizu 890ddd
				*(ptr + j) = 0xff000000 | (c << 16) | (c << 8) | c;
Toshihiro Shimizu 890ddd
				/* hor advance */
Toshihiro Shimizu 890ddd
				rx += invmat.a11;
Toshihiro Shimizu 890ddd
				ry += invmat.a21;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			/* vert advance */
Toshihiro Shimizu 890ddd
			p.x += invmat.a12;
Toshihiro Shimizu 890ddd
			p.y += invmat.a22;
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
/* 円の周辺の黒いマスク部分が bbox に相当する:
Toshihiro Shimizu 890ddd
	   コンサバには無限に大きな矩形を返すのが最もコンサバな方法だが、 rendering_setting_t の affine 変換行列を用いてよりよい予測をすることもできる.
Toshihiro Shimizu 890ddd
	 */
Toshihiro Shimizu 890ddd
#if 0
Toshihiro Shimizu 890ddd
	/* too concervative */
Toshihiro Shimizu 890ddd
	rect->x0 = -std::numeric_limits< double >::max();
Toshihiro Shimizu 890ddd
	rect->y0 = -std::numeric_limits< double >::max();
Toshihiro Shimizu 890ddd
	rect->x1 = std::numeric_limits< double >::max();
Toshihiro Shimizu 890ddd
	rect->y1 = std::numeric_limits< double >::max();
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#if 0
Toshihiro Shimizu 890ddd
	/* too aggressive */
Toshihiro Shimizu 890ddd
	rect->x0 = -64;
Toshihiro Shimizu 890ddd
	rect->y0 = -64;
Toshihiro Shimizu 890ddd
	rect->x1 = 64;
Toshihiro Shimizu 890ddd
	rect->y1 = 64;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
	/* more reasonable than above */
Toshihiro Shimizu 890ddd
	ToonzRect r(-64, -64, 64, 64);
Toshihiro Shimizu 890ddd
	ToonzRect bbox = ToonzAffine(rs->affine) * r;
Toshihiro Shimizu 890ddd
	rect->x0 = bbox.x0;
Toshihiro Shimizu 890ddd
	rect->y0 = bbox.y0;
Toshihiro Shimizu 890ddd
	rect->x1 = bbox.x1;
Toshihiro Shimizu 890ddd
	rect->y1 = bbox.y1;
Toshihiro Shimizu 890ddd
	return modified;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
const char *strtbl[] = {"tokyo", "osaka", "kobe"};
Toshihiro Shimizu 890ddd
param_desc_t params0_[] = {
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_int_t>("p1st", "integer", {2 /* default */, -10 /* min */, 10 /* max */}, "this is integer"),</traits_int_t>
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_enum_t>("p2nd", "enumuration", {1, 3, strtbl}),</traits_enum_t>
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_bool_t>("p3rd", "boolean", {1}),</traits_bool_t>
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_string_t>("p4th", "string", {"a message"}),</traits_string_t>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
toonz_param_traits_spectrum_t::valuetype specs[] = {{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 params1_[] = {
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_color_t>("p1st", "color", {0, 0, 255 /* blue */, 255}),</traits_color_t>
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_spectrum_t>("p2nd", "spectrum", {0.1, 3, specs}),</traits_spectrum_t>
Toshihiro Shimizu 890ddd
	param_desc_ctor<traits_tonecurve_t>("p3rd", "tone curve", {}),</traits_tonecurve_t>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
toonz_param_group_t groups0_[] = {
Toshihiro Shimizu 890ddd
	param_group_ctor("Group", sizeof(params0_) / sizeof(param_desc_t), params0_),
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
toonz_param_group_t groups1_[] = {
Toshihiro Shimizu 890ddd
	param_group_ctor("Group", sizeof(params1_) / sizeof(param_desc_t), params1_),
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
toonz_param_page_t pages0_[] = {
Toshihiro Shimizu 890ddd
	param_page_ctor("1st plugin", sizeof(groups0_) / sizeof(toonz_param_group_t), groups0_),
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
toonz_param_page_t pages1_[] = {
Toshihiro Shimizu 890ddd
	param_page_ctor("2nd plugin", sizeof(groups1_) / sizeof(toonz_param_group_t), groups1_),
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int node_setup_a(toonz::node_handle_t node)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("plugin A: setup(): node:%p\n", node);
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 *position = NULL;
Toshihiro Shimizu 890ddd
		int err = setup->set_parameter_pages_with_error(node, 1, pages0_, &errcode, &position);
Toshihiro Shimizu 890ddd
		if (err == TOONZ_ERROR_INVALID_VALUE) {
Toshihiro Shimizu 890ddd
			printf("setup err: reason:0x%x address:%p\n", errcode, position);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int node_setup_b(toonz::node_handle_t node)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("plugin B: setup(): node:%p\n", node);
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 *position = NULL;
Toshihiro Shimizu 890ddd
		int err = setup->set_parameter_pages_with_error(node, 1, pages1_, &errcode, &position);
Toshihiro Shimizu 890ddd
		if (err == TOONZ_ERROR_INVALID_VALUE) {
Toshihiro Shimizu 890ddd
			printf("setup err: reason:0x%x address:%p\n", errcode, position);
Toshihiro Shimizu 890ddd
		}
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("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__);
luz paz 6454c4
	/* geometric plugin のように Bounding Box が自明の場合、 Skew などの変換の影響でフルスクリーン効果のような大きな Bounding Box が
Toshihiro Shimizu 890ddd
	   過剰に大きくなってしまうことがある. これを防ぐには非ゼロを返すこと.
Toshihiro Shimizu 890ddd
	 */
Toshihiro Shimizu 890ddd
	return 1; /* non zero is 'true' */
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_handler0 = {
Toshihiro Shimizu 890ddd
	TOONZ_IF_VER(1, 0),		//	type 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_a};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
toonz_nodal_rasterfx_handler_t_ toonz_plugin_node_handler1 = {
Toshihiro Shimizu 890ddd
	TOONZ_IF_VER(1, 0),		//	type 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_b};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/**
Toshihiro Shimizu 890ddd
 *    Memory
Toshihiro Shimizu 890ddd
 *
Toshihiro Shimizu 890ddd
 *   |//////////////////////|
Toshihiro Shimizu 890ddd
 *   +----------------------+ <- toonz_plugin_info_list.begin
Toshihiro Shimizu 890ddd
 *   |  1st plugin          |
Toshihiro Shimizu 890ddd
 *   +----------------------+
Toshihiro Shimizu 890ddd
 *   |  2nd plugin          |
Toshihiro Shimizu 890ddd
 *   +----------------------+
Toshihiro Shimizu 890ddd
 *   |                      |
Toshihiro Shimizu 890ddd
 *             :
Toshihiro Shimizu 890ddd
 *   |                      |
Toshihiro Shimizu 890ddd
 *   +----------------------+ <- toonz_plugin_info_list.end
Toshihiro Shimizu 890ddd
 *   |  empty(all zeroed)   |
Toshihiro Shimizu 890ddd
 *   +----------------------+
Toshihiro Shimizu 890ddd
 *   |//// unused area /////|
Toshihiro Shimizu 890ddd
 * 
Toshihiro Shimizu 890ddd
 * 1. the array of plugins should be lain in the continuous area on a memory.
Toshihiro Shimizu 890ddd
 * 2. an empty element must be zero-ed all (including 'ver').
Toshihiro Shimizu 890ddd
 * 3. 'ver' fields must be same each other.
Toshihiro Shimizu 890ddd
 */
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), "multi1-plugin" /* name */, "dwango" /* vendor */, "multi1.plugin" /* identifier */, "1st plugin from the single module", "http://dwango.co.jp/", TOONZ_PLUGIN_CLASS_POSTPROCESS_SLAB | TOONZ_PLUGIN_CLASS_MODIFIER_GEOMETRIC, &toonz_plugin_node_handler0)
Toshihiro Shimizu 890ddd
,
Toshihiro Shimizu 890ddd
	TOONZ_PLUGIN_PROBE_DEFINE(TOONZ_PLUGIN_VER(1, 0), "multi2-plugin" /* name */, "dwango" /* vendor */, "multi2.plugin" /* identifier */, "2nd plugin from the single module", "http://dwango.co.jp/", TOONZ_PLUGIN_CLASS_POSTPROCESS_SLAB | TOONZ_PLUGIN_CLASS_MODIFIER_GEOMETRIC, &toonz_plugin_node_handler1)
Toshihiro Shimizu 890ddd
		TOONZ_PLUGIN_PROBE_END;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
const toonz_plugin_probe_list_t_ *toonz_plugin_probe()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	printf("toonz_plugin_probe()\n");
Toshihiro Shimizu 890ddd
	return &toonz_plugin_info_list;
Toshihiro Shimizu 890ddd
}