Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tpixelgr.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
template <typename pixtype=""></typename>
Toshihiro Shimizu 890ddd
inline void do_invert(TRasterPT<pixtype> ras)</pixtype>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int wrap = ras->getWrap();
Toshihiro Shimizu 890ddd
	int lx = ras->getLx();
Toshihiro Shimizu 890ddd
	PixType *rowIn = ras->pixels();
Toshihiro Shimizu 890ddd
	PixType *lastPix = rowIn + wrap * ras->getLy();
Toshihiro Shimizu 890ddd
	PixType *pixIn = 0;
Toshihiro Shimizu 890ddd
	PixType *endPix = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	while (pixIn < lastPix) {
Toshihiro Shimizu 890ddd
		pixIn = rowIn;
Toshihiro Shimizu 890ddd
		endPix = pixIn + lx;
Toshihiro Shimizu 890ddd
		while (pixIn < endPix) {
Toshihiro Shimizu 890ddd
			pixIn->r = pixIn->m - pixIn->r;
Toshihiro Shimizu 890ddd
			pixIn->g = pixIn->m - pixIn->g;
Toshihiro Shimizu 890ddd
			pixIn->b = pixIn->m - pixIn->b; /*pixIn->m = pixIn->m;*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			++pixIn;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		rowIn += wrap;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixtype=""></typename>
Toshihiro Shimizu 890ddd
inline void do_invert(TRasterPT<pixtype> ras, bool invRed, bool invGreen, bool invBlue, bool invMatte)</pixtype>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int wrap = ras->getWrap();
Toshihiro Shimizu 890ddd
	int lx = ras->getLx();
Toshihiro Shimizu 890ddd
	PixType *rowIn = ras->pixels();
Toshihiro Shimizu 890ddd
	PixType *lastPix = rowIn + wrap * ras->getLy();
Toshihiro Shimizu 890ddd
	PixType *pixIn = 0;
Toshihiro Shimizu 890ddd
	PixType *endPix = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	while (pixIn < lastPix) {
Toshihiro Shimizu 890ddd
		pixIn = rowIn;
Toshihiro Shimizu 890ddd
		endPix = pixIn + lx;
Toshihiro Shimizu 890ddd
		while (pixIn < endPix) {
Toshihiro Shimizu 890ddd
			if (invRed)
Toshihiro Shimizu 890ddd
				pixIn->r = pixIn->m - pixIn->r;
Toshihiro Shimizu 890ddd
			if (invGreen)
Toshihiro Shimizu 890ddd
				pixIn->g = pixIn->m - pixIn->g;
Toshihiro Shimizu 890ddd
			if (invBlue)
Toshihiro Shimizu 890ddd
				pixIn->b = pixIn->m - pixIn->b;
Toshihiro Shimizu 890ddd
			if (invMatte)
Toshihiro Shimizu 890ddd
				pixIn->m = ~pixIn->m;
Toshihiro Shimizu 890ddd
			++pixIn;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		rowIn += wrap;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
inline void do_invert<tpixelgr8>(TRasterPT<tpixelgr8> ras)</tpixelgr8></tpixelgr8>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int wrap = ras->getWrap();
Toshihiro Shimizu 890ddd
	int lx = ras->getLx();
Toshihiro Shimizu 890ddd
	TPixelGR8 *rowIn = ras->pixels();
Toshihiro Shimizu 890ddd
	TPixelGR8 *lastPix = rowIn + wrap * ras->getLy();
Toshihiro Shimizu 890ddd
	TPixelGR8 *pixIn = 0;
Toshihiro Shimizu 890ddd
	TPixelGR8 *endPix = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	while (pixIn < lastPix) {
Toshihiro Shimizu 890ddd
		pixIn = rowIn;
Toshihiro Shimizu 890ddd
		endPix = pixIn + lx;
Toshihiro Shimizu 890ddd
		while (pixIn < endPix) {
Toshihiro Shimizu 890ddd
			pixIn->value = 255 - pixIn->value;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			++pixIn;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		rowIn += wrap;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::invert(TRasterP ras, bool invRed, bool invGreen, bool invBlue, bool invMatte)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!invRed && !invGreen && !invBlue)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	bool flag = invRed && invGreen && invBlue && !invMatte;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P ras32 = ras;
Toshihiro Shimizu 890ddd
	ras->lock();
Toshihiro Shimizu 890ddd
	if (ras32)
Toshihiro Shimizu 890ddd
		if (flag)
Toshihiro Shimizu 890ddd
			do_invert<tpixel32>(ras32);</tpixel32>
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			do_invert<tpixel32>(ras, invRed, invGreen, invBlue, invMatte);</tpixel32>
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		TRaster64P ras64 = ras;
Toshihiro Shimizu 890ddd
		if (ras64)
Toshihiro Shimizu 890ddd
			if (flag)
Toshihiro Shimizu 890ddd
				do_invert<tpixel64>(ras64);</tpixel64>
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				do_invert<tpixel64>(ras64, invRed, invGreen, invBlue, invMatte);</tpixel64>
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
			TRasterGR8P ras8 = ras;
Toshihiro Shimizu 890ddd
			if (ras8)
Toshihiro Shimizu 890ddd
				do_invert<tpixelgr8>(ras8);</tpixelgr8>
Toshihiro Shimizu 890ddd
			else {
Toshihiro Shimizu 890ddd
				ras->unlock();
Toshihiro Shimizu 890ddd
				throw TRopException("unsupported pixel type");
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------