Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/captureparameters.h"
Toshihiro Shimizu 890ddd
#include "tiio.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
#include "tproperty.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//CaptureParameters
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
CaptureParameters::CaptureParameters()
Toshihiro Shimizu 890ddd
	: m_deviceName(L""), m_resolution(), m_brightness(0), m_contranst(0), m_useWhiteImage(false), m_upsideDown(false), m_filePath(TFilePath("+inputs")), m_increment(1), m_step(1), m_format("tif")
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
TPropertyGroup *CaptureParameters::getFileFormatProperties(std::string ext)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::map<std::string, *="" tpropertygroup="">::const_iterator it;</std::string,>
Toshihiro Shimizu 890ddd
	it = m_formatProperties.find(ext);
Toshihiro Shimizu 890ddd
	if (it == m_formatProperties.end()) {
Toshihiro Shimizu 890ddd
		TPropertyGroup *ret = Tiio::makeWriterProperties(ext);
Toshihiro Shimizu 890ddd
		m_formatProperties[ext] = ret;
Toshihiro Shimizu 890ddd
		return ret;
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		return it->second;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CaptureParameters::assign(const CaptureParameters *params)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_deviceName = params->getDeviceName();
Toshihiro Shimizu 890ddd
	m_resolution = params->getResolution();
Toshihiro Shimizu 890ddd
	m_brightness = params->getBrightness();
Toshihiro Shimizu 890ddd
	m_contranst = params->getContranst();
Toshihiro Shimizu 890ddd
	m_useWhiteImage = params->isUseWhiteImage();
Toshihiro Shimizu 890ddd
	m_upsideDown = params->isUpsideDown();
Toshihiro Shimizu 890ddd
	m_filePath = params->getFilePath();
Toshihiro Shimizu 890ddd
	m_increment = params->getIncrement();
Toshihiro Shimizu 890ddd
	m_step = params->getStep();
Toshihiro Shimizu 890ddd
	m_format = params->getFileFormat();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	std::map<std::string, *="" tpropertygroup="">::const_iterator it = params->m_formatProperties.begin();</std::string,>
Toshihiro Shimizu 890ddd
	while (it != params->m_formatProperties.end()) {
Toshihiro Shimizu 890ddd
		m_formatProperties[it->first] = it->second;
Toshihiro Shimizu 890ddd
		++it;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CaptureParameters::saveData(TOStream &os)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	os.child("deviceName") << m_deviceName;
Toshihiro Shimizu 890ddd
	os.child("reslution") << m_resolution.lx << m_resolution.ly;
Toshihiro Shimizu 890ddd
	os.child("brightness") << m_brightness;
Toshihiro Shimizu 890ddd
	os.child("contranst") << m_contranst;
Toshihiro Shimizu 890ddd
	os.child("useWhiteImage") << (int)m_useWhiteImage;
Toshihiro Shimizu 890ddd
	os.child("upsideDown") << (int)m_upsideDown;
Toshihiro Shimizu 890ddd
	os.child("filePath") << m_filePath;
Toshihiro Shimizu 890ddd
	//os.child("increment") << m_increment;
Toshihiro Shimizu 890ddd
	//os.child("step") << m_step;
Toshihiro Shimizu 890ddd
	os.child("format") << m_format;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	os.openChild("formatsProperties");
Shinya Kitaoka 3bfa54
	std::vector<std::string> fileExtensions;</std::string>
Toshihiro Shimizu 890ddd
	getFileFormatPropertiesExtensions(fileExtensions);
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)fileExtensions.size(); i++) {
Shinya Kitaoka 3bfa54
		std::string ext = fileExtensions[i];
Toshihiro Shimizu 890ddd
		TPropertyGroup *pg = getFileFormatProperties(ext);
Toshihiro Shimizu 890ddd
		assert(pg);
Shinya Kitaoka 3bfa54
		std::map<std::string, std::string=""> attr;</std::string,>
Toshihiro Shimizu 890ddd
		attr["ext"] = ext;
Toshihiro Shimizu 890ddd
		os.openChild("formatProperties", attr);
Toshihiro Shimizu 890ddd
		pg->saveData(os);
Toshihiro Shimizu 890ddd
		os.closeChild();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	os.closeChild();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CaptureParameters::loadData(TIStream &is)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::string tagName;
Toshihiro Shimizu 890ddd
	while (is.matchTag(tagName)) {
Toshihiro Shimizu 890ddd
		if (tagName == "deviceName")
Toshihiro Shimizu 890ddd
			is >> m_deviceName;
Toshihiro Shimizu 890ddd
		else if (tagName == "reslution")
Toshihiro Shimizu 890ddd
			is >> m_resolution.lx >> m_resolution.ly;
Toshihiro Shimizu 890ddd
		else if (tagName == "brightness")
Toshihiro Shimizu 890ddd
			is >> m_brightness;
Toshihiro Shimizu 890ddd
		else if (tagName == "contranst")
Toshihiro Shimizu 890ddd
			is >> m_contranst;
Toshihiro Shimizu 890ddd
		else if (tagName == "useWhiteImage") {
Toshihiro Shimizu 890ddd
			int value;
Toshihiro Shimizu 890ddd
			is >> value;
Toshihiro Shimizu 890ddd
			m_useWhiteImage = value != 0;
Toshihiro Shimizu 890ddd
		} else if (tagName == "upsideDown") {
Toshihiro Shimizu 890ddd
			int value;
Toshihiro Shimizu 890ddd
			is >> value;
Toshihiro Shimizu 890ddd
			m_upsideDown = value != 0;
Toshihiro Shimizu 890ddd
		} else if (tagName == "filePath") {
Shinya Kitaoka 3bfa54
			std::wstring str;
Toshihiro Shimizu 890ddd
			is >> str;
Toshihiro Shimizu 890ddd
			m_filePath = TFilePath(str);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		//else if(tagName == "increment")
Toshihiro Shimizu 890ddd
		//  is >> m_increment;
Toshihiro Shimizu 890ddd
		//else if(tagName == "step")
Toshihiro Shimizu 890ddd
		//  is >> m_step;
Toshihiro Shimizu 890ddd
		else if (tagName == "format")
Toshihiro Shimizu 890ddd
			is >> m_format;
Toshihiro Shimizu 890ddd
		else if (tagName == "formatsProperties") {
Toshihiro Shimizu 890ddd
			while (is.matchTag(tagName)) {
Toshihiro Shimizu 890ddd
				if (tagName == "formatProperties") {
Shinya Kitaoka 3bfa54
					std::string ext = is.getTagAttribute("ext");
Toshihiro Shimizu 890ddd
					TPropertyGroup *pg = getFileFormatProperties(ext);
Toshihiro Shimizu 890ddd
					if (ext == "avi") {
Toshihiro Shimizu 890ddd
						TPropertyGroup appProperties;
Toshihiro Shimizu 890ddd
						appProperties.loadData(is);
Toshihiro Shimizu 890ddd
						assert(appProperties.getPropertyCount() == 1);
Toshihiro Shimizu 890ddd
						if (pg->getPropertyCount() != 1) {
Toshihiro Shimizu 890ddd
							is.closeChild();
Toshihiro Shimizu 890ddd
							continue;
Toshihiro Shimizu 890ddd
						}
Toshihiro Shimizu 890ddd
						TEnumProperty *enumProp = dynamic_cast<tenumproperty *="">(pg->getProperty(0));</tenumproperty>
Toshihiro Shimizu 890ddd
						TEnumProperty *enumAppProp = dynamic_cast<tenumproperty *="">(appProperties.getProperty(0));</tenumproperty>
Toshihiro Shimizu 890ddd
						assert(enumAppProp && enumProp);
Toshihiro Shimizu 890ddd
						if (enumAppProp && enumProp) {
Toshihiro Shimizu 890ddd
							try {
Toshihiro Shimizu 890ddd
								enumProp->setValue(enumAppProp->getValue());
Toshihiro Shimizu 890ddd
							} catch (TProperty::RangeError &) {
Toshihiro Shimizu 890ddd
							}
Toshihiro Shimizu 890ddd
						} else
Toshihiro Shimizu 890ddd
							throw TException();
Toshihiro Shimizu 890ddd
					} else
Toshihiro Shimizu 890ddd
						pg->loadData(is);
Toshihiro Shimizu 890ddd
					is.closeChild();
Toshihiro Shimizu 890ddd
				} else
Toshihiro Shimizu 890ddd
					throw TException("unexpected tag: " + tagName);
Toshihiro Shimizu 890ddd
			} // end while
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			throw TException("unexpected property tag: " + tagName);
Toshihiro Shimizu 890ddd
		is.closeChild();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
void CaptureParameters::getFileFormatPropertiesExtensions(std::vector<std::string> &v) const</std::string>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	v.reserve(m_formatProperties.size());
Shinya Kitaoka 3bfa54
	std::map<std::string, *="" tpropertygroup="">::const_iterator it;</std::string,>
Toshihiro Shimizu 890ddd
	for (it = m_formatProperties.begin(); it != m_formatProperties.end(); ++it)
Toshihiro Shimizu 890ddd
		v.push_back(it->first);
Toshihiro Shimizu 890ddd
}