Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// YOMBParam.cpp: implementation of the CYOMBParam class.
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
#include "Windows.h"
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#include <iostream></iostream>
Toshihiro Shimizu 890ddd
#include <fstream></fstream>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
//#include <stdio.h></stdio.h>
Toshihiro Shimizu 890ddd
#include <string.h></string.h>
Toshihiro Shimizu 890ddd
#include "YOMBParam.h"
Toshihiro Shimizu 890ddd
#include "InputParam.h"
Toshihiro Shimizu 890ddd
#include "YombInputParam.h"
Toshihiro Shimizu 890ddd
#include "STColSelPic.h"
Toshihiro Shimizu 890ddd
#include "BlurMatrix.h"
Toshihiro Shimizu 890ddd
#include "SDef.h"
Toshihiro Shimizu 890ddd
#include "STColSelPic.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
// Construction/Destruction
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace std;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CYOMBParam::print()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
	char s[1024];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	OutputDebugString("   ----- YOMB Param -----\n");	
Toshihiro Shimizu 890ddd
	sprintf(s,"   Name=%s\n",m_name.c_str());
Toshihiro Shimizu 890ddd
	OutputDebugString(s);
Toshihiro Shimizu 890ddd
	sprintf(s,"   RandomSampling=%d\n",m_isRandomSampling);
Toshihiro Shimizu 890ddd
	OutputDebugString(s);
Toshihiro Shimizu 890ddd
	sprintf(s,"   ShowSelection=%d\n",m_isShowSelection);
Toshihiro Shimizu 890ddd
	OutputDebugString(s);
Toshihiro Shimizu 890ddd
	sprintf(s,"   StopAtContour=%d\n",m_isStopAtContour);
Toshihiro Shimizu 890ddd
	OutputDebugString(s);
Toshihiro Shimizu 890ddd
	sprintf(s,"   dSample=%f\n",m_dSample);
Toshihiro Shimizu 890ddd
	OutputDebugString(s);
Toshihiro Shimizu 890ddd
	sprintf(s,"   nbSample=%d\n",m_nbSample);
Toshihiro Shimizu 890ddd
	OutputDebugString(s);
Toshihiro Shimizu 890ddd
	sprintf(s,"   dA=%f\n",m_dA);
Toshihiro Shimizu 890ddd
	OutputDebugString(s);
Toshihiro Shimizu 890ddd
	sprintf(s,"   dAB=%f\n",m_dAB);
