Toshihiro Shimizu 890ddd
/*------------------------------------
Toshihiro Shimizu 890ddd
 Iwa_GradientWarpFx iwasawa
Toshihiro Shimizu 890ddd
 参照画像の勾配方向にWarpするエフェクト
Toshihiro Shimizu 890ddd
------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "iwa_gradientwarpfx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*------------------------------------------------------------
Toshihiro Shimizu 890ddd
 ソース画像を0〜1に正規化してホストメモリに読み込む
Toshihiro Shimizu 890ddd
------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixel="" raster,="" typename=""></typename>
Toshihiro Shimizu 890ddd
void Iwa_GradientWarpFx::setSourceRaster(const RASTER srcRas,
Toshihiro Shimizu 890ddd
										 float4 *dstMem,
Toshihiro Shimizu 890ddd
										 TDimensionI dim)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	float4 *chann_p = dstMem;
Toshihiro Shimizu 890ddd
	for (int j = 0; j < dim.ly; j++) {
Toshihiro Shimizu 890ddd
		PIXEL *pix = srcRas->pixels(j);
Toshihiro Shimizu 890ddd
		for (int i = 0; i < dim.lx; i++, pix++, chann_p++) {
Toshihiro Shimizu 890ddd
			(*chann_p).x = (float)pix->r / (float)PIXEL::maxChannelValue;
Toshihiro Shimizu 890ddd
			(*chann_p).y = (float)pix->g / (float)PIXEL::maxChannelValue;
Toshihiro Shimizu 890ddd
			(*chann_p).z = (float)pix->b / (float)PIXEL::maxChannelValue;
Toshihiro Shimizu 890ddd
			(*chann_p).w = (float)pix->m / (float)PIXEL::maxChannelValue;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*------------------------------------------------------------
Toshihiro Shimizu 890ddd
 参照画像の輝度値を0〜1に正規化してホストメモリに読み込む
Toshihiro Shimizu 890ddd
------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixel="" raster,="" typename=""></typename>
Toshihiro Shimizu 890ddd
void Iwa_GradientWarpFx::setWarperRaster(const RASTER warperRas,
Toshihiro Shimizu 890ddd
										 float *dstMem,
Toshihiro Shimizu 890ddd
										 TDimensionI dim)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	float *chann_p = dstMem;
Toshihiro Shimizu 890ddd
	for (int j = 0; j < dim.ly; j++) {
Toshihiro Shimizu 890ddd
		PIXEL *pix = warperRas->pixels(j);
Toshihiro Shimizu 890ddd
		for (int i = 0; i < dim.lx; i++, pix++, chann_p++) {
Toshihiro Shimizu 890ddd
			float r = (float)pix->r / (float)PIXEL::maxChannelValue;
Toshihiro Shimizu 890ddd
			float g = (float)pix->g / (float)PIXEL::maxChannelValue;
Toshihiro Shimizu 890ddd
			float b = (float)pix->b / (float)PIXEL::maxChannelValue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			(*chann_p) = 0.298912f * r + 0.586611f * g + 0.114478f * b;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*------------------------------------------------------------
Toshihiro Shimizu 890ddd
 出力結果をChannel値に変換してタイルに格納
Toshihiro Shimizu 890ddd
------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
template <typename pixel="" raster,="" typename=""></typename>
Toshihiro Shimizu 890ddd
void Iwa_GradientWarpFx::setOutputRaster(float4 *srcMem,
Toshihiro Shimizu 890ddd
										 const RASTER dstRas,
Toshihiro Shimizu 890ddd
										 TDimensionI dim,
Toshihiro Shimizu 890ddd
										 int2 margin)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int out_j = 0;
Toshihiro Shimizu 890ddd
	for (int j = margin.y; j < dstRas->getLy() + margin.y; j++, out_j++) {
Toshihiro Shimizu 890ddd
		PIXEL *pix = dstRas->pixels(out_j);
Toshihiro Shimizu 890ddd
		float4 *chan_p = srcMem;
Toshihiro Shimizu 890ddd
		chan_p += j * dim.lx + margin.x;
Toshihiro Shimizu 890ddd
		for (int i = 0; i < dstRas->getLx(); i++, pix++, chan_p++) {
Toshihiro Shimizu 890ddd
			float val;
Toshihiro Shimizu 890ddd
			val = (*chan_p).x * (float)PIXEL::maxChannelValue + 0.5f;
Toshihiro Shimizu 890ddd
			pix->r = (typename PIXEL::Channel)((val > (float)PIXEL::maxChannelValue) ? (float)PIXEL::maxChannelValue : val);
Toshihiro Shimizu 890ddd
			val = (*chan_p).y * (float)PIXEL::maxChannelValue + 0.5f;
Toshihiro Shimizu 890ddd
			pix->g = (typename PIXEL::Channel)((val > (float)PIXEL::maxChannelValue) ? (float)PIXEL::maxChannelValue : val);
Toshihiro Shimizu 890ddd
			val = (*chan_p).z * (float)PIXEL::maxChannelValue + 0.5f;
Toshihiro Shimizu 890ddd
			pix->b = (typename PIXEL::Channel)((val > (float)PIXEL::maxChannelValue) ? (float)PIXEL::maxChannelValue : val);
Toshihiro Shimizu 890ddd
			val = (*chan_p).w * (float)PIXEL::maxChannelValue + 0.5f;
Toshihiro Shimizu 890ddd
			pix->m = (typename PIXEL::Channel)((val > (float)PIXEL::maxChannelValue) ? (float)PIXEL::maxChannelValue : val);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Iwa_GradientWarpFx::Iwa_GradientWarpFx()
Toshihiro Shimizu 890ddd
	: m_h_maxlen(0.0), m_v_maxlen(0.0), m_scale(1.0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/*- 共通パラメータのバインド -*/
