Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class RGBMFadeFx : public TStandardRasterFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(RGBMFadeFx)
Toshihiro Shimizu 890ddd
	TRasterFxPort m_input;
Toshihiro Shimizu 890ddd
	TPixelParamP m_color;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_intensity;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	RGBMFadeFx()
Toshihiro Shimizu 890ddd
		: m_intensity(50.0), m_color(TPixel32::Black)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		bindParam(this, "color", m_color);
Toshihiro Shimizu 890ddd
		bindParam(this, "intensity", m_intensity);
Toshihiro Shimizu 890ddd
		m_intensity->setValueRange(0, 100);
Toshihiro Shimizu 890ddd
		addInputPort("Source", m_input);
Toshihiro Shimizu 890ddd
		m_color->enableMatte(false);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	~RGBMFadeFx(){};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_input.isConnected())
Toshihiro Shimizu 890ddd
			return 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
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
Toshihiro Shimizu 890ddd
template <typename pixel=""></typename>
Toshihiro Shimizu 890ddd
void doRGBMFade(TRasterPT<pixel> &ras, const PIXEL &col, double intensity)</pixel>
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
		PIXEL *pix = ras->pixels(j);
Toshihiro Shimizu 890ddd
		PIXEL *endPix = pix + ras->getLx();
Toshihiro Shimizu 890ddd
		while (pix < endPix) {
Toshihiro Shimizu 890ddd
			pix->m = pix->m;
Toshihiro Shimizu 890ddd
			double factor = pix->m / (double)PIXEL::maxChannelValue;
Toshihiro Shimizu 890ddd
			int val;
Toshihiro Shimizu 890ddd
			val = troundp(pix->r + intensity * (col.r * factor - pix->r));
Toshihiro Shimizu 890ddd
			pix->r = (val > PIXEL::maxChannelValue) ? PIXEL::maxChannelValue : val;
Toshihiro Shimizu 890ddd
			val = troundp(pix->g + intensity * (col.g * factor - pix->g));
Toshihiro Shimizu 890ddd
			pix->g = (val > PIXEL::maxChannelValue) ? PIXEL::maxChannelValue : val;
Toshihiro Shimizu 890ddd
			val = troundp(pix->b + intensity * (col.b * factor - pix->b));
Toshihiro Shimizu 890ddd
			pix->b = (val > PIXEL::maxChannelValue) ? PIXEL::maxChannelValue : val;
Toshihiro Shimizu 890ddd
			/*  qui si faceva il fade anche del matte
Toshihiro Shimizu 890ddd
      pix->r=(UCHAR)(pix->r+intensity*(col.r-pix->r));
Toshihiro Shimizu 890ddd
      pix->g=(UCHAR)(pix->g+intensity*(col.g-pix->g));
Toshihiro Shimizu 890ddd
      pix->b=(UCHAR)(pix->b+intensity*(col.b-pix->b));
Toshihiro Shimizu 890ddd
      pix->m=(UCHAR)(pix->m+intensity*(col.m-pix->m));*/
Toshihiro Shimizu 890ddd
			++pix;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RGBMFadeFx::doCompute(TTile &tile, double frame,
Toshihiro Shimizu 890ddd
						   const TRenderSettings &ri)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_input.isConnected())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_input->compute(tile, frame, ri);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPixel32 col = m_color->getValue(frame);
Toshihiro Shimizu 890ddd
	double min, max, step;
Toshihiro Shimizu 890ddd
	m_intensity->getValueRange(min, max, step);
Toshihiro Shimizu 890ddd
	double intensity = tcrop(m_intensity->getValue(frame), min, max) / 100;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P raster32 = tile.getRaster();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (raster32)
Toshihiro Shimizu 890ddd
		doRGBMFade<tpixel32>(raster32, col, intensity);</tpixel32>
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		TRaster64P raster64 = tile.getRaster();
Toshihiro Shimizu 890ddd
		if (raster64)
Toshihiro Shimizu 890ddd
			doRGBMFade<tpixel64>(raster64, toPixel64(col), intensity);</tpixel64>
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			throw TException("RGBMFadeFx: unsupported Pixel Type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(RGBMFadeFx, "rgbmFadeFx");