// demoDoc.cpp : implementation of the CDemoDoc class // #include "stdafx.h" #include "leadraster.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern void ExitMFCApp(); extern CDemoApp theApp; ///////////////////////////////////////////////////////////////////////////// // CDemoDoc IMPLEMENT_DYNCREATE(CDemoDoc, CDocument) BEGIN_MESSAGE_MAP(CDemoDoc, CDocument) //{{AFX_MSG_MAP(CDemoDoc) ON_COMMAND(ID_FILE_SAVE, OnFileSave) //}}AFX_MSG_MAP END_MESSAGE_MAP() static const WCHAR BASED_CODE _szLicString[] = L"LEADTOOLS OCX Copyright (c) 1991-2001 LEAD Technologies, Inc."; ///////////////////////////////////////////////////////////////////////////// // CDemoDoc construction/destruction CDemoDoc::CDemoDoc() { HRESULT hr; //Create the licensed LTRaster COM object m_pRaster = NULL; hr = theApp.CreateRasterObjectLic(&m_pRaster); if (FAILED(hr)){theApp.DisplayLEADError(ERROR_INV_PARAMETER);ExitMFCApp(); return;} m_pRasterFloaterBackground=NULL; hr = theApp.CreateRasterObjectLic(&m_pRasterFloaterBackground); if (FAILED(hr)){theApp.DisplayLEADError(ERROR_INV_PARAMETER);ExitMFCApp(); return;} m_pRasterUndo = NULL; hr = theApp.CreateRasterObjectLic(&m_pRasterUndo); if (FAILED(hr)){theApp.DisplayLEADError(ERROR_INV_PARAMETER);ExitMFCApp(); return;} m_bPanWin = FALSE; m_bMagGlass = FALSE; m_nFormat = 5; m_nBits = 0; m_nQFactor = 2; m_nMultipage = 0; } CDemoDoc::~CDemoDoc() { m_pRaster->Release(); m_pRasterFloaterBackground->Release(); m_pRasterUndo->Release(); } BOOL CDemoDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; TRY { switch(theApp.m_nOpenMode) { case OPENMODE_ISIS: return(OnOpenISIS()); break; case OPENMODE_BITMAP: return OnOpenBitmap(); break; case OPENMODE_TWAIN: return OnOpenTwain(); break; case OPENMODE_COLORMERGE: return OnOpenColorMerge(); break; /* case OPENMODE_CAPTURE: return(OnOpenCapture()); break; */ case OPENMODE_PASTE: return(OnOpenPaste()); break; default: break; } } CATCH_ALL(e) { theApp.DisplayLEADError(ERROR_FAILURE); return FALSE; } END_CATCH_ALL return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CDemoDoc serialization void CDemoDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CDemoDoc diagnostics #ifdef _DEBUG void CDemoDoc::AssertValid() const { CDocument::AssertValid(); } void CDemoDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CDemoDoc commands BOOL CDemoDoc::OnOpenBitmap() { //Make a copy of the temporary global m_pRaster object bitmap m_pRaster->Bitmap = (long)theApp.m_pBitmap; return(TRUE); } BOOL CDemoDoc::OnOpenDocument(LPCTSTR lpszPathName) { int nRet; if(lpszPathName) { UNLOCKSUPPORT(*m_pRaster); if(((CMainFrame*)theApp.m_pMainWnd)->m_pRaster->GetBitmap()) { m_pRaster->put_RefBitmap(TRUE); m_pRaster->put_Bitmap(((CMainFrame*)theApp.m_pMainWnd)->m_pRaster->GetBitmap()); m_pRaster->put_RefBitmap(FALSE); nRet = m_pRaster->GetBitmap()?0:ERROR_NO_BITMAP; } else { nRet = theApp.m_pRasterIO->GetFileInfo(NULL,lpszPathName,theApp.m_iPage,0) ; if( nRet == 0 ) { switch(theApp.m_pRasterIO->GetInfoFormat()) { case FILE_PCD: case FILE_FPX: case FILE_JP2: case FILE_J2K: case FILE_JBIG: theApp.m_pRasterIO->SetLoadResolution (m_pRaster, theApp.m_pRasterIO->InfoFormat, theApp.m_iXRes, theApp.m_iYRes); nRet = theApp.m_pRasterIO->Load(m_pRaster, lpszPathName, 0, theApp.m_iPage, 1); theApp.m_pRasterIO->SetLoadResolution (m_pRaster, theApp.m_pRasterIO->InfoFormat, 0, 0); break; default: nRet = theApp.m_pRasterIO->Load(m_pRaster, lpszPathName, 0, theApp.m_iPage, 1); } } } theApp.m_iPage = 1; if(nRet) { theApp.DisplayLEADError(nRet); return(FALSE); } theApp.m_pRasterIO->GetFileInfo(m_pRaster, lpszPathName, theApp.m_iPage, 0); DisplayDICOMLoadMsg(theApp.m_pRasterIO->GetInfoFormat()); return(TRUE); } return(FALSE); } #define DICOM_LOAD_MSG TEXT("This demo loads raster images stored in DICOM files.\n") \ TEXT("For full DICOM support, refer to the LEADTOOLS Medical Imaging demos.") void CDemoDoc::DisplayDICOMLoadMsg(short nFormat) { if(theApp.m_bDICOMLoadMsg) { switch(nFormat) { case FILE_DICOM_GRAY: case FILE_DICOM_COLOR: case FILE_DICOM_RLE_GRAY: case FILE_DICOM_RLE_COLOR: case FILE_DICOM_JPEG_GRAY: case FILE_DICOM_JPEG_COLOR: theApp.m_bDICOMLoadMsg = FALSE; //only do this one time MessageBox(AfxGetMainWnd()->m_hWnd, DICOM_LOAD_MSG, TEXT("DICOM Load Information"), MB_OK); break; } } return; } BOOL CDemoDoc::OnOpenTwain() { m_pRaster->Bitmap = theApp.m_pRaster->Bitmap; return TRUE; } BOOL CDemoDoc::OnOpenISIS() { int nRet=1; //if CoCreateInstance fails, this returns FALSE #ifndef _UNICODE ILEADRasterISIS *pRasterISIS; //Create the RasterTwain object HRESULT hr = CoCreateInstance(CLSID_LEADRasterISIS, NULL, CLSCTX_ALL, IID_ILEADRasterISIS, (void**)&pRasterISIS); if (SUCCEEDED(hr)) { pRasterISIS->EnableMethodErrors = FALSE; pRasterISIS->ISISLoadDriver(); nRet = pRasterISIS->ISISAcquire( long(theApp.m_pMainWnd->m_hWnd), m_pRaster, ISIS_SHOWUI, ISIS_BITMAP_LIST_OVERWRITE ); pRasterISIS->ISISUnloadDriver(); if( nRet ) theApp.DisplayLEADError(nRet); pRasterISIS->Release(); } #endif return(!nRet); } BOOL CDemoDoc::OnOpenColorMerge() { CColorMergeDlg dlg(NULL,this); if(dlg.DoModal() == IDOK) { int i; for(i = 0; i < 4; i++) { theApp.m_pRasterProcess->PutColorPlanes( i, ((CDemoDoc*)dlg.m_pDocument[i])->m_pRaster->Bitmap ); } theApp.m_pRasterProcess->ColorMerge(m_pRaster, (ColorSeparationConstants)dlg.m_dwFlags); for(i = 0; i < 4; i++) { theApp.m_pRasterProcess->PutColorPlanes(i, 0); } return(TRUE); } return(FALSE); } BOOL CDemoDoc::OnOpenPaste() { m_pRaster->Paste(PASTE_DOPASTE); return(TRUE); } ILEADRasterProcess * CDemoDoc::GetRasterProcess() { return theApp.m_pRasterProcess; } BOOL CDemoDoc::OnSaveDocument(LPCTSTR lpszPathName) { int nRet; if(lpszPathName) { DisplayDICOMSaveMsg(m_nFormat); nRet = theApp.m_pRasterIO->Save(m_pRasterViewForSave->GetRaster(), (LPTSTR)lpszPathName, (RasterFileConstants)m_nFormat, m_nBits, (QFactorConstants)m_nQFactor, m_nMultipage); if(nRet) { theApp.DisplayLEADError(nRet); return(FALSE); } SetModifiedFlag(FALSE); return(TRUE); } return(FALSE); } #define DICOM_SAVE_MSG TEXT("This demo can only be used to create a 'Secondary Capture Image Storage' DICOM Dataset.\n") \ TEXT("All elements in the Dataset will be set to appropriate default values.\n") \ TEXT("For full DICOM support, refer to the LEADTOOLS Medical Imaging demos.") void CDemoDoc::DisplayDICOMSaveMsg(short nFormat) { if(theApp.m_bDICOMSaveMsg) { switch(nFormat) { case FILE_DICOM_GRAY: case FILE_DICOM_COLOR: case FILE_DICOM_RLE_GRAY: case FILE_DICOM_RLE_COLOR: case FILE_DICOM_JPEG_GRAY: case FILE_DICOM_JPEG_COLOR: theApp.m_bDICOMSaveMsg = FALSE; //only do this one time MessageBox(AfxGetMainWnd()->m_hWnd, DICOM_SAVE_MSG, TEXT("DICOM Save Information"), MB_OK); break; } } return; } void CDemoDoc::OnFileSave() { BOOL bContinue=FALSE; CString sFileName; int nRet; theApp.m_pRasterFileDlg->PutEnableMethodErrors(FALSE); theApp.m_pRasterFileDlg->PutFileDlgFlags(0); theApp.m_pRasterFileDlg->PutSaveQFactor(2); theApp.m_pRasterFileDlg->PutPageNumber(1); theApp.m_pRasterFileDlg->PutDialogTitle("Save File"); theApp.m_pRasterFileDlg->PutUIFlags( SAVE_SHOW_FILEOPTIONS_MULTIPAGE | SAVE_SHOW_FILEOPTIONS_PROGRESSIVE | SAVE_SHOW_FILEOPTIONS_QFACTOR| SAVE_SHOW_FILEOPTIONS_STAMP | SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS| SAVE_SHOW_FILEOPTIONS_J2KOPTIONS | SAVE_SHOW_FILEOPTIONS_JBIG2OPTIONS); nRet = theApp.m_pRasterFileDlg->ShowSaveDlg((long)theApp.m_pMainWnd->m_hWnd); if(nRet == 0 ) { if( theApp.m_pRasterFileDlg->GetDialogStatus() ==DLG_OK ) { sFileName = theApp.m_pRasterFileDlg->GetFileName().copy(); m_nFormat = theApp.m_pRasterFileDlg->GetSaveFormat(); m_nBits = theApp.m_pRasterFileDlg->GetSaveBitsPerPixel(); m_nQFactor = theApp.m_pRasterFileDlg->GetSaveQFactor(); m_nMultipage = theApp.m_pRasterFileDlg->GetSaveMulti(); long nPage=1; switch(m_nMultipage) { case SAVE_APPEND: nPage = 2; break; case SAVE_OVERWRITE: nPage = 1; break; case SAVE_REPLACE: case SAVE_INSERT: nPage = theApp.m_pRasterFileDlg->GetPageNumber(); break; } theApp.m_pRasterIO->SavePage = (short)nPage; theApp.m_pRasterIO->SaveInterlaced = theApp.m_pRasterFileDlg->GetSaveInterlaced(); if((m_nFormat == FILE_J2K)|| (m_nFormat == FILE_JP2)|| (m_nFormat == FILE_CMW) || (m_nFormat == FILE_TIF_J2K)|| (m_nFormat == FILE_TIF_CMW)) { SetJ2KOptions(); } if((m_nFormat == FILE_JBIG2) || (m_nFormat == FILE_RAS_PDF_JBIG2)|| (m_nFormat == FILE_TIF_JBIG2)) { theApp.m_pRasterIO->JBIG2GBATX1 = theApp.m_pRasterFileDlg->JBIG2GBATX1; theApp.m_pRasterIO->JBIG2GBATY1 = theApp.m_pRasterFileDlg->JBIG2GBATY1; theApp.m_pRasterIO->JBIG2GBATX2 = theApp.m_pRasterFileDlg->JBIG2GBATX2; theApp.m_pRasterIO->JBIG2GBATY2 = theApp.m_pRasterFileDlg->JBIG2GBATY2; theApp.m_pRasterIO->JBIG2GBATX3 = theApp.m_pRasterFileDlg->JBIG2GBATX3; theApp.m_pRasterIO->JBIG2GBATY3 = theApp.m_pRasterFileDlg->JBIG2GBATY3; theApp.m_pRasterIO->JBIG2GBATX4 = theApp.m_pRasterFileDlg->JBIG2GBATX4; theApp.m_pRasterIO->JBIG2GBATY4 = theApp.m_pRasterFileDlg->JBIG2GBATY4; theApp.m_pRasterIO->JBIG2TemplateType = theApp.m_pRasterFileDlg->JBIG2TemplateType; theApp.m_pRasterIO->JBIG2SaveFlags = theApp.m_pRasterFileDlg->JBIG2SaveFlags; } OnSaveDocument((LPCTSTR)sFileName); } } else theApp.DisplayLEADError(nRet); } BOOL CDemoDoc::CanCloseFrame(CFrameWnd* pFrame) { POSITION pos = GetFirstViewPosition(); CDemoView* pView = (CDemoView *)GetNextView(pos); if (theApp.m_bStartEffect) return 0; return CDocument::CanCloseFrame(pFrame); } BOOL CDemoDoc::SaveModified() { if (!IsModified()) return TRUE; CString name; if (m_strPathName.IsEmpty()) { // get name based on caption name = m_strTitle; if (name.IsEmpty()) VERIFY(name.LoadString(AFX_IDS_UNTITLED)); } else { name = m_strPathName; } CString prompt; AfxFormatString1(prompt, AFX_IDP_ASK_TO_SAVE, name); switch (AfxMessageBox(prompt, MB_YESNOCANCEL, AFX_IDP_ASK_TO_SAVE)) { case IDYES: OnFileSave(); break; case IDNO: // If not saving changes, revert the document break; default: return FALSE; break; } return TRUE; // keep going } void CDemoDoc::SetJ2KOptions() { theApp.m_pRasterIO->J2KUseColorTransform = theApp.m_pRasterFileDlg->SaveJ2KUseColorTransform; theApp.m_pRasterIO->J2KDerivedQuantization = theApp.m_pRasterFileDlg->SaveJ2KDerivedQuantization; theApp.m_pRasterIO->J2KCompressionControl = theApp.m_pRasterFileDlg->GetSaveJ2KCompressionControl(); theApp.m_pRasterIO->J2KCompressionRatio = theApp.m_pRasterFileDlg->SaveJ2KCompressionRatio; theApp.m_pRasterIO->J2KTargetFileSize = theApp.m_pRasterFileDlg->SaveJ2KTargetFileSize; theApp.m_pRasterIO->J2KXOsiz = theApp.m_pRasterFileDlg->SaveJ2KXOsiz; theApp.m_pRasterIO->J2KYOsiz = theApp.m_pRasterFileDlg->SaveJ2KYOsiz; theApp.m_pRasterIO->J2KXTsiz = theApp.m_pRasterFileDlg->SaveJ2KXTsiz; theApp.m_pRasterIO->J2KYTsiz = theApp.m_pRasterFileDlg->SaveJ2KYTsiz; theApp.m_pRasterIO->J2KXTOsiz = theApp.m_pRasterFileDlg->SaveJ2KXTOsiz; theApp.m_pRasterIO->J2KYTOsiz = theApp.m_pRasterFileDlg->SaveJ2KYTOsiz; for (int i =0 ;iPutJ2KXRsiz(i,theApp.m_pRasterFileDlg->GetSaveJ2KXRsiz(i)); theApp.m_pRasterIO->PutJ2KYRsiz(i,theApp.m_pRasterFileDlg->GetSaveJ2KYRsiz(i)); } theApp.m_pRasterIO->J2KDecompLevel = theApp.m_pRasterFileDlg->SaveJ2KDecompLevel; theApp.m_pRasterIO->J2KProgressOrder = theApp.m_pRasterFileDlg->GetSaveJ2KProgressOrder(); theApp.m_pRasterIO->J2KCodBlockWidth = theApp.m_pRasterFileDlg->SaveJ2KCodBlockWidth; theApp.m_pRasterIO->J2KCodBlockHeight = theApp.m_pRasterFileDlg->SaveJ2KCodBlockHeight; theApp.m_pRasterIO->J2KCBS_SelectiveACBypass = theApp.m_pRasterFileDlg->SaveJ2KCBS_SelectiveACBypass; theApp.m_pRasterIO->J2KCBS_ResetContextOnBoundaries = theApp.m_pRasterFileDlg->SaveJ2KCBS_ResetContextOnBoundaries; theApp.m_pRasterIO->J2KCBS_TerminationOnEachPass = theApp.m_pRasterFileDlg->SaveJ2KCBS_TerminationOnEachPass; theApp.m_pRasterIO->J2KCBS_VerticallyCausalContext = theApp.m_pRasterFileDlg->SaveJ2KCBS_VerticallyCausalContext; theApp.m_pRasterIO->J2KCBS_PredictableTermination = theApp.m_pRasterFileDlg->SaveJ2KCBS_PredictableTermination; theApp.m_pRasterIO->J2KCBS_ErrorResilienceSymbol = theApp.m_pRasterFileDlg->SaveJ2KCBS_ErrorResilienceSymbol; theApp.m_pRasterIO->J2KGuardBits = theApp.m_pRasterFileDlg->SaveJ2KGuardBits; theApp.m_pRasterIO->J2KDerivedBaseMantissa = theApp.m_pRasterFileDlg->SaveJ2KDerivedBaseMantissa; theApp.m_pRasterIO->J2KDerivedBaseExponent = theApp.m_pRasterFileDlg->SaveJ2KDerivedBaseExponent; theApp.m_pRasterIO->J2KUseSOPMarker = theApp.m_pRasterFileDlg->SaveJ2KUseSOPMarker; theApp.m_pRasterIO->J2KUseEPHMarker = theApp.m_pRasterFileDlg->SaveJ2KUseEPHMarker; }