Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// YOMBParam.h: interface for the CYOMBParam class.
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if !defined(AFX_YOMBPARAM_H__41D42152_F2EE_11D5_B92D_0040F674BE6A__INCLUDED_)
Toshihiro Shimizu 890ddd
#define AFX_YOMBPARAM_H__41D42152_F2EE_11D5_B92D_0040F674BE6A__INCLUDED_
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if _MSC_VER > 1000
Toshihiro Shimizu 890ddd
#pragma once
Toshihiro Shimizu 890ddd
#endif // _MSC_VER > 1000
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
#include "STColSelPic.h"
Toshihiro Shimizu 890ddd
#include "SDef.h"
Toshihiro Shimizu 890ddd
#include "InputParam.h"
Campbell Barton d0e335
#include "YOMBInputParam.h"
Toshihiro Shimizu 890ddd
#include "BlurMatrix.h"
Toshihiro Shimizu 890ddd
//#pragma warning(disable: 4786)
Toshihiro Shimizu 890ddd
//#include "tmsg.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define P(d) tmsg_info(" - %d -\n", d)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class CYOMBParam
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	bool m_isRandomSampling;
Toshihiro Shimizu 890ddd
	bool m_isShowSelection;
Toshihiro Shimizu 890ddd
	bool m_isStopAtContour;
Toshihiro Shimizu 890ddd
	bool m_isBlurOnPair;
Toshihiro Shimizu 890ddd
	double m_dSample;
Toshihiro Shimizu 890ddd
	int m_nbSample;
Toshihiro Shimizu 890ddd
	double m_dA, m_dAB;
Shinya Kitaoka 3bfa54
	std::string m_name;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_isCM;
Toshihiro Shimizu 890ddd
	// for RGBM color groups
Shinya Kitaoka 3bfa54
	std::vector<i_pixel> m_color;</i_pixel>
Toshihiro Shimizu 890ddd
	// for CMAP color indides
Toshihiro Shimizu 890ddd
	COLOR_INDEX_LIST m_ink, m_paint;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	CYOMBParam() : m_isRandomSampling(false), m_isShowSelection(false),
Toshihiro Shimizu 890ddd
				   m_isStopAtContour(false), m_isBlurOnPair(false),
Toshihiro Shimizu 890ddd
				   m_dSample(0.0), m_nbSample(0),
Toshihiro Shimizu 890ddd
				   m_dA(0.0), m_dAB(0.0), m_name(""),
Toshihiro Shimizu 890ddd
				   m_isCM(false),
Toshihiro Shimizu 890ddd
				   m_color(0)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_ink.nb = m_paint.nb = 0;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	CYOMBParam(const CYOMBParam &bp) : m_color(bp.m_color),
Toshihiro Shimizu 890ddd
									   m_isRandomSampling(bp.m_isRandomSampling),
Toshihiro Shimizu 890ddd
									   m_isShowSelection(bp.m_isShowSelection),
Toshihiro Shimizu 890ddd
									   m_isStopAtContour(bp.m_isStopAtContour),
Toshihiro Shimizu 890ddd
									   m_isBlurOnPair(bp.m_isBlurOnPair),
Toshihiro Shimizu 890ddd
									   m_dSample(bp.m_dSample),
Toshihiro Shimizu 890ddd
									   m_nbSample(bp.m_nbSample),
Toshihiro Shimizu 890ddd
									   m_dA(bp.m_dA),
Toshihiro Shimizu 890ddd
									   m_dAB(bp.m_dAB),
Toshihiro Shimizu 890ddd
									   m_name(bp.m_name),
