Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// CallCircle.h: interface for the CCallCircle class.
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if !defined(AFX_CALLCIRCLE_H__D2565814_2151_11D6_B9B8_0040F674BE6A__INCLUDED_)
Toshihiro Shimizu 890ddd
#define AFX_CALLCIRCLE_H__D2565814_2151_11D6_B9B8_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 <memory.h></memory.h>
Toshihiro Shimizu 890ddd
#include <string.h></string.h>
Toshihiro Shimizu 890ddd
#include "SDef.h"
Toshihiro Shimizu 890ddd
#include "STColSelPic.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int xydwCompare(const void *a, const void *b);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class CCallCircle
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double m_r;
Toshihiro Shimizu 890ddd
	int m_nb;
Toshihiro Shimizu 890ddd
	SXYDW *m_c;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void draw(UCHAR *drawB, const int lX, const int lY,
Toshihiro Shimizu 890ddd
			  const int xx, const int yy, const double r);
Toshihiro Shimizu 890ddd
	void null();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	CCallCircle() : m_r(0.0), m_nb(0), m_c(0){};
Toshihiro Shimizu 890ddd
	CCallCircle(const double r);
Toshihiro Shimizu 890ddd
	virtual ~CCallCircle();
Toshihiro Shimizu 890ddd
	void print();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <class p=""></class>
Toshihiro Shimizu 890ddd
	void getCC(CSTColSelPic

&pic, P &col)

Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		int xy = pic.m_lX * pic.m_lY;
Toshihiro Shimizu 890ddd
		UCHAR *pSel = pic.m_sel;
Toshihiro Shimizu 890ddd
		for (int i = 0; i < xy; i++, pSel++)
