Filter Library | Camera | Interface Physics |
00001 // ScanFilterErosion.cpp: implementation of the CScanFilterErosion class. 00002 // 00003 ////////////////////////////////////////////////////////////////////// 00004 00005 #include "stdafx.h" 00006 #include "resource.h" 00007 #include <Camera/InterfaceDll.h> // Interface Dll definitions 00008 #include "ScanBaseBuffer.h" 00009 #include "ScanFilter.h" // Include overall FilterBaseClass 00010 #include "ScanFilterErosion.h" 00011 00012 #ifdef _DEBUG 00013 #undef THIS_FILE 00014 static char THIS_FILE[]=__FILE__; 00015 #define new DEBUG_NEW 00016 #endif 00017 00018 ////////////////////////////////////////////////////////////////////// 00019 // Construction/Destruction 00020 ////////////////////////////////////////////////////////////////////// 00021 00022 CScanFilterErosion::CScanFilterErosion() 00023 { 00024 m_csFilterName = m_lpcsFilterName; 00025 } 00026 00027 CScanFilterErosion::~CScanFilterErosion() 00028 { 00029 00030 } 00031 00032 //-------------------------------------------------------------------------------// 00033 00034 LPCTSTR CScanFilterErosion::m_lpcsFilterName = _T("Erosion"); 00035 // this filter's short name 00036 LPCTSTR CScanFilterErosion::m_lpcsShortFilterName = CScanFilterErosion::m_lpcsFilterName; 00037 IMPLEMENT_SERIAL(CScanFilterErosion, CScanFilter, 0) 00038 00039 //-------------------------------------------------------------------------------// 00040 00041 void CScanFilterErosion::Serialize(CArchive& ar) 00042 { 00043 CScanFilter::Serialize( ar ); 00044 }; 00045 00046 //-------------------------------------------------------------------------------// 00047 00048 BOOL CScanFilterErosion::SetParameters(LPCTSTR lpParameters) 00049 { 00050 /* 00051 * we do not expect any parameters, so say so: 00052 */ 00053 if ( Q_INVALID( NULL != lpParameters && "CScanFilterErosion (SetParameters): no parameters expected." ) ) 00054 { 00055 return FALSE; 00056 } 00057 00058 return TRUE; 00059 } 00060 00061 //-------------------------------------------------------------------------------// 00062 00063 LPCTSTR CScanFilterErosion::GetParameters() const 00064 { 00065 return NULL; 00066 } 00067 00068 //-------------------------------------------------------------------------------// 00069 00070 BOOL CScanFilterErosion::Apply() 00071 { 00072 ASSERT(m_lpsbIn); 00073 ASSERT(m_lpsbOut); 00074 00075 /* 00076 * copy the filter settings (not the data): 00077 */ 00078 Q_RETURN( m_lpsbOut->CreateOutputBufferFor( *m_lpsbIn ) ); 00079 00080 m_lpsbOut->m_csBufferName.Format( _T("%s - %s"),m_lpsbIn->m_csBufferName, m_lpcsShortFilterName ); 00081 00082 // Process first part (L2R) 00083 Erosion(0); 00084 00085 // If we have a double buffer, L2R and R2L, process that part too. 00086 if ((m_lpsbIn->m_dwFlags & SPM_SDBF_RIGHT2LEFT) && (m_lpsbIn->m_dwFlags & SPM_SDBF_LEFT2RIGHT)) 00087 Erosion(m_lpsbIn->m_dwSizeX * m_lpsbIn->m_dwSizeY); 00088 00089 return TRUE; 00090 } 00091 00092 //-------------------------------------------------------------------------------// 00093 00094 void CScanFilterErosion::Erosion(DWORD dwOffset) 00095 { 00096 // Check: can only handle completed frames 00097 ASSERT(m_lpsbIn->m_dwPixelOffset == 0); 00098 ASSERT(m_lpsbIn->m_dwPixelCount == m_lpsbIn->m_dwSizeX * m_lpsbIn->m_dwSizeY); 00099 00100 DWORD ptr = dwOffset; 00101 00102 for (DWORD y=0; y<m_lpsbIn->m_dwSizeY; y++) 00103 for (DWORD x=0; x<m_lpsbIn->m_dwSizeX; x++) 00104 { 00105 short nMin = 0x7FFF; // maximum 16b 00106 00107 // loop through 3x3 pixel area 00108 for (int yi=max(0,(int)y-1); yi<min((int)m_lpsbIn->m_dwSizeY,(int)y+2); yi++) 00109 for (int xi=max(0,(int)x-1); xi<min((int)m_lpsbIn->m_dwSizeX,(int)x+2); xi++) 00110 { 00111 if (m_lpsbIn->m_pwData[dwOffset + yi*m_lpsbIn->m_dwSizeX + xi] < nMin) 00112 nMin = m_lpsbIn->m_pwData[dwOffset + yi*m_lpsbIn->m_dwSizeX + xi]; 00113 } 00114 00115 m_lpsbOut->m_pwData[ptr++] = nMin; 00116 00117 } 00118 00119 } 00120 00121 //-------------------------------------------------------------------------------//