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