Toshihiro Shimizu 890ddd
			if (*pSel > (UCHAR)0) {
Toshihiro Shimizu 890ddd
				P *pPic = pic.m_pic + i;
Toshihiro Shimizu 890ddd
				col.r = pPic->r;
Toshihiro Shimizu 890ddd
				col.g = pPic->g;
Toshihiro Shimizu 890ddd
				col.b = pPic->b;
Toshihiro Shimizu 890ddd
				col.m = pPic->m;
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	template <class p=""></class>
Toshihiro Shimizu 890ddd
	void getCC(CSTColSelPic

&pic, const int xx, const int yy, P &col)

Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		for (int i = 0; i < m_nb; i++) {
Toshihiro Shimizu 890ddd
			int x = xx + m_c[i].x;
Toshihiro Shimizu 890ddd
			int y = yy + m_c[i].y;
Toshihiro Shimizu 890ddd
			if (x >= 0 && y >= 0 && x < pic.m_lX && y < pic.m_lY) {
Toshihiro Shimizu 890ddd
				UCHAR *pSel = pic.m_sel + y * pic.m_lX + x;
Toshihiro Shimizu 890ddd
				if (*pSel > (UCHAR)0) {
Toshihiro Shimizu 890ddd
					P *pPic = pic.m_pic + y * pic.m_lX + x;
Toshihiro Shimizu 890ddd
					col.r = pPic->r;
Toshihiro Shimizu 890ddd
					col.g = pPic->g;
Toshihiro Shimizu 890ddd
					col.b = pPic->b;
Toshihiro Shimizu 890ddd
					col.m = pPic->m;
Toshihiro Shimizu 890ddd
					return;
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 setNewContour(CSTColSelPic

&picOri, CSTColSelPic

&pic,

Toshihiro Shimizu 890ddd
					   UCHAR *drawB, const bool isOneCC)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		UCHAR *pDB = drawB;
Toshihiro Shimizu 890ddd
		P *p = pic.m_pic;
Toshihiro Shimizu 890ddd
		P *pOri = picOri.m_pic;
Toshihiro Shimizu 890ddd
		int xy = pic.m_lX * pic.m_lY;
Toshihiro Shimizu 890ddd
		P col = {0, 255, 0, 255};
Toshihiro Shimizu 890ddd
		int rgbmMax = pic.getType() == ST_RGBM64 ? US_MAX : UC_MAX;
Toshihiro Shimizu 890ddd
		double rgbmMaxD = (double)rgbmMax;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (isOneCC)
Toshihiro Shimizu 890ddd
			getCC(picOri, col);
Toshihiro Shimizu 890ddd
		for (int i = 0; i < xy; i++, pDB++, p++, pOri++) {
Toshihiro Shimizu 890ddd
			if (*pDB == 255) {
Toshihiro Shimizu 890ddd
				if (!isOneCC)
Toshihiro Shimizu 890ddd
					getCC(picOri, i % pic.m_lX, i / pic.m_lX, col);
Toshihiro Shimizu 890ddd
				p->r = col.r;
Toshihiro Shimizu 890ddd
				p->g = col.g;
Toshihiro Shimizu 890ddd
				p->b = col.b;
Toshihiro Shimizu 890ddd
				p->m = col.m;
Toshihiro Shimizu 890ddd
			} else if (*pDB > 0) {
Toshihiro Shimizu 890ddd
				if (!isOneCC)
Toshihiro Shimizu 890ddd
					getCC(picOri, i % pic.m_lX, i / pic.m_lX, col);
Toshihiro Shimizu 890ddd
				double q = ((double)(*pDB) / 255.0) * (double)col.m / (double)rgbmMax;
Toshihiro Shimizu 890ddd
				double qq = 1.0 - q;
Toshihiro Shimizu 890ddd
				double r = q * (double)col.r + qq * (double)(pOri->r);
Toshihiro Shimizu 890ddd
				double g = q * (double)col.g + qq * (double)(pOri->g);
Toshihiro Shimizu 890ddd
				double b = q * (double)col.b + qq * (double)(pOri->b);
Toshihiro Shimizu 890ddd
				double m = q * (double)col.m + qq * (double)(pOri->m);
Toshihiro Shimizu 890ddd
				r = D_CUT(r, 0.0, rgbmMaxD);
Toshihiro Shimizu 890ddd
				g = D_CUT(g, 0.0, rgbmMaxD);
Toshihiro Shimizu 890ddd
				b = D_CUT(b, 0.0, rgbmMaxD);
Toshihiro Shimizu 890ddd
				m = D_CUT(m, 0.0, rgbmMaxD);
Toshihiro Shimizu 890ddd
				if (rgbmMax == 255) {
Toshihiro Shimizu 890ddd
					p->r = UC_ROUND(r);
Toshihiro Shimizu 890ddd
					p->g = UC_ROUND(g);
Toshihiro Shimizu 890ddd
					p->b = UC_ROUND(b);
Toshihiro Shimizu 890ddd
					p->m = UC_ROUND(m);
Toshihiro Shimizu 890ddd
				} else {
Toshihiro Shimizu 890ddd
					p->r = (UCHAR)US_ROUND(r);
Toshihiro Shimizu 890ddd
					p->g = (UCHAR)US_ROUND(g);
Toshihiro Shimizu 890ddd
					p->b = (UCHAR)US_ROUND(b);
Toshihiro Shimizu 890ddd
					p->m = (UCHAR)US_ROUND(m);
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 draw(CSTColSelPic

&pic, const bool isOneCC, const double random)

Toshihiro Shimizu 890ddd
	// throw(SMemAllocError)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (m_nb <= 0 || m_c == 0)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		try {
Toshihiro Shimizu 890ddd
			UCHAR *drawB = 0;
Toshihiro Shimizu 890ddd
			CSTColSelPic

picOri;

Toshihiro Shimizu 890ddd
			picOri = pic;
Toshihiro Shimizu 890ddd
			if (pic.m_lX > 0 && pic.m_lY > 0) {
Toshihiro Shimizu 890ddd
				drawB = new UCHAR[pic.m_lX * pic.m_lY];
Toshihiro Shimizu 890ddd
				if (!drawB)
Toshihiro Shimizu 890ddd
					throw SMemAllocError("in callCircle");
Toshihiro Shimizu 890ddd
				memset(drawB, 0, pic.m_lX * pic.m_lY);
Toshihiro Shimizu 890ddd
				UCHAR *pSel = pic.m_sel;
Toshihiro Shimizu 890ddd
				for (int y = 0; y < pic.m_lY; y++)
Toshihiro Shimizu 890ddd
					for (int x = 0; x < pic.m_lX; x++, pSel++)
Toshihiro Shimizu 890ddd
						if (*pSel > (UCHAR)0) {
Toshihiro Shimizu 890ddd
							double q = m_r * (double)((*pSel) - 1) / 254.0;
Toshihiro Shimizu 890ddd
							int rani = I_ROUND(random);
Toshihiro Shimizu 890ddd
							int ranii = rani > 0 ? rand() % (2 * rani) - 15 * rani / 8 : 0;
Toshihiro Shimizu 890ddd
							q = q * (1.0 + (double)ranii / 100.0);
Toshihiro Shimizu 890ddd
							draw(drawB, pic.m_lX, pic.m_lY, x, y, q);
Toshihiro Shimizu 890ddd
						}
Toshihiro Shimizu 890ddd
				setNewContour(picOri, pic, drawB, isOneCC);
Toshihiro Shimizu 890ddd
				delete[] drawB;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} catch (SMemAllocError) {
Toshihiro Shimizu 890ddd
			throw;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // !defined(AFX_CALLCIRCLE_H__D2565814_2151_11D6_B9B8_0040F674BE6A__INCLUDED_)