Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "quickputP.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
#include "trastercm.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "tropcm.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
#include <emmintrin.h> // per SSE2</emmintrin.h>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline bool transp(const TPixel32 &p)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return p.m == 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
inline bool transp(const TPixel64 &p)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return p.m == 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline bool opaque(const TPixel32 &p)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return p.m == 0xff;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
inline bool opaque(const TPixel64 &p)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return p.m == 0xffff;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define MODO2
Toshihiro Shimizu 890ddd
#define VELOCE
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
void do_overT3(TRasterPT<t> rout, const TRasterPT<t> &rdn, const TRasterPT<t> &rup)</t></t></t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int y = 0; y < rout->getLy(); y++) {
Toshihiro Shimizu 890ddd
#ifdef MODO1
Toshihiro Shimizu 890ddd
		const T *dn_pix = rdn->pixels(y);
Toshihiro Shimizu 890ddd
		const T *up_pix = rup->pixels(y);
Toshihiro Shimizu 890ddd
		T *out_pix = rout->pixels(y);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#ifdef MODO2
Toshihiro Shimizu 890ddd
		const T *dn_pix = ((T *)rdn->getRawData()) + y * rdn->getWrap();
Toshihiro Shimizu 890ddd
		const T *up_pix = ((T *)rup->getRawData()) + y * rup->getWrap();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		T *out_pix = ((T *)rout->getRawData()) + y * rout->getWrap();
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		const T *dn_limit = dn_pix + rdn->getLx();
Toshihiro Shimizu 890ddd
		for (; dn_pix < dn_limit; dn_pix++, up_pix++, out_pix++) {
Toshihiro Shimizu 890ddd
#ifdef VELOCE
Toshihiro Shimizu 890ddd
			if (transp(*up_pix))
Toshihiro Shimizu 890ddd
				*out_pix = *dn_pix;
Toshihiro Shimizu 890ddd
			else if (opaque(*up_pix))
Toshihiro Shimizu 890ddd
				*out_pix = *up_pix;
Toshihiro Shimizu 890ddd
			else {
Toshihiro Shimizu 890ddd
				*out_pix = overPix(*dn_pix, *up_pix);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			T topval = *up_pix;
Toshihiro Shimizu 890ddd
			if (transp(topval))
Toshihiro Shimizu 890ddd
				*out_pix = *dn_pix;
Toshihiro Shimizu 890ddd
			else if (opaque(topval))
Toshihiro Shimizu 890ddd
				*out_pix = topval;
Toshihiro Shimizu 890ddd
			else {
Toshihiro Shimizu 890ddd
				*out_pix = overPix(*dn_pix, topval);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixtypedn,="" pixtypeout,="" pixtypeup="" typename=""></typename>
Toshihiro Shimizu 890ddd
void do_over(TRasterPT<pixtypeout> rout, const TRasterPT<pixtypedn> &rdn,</pixtypedn></pixtypeout>
Toshihiro Shimizu 890ddd
			 const TRasterPT<pixtypeup> &rup, const TRasterGR8P rmask)</pixtypeup>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int y = 0; y < rout->getLy(); y++) {
Toshihiro Shimizu 890ddd
		const PixTypeDn *dn_pix = ((PixTypeDn *)rdn->getRawData()) + y * rdn->getWrap();
Toshihiro Shimizu 890ddd
		const PixTypeUp *up_pix = ((PixTypeUp *)rup->getRawData()) + y * rup->getWrap();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		PixTypeOut *out_pix = ((PixTypeOut *)rout->getRawData()) + y * rout->getWrap();
Toshihiro Shimizu 890ddd
		TPixelGR8 *mask_pix = ((TPixelGR8 *)rmask->getRawData()) + y * rmask->getWrap();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		const PixTypeDn *dn_limit = dn_pix + rout->getLx();
Toshihiro Shimizu 890ddd
		for (; dn_pix < dn_limit; dn_pix++, up_pix++, out_pix++, mask_pix++) {
Toshihiro Shimizu 890ddd
			if (mask_pix->value == 0x00)
Toshihiro Shimizu 890ddd
				*out_pix = *dn_pix;
Toshihiro Shimizu 890ddd
			else if (mask_pix->value == 0xff)
Toshihiro Shimizu 890ddd
				*out_pix = *up_pix;
Toshihiro Shimizu 890ddd
			else {
Toshihiro Shimizu 890ddd
				PixTypeUp p(*up_pix);
Toshihiro Shimizu 890ddd
				p.m = mask_pix->value;
Toshihiro Shimizu 890ddd
				*out_pix = overPix(*dn_pix, p); //hei!
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 do_over(TRasterCM32P rout, const TRasterCM32P &rup)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(rout->getSize() == rup->getSize());
Toshihiro Shimizu 890ddd
	for (int y = 0; y < rout->getLy(); y++) {
Toshihiro Shimizu 890ddd
		TPixelCM32 *out_pix = rout->pixels(y);
Toshihiro Shimizu 890ddd
		TPixelCM32 *const out_end = out_pix + rout->getLx();
Toshihiro Shimizu 890ddd
		const TPixelCM32 *up_pix = rup->pixels(y);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (; out_pix < out_end; ++out_pix, ++up_pix) {
Toshihiro Shimizu 890ddd
			if (!up_pix->isPureInk() &&
Toshihiro Shimizu 890ddd
				up_pix->getPaint() != 0) // BackgroundStyle)
Toshihiro Shimizu 890ddd
				*out_pix = *up_pix;
Toshihiro Shimizu 890ddd
			else if (!up_pix->isPurePaint()) {
Toshihiro Shimizu 890ddd
				TUINT32 *outl = (TUINT32 *)out_pix, *upl = (TUINT32 *)up_pix;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				*outl = ((*upl) & (TPixelCM32::getInkMask())) |
Toshihiro Shimizu 890ddd
						((*outl) & (TPixelCM32::getPaintMask())) |
Toshihiro Shimizu 890ddd
						tmin(up_pix->getTone(), out_pix->getTone());
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class class="" q="" t,=""></class>
Toshihiro Shimizu 890ddd
void do_overT2(TRasterPT<t> rout, const TRasterPT<t> &rup)</t></t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	UINT max = T::maxChannelValue;
Toshihiro Shimizu 890ddd
	double maxD = max;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(rout->getSize() == rup->getSize());
Toshihiro Shimizu 890ddd
	for (int y = 0; y < rout->getLy(); y++) {
Toshihiro Shimizu 890ddd
		T *out_pix = rout->pixels(y);
Toshihiro Shimizu 890ddd
		T *const out_end = out_pix + rout->getLx();
Toshihiro Shimizu 890ddd
		const T *up_pix = rup->pixels(y);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (; out_pix < out_end; ++out_pix, ++up_pix) {
Toshihiro Shimizu 890ddd
			if (up_pix->m == max)
Toshihiro Shimizu 890ddd
				*out_pix = *up_pix;
Toshihiro Shimizu 890ddd
			else if (up_pix->m > 0) {
Toshihiro Shimizu 890ddd
				TUINT32 r, g, b;
Toshihiro Shimizu 890ddd
				r = up_pix->r + (out_pix->r * (max - up_pix->m)) / maxD;
Toshihiro Shimizu 890ddd
				g = up_pix->g + (out_pix->g * (max - up_pix->m)) / maxD;
Toshihiro Shimizu 890ddd
				b = up_pix->b + (out_pix->b * (max - up_pix->m)) / maxD;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				out_pix->r = (r < max) ? (Q)r : (Q)max;
Toshihiro Shimizu 890ddd
				out_pix->g = (g < max) ? (Q)g : (Q)max;
Toshihiro Shimizu 890ddd
				out_pix->b = (b < max) ? (Q)b : (Q)max;
Toshihiro Shimizu 890ddd
				out_pix->m = up_pix->m + (out_pix->m * (max - up_pix->m)) / maxD;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_over_SSE2(TRaster32P rout, const TRaster32P &rup)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	__m128i zeros = _mm_setzero_si128();
Toshihiro Shimizu 890ddd
	__m128i out_pix_packed_i, up_pix_packed_i;
Toshihiro Shimizu 890ddd
	__m128 out_pix_packed, up_pix_packed;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	float maxChannelValue = 255.0;
Toshihiro Shimizu 890ddd
	float maxChannelValueInv = 1.0f / maxChannelValue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	__m128 maxChanneValue_packed = _mm_load1_ps(&maxChannelValue);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(rout->getSize() == rup->getSize());
Toshihiro Shimizu 890ddd
	for (int y = 0; y < rout->getLy(); y++) {
Toshihiro Shimizu 890ddd
		TPixel32 *out_pix = rout->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *const out_end = out_pix + rout->getLx();
Toshihiro Shimizu 890ddd
		const TPixel32 *up_pix = rup->pixels(y);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (; out_pix < out_end; ++out_pix, ++up_pix) {
Toshihiro Shimizu 890ddd
			if (up_pix->m == 0xff)
Toshihiro Shimizu 890ddd
				*out_pix = *up_pix;
Toshihiro Shimizu 890ddd
			else if (up_pix->m > 0) {
Toshihiro Shimizu 890ddd
				float factor = (255.0f - up_pix->m) / 255.0f;
Toshihiro Shimizu 890ddd
				__m128 factor_packed = _mm_load1_ps(&factor);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				// carica up_pix e out_pix in due registri a 128 bit
Toshihiro Shimizu 890ddd
				up_pix_packed_i = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(DWORD *)up_pix), zeros);
Toshihiro Shimizu 890ddd
				up_pix_packed = _mm_cvtepi32_ps(_mm_unpacklo_epi16(up_pix_packed_i, zeros));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				out_pix_packed_i = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(DWORD *)out_pix), zeros);
Toshihiro Shimizu 890ddd
				out_pix_packed = _mm_cvtepi32_ps(_mm_unpacklo_epi16(out_pix_packed_i, zeros));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				out_pix_packed = _mm_add_ps(up_pix_packed, _mm_mul_ps(out_pix_packed, factor_packed));
Toshihiro Shimizu 890ddd
				out_pix_packed = _mm_min_ps(maxChanneValue_packed, out_pix_packed);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				out_pix_packed_i = _mm_cvtps_epi32(out_pix_packed);
Toshihiro Shimizu 890ddd
				out_pix_packed_i = _mm_packs_epi32(out_pix_packed_i, zeros);
Toshihiro Shimizu 890ddd
				out_pix_packed_i = _mm_packus_epi16(out_pix_packed_i, zeros);
Toshihiro Shimizu 890ddd
				*(DWORD *)(out_pix) = _mm_cvtsi128_si32(out_pix_packed_i);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_over(TRaster32P rout, const TRasterGR8P &rup)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(rout->getSize() == rup->getSize());
Toshihiro Shimizu 890ddd
	for (int y = rout->getLy(); --y >= 0;) {
Toshihiro Shimizu 890ddd
		TPixel32 *out_pix = rout->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *const out_end = out_pix + rout->getLx();
Toshihiro Shimizu 890ddd
		const TPixelGR8 *up_pix = rup->pixels(y);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (; out_pix < out_end; ++out_pix, ++up_pix) {
Toshihiro Shimizu 890ddd
			int v = up_pix->value;
Toshihiro Shimizu 890ddd
			out_pix->r = out_pix->r * v / 255;
Toshihiro Shimizu 890ddd
			out_pix->g = out_pix->r;
Toshihiro Shimizu 890ddd
			out_pix->b = out_pix->r;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_over(TRasterGR8P rout, const TRaster32P &rup)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(rout->getSize() == rup->getSize());
Toshihiro Shimizu 890ddd
	for (int y = rout->getLy(); --y >= 0;) {
Toshihiro Shimizu 890ddd
		TPixelGR8 *out_pix = rout->pixels(y);
Toshihiro Shimizu 890ddd
		TPixelGR8 *const out_end = out_pix + rout->getLx();
Toshihiro Shimizu 890ddd
		const TPixel32 *up_pix = rup->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *temp_pix = new TPixel32();
Toshihiro Shimizu 890ddd
		for (; out_pix < out_end; ++out_pix, ++up_pix) {
Toshihiro Shimizu 890ddd
			temp_pix->r = out_pix->value;
Toshihiro Shimizu 890ddd
			temp_pix->g = out_pix->value;
Toshihiro Shimizu 890ddd
			temp_pix->b = out_pix->value;
Toshihiro Shimizu 890ddd
			temp_pix->m = 0xff;
Toshihiro Shimizu 890ddd
			TPixel32 out32_pix = overPix(*temp_pix, *up_pix);
Toshihiro Shimizu 890ddd
			*out_pix = out_pix->from(out32_pix);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void do_over(TRaster32P rout, const TRasterGR8P &rup, const TPixel32 &color)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(rout->getSize() == rup->getSize());
Toshihiro Shimizu 890ddd
	for (int y = rout->getLy(); --y >= 0;) {
Toshihiro Shimizu 890ddd
		TPixel32 *out_pix = rout->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *const out_end = out_pix + rout->getLx();
Toshihiro Shimizu 890ddd
		const TPixelGR8 *up_pix = rup->pixels(y);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (; out_pix < out_end; ++out_pix, ++up_pix) {
Toshihiro Shimizu 890ddd
			double v = up_pix->value / 255.0;
Toshihiro Shimizu 890ddd
			TPixel32 up(troundp(v * color.r), troundp(v * color.g), troundp(v * color.b), troundp(v * color.m));
Toshihiro Shimizu 890ddd
			*out_pix = overPix(*out_pix, up);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::over(TRaster32P rout, const TRasterGR8P &rup, const TPixel32 &color)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	rout->lock();
Toshihiro Shimizu 890ddd
	do_over(rout, rup, color);
Toshihiro Shimizu 890ddd
	rout->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::over(const TRasterP &rout, const TRasterP &rdn, const TRasterP &rup)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRect rect = rout->getBounds() * rdn->getBounds() * rup->getBounds();
Toshihiro Shimizu 890ddd
	if (rect.isEmpty())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterP cRout = rout->extract(rect);
Toshihiro Shimizu 890ddd
	TRasterP cRdn = rdn->extract(rect);
Toshihiro Shimizu 890ddd
	TRasterP cRup = rup->extract(rect);
Toshihiro Shimizu 890ddd
	rout->lock();
Toshihiro Shimizu 890ddd
	rdn->lock();
Toshihiro Shimizu 890ddd
	rup->lock();
Toshihiro Shimizu 890ddd
	TRaster32P rout32 = cRout, rdn32 = cRdn, rup32 = cRup;
Toshihiro Shimizu 890ddd
	TRaster64P rout64 = cRout, rdn64 = cRdn, rup64 = cRup;
Toshihiro Shimizu 890ddd
	if (rout32 && rdn32 && rup32)
Toshihiro Shimizu 890ddd
		do_overT3<tpixel32>(rout32, rdn32, rup32);</tpixel32>
Toshihiro Shimizu 890ddd
	else if (rout64 && rdn64 && rup64)
Toshihiro Shimizu 890ddd
		do_overT3<tpixel64>(rout64, rdn64, rup64);</tpixel64>
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		rout->unlock();
Toshihiro Shimizu 890ddd
		rdn->unlock();
Toshihiro Shimizu 890ddd
		rup->unlock();
Toshihiro Shimizu 890ddd
		throw TRopException("unsupported pixel type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	rout->unlock();
Toshihiro Shimizu 890ddd
	rdn->unlock();
Toshihiro Shimizu 890ddd
	rup->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::over(const TRasterP &rout, const TRasterP &rup, const TPoint &pos)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRect outRect(rout->getBounds());
Toshihiro Shimizu 890ddd
	TRect upRect(rup->getBounds() + pos);
Toshihiro Shimizu 890ddd
	TRect intersection = outRect * upRect;
Toshihiro Shimizu 890ddd
	if (intersection.isEmpty())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterP cRout = rout->extract(intersection);
Toshihiro Shimizu 890ddd
	TRect r = intersection - pos;
Toshihiro Shimizu 890ddd
	TRasterP cRup = rup->extract(r);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P rout32 = cRout, rup32 = cRup;
Toshihiro Shimizu 890ddd
	TRaster64P rout64 = cRout, rup64 = cRup;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterGR8P rout8 = cRout, rup8 = cRup;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterCM32P routCM32 = cRout, rupCM32 = cRup;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	rout->lock();
Toshihiro Shimizu 890ddd
	rup->lock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// TRaster64P rout64 = rout, rin64 = rin;
Toshihiro Shimizu 890ddd
	if (rout32 && rup32) {
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
		if (TSystem::getCPUExtensions() & TSystem::CpuSupportsSse2)
Toshihiro Shimizu 890ddd
			do_over_SSE2(rout32, rup32);
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
			do_overT2<tpixel32, uchar="">(rout32, rup32);</tpixel32,>
Toshihiro Shimizu 890ddd
	} else if (rout64) {
Toshihiro Shimizu 890ddd
		if (!rup64) {
Toshihiro Shimizu 890ddd
			TRaster64P raux(cRup->getSize());
Toshihiro Shimizu 890ddd
			TRop::convert(raux, cRup);
Toshihiro Shimizu 890ddd
			rup64 = raux;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		do_overT2<tpixel64, ushort="">(rout64, rup64);</tpixel64,>
Toshihiro Shimizu 890ddd
	} else if (rout32 && rup8)
Toshihiro Shimizu 890ddd
		do_over(rout32, rup8);
Toshihiro Shimizu 890ddd
	else if (rout8 && rup32)
Toshihiro Shimizu 890ddd
		do_over(rout8, rup32);
Toshihiro Shimizu 890ddd
	else if (rout8 && rup8)
Toshihiro Shimizu 890ddd
		TRop::copy(rout8, rup8);
Toshihiro Shimizu 890ddd
	else if (routCM32 && rupCM32)
Toshihiro Shimizu 890ddd
		do_over(routCM32, rupCM32);
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		rout->unlock();
Toshihiro Shimizu 890ddd
		rup->unlock();
Toshihiro Shimizu 890ddd
		throw TRopException("unsupported pixel type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	rout->unlock();
Toshihiro Shimizu 890ddd
	rup->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
static void addBackground32(TRaster32P ras, const TPixel32 &col)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	ras->lock();
Toshihiro Shimizu 890ddd
	int nrows = ras->getLy();
Toshihiro Shimizu 890ddd
	while (nrows-- > 0) {
Toshihiro Shimizu 890ddd
		TPixel32 *pix = ras->pixels(nrows);
Toshihiro Shimizu 890ddd
		TPixel32 *endPix = pix + ras->getLx();
Toshihiro Shimizu 890ddd
		while (pix < endPix) {
Toshihiro Shimizu 890ddd
			*pix = overPix(col, *pix);
Toshihiro Shimizu 890ddd
			pix++;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::addBackground(TRasterP ras, const TPixel32 &col)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRaster32P ras32 = ras;
Toshihiro Shimizu 890ddd
	if (ras32)
Toshihiro Shimizu 890ddd
		addBackground32(ras32, col);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		throw TRopException("unsupported pixel type");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//Usata tinylinetest
Toshihiro Shimizu 890ddd
static void my_do_over(TRaster32P rout, const TRasterGR8P &rup)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(rout->getSize() == rup->getSize());
Toshihiro Shimizu 890ddd
	for (int y = rout->getLy(); --y >= 0;) {
Toshihiro Shimizu 890ddd
		TPixel32 *out_pix = rout->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *const out_end = out_pix + rout->getLx();
Toshihiro Shimizu 890ddd
		const TPixelGR8 *up_pix = rup->pixels(y);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (; out_pix < out_end; ++out_pix, ++up_pix) {
Toshihiro Shimizu 890ddd
			int v = up_pix->value;
Toshihiro Shimizu 890ddd
			out_pix->r = out_pix->r * v / 255;
Toshihiro Shimizu 890ddd
			out_pix->g = out_pix->r;
Toshihiro Shimizu 890ddd
			out_pix->b = out_pix->r;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::over(const TRasterP &out,
Toshihiro Shimizu 890ddd
				const TRasterP &up,
Toshihiro Shimizu 890ddd
				const TAffine &aff,
Toshihiro Shimizu 890ddd
				ResampleFilterType filterType)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	out->lock();
Toshihiro Shimizu 890ddd
	up->lock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (filterType == ClosestPixel || filterType == Bilinear)
Toshihiro Shimizu 890ddd
		::quickPut(out, up, aff, filterType);
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		TRect rasterBounds = up->getBounds();
Toshihiro Shimizu 890ddd
		TRectD dbounds(rasterBounds.x0, rasterBounds.y0, rasterBounds.x1 + 1, rasterBounds.y1 + 1);
Toshihiro Shimizu 890ddd
		dbounds = aff * dbounds;
Toshihiro Shimizu 890ddd
		TRect bounds(tfloor(dbounds.x0), tfloor(dbounds.y0), tceil(dbounds.x1) - 1, tceil(dbounds.y1) - 1);
Toshihiro Shimizu 890ddd
		TRasterP tmp = up->create(bounds.getLx(), bounds.getLy());
Toshihiro Shimizu 890ddd
		resample(tmp, up, TTranslation(-bounds.x0, -bounds.y0) * aff, filterType);
Toshihiro Shimizu 890ddd
		over(out, tmp, bounds.getP00());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	out->unlock();
Toshihiro Shimizu 890ddd
	up->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::over(const TRasterP &out, const TRasterP &up, const TPoint &pos, const TAffine &aff,
Toshihiro Shimizu 890ddd
				ResampleFilterType filterType)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (aff.isIdentity())
Toshihiro Shimizu 890ddd
		//simple over with offset
Toshihiro Shimizu 890ddd
		TRop::over(out, up, pos);
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		TRect rasterBounds = up->getBounds();
Toshihiro Shimizu 890ddd
		TRectD dbounds(rasterBounds.x0, rasterBounds.y0, rasterBounds.x1, rasterBounds.y1);
Toshihiro Shimizu 890ddd
		dbounds = aff * dbounds;
Toshihiro Shimizu 890ddd
		TRect bounds(tfloor(dbounds.x0), tfloor(dbounds.y0), tceil(dbounds.x1), tceil(dbounds.y1));
Toshihiro Shimizu 890ddd
		TRasterP tmp = up->create(bounds.getLx(), bounds.getLy());
Toshihiro Shimizu 890ddd
		resample(tmp, up, TTranslation(-dbounds.getP00()) * aff, filterType);
Toshihiro Shimizu 890ddd
		TRop::over(out, tmp, pos);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::over(TRasterP rout, const TRasterCM32P &rup, TPalette *palette, const TPoint &point, const TAffine &aff)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRaster32P app(rup->getSize());
Toshihiro Shimizu 890ddd
	TRop::convert(app, rup, palette);
Toshihiro Shimizu 890ddd
	TRop::over(rout, app, point, aff);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::quickPut(const TRasterP &out,
Toshihiro Shimizu 890ddd
					const TRasterP &up,
Toshihiro Shimizu 890ddd
					const TAffine &aff,
Toshihiro Shimizu 890ddd
					const TPixel32 &colorScale,
Toshihiro Shimizu 890ddd
					bool doPremultiply, bool whiteTransp, bool firstColumn,
Toshihiro Shimizu 890ddd
					bool doRasterDarkenBlendedView)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	::quickPut(out, up, aff, ClosestPixel, colorScale, doPremultiply, whiteTransp, firstColumn, doRasterDarkenBlendedView);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::over(const TRasterP &out, const TRasterP &dn, const TRasterP &up, const TRasterGR8P &mask)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	out->lock();
Toshihiro Shimizu 890ddd
	up->lock();
Toshihiro Shimizu 890ddd
	dn->lock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P out32 = out;
Toshihiro Shimizu 890ddd
	TRaster32P dn32 = dn;
Toshihiro Shimizu 890ddd
	TRaster32P up32 = up;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (out32 && dn32 && up32)
Toshihiro Shimizu 890ddd
		do_over<tpixel32, tpixel32="" tpixel32,="">(out32, dn32, up32, mask);</tpixel32,>
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		TRaster64P out64 = out;
Toshihiro Shimizu 890ddd
		TRaster64P dn64 = dn;
Toshihiro Shimizu 890ddd
		TRaster64P up64 = up;
Toshihiro Shimizu 890ddd
		if (out64 && dn64 && up64)
Toshihiro Shimizu 890ddd
			do_over<tpixel64, tpixel64="" tpixel64,="">(out64, dn64, up64, mask);</tpixel64,>
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			throw TRopException("unsupported pixel type");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	out->unlock();
Toshihiro Shimizu 890ddd
	up->unlock();
Toshihiro Shimizu 890ddd
	dn->unlock();
Toshihiro Shimizu 890ddd
}