Toshihiro Shimizu 890ddd
	OutputDebugString(s);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for( vector<i_pixel>::iterator p=m_color.begin(); </i_pixel>
Toshihiro Shimizu 890ddd
		 p!=m_color.end();
Toshihiro Shimizu 890ddd
		 ++p ) {
Toshihiro Shimizu 890ddd
		sprintf(s,"   RGBM=(%d,%d,%d,%d)\n",p->r,p->g,p->b,p->m);
Toshihiro Shimizu 890ddd
		OutputDebugString(s);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	OutputDebugString("   ----------------------\n");	
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CYOMBParam::null()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_name = "";
Toshihiro Shimizu 890ddd
	m_isRandomSampling = false;
Toshihiro Shimizu 890ddd
	m_isShowSelection = false;
Toshihiro Shimizu 890ddd
	m_isStopAtContour = false;
Toshihiro Shimizu 890ddd
	m_dSample = 0.0;
Toshihiro Shimizu 890ddd
	m_nbSample = 0;
Toshihiro Shimizu 890ddd
	m_dA = 0.0;
Toshihiro Shimizu 890ddd
	m_dAB = 0.0;
Toshihiro Shimizu 890ddd
	m_color.resize(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
bool CYOMBParam::read(basic_ifstream<char> &in)</char>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	char token[1000] = "";
Toshihiro Shimizu 890ddd
	bool isBegin = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	in >> token;
Toshihiro Shimizu 890ddd
	while (in.good() || (!in.good() && isBegin && strcmp(token, "END") == 0)) {
Toshihiro Shimizu 890ddd
		if (strcmp(token, "BEGIN_YOMB") == 0)
Toshihiro Shimizu 890ddd
			isBegin = true;
Toshihiro Shimizu 890ddd
		if (isBegin && strcmp(token, "NAME") == 0)
Toshihiro Shimizu 890ddd
			in >> m_name;
Toshihiro Shimizu 890ddd
		if (isBegin && strcmp(token, "STOP_AT_CONTOUR") == 0)
Toshihiro Shimizu 890ddd
			m_isStopAtContour = true;
Toshihiro Shimizu 890ddd
		if (isBegin && strcmp(token, "RANDOM_SAMPLING") == 0)
Toshihiro Shimizu 890ddd
			m_isRandomSampling = true;
Toshihiro Shimizu 890ddd
		if (isBegin && strcmp(token, "SHOW_SELECTION") == 0)
Toshihiro Shimizu 890ddd
			m_isShowSelection = true;
Toshihiro Shimizu 890ddd
		if (isBegin && strcmp(token, "BLUR_ON_PAIR") == 0)
Toshihiro Shimizu 890ddd
			m_isBlurOnPair = true;
Toshihiro Shimizu 890ddd
		if (isBegin && strcmp(token, "DSAMPLE") == 0)
Toshihiro Shimizu 890ddd
			in >> m_dSample;
Toshihiro Shimizu 890ddd
		if (isBegin && strcmp(token, "NBSAMPLE") == 0)
Toshihiro Shimizu 890ddd
			in >> m_nbSample;
Toshihiro Shimizu 890ddd
		if (isBegin && strcmp(token, "DA") == 0)
Toshihiro Shimizu 890ddd
			in >> m_dA;
Toshihiro Shimizu 890ddd
		if (isBegin && strcmp(token, "DAB") == 0)
Toshihiro Shimizu 890ddd
			in >> m_dAB;
Toshihiro Shimizu 890ddd
		if (isBegin && strcmp(token, "END") == 0)
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
		if (isBegin && strcmp(token, "COLOR") == 0) {
Toshihiro Shimizu 890ddd
			m_color.resize(m_color.size() + 1);
Toshihiro Shimizu 890ddd
			vector<i_pixel>::iterator p = m_color.end();</i_pixel>
Toshihiro Shimizu 890ddd
			p--;
Toshihiro Shimizu 890ddd
			p->r = p->g = p->b = p->m = 0;
Toshihiro Shimizu 890ddd
			if (in.good())
Toshihiro Shimizu 890ddd
				in >> p->r;
Toshihiro Shimizu 890ddd
			if (in.good())
Toshihiro Shimizu 890ddd
				in >> p->g;
Toshihiro Shimizu 890ddd
			if (in.good())
Toshihiro Shimizu 890ddd
				in >> p->b;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (in.good()) {
Toshihiro Shimizu 890ddd
			token[0] = '\0';
Toshihiro Shimizu 890ddd
			in >> token;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CYOMBParam::adjustToMatte(I_PIXEL &p)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double q = (double)p.m / 255.0;
Toshihiro Shimizu 890ddd
	double r = (double)p.r * q;
Toshihiro Shimizu 890ddd
	double g = (double)p.g * q;
Toshihiro Shimizu 890ddd
	double b = (double)p.b * q;
Toshihiro Shimizu 890ddd
	p.r = I_ROUNDP(r);
Toshihiro Shimizu 890ddd
	p.g = I_ROUNDP(g);
Toshihiro Shimizu 890ddd
	p.b = I_ROUNDP(b);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CYOMBParam::read(const CInputParam &ip)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const CYOMBInputParam *yombIP;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	yombIP = static_cast<const *="" cyombinputparam="">(&ip);</const>
Toshihiro Shimizu 890ddd
	m_name = "";
Toshihiro Shimizu 890ddd
	m_isRandomSampling = yombIP->m_isRandomSampling;
Toshihiro Shimizu 890ddd
	m_isShowSelection = yombIP->m_isShowSelection;
Toshihiro Shimizu 890ddd
	m_isStopAtContour = yombIP->m_isStopAtContour;
Toshihiro Shimizu 890ddd
	m_dSample = yombIP->m_dSample;
Toshihiro Shimizu 890ddd
	m_nbSample = yombIP->m_nbSample;
Toshihiro Shimizu 890ddd
	m_dA = yombIP->m_dA;
Toshihiro Shimizu 890ddd
	m_dAB = yombIP->m_dAB;
Toshihiro Shimizu 890ddd
	m_isCM = yombIP->m_isCM;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_isCM) {
Toshihiro Shimizu 890ddd
		m_ink.nb = yombIP->m_ink.nb;
Toshihiro Shimizu 890ddd
		int i;
Toshihiro Shimizu 890ddd
		for (i = 0; i < m_ink.nb; i++)
Toshihiro Shimizu 890ddd
			m_ink.ci[i] = yombIP->m_ink.ci[i];
Toshihiro Shimizu 890ddd
		m_paint.nb = yombIP->m_paint.nb;
Toshihiro Shimizu 890ddd
		for (i = 0; i < m_paint.nb; i++)
Toshihiro Shimizu 890ddd
			m_paint.ci[i] = yombIP->m_paint.ci[i];
Toshihiro Shimizu 890ddd
	} else if (yombIP->m_nbColor > 1) {
Toshihiro Shimizu 890ddd
		m_color.resize(yombIP->m_nbColor);
Toshihiro Shimizu 890ddd
		for (int i = 0; i < yombIP->m_nbColor; i++) {
Toshihiro Shimizu 890ddd
			m_color[i].r = yombIP->m_color[i][0];
Toshihiro Shimizu 890ddd
			m_color[i].g = yombIP->m_color[i][1];
Toshihiro Shimizu 890ddd
			m_color[i].b = yombIP->m_color[i][2];
Toshihiro Shimizu 890ddd
			m_color[i].m = yombIP->m_color[i][3];
Toshihiro Shimizu 890ddd
			adjustToMatte(m_color[i]);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CYOMBParam::addPixel(I_PIXEL &p, const I_PIXEL &pp)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	p.r += pp.r;
Toshihiro Shimizu 890ddd
	p.g += pp.g;
Toshihiro Shimizu 890ddd
	p.b += pp.b;
Toshihiro Shimizu 890ddd
	p.m += pp.m;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int CYOMBParam::getColorIndex(const UCHAR c)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return (c > (UCHAR)155 ? 255 - (int)c : 155 - (int)c + m_color.size() / 2);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CYOMBParam::scale(const double d)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (d >= 0) {
Toshihiro Shimizu 890ddd
		m_dSample *= d;
Toshihiro Shimizu 890ddd
		int s = (int)((double)m_nbSample * d + 0.5);
Toshihiro Shimizu 890ddd
		if (d < 0.99) {
Toshihiro Shimizu 890ddd
			m_nbSample = s <= 1 ? 3 : m_nbSample;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			m_nbSample = s <= 1 ? 1 : m_nbSample;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CYOMBParam::makeItUS()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_dA *= 200.0;
Toshihiro Shimizu 890ddd
	m_dAB *= 200.0;
Toshihiro Shimizu 890ddd
	makeColorsUS();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void CYOMBParam::makeColorsUS()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (vector<i_pixel>::iterator p = m_color.begin();</i_pixel>
Toshihiro Shimizu 890ddd
		 p != m_color.end();
Toshihiro Shimizu 890ddd
		 ++p) {
Toshihiro Shimizu 890ddd
		p->r = PIX_USHORT_FROM_BYTE((UCHAR)p->r);
Toshihiro Shimizu 890ddd
		p->g = PIX_USHORT_FROM_BYTE((UCHAR)p->g);
Toshihiro Shimizu 890ddd
		p->b = PIX_USHORT_FROM_BYTE((UCHAR)p->b);
Toshihiro Shimizu 890ddd
		p->m = PIX_USHORT_FROM_BYTE((UCHAR)p->m);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}