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
00031
00032 #include <cfl/ScanFilterClad.h>
00033 #include <cfl/FilterDlg_Clad.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_FILTERCLAD 0 // permanent storage schema version
00042
00043 LPCTSTR CScanFilterClad::m_lpcsFilterName = _T("Clad");
00044
00045 LPCTSTR CScanFilterClad::m_lpcsShortFilterName = CScanFilterClad::m_lpcsFilterName;
00046
00047 IMPLEMENT_SERIAL( CScanFilterClad, CScanFilter, CFL_SCHEMAVERSION_FILTERCLAD )
00048
00049
00050
00051
00052 const CScanFilterClad::SizeElementType CScanFilterClad::def_nWidth = 220;
00053
00054
00055
00056
00057 const CScanFilterClad::SizeElementType CScanFilterClad::def_nHeight = 120;
00058
00059
00060
00061
00062 CScanFilterClad::CScanFilterClad() :
00063 m_cSize( CSize( def_nWidth, def_nHeight ) )
00064 {
00065
00066
00067 m_csFilterName = m_lpcsFilterName;
00068
00069 ReadFilterSettings();
00070 }
00071
00072
00073
00074
00075 CScanFilterClad::~CScanFilterClad()
00076 {
00077
00078
00079 ;
00080 }
00081
00082
00083
00084
00085
00086 void CScanFilterClad::Serialize( CArchive& ar )
00087 {
00088
00089
00090 CScanFilter::Serialize( ar );
00091
00092 if ( ar.IsStoring() )
00093 {
00094 ar << m_cSize.cx << m_cSize.cy;
00095 }
00096 else
00097 {
00098 ar >> m_cSize.cx >> m_cSize.cy;
00099 }
00100 };
00101
00102
00103
00104
00105
00106 void CScanFilterClad::ReadFilterSettings()
00107 {
00108
00109
00110 CWinApp* pApp = AfxGetApp();
00111
00112 if ( Q_INVALID( NULL == pApp ) )
00113 return ;
00114
00115
00116
00117
00118 SetParameters( pApp->GetProfileString( gCflRegistrySubkey, m_lpcsFilterName, _T( "220,120" ) ) );
00119 }
00120
00121
00122
00123
00124
00125 void CScanFilterClad::WriteFilterSettings() const
00126 {
00127
00128
00129 CWinApp* pApp = AfxGetApp();
00130
00131 if ( Q_INVALID( NULL == pApp ) )
00132 return ;
00133
00134
00135
00136
00137 LPCTSTR pStr = GetParameters();
00138
00139 if ( pStr )
00140 {
00141 pApp->WriteProfileString( gCflRegistrySubkey, m_lpcsFilterName, pStr );
00142 delete const_cast<LPTSTR>( pStr );
00143 }
00144 }
00145
00146
00147
00148
00149
00150
00151 LPCTSTR CScanFilterClad::GetParameters() const
00152 {
00153
00154
00155
00156
00157
00158 CString csParameters;
00159
00160 csParameters.Format( _T( "%d,%d" ), m_cSize.cx, m_cSize.cy );
00161
00162 return strcpy( new TCHAR[ csParameters.GetLength() + 1 ], csParameters );
00163 }
00164
00165
00166
00167
00168
00169 BOOL CScanFilterClad::SetParameters( LPCTSTR lpParameters )
00170 {
00171
00172
00173 if ( Q_INVALID( NULL == lpParameters &&
00174 "CScanFilterClad (SetParameters): parameters expected, none provided (NULL)." ) )
00175 {
00176 return FALSE;
00177 }
00178
00179
00180
00181
00182 m_cSize = SizeType( def_nWidth, def_nHeight );
00183
00184 int nfields = _stscanf( lpParameters, _T( "%d,%d" ), &m_cSize.cx, &m_cSize.cy );
00185
00186 if ( Q_INVALID( 2 > nfields && "CScanFilterClad (SetParameters): x- and y-size expected, got none." ) )
00187 {
00188 return FALSE;
00189 }
00190
00191 return TRUE;
00192 }
00193
00194
00195
00196
00197
00198 BOOL CScanFilterClad::RunModeless( CWnd* pParentWnd, CDocument* pDoc )
00199 {
00200
00201
00202 CFilterDlg_CladPtr pDlg = new CFilterDlg_Clad();
00203
00204 if ( Q_INVALID( NULL == pDlg ) )
00205 return FALSE;
00206
00207 pDlg->SetParameters( this, pDoc );
00208
00209
00210
00211
00212
00213 pDlg->Create( IDD_FILTERDLG_CLAD, pParentWnd );
00214
00215 m_pDlg = pDlg;
00216
00217 BOOL bRet = Apply();
00218
00219 if ( bRet )
00220 {
00221 pDlg->UpdateView();
00222 }
00223
00224 return bRet;
00225 }
00226
00227 #pragma warning( push )
00228 #pragma warning( disable : 4100 ) // unreferenced formal parameter
00229
00230
00231
00232
00233 DragSupportType CScanFilterClad::SupportDragInput() const
00234 {
00235 return SFDS_RECT;
00236 }
00237
00238
00239
00240
00241 void CScanFilterClad::SetDragInput( BOOL bL2R, CRect rcIn )
00242 {
00243
00244
00245
00246
00247
00248
00249 rcIn.NormalizeRect();
00250 SetWidth ( max( rcIn.Width() , static_cast< int >( m_lpsbIn->Columns() ) ) );
00251 SetHeight( max( rcIn.Height(), static_cast< int >( m_lpsbIn->Rows () ) ) );
00252
00253 if ( IsInteractive() )
00254 {
00255 m_pDlg->SetDlgItemInt( IDC_CLAD_SIZEX, GetWidth() );
00256 m_pDlg->SetDlgItemInt( IDC_CLAD_SIZEY, GetHeight() );
00257 }
00258
00259 if ( Q_FAILED( Apply() ) )
00260 {
00261 return ;
00262 }
00263
00264 CFilterDlg_CladPtr pDlg = dynamic_cast<CFilterDlg_CladPtr>( m_pDlg );
00265
00266 if ( Q_ASSERT( NULL != pDlg ) )
00267 {
00268 pDlg->UpdateView();
00269 }
00270 }
00271
00272 #pragma warning( pop )
00273
00274
00275
00276
00277
00278
00279 BOOL CScanFilterClad::Apply()
00280 {
00281
00282
00283 if ( Q_INVALID( NULL == m_lpsbIn ) )
00284 return FALSE;
00285
00286 if ( Q_INVALID( NULL == m_lpsbOut ) )
00287 return FALSE;
00288
00289
00290
00291
00292 SetWidth ( max( GetWidth() , m_lpsbIn->Columns() ) );
00293 SetHeight( max( GetHeight(), m_lpsbIn->Rows () ) );
00294
00295
00296
00297
00298 SizeElementType extra = GetWidth() * GetHeight();
00299
00300
00301
00302
00303 Q_RETURN( m_lpsbOut->CreateOutputBufferFor( *m_lpsbIn, extra ) );
00304
00305
00306
00307
00308 Q_RETURN( m_lpsbOut->ResizeDataBuffer( GetSize(), extra ) );
00309
00310 m_lpsbOut->m_csBufferName.Format( _T("%s - %s %d,%d"),
00311 m_lpsbIn->m_csBufferName, m_lpcsShortFilterName, GetWidth(), GetHeight() );
00312
00313 if ( IsInteractive() )
00314 {
00315 m_pDlg->SetDlgItemText( IDC_BUFFEROUTNAME, m_lpsbOut->m_csBufferName );
00316 }
00317
00318
00319
00320
00321 Clad( FALSE );
00322
00323
00324
00325
00326 if ( m_lpsbIn->IsBidirectionalScan() && m_lpsbOut->IsBidirectionalScan() )
00327 {
00328 Clad( TRUE );
00329 }
00330
00331 return TRUE;
00332 }
00333
00334
00335
00336
00337 void CScanFilterClad::Clad( BOOL bDoR2L )
00338 {
00339 CScanBaseBuffer::ConstPointer pInpData = m_lpsbIn->Data() + ( bDoR2L ? m_lpsbIn->GetFrameSize() : 0 );
00340 CScanBaseBuffer::Pointer pOutData = m_lpsbOut->Data() + ( bDoR2L ? m_lpsbOut->GetFrameSize() : 0 );
00341
00342 SizeElementType newWidth = m_lpsbOut->Columns();
00343 SizeElementType newHeight = m_lpsbOut->Rows();
00344
00345 SizeElementType oldWidth = m_lpsbIn->Columns();
00346 SizeElementType oldHeight = m_lpsbIn->Rows();
00347
00348 SizeElementType extraWidth = newWidth - oldWidth;
00349 SizeElementType extraHeight = newHeight - oldHeight;
00350
00351
00352
00353
00354 for ( SizeElementType y = 0; y < oldHeight; ++y )
00355 {
00356
00357 memcpy( pOutData, pInpData, oldWidth * sizeof( CScanBaseBuffer::ValueType ) );
00358
00359
00360 memset( pOutData + oldWidth, 0, extraWidth * sizeof( CScanBaseBuffer::ValueType ) );
00361
00362 pInpData += oldWidth;
00363 pOutData += newWidth;
00364 }
00365
00366
00367
00368
00369
00370
00371 memset( pOutData, 0, extraHeight * newWidth * sizeof( CScanBaseBuffer::ValueType ) );
00372
00373 }
00374
00375
00376
00377
00378