Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "tspectrumparam.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
#include "tparamuiconcept.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
inline void pixelConvert(TPixel32 &dst, const TPixel32 &src) { dst = src; }
Toshihiro Shimizu 890ddd
inline void pixelConvert(TPixel64 &dst, const TPixel32 &src) { dst = toPixel64(src); }
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class FourPointsGradientFx : public TStandardZeraryFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(FourPointsGradientFx)
Toshihiro Shimizu 890ddd
	TSpectrumParamP m_colors;
Toshihiro Shimizu 890ddd
	TPointParamP m_point1;
Toshihiro Shimizu 890ddd
	TPointParamP m_point2;
Toshihiro Shimizu 890ddd
	TPointParamP m_point3;
Toshihiro Shimizu 890ddd
	TPointParamP m_point4;
Toshihiro Shimizu 890ddd
	TPixelParamP m_color1;
Toshihiro Shimizu 890ddd
	TPixelParamP m_color2;
Toshihiro Shimizu 890ddd
	TPixelParamP m_color3;
Toshihiro Shimizu 890ddd
	TPixelParamP m_color4;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	FourPointsGradientFx()
Toshihiro Shimizu 890ddd
		: m_point1(TPointD(200.0, 200.0)), m_point2(TPointD(-200.0, 200.0)), m_point3(TPointD(-200.0, -200.0)), m_point4(TPointD(200.0, -200.0)), m_color1(TPixel32::Red), m_color2(TPixel32::Green), m_color3(TPixel32::Blue), m_color4(TPixel32::Yellow)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_point1->getX()->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
		m_point1->getY()->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
		m_point2->getX()->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
		m_point2->getY()->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
		m_point3->getX()->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
		m_point3->getY()->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
		m_point4->getX()->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
		m_point4->getY()->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
		/*
Toshihiro Shimizu 890ddd
   bindParam(this,"point1", m_point1);
Toshihiro Shimizu 890ddd
	 bindParam(this,"point2", m_point2);
Toshihiro Shimizu 890ddd
	 bindParam(this,"point3", m_point3);
Toshihiro Shimizu 890ddd
	 bindParam(this,"point4", m_point4);
Toshihiro Shimizu 890ddd
   bindParam(this,"color_1", m_color1);
Toshihiro Shimizu 890ddd
   bindParam(this,"color_2", m_color2);
Toshihiro Shimizu 890ddd
   bindParam(this,"color_3", m_color3);
Toshihiro Shimizu 890ddd
   bindParam(this,"color_4", m_color4);
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
		bindParam(this, "Point_1", m_point1);
Toshihiro Shimizu 890ddd
		bindParam(this, "Color_1", m_color1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		bindParam(this, "Point_2", m_point2);
Toshihiro Shimizu 890ddd
		bindParam(this, "Color_2", m_color2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		bindParam(this, "Point_3", m_point3);
Toshihiro Shimizu 890ddd
		bindParam(this, "Color_3", m_color3);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		bindParam(this, "Point_4", m_point4);
Toshihiro Shimizu 890ddd
		bindParam(this, "Color_4", m_color4);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	~FourPointsGradientFx(){};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool doGetBBox(double, TRectD &bbox, const TRenderSettings &info)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		bbox = TConsts::infiniteRectD;
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
	void doCompute(TTile &tile, double frame, const TRenderSettings &ri);
Toshihiro Shimizu 890ddd
	bool canHandle(const TRenderSettings &info, double frame) { return true; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void getParamUIs(TParamUIConcept *&concepts, int &length)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		concepts = new TParamUIConcept[length = 4];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		concepts[0].m_type = TParamUIConcept::POINT;
Toshihiro Shimizu 890ddd
		concepts[0].m_label = "Point 1";
Toshihiro Shimizu 890ddd
		concepts[0].m_params.push_back(m_point1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		concepts[1].m_type = TParamUIConcept::POINT;
Toshihiro Shimizu 890ddd
		concepts[1].m_label = "Point 2";
Toshihiro Shimizu 890ddd
		concepts[1].m_params.push_back(m_point2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		concepts[2].m_type = TParamUIConcept::POINT;
Toshihiro Shimizu 890ddd
		concepts[2].m_label = "Point 3";
Toshihiro Shimizu 890ddd
		concepts[2].m_params.push_back(m_point3);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		concepts[3].m_type = TParamUIConcept::POINT;
Toshihiro Shimizu 890ddd
		concepts[3].m_label = "Point 4";
Toshihiro Shimizu 890ddd
		concepts[3].m_params.push_back(m_point4);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename channel_type="" pixel,="" typename=""></typename>
Toshihiro Shimizu 890ddd
void doFourPointsGradient(
Toshihiro Shimizu 890ddd
	const TRasterPT<pixel> &ras,</pixel>
Toshihiro Shimizu 890ddd
	TPointD tilepos,
Toshihiro Shimizu 890ddd
	TPointD pos1, TPointD pos2, TPointD pos3, TPointD pos4,
Toshihiro Shimizu 890ddd
	TPixel32 ccol1, TPixel32 ccol2, TPixel32 ccol3, TPixel32 ccol4)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	PIXEL col1, col2, col3, col4;
Toshihiro Shimizu 890ddd
	pixelConvert(col1, ccol1);
Toshihiro Shimizu 890ddd
	pixelConvert(col2, ccol2);
Toshihiro Shimizu 890ddd
	pixelConvert(col3, ccol3);
Toshihiro Shimizu 890ddd
	pixelConvert(col4, ccol4);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int j;
Toshihiro Shimizu 890ddd
	ras->lock();
Toshihiro Shimizu 890ddd
	for (j = 0; j < ras->getLy(); j++) {
Toshihiro Shimizu 890ddd
		TPointD pos = tilepos;
Toshihiro Shimizu 890ddd
		pos.y += j;
Toshihiro Shimizu 890ddd
		PIXEL *pix = ras->pixels(j);
Toshihiro Shimizu 890ddd
		PIXEL *endPix = pix + ras->getLx();
Toshihiro Shimizu 890ddd
		while (pix < endPix) {
Toshihiro Shimizu 890ddd
			double d1 = sqrt((pos1.x - pos.x) * (pos1.x - pos.x) + (pos1.y - pos.y) * (pos1.y - pos.y));
Toshihiro Shimizu 890ddd
			if (!d1) {
Toshihiro Shimizu 890ddd
				*pix = col1;
Toshihiro Shimizu 890ddd
				pos.x += 1;
Toshihiro Shimizu 890ddd
				++pix;
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			double d2 = sqrt((pos2.x - pos.x) * (pos2.x - pos.x) + (pos2.y - pos.y) * (pos2.y - pos.y));
Toshihiro Shimizu 890ddd
			if (!d2) {
Toshihiro Shimizu 890ddd
				*pix = col2;
Toshihiro Shimizu 890ddd
				pos.x += 1;
Toshihiro Shimizu 890ddd
				++pix;
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			double d3 = sqrt((pos3.x - pos.x) * (pos3.x - pos.x) + (pos3.y - pos.y) * (pos3.y - pos.y));
Toshihiro Shimizu 890ddd
			if (!d3) {
Toshihiro Shimizu 890ddd
				*pix = col3;
Toshihiro Shimizu 890ddd
				pos.x += 1;
Toshihiro Shimizu 890ddd
				++pix;
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			double d4 = sqrt((pos4.x - pos.x) * (pos4.x - pos.x) + (pos4.y - pos.y) * (pos4.y - pos.y));
Toshihiro Shimizu 890ddd
			if (!d4) {
Toshihiro Shimizu 890ddd
				*pix = col4;
Toshihiro Shimizu 890ddd
				pos.x += 1;
Toshihiro Shimizu 890ddd
				++pix;
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			double dtotal = 1 / d1 + 1 / d2 + 1 / d3 + 1 / d4;
Toshihiro Shimizu 890ddd
			pix->r = (CHANNEL_TYPE)(((1 / d1) / dtotal) * col1.r + ((1 / d2) / dtotal) * col2.r + ((1 / d3) / dtotal) * col3.r + ((1 / d4) / dtotal) * col4.r);
Toshihiro Shimizu 890ddd
			pix->g = (CHANNEL_TYPE)(((1 / d1) / dtotal) * col1.g + ((1 / d2) / dtotal) * col2.g + ((1 / d3) / dtotal) * col3.g + ((1 / d4) / dtotal) * col4.g);
Toshihiro Shimizu 890ddd
			pix->b = (CHANNEL_TYPE)(((1 / d1) / dtotal) * col1.b + ((1 / d2) / dtotal) * col2.b + ((1 / d3) / dtotal) * col3.b + ((1 / d4) / dtotal) * col4.b);
Toshihiro Shimizu 890ddd
			pix->m = (CHANNEL_TYPE)(((1 / d1) / dtotal) * col1.m + ((1 / d2) / dtotal) * col2.m + ((1 / d3) / dtotal) * col3.m + ((1 / d4) / dtotal) * col4.m);
Toshihiro Shimizu 890ddd
			pos.x += 1.0;
Toshihiro Shimizu 890ddd
			++pix;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FourPointsGradientFx::doCompute(TTile &tile, double frame, const TRenderSettings &ri)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPointD pos1 = m_point1->getValue(frame) * (1.0 / ri.m_shrinkX);
Toshihiro Shimizu 890ddd
	TPointD pos2 = m_point2->getValue(frame) * (1.0 / ri.m_shrinkX);
Toshihiro Shimizu 890ddd
	TPointD pos3 = m_point3->getValue(frame) * (1.0 / ri.m_shrinkX);
Toshihiro Shimizu 890ddd
	TPointD pos4 = m_point4->getValue(frame) * (1.0 / ri.m_shrinkX);
Toshihiro Shimizu 890ddd
	pos1 = ri.m_affine * pos1;
Toshihiro Shimizu 890ddd
	pos2 = ri.m_affine * pos2;
Toshihiro Shimizu 890ddd
	pos3 = ri.m_affine * pos3;
Toshihiro Shimizu 890ddd
	pos4 = ri.m_affine * pos4;
Toshihiro Shimizu 890ddd
	TPixel32 col1 = m_color1->getPremultipliedValue(frame);
Toshihiro Shimizu 890ddd
	TPixel32 col2 = m_color2->getPremultipliedValue(frame);
Toshihiro Shimizu 890ddd
	TPixel32 col3 = m_color3->getPremultipliedValue(frame);
Toshihiro Shimizu 890ddd
	TPixel32 col4 = m_color4->getPremultipliedValue(frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD pos = tile.m_pos;
Toshihiro Shimizu 890ddd
	TRaster32P raster32 = tile.getRaster();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (raster32)
Toshihiro Shimizu 890ddd
		doFourPointsGradient<tpixel32, uchar="">(raster32, pos, pos1, pos2, pos3, pos4, col1, col2, col3, col4);</tpixel32,>
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		TRaster64P raster64 = tile.getRaster();
Toshihiro Shimizu 890ddd
		if (raster64)
Toshihiro Shimizu 890ddd
			doFourPointsGradient<tpixel64, ushort="">(raster64, pos, pos1, pos2, pos3, pos4, col1, col2, col3, col4);</tpixel64,>
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			throw TException("Brightness&Contrast: unsupported Pixel Type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(FourPointsGradientFx, "fourPointsGradientFx");