Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/dpiscale.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshcell.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcamera.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
#include "toonz/stage.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "timagecache.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TAffine getDpiAffine(TXshSimpleLevel *level,
Toshihiro Shimizu 890ddd
					 const TFrameId &fid,
Toshihiro Shimizu 890ddd
					 bool forceFullSampling)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const double factor = Stage::inch;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (level->getType() == PLI_XSHLEVEL)
Toshihiro Shimizu 890ddd
		return TAffine();
Toshihiro Shimizu 890ddd
	LevelProperties *prop = level->getProperties();
Toshihiro Shimizu 890ddd
	TAffine aff;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::string imageId = level->getImageId(fid);
Toshihiro Shimizu 890ddd
	int frameStatus = level->getFrameStatus(fid);
Toshihiro Shimizu 890ddd
	if (frameStatus & TXshSimpleLevel::CleanupPreview) {
Toshihiro Shimizu 890ddd
		TRasterImageP ri = TImageCache::instance()->get(imageId, false);
Toshihiro Shimizu 890ddd
		if (ri) {
Toshihiro Shimizu 890ddd
			double dpix = 0, dpiy = 0;
Toshihiro Shimizu 890ddd
			ri->getDpi(dpix, dpiy);
Toshihiro Shimizu 890ddd
			if (dpix != 0.0 && dpiy != 0.0)
Toshihiro Shimizu 890ddd
				return TScale(factor / dpix, factor / dpiy);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int subs = prop->getSubsampling();
Toshihiro Shimizu 890ddd
	if (level->getType() != PLI_XSHLEVEL) {
Toshihiro Shimizu 890ddd
		TPointD dpi = level->getDpi(fid);
Toshihiro Shimizu 890ddd
		if (dpi.x != 0 && dpi.y != 0)
Toshihiro Shimizu 890ddd
			aff = TScale(factor / dpi.x, factor / dpi.y);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (!forceFullSampling)
Toshihiro Shimizu 890ddd
			TImageCache::instance()->getSubsampling(imageId, subs);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (subs != 1 && !forceFullSampling)
Toshihiro Shimizu 890ddd
		aff = TScale(subs) * aff;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return aff;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TAffine getDpiAffine(TCamera *camera)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const double factor = Stage::inch;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDimensionD size = camera->getSize();
Toshihiro Shimizu 890ddd
	TDimension res = camera->getRes();
Toshihiro Shimizu 890ddd
	double sx = factor * size.lx / res.lx;
Toshihiro Shimizu 890ddd
	double sy = factor * size.ly / res.ly;
Toshihiro Shimizu 890ddd
	return TScale(sx, sy);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPointD getCurrentDpiScale(TXshSimpleLevel *sl, const TFrameId &fid)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TAffine aff = getDpiAffine(sl, fid);
Toshihiro Shimizu 890ddd
	if ((sl->getType() == TZP_XSHLEVEL || sl->getType() == OVL_XSHLEVEL) && sl->getProperties()->getSubsampling() > 1) {
Toshihiro Shimizu 890ddd
		int subs = sl->getProperties()->getSubsampling();
Toshihiro Shimizu 890ddd
		TImageP img = TImageCache::instance()->get(sl->getImageId(fid), false);
Toshihiro Shimizu 890ddd
		TToonzImageP ti(img);
Toshihiro Shimizu 890ddd
		TRasterImageP ri(img);
Toshihiro Shimizu 890ddd
		if (ti)
Toshihiro Shimizu 890ddd
			subs = ti->getSubsampling();
Toshihiro Shimizu 890ddd
		else if (ri)
Toshihiro Shimizu 890ddd
			subs = ri->getSubsampling();
Toshihiro Shimizu 890ddd
		double f = 1.0 / subs;
Toshihiro Shimizu 890ddd
		return aff * TPointD(f, f);
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		return aff * TPointD(1, 1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef FORSE_OBSOLETO
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double getCurrentCameraStandDpi()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const double defaultDpi = 100;
Toshihiro Shimizu 890ddd
	TApplication *app = TApplication::instance();
Toshihiro Shimizu 890ddd
	if (app->isEditingLevelFrame()) {
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *sl = app->getCurrentLevel() ? app->getCurrentLevel()->getSimpleLevel() : 0;
Toshihiro Shimizu 890ddd
		if (sl) {
Toshihiro Shimizu 890ddd
			double dpi = sl->getDpi().x;
Toshihiro Shimizu 890ddd
			return dpi > 0.0 ? dpi : defaultDpi;
Toshihiro Shimizu 890ddd
			return sl->getDpi().x;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			return defaultDpi;
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		ToonzScene *scene = app->getCurrentScene();
Toshihiro Shimizu 890ddd
		TCamera *camera = scene->getCurrentCamera();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TDimensionD size = camera->getSize();
Toshihiro Shimizu 890ddd
		TDimension res = camera->getRes();
Toshihiro Shimizu 890ddd
		assert(size.lx > 0);
Toshihiro Shimizu 890ddd
		if (size.lx > 0)
Toshihiro Shimizu 890ddd
			return res.lx / size.lx;
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			return defaultDpi;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif