Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tpixelgr.h"
Toshihiro Shimizu 890ddd
#include "trandom.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************
Toshihiro Shimizu 890ddd
//    Conversion functions
Toshihiro Shimizu 890ddd
//******************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_convert(const TRaster64P &dst, const TRaster32P &src)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(dst->getSize() == src->getSize());
Toshihiro Shimizu 890ddd
	int lx = src->getLx();
Toshihiro Shimizu 890ddd
	for (int y = 0; y < src->getLy(); y++) {
Toshihiro Shimizu 890ddd
		TPixel64 *outPix = dst->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *inPix = src->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *inEndPix = inPix + lx;
Toshihiro Shimizu 890ddd
		for (; inPix < inEndPix; ++outPix, ++inPix) {
Toshihiro Shimizu 890ddd
			outPix->r = ushortFromByte(inPix->r);
Toshihiro Shimizu 890ddd
			outPix->g = ushortFromByte(inPix->g);
Toshihiro Shimizu 890ddd
			outPix->b = ushortFromByte(inPix->b);
Toshihiro Shimizu 890ddd
			outPix->m = ushortFromByte(inPix->m);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_convert(const TRasterGR8P &dst, const TRaster32P &src)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(dst->getSize() == src->getSize());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int lx = src->getLx();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int y = 0; y < src->getLy(); ++y) {
Toshihiro Shimizu 890ddd
		TPixelGR8 *outPix = dst->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *inPix = src->pixels(y), *inEndPix = inPix + lx;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (; inPix < inEndPix; ++outPix, ++inPix)
Toshihiro Shimizu 890ddd
			*outPix = TPixelGR8::from(overPix(TPixel32::White, *inPix));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_convert(const TRasterGR16P &dst, const TRaster32P &src)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(dst->getSize() == src->getSize());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int lx = src->getLx();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int y = 0; y < src->getLy(); ++y) {
Toshihiro Shimizu 890ddd
		TPixelGR16 *outPix = dst->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *inPix = src->pixels(y), *inEndPix = inPix + lx;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (; inPix < inEndPix; ++outPix, ++inPix)
Toshihiro Shimizu 890ddd
			outPix->value = 257 * (TPixelGR8::from(overPix(TPixel32::White, *inPix))).value;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_convert(const TRasterGR16P &dst, const TRaster64P &src)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(dst->getSize() == src->getSize());
Toshihiro Shimizu 890ddd
	int lx = src->getLx();
Toshihiro Shimizu 890ddd
	for (int y = 0; y < src->getLy(); y++) {
Toshihiro Shimizu 890ddd
		TPixelGR16 *outPix = dst->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel64 *inPix = src->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel64 *inEndPix = inPix + lx;
Toshihiro Shimizu 890ddd
		while (inPix < inEndPix) {
Toshihiro Shimizu 890ddd
			outPix->value = (inPix->r + 2 * inPix->g + inPix->b) >> 2;
Toshihiro Shimizu 890ddd
			outPix++;
Toshihiro Shimizu 890ddd
			inPix++;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_convert(const TRaster32P &dst, const TRasterGR8P &src)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(dst->getSize() == src->getSize());
Toshihiro Shimizu 890ddd
	int lx = src->getLx();
Toshihiro Shimizu 890ddd
	for (int y = 0; y < src->getLy(); y++) {
Toshihiro Shimizu 890ddd
		TPixel32 *outPix = dst->pixels(y);
Toshihiro Shimizu 890ddd
		TPixelGR8 *inPix = src->pixels(y);
Toshihiro Shimizu 890ddd
		TPixelGR8 *inEndPix = inPix + lx;
Toshihiro Shimizu 890ddd
		while (inPix < inEndPix) {
Toshihiro Shimizu 890ddd
			outPix->r = inPix->value;
Toshihiro Shimizu 890ddd
			outPix->g = inPix->value;
Toshihiro Shimizu 890ddd
			outPix->b = inPix->value;
Toshihiro Shimizu 890ddd
			outPix->m = 0xff;
Toshihiro Shimizu 890ddd
			outPix++;
Toshihiro Shimizu 890ddd
			inPix++;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define USHORT2BYTE_MAGICFAC (256U * 255U + 1U)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline UCHAR ditherUcharFromUshort(USHORT in, UINT rndNum)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return ((((in * USHORT2BYTE_MAGICFAC) - ((in * USHORT2BYTE_MAGICFAC) >> 24)) + rndNum) >> 24);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline void ditherRgbmFromRgbm64(TPixel32 &out, const TPixel64 &in, TRandom &rnd)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	UINT randomRound;
Toshihiro Shimizu 890ddd
	randomRound = rnd.getUInt() & ((1U << 24) - 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	out.r = ditherUcharFromUshort(in.r, randomRound);
Toshihiro Shimizu 890ddd
	out.g = ditherUcharFromUshort(in.g, randomRound);
Toshihiro Shimizu 890ddd
	out.b = ditherUcharFromUshort(in.b, randomRound);
Toshihiro Shimizu 890ddd
	out.m = ditherUcharFromUshort(in.m, randomRound);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline void ditherConvert(TRaster64P inRas, TRaster32P outRas)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int inWrap = inRas->getWrap();
Toshihiro Shimizu 890ddd
	int outWrap = outRas->getWrap();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPixel64 *inPix = 0, *inRow = inRas->pixels();
Toshihiro Shimizu 890ddd
	TPixel32 *outPix, *outRow = outRas->pixels();
Toshihiro Shimizu 890ddd
	TPixel64 *endPix;
Toshihiro Shimizu 890ddd
	int inLx = inRas->getLx();
Toshihiro Shimizu 890ddd
	TPixel64 *lastPix = inRow + inWrap * (inRas->getLy() - 1) + inLx;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRandom rnd(130266);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	while (inPix < lastPix) {
Toshihiro Shimizu 890ddd
		inPix = inRow;
Toshihiro Shimizu 890ddd
		outPix = outRow;
Toshihiro Shimizu 890ddd
		endPix = inPix + inLx;
Toshihiro Shimizu 890ddd
		while (inPix < endPix) {
Toshihiro Shimizu 890ddd
			ditherRgbmFromRgbm64(*outPix, *inPix, rnd);
Toshihiro Shimizu 890ddd
			inPix++;
Toshihiro Shimizu 890ddd
			outPix++;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		inRow += inWrap;
Toshihiro Shimizu 890ddd
		outRow += outWrap;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************
Toshihiro Shimizu 890ddd
//    Obsolete conversion functions
Toshihiro Shimizu 890ddd
//******************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_convert(const TRasterCM32P &dst, const TRasterGR8P &src)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(dst->getSize() == src->getSize());
Toshihiro Shimizu 890ddd
	TPixelCM32 bg = TPixelCM32(0, 0, TPixelCM32::getMaxTone());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int lx = src->getLx();
Toshihiro Shimizu 890ddd
	for (int y = 0; y < src->getLy(); y++) {
Toshihiro Shimizu 890ddd
		TPixelCM32 *outPix = dst->pixels(y);
Toshihiro Shimizu 890ddd
		TPixelGR8 *inPix = src->pixels(y);
Toshihiro Shimizu 890ddd
		TPixelGR8 *inEndPix = inPix + lx;
Toshihiro Shimizu 890ddd
		while (inPix < inEndPix) {
Toshihiro Shimizu 890ddd
			*outPix = (inPix->value == 255) ? bg : TPixelCM32(1, 0, inPix->value);
Toshihiro Shimizu 890ddd
			outPix++;
Toshihiro Shimizu 890ddd
			inPix++;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_convert(const TRasterCM32P &dst, const TRaster32P &src)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(dst->getSize() == src->getSize());
Toshihiro Shimizu 890ddd
	TPixelCM32 bg = TPixelCM32(0, 0, TPixelCM32::getMaxTone());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int lx = src->getLx();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isOverlay = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int y = 0; y < src->getLy(); y++) //if it is an overlay, I use the matte value for inks, otherwise I use the brightness.
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TPixel32 *inPix = src->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *inEndPix = inPix + lx;
Toshihiro Shimizu 890ddd
		while (inPix < inEndPix) {
Toshihiro Shimizu 890ddd
			if (inPix->m != 255) {
Toshihiro Shimizu 890ddd
				isOverlay = true;
Toshihiro Shimizu 890ddd
				break;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			inPix++;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (isOverlay)
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (isOverlay)
Toshihiro Shimizu 890ddd
		for (int y = 0; y < src->getLy(); y++) {
Toshihiro Shimizu 890ddd
			TPixelCM32 *outPix = dst->pixels(y);
Toshihiro Shimizu 890ddd
			TPixel32 *inPix = src->pixels(y);
Toshihiro Shimizu 890ddd
			TPixel32 *inEndPix = inPix + lx;
Toshihiro Shimizu 890ddd
			while (inPix < inEndPix) {
Toshihiro Shimizu 890ddd
				*outPix = (inPix->m == 0) ? bg : TPixelCM32(1, 0, 255 - inPix->m);
Toshihiro Shimizu 890ddd
				outPix++;
Toshihiro Shimizu 890ddd
				inPix++;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		for (int y = 0; y < src->getLy(); y++) {
Toshihiro Shimizu 890ddd
			TPixelCM32 *outPix = dst->pixels(y);
Toshihiro Shimizu 890ddd
			TPixel32 *inPix = src->pixels(y);
Toshihiro Shimizu 890ddd
			TPixel32 *inEndPix = inPix + lx;
Toshihiro Shimizu 890ddd
			while (inPix < inEndPix) {
Toshihiro Shimizu 890ddd
				UCHAR val = TPixelGR8::from(*inPix).value;
Toshihiro Shimizu 890ddd
				*outPix = (val == 255) ? bg : TPixelCM32(1, 0, val);
Toshihiro Shimizu 890ddd
				outPix++;
Toshihiro Shimizu 890ddd
				inPix++;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_convert(const TRasterYUV422P &dst, const TRaster32P &src)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(src->getLx() & 0);
Toshihiro Shimizu 890ddd
	long y1, y2, u, v, u1, u2, v1, v2;
Toshihiro Shimizu 890ddd
	TPixel32 *pix = (TPixel32 *)src->pixels();
Toshihiro Shimizu 890ddd
	TPixel32 *lastPix = &(src->pixels(src->getLy() - 1)[src->getLx() - 1]);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UCHAR *out = dst->getRawData();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	while (pix < lastPix) {
Toshihiro Shimizu 890ddd
		/* first pixel gives Y and 0.5 of chroma */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		y1 = 16829 * pix->r + 33039 * pix->g + 6416 * pix->b;
Toshihiro Shimizu 890ddd
		u1 = -4831 * pix->r + -9488 * pix->g + 14319 * pix->b;
Toshihiro Shimizu 890ddd
		v1 = 14322 * pix->r + -11992 * pix->g + -2330 * pix->b;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/* second pixel gives Y and 0.5 of chroma */
Toshihiro Shimizu 890ddd
		++pix;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		y2 = 16829 * pix->r + 33039 * pix->g + 6416 * pix->b;
Toshihiro Shimizu 890ddd
		u2 = -4831 * pix->r + -9488 * pix->g + 14319 * pix->b;
Toshihiro Shimizu 890ddd
		v2 = 14322 * pix->r + -11992 * pix->g + -2330 * pix->b;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/* average the chroma */
Toshihiro Shimizu 890ddd
		u = u1 + u2;
Toshihiro Shimizu 890ddd
		v = v1 + v2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/* round the chroma */
Toshihiro Shimizu 890ddd
		u1 = (u + 0x008000) >> 16;
Toshihiro Shimizu 890ddd
		v1 = (v + 0x008000) >> 16;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/* limit the chroma */
Toshihiro Shimizu 890ddd
		if (u1 < -112)
Toshihiro Shimizu 890ddd
			u1 = -112;
Toshihiro Shimizu 890ddd
		if (u1 > 111)
Toshihiro Shimizu 890ddd
			u1 = 111;
Toshihiro Shimizu 890ddd
		if (v1 < -112)
Toshihiro Shimizu 890ddd
			v1 = -112;
Toshihiro Shimizu 890ddd
		if (v1 > 111)
Toshihiro Shimizu 890ddd
			v1 = 111;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/* limit the lum */
Toshihiro Shimizu 890ddd
		if (y1 > 0x00dbffff)
Toshihiro Shimizu 890ddd
			y1 = 0x00dbffff;
Toshihiro Shimizu 890ddd
		if (y2 > 0x00dbffff)
Toshihiro Shimizu 890ddd
			y2 = 0x00dbffff;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/* save the results */
Toshihiro Shimizu 890ddd
		*out++ = (UCHAR)(u1 + 128);
Toshihiro Shimizu 890ddd
		*out++ = (UCHAR)((y1 >> 16) + 16);
Toshihiro Shimizu 890ddd
		*out++ = (UCHAR)(v1 + 128);
Toshihiro Shimizu 890ddd
		*out++ = (UCHAR)((y2 >> 16) + 16);
Toshihiro Shimizu 890ddd
		++pix;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_convert(const TRaster32P &dst, const TRasterYUV422P &src)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int long r, g, b, y1, y2, u, v;
Toshihiro Shimizu 890ddd
	TPixel32 *buf = dst->pixels();
Toshihiro Shimizu 890ddd
	const UCHAR *in = src->getRawData();
Toshihiro Shimizu 890ddd
	const UCHAR *last = in + src->getRowSize() * src->getLy() - 1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	while (in < last) {
Toshihiro Shimizu 890ddd
		u = *in;
Toshihiro Shimizu 890ddd
		u -= 128;
Toshihiro Shimizu 890ddd
		in++;
Toshihiro Shimizu 890ddd
		y1 = *in;
Toshihiro Shimizu 890ddd
		y1 -= 16;
Toshihiro Shimizu 890ddd
		in++;
Toshihiro Shimizu 890ddd
		v = *in;
Toshihiro Shimizu 890ddd
		v -= 128;
Toshihiro Shimizu 890ddd
		in++;
Toshihiro Shimizu 890ddd
		y2 = *in;
Toshihiro Shimizu 890ddd
		y2 -= 16;
Toshihiro Shimizu 890ddd
		in++;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		r = 76310 * y1 + 104635 * v;
Toshihiro Shimizu 890ddd
		if (r > 0xFFFFFF)
Toshihiro Shimizu 890ddd
			r = 0xFFFFFF;
Toshihiro Shimizu 890ddd
		if (r <= 0xFFFF)
Toshihiro Shimizu 890ddd
			r = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		g = 76310 * y1 + -25690 * u + -53294 * v;
Toshihiro Shimizu 890ddd
		if (g > 0xFFFFFF)
Toshihiro Shimizu 890ddd
			g = 0xFFFFFF;
Toshihiro Shimizu 890ddd
		if (g <= 0xFFFF)
Toshihiro Shimizu 890ddd
			g = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		b = 76310 * y1 + 132278 * u;
Toshihiro Shimizu 890ddd
		if (b > 0xFFFFFF)
Toshihiro Shimizu 890ddd
			b = 0xFFFFFF;
Toshihiro Shimizu 890ddd
		if (b <= 0xFFFF)
Toshihiro Shimizu 890ddd
			b = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		buf->r = (UCHAR)(r >> 16);
Toshihiro Shimizu 890ddd
		buf->g = (UCHAR)(g >> 16);
Toshihiro Shimizu 890ddd
		buf->b = (UCHAR)(b >> 16);
Toshihiro Shimizu 890ddd
		buf->m = (UCHAR)255;
Toshihiro Shimizu 890ddd
		buf++;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		r = 76310 * y2 + 104635 * v;
Toshihiro Shimizu 890ddd
		if (r > 0xFFFFFF)
Toshihiro Shimizu 890ddd
			r = 0xFFFFFF;
Toshihiro Shimizu 890ddd
		if (r <= 0xFFFF)
Toshihiro Shimizu 890ddd
			r = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		g = 76310 * y2 + -25690 * u + -53294 * v;
Toshihiro Shimizu 890ddd
		if (g > 0xFFFFFF)
Toshihiro Shimizu 890ddd
			g = 0xFFFFFF;
Toshihiro Shimizu 890ddd
		if (g <= 0xFFFF)
Toshihiro Shimizu 890ddd
			g = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		b = 76310 * y2 + 132278 * u;
Toshihiro Shimizu 890ddd
		if (b > 0xFFFFFF)
Toshihiro Shimizu 890ddd
			b = 0xFFFFFF;
Toshihiro Shimizu 890ddd
		if (b <= 0xFFFF)
Toshihiro Shimizu 890ddd
			b = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		buf->r = (UCHAR)(r >> 16);
Toshihiro Shimizu 890ddd
		buf->g = (UCHAR)(g >> 16);
Toshihiro Shimizu 890ddd
		buf->b = (UCHAR)(b >> 16);
Toshihiro Shimizu 890ddd
		buf->m = (UCHAR)255;
Toshihiro Shimizu 890ddd
		buf++;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************
Toshihiro Shimizu 890ddd
//    Main conversion function
Toshihiro Shimizu 890ddd
//******************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::convert(TRasterP dst, const TRasterP &src)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (dst->getSize() != src->getSize())
Toshihiro Shimizu 890ddd
		throw TRopException("convert: size mismatch");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P dst32 = dst;
Toshihiro Shimizu 890ddd
	TRasterGR8P dst8 = dst;
Toshihiro Shimizu 890ddd
	TRasterGR16P dst16 = dst;
Toshihiro Shimizu 890ddd
	TRaster64P dst64 = dst;
Toshihiro Shimizu 890ddd
	TRasterCM32P dstCm = dst;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P src32 = src;
Toshihiro Shimizu 890ddd
	TRasterGR8P src8 = src;
Toshihiro Shimizu 890ddd
	TRaster64P src64 = src;
Toshihiro Shimizu 890ddd
	TRasterYUV422P srcYUV = src;
Toshihiro Shimizu 890ddd
	TRasterYUV422P dstYUV = dst;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	src->lock();
Toshihiro Shimizu 890ddd
	dst->lock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (dst64 && src32)
Toshihiro Shimizu 890ddd
		do_convert(dst64, src32);
Toshihiro Shimizu 890ddd
	else if (dst8 && src32)
Toshihiro Shimizu 890ddd
		do_convert(dst8, src32);
Toshihiro Shimizu 890ddd
	else if (dst16 && src32)
Toshihiro Shimizu 890ddd
		do_convert(dst16, src32);
Toshihiro Shimizu 890ddd
	else if (dst32 && src64)
Toshihiro Shimizu 890ddd
		ditherConvert(src64, dst32);
Toshihiro Shimizu 890ddd
	else if (dst16 && src64)
Toshihiro Shimizu 890ddd
		do_convert(dst16, src64);
Toshihiro Shimizu 890ddd
	else if (dst32 && src8)
Toshihiro Shimizu 890ddd
		do_convert(dst32, src8);
Toshihiro Shimizu 890ddd
	else if (dstYUV && src32)
Toshihiro Shimizu 890ddd
		do_convert(dstYUV, src32); // Obsolete conversions
Toshihiro Shimizu 890ddd
	else if (dst32 && srcYUV)
Toshihiro Shimizu 890ddd
		do_convert(dst32, srcYUV); //
Toshihiro Shimizu 890ddd
	else if (dstCm && src32)
Toshihiro Shimizu 890ddd
		do_convert(dstCm, src32); //
Toshihiro Shimizu 890ddd
	else if (dstCm && src8)
Toshihiro Shimizu 890ddd
		do_convert(dstCm, src8); //
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		dst->unlock();
Toshihiro Shimizu 890ddd
		src->unlock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		throw TRopException("unsupported pixel type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	dst->unlock();
Toshihiro Shimizu 890ddd
	src->unlock();
Toshihiro Shimizu 890ddd
}