Toshihiro Shimizu 890ddd
	addInputPort("Source", m_source);
Toshihiro Shimizu 890ddd
	addInputPort("Warper", m_warper);
Toshihiro Shimizu 890ddd
	bindParam(this, "h_maxlen", m_h_maxlen);
Toshihiro Shimizu 890ddd
	bindParam(this, "v_maxlen", m_v_maxlen);
Toshihiro Shimizu 890ddd
	bindParam(this, "scale", m_scale);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_h_maxlen->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
	m_v_maxlen->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
	m_h_maxlen->setValueRange(-100.0, 100.0);
Toshihiro Shimizu 890ddd
	m_v_maxlen->setValueRange(-100.0, 100.0);
Toshihiro Shimizu 890ddd
	m_scale->setValueRange(1.0, 100.0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Iwa_GradientWarpFx::doCompute(TTile &tile,
Toshihiro Shimizu 890ddd
								   double frame,
Toshihiro Shimizu 890ddd
								   const TRenderSettings &settings)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/*- ソース画像が刺さっていなければreturn -*/
Toshihiro Shimizu 890ddd
	if (!m_source.isConnected()) {
Toshihiro Shimizu 890ddd
		tile.getRaster()->clear();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	/*- 参照画像が刺さっていなければ、ソース画像をそのまま返す -*/
Toshihiro Shimizu 890ddd
	if (!m_warper.isConnected()) {
Toshihiro Shimizu 890ddd
		m_source->compute(tile, frame, settings);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*-  計算パラメータを得る -*/
Toshihiro Shimizu 890ddd
	/*- 移動距離のピクセルサイズ -*/
Toshihiro Shimizu 890ddd
	/*--- 拡大縮小(移動回転しないで)のGeometryを反映させる ---*/
Toshihiro Shimizu 890ddd
	double k = sqrt(fabs(settings.m_affine.det()));
Toshihiro Shimizu 890ddd
	double hLength = m_h_maxlen->getValue(frame) * k;
Toshihiro Shimizu 890ddd
	double vLength = m_v_maxlen->getValue(frame) * k;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double scale = m_scale->getValue(frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*- ワープ距離が0なら、ソース画像をそのまま返す -*/
Toshihiro Shimizu 890ddd
	if (hLength == 0.0 && vLength == 0.0) {
Toshihiro Shimizu 890ddd
		m_source->compute(tile, frame, settings);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int margin = static_cast<int>(ceil((abs(hLength) < abs(vLength)) ? abs(vLength) : abs(hLength)));</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*- 素材計算範囲を計算 -*/
Toshihiro Shimizu 890ddd
	/*- 出力範囲 -*/
Toshihiro Shimizu 890ddd
	TRectD rectOut(tile.m_pos, TDimensionD(
Toshihiro Shimizu 890ddd
								   tile.getRaster()->getLx(), tile.getRaster()->getLy()));
Toshihiro Shimizu 890ddd
	TRectD enlargedRect = rectOut.enlarge((double)margin);
Toshihiro Shimizu 890ddd
	TDimensionI enlargedDim((int)enlargedRect.getLx(), (int)enlargedRect.getLy());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*- ソース画像を正規化して格納 -*/
Toshihiro Shimizu 890ddd
	float4 *source_host;
Toshihiro Shimizu 890ddd
	TRasterGR8P source_host_ras(enlargedDim.lx * sizeof(float4), enlargedDim.ly);
Toshihiro Shimizu 890ddd
	source_host_ras->lock();
Toshihiro Shimizu 890ddd
	source_host = (float4 *)source_host_ras->getRawData();
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		/*- タイルはこのフォーカス内だけ使用。正規化してsource_hostに取り込んだらもう使わない。 -*/
Toshihiro Shimizu 890ddd
		TTile sourceTile;
Toshihiro Shimizu 890ddd
		m_source->allocateAndCompute(
Toshihiro Shimizu 890ddd
			sourceTile, enlargedRect.getP00(),
Toshihiro Shimizu 890ddd
			enlargedDim,
Toshihiro Shimizu 890ddd
			tile.getRaster(), frame, settings);
Toshihiro Shimizu 890ddd
		/*- タイルの画像を0〜1に正規化してホストメモリに読み込む -*/
Toshihiro Shimizu 890ddd
		TRaster32P ras32 = (TRaster32P)sourceTile.getRaster();
Toshihiro Shimizu 890ddd
		TRaster64P ras64 = (TRaster64P)sourceTile.getRaster();
Toshihiro Shimizu 890ddd
		if (ras32)
Toshihiro Shimizu 890ddd
			setSourceRaster<traster32p, tpixel32="">(ras32, source_host, enlargedDim);</traster32p,>
Toshihiro Shimizu 890ddd
		else if (ras64)
Toshihiro Shimizu 890ddd
			setSourceRaster<traster64p, tpixel64="">(ras64, source_host, enlargedDim);</traster64p,>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*- 参照画像を正規化して格納 -*/
Toshihiro Shimizu 890ddd
	float *warper_host;
Toshihiro Shimizu 890ddd
	TRasterGR8P warper_host_ras(enlargedDim.lx * sizeof(float), enlargedDim.ly);
Toshihiro Shimizu 890ddd
	warper_host_ras->lock();
Toshihiro Shimizu 890ddd
	warper_host = (float *)warper_host_ras->getRawData();
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		/*- タイルはこのフォーカス内だけ使用。正規化してwarper_hostに取り込んだらもう使わない -*/
Toshihiro Shimizu 890ddd
		TTile warperTile;
Toshihiro Shimizu 890ddd
		m_warper->allocateAndCompute(
Toshihiro Shimizu 890ddd
			warperTile, enlargedRect.getP00(),
Toshihiro Shimizu 890ddd
			enlargedDim,
Toshihiro Shimizu 890ddd
			tile.getRaster(), frame, settings);
Toshihiro Shimizu 890ddd
		/*- タイルの画像の輝度値を0〜1に正規化してホストメモリに読み込む -*/
Toshihiro Shimizu 890ddd
		TRaster32P ras32 = (TRaster32P)warperTile.getRaster();
Toshihiro Shimizu 890ddd
		TRaster64P ras64 = (TRaster64P)warperTile.getRaster();
Toshihiro Shimizu 890ddd
		if (ras32)
Toshihiro Shimizu 890ddd
			setWarperRaster<traster32p, tpixel32="">(ras32, warper_host, enlargedDim);</traster32p,>
Toshihiro Shimizu 890ddd
		else if (ras64)
Toshihiro Shimizu 890ddd
			setWarperRaster<traster64p, tpixel64="">(ras64, warper_host, enlargedDim);</traster64p,>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*- 変位値をScale倍して増やす -*/
Toshihiro Shimizu 890ddd
	hLength *= scale;
Toshihiro Shimizu 890ddd
	vLength *= scale;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterGR8P result_host_ras;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	result_host_ras = TRasterGR8P(enlargedDim.lx * sizeof(float4), enlargedDim.ly);
Toshihiro Shimizu 890ddd
	/*- 結果を収めるメモリ -*/
Toshihiro Shimizu 890ddd
	float4 *result_host;
Toshihiro Shimizu 890ddd
	result_host_ras->lock();
Toshihiro Shimizu 890ddd
	result_host = (float4 *)result_host_ras->getRawData();
Toshihiro Shimizu 890ddd
	doCompute_CPU(tile, frame, settings,
Toshihiro Shimizu 890ddd
				  hLength, vLength,
Toshihiro Shimizu 890ddd
				  margin,
Toshihiro Shimizu 890ddd
				  enlargedDim,
Toshihiro Shimizu 890ddd
				  source_host,
Toshihiro Shimizu 890ddd
				  warper_host,
Toshihiro Shimizu 890ddd
				  result_host);
Toshihiro Shimizu 890ddd
	/*- ポインタ入れ替え -*/
Toshihiro Shimizu 890ddd
	source_host = result_host;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int2 yohaku = {(enlargedDim.lx - tile.getRaster()->getSize().lx) / 2,
Toshihiro Shimizu 890ddd
				   (enlargedDim.ly - tile.getRaster()->getSize().ly) / 2};
Toshihiro Shimizu 890ddd
	/*- ラスタのクリア -*/
Toshihiro Shimizu 890ddd
	tile.getRaster()->clear();
Toshihiro Shimizu 890ddd
	TRaster32P outRas32 = (TRaster32P)tile.getRaster();
Toshihiro Shimizu 890ddd
	TRaster64P outRas64 = (TRaster64P)tile.getRaster();
Toshihiro Shimizu 890ddd
	if (outRas32)
Toshihiro Shimizu 890ddd
		setOutputRaster<traster32p, tpixel32="">(source_host, outRas32, enlargedDim, yohaku);</traster32p,>
Toshihiro Shimizu 890ddd
	else if (outRas64)
Toshihiro Shimizu 890ddd
		setOutputRaster<traster64p, tpixel64="">(source_host, outRas64, enlargedDim, yohaku);</traster64p,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*- ソース画像のメモリ解放 -*/
Toshihiro Shimizu 890ddd
	source_host_ras->unlock();
Toshihiro Shimizu 890ddd
	/*- 参照画像のメモリ解放 -*/
Toshihiro Shimizu 890ddd
	warper_host_ras->unlock();
Toshihiro Shimizu 890ddd
	result_host_ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*------------------------------------
Toshihiro Shimizu 890ddd
 Fx計算
Toshihiro Shimizu 890ddd
------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Iwa_GradientWarpFx::doCompute_CPU(TTile &tile,
Toshihiro Shimizu 890ddd
									   const double frame,
Toshihiro Shimizu 890ddd
									   const TRenderSettings &settings,
Toshihiro Shimizu 890ddd
									   double hLength,
Toshihiro Shimizu 890ddd
									   double vLength,
Toshihiro Shimizu 890ddd
									   int margin,
Toshihiro Shimizu 890ddd
									   TDimensionI &enlargedDim,
Toshihiro Shimizu 890ddd
									   float4 *source_host,
Toshihiro Shimizu 890ddd
									   float *warper_host,
Toshihiro Shimizu 890ddd
									   float4 *result_host)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	float4 *res_p = result_host + margin * enlargedDim.lx + margin;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	float *warp_up = warper_host + (margin + 1) * enlargedDim.lx + margin;
Toshihiro Shimizu 890ddd
	float *warp_down = warper_host + (margin - 1) * enlargedDim.lx + margin;
Toshihiro Shimizu 890ddd
	float *warp_right = warper_host + margin * enlargedDim.lx + 1 + margin;
Toshihiro Shimizu 890ddd
	float *warp_left = warper_host + margin * enlargedDim.lx - 1 + margin;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int j = margin; j < enlargedDim.ly - margin; j++) {
Toshihiro Shimizu 890ddd
		for (int i = margin; i < enlargedDim.lx - margin;
Toshihiro Shimizu 890ddd
			 i++, res_p++, warp_up++, warp_down++, warp_right++, warp_left++) {
Toshihiro Shimizu 890ddd
			/*- 勾配を得る -*/
Toshihiro Shimizu 890ddd
			float2 grad = {static_cast<float>((*warp_right) - (*warp_left)),</float>
Toshihiro Shimizu 890ddd
						   static_cast<float>((*warp_up) - (*warp_down))};</float>
Toshihiro Shimizu 890ddd
			/*- 参照点 -*/
Toshihiro Shimizu 890ddd
			float2 samplePos = {static_cast<float>(i + grad.x * hLength),</float>
Toshihiro Shimizu 890ddd
								static_cast<float>(j + grad.y * vLength)};</float>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			int2 index = {(int)(samplePos.x + (float)enlargedDim.lx) - enlargedDim.lx,
Toshihiro Shimizu 890ddd
						  (int)(samplePos.y + (float)enlargedDim.ly) - enlargedDim.ly};
Toshihiro Shimizu 890ddd
			float2 ratio = {samplePos.x - (float)index.x,
Toshihiro Shimizu 890ddd
							samplePos.y - (float)index.y};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			/*- サンプリング点回りのピクセルを線形補間 -*/
Toshihiro Shimizu 890ddd
			float4 col1 = interp_CPU(getSourceVal_CPU(source_host, enlargedDim, index.x, index.y),
Toshihiro Shimizu 890ddd
									 getSourceVal_CPU(source_host, enlargedDim, index.x + 1, index.y),
Toshihiro Shimizu 890ddd
									 ratio.x);
Toshihiro Shimizu 890ddd
			float4 col2 = interp_CPU(getSourceVal_CPU(source_host, enlargedDim, index.x, index.y + 1),
Toshihiro Shimizu 890ddd
									 getSourceVal_CPU(source_host, enlargedDim, index.x + 1, index.y + 1),
Toshihiro Shimizu 890ddd
									 ratio.x);
Toshihiro Shimizu 890ddd
			*res_p = interp_CPU(col1, col2, ratio.y);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		res_p += 2 * margin;
Toshihiro Shimizu 890ddd
		warp_up += 2 * margin;
Toshihiro Shimizu 890ddd
		warp_down += 2 * margin;
Toshihiro Shimizu 890ddd
		warp_right += 2 * margin;
Toshihiro Shimizu 890ddd
		warp_left += 2 * margin;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
float4 Iwa_GradientWarpFx::getSourceVal_CPU(float4 *source_host,
Toshihiro Shimizu 890ddd
											TDimensionI &enlargedDim,
Toshihiro Shimizu 890ddd
											int pos_x, int pos_y)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (pos_x < 0 || pos_x >= enlargedDim.lx ||
Toshihiro Shimizu 890ddd
		pos_y < 0 || pos_y >= enlargedDim.ly)
Toshihiro Shimizu 890ddd
		return float4{0.0f, 0.0f, 0.0f, 0.0f};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return source_host[pos_y * enlargedDim.lx + pos_x];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
float4 Iwa_GradientWarpFx::interp_CPU(float4 val1, float4 val2, float ratio)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return float4{(1.0f - ratio) * val1.x + ratio * val2.x,
Toshihiro Shimizu 890ddd
				  (1.0f - ratio) * val1.y + ratio * val2.y,
Toshihiro Shimizu 890ddd
				  (1.0f - ratio) * val1.z + ratio * val2.z,
Toshihiro Shimizu 890ddd
				  (1.0f - ratio) * val1.w + ratio * val2.w};
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool Iwa_GradientWarpFx::doGetBBox(double frame,
Toshihiro Shimizu 890ddd
								   TRectD &bBox,
Toshihiro Shimizu 890ddd
								   const TRenderSettings &info)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_source.isConnected()) {
Toshihiro Shimizu 890ddd
		bBox = TRectD();
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const bool ret = m_source->doGetBBox(frame, bBox, info);
Toshihiro Shimizu 890ddd
	get_render_enlarge(frame, info.m_affine, bBox);
Toshihiro Shimizu 890ddd
	return ret;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool Iwa_GradientWarpFx::canHandle(const TRenderSettings &info,
Toshihiro Shimizu 890ddd
								   double frame)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Iwa_GradientWarpFx::get_render_real_hv(const double frame,
Toshihiro Shimizu 890ddd
											const TAffine affine,
Toshihiro Shimizu 890ddd
											double &h_maxlen,
Toshihiro Shimizu 890ddd
											double &v_maxlen)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/*--- ベクトルにする(プラス値) --- */
Toshihiro Shimizu 890ddd
	TPointD rend_vect;
Toshihiro Shimizu 890ddd
	rend_vect.x = abs(m_h_maxlen->getValue(frame));
Toshihiro Shimizu 890ddd
	rend_vect.y = abs(m_v_maxlen->getValue(frame));
Toshihiro Shimizu 890ddd
	/*--- 拡大縮小(移動回転しないで)のGeometryを反映させる ---*/
Toshihiro Shimizu 890ddd
	rend_vect = rend_vect * sqrt(fabs(affine.det()));
Toshihiro Shimizu 890ddd
	/*--- 方向は無視して長さを返す(プラス値) ---*/
Toshihiro Shimizu 890ddd
	h_maxlen = rend_vect.x;
Toshihiro Shimizu 890ddd
	v_maxlen = rend_vect.y;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Iwa_GradientWarpFx::get_render_enlarge(const double frame,
Toshihiro Shimizu 890ddd
											const TAffine affine,
Toshihiro Shimizu 890ddd
											TRectD &bBox)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double h_maxlen = 0.0;
Toshihiro Shimizu 890ddd
	double v_maxlen = 0.0;
Toshihiro Shimizu 890ddd
	this->get_render_real_hv(frame, affine, h_maxlen, v_maxlen);
Toshihiro Shimizu 890ddd
	const int margin = static_cast<int>(ceil(</int>
Toshihiro Shimizu 890ddd
		(h_maxlen < v_maxlen) ? v_maxlen : h_maxlen));
Toshihiro Shimizu 890ddd
	if (0 < margin) {
Toshihiro Shimizu 890ddd
		bBox = bBox.enlarge(static_cast<double>(margin));</double>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(Iwa_GradientWarpFx, "iwa_GradientWarpFx")