Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qdebug></qdebug>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "t32bitsrv_wrap.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//================================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int t32bitsrv::BufferExchanger::read(const char *srcBuf, int len)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_data = (UCHAR *)memcpy(m_data, srcBuf, len);
Toshihiro Shimizu 890ddd
	return len;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int t32bitsrv::BufferExchanger::write(char *dstBuf, int len)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	memcpy(dstBuf, m_data, len);
Toshihiro Shimizu 890ddd
	m_data += len;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return len;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//================================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixel=""></typename>
Toshihiro Shimizu 890ddd
int t32bitsrv::RasterExchanger<pixel>::read(const char *srcBuf, int len)</pixel>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_ras->getWrap() == m_ras->getLx()) {
Toshihiro Shimizu 890ddd
		memcpy(m_pix, srcBuf, len);
Toshihiro Shimizu 890ddd
		m_pix = (PIXEL *)((UCHAR *)m_pix + len);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		int xStart = (m_pix - m_ras->pixels(0)) % m_ras->getWrap();
Toshihiro Shimizu 890ddd
		int remainingData = len;
Toshihiro Shimizu 890ddd
		int lineData = m_ras->getLx() * sizeof(PIXEL);
Toshihiro Shimizu 890ddd
		int lineDataToRead = tmin((int)((m_ras->getLx() - xStart) * sizeof(PIXEL)), remainingData);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (; remainingData > 0;
Toshihiro Shimizu 890ddd
			 m_pix += (m_ras->getWrap() - xStart),
Toshihiro Shimizu 890ddd
			 remainingData -= lineDataToRead,
Toshihiro Shimizu 890ddd
			 lineDataToRead = tmin(lineData, remainingData),
Toshihiro Shimizu 890ddd
			 xStart = 0)
Toshihiro Shimizu 890ddd
			memcpy(m_pix, srcBuf, lineDataToRead);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return len;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixel=""></typename>
Toshihiro Shimizu 890ddd
int t32bitsrv::RasterExchanger<pixel>::write(char *dstBuf, int len)</pixel>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//We pass entire pixels, not just bytes
Toshihiro Shimizu 890ddd
	len = len - (len % sizeof(PIXEL));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_ras->getWrap() == m_ras->getLx()) {
Toshihiro Shimizu 890ddd
		memcpy(dstBuf, m_pix, len);
Toshihiro Shimizu 890ddd
		m_pix = (PIXEL *)((UCHAR *)m_pix + len);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		int xStart = (m_pix - m_ras->pixels(0)) % m_ras->getWrap();
Toshihiro Shimizu 890ddd
		int remainingData = len;
Toshihiro Shimizu 890ddd
		int lineData = m_ras->getLx() * sizeof(PIXEL);
Toshihiro Shimizu 890ddd
		int lineDataToWrite = tmin((int)((m_ras->getLx() - xStart) * sizeof(PIXEL)), remainingData);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (; remainingData > 0;
Toshihiro Shimizu 890ddd
			 m_pix += (m_ras->getWrap() - xStart),
Toshihiro Shimizu 890ddd
			 remainingData -= lineDataToWrite,
Toshihiro Shimizu 890ddd
			 lineDataToWrite = tmin(lineData, remainingData),
Toshihiro Shimizu 890ddd
			 xStart = 0)
Toshihiro Shimizu 890ddd
			memcpy(dstBuf, m_pix, lineDataToWrite);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return len;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//  Explicit specialization of raster exchangers
Toshihiro Shimizu 890ddd
template class DVAPI t32bitsrv::RasterExchanger<tpixel32>;</tpixel32>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//================================================================================