00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "stdafx.h"
00026
00027 #include <cfl/resource.h>
00028
00029 #include <Camera/InterfaceDll.h>
00030 #include <Camera/CameraGeneralDefines.h>
00031
00032 #include <cfl/ScanFilterDifferential.h>
00033 #include <cfl/FilterDlg_Differential.h>
00034
00035 #ifdef _DEBUG
00036 #undef THIS_FILE
00037 static char THIS_FILE[]=__FILE__;
00038 #define new DEBUG_NEW
00039 #endif
00040
00041 #define CFL_SCHEMAVERSION_FILTERDIFFERENTIAL 0 // permanent storage schema version
00042
00043 LPCTSTR CScanFilterDifferential::m_lpcsFilterName = _T("Differential-Plane");
00044
00045 LPCTSTR CScanFilterDifferential::m_lpcsShortFilterName = _T( "Diff" );
00046
00047 IMPLEMENT_SERIAL( CScanFilterDifferential, CScanFilter, CFL_SCHEMAVERSION_FILTERDIFFERENTIAL )
00048
00049
00050
00051
00052 const int CScanFilterDifferential::def_nAngle = 0;
00053
00054
00055
00056
00057 CScanFilterDifferential::CScanFilterDifferential() :
00058 m_nAngle( def_nAngle )
00059 {
00060 m_csFilterName = m_lpcsFilterName;
00061
00062 ReadFilterSettings();
00063 }
00064
00065
00066
00067
00068 CScanFilterDifferential::~CScanFilterDifferential()
00069 {
00070 ;
00071 }
00072
00073
00074
00075
00076
00077 void CScanFilterDifferential::Serialize(CArchive& ar)
00078 {
00079 CScanFilter::Serialize( ar );
00080
00081 if ( ar.IsStoring() )
00082 {
00083 ar << m_nAngle;
00084 }
00085 else
00086 {
00087 ar >> m_nAngle;
00088 }
00089 };
00090
00091
00092
00093
00094
00095 void CScanFilterDifferential::ReadFilterSettings( )
00096 {
00097
00098
00099 CWinApp* pApp = AfxGetApp();
00100
00101 if ( Q_INVALID( NULL == pApp ) )
00102 return ;
00103
00104
00105
00106
00107 SetParameters( pApp->GetProfileString( gCflRegistrySubkey, m_lpcsFilterName, _T( "0" ) ) );
00108 }
00109
00110
00111
00112
00113
00114 void CScanFilterDifferential::WriteFilterSettings() const
00115 {
00116
00117
00118 CWinApp* pApp = AfxGetApp();
00119
00120 if ( Q_INVALID( NULL == pApp ) )
00121 return ;
00122
00123
00124
00125
00126 LPCTSTR pStr = GetParameters();
00127
00128 if ( pStr )
00129 {
00130 pApp->WriteProfileString( gCflRegistrySubkey, m_lpcsFilterName, pStr );
00131 delete const_cast<LPTSTR>( pStr );
00132 }
00133 }
00134
00135
00136
00137
00138
00139
00140 LPCTSTR CScanFilterDifferential::GetParameters( ) const
00141 {
00142
00143
00144
00145
00146
00147 CString csParameters;
00148
00149 csParameters.Format( _T( "%d" ), m_nAngle );
00150
00151 return strcpy( new TCHAR[ csParameters.GetLength() + 1 ], csParameters );
00152 }
00153
00154
00155
00156
00157
00158 BOOL CScanFilterDifferential::SetParameters( LPCTSTR lpParameters )
00159 {
00160
00161
00162 if ( Q_INVALID( NULL == lpParameters ) &&
00163 "CScanFilterDifferential (SetParameters): parameters expected, none provided (NULL)." )
00164 {
00165 return FALSE;
00166 }
00167
00168
00169
00170
00171 m_nAngle = def_nAngle;
00172
00173 int nfields = _stscanf( lpParameters, _T( "%d" ), &m_nAngle );
00174
00175 if ( Q_INVALID( 1 > nfields && "CScanFilterDifferential (SetParameters): angle expected, got none." ) )
00176 {
00177 return FALSE;
00178 }
00179
00180 if ( Q_INVALID( ( m_nAngle < 0 || m_nAngle > 360 ) && "CScanFilterDifferential (SetParameters): invalid angle." ) )
00181 {
00182 return FALSE;
00183 }
00184
00185 return TRUE;
00186 }
00187
00188
00189
00190
00191
00192 BOOL CScanFilterDifferential::EditModeless( CWnd *pParentWnd )
00193 {
00194
00195
00196 CFilterDlg_DifferentialPtr pDlg = new CFilterDlg_Differential();
00197
00198 if ( Q_INVALID( NULL == pDlg ) )
00199 return FALSE;
00200
00201
00202
00203
00204 pDlg->SetParameters( this, NULL );
00205
00206
00207
00208
00209
00210 BOOL bRet = pDlg->Create( IDD_FILTERDLG_DIFFERENTIAL, pParentWnd );
00211 m_pDlg = pDlg;
00212
00213
00214
00215
00216 pDlg->DisableBufferControls();
00217
00218 return bRet;
00219 }
00220
00221
00222
00223
00224
00225 BOOL CScanFilterDifferential::RunModeless( CWnd* pParentWnd, CDocument* pDoc )
00226 {
00227
00228
00229 CFilterDlg_Differential *pDlg = new CFilterDlg_Differential();
00230
00231 if ( Q_INVALID( NULL == pDlg ) )
00232 return FALSE;
00233
00234 pDlg->SetParameters( this, pDoc );
00235
00236
00237
00238
00239
00240 pDlg->Create( IDD_FILTERDLG_DIFFERENTIAL, pParentWnd );
00241
00242 m_pDlg = pDlg;
00243
00244 BOOL bRet = Apply();
00245
00246 if ( bRet )
00247 {
00248 pDlg->UpdateView();
00249 }
00250
00251 return bRet;
00252 }
00253
00254
00255
00256
00257
00258
00259 BOOL CScanFilterDifferential::Apply()
00260 {
00261 if ( Q_INVALID( NULL == m_lpsbIn && "ensure valid input buffer" ) )
00262 return FALSE;
00263
00264 if ( Q_INVALID( NULL == m_lpsbOut && "ensure valid output buffer" ) )
00265 return FALSE;
00266
00267
00268
00269
00270 Q_RETURN( m_lpsbOut->CreateOutputBufferFor( *m_lpsbIn ) );
00271
00272 m_lpsbOut->m_csBufferName.Format( _T( "%s - %s:%d" ), m_lpsbIn->m_csBufferName, m_lpcsShortFilterName, m_nAngle );
00273
00274 if ( IsInteractive() )
00275 {
00276 m_pDlg->SetDlgItemText( IDC_BUFFEROUTNAME, m_lpsbOut->m_csBufferName );
00277 }
00278
00279
00280 Differentiate( 0 );
00281
00282
00283 if ( m_lpsbIn->IsBidirectionalScan() && m_lpsbOut->IsBidirectionalScan() )
00284 {
00285 Differentiate( m_lpsbIn->m_dwSizeX * m_lpsbIn->m_dwSizeY );
00286 }
00287
00288 return TRUE;
00289 }
00290
00291
00292
00293
00294 void CScanFilterDifferential::Differentiate( DWORD dwOffset )
00295 {
00296 int clox, chix, cloy, chiy, dx, dy, cybx;
00297
00298 double coslight = cos( m_nAngle * g_d2PI / 360.0 );
00299 double sinlight = sin( m_nAngle * g_d2PI / 360.0 );
00300
00301 int nSizeX = m_lpsbIn->Columns();
00302 int nSizeY = m_lpsbIn->Rows();
00303 int nCount = 0;
00304
00305 for ( int nCountY = 0; nCountY < nSizeY; ++nCountY )
00306 {
00307 cloy = max( 0 , ( nCountY - 1 ) );
00308 chiy = min( ( nSizeY - 1 ), ( nCountY + 1 ) );
00309 dy = chiy - cloy;
00310 cloy *= nSizeX;
00311 chiy *= nSizeX;
00312 cybx = nCount = nCountY * nSizeX;
00313
00314 for ( int nCountX = 0; nCountX < nSizeX; ++nCountX, ++nCount )
00315 {
00316 clox = max( 0 , ( nCountX-1 ) );
00317 chix = min( ( nSizeX-1), ( nCountX+1 ) );
00318 dx = chix - clox;
00319
00320 m_lpsbOut->m_pwData[ nCount + dwOffset ] = (short)(
00321 coslight * ( m_lpsbIn->m_pwData[ chix + cybx + dwOffset] - m_lpsbIn->m_pwData[ clox + cybx + dwOffset ] ) / dx +
00322 sinlight * ( m_lpsbIn->m_pwData[ nCountX + chiy + dwOffset] - m_lpsbIn->m_pwData[ nCountX + cloy + dwOffset ] ) / dy
00323 );
00324 }
00325 }
00326 }
00327
00328
00329
00330