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