Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include <math.h></math.h>
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "hsvutil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class HSVScaleFx : public TStandardRasterFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(HSVScaleFx)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterFxPort m_input;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_hue;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_sat;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_value;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_hueScale;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_satScale;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_valueScale;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	HSVScaleFx()
Toshihiro Shimizu 890ddd
		: m_hue(0.0), m_sat(0.0), m_value(0.0), m_hueScale(100.0), m_satScale(100.0), m_valueScale(100.0)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		bindParam(this, "hue", m_hue);
Toshihiro Shimizu 890ddd
		bindParam(this, "saturation", m_sat);
Toshihiro Shimizu 890ddd
		bindParam(this, "value", m_value);
Toshihiro Shimizu 890ddd
		bindParam(this, "hue_scale", m_hueScale);
Toshihiro Shimizu 890ddd
		bindParam(this, "saturation_scale", m_satScale);
Toshihiro Shimizu 890ddd
		bindParam(this, "value_scale", m_valueScale);
Toshihiro Shimizu 890ddd
		m_hue->setValueRange(-180, 180);
Toshihiro Shimizu 890ddd
		m_sat->setValueRange(-1, 1);
Toshihiro Shimizu 890ddd
		m_value->setValueRange(-1, 1);
Toshihiro Shimizu 890ddd
		m_hueScale->setValueRange(0, (std::numeric_limits<double>::max)());</double>
Toshihiro Shimizu 890ddd
		m_satScale->setValueRange(0, (std::numeric_limits<double>::max)());</double>
Toshihiro Shimizu 890ddd
		m_valueScale->setValueRange(0, (std::numeric_limits<double>::max)());</double>
Toshihiro Shimizu 890ddd
		addInputPort("Source", m_input);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~HSVScaleFx(){};
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
			m_input->doGetBBox(frame, bBox, info);
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void doCompute(TTile &tile, double frame, const TRenderSettings &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool canHandle(const TRenderSettings &info, double frame) { return true; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename channel_type="" pixel,="" typename=""></typename>
Toshihiro Shimizu 890ddd
void doHSVScale(const TRasterPT<pixel> &ras, double hue, double sat, double value,</pixel>
Toshihiro Shimizu 890ddd
				double hueScale, double satScale, double valueScale)
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
Toshihiro Shimizu 890ddd
		PIXEL *pix = ras->pixels(j);
Toshihiro Shimizu 890ddd
		PIXEL *endPix = pix + ras->getLx();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (; pix < endPix; ++pix) {
Toshihiro Shimizu 890ddd
			if (pix->m == 0)
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			double m = pix->m;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			double r, g, b, h, s, v;
Toshihiro Shimizu 890ddd
			//depremult(pix);
Toshihiro Shimizu 890ddd
			r = pix->r / m;
Toshihiro Shimizu 890ddd
			g = pix->g / m;
Toshihiro Shimizu 890ddd
			b = pix->b / m;
Toshihiro Shimizu 890ddd
			OLDRGB2HSV(r, g, b, &h, &s, &v);
Toshihiro Shimizu 890ddd
			/*     int hsv[3];
Toshihiro Shimizu 890ddd
       rgb2hsv(hsv, *pix);
Toshihiro Shimizu 890ddd
       h =((double)hsv[0]/255.)*360.;
Toshihiro Shimizu 890ddd
       s =hsv[1]/255.;
Toshihiro Shimizu 890ddd
       v =hsv[2]/255.;*/
Toshihiro Shimizu 890ddd
			h += hue;
Toshihiro Shimizu 890ddd
			s += sat;
Toshihiro Shimizu 890ddd
			v += value;
Toshihiro Shimizu 890ddd
			h *= hueScale;
Toshihiro Shimizu 890ddd
			s *= satScale;
Toshihiro Shimizu 890ddd
			v *= valueScale;
Toshihiro Shimizu 890ddd
			/*     hsv[0]=tcrop((int)((h/360.)*255.),0,255);
Toshihiro Shimizu 890ddd
       hsv[1]=tcrop((int)s*255, 0,255);
Toshihiro Shimizu 890ddd
       hsv[2]=tcrop((int)v*255, 0,255);  
Toshihiro Shimizu 890ddd
       hsv2rgb(*pix,hsv);*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			OLDHSV2RGB(h, s, v, &r, &g, &b);
Toshihiro Shimizu 890ddd
			pix->r = (CHANNEL_TYPE)(r * m);
Toshihiro Shimizu 890ddd
			pix->g = (CHANNEL_TYPE)(g * m);
Toshihiro Shimizu 890ddd
			pix->b = (CHANNEL_TYPE)(b * m);
Toshihiro Shimizu 890ddd
			//premultiply(*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 HSVScaleFx::doCompute(TTile &tile, double frame, const TRenderSettings &ri)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_input.isConnected())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_input->compute(tile, frame, ri);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double hue = m_hue->getValue(frame);
Toshihiro Shimizu 890ddd
	double sat = m_sat->getValue(frame);
Toshihiro Shimizu 890ddd
	double value = m_value->getValue(frame);
Toshihiro Shimizu 890ddd
	double hueScale = m_hueScale->getValue(frame) / 100.0;
Toshihiro Shimizu 890ddd
	double satScale = m_satScale->getValue(frame) / 100.0;
Toshihiro Shimizu 890ddd
	double valueScale = m_valueScale->getValue(frame) / 100.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P raster32 = tile.getRaster();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (raster32)
Toshihiro Shimizu 890ddd
		doHSVScale<tpixel32, uchar="">(raster32, hue, sat, value, hueScale, satScale, valueScale);</tpixel32,>
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		TRaster64P raster64 = tile.getRaster();
Toshihiro Shimizu 890ddd
		if (raster64)
Toshihiro Shimizu 890ddd
			doHSVScale<tpixel64, ushort="">(raster64, hue, sat, value, hueScale, satScale, valueScale);</tpixel64,>
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			throw TException("HSVScale: unsupported Pixel Type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(HSVScaleFx, "hsvScaleFx")