Toshihiro Shimizu 890ddd
									   m_isCM(bp.m_isCM)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_isCM) {
Toshihiro Shimizu 890ddd
			m_ink.nb = bp.m_ink.nb;
Toshihiro Shimizu 890ddd
			int i = 0;
Toshihiro Shimizu 890ddd
			for (i = 0; i < m_ink.nb; i++)
Toshihiro Shimizu 890ddd
				m_ink.ci[i] = bp.m_ink.ci[i];
Toshihiro Shimizu 890ddd
			m_paint.nb = bp.m_paint.nb;
Toshihiro Shimizu 890ddd
			for (i = 0; i < m_paint.nb; i++)
Toshihiro Shimizu 890ddd
				m_paint.ci[i] = bp.m_paint.ci[i];
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual ~CYOMBParam(){};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void print();
Toshihiro Shimizu 890ddd
	void null();
Toshihiro Shimizu 890ddd
	void read(const CInputParam &ip);
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 2148c8
	bool read(std::basic_ifstream<char> &in);</char>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
	void makeColorsUS();
Toshihiro Shimizu 890ddd
	void makeItUS();
Toshihiro Shimizu 890ddd
	static void adjustToMatte(I_PIXEL &p);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//	void blurPixel(CSTColSelPic<uc_pixel>& pic, const int xx, const int yy,</uc_pixel>
Toshihiro Shimizu 890ddd
	//				   const CBlurMatrix& bm, UC_PIXEL& col,const UCHAR osel);
Toshihiro Shimizu 890ddd
	//	bool isContourOnPath(const int xx, const int yy,
Shinya Kitaoka 3bfa54
	//						 std::vector<blursection>::const_iterator pBS,</blursection>
Toshihiro Shimizu 890ddd
	//						 CSTColSelPic<uc_pixel>& pic);</uc_pixel>
Toshihiro Shimizu 890ddd
	//	void addPixel(I_PIXEL& p, const UC_PIXEL* pic);
Toshihiro Shimizu 890ddd
	//	void addPixel(I_PIXEL& p, const CSTColSelPic<uc_pixel>& pic,</uc_pixel>
Toshihiro Shimizu 890ddd
	//                 const int xxyy, const int xy );
Toshihiro Shimizu 890ddd
	void addPixel(I_PIXEL &p, const I_PIXEL &pp);
Toshihiro Shimizu 890ddd
	int getColorIndex(const UCHAR c);
Toshihiro Shimizu 890ddd
	void scale(const double d);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <class p=""></class>
Toshihiro Shimizu 890ddd
	void addPixel(I_PIXEL &p, const P *pic)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		p.r += ((int)pic->r);
Toshihiro Shimizu 890ddd
		p.g += ((int)pic->g);
Toshihiro Shimizu 890ddd
		p.b += ((int)pic->b);
Toshihiro Shimizu 890ddd
		p.m += ((int)pic->m);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Checks the path from blurred pixel to the sample pixel.
Toshihiro Shimizu 890ddd
	template <class p=""></class>
Toshihiro Shimizu 890ddd
	bool isContourOnPath(const int xx, const int yy,
Shinya Kitaoka 3bfa54
						 std::vector<blursection>::const_iterator pBS,</blursection>
Toshihiro Shimizu 890ddd
						 CSTColSelPic

&pic)

Toshihiro Shimizu 890ddd
	{
Shinya Kitaoka 3bfa54
		for (std::vector<sxyd>::const_iterator p = pBS->begin();</sxyd>
Toshihiro Shimizu 890ddd
			 p != pBS->end();
Toshihiro Shimizu 890ddd
			 ++p) {
Toshihiro Shimizu 890ddd
			int x = xx + p->x;
Toshihiro Shimizu 890ddd
			int y = yy + p->y;
Toshihiro Shimizu 890ddd
			int xy = y * pic.m_lX + x;
Toshihiro Shimizu 890ddd
			if (x >= 0 && y >= 0 && x < pic.m_lX && y < pic.m_lY)
Toshihiro Shimizu 890ddd
				if (*(pic.m_sel + xy) == (UCHAR)0)
Toshihiro Shimizu 890ddd
					return true;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <class p=""></class>
Toshihiro Shimizu 890ddd
	void addPixel(I_PIXEL &ip, const CSTColSelPic

&pic,

Toshihiro Shimizu 890ddd
				  const int xxyy, const int xy)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (!m_isBlurOnPair) {
Toshihiro Shimizu 890ddd
			addPixel(ip, pic.m_pic + xy);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			int i = getColorIndex(*(pic.m_sel + xy));
Toshihiro Shimizu 890ddd
			int ii = getColorIndex(*(pic.m_sel + xxyy));
Toshihiro Shimizu 890ddd
			int l = m_color.size() / 2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (i == ii || abs(ii - i) == l) {
Toshihiro Shimizu 890ddd
				addPixel(ip, pic.m_pic + xy);
Toshihiro Shimizu 890ddd
			} else {
Toshihiro Shimizu 890ddd
				if (ii < l) {
Toshihiro Shimizu 890ddd
					if (i < l) {
Toshihiro Shimizu 890ddd
						addPixel(ip, m_color[ii]);
Toshihiro Shimizu 890ddd
					} else
Toshihiro Shimizu 890ddd
						addPixel(ip, m_color[ii + l]);
Toshihiro Shimizu 890ddd
				} else {
Toshihiro Shimizu 890ddd
					if (i < l) {
Toshihiro Shimizu 890ddd
						addPixel(ip, m_color[ii - l]);
Toshihiro Shimizu 890ddd
					} else
Toshihiro Shimizu 890ddd
						addPixel(ip, m_color[ii]);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <class p=""></class>
Toshihiro Shimizu 890ddd
	void blurPixel(CSTColSelPic

&pic, const int xx, const int yy,

Toshihiro Shimizu 890ddd
				   const CBlurMatrix &bm, I_PIXEL &col, const int iBm)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		I_PIXEL p = {0, 0, 0, 0};
Toshihiro Shimizu 890ddd
		int nb = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		int xxyy = yy * pic.m_lX + xx;
Shinya Kitaoka 3bfa54
		for (std::vector<blursection>::const_iterator pBS = bm.m_m[iBm].begin();</blursection>
Toshihiro Shimizu 890ddd
			 pBS != bm.m_m[iBm].end();
Toshihiro Shimizu 890ddd
			 ++pBS) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//		const SXYD* xyd=pBS->begin();
Toshihiro Shimizu 890ddd
			BLURSECTION::const_iterator xyd = pBS->begin();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			int x = xx + xyd->x;
Toshihiro Shimizu 890ddd
			int y = yy + xyd->y;
Toshihiro Shimizu 890ddd
			if (x >= 0 && y >= 0 && x < pic.m_lX && y < pic.m_lY) {
Toshihiro Shimizu 890ddd
				int xy = y * pic.m_lX + x;
Toshihiro Shimizu 890ddd
				if (*(pic.m_sel + xy) > (UCHAR)0)
Toshihiro Shimizu 890ddd
					if (bm.m_isSAC) {
Toshihiro Shimizu 890ddd
						if (!isContourOnPath(xx, yy, pBS, pic)) {
Toshihiro Shimizu 890ddd
							addPixel(p, pic, xxyy, xy);
Toshihiro Shimizu 890ddd
							nb++;
Toshihiro Shimizu 890ddd
						}
Toshihiro Shimizu 890ddd
					} else {
Toshihiro Shimizu 890ddd
						addPixel(p, pic, xxyy, xy);
Toshihiro Shimizu 890ddd
						nb++;
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (nb > 0) {
Toshihiro Shimizu 890ddd
			double r = (double)p.r / (double)nb;
Toshihiro Shimizu 890ddd
			double g = (double)p.g / (double)nb;
Toshihiro Shimizu 890ddd
			double b = (double)p.b / (double)nb;
Toshihiro Shimizu 890ddd
			double m = (double)p.m / (double)nb;
Toshihiro Shimizu 890ddd
			col.r = I_ROUND(r);
Toshihiro Shimizu 890ddd
			col.g = I_ROUND(g);
Toshihiro Shimizu 890ddd
			col.b = I_ROUND(b);
Toshihiro Shimizu 890ddd
			col.m = I_ROUND(m);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			P *pPic = pic.m_pic + yy * pic.m_lX + xx;
Toshihiro Shimizu 890ddd
			col.r = (int)(pPic->r);
Toshihiro Shimizu 890ddd
			col.g = (int)(pPic->g);
Toshihiro Shimizu 890ddd
			col.b = (int)(pPic->b);
Toshihiro Shimizu 890ddd
			col.m = (int)(pPic->m);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <class p=""></class>
Toshihiro Shimizu 890ddd
	bool isRealMixture(CSTColSelPic

&pic, const int xx, const int yy,

Toshihiro Shimizu 890ddd
					   const CBlurMatrix &bm, const int iBm, const UCHAR osel) const
Toshihiro Shimizu 890ddd
	{
Shinya Kitaoka 3bfa54
		for (std::vector<blursection>::const_iterator pBS = bm.m_m[iBm].begin();</blursection>
Toshihiro Shimizu 890ddd
			 pBS != bm.m_m[iBm].end();
Toshihiro Shimizu 890ddd
			 ++pBS) {
Toshihiro Shimizu 890ddd
			//		const SXYD* xyd= pBS->begin();
Toshihiro Shimizu 890ddd
			BLURSECTION::const_iterator xyd = pBS->begin();
Toshihiro Shimizu 890ddd
			int x = xx + xyd->x;
Toshihiro Shimizu 890ddd
			int y = yy + xyd->y;
Toshihiro Shimizu 890ddd
			if (x >= 0 && x < pic.m_lX && y >= 0 && y < pic.m_lY) {
Toshihiro Shimizu 890ddd
				int xy = y * pic.m_lX + x;
Toshihiro Shimizu 890ddd
				UCHAR *pSel = pic.m_sel + xy;
Toshihiro Shimizu 890ddd
				if (*pSel > (UCHAR)0 && *pSel != osel)
Toshihiro Shimizu 890ddd
					return true;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <class p=""></class>
Toshihiro Shimizu 890ddd
	void doIt(CSTColSelPic

&ipic, CSTColSelPic

&opic)

Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		CBlurMatrix bm(m_dSample, m_nbSample, m_isStopAtContour, m_isRandomSampling);
Toshihiro Shimizu 890ddd
		UCHAR *pSel = ipic.m_sel;
Toshihiro Shimizu 890ddd
		for (int y = 0; y < ipic.m_lY; y++)
Toshihiro Shimizu 890ddd
			for (int x = 0; x < ipic.m_lX; x++, pSel++)
Toshihiro Shimizu 890ddd
				if (*pSel > (UCHAR)0) {
Toshihiro Shimizu 890ddd
					I_PIXEL col;
Toshihiro Shimizu 890ddd
					int iBm = bm.m_isRS ? rand() % NBRS : 0;
Toshihiro Shimizu 890ddd
					if (isRealMixture(ipic, x, y, bm, iBm, *pSel))
Toshihiro Shimizu 890ddd
						blurPixel(ipic, x, y, bm, col, iBm);
Toshihiro Shimizu 890ddd
					else
Toshihiro Shimizu 890ddd
						ipic.getPixel(x, y, col);
Toshihiro Shimizu 890ddd
					opic.setRGBM(x, y, col);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // !defined(AFX_YOMBPARAM_H__41D42152_F2EE_11D5_B92D_0040F674BE6A__INCLUDED_)