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
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
TPixel32 unmultiply(const TPixel32 &pix)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!pix.m)
Toshihiro Shimizu 890ddd
		return pix;
Toshihiro Shimizu 890ddd
	double depremult = 255.0 / pix.m;
Toshihiro Shimizu 890ddd
	return TPixel32((UCHAR)(pix.r * depremult),
Toshihiro Shimizu 890ddd
					(UCHAR)(pix.g * depremult),
Toshihiro Shimizu 890ddd
					(UCHAR)(pix.b * depremult),
Toshihiro Shimizu 890ddd
					pix.m);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class UnmultiplyFx : public TStandardRasterFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(UnmultiplyFx)
Toshihiro Shimizu 890ddd
	TRasterFxPort m_input;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	UnmultiplyFx() { addInputPort("Source", m_input); }
Toshihiro Shimizu 890ddd
	~UnmultiplyFx(){};
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
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void UnmultiplyFx::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
Toshihiro Shimizu 890ddd
	m_input->compute(tile, frame, ri);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P raster32 = tile.getRaster();
Toshihiro Shimizu 890ddd
	assert(raster32); // per ora gestisco solo i Raster32
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int j;
Toshihiro Shimizu 890ddd
	raster32->lock();
Toshihiro Shimizu 890ddd
	for (j = 0; j < raster32->getLy(); j++) {
Toshihiro Shimizu 890ddd
		TPixel32 *pix = raster32->pixels(j);
Toshihiro Shimizu 890ddd
		TPixel32 *endPix = pix + raster32->getLx();
Toshihiro Shimizu 890ddd
		while (pix < endPix) {
Toshihiro Shimizu 890ddd
			if (pix->m) {
Toshihiro Shimizu 890ddd
				double depremult = 255.0 / pix->m;
Toshihiro Shimizu 890ddd
				pix->r = (UCHAR)(pix->r * depremult);
Toshihiro Shimizu 890ddd
				pix->g = (UCHAR)(pix->g * depremult);
Toshihiro Shimizu 890ddd
				pix->b = (UCHAR)(pix->b * depremult);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//*pix=unmultiply(*pix);
Toshihiro Shimizu 890ddd
			pix++;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	raster32->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(UnmultiplyFx, "unmultiplyFx");