Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/ttileset.h"
Toshihiro Shimizu 890ddd
#include "tcodec.h"
Toshihiro Shimizu 890ddd
#include "timagecache.h"
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSet::Tile::Tile()
Toshihiro Shimizu 890ddd
	: m_rasterBounds(TRect()), m_dim(), m_pixelSize(0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSet::Tile::Tile(const TRasterP &ras, const TPoint &p)
Toshihiro Shimizu 890ddd
	: m_rasterBounds(ras->getBounds() + p), m_dim(ras->getSize()), m_pixelSize(ras->getPixelSize())
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSet::Tile::~Tile()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSet::~TTileSet()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	clearPointerContainer(m_tiles);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TTileSet::add(Tile *tile)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_tiles.push_back(tile);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
void TTileSet::getRects(std::vector<trect> &rects) const</trect>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (Tiles::const_iterator it = m_tiles.begin(); it != m_tiles.end(); ++it)
Toshihiro Shimizu 890ddd
		rects.push_back((*it)->m_rasterBounds);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRect TTileSet::getBBox() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_tiles.empty()) {
Toshihiro Shimizu 890ddd
		return TRect();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	Tiles::const_iterator it = m_tiles.begin();
Toshihiro Shimizu 890ddd
	TRect bbox = (*it)->m_rasterBounds;
Toshihiro Shimizu 890ddd
	for (; it != m_tiles.end(); ++it)
Toshihiro Shimizu 890ddd
		bbox += (*it)->m_rasterBounds;
Toshihiro Shimizu 890ddd
	return bbox;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TTileSet::getMemorySize() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int i, size = 0;
Toshihiro Shimizu 890ddd
	for (i = 0; i < m_tiles.size(); i++) {
Toshihiro Shimizu 890ddd
		size += m_tiles[i]->getSize();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return size;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSetCM32::Tile::Tile()
Toshihiro Shimizu 890ddd
	: TTileSet::Tile()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSetCM32::Tile::Tile(const TRasterCM32P &ras, const TPoint &p)
Toshihiro Shimizu 890ddd
	: TTileSet::Tile(TRasterP(ras), p)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TImageCache::instance()->add(id(), TToonzImageP(ras, ras->getBounds()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSetCM32::Tile::~Tile()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TImageCache::instance()->remove(id());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSetCM32::~TTileSetCM32()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TTileSetCM32::Tile::getRaster(TRasterCM32P &ras) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TToonzImageP timg = (TToonzImageP)TImageCache::instance()->get(id(), true);
Toshihiro Shimizu 890ddd
	if (!timg)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	ras = timg->getRaster();
Toshihiro Shimizu 890ddd
	assert(ras);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSetCM32::Tile *TTileSetCM32::Tile::clone() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Tile *tile = new Tile();
Toshihiro Shimizu 890ddd
	tile->m_rasterBounds = m_rasterBounds;
Toshihiro Shimizu 890ddd
	TToonzImageP timg = (TToonzImageP)TImageCache::instance()->get(id(), true);
Toshihiro Shimizu 890ddd
	if (!timg)
Toshihiro Shimizu 890ddd
		return tile;
Toshihiro Shimizu 890ddd
	TImageCache::instance()->add(tile->id(), timg->clone());
Toshihiro Shimizu 890ddd
	return tile;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TTileSetCM32::add(const TRasterP &ras, TRect rect)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRect bounds = ras->getBounds();
Toshihiro Shimizu 890ddd
	if (!bounds.overlaps(rect))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	rect *= bounds;
Toshihiro Shimizu 890ddd
	assert(!rect.isEmpty());
Toshihiro Shimizu 890ddd
	assert(bounds.contains(rect));
Toshihiro Shimizu 890ddd
	TTileSet::add(new Tile(ras->extract(rect)->clone(), rect.getP00()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
const TTileSetCM32::Tile *TTileSetCM32::getTile(int index) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(0 <= index && index < getTileCount());
Toshihiro Shimizu 890ddd
	TTileSetCM32::Tile *tile = dynamic_cast<ttilesetcm32::tile *="">(m_tiles[index]);</ttilesetcm32::tile>
Toshihiro Shimizu 890ddd
	assert(tile);
Toshihiro Shimizu 890ddd
	return tile;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSetCM32::Tile *TTileSetCM32::editTile(int index) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(0 <= index && index < getTileCount());
Toshihiro Shimizu 890ddd
	TTileSetCM32::Tile *tile = dynamic_cast<ttilesetcm32::tile *="">(m_tiles[index]);</ttilesetcm32::tile>
Toshihiro Shimizu 890ddd
	assert(tile);
Toshihiro Shimizu 890ddd
	return tile;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSetCM32 *TTileSetCM32::clone() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TTileSetCM32 *tileSet = new TTileSetCM32(m_srcImageSize);
Toshihiro Shimizu 890ddd
	Tiles::const_iterator it = m_tiles.begin();
Toshihiro Shimizu 890ddd
	for (; it != m_tiles.end(); ++it)
Toshihiro Shimizu 890ddd
		tileSet->m_tiles.push_back((*it)->clone());
Toshihiro Shimizu 890ddd
	return tileSet;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSetFullColor::Tile::Tile()
Toshihiro Shimizu 890ddd
	: TTileSet::Tile()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSetFullColor::Tile::Tile(const TRasterP &ras, const TPoint &p)
Toshihiro Shimizu 890ddd
	: TTileSet::Tile(ras, p)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TImageCache::instance()->add(id(), TRasterImageP(ras));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSetFullColor::Tile::~Tile()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TImageCache::instance()->remove(id());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSetFullColor::~TTileSetFullColor()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TTileSetFullColor::Tile::getRaster(TRasterP &ras) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRasterImageP img = (TRasterImageP)TImageCache::instance()->get(id(), true);
Toshihiro Shimizu 890ddd
	if (!img)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	ras = img->getRaster();
Toshihiro Shimizu 890ddd
	assert(!!ras);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSetFullColor::Tile *TTileSetFullColor::Tile::clone() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Tile *tile = new Tile();
Toshihiro Shimizu 890ddd
	tile->m_rasterBounds = m_rasterBounds;
Toshihiro Shimizu 890ddd
	TRasterImageP img = (TRasterImageP)TImageCache::instance()->get(id(), true);
Toshihiro Shimizu 890ddd
	if (!img)
Toshihiro Shimizu 890ddd
		return tile;
Toshihiro Shimizu 890ddd
	TRasterImageP clonedImage(img->getRaster()->clone());
Toshihiro Shimizu 890ddd
	TImageCache::instance()->add(tile->id(), clonedImage);
Toshihiro Shimizu 890ddd
	return tile;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TTileSetFullColor::add(const TRasterP &ras, TRect rect)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRect bounds = ras->getBounds();
Toshihiro Shimizu 890ddd
	if (!bounds.overlaps(rect))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	rect *= bounds;
Toshihiro Shimizu 890ddd
	assert(!rect.isEmpty());
Toshihiro Shimizu 890ddd
	assert(bounds.contains(rect));
Toshihiro Shimizu 890ddd
	TTileSet::add(new Tile(ras->extract(rect)->clone(), rect.getP00()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
const TTileSetFullColor::Tile *TTileSetFullColor::getTile(int index) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(0 <= index && index < getTileCount());
Toshihiro Shimizu 890ddd
	TTileSetFullColor::Tile *tile = dynamic_cast<ttilesetfullcolor::tile *="">(m_tiles[index]);</ttilesetfullcolor::tile>
Toshihiro Shimizu 890ddd
	assert(tile);
Toshihiro Shimizu 890ddd
	return tile;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TTileSetFullColor *TTileSetFullColor::clone() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TTileSetFullColor *tileSet = new TTileSetFullColor(m_srcImageSize);
Toshihiro Shimizu 890ddd
	Tiles::const_iterator it = m_tiles.begin();
Toshihiro Shimizu 890ddd
	for (; it != m_tiles.end(); ++it)
Toshihiro Shimizu 890ddd
		tileSet->m_tiles.push_back((*it)->clone());
Toshihiro Shimizu 890ddd
	return tileSet;
Toshihiro Shimizu 890ddd
}