Toshihiro Shimizu 890ddd
#include <sstream> /* std::ostringstream */</sstream>
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ino_common.h"
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Toshihiro Shimizu 890ddd
class ino_negate : public TStandardRasterFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(ino_negate)
Toshihiro Shimizu 890ddd
	TRasterFxPort m_input;
Toshihiro Shimizu 890ddd
	TBoolParamP m_red;
Toshihiro Shimizu 890ddd
	TBoolParamP m_green;
Toshihiro Shimizu 890ddd
	TBoolParamP m_blue;
Toshihiro Shimizu 890ddd
	TBoolParamP m_alpha;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ino_negate()
Toshihiro Shimizu 890ddd
		: m_red(true), m_green(true), m_blue(true), m_alpha(false)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		addInputPort("Source", this->m_input);
Toshihiro Shimizu 890ddd
		bindParam(this, "red", this->m_red);
Toshihiro Shimizu 890ddd
		bindParam(this, "green", this->m_green);
Toshihiro Shimizu 890ddd
		bindParam(this, "blue", this->m_blue);
Toshihiro Shimizu 890ddd
		bindParam(this, "alpha", this->m_alpha);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	bool doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (this->m_input.isConnected()) {
Toshihiro Shimizu 890ddd
			return this->m_input->doGetBBox(frame, bBox, info);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			bBox = TRectD();
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	bool canHandle(const TRenderSettings &info, double frame)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void doCompute(
Toshihiro Shimizu 890ddd
		TTile &tile, double frame, const TRenderSettings &rend_sets);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(ino_negate, "inoNegateFx");
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Toshihiro Shimizu 890ddd
#include "igs_negate.h"
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
void fx_(
Toshihiro Shimizu 890ddd
	TRasterP in_ras, const bool sw_array[4])
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/***std::vector<unsigned char=""> in_vec;</unsigned>
Toshihiro Shimizu 890ddd
	ino::ras_to_vec( in_ras, ino::channels(), in_vec );***/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterGR8P in_gr8(
Toshihiro Shimizu 890ddd
		in_ras->getLy(), in_ras->getLx() * ino::channels() *
Toshihiro Shimizu 890ddd
							 ((TRaster64P)in_ras ? sizeof(unsigned short) : sizeof(unsigned char)));
Toshihiro Shimizu 890ddd
	in_gr8->lock();
Toshihiro Shimizu 890ddd
	ino::ras_to_arr(in_ras, ino::channels(), in_gr8->getRawData());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	igs::negate::change(
Toshihiro Shimizu 890ddd
		//in_ras->getRawData() // BGRA
Toshihiro Shimizu 890ddd
		//&in_vec.at(0) // RGBA
Toshihiro Shimizu 890ddd
		in_gr8->getRawData()
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			,
Toshihiro Shimizu 890ddd
		in_ras->getLy(), in_ras->getLx() // Not use in_ras->getWrap()
Toshihiro Shimizu 890ddd
		,
Toshihiro Shimizu 890ddd
		ino::channels(), ino::bits(in_ras)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
							 ,
Toshihiro Shimizu 890ddd
		sw_array);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/***ino::vec_to_ras( in_vec, ino::channels(), in_ras, 0 );***/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ino::arr_to_ras(in_gr8->getRawData(), ino::channels(), in_ras, 0);
Toshihiro Shimizu 890ddd
	in_gr8->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Toshihiro Shimizu 890ddd
void ino_negate::doCompute(
Toshihiro Shimizu 890ddd
	TTile &tile, double frame, const TRenderSettings &rend_sets)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/* ------ 接続していなければ処理しない -------------------- */
Toshihiro Shimizu 890ddd
	if (!this->m_input.isConnected()) {
Toshihiro Shimizu 890ddd
		tile.getRaster()->clear(); /* 塗りつぶしクリア */
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/* ------ サポートしていないPixelタイプはエラーを投げる --- */
Toshihiro Shimizu 890ddd
	if (!((TRaster32P)tile.getRaster()) &&
Toshihiro Shimizu 890ddd
		!((TRaster64P)tile.getRaster())) {
Toshihiro Shimizu 890ddd
		throw TRopException("unsupported input pixel type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/* ------ 動作パラメータを得る ---------------------------- */
Toshihiro Shimizu 890ddd
	bool sw_array[4];
Toshihiro Shimizu 890ddd
	sw_array[0] = this->m_red->getValue();
Toshihiro Shimizu 890ddd
	sw_array[1] = this->m_green->getValue();
Toshihiro Shimizu 890ddd
	sw_array[2] = this->m_blue->getValue();
Toshihiro Shimizu 890ddd
	sw_array[3] = this->m_alpha->getValue();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/* ------ 画像生成 ---------------------------------------- */
Toshihiro Shimizu 890ddd
	this->m_input->compute(tile, frame, rend_sets);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/* ------ (app_begin)log記憶 ------------------------------ */
Toshihiro Shimizu 890ddd
	const bool log_sw = ino::log_enable_sw();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (log_sw) {
Toshihiro Shimizu 890ddd
		std::ostringstream os;
Toshihiro Shimizu 890ddd
		os << "params"
Toshihiro Shimizu 890ddd
		   << "  r_sw " << sw_array[0]
Toshihiro Shimizu 890ddd
		   << "  g_sw " << sw_array[1]
Toshihiro Shimizu 890ddd
		   << "  b_sw " << sw_array[2]
Toshihiro Shimizu 890ddd
		   << "  a_sw " << sw_array[3]
Toshihiro Shimizu 890ddd
		   << "   tile w " << tile.getRaster()->getLx()
Toshihiro Shimizu 890ddd
		   << "  h " << tile.getRaster()->getLy()
Toshihiro Shimizu 890ddd
		   << "  pixbits " << ino::pixel_bits(tile.getRaster())
Toshihiro Shimizu 890ddd
		   << "   frame " << frame;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/* ------ fx処理 ------------------------------------------ */
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		tile.getRaster()->lock();
Toshihiro Shimizu 890ddd
		fx_(tile.getRaster(), sw_array);
Toshihiro Shimizu 890ddd
		tile.getRaster()->unlock();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/* ------ error処理 --------------------------------------- */
Toshihiro Shimizu 890ddd
	catch (std::bad_alloc &e) {
Toshihiro Shimizu 890ddd
		tile.getRaster()->unlock();
Toshihiro Shimizu 890ddd
		if (log_sw) {
Toshihiro Shimizu 890ddd
			std::string str("std::bad_alloc <");
Toshihiro Shimizu 890ddd
			str += e.what();
Toshihiro Shimizu 890ddd
			str += '>';
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		throw;
Toshihiro Shimizu 890ddd
	} catch (std::exception &e) {
Toshihiro Shimizu 890ddd
		tile.getRaster()->unlock();
Toshihiro Shimizu 890ddd
		if (log_sw) {
Toshihiro Shimizu 890ddd
			std::string str("exception <");
Toshihiro Shimizu 890ddd
			str += e.what();
Toshihiro Shimizu 890ddd
			str += '>';
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		throw;
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
		tile.getRaster()->unlock();
Toshihiro Shimizu 890ddd
		if (log_sw) {
Toshihiro Shimizu 890ddd
			std::string str("other exception");
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		throw;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}