Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void ropSharpen(const TRasterPT<t> &rin, TRasterPT<t> &rout, int sharpen_max_corr)</t></t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	T *bufin, *east, *northeast, *southeast;
Toshihiro Shimizu 890ddd
	T *bufout, *pixout;
Toshihiro Shimizu 890ddd
	int lx, ly, wrapin, wrapout, x, y, count;
Toshihiro Shimizu 890ddd
	int cntr_r, east_r, col_west_r, col_cntr_r, col_east_r;
Toshihiro Shimizu 890ddd
	int cntr_g, east_g, col_west_g, col_cntr_g, col_east_g;
Toshihiro Shimizu 890ddd
	int cntr_b, east_b, col_west_b, col_cntr_b, col_east_b;
Toshihiro Shimizu 890ddd
	int cntr_m, east_m, col_west_m, col_cntr_m, col_east_m;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int lapl, out;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define SET_PIXOUT(X)                                                                     \
Toshihiro Shimizu 890ddd
	{                                                                                     \
Toshihiro Shimizu 890ddd
		lapl = (cntr_##X << 3) + cntr_##X - (col_west_##X + col_cntr_##X + col_east_##X); \
Toshihiro Shimizu 890ddd
		if (lapl < 0) {                                                                   \
Toshihiro Shimizu 890ddd
			out = cntr_##X - ((256 * 4 - lapl * sharpen_max_corr) >> (8 + 3));            \
Toshihiro Shimizu 890ddd
			pixout->X = (out <= 0) ? 0 : out;                                             \
Toshihiro Shimizu 890ddd
		} else {                                                                          \
Toshihiro Shimizu 890ddd
			out = cntr_##X + ((256 * 4 + lapl * sharpen_max_corr) >> (8 + 3));            \
Toshihiro Shimizu 890ddd
			pixout->X = (out >= maxChanVal) ? maxChanVal : out;                           \
Toshihiro Shimizu 890ddd
		}                                                                                 \
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	rin->lock();
Toshihiro Shimizu 890ddd
	rout->lock();
Toshihiro Shimizu 890ddd
	bufin = (T *)rin->getRawData();
Toshihiro Shimizu 890ddd
	bufout = (T *)rout->getRawData();
Toshihiro Shimizu 890ddd
	lx = tmin(rin->getLx(), rout->getLx());
Toshihiro Shimizu 890ddd
	ly = tmin(rin->getLy(), rout->getLy());
Toshihiro Shimizu 890ddd
	wrapin = rin->getWrap();
Toshihiro Shimizu 890ddd
	wrapout = rout->getWrap();
Toshihiro Shimizu 890ddd
	int maxChanVal = T::maxChannelValue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (lx <= 1 || ly <= 1) {
Toshihiro Shimizu 890ddd
		for (y = 0; y < ly; y++)
Toshihiro Shimizu 890ddd
			for (x = 0; x < lx; x++)
Toshihiro Shimizu 890ddd
				bufout[x + y * wrapout] = bufin[x + y * wrapin];
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	east = bufin;
Toshihiro Shimizu 890ddd
	northeast = east + wrapin;
Toshihiro Shimizu 890ddd
	east_r = east->r;
Toshihiro Shimizu 890ddd
	east_g = east->g;
Toshihiro Shimizu 890ddd
	east_b = east->b;
Toshihiro Shimizu 890ddd
	east_m = east->m;
Toshihiro Shimizu 890ddd
	col_east_r = 2 * east_r + northeast->r;
Toshihiro Shimizu 890ddd
	col_east_g = 2 * east_g + northeast->g;
Toshihiro Shimizu 890ddd
	col_east_b = 2 * east_b + northeast->b;
Toshihiro Shimizu 890ddd
	col_east_m = 2 * east_m + northeast->m;
Toshihiro Shimizu 890ddd
	col_cntr_r = col_east_r;
Toshihiro Shimizu 890ddd
	col_cntr_g = col_east_g;
Toshihiro Shimizu 890ddd
	col_cntr_b = col_east_b;
Toshihiro Shimizu 890ddd
	col_cntr_m = col_east_m;
Toshihiro Shimizu 890ddd
	east++;
Toshihiro Shimizu 890ddd
	northeast++;
Toshihiro Shimizu 890ddd
	pixout = bufout;
Toshihiro Shimizu 890ddd
	for (count = lx - 1;
Toshihiro Shimizu 890ddd
		 count > 0;
Toshihiro Shimizu 890ddd
		 count--, east++, northeast++, pixout++) {
Toshihiro Shimizu 890ddd
		cntr_r = east_r;
Toshihiro Shimizu 890ddd
		east_r = east->r;
Toshihiro Shimizu 890ddd
		col_west_r = col_cntr_r;
Toshihiro Shimizu 890ddd
		col_cntr_r = col_east_r;
Toshihiro Shimizu 890ddd
		col_east_r = 2 * east_r + northeast->r;
Toshihiro Shimizu 890ddd
		SET_PIXOUT(r)
Toshihiro Shimizu 890ddd
		cntr_g = east_g;
Toshihiro Shimizu 890ddd
		east_g = east->g;
Toshihiro Shimizu 890ddd
		col_west_g = col_cntr_g;
Toshihiro Shimizu 890ddd
		col_cntr_g = col_east_g;
Toshihiro Shimizu 890ddd
		col_east_g = 2 * east_g + northeast->g;
Toshihiro Shimizu 890ddd
		SET_PIXOUT(g)
Toshihiro Shimizu 890ddd
		cntr_b = east_b;
Toshihiro Shimizu 890ddd
		east_b = east->b;
Toshihiro Shimizu 890ddd
		col_west_b = col_cntr_b;
Toshihiro Shimizu 890ddd
		col_cntr_b = col_east_b;
Toshihiro Shimizu 890ddd
		col_east_b = 2 * east_b + northeast->b;
Toshihiro Shimizu 890ddd
		SET_PIXOUT(b)
Toshihiro Shimizu 890ddd
		cntr_m = east_m;
Toshihiro Shimizu 890ddd
		east_m = east->m;
Toshihiro Shimizu 890ddd
		col_west_m = col_cntr_m;
Toshihiro Shimizu 890ddd
		col_cntr_m = col_east_m;
Toshihiro Shimizu 890ddd
		col_east_m = 2 * east_m + northeast->m;
Toshihiro Shimizu 890ddd
		SET_PIXOUT(m)
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	cntr_r = east_r;
Toshihiro Shimizu 890ddd
	col_west_r = col_cntr_r;
Toshihiro Shimizu 890ddd
	col_cntr_r = col_east_r;
Toshihiro Shimizu 890ddd
	SET_PIXOUT(r)
Toshihiro Shimizu 890ddd
	cntr_g = east_g;
Toshihiro Shimizu 890ddd
	col_west_g = col_cntr_g;
Toshihiro Shimizu 890ddd
	col_cntr_g = col_east_g;
Toshihiro Shimizu 890ddd
	SET_PIXOUT(g)
Toshihiro Shimizu 890ddd
	cntr_b = east_b;
Toshihiro Shimizu 890ddd
	col_west_b = col_cntr_b;
Toshihiro Shimizu 890ddd
	col_cntr_b = col_east_b;
Toshihiro Shimizu 890ddd
	SET_PIXOUT(b)
Toshihiro Shimizu 890ddd
	cntr_m = east_m;
Toshihiro Shimizu 890ddd
	col_west_m = col_cntr_m;
Toshihiro Shimizu 890ddd
	col_cntr_m = col_east_m;
Toshihiro Shimizu 890ddd
	SET_PIXOUT(m)
Toshihiro Shimizu 890ddd
	for (y = 1; y < ly - 1; y++) {
Toshihiro Shimizu 890ddd
		east = bufin + y * wrapin;
Toshihiro Shimizu 890ddd
		northeast = east + wrapin;
Toshihiro Shimizu 890ddd
		southeast = east - wrapin;
Toshihiro Shimizu 890ddd
		east_r = east->r;
Toshihiro Shimizu 890ddd
		east_g = east->g;
Toshihiro Shimizu 890ddd
		east_b = east->b;
Toshihiro Shimizu 890ddd
		east_m = east->m;
Toshihiro Shimizu 890ddd
		col_east_r = east_r + northeast->r + southeast->r;
Toshihiro Shimizu 890ddd
		col_east_g = east_g + northeast->g + southeast->g;
Toshihiro Shimizu 890ddd
		col_east_b = east_b + northeast->b + southeast->b;
Toshihiro Shimizu 890ddd
		col_east_m = east_m + northeast->m + southeast->m;
Toshihiro Shimizu 890ddd
		col_cntr_r = col_east_r;
Toshihiro Shimizu 890ddd
		col_cntr_g = col_east_g;
Toshihiro Shimizu 890ddd
		col_cntr_b = col_east_b;
Toshihiro Shimizu 890ddd
		col_cntr_m = col_east_m;
Toshihiro Shimizu 890ddd
		east++;
Toshihiro Shimizu 890ddd
		northeast++;
Toshihiro Shimizu 890ddd
		southeast++;
Toshihiro Shimizu 890ddd
		pixout = bufout + y * wrapout;
Toshihiro Shimizu 890ddd
		for (count = lx - 1;
Toshihiro Shimizu 890ddd
			 count > 0;
Toshihiro Shimizu 890ddd
			 count--, east++, northeast++, southeast++, pixout++) {
Toshihiro Shimizu 890ddd
			cntr_r = east_r;
Toshihiro Shimizu 890ddd
			east_r = east->r;
Toshihiro Shimizu 890ddd
			col_west_r = col_cntr_r;
Toshihiro Shimizu 890ddd
			col_cntr_r = col_east_r;
Toshihiro Shimizu 890ddd
			col_east_r = east_r + northeast->r + southeast->r;
Toshihiro Shimizu 890ddd
			SET_PIXOUT(r)
Toshihiro Shimizu 890ddd
			cntr_g = east_g;
Toshihiro Shimizu 890ddd
			east_g = east->g;
Toshihiro Shimizu 890ddd
			col_west_g = col_cntr_g;
Toshihiro Shimizu 890ddd
			col_cntr_g = col_east_g;
Toshihiro Shimizu 890ddd
			col_east_g = east_g + northeast->g + southeast->g;
Toshihiro Shimizu 890ddd
			SET_PIXOUT(g)
Toshihiro Shimizu 890ddd
			cntr_b = east_b;
Toshihiro Shimizu 890ddd
			east_b = east->b;
Toshihiro Shimizu 890ddd
			col_west_b = col_cntr_b;
Toshihiro Shimizu 890ddd
			col_cntr_b = col_east_b;
Toshihiro Shimizu 890ddd
			col_east_b = east_b + northeast->b + southeast->b;
Toshihiro Shimizu 890ddd
			SET_PIXOUT(b)
Toshihiro Shimizu 890ddd
			cntr_m = east_m;
Toshihiro Shimizu 890ddd
			east_m = east->m;
Toshihiro Shimizu 890ddd
			col_west_m = col_cntr_m;
Toshihiro Shimizu 890ddd
			col_cntr_m = col_east_m;
Toshihiro Shimizu 890ddd
			col_east_m = east_m + northeast->m + southeast->m;
Toshihiro Shimizu 890ddd
			SET_PIXOUT(m)
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		cntr_r = east_r;
Toshihiro Shimizu 890ddd
		col_west_r = col_cntr_r;
Toshihiro Shimizu 890ddd
		col_cntr_r = col_east_r;
Toshihiro Shimizu 890ddd
		SET_PIXOUT(r)
Toshihiro Shimizu 890ddd
		cntr_g = east_g;
Toshihiro Shimizu 890ddd
		col_west_g = col_cntr_g;
Toshihiro Shimizu 890ddd
		col_cntr_g = col_east_g;
Toshihiro Shimizu 890ddd
		SET_PIXOUT(g)
Toshihiro Shimizu 890ddd
		cntr_b = east_b;
Toshihiro Shimizu 890ddd
		col_west_b = col_cntr_b;
Toshihiro Shimizu 890ddd
		col_cntr_b = col_east_b;
Toshihiro Shimizu 890ddd
		SET_PIXOUT(b)
Toshihiro Shimizu 890ddd
		cntr_m = east_m;
Toshihiro Shimizu 890ddd
		col_west_m = col_cntr_m;
Toshihiro Shimizu 890ddd
		col_cntr_m = col_east_m;
Toshihiro Shimizu 890ddd
		SET_PIXOUT(m)
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	east = bufin + y * wrapin;
Toshihiro Shimizu 890ddd
	southeast = east - wrapin;
Toshihiro Shimizu 890ddd
	east_r = east->r;
Toshihiro Shimizu 890ddd
	east_g = east->g;
Toshihiro Shimizu 890ddd
	east_b = east->b;
Toshihiro Shimizu 890ddd
	east_m = east->m;
Toshihiro Shimizu 890ddd
	col_east_r = 2 * east_r + southeast->r;
Toshihiro Shimizu 890ddd
	col_east_g = 2 * east_g + southeast->g;
Toshihiro Shimizu 890ddd
	col_east_b = 2 * east_b + southeast->b;
Toshihiro Shimizu 890ddd
	col_east_m = 2 * east_m + southeast->m;
Toshihiro Shimizu 890ddd
	col_cntr_r = col_east_r;
Toshihiro Shimizu 890ddd
	col_cntr_g = col_east_g;
Toshihiro Shimizu 890ddd
	col_cntr_b = col_east_b;
Toshihiro Shimizu 890ddd
	col_cntr_m = col_east_m;
Toshihiro Shimizu 890ddd
	east++;
Toshihiro Shimizu 890ddd
	southeast++;
Toshihiro Shimizu 890ddd
	pixout = bufout + y * wrapout;
Toshihiro Shimizu 890ddd
	for (count = lx - 1;
Toshihiro Shimizu 890ddd
		 count > 0;
Toshihiro Shimizu 890ddd
		 count--, east++, southeast++, pixout++) {
Toshihiro Shimizu 890ddd
		cntr_r = east_r;
Toshihiro Shimizu 890ddd
		east_r = east->r;
Toshihiro Shimizu 890ddd
		col_west_r = col_cntr_r;
Toshihiro Shimizu 890ddd
		col_cntr_r = col_east_r;
Toshihiro Shimizu 890ddd
		col_east_r = 2 * east_r + southeast->r;
Toshihiro Shimizu 890ddd
		SET_PIXOUT(r)
Toshihiro Shimizu 890ddd
		cntr_g = east_g;
Toshihiro Shimizu 890ddd
		east_g = east->g;
Toshihiro Shimizu 890ddd
		col_west_g = col_cntr_g;
Toshihiro Shimizu 890ddd
		col_cntr_g = col_east_g;
Toshihiro Shimizu 890ddd
		col_east_g = 2 * east_g + southeast->g;
Toshihiro Shimizu 890ddd
		SET_PIXOUT(g)
Toshihiro Shimizu 890ddd
		cntr_b = east_b;
Toshihiro Shimizu 890ddd
		east_b = east->b;
Toshihiro Shimizu 890ddd
		col_west_b = col_cntr_b;
Toshihiro Shimizu 890ddd
		col_cntr_b = col_east_b;
Toshihiro Shimizu 890ddd
		col_east_b = 2 * east_b + southeast->b;
Toshihiro Shimizu 890ddd
		SET_PIXOUT(b)
Toshihiro Shimizu 890ddd
		cntr_m = east_m;
Toshihiro Shimizu 890ddd
		east_m = east->m;
Toshihiro Shimizu 890ddd
		col_west_m = col_cntr_m;
Toshihiro Shimizu 890ddd
		col_cntr_m = col_east_m;
Toshihiro Shimizu 890ddd
		col_east_m = 2 * east_m + southeast->m;
Toshihiro Shimizu 890ddd
		SET_PIXOUT(m)
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	cntr_r = east_r;
Toshihiro Shimizu 890ddd
	col_west_r = col_cntr_r;
Toshihiro Shimizu 890ddd
	col_cntr_r = col_east_r;
Toshihiro Shimizu 890ddd
	SET_PIXOUT(r)
Toshihiro Shimizu 890ddd
	cntr_g = east_g;
Toshihiro Shimizu 890ddd
	col_west_g = col_cntr_g;
Toshihiro Shimizu 890ddd
	col_cntr_g = col_east_g;
Toshihiro Shimizu 890ddd
	SET_PIXOUT(g)
Toshihiro Shimizu 890ddd
	cntr_b = east_b;
Toshihiro Shimizu 890ddd
	col_west_b = col_cntr_b;
Toshihiro Shimizu 890ddd
	col_cntr_b = col_east_b;
Toshihiro Shimizu 890ddd
	SET_PIXOUT(b)
Toshihiro Shimizu 890ddd
	cntr_m = east_m;
Toshihiro Shimizu 890ddd
	col_west_m = col_cntr_m;
Toshihiro Shimizu 890ddd
	col_cntr_m = col_east_m;
Toshihiro Shimizu 890ddd
	SET_PIXOUT(m)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	rin->unlock();
Toshihiro Shimizu 890ddd
	rout->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class SharpenFx : public TStandardRasterFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(SharpenFx)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterFxPort m_input;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_intensity;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	SharpenFx()
Toshihiro Shimizu 890ddd
		: m_intensity(50)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		bindParam(this, "intensity", m_intensity);
Toshihiro Shimizu 890ddd
		addInputPort("Source", m_input);
Toshihiro Shimizu 890ddd
		m_intensity->setValueRange(0.0, 999999, 1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~SharpenFx(){};
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
			bool ret = m_input->doGetBBox(frame, bBox, info);
Toshihiro Shimizu 890ddd
			return ret;
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
Toshihiro Shimizu 890ddd
	bool canHandle(const TRenderSettings &info, double frame) { return true; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SharpenFx::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
	int intensity = troundp(m_intensity->getValue(frame));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterP srcRas = tile.getRaster()->create(tile.getRaster()->getLx(), tile.getRaster()->getLy());
Toshihiro Shimizu 890ddd
	//TRaster32P srcRas(tile.getRaster()->getLx() + border*2, tile.getRaster()->getLy() + border*2);
Toshihiro Shimizu 890ddd
	TTile srcTile(srcRas, tile.m_pos);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_input->compute(srcTile, frame, ri);
Toshihiro Shimizu 890ddd
	TRaster32P raster32 = tile.getRaster();
Toshihiro Shimizu 890ddd
	TRaster32P srcraster32 = srcTile.getRaster();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (raster32)
Toshihiro Shimizu 890ddd
		ropSharpen<tpixel32>(srcraster32, raster32, intensity);</tpixel32>
Toshihiro Shimizu 890ddd
	//doEmboss<tpixel32, tpixelgr8,="" uchar="">(raster32, srcraster32, azimuth, elevation, intensity, border);</tpixel32,>
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		TRaster64P raster64 = tile.getRaster();
Toshihiro Shimizu 890ddd
		TRaster64P srcraster64 = srcTile.getRaster();
Toshihiro Shimizu 890ddd
		if (raster64)
Toshihiro Shimizu 890ddd
			ropSharpen<tpixel64>(srcraster64, raster64, intensity);</tpixel64>
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			throw TException("sharpen: unsupported Pixel Type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(SharpenFx, "sharpenFx");