#include "StdAfx.h"
|
#include "PitchStat.h"
|
#include "PitchStat2d.h"
|
#include "MosisAssem/AssemUtil.h"
|
|
CPitchStat2d::CPitchStat2d(void) :m_bPitchMade(FALSE)
|
{
|
}
|
|
CPitchStat2d::~CPitchStat2d(void)
|
{
|
}
|
|
BOOL CPitchStat2d::CheckPitch2d(CMosisBuffer &buff, CRect &rect, stPitchParam ¶m)
|
{
|
return CheckPitch2d(buff.GetDataAddress(), buff.GetDataWidth(), buff.GetHeight(), rect, param);
|
}
|
|
void CPitchStat2d::ResetConvBuff(int size)
|
{
|
if (size < 1) size = 1;
|
size = (size + 32) * 16; // vertÀÇ °æ¿ì 16¹èÀÇ Conv Buff°¡ ÇÊ¿äÇÏ´Ù.
|
|
m_ConvBlock.SetSize(size);
|
m_ConvBlock2.SetSize(size);
|
}
|
|
void CPitchStat2d::AddPitch(int xx, int yy, int pitch16, int xTimes, int yTimes)
|
{
|
xx = xx >> 4; yy = yy >> 4;
|
for (int y = 0; y < yTimes; y++)
|
{
|
for (int x = 0; x < xTimes; x++)
|
{
|
*GetData(xx + x, yy + y) = pitch16;
|
}
|
}
|
}
|
|
BOOL CPitchStat2d::WritePitch2d(char* fileName)
|
{
|
char str[100];
|
FILE *pFile;
|
fopen_s(&pFile, fileName, "w");
|
if (pFile == NULL) return FALSE;
|
|
int xn = m_xInterval >> 4;// m_xInterval, m_yInterval ´Â 16ÀÇ ¹è¼ö
|
int yn = m_yInterval >> 4;
|
|
int sx = (m_xStart), ex = (m_xEnd);
|
int sy = (m_yStart), ey = (m_yEnd);
|
|
sx = 0; ex = GetWidth();
|
sy = 0; ey = GetHeight();
|
float pitch;
|
for (int y = sy; y < ey; y += yn)
|
{
|
sprintf_s(str, "%d:%t", y*m_yInterval);
|
fprintf(pFile, str);
|
for (int x = sx; x < ex; x += xn)
|
{
|
pitch = ((float)*GetData(x, y)) / 16;
|
sprintf_s(str, "%.3f\t", pitch);
|
fprintf(pFile, str);
|
}
|
sprintf_s(str, "\n");
|
fprintf(pFile, str);
|
}
|
|
fclose(pFile);
|
|
return TRUE;
|
}
|
|
void CPitchStat2d::VerifyPitch(int x, int x2, int y, int y2, int exWidth, int eyHeight)
|
{
|
m_xStart = x >> 4; m_yStart = y >> 4;
|
m_xEnd = x2 >> 4; m_yEnd = y2 >> 4;
|
|
int pitch;
|
int sx, ex, sy, ey;
|
|
exWidth = exWidth >> 4;
|
eyHeight = eyHeight >> 4;
|
|
sx = m_xStart - exWidth;
|
if (sx < 0) sx = 0;
|
ex = m_xEnd + exWidth;
|
if (ex >= GetWidth()) ex = GetWidth() - 1;
|
sy = m_yStart - eyHeight;
|
if (sy < 0) sy = 0;
|
ey = m_yEnd + eyHeight;
|
if (ey >= GetHeight()) ey = GetHeight() - 1;
|
|
m_sxExtend = sx; m_exExtend = ex;
|
m_syExtend = sy; m_eyExtend = ey;
|
|
for (y = m_yStart; y <= m_yEnd; y++)
|
{
|
pitch = *GetData(m_xEnd, y);
|
for (x = m_xEnd + 1; x <= ex; x++)
|
{
|
*GetData(x, y) = pitch;
|
}
|
}
|
|
for (y = m_yStart; y <= m_yEnd; y++)
|
{
|
pitch = *GetData(m_xStart, y);
|
for (x = sx; x < m_xStart; x++)
|
{
|
*GetData(x, y) = pitch;
|
}
|
}
|
|
int width = ex - sx + 1;
|
for (y = sy; y < m_yStart; y++)
|
{
|
memcpy(GetData(sx, y), GetData(sx, m_yStart), sizeof(int)*width);
|
}
|
for (y = m_yEnd + 1; y <= ey; y++)
|
{
|
memcpy(GetData(sx, y), GetData(sx, m_yEnd), sizeof(int)*width);
|
}
|
}
|
|
BOOL CPitchStat2d::MakePitchSpace(int x, int y)
|
{
|
return SetSize(x / 16 + 4, y / 16 + 4);// Pitch Á¤º¸´Â 16 byte¿¡ Çѹø¾¿ ÀúÀåÇÔ.
|
}
|
|
BOOL CPitchStat2d::CheckPitch2d(BYTE *pData, int dataWidth, int height, CRect &rect, stPitchParam ¶m)
|
{
|
// interval °ú dist¸¦ 16ÀÇ ¹è¼ö·Î ¸¸µç´Ù.
|
int dist = param.Dist;
|
int interval = param.Interval;
|
interval = interval >> 4 << 4; if (interval < 16) interval = 16;
|
dist = dist >> 4 << 4; if (dist < 16) dist = 16;
|
|
m_bPitchMade = FALSE;
|
m_Rect = rect;
|
|
MakePitchSpace(dataWidth, height);
|
|
int start, end;
|
int start2, end2;
|
int basePitch;
|
int pitch16;
|
int iPitch, spr;
|
int xTimes, yTimes;
|
|
basePitch = pitch16 = _DI16(param.PitchStart);
|
|
if (param.Direction == stPitchParam::PP_HORIZONTAL)
|
{
|
ResetConvBuff(rect.Width());
|
|
m_xInterval = interval;
|
m_yInterval = dist;
|
|
xTimes = interval >> 4;// 32 Pixel¿¡ Çѹø ã´Â´Ù¸é, Çѹø¿¡ 2°³¾¿ ÀúÀåÇØ¾ßÇÔ(data´Â 16 Çȼ¿¿¡ Çѹø¾¿ ä¿ò)
|
yTimes = dist >> 4;
|
start = rect.left;
|
end = (int)(rect.right - param.Width - param.PitchEnd - interval);
|
start2 = rect.top;
|
end2 = rect.bottom - param.Height - dist;
|
CAssemUtil::CheckPitchSmall16(pitch16, _DI16(param.GetPitchRange()), rect.left, rect.top, param.Width, param.Height, pData, dataWidth, param.ZeroBack, pitch16, iPitch, spr);
|
|
//AddPitch(start, start2, pitch16);
|
int x, y;
|
for (y = start2; y < end2; y += dist)
|
{
|
for (x = start; x < end; x += interval)
|
{
|
CAssemUtil::CheckPitchSmall16(pitch16, 1, x, y, param.Width, param.Height, pData, dataWidth, param.ZeroBack, pitch16, iPitch, spr);
|
AddPitch(x, y, pitch16, xTimes, yTimes);
|
}
|
}
|
VerifyPitch(start, x - interval, start2, y - dist, 1600, 1600);
|
m_bPitchMade = TRUE;
|
return m_bPitchMade;
|
}
|
|
//
|
ResetConvBuff(rect.Height());
|
|
start = rect.top;
|
end = (int)(rect.bottom - param.Height - param.PitchEnd - interval);
|
start2 = rect.left;
|
end2 = rect.right - param.Width - dist;
|
|
CAssemUtil::CheckPitchSmallVert16(pitch16, _DI16(param.GetPitchRange()), rect.left, rect.top, param.Width, param.Height, pData, dataWidth, param.ZeroBack, pitch16, iPitch, spr);
|
|
m_xInterval = dist;
|
m_yInterval = interval;
|
xTimes = dist >> 4;
|
yTimes = interval >> 4;// 32 Pixel¿¡ Çѹø ã´Â´Ù¸é, Çѹø¿¡ 2°³¾¿ ÀúÀåÇØ¾ßÇÔ(data´Â 16 Çȼ¿¿¡ Çѹø¾¿ ÀúÀå)
|
for (int x = start2; x < end2; x += dist)
|
{
|
for (int y = start; y < end; y += interval)
|
{
|
CAssemUtil::CheckPitchSmallVert16(pitch16, _DI16(param.GetPitchRange()), x, y, param.Width, param.Height, pData, dataWidth, param.ZeroBack, pitch16, iPitch, spr);
|
AddPitch(x, y, pitch16, xTimes, yTimes);
|
}
|
}
|
VerifyPitch(start, end, start2, end2, 16, 16);
|
m_bPitchMade = TRUE;
|
return TRUE;
|
}
|