Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef T_RASTER_INCLUDED
Toshihiro Shimizu 890ddd
#define T_RASTER_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tutil.h"
Toshihiro Shimizu 890ddd
#include "tgeometry.h"
Toshihiro Shimizu 890ddd
#include "tpixel.h"
Toshihiro Shimizu 890ddd
#include "tpixelgr.h"
Toshihiro Shimizu 890ddd
#include "tsmartpointer.h"
Toshihiro Shimizu 890ddd
#include "tbigmemorymanager.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TRASTER_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TRasterType
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int m_id;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	enum Type {
Toshihiro Shimizu 890ddd
		None,
Toshihiro Shimizu 890ddd
		BW,
Toshihiro Shimizu 890ddd
		WB,
Toshihiro Shimizu 890ddd
		RGBM32,  // LPIXEL, matte channel considered
Toshihiro Shimizu 890ddd
		RGBM64,  // SPIXEL, matte channel considered 
Toshihiro Shimizu 890ddd
		CM8,     // color-mapped,  8 bits 
Toshihiro Shimizu 890ddd
		GR8,     // grey tones, 8 bits 
Toshihiro Shimizu 890ddd
		CM16,    // color-mapped, 16 bits 
Toshihiro Shimizu 890ddd
		GR16,    // grey tones, 16 bits 
Toshihiro Shimizu 890ddd
		RGB555,
Toshihiro Shimizu 890ddd
		RGB565,
Toshihiro Shimizu 890ddd
		CM24,    // cmapped, 8+8+8 bits (ink, paint, ramp), +8 bits spare (MSB)
Toshihiro Shimizu 890ddd
		CM16S12,
Toshihiro Shimizu 890ddd
		CM16S8   // cmapped, 16 bits, standard SGI 256-color colormap
Toshihiro Shimizu 890ddd
		// ....
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TRasterType(int id) : m_id(id){};
Toshihiro Shimizu 890ddd
	int getId() const { return m_id; };
Toshihiro Shimizu 890ddd
	bool operator==(TRasterType a) { return m_id == a.m_id; };
Toshihiro Shimizu 890ddd
	bool operator!=(TRasterType a) { return m_id != a.m_id; };
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// forward declaration
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TRasterPT;
Toshihiro Shimizu 890ddd
class TRaster;
Toshihiro Shimizu 890ddd
typedef TSmartPointerT<traster> TRasterP;</traster>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
/*!This class stores bitmap images. */
Toshihiro Shimizu 890ddd
class DVAPI TRaster : public TSmartObject
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DECLARE_CLASS_CODE
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	int m_pixelSize;
Toshihiro Shimizu 890ddd
	int m_lx, m_ly;
Toshihiro Shimizu 890ddd
	int m_wrap;
Toshihiro Shimizu 890ddd
	int m_lockCount;
Toshihiro Shimizu 890ddd
	TRaster *m_parent; // nel caso di sotto-raster
Toshihiro Shimizu 890ddd
	UCHAR *m_buffer;
Toshihiro Shimizu 890ddd
	bool m_bufferOwner;
Toshihiro Shimizu 890ddd
	// i costruttori sono qui per centralizzare la gestione della memoria
Toshihiro Shimizu 890ddd
	// e' comunque impossibile fare new TRaster perche' e' una classe astratta (clone, extract)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// crea il buffer associato (NON fa addRef())
Toshihiro Shimizu 890ddd
	TRaster(int lx, int ly, int pixelSize);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// si attacca ad un buffer pre-esistente (NON fa addRef() - neanche a parent)
Toshihiro Shimizu 890ddd
	TRaster(int lx, int ly, int pixelSize,
Toshihiro Shimizu 890ddd
			int wrap, UCHAR *buffer, TRaster *parent, bool bufferOwner = false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	static TAtomicVar m_totalMemory;
Toshihiro Shimizu 890ddd
	TThread::Mutex m_mutex;
Toshihiro Shimizu 890ddd
	// not implemented
Toshihiro Shimizu 890ddd
	TRaster(const TRaster &);
Toshihiro Shimizu 890ddd
	TRaster &operator=(const TRaster &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Toshihiro Shimizu 890ddd
	bool m_cashed;
Toshihiro Shimizu 890ddd
	static unsigned long getTotalMemoryInKB();
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual ~TRaster();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// accessors
Toshihiro Shimizu 890ddd
	// TRasterType getType() const {return m_type;};
Toshihiro Shimizu 890ddd
	int getLx() const { return m_lx; };
Toshihiro Shimizu 890ddd
	int getLy() const { return m_ly; };
Toshihiro Shimizu 890ddd
	TDimension getSize() const { return TDimension(m_lx, m_ly); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns the length of a row in pixel.
Toshihiro Shimizu 890ddd
	int getWrap() const { return m_wrap; }; // lunghezza di una riga in pixel
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD getCenterD() const { return TPointD(0.5 * m_lx, 0.5 * m_ly); };
Toshihiro Shimizu 890ddd
	TPoint getCenter() const { return TPoint(m_lx / 2, m_ly / 2); };
Toshihiro Shimizu 890ddd
	TRect getBounds() const { return TRect(0, 0, m_lx - 1, m_ly - 1); };
Toshihiro Shimizu 890ddd
	int getPixelSize() const { return m_pixelSize; };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getRowSize() const { return m_pixelSize * m_lx; };
Toshihiro Shimizu 890ddd
	// in bytes
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//when the bigMemoryManager is active, remapping can change buffers...need to to lock/unlock them o use them.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void lock()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (!TBigMemoryManager::instance()->isActive())
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TThread::MutexLocker sl(&m_mutex);
Toshihiro Shimizu 890ddd
		if (m_parent)
Toshihiro Shimizu 890ddd
			m_parent->lock();
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			++m_lockCount;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void unlock()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (!TBigMemoryManager::instance()->isActive())
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		TThread::MutexLocker sl(&m_mutex);
Toshihiro Shimizu 890ddd
		if (m_parent)
Toshihiro Shimizu 890ddd
			m_parent->unlock();
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
			assert(m_lockCount > 0);
Toshihiro Shimizu 890ddd
			--m_lockCount;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void beginRemapping();
Toshihiro Shimizu 890ddd
	void endRemapping();
Toshihiro Shimizu 890ddd
	//!Returns a pointer to the image buffer.
Toshihiro Shimizu 890ddd
	//WARNING!!!!! before getting the buffer with getRawData(),
Toshihiro Shimizu 890ddd
	//you have to lock the raster with'lock method, and unlock
Toshihiro Shimizu 890ddd
	//it when you've done with the buffer
Toshihiro Shimizu 890ddd
	const UCHAR *getRawData() const { return m_buffer; };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UCHAR *getRawData() { return m_buffer; };
Toshihiro Shimizu 890ddd
	//!Returns a pointer to the image buffer positioned in the (x,y) coords.
Toshihiro Shimizu 890ddd
	const UCHAR *getRawData(int x, int y) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(0 <= x && x < m_lx && 0 <= y && y < m_ly);
Toshihiro Shimizu 890ddd
		return m_buffer + (y * m_wrap + x) * m_pixelSize;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
	UCHAR *getRawData(int x, int y)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(0 <= x && x < m_lx && 0 <= y && y < m_ly);
Toshihiro Shimizu 890ddd
		return m_buffer + (y * m_wrap + x) * m_pixelSize;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
	bool isEmpty() const { return getSize() == TDimension(); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterP getParent() { return m_parent; }
Toshihiro Shimizu 890ddd
	// creazione di TRaster derivati
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// devono essere virtuali puri perche' il nuovo raster creato deve essere del tipo giusto
Toshihiro Shimizu 890ddd
	virtual TRasterP clone() const = 0;
Toshihiro Shimizu 890ddd
	virtual TRasterP extract(TRect &rect) = 0;
Toshihiro Shimizu 890ddd
	virtual TRasterP create() const = 0;
Toshihiro Shimizu 890ddd
	virtual TRasterP create(int lx, int ly) const = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// definita in termini di extract(rect); non lo posso fare subito perche' manca il
Toshihiro Shimizu 890ddd
	// costruttore di copia di TRasterP
Toshihiro Shimizu 890ddd
	inline virtual TRasterP extract(int x0, int y0, int x1, int y1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// operazioni sui pixel
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Copia il contenuto di src (spostato di offset) nel raster corrente.
Toshihiro Shimizu 890ddd
	// Il tipo deve essere lo stesso
Toshihiro Shimizu 890ddd
	// In caso di dimensione diversa l'area copiata e' l'intersezione dei due getBounds()
Toshihiro Shimizu 890ddd
	// e i due raster sono allineati in basso a sinistra (src[0,0] -> dst[offset])
Toshihiro Shimizu 890ddd
	/*!Copies the content of the source raster in the current raster.
Toshihiro Shimizu 890ddd
     */
Toshihiro Shimizu 890ddd
	void copy(const TRasterP &src, const TPoint &offset = TPoint());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void xMirror();
Toshihiro Shimizu 890ddd
	void yMirror();
Toshihiro Shimizu 890ddd
	void rotate180();
Toshihiro Shimizu 890ddd
	void rotate90();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void clear();
Toshihiro Shimizu 890ddd
	void clearOutside(const TRect &rect);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	friend class TBigMemoryManager;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	void fillRawData(const UCHAR *pixel);
Toshihiro Shimizu 890ddd
	void fillRawDataOutside(const TRect &rect, const UCHAR *pixel);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	void remap(UCHAR *newLocation);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Smart Pointer a TRaster
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
template class DVAPI TSmartPointerT<traster>;</traster>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline void detach(TRasterP &r)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!r || r->getRefCount() == 1)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TRasterP tmp(r->clone());
Toshihiro Shimizu 890ddd
	r = tmp;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// forward declaration
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TRasterT;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// TRasterPT<pixel>:</pixel>
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Smart Pointer to TRasterT<pixel></pixel>
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//!\include raster_ex1.cpp
Toshihiro Shimizu 890ddd
//! \include rasterpt_ex1.cpp
Toshihiro Shimizu 890ddd
// class TRasterPT<t></t>
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TRasterPT : public TSmartPointerT<trastert<t>></trastert<t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef T Pixel;
Toshihiro Shimizu 890ddd
	typedef TRasterT<t> Raster;</t>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterPT(){};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterPT(int lx, int ly) { create(lx, ly); };
Toshihiro Shimizu 890ddd
	TRasterPT(const TDimension &d) { create(d.lx, d.ly); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	inline TRasterPT(const TRasterP &src);
Toshihiro Shimizu 890ddd
	inline TRasterPT(int lx, int ly, int wrap, T *buffer, bool bufferOwner = false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~TRasterPT(){};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void create(int lx, int ly);
Toshihiro Shimizu 890ddd
	void create(const TDimension &d) { create(d.lx, d.ly); };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	inline void detach();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	operator TRasterP() const;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// TRasterT<pixel></pixel>
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// e' la classe concreta che discende da TRaster
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TRasterT : public TRaster
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	// Constructors are protected to prevent direct allocation of TRasterT instances.
Toshihiro Shimizu 890ddd
	// Users must adopt the TRasterPT smart pointer syntax instead.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Buffer Allocation
Toshihiro Shimizu 890ddd
	TRasterT(int lx, int ly) : TRaster(lx, ly, sizeof(T)) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Buffer Attachment
Toshihiro Shimizu 890ddd
	TRasterT(int lx, int ly, int wrap, T *buffer, TRasterT<t> *parent, bool bufferOwner = false)</t>
Toshihiro Shimizu 890ddd
		: TRaster(lx, ly, sizeof(T), wrap, reinterpret_cast<uchar *="">(buffer), parent, bufferOwner) {}</uchar>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef T Pixel;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~TRasterT(){};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// accessors
Toshihiro Shimizu 890ddd
	//WARNING!!!!! before getting the buffer with pixels(int y),
Toshihiro Shimizu 890ddd
	//you have to lock the raster with'lock method, and unlock
Toshihiro Shimizu 890ddd
	//it when you've done with the buffer
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const T *pixels(int y = 0) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(0 <= y && y < getLy());
Toshihiro Shimizu 890ddd
		return reinterpret_cast<t *="">(m_buffer) + getWrap() * y;</t>
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
	T *pixels(int y = 0)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(0 <= y && y < getLy());
Toshihiro Shimizu 890ddd
		return reinterpret_cast<t *="">(m_buffer) + getWrap() * y;</t>
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Derived rasters creation
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterP clone() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TRasterP dst = TRasterPT<t>(m_lx, m_ly);</t>
Toshihiro Shimizu 890ddd
		TRasterP src(const_cast<traster *="">((const TRaster *)this));</traster>
Toshihiro Shimizu 890ddd
		dst->copy(src);
Toshihiro Shimizu 890ddd
		return dst;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterP create() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return TRasterPT<t>(m_lx, m_ly);</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual TRasterP create(int lx, int ly) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return TRasterPT<t>(lx, ly);</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!\include raster_ex2.cpp
Toshihiro Shimizu 890ddd
	TRasterP extract(int x0, int y0, int x1, int y1)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TRect rect(x0, y0, x1, y1);
Toshihiro Shimizu 890ddd
		return extract(rect);
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterP extract(TRect &rect)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (isEmpty() || getBounds().overlaps(rect) == false)
Toshihiro Shimizu 890ddd
			return TRasterP();
Toshihiro Shimizu 890ddd
		rect = getBounds() * rect;
Toshihiro Shimizu 890ddd
		//addRef();
Toshihiro Shimizu 890ddd
		return TRasterP(
Toshihiro Shimizu 890ddd
			new TRasterT<t>(rect.getLx(), rect.getLy(), m_wrap,</t>
Toshihiro Shimizu 890ddd
							pixels(rect.y0) + rect.x0, this));
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterPT<t> extractT(TRect &rect);</t>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterPT<t> extractT(int x0, int y0, int x1, int y1)</t>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TRect rect(x0, y0, x1, y1);
Toshihiro Shimizu 890ddd
		return extractT(rect);
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	friend class TRasterPT<t>;</t>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Pixel Operations
Toshihiro Shimizu 890ddd
	void fill(const T &a)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		fillRawData(reinterpret_cast<const *="" uchar="">(&a));</const>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void fillOutside(const TRect &rect, const T &a)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		fillRawDataOutside(rect, reinterpret_cast<const *="" uchar="">(&a));</const>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline TRasterP TRaster::extract(int x0, int y0, int x1, int y1)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRect rect(x0, y0, x1, y1);
Toshihiro Shimizu 890ddd
	return extract(rect);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
TRasterPT<t> TRasterT<t>::extractT(TRect &rect)</t></t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (isEmpty() || getBounds().overlaps(rect) == false) {
Toshihiro Shimizu 890ddd
		return TRasterPT<t>();</t>
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	rect = getBounds() * rect;
Toshihiro Shimizu 890ddd
	//addRef();
Toshihiro Shimizu 890ddd
	return TRasterPT<t>(</t>
Toshihiro Shimizu 890ddd
		new TRasterT<t>(rect.getLx(), rect.getLy(), m_wrap,</t>
Toshihiro Shimizu 890ddd
						pixels(rect.y0) + rect.x0, this));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// metodi inline di TRasterPT
Toshihiro Shimizu 890ddd
// (n.b. se non si fanno esplicitament "inline" NT si confonde con dll exort/import)
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
inline TRasterPT<t>::TRasterPT(const TRasterP &src)</t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TSmartPointerT<trastert<t>>::m_pointer = dynamic_cast<trastert<t> *>(src.getPointer());</trastert<t></trastert<t>
Toshihiro Shimizu 890ddd
	if (TSmartPointerT<trastert<t>>::m_pointer)</trastert<t>
Toshihiro Shimizu 890ddd
		TSmartPointerT<trastert<t>>::m_pointer->addRef();</trastert<t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
inline void TRasterPT<t>::create(int lx, int ly)</t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRasterT<t> *raster = new TRasterT<t>(lx, ly);</t></t>
Toshihiro Shimizu 890ddd
	*this = TRasterPT<t>(raster);</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
inline void TRasterPT<t>::detach()</t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!TSmartPointerT<trastert<t>>::m_pointer || TSmartPointerT<trastert<t>>::m_pointer->getRefCount() == 1)</trastert<t></trastert<t>
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	*this = TRasterPT(TSmartPointerT<trastert<t>>::m_pointer->clone());</trastert<t>
Toshihiro Shimizu 890ddd
	// uso l'operator di assign per aggiornare correttamente
Toshihiro Shimizu 890ddd
	// i reference counts del vecchio e del nuovo raster
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
inline TRasterPT<t>::operator TRasterP() const</t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return TRasterP(TSmartPointerT<trastert<t>>::m_pointer);</trastert<t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
inline TRasterPT<t>::TRasterPT(int lx, int ly, int wrap, T *buffer, bool bufferOwner)</t>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TSmartPointerT<trastert<t>>::m_pointer = new TRasterT<t>(lx, ly, wrap, buffer, 0, bufferOwner);</t></trastert<t>
Toshihiro Shimizu 890ddd
	TSmartPointerT<trastert<t>>::m_pointer->addRef();</trastert<t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
// su NT e' necessario per evitare un warning nelle classi
Toshihiro Shimizu 890ddd
// esportate che si riferiscono a TRaster32P/TRaster64P
Toshihiro Shimizu 890ddd
// su IRIX non compila perche' non riesce ad instanziare le
Toshihiro Shimizu 890ddd
// funzioni online (!!!)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template class DVAPI TSmartPointerT<trastert<tpixel32>>;</trastert<tpixel32>
Toshihiro Shimizu 890ddd
template class DVAPI TRasterPT<tpixel32>;</tpixel32>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template class DVAPI TSmartPointerT<trastert<tpixel64>>;</trastert<tpixel64>
Toshihiro Shimizu 890ddd
template class DVAPI TRasterPT<tpixel64>;</tpixel64>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template class DVAPI TSmartPointerT<trastert<tpixelgr8>>;</trastert<tpixelgr8>
Toshihiro Shimizu 890ddd
template class DVAPI TRasterPT<tpixelgr8>;</tpixelgr8>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template class DVAPI TSmartPointerT<trastert<tpixelgr16>>;</trastert<tpixelgr16>
Toshihiro Shimizu 890ddd
template class DVAPI TRasterPT<tpixelgr16>;</tpixelgr16>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template class DVAPI TSmartPointerT<trastert<tpixelgrd>>;</trastert<tpixelgrd>
Toshihiro Shimizu 890ddd
template class DVAPI TRasterPT<tpixelgrd>;</tpixelgrd>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template class DVAPI TSmartPointerT<trastert<tpixelcy>>;</trastert<tpixelcy>
Toshihiro Shimizu 890ddd
template class DVAPI TRasterPT<tpixelcy>;</tpixelcy>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef TRasterPT<tpixel32> TRaster32P;</tpixel32>
Toshihiro Shimizu 890ddd
typedef TRasterPT<tpixel64> TRaster64P;</tpixel64>
Toshihiro Shimizu 890ddd
typedef TRasterPT<tpixelgr8> TRasterGR8P;</tpixelgr8>
Toshihiro Shimizu 890ddd
typedef TRasterPT<tpixelgr16> TRasterGR16P;</tpixelgr16>
Toshihiro Shimizu 890ddd
typedef TRasterPT<tpixelgrd> TRasterGRDP;</tpixelgrd>
Toshihiro Shimizu 890ddd
typedef TRasterPT<tpixelcy> TRasterYUV422P;</tpixelcy>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif //__T_RASTER_INCLUDED