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