Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
#include "tfiletype.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "timagecache.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
#include "tropcm.h"
Toshihiro Shimizu 890ddd
#include "timageinfo.h"
Toshihiro Shimizu 890ddd
#include "timage_io.h"
Toshihiro Shimizu 890ddd
#include "tlevel_io.h"
Toshihiro Shimizu 890ddd
#include "tofflinegl.h"
Toshihiro Shimizu 890ddd
#include "tgl.h"
Toshihiro Shimizu 890ddd
#include "tvectorrenderdata.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "tthreadmessage.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Toshihiro Shimizu 890ddd
#include "tmeshimage.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzExt includes
Toshihiro Shimizu 890ddd
#include "ext/meshutils.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/sceneproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshchildlevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/tstageobjectspline.h"
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
#include "toonz/sceneresources.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage2.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/icongenerator.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//    Local namespace
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
const TDimension IconSize(80, 60);
Toshihiro Shimizu 890ddd
TDimension FilmstripIconSize(0, 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//Access name-based storage
Toshihiro Shimizu 890ddd
std::set<std::string> iconsMap;</std::string>
Toshihiro Shimizu 890ddd
typedef std::set<std::string>::iterator IconIterator;</std::string>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//Returns true if the image request was already submitted.
Toshihiro Shimizu 890ddd
bool getIcon(const std::string &iconName, QPixmap &pix, TXshSimpleLevel *simpleLevel = 0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	IconIterator it;
Toshihiro Shimizu 890ddd
	it = iconsMap.find(iconName);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (it != iconsMap.end()) {
Toshihiro Shimizu 890ddd
		TImageP im = TImageCache::instance()->get(iconName, false);
Toshihiro Shimizu 890ddd
		TToonzImage *timgp = dynamic_cast<ttoonzimage *="">(im.getPointer());</ttoonzimage>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (simpleLevel && timgp) {
Toshihiro Shimizu 890ddd
			IconGenerator::Settings settings = IconGenerator::instance()->getSettings();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			TRaster32P icon(timgp->getSize());
Toshihiro Shimizu 890ddd
			icon->clear();
Toshihiro Shimizu 890ddd
			icon->fill((settings.m_blackBgCheck) ? TPixel::Black : TPixel::White);
Toshihiro Shimizu 890ddd
			if (settings.m_transparencyCheck ||
Toshihiro Shimizu 890ddd
				settings.m_inkIndex != -1 ||
Toshihiro Shimizu 890ddd
				settings.m_paintIndex != -1) {
Toshihiro Shimizu 890ddd
				TRop::CmappedQuickputSettings s;
Toshihiro Shimizu 890ddd
				s.m_globalColorScale = TPixel32::Black;
Toshihiro Shimizu 890ddd
				s.m_inksOnly = false;
Toshihiro Shimizu 890ddd
				s.m_transparencyCheck = settings.m_transparencyCheck;
Toshihiro Shimizu 890ddd
				s.m_blackBgCheck = settings.m_blackBgCheck;
Toshihiro Shimizu 890ddd
				s.m_inkIndex = settings.m_inkIndex;
Toshihiro Shimizu 890ddd
				s.m_paintIndex = settings.m_paintIndex;
Toshihiro Shimizu 890ddd
				Preferences::instance()->getTranspCheckData(s.m_transpCheckBg, s.m_transpCheckInk, s.m_transpCheckPaint);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				TRop::quickPut(icon, timgp->getRaster(), simpleLevel->getPalette(), TAffine(), s);
Toshihiro Shimizu 890ddd
			} else
Toshihiro Shimizu 890ddd
				TRop::quickPut(icon, timgp->getRaster(), simpleLevel->getPalette(), TAffine());
Toshihiro Shimizu 890ddd
			pix = rasterToQPixmap(icon, false);
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		TRasterImageP img = static_cast<trasterimagep>(im);</trasterimagep>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (!img) {
Toshihiro Shimizu 890ddd
			pix = QPixmap();
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		assert(!(TRasterGR8P)img->getRaster());
Toshihiro Shimizu 890ddd
		const TRaster32P &ras = img->getRaster();
Toshihiro Shimizu 890ddd
		pix = rasterToQPixmap(ras, false);
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void setIcon(const std::string &iconName, const TRaster32P &icon)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (iconsMap.find(iconName) != iconsMap.end())
Toshihiro Shimizu 890ddd
		TImageCache::instance()->add(iconName, TRasterImageP(icon), true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! Cache icon data in TToonzImage format if ToonzImageIconRenderer generates them
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
void setIcon_TnzImg(const std::string &iconName, const TRasterCM32P &icon)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (iconsMap.find(iconName) != iconsMap.end())
Toshihiro Shimizu 890ddd
		TImageCache::instance()->add(iconName, TToonzImageP(icon, TRect(icon->getSize())), true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void removeIcon(const std::string &iconName)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	IconIterator it;
Toshihiro Shimizu 890ddd
	it = iconsMap.find(iconName);
Toshihiro Shimizu 890ddd
	if (it != iconsMap.end()) {
Toshihiro Shimizu 890ddd
		TImageCache::instance()->remove(iconName);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	iconsMap.erase(iconName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool isUnpremultiplied(const TRaster32P &r)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int lx = r->getLx();
Toshihiro Shimizu 890ddd
	int y = r->getLy();
Toshihiro Shimizu 890ddd
	r->lock();
Toshihiro Shimizu 890ddd
	while (--y >= 0) {
Toshihiro Shimizu 890ddd
		TPixel32 *pix = r->pixels(y);
Toshihiro Shimizu 890ddd
		TPixel32 *endPix = pix + lx;
Toshihiro Shimizu 890ddd
		while (pix < endPix) {
Toshihiro Shimizu 890ddd
			if (pix->r > pix->m ||
Toshihiro Shimizu 890ddd
				pix->g > pix->m ||
Toshihiro Shimizu 890ddd
				pix->b > pix->m) {
Toshihiro Shimizu 890ddd
				r->unlock();
Toshihiro Shimizu 890ddd
				return true;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			++pix;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	r->unlock();
Toshihiro Shimizu 890ddd
	return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void makeChessBackground(const TRaster32P &ras)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	ras->lock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const TPixel32 gray1(230, 230, 230, 255), gray2(180, 180, 180, 255);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int lx = ras->getLx(), ly = ras->getLy();
Toshihiro Shimizu 890ddd
	for (int y = 0; y != ly; ++y) {
Toshihiro Shimizu 890ddd
		TPixel32 *pix = ras->pixels(y), *lineEnd = pix + lx;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int yCol = (y & 4);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (int x = 0; pix != lineEnd; ++x, ++pix)
Toshihiro Shimizu 890ddd
			if (pix->m != 255)
Toshihiro Shimizu 890ddd
				*pix = overPix((x & 4) == yCol ? gray1 : gray2, *pix);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==========================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//    Image-to-Icon convertion methods
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
TRaster32P convertToIcon(
Toshihiro Shimizu 890ddd
	TVectorImageP vimage,
Toshihiro Shimizu 890ddd
	int frame,
Toshihiro Shimizu 890ddd
	const TDimension &iconSize,
Toshihiro Shimizu 890ddd
	const IconGenerator::Settings &settings)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!vimage)
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette *plt = vimage->getPalette()->clone();
Toshihiro Shimizu 890ddd
	if (!plt)
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
	plt->setFrame(frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TOfflineGL *glContext = IconGenerator::instance()->getOfflineGLContext();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// l'immagine e' contenuta dentro imageBox (aggiungo un piccolo margine anche
Toshihiro Shimizu 890ddd
	// per evitare problemi con immagini vuote)
Toshihiro Shimizu 890ddd
	TRectD imageBox;
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		QMutexLocker sl(vimage->getMutex());
Toshihiro Shimizu 890ddd
		imageBox = vimage->getBBox().enlarge(.1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	TPointD imageCenter = (imageBox.getP00() + imageBox.getP11()) * 0.5;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// calcolo una matrice di trasformazione che sposti l'immagine dentro l'icona.
Toshihiro Shimizu 890ddd
	// il fattore di scala e' scelto in modo che l'immagine sia interamente
Toshihiro Shimizu 890ddd
	// contenuta nell'icona (con un margine di 'margin' pixel)
Toshihiro Shimizu 890ddd
	const int margin = 10;
Toshihiro Shimizu 890ddd
	double scx = (iconSize.lx - margin) / imageBox.getLx();
Toshihiro Shimizu 890ddd
	double scy = (iconSize.ly - margin) / imageBox.getLy();
Toshihiro Shimizu 890ddd
	double sc = tmin(scx, scy);
Toshihiro Shimizu 890ddd
	// aggiungo la traslazione: il punto centrale dell'immagine va nel punto
Toshihiro Shimizu 890ddd
	// centrale della pixmap
Toshihiro Shimizu 890ddd
	TPointD iconCenter(iconSize.lx * 0.5, iconSize.ly * 0.5);
Toshihiro Shimizu 890ddd
	TAffine aff = TScale(sc).place(imageCenter, iconCenter);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// RenderData
Toshihiro Shimizu 890ddd
	TVectorRenderData rd(
Toshihiro Shimizu 890ddd
		aff,
Toshihiro Shimizu 890ddd
		TRect(iconSize),
Toshihiro Shimizu 890ddd
		plt,
Toshihiro Shimizu 890ddd
		0, true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	rd.m_tcheckEnabled = settings.m_transparencyCheck;
Toshihiro Shimizu 890ddd
	rd.m_blackBgEnabled = settings.m_blackBgCheck;
Toshihiro Shimizu 890ddd
	rd.m_drawRegions = !settings.m_inksOnly;
Toshihiro Shimizu 890ddd
	rd.m_inkCheckEnabled = settings.m_inkIndex != -1;
Toshihiro Shimizu 890ddd
	rd.m_paintCheckEnabled = settings.m_paintIndex != -1;
Toshihiro Shimizu 890ddd
	rd.m_colorCheckIndex = rd.m_inkCheckEnabled ? settings.m_inkIndex : settings.m_paintIndex;
Toshihiro Shimizu 890ddd
	rd.m_isIcon = true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// disegno l'immagine
Toshihiro Shimizu 890ddd
	glContext->makeCurrent();
Toshihiro Shimizu 890ddd
	glContext->clear(rd.m_blackBgEnabled ? TPixel::Black : TPixel32::White);
Toshihiro Shimizu 890ddd
	glContext->draw(vimage, rd);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P ras(iconSize);
Toshihiro Shimizu 890ddd
	glContext->getRaster(ras);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glContext->doneCurrent();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	delete plt;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return ras;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P convertToIcon(
Toshihiro Shimizu 890ddd
	TToonzImageP timage,
Toshihiro Shimizu 890ddd
	int frame,
Toshihiro Shimizu 890ddd
	const TDimension &iconSize,
Toshihiro Shimizu 890ddd
	const IconGenerator::Settings &settings)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!timage)
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPalette *plt = timage->getPalette();
Toshihiro Shimizu 890ddd
	if (!plt)
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	plt->setFrame(frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterCM32P rasCM32 = timage->getRaster();
Toshihiro Shimizu 890ddd
	if (!rasCM32.getPointer())
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int lx = rasCM32->getSize().lx;
Toshihiro Shimizu 890ddd
	int ly = rasCM32->getSize().ly;
Toshihiro Shimizu 890ddd
	int iconLx = iconSize.lx, iconLy = iconSize.ly;
Toshihiro Shimizu 890ddd
	if (tmax(double(lx) / iconSize.lx, double(ly) / iconSize.ly) == double(ly) / iconSize.ly)
Toshihiro Shimizu 890ddd
		iconLx = tround((double(lx) * iconSize.ly) / ly);
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		iconLy = tround((double(ly) * iconSize.lx) / lx);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDimension iconSize2 = TDimension(iconLx, iconLy); // dimensione dell'icona con aspectRatio esatto
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P icon(iconSize2);
Toshihiro Shimizu 890ddd
	icon->clear();
Toshihiro Shimizu 890ddd
	icon->fill(settings.m_blackBgCheck ? TPixel::Black : TPixel::White);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDimension dim = rasCM32->getSize();
Toshihiro Shimizu 890ddd
	if (dim != iconSize2) {
Toshihiro Shimizu 890ddd
		TRasterCM32P auxCM32(icon->getSize());
Toshihiro Shimizu 890ddd
		auxCM32->clear();
Toshihiro Shimizu 890ddd
		TRop::makeIcon(auxCM32, rasCM32);
Toshihiro Shimizu 890ddd
		rasCM32 = auxCM32;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (settings.m_transparencyCheck ||
Toshihiro Shimizu 890ddd
		settings.m_inksOnly ||
Toshihiro Shimizu 890ddd
		settings.m_inkIndex != -1 ||
Toshihiro Shimizu 890ddd
		settings.m_paintIndex != -1) {
Toshihiro Shimizu 890ddd
		TRop::CmappedQuickputSettings s;
Toshihiro Shimizu 890ddd
		s.m_globalColorScale = TPixel32::Black;
Toshihiro Shimizu 890ddd
		s.m_inksOnly = settings.m_inksOnly;
Toshihiro Shimizu 890ddd
		s.m_transparencyCheck = settings.m_transparencyCheck;
Toshihiro Shimizu 890ddd
		s.m_blackBgCheck = settings.m_blackBgCheck;
Toshihiro Shimizu 890ddd
		s.m_inkIndex = settings.m_inkIndex;
Toshihiro Shimizu 890ddd
		s.m_paintIndex = settings.m_paintIndex;
Toshihiro Shimizu 890ddd
		Preferences::instance()->getTranspCheckData(s.m_transpCheckBg, s.m_transpCheckInk, s.m_transpCheckPaint);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRop::quickPut(icon, rasCM32, timage->getPalette(), TAffine(), s);
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		TRop::quickPut(icon, rasCM32, timage->getPalette(), TAffine());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(iconSize2.lx <= iconSize.lx && iconSize2.ly <= iconSize.ly);
Toshihiro Shimizu 890ddd
	TRaster32P outIcon(iconSize);
Toshihiro Shimizu 890ddd
	outIcon->clear();
Toshihiro Shimizu 890ddd
	int dx = (outIcon->getLx() - icon->getLx()) / 2;
Toshihiro Shimizu 890ddd
	int dy = (outIcon->getLy() - icon->getLy()) / 2;
Toshihiro Shimizu 890ddd
	assert(dx >= 0 && dy >= 0);
Toshihiro Shimizu 890ddd
	TRect box = outIcon->getBounds().enlarge(-dx, -dy);
Toshihiro Shimizu 890ddd
	TRop::copy(outIcon->extract(box), icon);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return outIcon;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P convertToIcon(
Toshihiro Shimizu 890ddd
	TRasterImageP rimage,
Toshihiro Shimizu 890ddd
	const TDimension &iconSize)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!rimage)
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterP ras = rimage->getRaster();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!(TRaster32P)ras && !(TRasterGR8P)ras)
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (ras->getSize() == iconSize)
Toshihiro Shimizu 890ddd
		return ras;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P icon(iconSize);
Toshihiro Shimizu 890ddd
	icon->fill(TPixel32(235, 235, 235));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double sx = (double)icon->getLx() / ras->getLx();
Toshihiro Shimizu 890ddd
	double sy = (double)icon->getLy() / ras->getLy();
Toshihiro Shimizu 890ddd
	double sc = sx < sy ? sx : sy;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TAffine aff = TScale(sc).place(ras->getCenterD(), icon->getCenterD());
Toshihiro Shimizu 890ddd
	TRop::resample(icon, ras, aff, TRop::Bilinear);
Toshihiro Shimizu 890ddd
	TRop::addBackground(icon, TPixel32::White);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return icon;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P convertToIcon(
Toshihiro Shimizu 890ddd
	TMeshImageP mi,
Toshihiro Shimizu 890ddd
	int frame,
Toshihiro Shimizu 890ddd
	const TDimension &iconSize,
Toshihiro Shimizu 890ddd
	const IconGenerator::Settings &settings)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!mi)
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TOfflineGL *glContext = IconGenerator::instance()->getOfflineGLContext();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// l'immagine e' contenuta dentro imageBox (aggiungo un piccolo margine anche
Toshihiro Shimizu 890ddd
	// per evitare problemi con immagini vuote)
Toshihiro Shimizu 890ddd
	TRectD imageBox;
Toshihiro Shimizu 890ddd
	imageBox = mi->getBBox().enlarge(.1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD imageCenter(0.5 * (imageBox.getP00() + imageBox.getP11()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// calcolo una matrice di trasformazione che sposti l'immagine dentro l'icona.
Toshihiro Shimizu 890ddd
	// il fattore di scala e' scelto in modo che l'immagine sia interamente
Toshihiro Shimizu 890ddd
	// contenuta nell'icona (con un margine di 'margin' pixel)
Toshihiro Shimizu 890ddd
	const int margin = 10;
Toshihiro Shimizu 890ddd
	double scx = (iconSize.lx - margin) / imageBox.getLx();
Toshihiro Shimizu 890ddd
	double scy = (iconSize.ly - margin) / imageBox.getLy();
Toshihiro Shimizu 890ddd
	double sc = tmin(scx, scy);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// aggiungo la traslazione: il punto centrale dell'immagine va nel punto
Toshihiro Shimizu 890ddd
	// centrale della pixmap
Toshihiro Shimizu 890ddd
	TPointD iconCenter(iconSize.lx * 0.5, iconSize.ly * 0.5);
Toshihiro Shimizu 890ddd
	TAffine aff = TScale(sc).place(imageCenter, iconCenter);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// disegno l'immagine
Toshihiro Shimizu 890ddd
	glContext->makeCurrent();
Toshihiro Shimizu 890ddd
	glContext->clear(settings.m_blackBgCheck ? TPixel::Black : TPixel32::White);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
Toshihiro Shimizu 890ddd
	glEnable(GL_BLEND);
Toshihiro Shimizu 890ddd
	glEnable(GL_LINE_SMOOTH);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glPushMatrix();
Toshihiro Shimizu 890ddd
	tglMultMatrix(aff);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glColor4f(0.0f, 1.0f, 0.0f, 0.7f);
Toshihiro Shimizu 890ddd
	tglDrawEdges(*mi);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glPopMatrix();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glPopAttrib();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P ras(iconSize);
Toshihiro Shimizu 890ddd
	glContext->getRaster(ras);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glContext->doneCurrent();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return ras;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P convertToIcon(
Toshihiro Shimizu 890ddd
	TImageP image,
Toshihiro Shimizu 890ddd
	int frame,
Toshihiro Shimizu 890ddd
	const TDimension &iconSize,
Toshihiro Shimizu 890ddd
	const IconGenerator::Settings &settings)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRasterImageP ri(image);
Toshihiro Shimizu 890ddd
	if (ri)
Toshihiro Shimizu 890ddd
		return convertToIcon(ri, iconSize);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TToonzImageP ti(image);
Toshihiro Shimizu 890ddd
	if (ti)
Toshihiro Shimizu 890ddd
		return convertToIcon(ti, frame, iconSize, settings);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TVectorImageP vi(image);
Toshihiro Shimizu 890ddd
	if (vi)
Toshihiro Shimizu 890ddd
		return convertToIcon(vi, frame, iconSize, settings);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TMeshImageP mi(image);
Toshihiro Shimizu 890ddd
	if (mi)
Toshihiro Shimizu 890ddd
		return convertToIcon(mi, frame, iconSize, settings);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return TRaster32P();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//============================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//    IconRenderer class
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//----------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class IconRenderer : public TThread::Runnable
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRaster32P m_icon;
Toshihiro Shimizu 890ddd
	TDimension m_iconSize;
Toshihiro Shimizu 890ddd
	std::string m_id;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_started;
Toshihiro Shimizu 890ddd
	bool m_terminated;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	IconRenderer(const std::string &id, const TDimension &iconSize);
Toshihiro Shimizu 890ddd
	virtual ~IconRenderer();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void run() = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setIcon(const TRaster32P &icon) { m_icon = icon; }
Toshihiro Shimizu 890ddd
	TRaster32P getIcon() const { return m_icon; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDimension getIconSize() { return m_iconSize; }
Toshihiro Shimizu 890ddd
	const std::string &getId() const { return m_id; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool &hasStarted() { return m_started; }
Toshihiro Shimizu 890ddd
	bool &wasTerminated() { return m_terminated; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
IconRenderer::IconRenderer(const std::string &id, const TDimension &iconSize)
Toshihiro Shimizu 890ddd
	: m_icon(), m_iconSize(iconSize), m_id(id), m_started(false), m_terminated(false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(started(TThread::RunnableP)), IconGenerator::instance(), SLOT(onStarted(TThread::RunnableP)));
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(finished(TThread::RunnableP)), IconGenerator::instance(), SLOT(onFinished(TThread::RunnableP)));
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(canceled(TThread::RunnableP)), IconGenerator::instance(), SLOT(onCanceled(TThread::RunnableP)),
Toshihiro Shimizu 890ddd
			Qt::QueuedConnection);
Toshihiro Shimizu 890ddd
	connect(this, SIGNAL(terminated(TThread::RunnableP)), IconGenerator::instance(), SLOT(onTerminated(TThread::RunnableP)),
Toshihiro Shimizu 890ddd
			Qt::QueuedConnection);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
IconRenderer::~IconRenderer()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//    Specific icon renderers
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//======================================
Toshihiro Shimizu 890ddd
//    VectorImageIconRenderer class
Toshihiro Shimizu 890ddd
//--------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class VectorImageIconRenderer : public IconRenderer
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TVectorImageP m_vimage;
Toshihiro Shimizu 890ddd
	TXshSimpleLevelP m_sl;
Toshihiro Shimizu 890ddd
	TFrameId m_fid;
Toshihiro Shimizu 890ddd
	IconGenerator::Settings m_settings;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	VectorImageIconRenderer(
Toshihiro Shimizu 890ddd
		const std::string &id,
Toshihiro Shimizu 890ddd
		const TDimension &iconSize,
Toshihiro Shimizu 890ddd
		TXshSimpleLevelP sl,
Toshihiro Shimizu 890ddd
		const TFrameId &fid,
Toshihiro Shimizu 890ddd
		const IconGenerator::Settings &settings)
Toshihiro Shimizu 890ddd
		: IconRenderer(id, iconSize), m_vimage(), m_sl(sl), m_fid(fid), m_settings(settings) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	VectorImageIconRenderer(
Toshihiro Shimizu 890ddd
		const std::string &id,
Toshihiro Shimizu 890ddd
		const TDimension &iconSize,
Toshihiro Shimizu 890ddd
		TVectorImageP vimage,
Toshihiro Shimizu 890ddd
		const IconGenerator::Settings &settings)
Toshihiro Shimizu 890ddd
		: IconRenderer(id, iconSize), m_vimage(vimage), m_sl(0), m_fid(-1), m_settings(settings) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P generateRaster(const TDimension &iconSize) const;
Toshihiro Shimizu 890ddd
	void run();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P VectorImageIconRenderer::generateRaster(const TDimension &iconSize) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TVectorImageP vimage;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int frame = 0;
Toshihiro Shimizu 890ddd
	if (!m_vimage) {
Toshihiro Shimizu 890ddd
		assert(m_sl);
Toshihiro Shimizu 890ddd
		if (!m_sl->isFid(m_fid))
Toshihiro Shimizu 890ddd
			return TRaster32P();
Toshihiro Shimizu 890ddd
		TImageP image = m_sl->getFrameIcon(m_fid);
Toshihiro Shimizu 890ddd
		if (!image)
Toshihiro Shimizu 890ddd
			return TRaster32P();
Toshihiro Shimizu 890ddd
		vimage = (TVectorImageP)image;
Toshihiro Shimizu 890ddd
		if (!vimage)
Toshihiro Shimizu 890ddd
			return TRaster32P();
Toshihiro Shimizu 890ddd
		frame = m_sl->guessIndex(m_fid);
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		vimage = m_vimage;
Toshihiro Shimizu 890ddd
	assert(vimage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P ras(convertToIcon(vimage, frame, iconSize, m_settings));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return ras;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void VectorImageIconRenderer::run()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		TRaster32P ras(generateRaster(getIconSize()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (ras)
Toshihiro Shimizu 890ddd
			setIcon(ras);
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//======================================
Toshihiro Shimizu 890ddd
//    SplineImageIconRenderer class
Toshihiro Shimizu 890ddd
//--------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class SplineIconRenderer : public IconRenderer
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TStageObjectSpline *m_spline;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	SplineIconRenderer(const std::string &id, const TDimension &iconSize, TStageObjectSpline *spline)
Toshihiro Shimizu 890ddd
		: IconRenderer(id, iconSize), m_spline(spline) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P generateRaster(const TDimension &iconSize) const;
Toshihiro Shimizu 890ddd
	void run();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P SplineIconRenderer::generateRaster(const TDimension &iconSize) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//get the glContext
Toshihiro Shimizu 890ddd
	TOfflineGL *glContext = IconGenerator::instance()->getOfflineGLContext();
Toshihiro Shimizu 890ddd
	glContext->makeCurrent();
Toshihiro Shimizu 890ddd
	glContext->clear(TPixel32::White);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const TStroke *stroke = m_spline->getStroke();
Toshihiro Shimizu 890ddd
	assert(stroke);
Toshihiro Shimizu 890ddd
	if (!stroke)
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
	TRectD sbbox = stroke->getBBox();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	glColor3d(0, 0, 0);
Toshihiro Shimizu 890ddd
	double scaleX = 1, scaleY = 1;
Toshihiro Shimizu 890ddd
	if (sbbox.getLx() > 0.0)
Toshihiro Shimizu 890ddd
		scaleX = (double)iconSize.lx / sbbox.getLx();
Toshihiro Shimizu 890ddd
	if (sbbox.getLy() > 0.0)
Toshihiro Shimizu 890ddd
		scaleY = (double)iconSize.ly / sbbox.getLy();
Toshihiro Shimizu 890ddd
	double scale = 0.8 * tmin(scaleX, scaleY);
Toshihiro Shimizu 890ddd
	TPointD centerStroke = 0.5 * (sbbox.getP00() + sbbox.getP11());
Toshihiro Shimizu 890ddd
	TPointD centerPixmap(iconSize.lx * 0.5, iconSize.ly * 0.5);
Toshihiro Shimizu 890ddd
	glPushMatrix();
Toshihiro Shimizu 890ddd
	tglMultMatrix(TScale(scale).place(centerStroke, centerPixmap));
Toshihiro Shimizu 890ddd
	int n = 50;
Toshihiro Shimizu 890ddd
	glBegin(GL_LINE_STRIP);
Toshihiro Shimizu 890ddd
	for (int i = 0; i < n; i++)
Toshihiro Shimizu 890ddd
		tglVertex(stroke->getPoint((double)i / (double)(n - 1)));
Toshihiro Shimizu 890ddd
	glEnd();
Toshihiro Shimizu 890ddd
	glPopMatrix();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P ras(iconSize);
Toshihiro Shimizu 890ddd
	glContext->getRaster(ras);
Toshihiro Shimizu 890ddd
	glContext->doneCurrent();
Toshihiro Shimizu 890ddd
	return ras;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SplineIconRenderer::run()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRaster32P raster = generateRaster(getIconSize());
Toshihiro Shimizu 890ddd
	if (raster)
Toshihiro Shimizu 890ddd
		setIcon(raster);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//======================================
Toshihiro Shimizu 890ddd
//    RasterImageIconRenderer class
Toshihiro Shimizu 890ddd
//--------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class RasterImageIconRenderer : public IconRenderer
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXshSimpleLevelP m_sl;
Toshihiro Shimizu 890ddd
	TFrameId m_fid;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	RasterImageIconRenderer(
Toshihiro Shimizu 890ddd
		const std::string &id,
Toshihiro Shimizu 890ddd
		const TDimension &iconSize,
Toshihiro Shimizu 890ddd
		TXshSimpleLevelP sl,
Toshihiro Shimizu 890ddd
		const TFrameId &fid)
Toshihiro Shimizu 890ddd
		: IconRenderer(id, iconSize),
Toshihiro Shimizu 890ddd
		  m_sl(sl),
Toshihiro Shimizu 890ddd
		  m_fid(fid) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void run();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RasterImageIconRenderer::run()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_sl->isFid(m_fid))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TImageP image = m_sl->getFrameIcon(m_fid);
Toshihiro Shimizu 890ddd
	if (!image)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterImageP rimage = (TRasterImageP)image;
Toshihiro Shimizu 890ddd
	assert(rimage);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P icon(convertToIcon(rimage, getIconSize()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (icon)
Toshihiro Shimizu 890ddd
		setIcon(icon);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//======================================
Toshihiro Shimizu 890ddd
//    ToonzImageIconRenderer class
Toshihiro Shimizu 890ddd
//--------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ToonzImageIconRenderer : public IconRenderer
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXshSimpleLevelP m_sl;
Toshihiro Shimizu 890ddd
	TFrameId m_fid;
Toshihiro Shimizu 890ddd
	IconGenerator::Settings m_settings;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterCM32P m_tnzImgIcon;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ToonzImageIconRenderer(
Toshihiro Shimizu 890ddd
		const std::string &id,
Toshihiro Shimizu 890ddd
		const TDimension &iconSize,
Toshihiro Shimizu 890ddd
		TXshSimpleLevelP sl,
Toshihiro Shimizu 890ddd
		const TFrameId &fid,
Toshihiro Shimizu 890ddd
		const IconGenerator::Settings &settings)
Toshihiro Shimizu 890ddd
		: IconRenderer(id, iconSize), m_sl(sl), m_fid(fid), m_settings(settings), m_tnzImgIcon(0) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void run();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setIcon_TnzImg(const TRasterCM32P &timgp) { m_tnzImgIcon = timgp; }
Toshihiro Shimizu 890ddd
	TRasterCM32P getIcon_TnzImg() const { return m_tnzImgIcon; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ToonzImageIconRenderer::run()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_sl->isFid(m_fid))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TImageP image = m_sl->getFrameIcon(m_fid);
Toshihiro Shimizu 890ddd
	if (!image)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterImageP rimage(image);
Toshihiro Shimizu 890ddd
	if (rimage) {
Toshihiro Shimizu 890ddd
		TRaster32P icon(convertToIcon(rimage, getIconSize()));
Toshihiro Shimizu 890ddd
		if (icon)
Toshihiro Shimizu 890ddd
			setIcon(icon);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TToonzImageP timage = (TToonzImageP)image;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDimension iconSize(getIconSize());
Toshihiro Shimizu 890ddd
	if (!timage) {
Toshihiro Shimizu 890ddd
		TRaster32P p(iconSize.lx, iconSize.ly);
Toshihiro Shimizu 890ddd
		p->fill(TPixelRGBM32::Yellow);
Toshihiro Shimizu 890ddd
		setIcon(p);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRasterCM32P rasCM32 = timage->getRaster();
Toshihiro Shimizu 890ddd
	if (!rasCM32.getPointer())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int lx = rasCM32->getSize().lx;
Toshihiro Shimizu 890ddd
	int ly = rasCM32->getSize().ly;
Toshihiro Shimizu 890ddd
	int iconLx = iconSize.lx, iconLy = iconSize.ly;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P icon(iconSize);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	icon->fill(m_settings.m_blackBgCheck ? TPixel::Black : TPixel::White);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (lx != iconLx && ly != iconLy) {
Toshihiro Shimizu 890ddd
		// The icons stored in the tlv file don't have the required size.
Toshihiro Shimizu 890ddd
		// Fetch the original and iconize it.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		image = m_sl->getFrame(m_fid, ImageManager::dontPutInCache, 0); // 0 uses the level properties' subsampling
Toshihiro Shimizu 890ddd
		if (!image)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		timage = (TToonzImageP)image;
Toshihiro Shimizu 890ddd
		if (!timage) {
Toshihiro Shimizu 890ddd
			TRaster32P p(iconSize.lx, iconSize.ly);
Toshihiro Shimizu 890ddd
			p->fill(TPixelRGBM32::Yellow);
Toshihiro Shimizu 890ddd
			setIcon(p);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		rasCM32 = timage->getRaster();
Toshihiro Shimizu 890ddd
		if (!rasCM32.getPointer())
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRasterCM32P auxCM32(icon->getSize());
Toshihiro Shimizu 890ddd
		auxCM32->clear();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRop::makeIcon(auxCM32, rasCM32);
Toshihiro Shimizu 890ddd
		rasCM32 = auxCM32;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!m_sl->getPalette())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPaletteP plt = m_sl->getPalette()->clone();
Toshihiro Shimizu 890ddd
	if (!plt)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int frame = m_sl->guessIndex(m_fid);
Toshihiro Shimizu 890ddd
	plt->setFrame(frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setIcon_TnzImg(rasCM32);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//======================================
Toshihiro Shimizu 890ddd
//    MeshImageIconRenderer class
Toshihiro Shimizu 890ddd
//--------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class MeshImageIconRenderer : public IconRenderer
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TMeshImageP m_image;
Toshihiro Shimizu 890ddd
	TXshSimpleLevelP m_sl;
Toshihiro Shimizu 890ddd
	TFrameId m_fid;
Toshihiro Shimizu 890ddd
	IconGenerator::Settings m_settings;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	MeshImageIconRenderer(
Toshihiro Shimizu 890ddd
		const std::string &id,
Toshihiro Shimizu 890ddd
		const TDimension &iconSize,
Toshihiro Shimizu 890ddd
		TXshSimpleLevelP sl,
Toshihiro Shimizu 890ddd
		const TFrameId &fid,
Toshihiro Shimizu 890ddd
		const IconGenerator::Settings &settings)
Toshihiro Shimizu 890ddd
		: IconRenderer(id, iconSize), m_image(), m_sl(sl), m_fid(fid), m_settings(settings) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	MeshImageIconRenderer(
Toshihiro Shimizu 890ddd
		const std::string &id,
Toshihiro Shimizu 890ddd
		const TDimension &iconSize,
Toshihiro Shimizu 890ddd
		TMeshImageP image,
Toshihiro Shimizu 890ddd
		const IconGenerator::Settings &settings)
Toshihiro Shimizu 890ddd
		: IconRenderer(id, iconSize), m_image(image), m_sl(0), m_fid(-1), m_settings(settings) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P generateRaster(const TDimension &iconSize) const;
Toshihiro Shimizu 890ddd
	void run();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P MeshImageIconRenderer::generateRaster(const TDimension &iconSize) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TMeshImageP mi;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int frame = 0;
Toshihiro Shimizu 890ddd
	if (!m_image) {
Toshihiro Shimizu 890ddd
		assert(m_sl);
Toshihiro Shimizu 890ddd
		if (!m_sl->isFid(m_fid))
Toshihiro Shimizu 890ddd
			return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TImageP image = m_sl->getFrameIcon(m_fid);
Toshihiro Shimizu 890ddd
		if (!image)
Toshihiro Shimizu 890ddd
			return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		mi = (TMeshImageP)image;
Toshihiro Shimizu 890ddd
		if (!mi)
Toshihiro Shimizu 890ddd
			return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		frame = m_sl->guessIndex(m_fid);
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		mi = m_image;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(mi);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return convertToIcon(mi, frame, iconSize, m_settings);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void MeshImageIconRenderer::run()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		TRaster32P ras(generateRaster(getIconSize()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (ras)
Toshihiro Shimizu 890ddd
			setIcon(ras);
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================
Toshihiro Shimizu 890ddd
//    XsheetIconRenderer class
Toshihiro Shimizu 890ddd
//----------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class XsheetIconRenderer : public IconRenderer
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXsheet *m_xsheet;
Toshihiro Shimizu 890ddd
	int m_row;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	XsheetIconRenderer(const std::string &id, const TDimension &iconSize, TXsheet *xsheet, int row = 0)
Toshihiro Shimizu 890ddd
		: IconRenderer(id, iconSize), m_xsheet(xsheet), m_row(row)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_xsheet) {
Toshihiro Shimizu 890ddd
			assert(m_xsheet->getRefCount() > 0);
Toshihiro Shimizu 890ddd
			m_xsheet->addRef();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~XsheetIconRenderer()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_xsheet)
Toshihiro Shimizu 890ddd
			m_xsheet->release();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static std::string getId(TXshChildLevel *level, int row)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return "sub:" + toString(level->getName()) + toString(row);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P generateRaster(const TDimension &iconSize) const;
Toshihiro Shimizu 890ddd
	void run();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P XsheetIconRenderer::generateRaster(const TDimension &iconSize) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	ToonzScene *scene = m_xsheet->getScene();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P ras(iconSize);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPixel32 bgColor = scene->getProperties()->getBgColor();
Toshihiro Shimizu 890ddd
	bgColor.m = 255;
Toshihiro Shimizu 890ddd
	ras->fill(bgColor);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TImageCache::instance()->setEnabled(false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//All checks are disabled
Toshihiro Shimizu 890ddd
	scene->renderFrame(ras, m_row, m_xsheet, false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TImageCache::instance()->setEnabled(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return ras;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void XsheetIconRenderer::run()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRaster32P ras = generateRaster(getIconSize());
Toshihiro Shimizu 890ddd
	if (ras)
Toshihiro Shimizu 890ddd
		setIcon(ras);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//================================
Toshihiro Shimizu 890ddd
//    FileIconRenderer class
Toshihiro Shimizu 890ddd
//--------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class FileIconRenderer : public IconRenderer
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath m_path;
Toshihiro Shimizu 890ddd
	TFrameId m_fid;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	FileIconRenderer(
Toshihiro Shimizu 890ddd
		const TDimension &iconSize,
Toshihiro Shimizu 890ddd
		const TFilePath &path,
Toshihiro Shimizu 890ddd
		const TFrameId &fid)
Toshihiro Shimizu 890ddd
		: IconRenderer(getId(path, fid), iconSize), m_path(path), m_fid(fid) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static std::string getId(const TFilePath &path, const TFrameId &fid);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void run();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
std::string FileIconRenderer::getId(const TFilePath &path, const TFrameId &fid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::string type(path.getType());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (type == "tab" || type == "tnz" || type == "mesh" || // meshes are not currently viewable
Toshihiro Shimizu 890ddd
		TFileType::isViewable(TFileType::getInfo(path))) {
Shinya Kitaoka 3bfa54
		std::string fidNumber;
Toshihiro Shimizu 890ddd
		if (fid != TFrameId::NO_FRAME)
Toshihiro Shimizu 890ddd
			fidNumber = "frame:" + fid.expand(TFrameId::NO_PAD);
Toshihiro Shimizu 890ddd
		return "$:" + toString(path) + fidNumber;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//All the other types whose icon is the same for file type, get the same id per type.
Toshihiro Shimizu 890ddd
	else if (type == "tpl")
Toshihiro Shimizu 890ddd
		return "$:tpl";
Toshihiro Shimizu 890ddd
	else if (type == "tzp")
Toshihiro Shimizu 890ddd
		return "$:tzp";
Toshihiro Shimizu 890ddd
	else if (type == "svg")
Toshihiro Shimizu 890ddd
		return "$:svg";
Toshihiro Shimizu 890ddd
	else if (type == "tzu")
Toshihiro Shimizu 890ddd
		return "$:tzu";
Toshihiro Shimizu 890ddd
	else if (TFileType::getInfo(path) == TFileType::AUDIO_LEVEL)
Toshihiro Shimizu 890ddd
		return "$:audio";
Toshihiro Shimizu 890ddd
	else if (type == "scr")
Toshihiro Shimizu 890ddd
		return "$:scr";
Toshihiro Shimizu 890ddd
	else if (type == "mpath")
Toshihiro Shimizu 890ddd
		return "$:mpath";
Toshihiro Shimizu 890ddd
	else if (type == "curve")
Toshihiro Shimizu 890ddd
		return "$:curve";
Toshihiro Shimizu 890ddd
	else if (type == "cln")
Toshihiro Shimizu 890ddd
		return "$:cln";
Toshihiro Shimizu 890ddd
	else if (type == "tnzbat")
Toshihiro Shimizu 890ddd
		return "$:tnzbat";
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return "$:unknown";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P IconGenerator::generateVectorFileIcon(
Toshihiro Shimizu 890ddd
	const TFilePath &path,
Toshihiro Shimizu 890ddd
	const TDimension &iconSize,
Toshihiro Shimizu 890ddd
	const TFrameId &fid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TLevelReaderP lr(path);
Toshihiro Shimizu 890ddd
	TLevelP level = lr->loadInfo();
Toshihiro Shimizu 890ddd
	if (level->begin() == level->end())
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
	TFrameId frameId = fid;
Toshihiro Shimizu 890ddd
	if (fid == TFrameId::NO_FRAME)
Toshihiro Shimizu 890ddd
		frameId = level->begin()->first;
Toshihiro Shimizu 890ddd
	TImageP img = lr->getFrameReader(frameId)->load();
Toshihiro Shimizu 890ddd
	TVectorImageP vi = img;
Toshihiro Shimizu 890ddd
	if (!vi)
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
	vi->setPalette(level->getPalette());
Toshihiro Shimizu 890ddd
	VectorImageIconRenderer vir("", iconSize, vi.getPointer(), IconGenerator::Settings());
Toshihiro Shimizu 890ddd
	return vir.generateRaster(iconSize);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P IconGenerator::generateRasterFileIcon(
Toshihiro Shimizu 890ddd
	const TFilePath &path,
Toshihiro Shimizu 890ddd
	const TDimension &iconSize,
Toshihiro Shimizu 890ddd
	const TFrameId &fid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TImageP img;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		// Attempt image reading
Toshihiro Shimizu 890ddd
		TLevelReaderP lr(path);
Toshihiro Shimizu 890ddd
		TLevelP level = lr->loadInfo();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (level->begin() == level->end())
Toshihiro Shimizu 890ddd
			return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TFrameId frameId = fid;
Toshihiro Shimizu 890ddd
		if (fid == TFrameId::NO_FRAME)		 // In case no frame was specified, pick the
Toshihiro Shimizu 890ddd
			frameId = level->begin()->first; // first level frame
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TImageReaderP ir = lr->getFrameReader(frameId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (const TImageInfo *ii = ir->getImageInfo()) {
Toshihiro Shimizu 890ddd
			int shrinkX = ii->m_lx / iconSize.lx;
Toshihiro Shimizu 890ddd
			int shrinkY = ii->m_ly / iconSize.ly;
Toshihiro Shimizu 890ddd
			int shrink = shrinkX < shrinkY ? shrinkX : shrinkY;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (shrink > 1)
Toshihiro Shimizu 890ddd
				ir->setShrink(shrink);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		img = (toUpper(path.getType()) == "TLV") ? ir->loadIcon() : ir->load();
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Extract a 32-bit fullcolor raster from img
Toshihiro Shimizu 890ddd
	TRaster32P ras32;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TRasterImageP ri = img) {
Toshihiro Shimizu 890ddd
		ras32 = ri->getRaster();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (!ras32) {
Toshihiro Shimizu 890ddd
			if (TRasterGR8P rasGR8 = ri->getRaster()) {
Toshihiro Shimizu 890ddd
				TRaster32P raux(rasGR8->getSize());
Toshihiro Shimizu 890ddd
				TRop::convert(raux, rasGR8);
Toshihiro Shimizu 890ddd
				ras32 = raux;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} else if (TToonzImageP ti = img) {
Toshihiro Shimizu 890ddd
		TRasterCM32P auxRaster = ti->getRaster();
Toshihiro Shimizu 890ddd
		TRaster32P dstRaster(auxRaster->getSize());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (TPaletteP plt = ti->getPalette())
Toshihiro Shimizu 890ddd
			TRop::convert(dstRaster, auxRaster, plt, false);
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			dstRaster->fill(TPixel32::Magenta);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		ras32 = dstRaster;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!ras32)
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
    // NOTE: The following was possible with the old Qt version 4.3.3 - but in the new 4.5.0
Toshihiro Shimizu 890ddd
    // it's not: 'It is not safe to use QPixmaps outside the GUI thread'...
Toshihiro Shimizu 890ddd
    TRaster32P icon;
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
      QPixmap p(rasterToQPixmap(ras32));
Toshihiro Shimizu 890ddd
      icon = rasterFromQPixmap(
Toshihiro Shimizu 890ddd
        scalePixmapKeepingAspectRatio(p, QSize(iconSize.lx, iconSize.ly), Qt::transparent)
Toshihiro Shimizu 890ddd
        , false);
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRaster32P icon(iconSize);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double sx = double(iconSize.lx) / ras32->getLx();
Toshihiro Shimizu 890ddd
	double sy = double(iconSize.ly) / ras32->getLy();
Toshihiro Shimizu 890ddd
	double sc = tmin(sx, sy); // show all the image, possibly adding bands
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TAffine aff = TScale(sc).place(ras32->getCenterD(), icon->getCenterD());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	icon->fill(TPixel32(160, 160, 160)); // "bands" color
Toshihiro Shimizu 890ddd
	TRop::resample(icon, ras32, aff, TRop::Triangle);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (icon) {
Toshihiro Shimizu 890ddd
		if (::isUnpremultiplied(icon)) // APPALLING. I'm not touching this, but
Toshihiro Shimizu 890ddd
			TRop::premultiply(icon);   // YOU JUST CAN'T TELL IF AN IMAGE IS PREMULTIPLIED
Toshihiro Shimizu 890ddd
									   // OR NOT BY SCANNING ITS PIXELS.
Toshihiro Shimizu 890ddd
									   // You either know it FOR A GIVEN, or you don't...      >_<
Toshihiro Shimizu 890ddd
		TRectI srcBBoxI = ras32->getBounds();
Toshihiro Shimizu 890ddd
		TRectD srcBBoxD = aff * TRectD(srcBBoxI.x0, srcBBoxI.y0,
Toshihiro Shimizu 890ddd
									   srcBBoxI.x1 + 1, srcBBoxI.y1 + 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRect bbox = TRect(tfloor(srcBBoxD.x0), tceil(srcBBoxD.y0) - 1,
Toshihiro Shimizu 890ddd
						   tfloor(srcBBoxD.x1), tceil(srcBBoxD.y1) - 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		bbox = (bbox * icon->getBounds()).enlarge(-1); // Add a 1 pixel transparent margin - this
Toshihiro Shimizu 890ddd
		if (bbox.getLx() > 0 && bbox.getLy() > 0)	  // way the actual content doesn't look trimmed.
Toshihiro Shimizu 890ddd
			::makeChessBackground(icon->extract(bbox));
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		icon->fill(TPixel32(255, 0, 0));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return icon;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P IconGenerator::generateSplineFileIcon(const TFilePath &path, const TDimension &iconSize)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TStageObjectSpline *spline = new TStageObjectSpline();
Toshihiro Shimizu 890ddd
	TIStream is(path);
Toshihiro Shimizu 890ddd
	spline->loadData(is);
Toshihiro Shimizu 890ddd
	SplineIconRenderer sr("", iconSize, spline);
Toshihiro Shimizu 890ddd
	TRaster32P icon = sr.generateRaster(iconSize);
Toshihiro Shimizu 890ddd
	delete spline;
Toshihiro Shimizu 890ddd
	return icon;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P IconGenerator::generateMeshFileIcon(const TFilePath &path, const TDimension &iconSize, const TFrameId &fid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TLevelReaderP lr(path);
Toshihiro Shimizu 890ddd
	TLevelP level = lr->loadInfo();
Toshihiro Shimizu 890ddd
	if (level->begin() == level->end())
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFrameId frameId = fid;
Toshihiro Shimizu 890ddd
	if (fid == TFrameId::NO_FRAME)
Toshihiro Shimizu 890ddd
		frameId = level->begin()->first;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TMeshImageP mi = lr->getFrameReader(frameId)->load();
Toshihiro Shimizu 890ddd
	if (!mi)
Toshihiro Shimizu 890ddd
		return TRaster32P();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	MeshImageIconRenderer mir("", iconSize, mi.getPointer(), IconGenerator::Settings());
Toshihiro Shimizu 890ddd
	return mir.generateRaster(iconSize);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P IconGenerator::generateSceneFileIcon(
Toshihiro Shimizu 890ddd
	const TFilePath &path,
Toshihiro Shimizu 890ddd
	const TDimension &iconSize,
Toshihiro Shimizu 890ddd
	int row)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (row == 0 || row == TFrameId::NO_FRAME - 1) {
Toshihiro Shimizu 890ddd
		TFilePath iconPath = path.getParentDir() + "sceneIcons" + (path.getWideName() + L" .png");
Toshihiro Shimizu 890ddd
		return generateRasterFileIcon(iconPath, iconSize, TFrameId::NO_FRAME);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		//obsolete
Toshihiro Shimizu 890ddd
		ToonzScene scene;
Toshihiro Shimizu 890ddd
		scene.load(path);
Toshihiro Shimizu 890ddd
		XsheetIconRenderer ir("", iconSize, scene.getXsheet(), row);
Toshihiro Shimizu 890ddd
		return ir.generateRaster(iconSize);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FileIconRenderer::run()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TDimension iconSize(getIconSize());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		TRaster32P iconRaster;
Toshihiro Shimizu 890ddd
		std::string type(m_path.getType());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (type == "tnz" || type == "tab")
Toshihiro Shimizu 890ddd
			iconRaster = IconGenerator::generateSceneFileIcon(m_path, iconSize, m_fid.getNumber() - 1);
Toshihiro Shimizu 890ddd
		else if (type == "pli")
Toshihiro Shimizu 890ddd
			iconRaster = IconGenerator::generateVectorFileIcon(m_path, iconSize, m_fid);
Toshihiro Shimizu 890ddd
		else if (type == "tpl") {
Toshihiro Shimizu 890ddd
			QImage palette(":Resources/paletteicon.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(palette));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		} else if (type == "tzp") {
Toshihiro Shimizu 890ddd
			QImage palette(":Resources/tzpicon.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(palette));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		} else if (type == "svg") {
Toshihiro Shimizu 890ddd
			QImage palette(":Resources/svg.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(palette));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		} else if (type == "tzu") {
Toshihiro Shimizu 890ddd
			QImage palette(":Resources/tzuicon.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(palette));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		} else if (TFileType::getInfo(m_path) == TFileType::AUDIO_LEVEL) {
Toshihiro Shimizu 890ddd
			QImage loudspeaker(":Resources/audio.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(loudspeaker));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		} else if (type == "scr") {
Toshihiro Shimizu 890ddd
			QImage screensaver(":Resources/savescreen.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(screensaver));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		} else if (type == "psd") {
Toshihiro Shimizu 890ddd
			QImage psdPath(":Resources/psd.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(psdPath));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		} else if (type == "mesh")
Toshihiro Shimizu 890ddd
			iconRaster = IconGenerator::generateMeshFileIcon(m_path, iconSize, m_fid);
Toshihiro Shimizu 890ddd
		else if (TFileType::isViewable(TFileType::getInfo(m_path)) || type == "tlv")
Toshihiro Shimizu 890ddd
			iconRaster = IconGenerator::generateRasterFileIcon(m_path, iconSize, m_fid);
Toshihiro Shimizu 890ddd
		else if (type == "mpath") {
Toshihiro Shimizu 890ddd
			QImage motionPath(":Resources/motionpath.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(motionPath));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		} else if (type == "curve") {
Toshihiro Shimizu 890ddd
			QImage motionPath(":Resources/curve.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(motionPath));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		} else if (type == "cln") {
Toshihiro Shimizu 890ddd
			QImage motionPath(":Resources/cleanup.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(motionPath));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		} else if (type == "tnzbat") {
Toshihiro Shimizu 890ddd
			QImage motionPath(":Resources/tasklist.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(motionPath));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		} else if (type == "tls") {
Toshihiro Shimizu 890ddd
			QImage magpie(":Resources/magpie.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(magpie));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		} else if (type == "js") {
Toshihiro Shimizu 890ddd
			QImage script(":Resources/scripticon.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(script));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
			QImage unknown(":Resources/unknown.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(unknown));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (!iconRaster) {
Toshihiro Shimizu 890ddd
			QImage broken(":Resources/broken.png");
Toshihiro Shimizu 890ddd
			setIcon(rasterFromQImage(broken));
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		setIcon(iconRaster);
Toshihiro Shimizu 890ddd
	} catch (const TImageVersionException &) {
Toshihiro Shimizu 890ddd
		QImage unknown(":Resources/unknown.png");
Toshihiro Shimizu 890ddd
		setIcon(rasterFromQImage(unknown));
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
		QImage broken(":Resources/broken.png");
Toshihiro Shimizu 890ddd
		setIcon(rasterFromQImage(broken));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//================================
Toshihiro Shimizu 890ddd
//    SceneIconRenderer class
Toshihiro Shimizu 890ddd
//--------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class SceneIconRenderer : public IconRenderer
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	ToonzScene *m_toonzScene;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	SceneIconRenderer(const TDimension &iconSize, ToonzScene *scene)
Toshihiro Shimizu 890ddd
		: IconRenderer(getId(), iconSize), m_toonzScene(scene) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static std::string getId() { return "currentScene"; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void run();
Toshihiro Shimizu 890ddd
	TRaster32P generateIcon(const TDimension &iconSize) const;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRaster32P SceneIconRenderer::generateIcon(const TDimension &iconSize) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRaster32P ras(iconSize);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPixel32 bgColor = m_toonzScene->getProperties()->getBgColor();
Toshihiro Shimizu 890ddd
	bgColor.m = 255;
Toshihiro Shimizu 890ddd
	ras->fill(bgColor);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_toonzScene->renderFrame(ras, 0, 0, false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return ras;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SceneIconRenderer::run()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setIcon(generateIcon(getIconSize()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//    IconGenerator class
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
IconGenerator::IconGenerator() : m_iconSize(FilmstripIconSize)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_executor.setMaxActiveTasks(1); //Only one thread to render icons...
Toshihiro Shimizu 890ddd
	m_executor.setDedicatedThreads(true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
IconGenerator::~IconGenerator()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
IconGenerator *IconGenerator::instance()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	static IconGenerator _instance;
Toshihiro Shimizu 890ddd
	return &_instance;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::setFilmstripIconSize(const TDimension &dim)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FilmstripIconSize = dim;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TDimension IconGenerator::getIconSize() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return FilmstripIconSize;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TOfflineGL *IconGenerator::getOfflineGLContext()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//One context per rendering thread
Toshihiro Shimizu 890ddd
	if (!m_contexts.hasLocalData()) {
Toshihiro Shimizu 890ddd
		TDimension contextSize(tmax(FilmstripIconSize.lx, IconSize.lx), tmax(FilmstripIconSize.ly, IconSize.ly));
Toshihiro Shimizu 890ddd
		m_contexts.setLocalData(new TOfflineGL(contextSize));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return m_contexts.localData();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::addTask(const std::string &id, TThread::RunnableP iconRenderer)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	iconsMap.insert(id);
Toshihiro Shimizu 890ddd
	m_executor.addTask(iconRenderer);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QPixmap IconGenerator::getIcon(TXshLevel *xl, const TFrameId &fid, bool filmStrip, bool onDemand)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!xl)
Toshihiro Shimizu 890ddd
		return QPixmap();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TXshChildLevel *cl = xl->getChildLevel()) {
Toshihiro Shimizu 890ddd
		if (filmStrip)
Toshihiro Shimizu 890ddd
			return QPixmap();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		std::string id = XsheetIconRenderer::getId(cl, fid.getNumber() - 1);
Toshihiro Shimizu 890ddd
		QPixmap pix;
Toshihiro Shimizu 890ddd
		if (::getIcon(id, pix))
Toshihiro Shimizu 890ddd
			return pix;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (onDemand)
Toshihiro Shimizu 890ddd
			return pix;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TDimension iconSize = TDimension(80, 60);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//The icon must be calculated - add an IconRenderer task.
Toshihiro Shimizu 890ddd
		//storeIcon(id, QPixmap());   //It was automatically added by the former access
Toshihiro Shimizu 890ddd
		addTask(id, new XsheetIconRenderer(id, iconSize, cl->getXsheet()));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TXshSimpleLevel *sl = xl->getSimpleLevel()) {
Toshihiro Shimizu 890ddd
		// make thumbnails for cleanup preview and cameratest to be the same as normal TLV
Toshihiro Shimizu 890ddd
		std::string id;
Toshihiro Shimizu 890ddd
		int status = sl->getFrameStatus(fid);
Toshihiro Shimizu 890ddd
		if (sl->getType() == TZP_XSHLEVEL &&
Toshihiro Shimizu 890ddd
			status & TXshSimpleLevel::CleanupPreview) {
Toshihiro Shimizu 890ddd
			sl->setFrameStatus(fid, status & ~TXshSimpleLevel::CleanupPreview);
Toshihiro Shimizu 890ddd
			id = sl->getIconId(fid);
Toshihiro Shimizu 890ddd
			sl->setFrameStatus(fid, status);
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			id = sl->getIconId(fid);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (!filmStrip)
Toshihiro Shimizu 890ddd
			id += "_small";
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		QPixmap pix;
Toshihiro Shimizu 890ddd
		if (::getIcon(id, pix, xl->getSimpleLevel()))
Toshihiro Shimizu 890ddd
			return pix;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (onDemand)
Toshihiro Shimizu 890ddd
			return pix;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		IconGenerator::Settings oldSettings = m_settings;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// Disable transparency check for cast and xsheet icons
Toshihiro Shimizu 890ddd
		if (!filmStrip)
Toshihiro Shimizu 890ddd
			m_settings = IconGenerator::Settings();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TDimension iconSize = filmStrip ? m_iconSize : TDimension(80, 60);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//storeIcon(id, QPixmap());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int type = sl->getType();
Toshihiro Shimizu 890ddd
		switch (type) {
Toshihiro Shimizu 890ddd
		case OVL_XSHLEVEL:
Toshihiro Shimizu 890ddd
		case TZI_XSHLEVEL:
Toshihiro Shimizu 890ddd
			addTask(id, new RasterImageIconRenderer(id, iconSize, sl, fid));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			CASE PLI_XSHLEVEL : addTask(id, new VectorImageIconRenderer(id, iconSize, sl, fid, m_settings));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			CASE TZP_XSHLEVEL:
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				// Yep, we could have rasters, due to a cleanupping process
Toshihiro Shimizu 890ddd
				if (status == TXshSimpleLevel::Scanned)
Toshihiro Shimizu 890ddd
					addTask(id, new RasterImageIconRenderer(id, iconSize, sl, fid));
Toshihiro Shimizu 890ddd
				else
Toshihiro Shimizu 890ddd
					addTask(id, new ToonzImageIconRenderer(id, iconSize, sl, fid, m_settings));
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			CASE MESH_XSHLEVEL : addTask(id, new MeshImageIconRenderer(id, iconSize, sl, fid, m_settings));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		DEFAULT:
Toshihiro Shimizu 890ddd
			assert(false);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_settings = oldSettings;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return QPixmap();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::invalidate(TXshLevel *xl, const TFrameId &fid, bool onlyFilmStrip)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!xl)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (TXshSimpleLevel *sl = xl->getSimpleLevel()) {
Toshihiro Shimizu 890ddd
		std::string id = sl->getIconId(fid);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int type = sl->getType();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		switch (type) {
Toshihiro Shimizu 890ddd
		case OVL_XSHLEVEL:
Toshihiro Shimizu 890ddd
		case TZI_XSHLEVEL:
Toshihiro Shimizu 890ddd
			addTask(id, new RasterImageIconRenderer(id, getIconSize(), sl, fid));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			CASE PLI_XSHLEVEL : removeIcon(id);
Toshihiro Shimizu 890ddd
			addTask(id, new VectorImageIconRenderer(id, getIconSize(), sl, fid, m_settings));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			CASE TZP_XSHLEVEL:
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				int status = sl->getFrameStatus(fid);
Toshihiro Shimizu 890ddd
				if (status == TXshSimpleLevel::Scanned)
Toshihiro Shimizu 890ddd
					addTask(id, new RasterImageIconRenderer(id, getIconSize(), sl, fid));
Toshihiro Shimizu 890ddd
				else
Toshihiro Shimizu 890ddd
					addTask(id, new ToonzImageIconRenderer(id, getIconSize(), sl, fid, m_settings));
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			CASE MESH_XSHLEVEL : addTask(id, new MeshImageIconRenderer(id, getIconSize(), sl, fid, m_settings));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		DEFAULT:
Toshihiro Shimizu 890ddd
			assert(false);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (onlyFilmStrip)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		id += "_small";
Toshihiro Shimizu 890ddd
		if (iconsMap.find(id) == iconsMap.end())
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//Not-filmstrip icons diable all checks
Toshihiro Shimizu 890ddd
		IconGenerator::Settings oldSettings = m_settings;
Toshihiro Shimizu 890ddd
		m_settings.m_transparencyCheck = false;
Toshihiro Shimizu 890ddd
		m_settings.m_inkIndex = -1;
Toshihiro Shimizu 890ddd
		m_settings.m_paintIndex = -1;
Toshihiro Shimizu 890ddd
		m_settings.m_blackBgCheck = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		switch (type) {
Toshihiro Shimizu 890ddd
		case OVL_XSHLEVEL:
Toshihiro Shimizu 890ddd
		case TZI_XSHLEVEL:
Toshihiro Shimizu 890ddd
			addTask(id, new RasterImageIconRenderer(id, TDimension(80, 60), sl, fid));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			CASE PLI_XSHLEVEL : addTask(id, new VectorImageIconRenderer(id, TDimension(80, 60), sl, fid, m_settings));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			CASE TZP_XSHLEVEL:
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				int status = sl->getFrameStatus(fid);
Toshihiro Shimizu 890ddd
				if (status == TXshSimpleLevel::Scanned)
Toshihiro Shimizu 890ddd
					addTask(id, new RasterImageIconRenderer(id, TDimension(80, 60), sl, fid));
Toshihiro Shimizu 890ddd
				else
Toshihiro Shimizu 890ddd
					addTask(id, new ToonzImageIconRenderer(id, TDimension(80, 60), sl, fid, m_settings));
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			CASE MESH_XSHLEVEL : addTask(id, new MeshImageIconRenderer(id, TDimension(80, 60), sl, fid, m_settings));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		DEFAULT:
Toshihiro Shimizu 890ddd
			assert(false);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_settings = oldSettings;
Toshihiro Shimizu 890ddd
	} else if (TXshChildLevel *cl = xl->getChildLevel()) {
Toshihiro Shimizu 890ddd
		if (onlyFilmStrip)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		std::string id = XsheetIconRenderer::getId(cl, fid.getNumber() - 1);
Toshihiro Shimizu 890ddd
		removeIcon(id);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		getIcon(xl, fid);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::remove(TXshLevel *xl, const TFrameId &fid, bool onlyFilmStrip)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!xl)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (TXshSimpleLevel *sl = xl->getSimpleLevel()) {
Toshihiro Shimizu 890ddd
		std::string id(sl->getIconId(fid));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		removeIcon(id);
Toshihiro Shimizu 890ddd
		if (!onlyFilmStrip)
Toshihiro Shimizu 890ddd
			removeIcon(id + "_small");
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		TXshChildLevel *cl = xl->getChildLevel();
Toshihiro Shimizu 890ddd
		if (cl && !onlyFilmStrip)
Toshihiro Shimizu 890ddd
			removeIcon(XsheetIconRenderer::getId(cl, fid.getNumber() - 1));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QPixmap IconGenerator::getIcon(TStageObjectSpline *spline)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!spline)
Toshihiro Shimizu 890ddd
		return QPixmap();
Shinya Kitaoka 3bfa54
	std::string iconName = spline->getIconId();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QPixmap pix;
Toshihiro Shimizu 890ddd
	if (::getIcon(iconName, pix))
Toshihiro Shimizu 890ddd
		return pix;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//storeIcon(id, QPixmap());
Toshihiro Shimizu 890ddd
	addTask(iconName, new SplineIconRenderer(iconName, getIconSize(), spline));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return QPixmap();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::invalidate(TStageObjectSpline *spline)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!spline)
Toshihiro Shimizu 890ddd
		return;
Shinya Kitaoka 3bfa54
	std::string iconName = spline->getIconId();
Toshihiro Shimizu 890ddd
	removeIcon(iconName);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	addTask(iconName, new SplineIconRenderer(iconName, getIconSize(), spline));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::remove(TStageObjectSpline *spline)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!spline)
Toshihiro Shimizu 890ddd
		return;
Shinya Kitaoka 3bfa54
	std::string iconName = spline->getIconId();
Toshihiro Shimizu 890ddd
	removeIcon(iconName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QPixmap IconGenerator::getIcon(const TFilePath &path, const TFrameId &fid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::string id = FileIconRenderer::getId(path, fid);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QPixmap pix;
Toshihiro Shimizu 890ddd
	if (::getIcon(id, pix))
Toshihiro Shimizu 890ddd
		return pix;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	addTask(id, new FileIconRenderer(TDimension(80, 60), path, fid));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return QPixmap();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::invalidate(const TFilePath &path, const TFrameId &fid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::string id = FileIconRenderer::getId(path, fid);
Toshihiro Shimizu 890ddd
	removeIcon(id);
Toshihiro Shimizu 890ddd
	addTask(id, new FileIconRenderer(TDimension(80, 60), path, fid));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::remove(const TFilePath &path, const TFrameId &fid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	removeIcon(FileIconRenderer::getId(path, fid));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QPixmap IconGenerator::getSceneIcon(ToonzScene *scene)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::string id(SceneIconRenderer::getId());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QPixmap pix;
Toshihiro Shimizu 890ddd
	if (::getIcon(id, pix))
Toshihiro Shimizu 890ddd
		return pix;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//storeIcon(id, QPixmap());
Toshihiro Shimizu 890ddd
	addTask(id, new SceneIconRenderer(getIconSize(), scene));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return QPixmap();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::invalidateSceneIcon()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	removeIcon(SceneIconRenderer::getId());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
void IconGenerator::remap(const std::string &newIconId, const std::string &oldIconId)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	IconIterator it = iconsMap.find(oldIconId);
Toshihiro Shimizu 890ddd
	if (it == iconsMap.end())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	iconsMap.erase(it);
Toshihiro Shimizu 890ddd
	iconsMap.insert(newIconId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TImageCache::instance()->remap(newIconId, oldIconId);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::clearRequests()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_executor.cancelAll();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::clearSceneIcons()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//Eliminate all icons whose prefix is not "$:" (that is, scene-independent images).
Toshihiro Shimizu 890ddd
	//The abovementioned prefix is internally recognized by the image cache when the scene
Toshihiro Shimizu 890ddd
	//changes to avoid clearing file browser's icons.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Observe that image cache's clear function invoked during scene changes is called through
Toshihiro Shimizu 890ddd
	//the ImageManager::clear() method, including FilmStrip icons.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//note the ';' - which follows ':' in the ascii table
Toshihiro Shimizu 890ddd
	iconsMap.erase(iconsMap.begin(), iconsMap.lower_bound("$:"));
Toshihiro Shimizu 890ddd
	iconsMap.erase(iconsMap.lower_bound("$;"), iconsMap.end());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::onStarted(TThread::RunnableP iconRenderer)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	IconRenderer *ir = static_cast<iconrenderer *="">(iconRenderer.getPointer());</iconrenderer>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ir->hasStarted() = true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::onCanceled(TThread::RunnableP iconRenderer)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	IconRenderer *ir = static_cast<iconrenderer *="">(iconRenderer.getPointer());</iconrenderer>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!ir->hasStarted()) {
Toshihiro Shimizu 890ddd
		removeIcon(ir->getId());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::onFinished(TThread::RunnableP iconRenderer)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	IconRenderer *ir = static_cast<iconrenderer *="">(iconRenderer.getPointer());</iconrenderer>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// if the icon was generated in TToonzImage format, cache it instead
Toshihiro Shimizu 890ddd
	ToonzImageIconRenderer *tir = dynamic_cast<toonzimageiconrenderer *="">(ir);</toonzimageiconrenderer>
Toshihiro Shimizu 890ddd
	if (tir) {
Toshihiro Shimizu 890ddd
		TRasterCM32P timgp = tir->getIcon_TnzImg();
Toshihiro Shimizu 890ddd
		if (timgp) {
Toshihiro Shimizu 890ddd
			::setIcon_TnzImg(ir->getId(), timgp);
Toshihiro Shimizu 890ddd
			emit iconGenerated();
Toshihiro Shimizu 890ddd
			if (ir->wasTerminated())
Toshihiro Shimizu 890ddd
				m_iconsTerminationLoop.quit();
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Update the icons map
Toshihiro Shimizu 890ddd
	if (ir->getIcon()) {
Toshihiro Shimizu 890ddd
		::setIcon(ir->getId(), ir->getIcon());
Toshihiro Shimizu 890ddd
		emit iconGenerated();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (ir->wasTerminated())
Toshihiro Shimizu 890ddd
		m_iconsTerminationLoop.quit();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::onException(TThread::RunnableP iconRenderer)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	IconRenderer *ir = static_cast<iconrenderer *="">(iconRenderer.getPointer());</iconrenderer>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (ir->wasTerminated())
Toshihiro Shimizu 890ddd
		m_iconsTerminationLoop.quit();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IconGenerator::onTerminated(TThread::RunnableP iconRenderer)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	IconRenderer *ir = static_cast<iconrenderer *="">(iconRenderer.getPointer());</iconrenderer>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ir->wasTerminated() = true;
Toshihiro Shimizu 890ddd
	m_iconsTerminationLoop.exec();
Toshihiro Shimizu 890ddd
}