Filter Library | Camera | Interface Physics |
00001 // ScanFilterDilation.cpp: implementation of the CScanFilterDilation 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 "ScanFilterDilation.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 CScanFilterDilation::CScanFilterDilation() 00023 { 00024 m_csFilterName = m_lpcsFilterName; 00025 } 00026 00027 CScanFilterDilation::~CScanFilterDilation() 00028 { 00029 00030 } 00031 00032 //-------------------------------------------------------------------------------// 00033 00034 LPCTSTR CScanFilterDilation::m_lpcsFilterName = _T("Dilation"); 00035 // this filter's short name 00036 LPCTSTR CScanFilterDilation::m_lpcsShortFilterName = CScanFilterDilation::m_lpcsFilterName; 00037 IMPLEMENT_SERIAL(CScanFilterDilation, CScanFilter, 0) 00038 00039 //-------------------------------------------------------------------------------// 00040 00041 void CScanFilterDilation::Serialize(CArchive& ar) 00042 { 00043 CScanFilter::Serialize( ar ); 00044 }; 00045 00046 //-------------------------------------------------------------------------------// 00047 00048 BOOL CScanFilterDilation::SetParameters(LPCTSTR lpParameters) 00049 { 00050 /* 00051 * we do not expect any parameters, so say so: 00052 */ 00053 if ( Q_INVALID( NULL != lpParameters && "CScanFilterDilation (SetParameters): no parameters expected." ) ) 00054 { 00055 return FALSE; 00056 } 00057 00058 return TRUE; 00059 } 00060 00061 //-------------------------------------------------------------------------------// 00062 00063 LPCTSTR CScanFilterDilation::GetParameters() const 00064 { 00065 return NULL; 00066 } 00067 00068 //-------------------------------------------------------------------------------// 00069 00070 BOOL CScanFilterDilation::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 Dilation(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 Dilation(m_lpsbIn->m_dwSizeX * m_lpsbIn->m_dwSizeY); 00088 00089 return TRUE; 00090 } 00091 00092 //-------------------------------------------------------------------------------// 00093 00094 void CScanFilterDilation::Dilation(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 /* 00106 * should really be: std::numeric_limits<ValueType>::min(), 00107 * but this min() clashes with macro min() !! 00108 */ 00109 // short nMax = (short)0x8000; // minimal 16b 00110 short nMax = -32768; 00111 00112 // loop through 3x3 pixel area 00113 for (int yi=max(0,(int)y-1); yi<min((int)m_lpsbIn->m_dwSizeY,(int)y+2); yi++) 00114 for (int xi=max(0,(int)x-1); xi<min((int)m_lpsbIn->m_dwSizeX,(int)x+2); xi++) 00115 { 00116 if (m_lpsbIn->m_pwData[dwOffset + yi*m_lpsbIn->m_dwSizeX + xi] > nMax) 00117 nMax = m_lpsbIn->m_pwData[dwOffset + yi*m_lpsbIn->m_dwSizeX + xi]; 00118 } 00119 00120 m_lpsbOut->m_pwData[ptr++] = nMax; 00121 00122 } 00123 00124 } 00125 00126 //-------------------------------------------------------------------------------//