Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
shun-iwasawa 481b59
// #include "tpixelparam.h"
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
#include "tdoubleparam.h"
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TPixelParamImp {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TPixelParamImp(const TPixel32 &p)
Shinya Kitaoka 120a6e
      : m_r(new TDoubleParam(p.r / 255.0))
Shinya Kitaoka 120a6e
      , m_g(new TDoubleParam(p.g / 255.0))
Shinya Kitaoka 120a6e
      , m_b(new TDoubleParam(p.b / 255.0))
Shinya Kitaoka 120a6e
      , m_m(new TDoubleParam(p.m / 255.0))
Shinya Kitaoka 120a6e
      , m_isMatteEnabled(true) {}
Shinya Kitaoka 120a6e
  TPixelParamImp(const TPixelParamImp &src)
Shinya Kitaoka 120a6e
      : m_r(src.m_r->clone())
Shinya Kitaoka 120a6e
      , m_g(src.m_g->clone())
Shinya Kitaoka 120a6e
      , m_b(src.m_b->clone())
Shinya Kitaoka 120a6e
      , m_m(src.m_m->clone())
Shinya Kitaoka 120a6e
      , m_isMatteEnabled(src.m_isMatteEnabled) {}
Shinya Kitaoka 120a6e
  ~TPixelParamImp() {}
Shinya Kitaoka 120a6e
  TDoubleParamP m_r, m_g, m_b, m_m;
Shinya Kitaoka 120a6e
  bool m_isMatteEnabled;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TPixelParam, "pixelParam")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPixelParam::TPixelParam(const TPixel32 &p) : m_data(new TPixelParamImp(p)) {
Shinya Kitaoka 120a6e
  addParam(m_data->m_r, "Red");
Shinya Kitaoka 120a6e
  addParam(m_data->m_g, "Green");
Shinya Kitaoka 120a6e
  addParam(m_data->m_b, "Blue");
Shinya Kitaoka 120a6e
  addParam(m_data->m_m, "Alpha");
Shinya Kitaoka 120a6e
  std::string measureName("colorChannel");
Shinya Kitaoka 120a6e
  m_data->m_r->setMeasureName(measureName);
Shinya Kitaoka 120a6e
  m_data->m_g->setMeasureName(measureName);
Shinya Kitaoka 120a6e
  m_data->m_b->setMeasureName(measureName);
Shinya Kitaoka 120a6e
  m_data->m_m->setMeasureName(measureName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPixelParam::TPixelParam(const TPixelParam &src)
Shinya Kitaoka 120a6e
    : TParamSet(src.getName()), m_data(new TPixelParamImp(*src.m_data)) {
Shinya Kitaoka 120a6e
  addParam(m_data->m_r, "Red");
Shinya Kitaoka 120a6e
  addParam(m_data->m_g, "Green");
Shinya Kitaoka 120a6e
  addParam(m_data->m_b, "Blue");
Shinya Kitaoka 120a6e
  addParam(m_data->m_m, "Alpha");
Shinya Kitaoka 120a6e
  std::string measureName("colorChannel");
Shinya Kitaoka 120a6e
  m_data->m_r->setMeasureName(measureName);
Shinya Kitaoka 120a6e
  m_data->m_g->setMeasureName(measureName);
Shinya Kitaoka 120a6e
  m_data->m_b->setMeasureName(measureName);
Shinya Kitaoka 120a6e
  m_data->m_m->setMeasureName(measureName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TPixelParam::copy(TParam *src) {
Shinya Kitaoka 120a6e
  TPixelParam *p = dynamic_cast<tpixelparam *="">(src);</tpixelparam>
Shinya Kitaoka 120a6e
  if (!p) throw TException("invalid source for copy");
Shinya Kitaoka 120a6e
  setName(src->getName());
Shinya Kitaoka 120a6e
  m_data->m_r->copy(p->m_data->m_r.getPointer());
Shinya Kitaoka 120a6e
  m_data->m_g->copy(p->m_data->m_g.getPointer());
Shinya Kitaoka 120a6e
  m_data->m_b->copy(p->m_data->m_b.getPointer());
Shinya Kitaoka 120a6e
  m_data->m_m->copy(p->m_data->m_m.getPointer());
Shinya Kitaoka 120a6e
  std::string measureName("colorChannel");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_data->m_r->setMeasureName(measureName);
Shinya Kitaoka 120a6e
  m_data->m_g->setMeasureName(measureName);
Shinya Kitaoka 120a6e
  m_data->m_b->setMeasureName(measureName);
Shinya Kitaoka 120a6e
  m_data->m_m->setMeasureName(measureName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPixelParam::~TPixelParam() { delete m_data; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPixel32 TPixelParam::getDefaultValue() const {
Shinya Kitaoka 120a6e
  TPixelD pixd(m_data->m_r->getDefaultValue(), m_data->m_g->getDefaultValue(),
Shinya Kitaoka 120a6e
               m_data->m_b->getDefaultValue(), m_data->m_m->getDefaultValue());
Shinya Kitaoka 120a6e
  return toPixel32(pixd);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TPixelParam::setDefaultValue(const TPixel32 &p) {
Shinya Kitaoka 120a6e
  TPixelD pixd = toPixelD(p);
Shinya Kitaoka 120a6e
  m_data->m_r->setDefaultValue(pixd.r);
Shinya Kitaoka 120a6e
  m_data->m_g->setDefaultValue(pixd.g);
Shinya Kitaoka 120a6e
  m_data->m_b->setDefaultValue(pixd.b);
Shinya Kitaoka 120a6e
  m_data->m_m->setDefaultValue(pixd.m);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPixelD TPixelParam::getValueD(double frame) const {
Shinya Kitaoka 120a6e
  return TPixelD(m_data->m_r->getValue(frame), m_data->m_g->getValue(frame),
Shinya Kitaoka 120a6e
                 m_data->m_b->getValue(frame), m_data->m_m->getValue(frame));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPixel32 TPixelParam::getValue(double frame) const {
Shinya Kitaoka 120a6e
  return toPixel32(getValueD(frame));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 481b59
TPixel32 TPixelParam::getValue(double frame, bool linear,
shun-iwasawa 481b59
                               double colorSpaceGamma) const {
shun-iwasawa 481b59
  if (!linear) return getValue(frame);
shun-iwasawa 481b59
  return toPixel32(toLinear(getValueD(frame), colorSpaceGamma));
shun-iwasawa 481b59
}
shun-iwasawa 481b59
shun-iwasawa 481b59
//---------------------------------------------------------
shun-iwasawa 481b59
Shinya Kitaoka 120a6e
TPixel64 TPixelParam::getValue64(double frame) const {
Shinya Kitaoka 120a6e
  return toPixel64(getValueD(frame));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TPixel32 TPixelParam::getPremultipliedValue(double frame) const {
Shinya Kitaoka 120a6e
  return premultiply(getValue(frame));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TPixelParam::setValueD(double frame, const TPixelD &p) {
Shinya Kitaoka 120a6e
  beginParameterChange();
Shinya Kitaoka 120a6e
  m_data->m_r->setValue(frame, p.r);
Shinya Kitaoka 120a6e
  m_data->m_g->setValue(frame, p.g);
Shinya Kitaoka 120a6e
  m_data->m_b->setValue(frame, p.b);
Shinya Kitaoka 120a6e
  m_data->m_m->setValue(frame, p.m);
Shinya Kitaoka 120a6e
  endParameterChange();
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TPixelParam::setValue(double frame, const TPixel32 &pix) {
Shinya Kitaoka 120a6e
  return setValueD(frame, toPixelD(pix));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TPixelParam::setValue64(double frame, const TPixel64 &pix) {
Shinya Kitaoka 120a6e
  return setValueD(frame, toPixelD(pix));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TPixelParam::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  std::string childName;
Shinya Kitaoka 120a6e
  while (is.openChild(childName)) {
Shinya Kitaoka 120a6e
    if (childName == "red")
Shinya Kitaoka 120a6e
      m_data->m_r->loadData(is);
Shinya Kitaoka 120a6e
    else if (childName == "green")
Shinya Kitaoka 120a6e
      m_data->m_g->loadData(is);
Shinya Kitaoka 120a6e
    else if (childName == "blue")
Shinya Kitaoka 120a6e
      m_data->m_b->loadData(is);
Shinya Kitaoka 120a6e
    else if (childName == "matte")
Shinya Kitaoka 120a6e
      m_data->m_m->loadData(is);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      throw TException("unknown channel name: " + childName);
Shinya Kitaoka 120a6e
    is.closeChild();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TPixelParam::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os.openChild("red");
Shinya Kitaoka 120a6e
  m_data->m_r->saveData(os);
Shinya Kitaoka 120a6e
  os.closeChild();
Shinya Kitaoka 120a6e
  os.openChild("green");
Shinya Kitaoka 120a6e
  m_data->m_g->saveData(os);
Shinya Kitaoka 120a6e
  os.closeChild();
Shinya Kitaoka 120a6e
  os.openChild("blue");
Shinya Kitaoka 120a6e
  m_data->m_b->saveData(os);
Shinya Kitaoka 120a6e
  os.closeChild();
Shinya Kitaoka 120a6e
  os.openChild("matte");
Shinya Kitaoka 120a6e
  m_data->m_m->saveData(os);
Shinya Kitaoka 120a6e
  os.closeChild();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TDoubleParamP &TPixelParam::getRed() { return m_data->m_r; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TDoubleParamP &TPixelParam::getGreen() { return m_data->m_g; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TDoubleParamP &TPixelParam::getBlue() { return m_data->m_b; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TDoubleParamP &TPixelParam::getMatte() { return m_data->m_m; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TPixelParam::enableMatte(bool on) {
shun-iwasawa 481b59
  m_data->m_isMatteEnabled = on;
Shinya Kitaoka 120a6e
  if (on == false) m_data->m_m = new TDoubleParam(255.0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TPixelParam::isMatteEnabled() const { return m_data->m_isMatteEnabled; }