Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef T_TILE_INCLUDED
Toshihiro Shimizu 890ddd
#define T_TILE_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "traster.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Toshihiro Shimizu 890ddd
#include "timagecache.h"
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
class DVAPI TTile
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	string m_rasterId;
Toshihiro Shimizu 890ddd
	TRect m_subRect;
Toshihiro Shimizu 890ddd
	TTile(const TTile &);
Toshihiro Shimizu 890ddd
	TTile &operator=(const TTile &);
Toshihiro Shimizu 890ddd
	void addInCache(const TRasterP &raster);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TPointD m_pos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TTile() : m_rasterId(""), m_pos(), m_subRect() {}
Toshihiro Shimizu 890ddd
	TTile(const TRasterP &raster);
Toshihiro Shimizu 890ddd
	TTile(const TRasterP &raster, TPointD pos);
Toshihiro Shimizu 890ddd
	~TTile();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setRaster(const TRasterP &raster);
Toshihiro Shimizu 890ddd
	inline const TRasterP getRaster() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TImageP img = TImageCache::instance()->get(m_rasterId, true);
Toshihiro Shimizu 890ddd
		TRasterImageP rimg = (TRasterImageP)img;
Toshihiro Shimizu 890ddd
		if (rimg) {
Toshihiro Shimizu 890ddd
			if (m_subRect == rimg->getRaster()->getBounds())
Toshihiro Shimizu 890ddd
				return rimg->getRaster();
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				return rimg->getRaster()->extract(m_subRect.x0, m_subRect.y0, m_subRect.x1, m_subRect.y1);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TToonzImageP timg = (TToonzImageP)img;
Toshihiro Shimizu 890ddd
		if (timg) {
Toshihiro Shimizu 890ddd
			if (m_subRect == timg->getRaster()->getBounds())
Toshihiro Shimizu 890ddd
				return timg->getRaster();
Toshihiro Shimizu 890ddd
			else
Toshihiro Shimizu 890ddd
				return timg->getRaster()->extract(m_subRect.x0, m_subRect.y0, m_subRect.x1, m_subRect.y1);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return TRasterP();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif