// SISPitch.cpp: implementation of the CSISPitch class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "SISPitch.h" #include "SISBuffer.h" #include "SISMath.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif BOOL CSISPitch::CheckPitch(CSISBuffer buffer, CRect rect) { m_xPitch= 0; m_yPitch= 0; m_Rect= rect; int xIntPitch= (int)m_xPitchOrigin; int yIntPitch= (int)m_yPitchOrigin; if(xIntPitch < 10 || yIntPitch < 10) return FALSE; if(rect.top < 0) return FALSE; CSISHive1B m_DifferenceHive; if(m_DifferenceHive.SetSize(m_xSearchRange*2+ 2, FALSE) < 1) return FALSE; if(m_DifferenceHive.SetSize(m_ySearchRange*2+ 2, FALSE) < 1) return FALSE; int64 *differences= m_DifferenceHive.GetData(0); int i; double xResult= -1; double yResult= -1; int x, y, x2, y2; x= rect.left; y= rect.top; x2= x+ xIntPitch- m_xSearchRange; y2= y; if(rect.left+ xIntPitch+ m_xSearchRange*2+ m_CheckWidth < rect.right) { for(i= 0; i< m_xSearchRange*2; i++) { differences[i]= CSISMath::GetAbsDiff(buffer, x, y, m_CheckWidth, m_CheckHeight, buffer, x2+ i, y2); } xResult= CSISMath::SearchMinimum(differences, m_xSearchRange*2); } if(xResult >= 0) { m_xPitch= x2- x+ xResult; }else m_xPitch= 0; x2= x; y2= y+ yIntPitch- m_ySearchRange; if(rect.top+ yIntPitch+ m_ySearchRange*2+ m_CheckHeight < rect.bottom) { for(i= 0; i< m_ySearchRange*2; i++) { differences[i]= CSISMath::GetAbsDiff(buffer, x, y, m_CheckWidth, m_CheckHeight, buffer, x2, y2+ i); } yResult= CSISMath::SearchMinimum(differences, m_ySearchRange*2); } if(yResult >= 0) { m_yPitch= y2- y+ yResult; }else m_yPitch= 0; return xResult >= 0 && yResult >= 0; }