|
Shinya Kitaoka |
810553 |
#pragma once
|
|
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 |
#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 |
|
|
Shinya Kitaoka |
120a6e |
class CCallCircle {
|
|
Shinya Kitaoka |
120a6e |
double m_r;
|
|
Shinya Kitaoka |
120a6e |
int m_nb;
|
|
Shinya Kitaoka |
120a6e |
std::unique_ptr<sxydw[]> m_c;</sxydw[]>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void draw(UCHAR *drawB, const int lX, const int lY, const int xx,
|
|
Shinya Kitaoka |
120a6e |
const int yy, const double r);
|
|
Shinya Kitaoka |
120a6e |
void null();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
CCallCircle() : m_r(0.0), m_nb(0) {}
|
|
Shinya Kitaoka |
120a6e |
CCallCircle(const double r);
|
|
Shinya Kitaoka |
120a6e |
virtual ~CCallCircle();
|
|
Shinya Kitaoka |
120a6e |
void print();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
template <class p=""></class>
|
|
Shinya Kitaoka |
120a6e |
void getCC(CSTColSelPic &pic, P &col) {
|
|
Shinya Kitaoka |
120a6e |
int xy = pic.m_lX * pic.m_lY;
|
|
Shinya Kitaoka |
120a6e |
UCHAR *pSel = pic.m_sel.get();
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < xy; i++, pSel++)
|
|
Shinya Kitaoka |
120a6e |
if (*pSel > (UCHAR)0) {
|
|
Shinya Kitaoka |
120a6e |
P *pPic = pic.m_pic + i;
|
|
Shinya Kitaoka |
120a6e |
col.r = pPic->r;
|
|
Shinya Kitaoka |
120a6e |
col.g = pPic->g;
|
|
Shinya Kitaoka |
120a6e |
col.b = pPic->b;
|
|
Shinya Kitaoka |
120a6e |
col.m = pPic->m;
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
template <class p=""></class>
|
|
Shinya Kitaoka |
120a6e |
void getCC(CSTColSelPic &pic, const int xx, const int yy, P &col) {
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < m_nb; i++) {
|
|
Shinya Kitaoka |
120a6e |
int x = xx + m_c[i].x;
|
|
Shinya Kitaoka |
120a6e |
int y = yy + m_c[i].y;
|
|
Shinya Kitaoka |
120a6e |
if (x >= 0 && y >= 0 && x < pic.m_lX && y < pic.m_lY) {
|
|
Shinya Kitaoka |
120a6e |
UCHAR *pSel = pic.m_sel.get() + y * pic.m_lX + x;
|
|
Shinya Kitaoka |
120a6e |
if (*pSel > (UCHAR)0) {
|
|
Shinya Kitaoka |
120a6e |
P *pPic = pic.m_pic + y * pic.m_lX + x;
|
|
Shinya Kitaoka |
120a6e |
col.r = pPic->r;
|
|
Shinya Kitaoka |
120a6e |
col.g = pPic->g;
|
|
Shinya Kitaoka |
120a6e |
col.b = pPic->b;
|
|
Shinya Kitaoka |
120a6e |
col.m = pPic->m;
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
template <class p=""></class>
|
|
Shinya Kitaoka |
120a6e |
void setNewContour(CSTColSelPic &picOri, CSTColSelPic &pic,
|
|
Shinya Kitaoka |
120a6e |
UCHAR *drawB, const bool isOneCC) {
|
|
Shinya Kitaoka |
120a6e |
UCHAR *pDB = drawB;
|
|
Shinya Kitaoka |
120a6e |
P *p = pic.m_pic;
|
|
Shinya Kitaoka |
120a6e |
P *pOri = picOri.m_pic;
|
|
Shinya Kitaoka |
120a6e |
int xy = pic.m_lX * pic.m_lY;
|
|
Shinya Kitaoka |
120a6e |
P col = {0, 255, 0, 255};
|
|
Shinya Kitaoka |
120a6e |
int rgbmMax = pic.getType() == ST_RGBM64 ? US_MAX : UC_MAX;
|
|
Shinya Kitaoka |
120a6e |
double rgbmMaxD = (double)rgbmMax;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (isOneCC) getCC(picOri, col);
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < xy; i++, pDB++, p++, pOri++) {
|
|
Shinya Kitaoka |
120a6e |
if (*pDB == 255) {
|
|
Shinya Kitaoka |
120a6e |
if (!isOneCC) getCC(picOri, i % pic.m_lX, i / pic.m_lX, col);
|
|
Shinya Kitaoka |
120a6e |
p->r = col.r;
|
|
Shinya Kitaoka |
120a6e |
p->g = col.g;
|
|
Shinya Kitaoka |
120a6e |
p->b = col.b;
|
|
Shinya Kitaoka |
120a6e |
p->m = col.m;
|
|
Shinya Kitaoka |
120a6e |
} else if (*pDB > 0) {
|
|
Shinya Kitaoka |
120a6e |
if (!isOneCC) getCC(picOri, i % pic.m_lX, i / pic.m_lX, col);
|
|
Shinya Kitaoka |
120a6e |
double q = ((double)(*pDB) / 255.0) * (double)col.m / (double)rgbmMax;
|
|
Shinya Kitaoka |
120a6e |
double qq = 1.0 - q;
|
|
Shinya Kitaoka |
120a6e |
double r = q * (double)col.r + qq * (double)(pOri->r);
|
|
Shinya Kitaoka |
120a6e |
double g = q * (double)col.g + qq * (double)(pOri->g);
|
|
Shinya Kitaoka |
120a6e |
double b = q * (double)col.b + qq * (double)(pOri->b);
|
|
Shinya Kitaoka |
120a6e |
double m = q * (double)col.m + qq * (double)(pOri->m);
|
|
Shinya Kitaoka |
120a6e |
r = D_CUT(r, 0.0, rgbmMaxD);
|
|
Shinya Kitaoka |
120a6e |
g = D_CUT(g, 0.0, rgbmMaxD);
|
|
Shinya Kitaoka |
120a6e |
b = D_CUT(b, 0.0, rgbmMaxD);
|
|
Shinya Kitaoka |
120a6e |
m = D_CUT(m, 0.0, rgbmMaxD);
|
|
Shinya Kitaoka |
120a6e |
if (rgbmMax == 255) {
|
|
Shinya Kitaoka |
120a6e |
p->r = UC_ROUND(r);
|
|
Shinya Kitaoka |
120a6e |
p->g = UC_ROUND(g);
|
|
Shinya Kitaoka |
120a6e |
p->b = UC_ROUND(b);
|
|
Shinya Kitaoka |
120a6e |
p->m = UC_ROUND(m);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
p->r = (UCHAR)US_ROUND(r);
|
|
Shinya Kitaoka |
120a6e |
p->g = (UCHAR)US_ROUND(g);
|
|
Shinya Kitaoka |
120a6e |
p->b = (UCHAR)US_ROUND(b);
|
|
Shinya Kitaoka |
120a6e |
p->m = (UCHAR)US_ROUND(m);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
template <class p=""></class>
|
|
Shinya Kitaoka |
120a6e |
void draw(CSTColSelPic &pic, const bool isOneCC, const double random)
|
|
Shinya Kitaoka |
120a6e |
// throw(SMemAllocError)
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
if (m_nb <= 0 || m_c == 0) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
try {
|
|
Shinya Kitaoka |
120a6e |
CSTColSelPic picOri;
|
|
Shinya Kitaoka |
120a6e |
picOri = pic;
|
|
Shinya Kitaoka |
120a6e |
if (pic.m_lX > 0 && pic.m_lY > 0) {
|
|
Shinya Kitaoka |
120a6e |
std::unique_ptr<uchar[]> drawB(new UCHAR[pic.m_lX * pic.m_lY]);</uchar[]>
|
|
Shinya Kitaoka |
120a6e |
if (!drawB) throw SMemAllocError("in callCircle");
|
|
Shinya Kitaoka |
120a6e |
memset(drawB.get(), 0, pic.m_lX * pic.m_lY);
|
|
Shinya Kitaoka |
120a6e |
UCHAR *pSel = pic.m_sel.get();
|
|
Shinya Kitaoka |
120a6e |
for (int y = 0; y < pic.m_lY; y++)
|
|
Shinya Kitaoka |
120a6e |
for (int x = 0; x < pic.m_lX; x++, pSel++)
|
|
Shinya Kitaoka |
120a6e |
if (*pSel > (UCHAR)0) {
|
|
Shinya Kitaoka |
120a6e |
double q = m_r * (double)((*pSel) - 1) / 254.0;
|
|
Shinya Kitaoka |
120a6e |
int rani = I_ROUND(random);
|
|
Shinya Kitaoka |
120a6e |
int ranii = rani > 0 ? rand() % (2 * rani) - 15 * rani / 8 : 0;
|
|
Shinya Kitaoka |
120a6e |
q = q * (1.0 + (double)ranii / 100.0);
|
|
Shinya Kitaoka |
120a6e |
draw(drawB.get(), pic.m_lX, pic.m_lY, x, y, q);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
setNewContour(picOri, pic, drawB.get(), isOneCC);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} catch (SMemAllocError) {
|
|
Shinya Kitaoka |
120a6e |
throw;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#endif // !defined(AFX_CALLCIRCLE_H__D2565814_2151_11D6_B9B8_0040F674BE6A__INCLUDED_)
|