Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ttonecurveparam.h"
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qlist></qlist>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TToneCurveParam, "toneCurveParam")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TToneCurveParam::TToneCurveParam() : TParam() {
Shinya Kitaoka 120a6e
  m_toneChannel = RGBA;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::vector<tpointd> points;</tpointd>
Shinya Kitaoka 120a6e
  // Inserisco dei punti fuori dal range(0-255) perche' mi consentono di gestire
Shinya Kitaoka 120a6e
  // i primi punti come speciali.
Shinya Kitaoka 120a6e
  points.push_back(TPointD(-40, 0));
Shinya Kitaoka 120a6e
  points.push_back(TPointD(-20, 0));
Shinya Kitaoka 120a6e
  points.push_back(TPointD(-20, 0));
Shinya Kitaoka 120a6e
  points.push_back(TPointD(0, 0));
Shinya Kitaoka 120a6e
  points.push_back(TPointD(16, 16));
Shinya Kitaoka 120a6e
  points.push_back(TPointD(239, 239));
Shinya Kitaoka 120a6e
  points.push_back(TPointD(255, 255));
Shinya Kitaoka 120a6e
  points.push_back(TPointD(275, 255));
Shinya Kitaoka 120a6e
  points.push_back(TPointD(275, 255));
Shinya Kitaoka 120a6e
  points.push_back(TPointD(295, 255));
Shinya Kitaoka 120a6e
  m_rgbaParamSet = new TParamSet("redgreenbluealphachannel");
Shinya Kitaoka 120a6e
  m_rgbParamSet  = new TParamSet("redgreenbluechannel");
Shinya Kitaoka 120a6e
  m_rParamSet    = new TParamSet("redchannel");
Shinya Kitaoka 120a6e
  m_gParamSet    = new TParamSet("greenchannel");
Shinya Kitaoka 120a6e
  m_bParamSet    = new TParamSet("bluechannel");
Shinya Kitaoka 120a6e
  m_aParamSet    = new TParamSet("alphachannel");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_isLinear = new TBoolParam(false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < (int)points.size(); i++) {
Shinya Kitaoka 120a6e
    m_rgbaParamSet->addParam(new TPointParam(points[i]), "point");
Shinya Kitaoka 120a6e
    m_rgbParamSet->addParam(new TPointParam(points[i]), "point");
Shinya Kitaoka 120a6e
    m_rParamSet->addParam(new TPointParam(points[i]), "point");
Shinya Kitaoka 120a6e
    m_gParamSet->addParam(new TPointParam(points[i]), "point");
Shinya Kitaoka 120a6e
    m_bParamSet->addParam(new TPointParam(points[i]), "point");
Shinya Kitaoka 120a6e
    m_aParamSet->addParam(new TPointParam(points[i]), "point");
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Campbell Barton 8c6c57
static TParamSetP getClonedParamSet(TParamSetP srcParamSet) {
Shinya Kitaoka 120a6e
  TParamSetP dstParamSet = new TParamSet(srcParamSet->getName());
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < srcParamSet->getParamCount(); i++) {
Shinya Kitaoka 120a6e
    TParamP param = srcParamSet->getParam(i);
Shinya Kitaoka 120a6e
    dstParamSet->addParam(param->clone(), param->getName());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return dstParamSet;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TToneCurveParam::TToneCurveParam(const TToneCurveParam &src)
Shinya Kitaoka 120a6e
    : TParam(src.getName()) {
Shinya Kitaoka 120a6e
  m_rgbaParamSet = getClonedParamSet(src.getParamSet(RGBA));
Shinya Kitaoka 120a6e
  m_rgbParamSet  = getClonedParamSet(src.getParamSet(RGB));
Shinya Kitaoka 120a6e
  m_rParamSet    = getClonedParamSet(src.getParamSet(Red));
Shinya Kitaoka 120a6e
  m_gParamSet    = getClonedParamSet(src.getParamSet(Green));
Shinya Kitaoka 120a6e
  m_bParamSet    = getClonedParamSet(src.getParamSet(Blue));
Shinya Kitaoka 120a6e
  m_aParamSet    = getClonedParamSet(src.getParamSet(Alpha));
Shinya Kitaoka 120a6e
  m_toneChannel  = src.getCurrentChannel();
Shinya Kitaoka 120a6e
  m_isLinear     = src.getIsLinearParam()->clone();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::copy(TParam *src) {
Shinya Kitaoka 120a6e
  TToneCurveParam *p = dynamic_cast<ttonecurveparam *="">(src);</ttonecurveparam>
Shinya Kitaoka 120a6e
  if (!p) throw TException("invalid source for copy");
Shinya Kitaoka 120a6e
  setName(src->getName());
Shinya Kitaoka 120a6e
  m_rgbaParamSet->copy(p->getParamSet(RGBA).getPointer());
Shinya Kitaoka 120a6e
  m_rgbParamSet->copy(p->getParamSet(RGB).getPointer());
Shinya Kitaoka 120a6e
  m_rParamSet->copy(p->getParamSet(Red).getPointer());
Shinya Kitaoka 120a6e
  m_gParamSet->copy(p->getParamSet(Green).getPointer());
Shinya Kitaoka 120a6e
  m_bParamSet->copy(p->getParamSet(Blue).getPointer());
Shinya Kitaoka 120a6e
  m_aParamSet->copy(p->getParamSet(Alpha).getPointer());
Shinya Kitaoka 120a6e
  m_isLinear->copy(p->getIsLinearParam().getPointer());
Shinya Kitaoka 120a6e
  m_toneChannel = p->getCurrentChannel();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::addObserver(TParamObserver *observer) {
Shinya Kitaoka 120a6e
  m_rgbaParamSet->addObserver(observer);
Shinya Kitaoka 120a6e
  m_rgbParamSet->addObserver(observer);
Shinya Kitaoka 120a6e
  m_rParamSet->addObserver(observer);
Shinya Kitaoka 120a6e
  m_gParamSet->addObserver(observer);
Shinya Kitaoka 120a6e
  m_bParamSet->addObserver(observer);
Shinya Kitaoka 120a6e
  m_aParamSet->addObserver(observer);
Shinya Kitaoka 120a6e
  m_isLinear->addObserver(observer);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::removeObserver(TParamObserver *observer) {
Shinya Kitaoka 120a6e
  m_rgbaParamSet->removeObserver(observer);
Shinya Kitaoka 120a6e
  m_rgbParamSet->removeObserver(observer);
Shinya Kitaoka 120a6e
  m_rParamSet->removeObserver(observer);
Shinya Kitaoka 120a6e
  m_gParamSet->removeObserver(observer);
Shinya Kitaoka 120a6e
  m_bParamSet->removeObserver(observer);
Shinya Kitaoka 120a6e
  m_aParamSet->removeObserver(observer);
Shinya Kitaoka 120a6e
  m_isLinear->removeObserver(observer);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TParamSetP TToneCurveParam::getParamSet(ToneChannel channel) const {
Shinya Kitaoka 120a6e
  if (channel == RGBA)
Shinya Kitaoka 120a6e
    return m_rgbaParamSet;
Shinya Kitaoka 120a6e
  else if (channel == RGB)
Shinya Kitaoka 120a6e
    return m_rgbParamSet;
Shinya Kitaoka 120a6e
  else if (channel == Red)
Shinya Kitaoka 120a6e
    return m_rParamSet;
Shinya Kitaoka 120a6e
  else if (channel == Green)
Shinya Kitaoka 120a6e
    return m_gParamSet;
Shinya Kitaoka 120a6e
  else if (channel == Blue)
Shinya Kitaoka 120a6e
    return m_bParamSet;
Shinya Kitaoka 120a6e
  else if (channel == Alpha)
Shinya Kitaoka 120a6e
    return m_aParamSet;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TParamSetP TToneCurveParam::getCurrentParamSet() const {
Shinya Kitaoka 120a6e
  return getParamSet(m_toneChannel);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::setCurrentChannel(ToneChannel channel) {
Shinya Kitaoka 120a6e
  m_toneChannel = channel;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QList<tpointd> TToneCurveParam::getValue(double frame) const {</tpointd>
shun-iwasawa 0ed559
  // compute the handle angle and length
shun-iwasawa 0ed559
  // in case the handle length is 0 on one side, take the oppositte handle to
shun-iwasawa 0ed559
  // calculate the angle
shun-iwasawa 0ed559
  auto handleAngleLength = [](TPointParamP handle, TPointParamP cp,
shun-iwasawa 0ed559
                              TPointParamP opposite, double f,
shun-iwasawa 0ed559
                              bool isLeft = true) {
shun-iwasawa 0ed559
    TPointD vec_h_cp = handle->getValue(f) - cp->getValue(f);
shun-iwasawa 0ed559
    double angle;
shun-iwasawa 0ed559
    if (vec_h_cp.x == 0 && vec_h_cp.y == 0) {
shun-iwasawa 0ed559
      TPointD vec_h_op = handle->getValue(f) - opposite->getValue(f);
shun-iwasawa 0ed559
      angle            = std::atan2(vec_h_op.y, vec_h_op.x);
shun-iwasawa 0ed559
    } else
shun-iwasawa 0ed559
      angle = std::atan2(vec_h_cp.y, vec_h_cp.x);
shun-iwasawa 0ed559
shun-iwasawa 0ed559
    // make the angle continuous
shun-iwasawa 0ed559
    if (isLeft && angle < 0) angle += M_2PI;
shun-iwasawa 0ed559
    double length =
shun-iwasawa 0ed559
        std::sqrt(vec_h_cp.x * vec_h_cp.x + vec_h_cp.y * vec_h_cp.y);
shun-iwasawa 0ed559
    return TPointD(angle, length);
shun-iwasawa 0ed559
  };
shun-iwasawa 0ed559
  auto angleLengthToPos = [](TPointD anLen) {
shun-iwasawa 0ed559
    return TPointD(anLen.y * std::cos(anLen.x), anLen.y * std::sin(anLen.x));
shun-iwasawa 0ed559
  };
shun-iwasawa 0ed559
shun-iwasawa 0ed559
  std::set<double> frames;</double>
shun-iwasawa 0ed559
  getCurrentParamSet()->getKeyframes(frames);
shun-iwasawa 0ed559
  std::set<double>::iterator prevIt = frames.lower_bound(frame);</double>
shun-iwasawa 0ed559
  std::set<double>::iterator nextIt = frames.upper_bound(frame);</double>
shun-iwasawa 0ed559
  bool isNotInSegment               = getCurrentParamSet()->isKeyframe(frame) ||
shun-iwasawa 0ed559
                        prevIt == frames.begin() || nextIt == frames.end();
shun-iwasawa 0ed559
  if (prevIt != frames.begin()) prevIt--;
shun-iwasawa 0ed559
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  QList<tpointd> points;</tpointd>
shun-iwasawa 0ed559
  int pointCount = getCurrentParamSet()->getParamCount();
shun-iwasawa 0ed559
  for (i = 0; i < pointCount; i++) {
shun-iwasawa 0ed559
    // control point case or the current frame is not between the keys
shun-iwasawa 0ed559
    if (i % 3 == 0 || isNotInSegment) {
shun-iwasawa 0ed559
      TPointParamP pointParam = getCurrentParamSet()->getParam(i);
shun-iwasawa 0ed559
      points.push_back(pointParam->getValue(frame));
shun-iwasawa 0ed559
    } else {
shun-iwasawa 0ed559
      double prevF = (*prevIt);
shun-iwasawa 0ed559
      double nextF = (*nextIt);
shun-iwasawa 0ed559
      double ratio = (frame - prevF) / (nextF - prevF);
shun-iwasawa 0ed559
      if (i % 3 == 2) {  // left handle
shun-iwasawa 0ed559
        TPointParamP left_Param  = getCurrentParamSet()->getParam(i);
shun-iwasawa 0ed559
        TPointParamP cp_Param    = getCurrentParamSet()->getParam(i + 1);
shun-iwasawa 0ed559
        TPointParamP right_Param = (i == pointCount - 2)
shun-iwasawa 0ed559
                                       ? cp_Param
shun-iwasawa 0ed559
                                       : TPointParamP(getCurrentParamSet()->getParam(i + 2));
shun-iwasawa 0ed559
shun-iwasawa 0ed559
        TPointD prevAnLen =
shun-iwasawa 0ed559
            handleAngleLength(left_Param, cp_Param, right_Param, prevF);
shun-iwasawa 0ed559
        TPointD nextAnLen =
shun-iwasawa 0ed559
            handleAngleLength(left_Param, cp_Param, right_Param, nextF);
shun-iwasawa 0ed559
        // linear interpolation of angle & length
shun-iwasawa 0ed559
        TPointD handle =
shun-iwasawa 0ed559
            angleLengthToPos(prevAnLen * (1.0 - ratio) + nextAnLen * (ratio));
shun-iwasawa 0ed559
        points.push_back(cp_Param->getValue(frame) + handle);
shun-iwasawa 0ed559
      } else {  // right handle
shun-iwasawa 0ed559
        TPointParamP right_Param = getCurrentParamSet()->getParam(i);
shun-iwasawa 0ed559
        TPointParamP cp_Param    = getCurrentParamSet()->getParam(i - 1);
shun-iwasawa 0ed559
        TPointParamP left_Param =
shun-iwasawa 0ed559
            (i == 1) ? cp_Param : TPointParamP(getCurrentParamSet()->getParam(i - 2));
shun-iwasawa 0ed559
shun-iwasawa 0ed559
        TPointD prevAnLen =
shun-iwasawa 0ed559
            handleAngleLength(right_Param, cp_Param, left_Param, prevF, false);
shun-iwasawa 0ed559
        TPointD nextAnLen =
shun-iwasawa 0ed559
            handleAngleLength(right_Param, cp_Param, left_Param, nextF, false);
shun-iwasawa 0ed559
        // linear interpolation of angle & length
shun-iwasawa 0ed559
        TPointD handle =
shun-iwasawa 0ed559
            angleLengthToPos(prevAnLen * (1.0 - ratio) + nextAnLen * (ratio));
shun-iwasawa 0ed559
        points.push_back(cp_Param->getValue(frame) + handle);
shun-iwasawa 0ed559
      }
shun-iwasawa 0ed559
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return points;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::setValue(double frame, const QList<tpointd> &value,</tpointd>
Shinya Kitaoka 120a6e
                               bool undoing) {
Shinya Kitaoka 120a6e
  if (value.size() == 0) return;
Shinya Kitaoka 120a6e
  int paramCount = getCurrentParamSet()->getParamCount();
Shinya Kitaoka 120a6e
  assert(paramCount == value.size());
Shinya Kitaoka 120a6e
  int i = 0;
Shinya Kitaoka 120a6e
  for (i = 0; i < paramCount; i++) {
Shinya Kitaoka 120a6e
    TPointParamP param = getCurrentParamSet()->getParam(i);
Shinya Kitaoka 120a6e
    TPointD point      = value.at(i);
Shinya Kitaoka 120a6e
    param->setValue(frame, point);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TToneCurveParam::isLinear() const { return m_isLinear->getValue(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::setIsLinear(bool isLinear) {
Shinya Kitaoka 120a6e
  m_isLinear->setValue(isLinear);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::addValue(double frame, const QList<tpointd> &value,</tpointd>
Shinya Kitaoka 120a6e
                               int index) {
Shinya Kitaoka 120a6e
  getCurrentParamSet()->insertParam(new TPointParam(value.at(index - 1)),
Shinya Kitaoka 120a6e
                                    "point", index - 1);
Shinya Kitaoka 120a6e
  getCurrentParamSet()->insertParam(new TPointParam(value.at(index)), "point",
Shinya Kitaoka 120a6e
                                    index);
Shinya Kitaoka 120a6e
  getCurrentParamSet()->insertParam(new TPointParam(value.at(index + 1)),
Shinya Kitaoka 120a6e
                                    "point", index + 1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::removeValue(double frame, int index) {
Shinya Kitaoka 120a6e
  getCurrentParamSet()->removeParam(getCurrentParamSet()->getParam(index - 1));
Shinya Kitaoka 120a6e
  getCurrentParamSet()->removeParam(getCurrentParamSet()->getParam(index - 1));
Shinya Kitaoka 120a6e
  getCurrentParamSet()->removeParam(getCurrentParamSet()->getParam(index - 1));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::setDefaultValue(const QList<tpointd> &value) {</tpointd>
Shinya Kitaoka 120a6e
  int pointCount = value.size();
Shinya Kitaoka 120a6e
  if (pointCount == 0) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int paramCount = getCurrentParamSet()->getParamCount();
Shinya Kitaoka 120a6e
  assert(paramCount == pointCount);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < pointCount; i++) {
Shinya Kitaoka 120a6e
    TPointParamP param = getCurrentParamSet()->getParam(i);
Shinya Kitaoka 120a6e
    TPointD paramPoint(param->getValue(0));
Shinya Kitaoka 120a6e
    TPointD strokePoint(value.at(i));
Shinya Kitaoka 120a6e
    param->setDefaultValue(strokePoint);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_isLinear->setDefaultValue(false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::string TToneCurveParam::getValueAlias(double frame, int precision) {
Shinya Kitaoka 120a6e
  return getCurrentParamSet()->getValueAlias(frame, precision) +
Shinya Kitaoka 120a6e
         m_isLinear->getValueAlias(frame, precision);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TToneCurveParam::isKeyframe(double frame) const {
Shinya Kitaoka 120a6e
  if (m_rgbaParamSet->isKeyframe(frame) || m_rgbParamSet->isKeyframe(frame) ||
Shinya Kitaoka 120a6e
      m_rParamSet->isKeyframe(frame) || m_gParamSet->isKeyframe(frame) ||
Shinya Kitaoka 120a6e
      m_bParamSet->isKeyframe(frame) || m_aParamSet->isKeyframe(frame))
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::deleteKeyframe(double frame) {
Shinya Kitaoka 120a6e
  m_rgbaParamSet->deleteKeyframe(frame);
Shinya Kitaoka 120a6e
  m_rgbParamSet->deleteKeyframe(frame);
Shinya Kitaoka 120a6e
  m_rParamSet->deleteKeyframe(frame);
Shinya Kitaoka 120a6e
  m_gParamSet->deleteKeyframe(frame);
Shinya Kitaoka 120a6e
  m_bParamSet->deleteKeyframe(frame);
Shinya Kitaoka 120a6e
  m_aParamSet->deleteKeyframe(frame);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::clearKeyframes() {
Shinya Kitaoka 120a6e
  m_rgbaParamSet->clearKeyframes();
Shinya Kitaoka 120a6e
  m_rgbParamSet->clearKeyframes();
Shinya Kitaoka 120a6e
  m_rParamSet->clearKeyframes();
Shinya Kitaoka 120a6e
  m_gParamSet->clearKeyframes();
Shinya Kitaoka 120a6e
  m_bParamSet->clearKeyframes();
Shinya Kitaoka 120a6e
  m_aParamSet->clearKeyframes();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::assignKeyframe(double frame,
Shinya Kitaoka 120a6e
                                     const TSmartPointerT<tparam> &src,</tparam>
Shinya Kitaoka 120a6e
                                     double srcFrame, bool changedOnly) {
Shinya Kitaoka 120a6e
  m_rgbaParamSet->assignKeyframe(frame, src, srcFrame, changedOnly);
Shinya Kitaoka 120a6e
  m_rgbParamSet->assignKeyframe(frame, src, srcFrame, changedOnly);
Shinya Kitaoka 120a6e
  m_rParamSet->assignKeyframe(frame, src, srcFrame, changedOnly);
Shinya Kitaoka 120a6e
  m_gParamSet->assignKeyframe(frame, src, srcFrame, changedOnly);
Shinya Kitaoka 120a6e
  m_bParamSet->assignKeyframe(frame, src, srcFrame, changedOnly);
Shinya Kitaoka 120a6e
  m_aParamSet->assignKeyframe(frame, src, srcFrame, changedOnly);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::getKeyframes(std::set<double> &frames) const {</double>
Shinya Kitaoka 120a6e
  m_rgbaParamSet->getKeyframes(frames);
Shinya Kitaoka 120a6e
  m_rgbParamSet->getKeyframes(frames);
Shinya Kitaoka 120a6e
  m_rParamSet->getKeyframes(frames);
Shinya Kitaoka 120a6e
  m_gParamSet->getKeyframes(frames);
Shinya Kitaoka 120a6e
  m_bParamSet->getKeyframes(frames);
Shinya Kitaoka 120a6e
  m_aParamSet->getKeyframes(frames);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TToneCurveParam::hasKeyframes() const {
Shinya Kitaoka 120a6e
  if (m_rgbaParamSet->hasKeyframes() || m_rgbParamSet->hasKeyframes() ||
Shinya Kitaoka 120a6e
      m_rParamSet->hasKeyframes() || m_gParamSet->hasKeyframes() ||
Shinya Kitaoka 120a6e
      m_bParamSet->hasKeyframes() || m_aParamSet->hasKeyframes())
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TToneCurveParam::getNextKeyframe(double frame) const {
Shinya Kitaoka 120a6e
  std::set<double> frames;</double>
Shinya Kitaoka 120a6e
  getKeyframes(frames);
Shinya Kitaoka 120a6e
  std::set<double>::iterator it = frames.upper_bound(frame);</double>
Shinya Kitaoka 120a6e
  if (it == frames.end())
Shinya Kitaoka 120a6e
    return -1;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return std::distance(frames.begin(), it);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TToneCurveParam::getPrevKeyframe(double frame) const {
Shinya Kitaoka 120a6e
  std::set<double> frames;</double>
Shinya Kitaoka 120a6e
  getKeyframes(frames);
Shinya Kitaoka 120a6e
  std::set<double>::iterator it = frames.lower_bound(frame);</double>
Shinya Kitaoka 120a6e
  if (it == frames.begin())
Shinya Kitaoka 120a6e
    return -1;
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    --it;
Shinya Kitaoka 120a6e
    return std::distance(frames.begin(), it);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TToneCurveParam::keyframeIndexToFrame(int index) const {
Shinya Kitaoka 120a6e
  std::set<double> frames;</double>
Shinya Kitaoka 120a6e
  getKeyframes(frames);
Shinya Kitaoka 120a6e
  assert(0 <= index && index < (int)frames.size());
Shinya Kitaoka 120a6e
  std::set<double>::const_iterator it = frames.begin();</double>
Shinya Kitaoka 120a6e
  std::advance(it, index);
Shinya Kitaoka 120a6e
  return *it;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  std::string tagName;
Shinya Kitaoka 120a6e
  is.openChild(tagName);
Shinya Kitaoka 120a6e
  assert(tagName == "tonecurve");
Shinya Kitaoka 120a6e
  m_rgbaParamSet->removeAllParam();
Shinya Kitaoka 120a6e
  m_rgbaParamSet->loadData(is);
Shinya Kitaoka 120a6e
  m_rgbParamSet->removeAllParam();
Shinya Kitaoka 120a6e
  m_rgbParamSet->loadData(is);
Shinya Kitaoka 120a6e
  m_rParamSet->removeAllParam();
Shinya Kitaoka 120a6e
  m_rParamSet->loadData(is);
Shinya Kitaoka 120a6e
  m_gParamSet->removeAllParam();
Shinya Kitaoka 120a6e
  m_gParamSet->loadData(is);
Shinya Kitaoka 120a6e
  m_bParamSet->removeAllParam();
Shinya Kitaoka 120a6e
  m_bParamSet->loadData(is);
Shinya Kitaoka 120a6e
  m_aParamSet->removeAllParam();
Shinya Kitaoka 120a6e
  m_aParamSet->loadData(is);
Shinya Kitaoka 120a6e
  is.openChild(tagName);
Shinya Kitaoka 120a6e
  m_isLinear->loadData(is);
Shinya Kitaoka 120a6e
  is.closeChild();
Shinya Kitaoka 120a6e
  is.closeChild();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TToneCurveParam::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os.openChild("tonecurve");
Shinya Kitaoka 120a6e
  m_rgbaParamSet->saveData(os);
Shinya Kitaoka 120a6e
  m_rgbParamSet->saveData(os);
Shinya Kitaoka 120a6e
  m_rParamSet->saveData(os);
Shinya Kitaoka 120a6e
  m_gParamSet->saveData(os);
Shinya Kitaoka 120a6e
  m_bParamSet->saveData(os);
Shinya Kitaoka 120a6e
  m_aParamSet->saveData(os);
Shinya Kitaoka 120a6e
  os.openChild("isLineaer");
Shinya Kitaoka 120a6e
  m_isLinear->saveData(os);
Shinya Kitaoka 120a6e
  os.closeChild();
Shinya Kitaoka 120a6e
  os.closeChild();
Toshihiro Shimizu 890ddd
}