#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include char ViewWindow::szClassName[]="GIFView"; char ViewWindow::szMenuName[]=""; HINSTANCE ViewWindow::smhInstance=0; ViewWindow::ViewWindow() : mhClientWindow(0), mhFrameWindow(0), mIsDestroyed(0), mMaxColors(0), mWidth(0), mHeight(0), mhPalette(0), mhGlobalInvert(0), mhGlobal(0), mhBMPGlobal(0), mpStatusBar(0), mpProcessImage(0), mpBI(0), mhpImageInvert(0), mhpImage(0), mhSystemMenu(0), mhFrameMenu(0), mhViewMenu(0), mpSpacial(0), mpPerspectiveWarp(0), mlpClipboard(0), mlpToolBar(0), mlpGridMesh(0), mlpConvexTransform(0), mToolbarVisibility(TRUE), mCurrentMeshFrames(DefaultFrames) { mPathFileName[0]=0; } ViewWindow::ViewWindow(const ViewWindow &/*someViewWindow*/) : mhClientWindow(0), mhFrameWindow(0), mIsDestroyed(0), mMaxColors(0), mWidth(0), mHeight(0), mhPalette(0), mhGlobalInvert(0), mhGlobal(0), mhBMPGlobal(0), mpStatusBar(0), mpProcessImage(0), mpBI(0), mhpImageInvert(0), mhpImage(0), mhSystemMenu(0), mhFrameMenu(0), mhViewMenu(0), mpSpacial(0), mpPerspectiveWarp(0), mlpClipboard(0), mlpToolBar(0), mlpGridMesh(0), mlpConvexTransform(0), mToolbarVisibility(TRUE), mCurrentMeshFrames(DefaultFrames) { mPathFileName[0]=0; } ViewWindow::~ViewWindow() { if(mhPalette)::DeleteObject(mhPalette); if(mhGlobalInvert) { ::GlobalUnlock(mhGlobalInvert); ::GlobalFree(mhGlobalInvert); } if(mhBMPGlobal) { ::GlobalUnlock(mhBMPGlobal); ::GlobalFree(mhBMPGlobal); } if(mhViewMenu)::DestroyMenu(mhViewMenu); if(!mIsDestroyed && GetHandle()) ::SendMessage(mhClientWindow,WM_MDIDESTROY,(WPARAM)GetHandle(),0L); if(mlpToolBar)delete mlpToolBar; if(mlpGridMesh)delete mlpGridMesh; } void ViewWindow::Register(HINSTANCE hInstance) { WNDCLASS wndclass; smhInstance=hInstance; wndclass.style =CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS|CS_OWNDC; wndclass.lpfnWndProc =(WNDPROC)MDIWindow::MDIWndProc; wndclass.cbClsExtra =0; wndclass.cbWndExtra =sizeof(ViewWindow*); wndclass.hInstance =hInstance; wndclass.hIcon =::LoadIcon(NULL,IDI_APPLICATION); wndclass.hCursor =::LoadCursor(NULL,IDC_ARROW); wndclass.hbrBackground =(HBRUSH)::GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName =szMenuName; wndclass.lpszClassName =szClassName; ::RegisterClass(&wndclass); } // *************** GIF DECODER IMAGE ENTRY POINTS ************** void ViewWindow::paletteHandler(const UCHAR FAR *paletteData,USHORT numColors) { RGBStruct FAR *pRGB; int i; mMaxColors=numColors; for(i=0;ibmiHeader.biSize=sizeof(BITMAPINFOHEADER); mpBI->bmiHeader.biWidth=mWidth; mpBI->bmiHeader.biHeight=mHeight; mpBI->bmiHeader.biPlanes=1; mpBI->bmiHeader.biBitCount=MaxGifBitsPerPixel; mpBI->bmiHeader.biCompression=BI_RGB; mpBI->bmiHeader.biSizeImage=0; mpBI->bmiHeader.biXPelsPerMeter=0; mpBI->bmiHeader.biYPelsPerMeter=0; mpBI->bmiHeader.biClrUsed=mMaxColors; mpBI->bmiHeader.biClrImportant=mMaxColors; for(i=0;ibmiColors[i]; pRGBQuad->rgbRed=mPaletteData[i].Red(); pRGBQuad->rgbGreen=mPaletteData[i].Green(); pRGBQuad->rgbBlue=mPaletteData[i].Blue(); pRGBQuad->rgbReserved=0; } ::GlobalUnlock(mhGlobal); ::GlobalFree(mhGlobal); mhGlobal=0; return; } void ViewWindow::showHandler(USHORT imageWide,USHORT imageDeep,const UCHAR FAR *lpRowData,USHORT yLocation) { if(!mhGlobal) { mWidth=imageWide; mHeight=imageDeep; mhGlobal=::GlobalAlloc(GMEM_FIXED,(long)mWidth*(long)mHeight); mhpImage=(UHUGE *)::GlobalLock(mhGlobal); } Main::hmemcpy(mhpImage+((long)yLocation*(long)mWidth),(UHUGE*)lpRowData,mWidth); return; } void ViewWindow::errorHandler(const CHAR FAR *errorMessage) { ::MessageBox(GetHandle(),(LPSTR)errorMessage,(LPSTR)"ERROR",MB_ICONASTERISK|MB_OK); return; } // ************************************************************** void ViewWindow::showWindow(HWND hClientWindow,const char *pathFileName,BWindow *statusBar,HMENU hFrameMenu) { mhFrameMenu=hFrameMenu; mhViewMenu=::LoadMenu(smhInstance,(LPSTR)"viewMenu"); mhClientWindow=hClientWindow; mhFrameWindow=::GetParent(mhClientWindow); mpStatusBar=statusBar; ::strcpy(mPathFileName,pathFileName); decodeMDIImage(); createMDIChildWindow(); createToolBarWindow(); } void ViewWindow::decodeMDIImage(void) { WORD resultCode; GIFDecoder *lpGIFDecoder; mpStatusBar->setText("Decoding Image."); waitCursor(TRUE); lpGIFDecoder=new GIFDecoder(mPathFileName); assert(0!=lpGIFDecoder); lpGIFDecoder->setPaletteHandler(this,&ViewWindow::paletteHandler); lpGIFDecoder->setBackgroundHandler(this,&ViewWindow::backgroundHandler); lpGIFDecoder->setImageHandler(this,&ViewWindow::imageHandler); lpGIFDecoder->setShowHandler(this,&ViewWindow::showHandler); lpGIFDecoder->setErrorHandler(this,&ViewWindow::errorHandler); resultCode=lpGIFDecoder->unpackImage(); delete lpGIFDecoder; if(!resultCode) { Bitmap bitmapImage; bitmapImage=mPathFileName; if(bitmapImage.isOkay())*this=bitmapImage; } waitCursor(FALSE); mpStatusBar->setText(""); } void ViewWindow::operator=(Bitmap &someBitmap) { RGBQUAD FAR *pRGBQuad; RGBStruct rgbStruct; DWORD sizeBitmapInfo; DWORD sizeImage; HGLOBAL hGlobalSourceBitmapInfo; HGLOBAL hGlobalSourceImage; BITMAPINFO FAR *lpSourceBitmapInfo; UHUGE *lpSourceImage; hGlobalSourceBitmapInfo=someBitmap.lockedBitmapInfo(); #if defined(__FLAT__) sizeBitmapInfo=::GlobalSize(hGlobalSourceBitmapInfo); #else sizeBitmapInfo=::GetSelectorLimit((UINT)hGlobalSourceBitmapInfo)+1L; #endif mhBMPGlobal=::GlobalAlloc(GMEM_FIXED,sizeBitmapInfo); mpBI=(BITMAPINFO FAR *)::GlobalLock(mhBMPGlobal); lpSourceBitmapInfo=(BITMAPINFO *)::GlobalLock(hGlobalSourceBitmapInfo); Main::hmemcpy((UHUGE *)mpBI,(UHUGE *)lpSourceBitmapInfo,sizeBitmapInfo); ::GlobalUnlock(hGlobalSourceBitmapInfo); sizeImage=((((mpBI->bmiHeader.biWidth* mpBI->bmiHeader.biBitCount)+31)&~31)>>3)* mpBI->bmiHeader.biHeight; mhGlobalInvert=::GlobalAlloc(GMEM_FIXED,sizeImage); mhpImageInvert=(UHUGE*)::GlobalLock(mhGlobalInvert); hGlobalSourceImage=someBitmap.lockedImageData(); lpSourceImage=(UHUGE*)::GlobalLock(hGlobalSourceImage); Main::hmemcpy(mhpImageInvert,lpSourceImage,sizeImage); ::GlobalUnlock(hGlobalSourceImage); mWidth=(WORD)mpBI->bmiHeader.biWidth; mHeight=(WORD)mpBI->bmiHeader.biHeight; if(!(mMaxColors=(WORD)mpBI->bmiHeader.biClrUsed)) mMaxColors=1 << mpBI->bmiHeader.biBitCount; for(int i=0;ibmiColors[i]; rgbStruct.Red(pRGBQuad->rgbRed); rgbStruct.Green(pRGBQuad->rgbGreen); rgbStruct.Blue(pRGBQuad->rgbBlue); mPaletteData.insert(&rgbStruct); } createPalette(); } void ViewWindow::createMDIChildWindow(void) { MDICREATESTRUCT createStruct; createStruct.szClass=(LPSTR)szClassName; createStruct.szTitle=(LPSTR)szClassName; createStruct.hOwner=smhInstance; createStruct.x=CW_USEDEFAULT; createStruct.y=CW_USEDEFAULT; createStruct.cx=CW_USEDEFAULT; createStruct.cy=CW_USEDEFAULT; createStruct.style=WS_SYSMENU|WS_CAPTION|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_VISIBLE|WS_CLIPCHILDREN; createStruct.lParam=(LONG)this; ::SendMessage(mhClientWindow,WM_MDICREATE,0,(LONG)(LPMDICREATESTRUCT)&createStruct); Show(SW_SHOW); Update(); } void ViewWindow::createToolBarWindow(void) { mlpToolBar=new ToolBar(GetHandle(),String(STRING_LITERALTOOLBAR,Main::processInstance())); mlpToolBar->addBitmap(String(STRING_LITERALMESH,Main::processInstance()),WM_COMMAND,MENU_TBMESH,0L); mlpToolBar->addBitmap(String(STRING_LITERALCLIP,Main::processInstance()),WM_COMMAND,MENU_TBCLIP,0L); mlpToolBar->addBitmap(String(STRING_LITERALBLOAD,Main::processInstance()),WM_COMMAND,MENU_TBLOAD,0L); mlpToolBar->addBitmap(String(STRING_LITERALBSAVE,Main::processInstance()),WM_COMMAND,MENU_TBSAVE,0L); mlpToolBar->addBitmap(String(STRING_LITERALTRANSFORMB,Main::processInstance()),WM_COMMAND,MENU_TBTRANSFORMB,0L); mlpToolBar->addBitmap(String(STRING_LITERALTRANSFORMA,Main::processInstance()),WM_COMMAND,MENU_TBTRANSFORMA,0L); mlpToolBar->addBitmap(String(STRING_LITERALSIGMA,Main::processInstance()),WM_COMMAND,MENU_TBSIGMA,0L); mlpToolBar->addBitmap(String(STRING_LITERALDISSOLVE,Main::processInstance()),WM_COMMAND,MENU_DISSOLVE,0L); mlpToolBar->showWindow(); } void ViewWindow::createPalette(void) { PALETTEENTRY FAR *pPaletteEntry; LOGPALETTE FAR *pLogPalette; HGLOBAL hPALGlobal; if(mhPalette)::DeleteObject(mhPalette); hPALGlobal=::GlobalAlloc(GMEM_ZEROINIT|GMEM_MOVEABLE,sizeof(LOGPALETTE)+(mMaxColors*sizeof(PALETTEENTRY))); pLogPalette=(LOGPALETTE FAR *)::GlobalLock(hPALGlobal); pLogPalette->palNumEntries=mMaxColors; pLogPalette->palVersion=0x300; for(int i=0;ipalPalEntry[i]; pPaletteEntry->peRed=mPaletteData[i].Red(); pPaletteEntry->peGreen=mPaletteData[i].Green(); pPaletteEntry->peBlue=mPaletteData[i].Blue(); pPaletteEntry->peFlags=0; } mhPalette=::CreatePalette((LOGPALETTE FAR *)pLogPalette); ::GlobalUnlock(hPALGlobal); ::GlobalFree(hPALGlobal); } void ViewWindow::Paint(void) { RECT rect; PAINTSTRUCT ps; HDC hDC; HPALETTE hOldPalette; HWND activeWindow; WORD menuState; WORD errorCount=0; ::GetClientRect(GetHandle(),(RECT FAR *)&rect); activeWindow=(HWND)LOWORD(::SendMessage(mhClientWindow,WM_MDIGETACTIVE,0,0L)); hDC=::BeginPaint(GetHandle(),&ps); if(GetHandle()==activeWindow)hOldPalette=::SelectPalette(hDC,mhPalette,FALSE); else hOldPalette=::SelectPalette(hDC,mhPalette,TRUE); ::RealizePalette(hDC); menuState=::GetMenuState(mhSystemMenu,MenuConform,MF_BYCOMMAND); if(!(menuState&MF_CHECKED)) ::StretchDIBits(hDC,0,0,rect.right,rect.bottom,0,0,mWidth,mHeight,mhpImageInvert,(BITMAPINFO *)mpBI,DIB_RGB_COLORS,SRCCOPY); else { while(!::StretchDIBits(hDC,0,0,mWidth,mHeight,0,0,mWidth,mHeight,mhpImageInvert,(BITMAPINFO *)mpBI,DIB_RGB_COLORS,SRCCOPY)) { errorCount++; ::MessageBeep(0); mWidth--; mHeight--; if((int)mWidth-1<0 || (int)mHeight-1<0)break; ::GlobalUnlock(mhGlobalInvert); Resize resizeImage(mWidth+1,mHeight+1,mWidth,mHeight,mhGlobalInvert); HGLOBAL hGlobalTemp=resizeImage.resizeImage(); ::GlobalFree(mhGlobalInvert); mhGlobalInvert=hGlobalTemp; mhpImageInvert=(UHUGE *)::GlobalLock(hGlobalTemp); mpBI->bmiHeader.biWidth=mWidth; mpBI->bmiHeader.biHeight=mHeight; } if(errorCount)updateCaption(); } if(GetHandle()==activeWindow)::SelectPalette(hDC,hOldPalette,FALSE); else ::SelectPalette(hDC,hOldPalette,TRUE); ::EndPaint(GetHandle(),&ps); if(mlpGridMesh)mlpGridMesh->suspendMesh(FALSE); } void ViewWindow::updateCaption(void)const { char Buffer[MaxFileName]; char *ptr; ::GetWindowText(GetHandle(),(LPSTR)Buffer,sizeof(Buffer)); ptr=Buffer+::strlen(Buffer)-1; while(*ptr!='-')ptr--; ptr+=2; ::sprintf(ptr,"%dx%dx%d",mWidth,mHeight,mMaxColors); ::SetWindowText(GetHandle(),(LPSTR)Buffer); } void ViewWindow::modifySystemMenu(void) { if(mhSystemMenu)return; mhSystemMenu=::GetSystemMenu(GetHandle(),FALSE); ::AppendMenu(mhSystemMenu,MF_SEPARATOR,0,0); ::AppendMenu(mhSystemMenu,MF_STRING|MF_CHECKED,MenuConform,(LPSTR)"Non-Conforming"); ::DrawMenuBar(GetHandle()); } void ViewWindow::handleDestroyEvent() { if(mpProcessImage)mpProcessImage->cancelThread(); if(mpSpacial)mpSpacial->cancelThread(); if(mpPerspectiveWarp)mpPerspectiveWarp->cancelThread(); if(mlpConvexTransform)mlpConvexTransform->cancelThread(); if(mlpClipboard)delete mlpClipboard; mIsDestroyed=TRUE; return; } void ViewWindow::handleActivateEvent(WPARAM wParam,LPARAM /*lParam*/) { if(wParam) { if(mlpGridMesh)mlpGridMesh->suspendMesh(TRUE); HDC inhDC(::GetDC(GetHandle())); ::SelectPalette(inhDC,mhPalette,FALSE); ::SendMessage(mhFrameWindow,WM_COMMAND,IDM_INVALIDATEMDIWINDOWS,MAKELPARAM(0,0)); if(::RealizePalette(inhDC)>0)::InvalidateRect(GetHandle(),0,TRUE); ::ReleaseDC(GetHandle(),inhDC); #if defined(__FLAT__) ::SendMessage(mhClientWindow,WM_MDISETMENU,(WPARAM)mhViewMenu,(LPARAM)::GetSubMenu(mhViewMenu,0)); #else ::SendMessage(mhClientWindow,WM_MDISETMENU,FALSE,MAKELONG(mhViewMenu,::GetSubMenu(mhViewMenu,0))); #endif if(mToolbarVisibility&&mlpToolBar&&!mlpToolBar->isVisible())mlpToolBar->showWindow(); } else { if(mlpToolBar&&mlpToolBar->isVisible())mlpToolBar->showWindow(FALSE); if(mlpGridMesh)mlpGridMesh->showWindow(TRUE); #if defined(__FLAT__) ::SendMessage(mhClientWindow,WM_MDISETMENU,(WPARAM)mhFrameMenu,(LPARAM)0); #else ::SendMessage(mhClientWindow,WM_MDISETMENU,FALSE,MAKELONG(mhFrameMenu,0)); #endif } ::DrawMenuBar(mhFrameWindow); return; } long ViewWindow::WndProc(UINT message,WPARAM wParam,LPARAM lParam) { switch(message) { case WM_CREATE : { char buffer[100]; mlpClipboard=new Clipboard(GetHandle()); assert(0!=mlpClipboard); ::SetWindowText(GetHandle(),(LPSTR)mPathFileName); ::sprintf(buffer,"%s - %dx%dx%d",mPathFileName,mWidth,mHeight,mMaxColors); ::SetWindowText(GetHandle(),(LPSTR)buffer); modifySystemMenu(); mCapture=GetHandle(); ::EnableMenuItem(mhViewMenu,MENU_PASTE,MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); } return FALSE; case WM_CHANGECBCHAIN : if(!mlpClipboard)break; mlpClipboard->changeClipboardChain(message,wParam,lParam); return FALSE; case WM_DRAWCLIPBOARD : if(!mlpClipboard)break; if(mlpClipboard->drawClipboard(message,wParam,lParam)) ::EnableMenuItem(mhViewMenu,MENU_PASTE,MF_BYCOMMAND|MF_ENABLED); return FALSE; case WM_LBUTTONDOWN : mCapture.leftButtonDown(lParam); return FALSE; case WM_MOUSEMOVE : mCapture.mouseMove(lParam); return FALSE; case WM_LBUTTONUP : mCapture.leftButtonUp(); return FALSE; case WM_PAINT : Paint(); return FALSE; case WM_MDIACTIVATE : #if defined(__FLAT__) handleActivateEvent((WPARAM)lParam,(LPARAM)wParam); #else handleActivateEvent(wParam,lParam); #endif return FALSE; case WM_QUERYENDSESSION : break; case WM_DESTROY : handleDestroyEvent(); return FALSE; case WM_SYSCOMMAND : handleSystemMenuEvent(wParam); break; case WM_COMMAND : switch(GET_WM_COMMAND_ID(wParam,lParam)) { case MenuConform : ::SendMessage(GetHandle(),WM_SYSCOMMAND,MenuConform,0L); return FALSE; case MENU_SMOOTHING : imageProcessing(); return FALSE; case MENU_RESIZE : resizeImage(); return FALSE; case MENU_TRANSLATE : translateMatrix(); return FALSE; case MENU_SHEAR : shearTransform(); return FALSE; case MENU_WARP_PERSPECTIVE : warpPerspective(); return FALSE; case MENU_WARP_CONVEX : warpConvex(); return FALSE; case MENU_CLIP : menuClip(); return FALSE; case MENU_DISSOLVE : { AdjustDissolve adjustDissolve(GetHandle()); adjustDissolve.adjustDissolve(mDissolveSchedule,mCurrentMeshFrames); } return FALSE; case MENU_TBSIGMA : { FrameDialog frameDialog(GetHandle()); frameDialog.performFrameDialog(mCurrentMeshFrames); } return FALSE; case MENU_TBLOAD : case MENU_TBSAVE : case MENU_TBTRANSFORMB : case MENU_TBTRANSFORMA : case IDM_WINLIST : handleMeshRequest(wParam,lParam); return FALSE; case MENU_TBCLIP : mCapture.reset(); if(mlpGridMesh) { delete mlpGridMesh; mlpGridMesh=0; } return FALSE; case MENU_TBMESH : if(!mlpGridMesh)mlpGridMesh=new GridMesh(GetHandle(),mWidth,mHeight); else mlpGridMesh->newMesh(mlpGridMesh->gridLines()+2); return FALSE; case MENU_FILE_SAVEBITMAP : saveBitmap(); return FALSE; case MENU_PALETTE_VIEW : { PaletteDialog viewPalette(GetHandle(),mhPalette); viewPalette.showPalette(); return FALSE; } case IDM_TOOLBAR : handleToolbarToggle(); break; default : return FALSE; } } return ::DefMDIChildProc(GetHandle(),message,wParam,lParam); } // ************************************************************** void ViewWindow::handleToolbarToggle(void) { String showToolbarString(STRING_SHOWTOOLBAR,Main::processInstance()); String hideToolbarString(STRING_HIDETOOLBAR,Main::processInstance()); String menuString; ::GetMenuString(mhViewMenu,IDM_TOOLBAR,menuString,String::MaxString,MF_BYCOMMAND); if(showToolbarString==menuString) { ::ModifyMenu(mhViewMenu,IDM_TOOLBAR,MF_STRING|MF_ENABLED,IDM_TOOLBAR,(LPSTR)hideToolbarString); mlpToolBar->showWindow(TRUE); mToolbarVisibility=TRUE; } else { ::ModifyMenu(mhViewMenu,IDM_TOOLBAR,MF_STRING|MF_ENABLED,IDM_TOOLBAR,(LPSTR)showToolbarString); mlpToolBar->showWindow(FALSE); mToolbarVisibility=FALSE; } ::DrawMenuBar(GetHandle()); } void ViewWindow::handleMeshRequest(WPARAM wParam,LPARAM lParam) { String meshFileName(mPathFileName); String meshPathFileName; IniFile iniSettings; iniSettings.makeFileName(meshFileName); meshFileName.token(".\0"); meshFileName+=".MSH"; meshPathFileName=iniSettings.meshDirectory(); meshPathFileName+=meshFileName; switch(wParam) { case MENU_TBLOAD : if(!mlpGridMesh)mlpGridMesh=new GridMesh(GetHandle(),mWidth,mHeight,GridMesh::NoShow); mlpGridMesh->loadMesh(meshPathFileName); break; case MENU_TBTRANSFORMA : if(!mlpGridMesh){::MessageBeep(0);break;} meshWarp(); break; case MENU_TBTRANSFORMB : if(!mlpGridMesh){::MessageBeep(0);break;} ::PostMessage(mhFrameWindow,WM_COMMAND,IDM_GETWINLIST,MAKELPARAM(GetHandle(),0)); break; case IDM_WINLIST : { WORD itemIndex; Block *lpViewBlock=(Block*)(lParam); if(!lpViewBlock||!lpViewBlock->size()){::MessageBeep(0);break;} ViewSelect selectView(GetHandle()); if(selectView.selectView(*lpViewBlock,itemIndex,mWidth,mHeight))meshWarp((*lpViewBlock)[itemIndex].windowPtr()); delete lpViewBlock; } break; case MENU_TBSAVE : if(!mlpGridMesh)break; mlpGridMesh->saveMesh(meshPathFileName); break; } return; } void ViewWindow::handleSystemMenuEvent(WPARAM wParam)const { WORD menuState; switch(wParam) { case MenuConform : menuState=::GetMenuState(mhSystemMenu,MenuConform,MF_BYCOMMAND); ::CheckMenuItem(mhSystemMenu,MenuConform,MF_BYCOMMAND | (menuState&MF_CHECKED?MF_UNCHECKED:MF_CHECKED)); ::DrawMenuBar(GetHandle()); ::InvalidateRect(GetHandle(),NULL,TRUE); } } void ViewWindow::enableMenu(const char isEnabled)const { if(isEnabled) { ::EnableMenuItem(mhViewMenu,MENU_CUT,MF_BYCOMMAND|MF_ENABLED); ::EnableMenuItem(mhViewMenu,MENU_COPY,MF_BYCOMMAND|MF_ENABLED); ::EnableMenuItem(mhViewMenu,MENU_PASTE,MF_BYCOMMAND|MF_ENABLED); ::EnableMenuItem(mhViewMenu,MENU_SMOOTHING,MF_BYCOMMAND|MF_ENABLED); ::EnableMenuItem(mhViewMenu,MENU_RESIZE,MF_BYCOMMAND|MF_ENABLED); ::EnableMenuItem(mhViewMenu,MENU_TRANSLATE,MF_BYCOMMAND|MF_ENABLED); ::EnableMenuItem(mhViewMenu,MENU_WARP_PERSPECTIVE,MF_BYCOMMAND|MF_ENABLED); ::EnableMenuItem(mhViewMenu,MENU_FILE_SAVEBITMAP,MF_BYCOMMAND|MF_ENABLED); } else { ::EnableMenuItem(mhViewMenu,MENU_CUT,MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); ::EnableMenuItem(mhViewMenu,MENU_COPY,MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); ::EnableMenuItem(mhViewMenu,MENU_PASTE,MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); ::EnableMenuItem(mhViewMenu,MENU_SMOOTHING,MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); ::EnableMenuItem(mhViewMenu,MENU_RESIZE,MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); ::EnableMenuItem(mhViewMenu,MENU_TRANSLATE,MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); ::EnableMenuItem(mhViewMenu,MENU_WARP_PERSPECTIVE,MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); ::EnableMenuItem(mhViewMenu,MENU_FILE_SAVEBITMAP,MF_BYCOMMAND|MF_DISABLED|MF_GRAYED); } } void ViewWindow::imageProcessing(void) { enableMenu(FALSE); mpProcessImage=new Process(mhPalette,mhpImageInvert,mWidth,mHeight); if(mpProcessImage->showProcess(GetHandle(),mPathFileName) && !mIsDestroyed) ::InvalidateRect(GetHandle(),NULL,TRUE); if(!mIsDestroyed)enableMenu(TRUE); delete mpProcessImage; mpProcessImage=0; } void ViewWindow::resizeImage(void) { HGLOBAL hGlobal; double sizeFactor; Factor resizeFactor(GetHandle(),"Resize Factor"); if(!resizeFactor.showFactor(sizeFactor,sizeFactor)||!sizeFactor)return; enableMenu(FALSE); mpSpacial=new SpacialTransform(mhPalette,mhpImageInvert,mWidth,mHeight,sizeFactor); hGlobal=mpSpacial->resizeImage(); if(mpSpacial->isCancelled()) { delete mpSpacial; mpSpacial=0; return; } delete mpSpacial; mpSpacial=0; if(hGlobal) { mWidth*=(sizeFactor/100.00); mHeight*=(sizeFactor/100.00); ::GlobalUnlock(mhGlobalInvert); ::GlobalFree(mhGlobalInvert); mhGlobalInvert=hGlobal; mhpImageInvert=(UHUGE *)::GlobalLock(mhGlobalInvert); mpBI->bmiHeader.biWidth=mWidth; mpBI->bmiHeader.biHeight=mHeight; } ::InvalidateRect(GetHandle(),NULL,TRUE); enableMenu(TRUE); updateCaption(); } void ViewWindow::menuClip(void) { RECT copyRect; HGLOBAL hGlobalResizedImage; UHUGE *ptrResizedImage; if(!mCapture.hasRectangle())return; mCapture.boundedRect(copyRect); enableMenu(FALSE); ::GlobalUnlock(mhGlobalInvert); Resize resizeImage(mWidth,mHeight,copyRect,mhGlobalInvert); if(0!=(hGlobalResizedImage=resizeImage.resizeImage())) { ::GlobalFree(mhGlobalInvert); ptrResizedImage=(UHUGE *)::GlobalLock(hGlobalResizedImage); mhGlobalInvert=hGlobalResizedImage; mhpImageInvert=ptrResizedImage; mpBI->bmiHeader.biWidth=mWidth=(copyRect.right-copyRect.left)+1; mpBI->bmiHeader.biHeight=mHeight=(copyRect.bottom-copyRect.top)+1; ::InvalidateRect(GetHandle(),NULL,TRUE); } else ::GlobalLock(mhGlobalInvert); updateCaption(); enableMenu(TRUE); } void ViewWindow::saveBitmap(void) { char bitmapName[MaxFileName]; SelectFile selector(GetHandle(),SelectFile::Write); selector.SetFileSpec(String(STRING_ASTERISKDOTBMP,Main::processInstance())); if(selector.GetFileName(bitmapName,sizeof(bitmapName))) { waitCursor(TRUE); Bitmap bitmapImage(bitmapName,mhGlobalInvert,mhBMPGlobal); bitmapImage.saveBitmap(); waitCursor(FALSE); } } void ViewWindow::translateMatrix(void) { UHUGE *ptr; double xFactor; double yFactor; Factor resizeFactor(GetHandle(),"Translate Factor"); if(!resizeFactor.showFactor(yFactor,xFactor))return; if(!yFactor && !xFactor)return; enableMenu(FALSE); waitCursor(TRUE); yFactor*=-1; xFactor*=-1; HGLOBAL hGlobal=::GlobalAlloc(GMEM_FIXED,(LONG)mWidth*(LONG)mHeight); ptr=(UHUGE*)::GlobalLock(hGlobal); TranslationMatrix translation(mHeight,mWidth,(int)xFactor,(int)yFactor,&mhpImageInvert,&ptr); translation.performTranslation(); ::GlobalUnlock(mhGlobalInvert); ::GlobalFree(mhGlobalInvert); mhGlobalInvert=hGlobal; mhpImageInvert=ptr; ::InvalidateRect(GetHandle(),NULL,TRUE); waitCursor(FALSE); enableMenu(TRUE); } void ViewWindow::shearTransform(void) { HGLOBAL hGlobalTemp; WORD width(mWidth); WORD height(mHeight); double xFactor(0.3); double yFactor(0.00); Factor shearFactor(GetHandle(),"Shear Factors"); if(!shearFactor.showFactor(xFactor,yFactor))return; Shear shearTransform; hGlobalTemp=shearTransform.performShear (width,height,xFactor,yFactor,mhpImageInvert); if(hGlobalTemp) { ::GlobalUnlock(mhGlobalInvert); ::GlobalFree(mhGlobalInvert); mpBI->bmiHeader.biWidth=mWidth=width; mpBI->bmiHeader.biHeight=mHeight=height; mhGlobalInvert=hGlobalTemp; mhpImageInvert=(UHUGE*)::GlobalLock(hGlobalTemp); } ::InvalidateRect(GetHandle(),NULL,TRUE); } void ViewWindow::warpPerspective(void) { HGLOBAL hGlobalTemp; Factor::Operation widthOperation; Factor::Operation heightOperation; double widthIncremental; double heightIncremental; double wRow; double wCol; WORD isCancelled; Factor resizeFactor(GetHandle(),"Perpective Warp"); if(!resizeFactor.showFactor( wRow,wCol, widthIncremental,widthOperation, heightIncremental,heightOperation ))return; enableMenu(FALSE); if(Factor::None==widthOperation&&Factor::None==heightOperation) mpPerspectiveWarp=new PerspectiveWarp(mWidth,mHeight,mhpImageInvert,wRow,wCol); else mpPerspectiveWarp=new PerspectiveWarp(mWidth,mHeight,wRow,wCol, (PerspectiveWarp::Operation)widthOperation,widthIncremental, (PerspectiveWarp::Operation)heightOperation,heightIncremental,mhpImageInvert); hGlobalTemp=mpPerspectiveWarp->performPerspectiveWarp(); isCancelled=mpPerspectiveWarp->isCancelled(); delete mpPerspectiveWarp; mpPerspectiveWarp=0; enableMenu(TRUE); if(isCancelled)return; if(hGlobalTemp) { ::GlobalUnlock(mhGlobalInvert); ::GlobalFree(mhGlobalInvert); mhGlobalInvert=hGlobalTemp; mhpImageInvert=(UHUGE*)::GlobalLock(hGlobalTemp); } ::InvalidateRect(GetHandle(),NULL,TRUE); } void ViewWindow::warpConvex(void) { HGLOBAL hGlobalTemp; WORD isCancelled; mlpConvexTransform=new Convex; hGlobalTemp=mlpConvexTransform->performConvex(mWidth,mHeight,mhpImageInvert); isCancelled=mlpConvexTransform->isCancelled(); delete mlpConvexTransform; mlpConvexTransform=0; if(isCancelled)return; if(hGlobalTemp) { ::GlobalUnlock(mhGlobalInvert); ::GlobalFree(mhGlobalInvert); mhGlobalInvert=hGlobalTemp; mhpImageInvert=(UHUGE*)::GlobalLock(hGlobalTemp); } ::InvalidateRect(GetHandle(),NULL,TRUE); } // ********************************************************************************* void ViewWindow::meshWarp(Direction warpDirection) { Vector sourcePairs; Vector destPairs; Vector meshFrames; Vector sourcePoints; Vector destPoints; Block intermediatePathFileNames; HGLOBAL hGlobalOriginal; UHUGE *lpOriginal; int originalWidth; int originalHeight; HGLOBAL hGlobalTemp(0); MeshFrames meshFrame; int newWidth; int newHeight; size_t size; mlpGridMesh->retrieveMesh(sourcePoints,destPoints); if((size=(int)sourcePoints.size())!=destPoints.size())return; sourcePairs.size(destPairs.size(size)); for(int i=0;irowCols(),newWidth,newHeight); ::GlobalUnlock(mhGlobalInvert); ::GlobalFree(mhGlobalInvert); if(!hGlobalTemp)break; mhGlobalInvert=hGlobalTemp; mhpImageInvert=(UHUGE*)::GlobalLock(hGlobalTemp); mpBI->bmiHeader.biWidth=mWidth=newWidth; mpBI->bmiHeader.biHeight=mHeight=newHeight; ::InvalidateRect(GetHandle(),NULL,TRUE); ::UpdateWindow(GetHandle()); Bitmap bitmapImage(intermediatePathFileNames[i+1],mhGlobalInvert,mhBMPGlobal); bitmapImage.saveBitmap(); } if(!hGlobalTemp) { String tempString; ::sprintf(tempString,"Warp failed at %d",i); ::MessageBox(GetHandle(),(LPSTR)tempString,(LPSTR)"WARP ERROR",MB_ICONASTERISK); mhGlobalInvert=hGlobalOriginal; mhpImageInvert=lpOriginal; mpBI->bmiHeader.biWidth=mWidth=originalWidth; mpBI->bmiHeader.biHeight=mHeight=originalHeight; } else { ::GlobalUnlock(hGlobalOriginal); ::GlobalFree(hGlobalOriginal); } if(WarpForward==warpDirection)createProjectFile(intermediatePathFileNames); ::InvalidateRect(GetHandle(),NULL,TRUE); mlpGridMesh->showWindow(); } void ViewWindow::meshWarp(ViewWindow *lpTargetView) { Block intermediateSrcImage; Block intermediateDstImage; CrossDissolve crossDissolve; WORD currentTargetFrames; meshWarp(); currentTargetFrames=lpTargetView->mCurrentMeshFrames; lpTargetView->mCurrentMeshFrames=mCurrentMeshFrames; lpTargetView->meshWarp(WarpReverse); sequentialNames(mPathFileName,intermediateSrcImage,mCurrentMeshFrames); lpTargetView->sequentialNames(lpTargetView->mPathFileName,intermediateDstImage,lpTargetView->mCurrentMeshFrames); if(mDissolveSchedule.size()) crossDissolve.crossDissolve(intermediateSrcImage,intermediateDstImage,mDissolveSchedule); else crossDissolve.crossDissolve(intermediateSrcImage,intermediateDstImage); lpTargetView->mCurrentMeshFrames=currentTargetFrames; } void ViewWindow::createProjectFile(Block &pathFileNames) { String projectIDString(STRING_PROJECTIDSTRING,Main::processInstance()); String projectExtension(STRING_PROJECTEXTENSION,Main::processInstance()); String carriageReturn(STRING_CRLF,Main::processInstance()); String dotString(STRING_DOT,Main::processInstance()); String fileNameString; size_t size((int)pathFileNames.size()); if(!size)return; fileNameString=pathFileNames[0]; fileNameString.token(dotString); fileNameString+=projectExtension; ofstream outputProject(fileNameString); if(!outputProject.fail()&&!outputProject.bad()) { outputProject << (LPSTR)projectIDString << (LPSTR)carriageReturn; for(int i=0;i &pathFileNames,int nFrames) { IniFile iniSettings; String currentExtension(STRING_MESHEXTENSION,Main::processInstance()); String dotString(STRING_DOT,Main::processInstance()); String tempString(pathFileName); String intermediatePathFileName; pathFileNames.remove(); iniSettings.makeFileName(tempString); intermediatePathFileName=iniSettings.projectDirectory(); intermediatePathFileName+=tempString; for(int i=0;i