Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
//#include "trastercm.h"
Toshihiro Shimizu 890ddd
#ifndef TNZCORE_LIGHT
Toshihiro Shimizu 890ddd
#include "timagecache.h"
Toshihiro Shimizu 890ddd
#include "ttile.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TString TRopException::getMessage() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return toWideString(message);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool isOpaque32(TRaster32P &ras)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	ras->lock();
Toshihiro Shimizu 890ddd
	UCHAR *m0 = &(ras->pixels()->m);
Toshihiro Shimizu 890ddd
	if (0 < m0[0] && m0[0] < 255)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int wrap4 = ras->getWrap() * 4;
Toshihiro Shimizu 890ddd
	int lx4 = ras->getLx() * 4;
Toshihiro Shimizu 890ddd
	const UCHAR cm = *m0;
Toshihiro Shimizu 890ddd
	int nrows = ras->getLy();
Toshihiro Shimizu 890ddd
	while (nrows-- > 0) {
Toshihiro Shimizu 890ddd
		UCHAR *m1 = m0 + lx4;
Toshihiro Shimizu 890ddd
		UCHAR *m = m0;
Toshihiro Shimizu 890ddd
		while (m < m1 && *m == cm)
Toshihiro Shimizu 890ddd
			m += 4;
Toshihiro Shimizu 890ddd
		if (m < m1)
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		m0 += wrap4;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	ras->unlock();
Toshihiro Shimizu 890ddd
	return (nrows <= 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//m_image->setOpaqueFlag(true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} //namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TRop::isOpaque(TRasterP ras)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRaster32P ras32 = ras;
Toshihiro Shimizu 890ddd
	if (ras32)
Toshihiro Shimizu 890ddd
		return isOpaque32(ras32);
Toshihiro Shimizu 890ddd
	else if (TRasterGR8P(ras))
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		throw TRopException("isOpaque: unsupported pixel type");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef TNZ_MACHINE_CHANNEL_ORDER_MRGB
Toshihiro Shimizu 890ddd
void TRop::swapRBChannels(const TRaster32P &r)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int lx = r->getLx();
Toshihiro Shimizu 890ddd
	int y = r->getLy();
Toshihiro Shimizu 890ddd
	r->lock();
Toshihiro Shimizu 890ddd
	while (--y >= 0) {
Toshihiro Shimizu 890ddd
		TPixel32 *pix = r->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *endPix = pix + lx;
Toshihiro Shimizu 890ddd
		while (pix < endPix) {
Toshihiro Shimizu 890ddd
			tswap(pix->r, pix->b);
Toshihiro Shimizu 890ddd
			++pix;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	r->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P TRop::copyAndSwapRBChannels(const TRaster32P &srcRaster)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRaster32P newRaster(srcRaster->getSize());
Toshihiro Shimizu 890ddd
	int lx = srcRaster->getLx();
Toshihiro Shimizu 890ddd
	int y = srcRaster->getLy();
Toshihiro Shimizu 890ddd
	srcRaster->lock();
Toshihiro Shimizu 890ddd
	newRaster->lock();
Toshihiro Shimizu 890ddd
	while (--y >= 0) {
Toshihiro Shimizu 890ddd
		TPixel32 *pix = srcRaster->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *newpix = newRaster->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *endPix = pix + lx;
Toshihiro Shimizu 890ddd
		while (pix < endPix) {
Toshihiro Shimizu 890ddd
			newpix->r = pix->b;
Toshihiro Shimizu 890ddd
			newpix->g = pix->g;
Toshihiro Shimizu 890ddd
			newpix->b = pix->r;
Toshihiro Shimizu 890ddd
			newpix->m = pix->m;
Toshihiro Shimizu 890ddd
			++pix;
Toshihiro Shimizu 890ddd
			++newpix;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	srcRaster->unlock();
Toshihiro Shimizu 890ddd
	newRaster->unlock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return newRaster;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::copy(TRasterP dst, const TRasterP &src)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(!((TRasterCM32P)src) || (TRasterCM32P)dst);
Toshihiro Shimizu 890ddd
	if (dst->getPixelSize() == src->getPixelSize())
Toshihiro Shimizu 890ddd
		dst->copy(src);
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		if (dst->getBounds() != src->getBounds()) {
Toshihiro Shimizu 890ddd
			TRect rect = dst->getBounds() * src->getBounds();
Toshihiro Shimizu 890ddd
			if (rect.isEmpty())
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
			TRop::convert(dst->extract(rect), src->extract(rect));
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			TRop::convert(dst, src);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
template <class q=""></class>
Toshihiro Shimizu 890ddd
class Gamma_Lut
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 3bfa54
	std::vector<q> m_table;</q>
Toshihiro Shimizu 890ddd
	Gamma_Lut(int insteps, int outsteps, double gamma)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		double inspace = (double)(insteps);
Toshihiro Shimizu 890ddd
		for (int i = 0; i <= insteps; i++)
Toshihiro Shimizu 890ddd
			m_table.push_back((Q)((outsteps) *
Toshihiro Shimizu 890ddd
									  (pow(i / inspace, 1.0 / gamma)) +
Toshihiro Shimizu 890ddd
								  0.5));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class class="" q="" t,=""></class>
Toshihiro Shimizu 890ddd
void doGammaCorrect(TRasterPT<t> raster, double gamma)</t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Gamma_Lut<q> lut(T::maxChannelValue, T::maxChannelValue, gamma);</q>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int j;
Toshihiro Shimizu 890ddd
	for (j = 0; j < raster->getLy(); j++) {
Toshihiro Shimizu 890ddd
		T *pix = raster->pixels(j);
Toshihiro Shimizu 890ddd
		T *endPix = pix + raster->getLx();
Toshihiro Shimizu 890ddd
		while (pix < endPix) {
Toshihiro Shimizu 890ddd
			pix->r = lut.m_table[pix->r];
Toshihiro Shimizu 890ddd
			pix->b = lut.m_table[pix->b];
Toshihiro Shimizu 890ddd
			pix->g = lut.m_table[pix->g];
Toshihiro Shimizu 890ddd
			/*if(pix->m != T::maxChannelValue)
Toshihiro Shimizu 890ddd
      {
Toshihiro Shimizu 890ddd
      pix->r= pix->r*pix->m/T::maxChannelValue;
Toshihiro Shimizu 890ddd
      pix->g= pix->g*pix->m/T::maxChannelValue; 
Toshihiro Shimizu 890ddd
      pix->b= pix->b*pix->m/T::maxChannelValue;
Toshihiro Shimizu 890ddd
	    }*/
Toshihiro Shimizu 890ddd
			*pix++;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
template <class class="" q="" t,=""></class>
Toshihiro Shimizu 890ddd
void doGammaCorrectRGBM(TRasterPT<t> raster, double gammar, double gammag, double gammab, double gammam)</t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Gamma_Lut<q> lutr(T::maxChannelValue, T::maxChannelValue, gammar);</q>
Toshihiro Shimizu 890ddd
	Gamma_Lut<q> lutg(T::maxChannelValue, T::maxChannelValue, gammag);</q>
Toshihiro Shimizu 890ddd
	Gamma_Lut<q> lutb(T::maxChannelValue, T::maxChannelValue, gammab);</q>
Toshihiro Shimizu 890ddd
	Gamma_Lut<q> lutm(T::maxChannelValue, T::maxChannelValue, gammam);</q>
Toshihiro Shimizu 890ddd
	int j;
Toshihiro Shimizu 890ddd
	for (j = 0; j < raster->getLy(); j++) {
Toshihiro Shimizu 890ddd
		T *pix = raster->pixels(j);
Toshihiro Shimizu 890ddd
		T *endPix = pix + raster->getLx();
Toshihiro Shimizu 890ddd
		while (pix < endPix) {
Toshihiro Shimizu 890ddd
			pix->r = lutr.m_table[pix->r];
Toshihiro Shimizu 890ddd
			pix->g = lutg.m_table[pix->g];
Toshihiro Shimizu 890ddd
			pix->b = lutb.m_table[pix->b];
Toshihiro Shimizu 890ddd
			pix->m = lutm.m_table[pix->m];
Toshihiro Shimizu 890ddd
			/*if(pix->m != T::maxChannelValue)
Toshihiro Shimizu 890ddd
      {
Toshihiro Shimizu 890ddd
      pix->r= pix->r*pix->m/T::maxChannelValue;
Toshihiro Shimizu 890ddd
      pix->g= pix->g*pix->m/T::maxChannelValue; 
Toshihiro Shimizu 890ddd
      pix->b= pix->b*pix->m/T::maxChannelValue;
Toshihiro Shimizu 890ddd
	    }*/
Toshihiro Shimizu 890ddd
			*pix++;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::gammaCorrect(TRasterP raster, double gamma)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (gamma <= 0)
Toshihiro Shimizu 890ddd
		gamma = 0.01;
Toshihiro Shimizu 890ddd
	raster->lock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if ((TRaster32P)raster)
Toshihiro Shimizu 890ddd
		doGammaCorrect<tpixel32, uchar="">(raster, gamma);</tpixel32,>
Toshihiro Shimizu 890ddd
	else if ((TRaster64P)raster)
Toshihiro Shimizu 890ddd
		doGammaCorrect<tpixel64, ushort="">(raster, gamma);</tpixel64,>
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		raster->unlock();
Toshihiro Shimizu 890ddd
		throw TRopException("isOpaque: unsupported pixel type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	raster->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::gammaCorrectRGBM(TRasterP raster, double gammar, double gammag,
Toshihiro Shimizu 890ddd
							double gammab, double gammam)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (gammar <= 0)
Toshihiro Shimizu 890ddd
		gammar = 0.01;
Toshihiro Shimizu 890ddd
	if (gammag <= 0)
Toshihiro Shimizu 890ddd
		gammag = 0.01;
Toshihiro Shimizu 890ddd
	if (gammab <= 0)
Toshihiro Shimizu 890ddd
		gammab = 0.01;
Toshihiro Shimizu 890ddd
	if (gammam <= 0)
Toshihiro Shimizu 890ddd
		gammam = 0.01;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	raster->lock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if ((TRaster32P)raster)
Toshihiro Shimizu 890ddd
		doGammaCorrectRGBM<tpixel32, uchar="">(raster, gammar, gammag, gammab, gammam);</tpixel32,>
Toshihiro Shimizu 890ddd
	else if ((TRaster64P)raster)
Toshihiro Shimizu 890ddd
		doGammaCorrectRGBM<tpixel64, ushort="">(raster, gammar, gammag, gammab, gammam);</tpixel64,>
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		raster->unlock();
Toshihiro Shimizu 890ddd
		throw TRopException("isOpaque: unsupported pixel type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	raster->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void doSetChannel(const TRasterPT<t> &rin, const TRasterPT<t> &rout, UCHAR channel, bool greytones)</t></t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int lx = rin->getLx();
Toshihiro Shimizu 890ddd
	int ly = rout->getLy();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int i, j;
Toshihiro Shimizu 890ddd
	for (i = 0; i < ly; i++) {
Toshihiro Shimizu 890ddd
		T *pixin = rin->pixels(i);
Toshihiro Shimizu 890ddd
		T *pixout = rout->pixels(i);
Toshihiro Shimizu 890ddd
		if (greytones || channel == TRop::MChan) {
Toshihiro Shimizu 890ddd
			switch (channel) {
Toshihiro Shimizu 890ddd
			case TRop::RChan:
Toshihiro Shimizu 890ddd
				for (j = 0; j < lx; j++, pixin++, pixout++)
Toshihiro Shimizu 890ddd
					pixout->r = pixout->g = pixout->b = pixout->m = pixin->r;
Toshihiro Shimizu 890ddd
				break;
Toshihiro Shimizu 890ddd
			case TRop::GChan:
Toshihiro Shimizu 890ddd
				for (j = 0; j < lx; j++, pixin++, pixout++)
Toshihiro Shimizu 890ddd
					pixout->r = pixout->g = pixout->b = pixout->m = pixin->g;
Toshihiro Shimizu 890ddd
				break;
Toshihiro Shimizu 890ddd
			case TRop::BChan:
Toshihiro Shimizu 890ddd
				for (j = 0; j < lx; j++, pixin++, pixout++)
Toshihiro Shimizu 890ddd
					pixout->r = pixout->g = pixout->b = pixout->m = pixin->b;
Toshihiro Shimizu 890ddd
				break;
Toshihiro Shimizu 890ddd
			case TRop::MChan:
Toshihiro Shimizu 890ddd
				for (j = 0; j < lx; j++, pixin++, pixout++)
Toshihiro Shimizu 890ddd
					pixout->r = pixout->g = pixout->b = pixout->m = pixin->m;
Toshihiro Shimizu 890ddd
				break;
Toshihiro Shimizu 890ddd
			default:
Toshihiro Shimizu 890ddd
				assert(false);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			for (j = 0; j < lx; j++, pixin++, pixout++) {
Toshihiro Shimizu 890ddd
				pixout->r = channel & TRop::RChan ? pixin->r : 0;
Toshihiro Shimizu 890ddd
				pixout->b = channel & TRop::BChan ? pixin->b : 0;
Toshihiro Shimizu 890ddd
				pixout->g = channel & TRop::GChan ? pixin->g : 0;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::setChannel(const TRasterP &rin, TRasterP rout, UCHAR chan, bool greytones)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(rin->getSize() == rout->getSize());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	rout->lock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if ((TRaster32P)rin && (TRaster32P)rout)
Toshihiro Shimizu 890ddd
		doSetChannel<tpixel32>(rin, rout, chan, greytones);</tpixel32>
Toshihiro Shimizu 890ddd
	else if ((TRaster64P)rin && (TRaster64P)rout)
Toshihiro Shimizu 890ddd
		doSetChannel<tpixel64>(rin, rout, chan, greytones);</tpixel64>
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		rout->unlock();
Toshihiro Shimizu 890ddd
		throw TRopException("setChannel: unsupported pixel type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	rout->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRasterP TRop::shrink(TRasterP rin, int shrink)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int pixelSize = rin->getPixelSize();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int lx = (rin->getLx() - 1) / shrink + 1;
Toshihiro Shimizu 890ddd
	int ly = (rin->getLy() - 1) / shrink + 1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterP rout;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if ((TRaster32P)rin)
Toshihiro Shimizu 890ddd
		rout = TRaster32P(lx, ly);
Toshihiro Shimizu 890ddd
	else if ((TRaster64P)rin)
Toshihiro Shimizu 890ddd
		rout = TRaster64P(lx, ly);
Toshihiro Shimizu 890ddd
	if ((TRasterCM32P)rin)
Toshihiro Shimizu 890ddd
		rout = TRasterCM32P(lx, ly);
Toshihiro Shimizu 890ddd
	if ((TRasterGR8P)rin)
Toshihiro Shimizu 890ddd
		rout = TRasterGR8P(lx, ly);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int i, j;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (i = 0; i < ly; i++) {
Toshihiro Shimizu 890ddd
		UCHAR *bufin = (UCHAR *)rin->getRawData() + (i * shrink) * rin->getWrap() * pixelSize;
Toshihiro Shimizu 890ddd
		UCHAR *bufout = (UCHAR *)rout->getRawData() + i * rout->getWrap() * pixelSize;
Toshihiro Shimizu 890ddd
		for (j = 0; j < lx; j++) {
Toshihiro Shimizu 890ddd
			memcpy(bufout, bufin, pixelSize);
Toshihiro Shimizu 890ddd
			bufin += shrink * pixelSize;
Toshihiro Shimizu 890ddd
			bufout += pixelSize;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return rout;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void doMakeStereoRaster(const TRasterPT<t> &rleft, const TRasterPT<t> &rright)</t></t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int lx = rleft->getLx();
Toshihiro Shimizu 890ddd
	int ly = rright->getLy();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int i = 0; i < ly; i++) {
Toshihiro Shimizu 890ddd
		T *pixl = rleft->pixels(i);
Toshihiro Shimizu 890ddd
		T *pixr = rright->pixels(i);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (int j = 0; j < lx; j++, pixl++, pixr++) {
Toshihiro Shimizu 890ddd
			pixl->g = pixr->g;
Toshihiro Shimizu 890ddd
			pixl->b = pixr->b;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::makeStereoRaster(const TRasterP &left, const TRasterP &right)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(left->getSize() == right->getSize());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	left->lock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if ((TRaster32P)left && (TRaster32P)right)
Toshihiro Shimizu 890ddd
		doMakeStereoRaster<tpixel32>(left, right);</tpixel32>
Toshihiro Shimizu 890ddd
	else if ((TRaster64P)left && (TRaster64P)right)
Toshihiro Shimizu 890ddd
		doMakeStereoRaster<tpixel64>(left, right);</tpixel64>
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		left->unlock();
Toshihiro Shimizu 890ddd
		throw TRopException("setChannel: unsupported pixel type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	left->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
#ifndef TNZCORE_LIGHT
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TTile::addInCache(const TRasterP &raster)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!raster) {
Toshihiro Shimizu 890ddd
		m_rasterId = "";
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TRasterP rin;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_rasterId = TImageCache::instance()->getUniqueId();
Toshihiro Shimizu 890ddd
	if (raster->getParent()) {
Toshihiro Shimizu 890ddd
		rin = raster->getParent();
Toshihiro Shimizu 890ddd
		unsigned long offs = (raster->getRawData() - raster->getParent()->getRawData()) / raster->getPixelSize();
Toshihiro Shimizu 890ddd
		m_subRect = TRect(TPoint(offs % raster->getWrap(), offs / raster->getWrap()), raster->getSize());
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		m_subRect = raster->getBounds();
Toshihiro Shimizu 890ddd
		rin = raster;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if ((TRasterCM32P)rin)
Toshihiro Shimizu 890ddd
		TImageCache::instance()->add(m_rasterId, TToonzImageP(rin, rin->getBounds()));
Toshihiro Shimizu 890ddd
	else if ((TRaster32P)rin || (TRaster64P)rin)
Toshihiro Shimizu 890ddd
		TImageCache::instance()->add(m_rasterId, TRasterImageP(rin));
Toshihiro Shimizu 890ddd
	else if ((TRasterGR8P)rin || (TRasterGR16P)rin)
Toshihiro Shimizu 890ddd
		TImageCache::instance()->add(m_rasterId, TRasterImageP(rin));
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		assert(false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTile::TTile(const TRasterP &raster)
Toshihiro Shimizu 890ddd
	: m_pos(), m_subRect()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	addInCache(raster);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTile::TTile(const TRasterP &raster, TPointD pos)
Toshihiro Shimizu 890ddd
	: m_pos(pos), m_subRect()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	addInCache(raster);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TTile::setRaster(const TRasterP &raster)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_rasterId != "")
Toshihiro Shimizu 890ddd
		TImageCache::instance()->remove(m_rasterId);
Toshihiro Shimizu 890ddd
	m_subRect = TRect();
Toshihiro Shimizu 890ddd
	addInCache(raster);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTile::~TTile()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_rasterId.empty())
Toshihiro Shimizu 890ddd
		TImageCache::instance()->remove(m_rasterId);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif