int main(int argc, char* argv[]) { int speed; if (argc == 3) { if (sscanf(argv[1],"-s%d",&speed) != 1) { DisplayUsage(); return 0; } NextImage(argv[2], speed); } else if(argc == 2) { speed = 1000; NextImage(argv[1], speed); } else DisplayUsage(); return 0; }
void RBUITutorial::NextFrame(float delta) { if(m_runcheck) { RBCourseEntry *course = GetCourseData(m_course); if(course && course->m_holes != kCourseDrivingRange) { m_done = true; return; } m_runcheck = false; m_texture = -1; m_curImage = -1; NextImage(); } if(m_imageDelay > 0) { m_imageDelay--; if(m_imageDelay == 0) { if(m_texture >= 0) { m_texture = RudeTextureManager::GetInstance()->ReplaceTextureFromPNGFile(m_texture, kTutorialImages[m_curImage]); } else { m_texture = RudeTextureManager::GetInstance()->LoadTextureFromPNGFile(kTutorialImages[m_curImage]); } } } }
BOOL CPlayGif::Play1(void) { HDC hDC,hMemDC,hMemDC1,hPauseMemDC; HBITMAP hOldBitmap,hOldBitmap1,hBitmap,hPreviousBitmap,hPauseBitmap; DWORD systimer1,systimer2,speed; BOOL PauseShow=FALSE; hDC=::GetDC(m_hWnd); hMemDC=::CreateCompatibleDC(hDC); hMemDC1=::CreateCompatibleDC(hDC); hPauseMemDC=::CreateCompatibleDC(hDC); m_hDC=hDC; hPreviousBitmap=0; while(m_bLockBitmap); m_bLockBitmap=TRUE; if(m_hRedrawBitmap!=0)DeleteObject(m_hRedrawBitmap); m_hRedrawBitmap=::CreateCompatibleBitmap(hDC,m_iGifWidth,m_iGifHeight); hOldBitmap1=(HBITMAP)SelectObject(hMemDC1,m_hRedrawBitmap); hPauseBitmap=::CreateCompatibleBitmap(hDC,m_iGifWidth,m_iGifHeight); SelectObject(hPauseMemDC,hPauseBitmap); ::BitBlt(hMemDC1,0,0,m_iGifWidth,m_iGifHeight,hDC,m_nPosX,m_nPosY,SRCCOPY); SelectObject(hMemDC1,hOldBitmap1); m_bLockBitmap=FALSE; m_iDisposalMethod=DISPOSAL_NOT; while(m_EndRun!=1) { systimer2=systimer1=GetTickCount(); while(m_bLockBitmap); m_bLockBitmap=TRUE; hOldBitmap1=(HBITMAP)SelectObject(hMemDC1,m_hRedrawBitmap); switch(m_iDisposalMethod) { case DISPOSAL_NO: break; case DISPOSAL_NOT: break; case DISPOSAL_RESTBACK: case DISPOSAL_RESTORE: hOldBitmap=(HBITMAP)SelectObject(hMemDC,hPreviousBitmap); ::BitBlt(hMemDC1,m_iLeft,m_iTop,m_iWidth,m_iHeight,hMemDC,0,0,SRCCOPY); SelectObject(hMemDC,hOldBitmap); DeleteObject(hPreviousBitmap); hPreviousBitmap=0; break; } m_iDisposalMethod=DISPOSAL_NO; //tel:13366898744 if(!PauseShow) { hBitmap=NextImage(); switch(m_iDisposalMethod) { case DISPOSAL_NO: break; case DISPOSAL_NOT: break; case DISPOSAL_RESTBACK: case DISPOSAL_RESTORE: hPreviousBitmap=::CreateCompatibleBitmap(hDC,m_iWidth,m_iHeight); hOldBitmap=(HBITMAP)SelectObject(hMemDC,hPreviousBitmap); ::BitBlt(hMemDC,0,0,m_iWidth,m_iHeight,hMemDC1,m_iLeft,m_iTop,SRCCOPY); SelectObject(hMemDC,hOldBitmap); break; } hOldBitmap=(HBITMAP)SelectObject(hMemDC,hBitmap); if(m_bTransparentIndex) { HBITMAP bmAndBack, bmAndObject; HBITMAP bmBackOld, bmObjectOld; HDC hdcBack, hdcObject; COLORREF cColor; hdcBack=::CreateCompatibleDC(hDC); hdcObject=::CreateCompatibleDC(hDC); bmAndBack=CreateBitmap(m_iWidth,m_iHeight,1,1,NULL); bmAndObject=CreateBitmap(m_iWidth,m_iHeight,1,1,NULL); bmBackOld=(HBITMAP)SelectObject(hdcBack,bmAndBack); bmObjectOld=(HBITMAP)SelectObject(hdcObject,bmAndObject); cColor=SetBkColor(hMemDC,m_TransparentColor); ::BitBlt(hdcObject,0,0,m_iWidth,m_iHeight,hMemDC,0,0,SRCCOPY); SetBkColor(hMemDC,cColor); ::BitBlt(hdcBack,0,0,m_iWidth,m_iHeight,hdcObject,0,0,NOTSRCCOPY); ::BitBlt(hMemDC1,m_iLeft,m_iTop,m_iWidth,m_iHeight,hdcObject,0,0,SRCAND); ::BitBlt(hMemDC,0,0,m_iWidth,m_iHeight,hdcBack,0,0,SRCAND); ::BitBlt(hMemDC1,m_iLeft,m_iTop,m_iWidth,m_iHeight,hMemDC,0,0,SRCPAINT); DeleteObject(SelectObject(hdcBack,bmBackOld)); DeleteObject(SelectObject(hdcObject,bmObjectOld)); DeleteDC(hdcBack); DeleteDC(hdcObject); } else { ::BitBlt(hMemDC1,m_iLeft,m_iTop,m_iWidth,m_iHeight,hMemDC,0,0,SRCCOPY); } SelectObject(hMemDC,hOldBitmap); DeleteObject(hBitmap); ::BitBlt(hDC,m_nPosX,m_nPosY,m_iGifWidth,m_iGifHeight,hMemDC1,0,0,SRCCOPY); ::BitBlt(hPauseMemDC,0,0,m_iGifWidth,m_iGifHeight,hMemDC1,0,0,SRCCOPY); } else ::BitBlt(hDC,m_nPosX,m_nPosY,m_iGifWidth,m_iGifHeight,hPauseMemDC,0,0,SRCCOPY); SelectObject(hMemDC1,hOldBitmap1); m_bLockBitmap=FALSE; if(m_iDelayTime!=0)speed=m_iDelayTime*10;else speed=m_dwSpeed; while((m_EndRun!=1)&&(speed>systimer2-systimer1)) { Sleep(10); systimer2=GetTickCount(); } PauseShow=m_bPause; } if(hPreviousBitmap!=0)DeleteObject(hPreviousBitmap); DeleteDC(hMemDC); DeleteDC(hMemDC1); ::ReleaseDC(m_hWnd,hDC); m_EndRun=2; return TRUE; }
HBITMAP CPlayGif::FirstImage(void) { m_pcGifTrack=m_pcGif; m_iTotalReadByte=0; return NextImage(); }
LRESULT CALLBACK MainWindowProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) { switch (message) { case WM_CREATE: { ImageDC = CreateCompatibleDC(NULL); SetTimer(window, TIMER_ID, Timer, NULL); return 0; } //////////////////////////////////////////////////////////////////////// case WM_DESTROY: { KillTimer(window, TIMER_ID); DeleteDC(ImageDC); ImageList.clear(); PostQuitMessage(0); return 0; } //////////////////////////////////////////////////////////////////////// case WM_RBUTTONUP: { HMENU menu = LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(IDR_MAIN)); HMENU sub_menu = GetSubMenu(menu, 0); // update the menu switch (Timer) { case 0: CheckMenuItem(menu, ID_MAIN_DELAY_NONE, BST_CHECKED); break; case 1000: CheckMenuItem(menu, ID_MAIN_DELAY_1S, BST_CHECKED); break; case 2000: CheckMenuItem(menu, ID_MAIN_DELAY_2S, BST_CHECKED); break; case 5000: CheckMenuItem(menu, ID_MAIN_DELAY_5S, BST_CHECKED); break; case 10000: CheckMenuItem(menu, ID_MAIN_DELAY_10S, BST_CHECKED); break; default: CheckMenuItem(menu, ID_MAIN_DELAY_OTHER, BST_CHECKED); break; } if (DisplayMode == DM_ORIGINALSIZE) { CheckMenuItem(menu, ID_MAIN_DISPLAY_ORIGINALSIZE, BST_CHECKED); } else { CheckMenuItem(menu, ID_MAIN_DISPLAY_STRETCHED, BST_CHECKED); } if (Random) { CheckMenuItem(menu, ID_MAIN_OPTIONS_RANDOM, BST_CHECKED); } if (RecurseSubdirectories) { CheckMenuItem(menu, ID_MAIN_OPTIONS_RECURSESUBDIRECTORIES, BST_CHECKED); } POINT cursor; GetCursorPos(&cursor); TrackPopupMenuEx(sub_menu, TPM_LEFTALIGN | TPM_TOPALIGN, cursor.x, cursor.y, window, NULL); return 0; } //////////////////////////////////////////////////////////////////////// case WM_LBUTTONDOWN: { if (wparam & MK_SHIFT) { PrevImage(); } else { NextImage(); } InvalidateRect(window, NULL, TRUE); ResetTimer(window); return 0; } //////////////////////////////////////////////////////////////////////// case WM_KEYDOWN: { /// @todo check the key NextImage(); InvalidateRect(window, NULL, TRUE); return 0; } //////////////////////////////////////////////////////////////////////// case WM_COMMAND: { switch (LOWORD(wparam)) { case ID_MAIN_SETDIRECTORY: { char image_folder[MAX_PATH]; if (BrowseForFolderDialog(window, "Choose Image Directory", image_folder)) { // now that we have the directory, update the image list CurrentImage = -1; ImageList.clear(); CreateImageList(image_folder); UpdateImage(); InvalidateRect(window, NULL, TRUE); ResetTimer(window); } return 0; } case ID_MAIN_DELAY_NONE: { Timer = 0; ResetTimer(window); return 0; } case ID_MAIN_DELAY_1S: { Timer = 1000; ResetTimer(window); return 0; } case ID_MAIN_DELAY_2S: { Timer = 2000; ResetTimer(window); return 0; } case ID_MAIN_DELAY_5S: { Timer = 5000; ResetTimer(window); return 0; } case ID_MAIN_DELAY_10S: { Timer = 10000; ResetTimer(window); return 0; } case ID_MAIN_DELAY_OTHER: { int timer = GetDelayDialog(window); if (timer != -1) Timer = timer; ResetTimer(window); return 0; } case ID_MAIN_DISPLAY_ORIGINALSIZE: { DisplayMode = DM_ORIGINALSIZE; InvalidateRect(window, NULL, TRUE); return 0; } case ID_MAIN_DISPLAY_STRETCHED: { DisplayMode = DM_STRETCHED; InvalidateRect(window, NULL, TRUE); return 0; } case ID_MAIN_OPTIONS_RANDOM: { Random = !Random; return 0; } case ID_MAIN_OPTIONS_RECURSESUBDIRECTORIES: { RecurseSubdirectories = !RecurseSubdirectories; return 0; } case ID_MAIN_ABOUT: { MessageBox(window, "(c) Chad Austin 2002\n" __DATE__, "PictureShow", MB_OK); return 0; } case ID_MAIN_EXIT: { DestroyWindow(window); return 0; } } return 0; } //////////////////////////////////////////////////////////////////////// case WM_TIMER: { if (Timer != 0) { NextImage(); InvalidateRect(window, NULL, TRUE); } return 0; } //////////////////////////////////////////////////////////////////////// case WM_PAINT: { PAINTSTRUCT ps; BeginPaint(window, &ps); // draw the image if (ImageWidth != 0 && ImageHeight != 0) { int screen_width = GetSystemMetrics(SM_CXSCREEN); int screen_height = GetSystemMetrics(SM_CYSCREEN); bool stretched_view = DisplayMode == DM_STRETCHED; if (DisplayMode == DM_ORIGINALSIZE) { // original size view if (ImageWidth < screen_width && ImageHeight < screen_height) { int x = (screen_width - ImageWidth) / 2; int y = (screen_height - ImageHeight) / 2; HBITMAP old = (HBITMAP)SelectObject(ImageDC, ImageBitmap); BitBlt(ps.hdc, x, y, ImageWidth, ImageHeight, ImageDC, 0, 0, SRCCOPY); SelectObject(ImageDC, old); } else { // do the stretched view if the image is bigger than the screen stretched_view = true; } } // stretched view if (stretched_view) { float screen_aspect_ratio = (float)screen_width / screen_height; // calculate destination rectangle float image_aspect_ratio = (float)ImageWidth / ImageHeight; int dest_x = 0; int dest_y = 0; int dest_w; int dest_h; // we're going to fill the width, but not the height if (image_aspect_ratio > screen_aspect_ratio) { dest_w = screen_width; dest_h = (int)(screen_height * screen_aspect_ratio / image_aspect_ratio); } else { dest_w = (int)(screen_width * image_aspect_ratio / screen_aspect_ratio); dest_h = screen_height; } dest_x = (screen_width - dest_w) / 2; dest_y = (screen_height - dest_h) / 2; HBITMAP old = (HBITMAP)SelectObject(ImageDC, ImageBitmap); StretchBlt(ps.hdc, dest_x, dest_y, dest_w, dest_h, ImageDC, 0, 0, ImageWidth, ImageHeight, SRCCOPY); (HBITMAP)SelectObject(ImageDC, old); } } // draw the image filename char text[MAX_PATH + 80]; sprintf(text, "%d/%d", CurrentImage + 1, ImageList.size()); if (CurrentImage < ImageList.size() && ImageList.size() > 0) { strcat(text, " -- "); strcat(text, ImageList[CurrentImage].c_str()); } DrawShadedText(ps.hdc, 0, 0, text); EndPaint(window, &ps); return 0; } //////////////////////////////////////////////////////////////////////// default: { return DefWindowProc(window, message, wparam, lparam); } } }
// Loads image from files 1-9 // Allocates memory for source images in 3D cube // based size of image, image type must be bmp int loadImages(char* fileName, const char* path, byte** imgSrc, ROI* imgSize, int *imgStride, int depth) { //preload image (acquire dimensions) int ImgWidth, ImgHeight, tmpW, tmpH; ROI imgOrgSize; // Original byte *imgCur; //char *pImageFpath = cutFindFilePath(fileName, path); char ImageName[50]; sprintf(ImageName, fileName, 1); DEBUG_MSG("[loadImages]\n"); int res = PreLoadBmp(ImageName, &ImgWidth, &ImgHeight); if (res) { printf("\nError %d: Image file %s not found or invalid!\n", res, ImageName); printf("Press ENTER to exit...\n"); getchar(); return 1; } tmpW = ImgWidth % BLOCK_SIZE; if (tmpW > 0) ImgWidth += BLOCK_SIZE - tmpW; tmpH = ImgHeight % BLOCK_SIZE; if (tmpH > 0) ImgHeight += BLOCK_SIZE - tmpH; //check image dimensions are multiples of BLOCK_SIZE if (ImgWidth % BLOCK_SIZE != 0 || ImgHeight % BLOCK_SIZE != 0) { printf("\nError: Input image dimensions must be multiples of 8!\n"); printf("Press ENTER to exit...\n"); getchar(); return 1; } //allocate image buffers *imgSrc = MallocCubeByte(ImgWidth, ImgHeight, depth, imgStride); imgSize->width = ImgWidth; imgSize->height = ImgHeight; imgCur = *imgSrc; //load sample images for (int i = 1; i <= depth; i++) { DEBUG_MSG("Loading image %s [%d,%d,%d] \n", ImageName, ImgWidth, ImgHeight, *imgStride); sprintf(ImageName, fileName, i); res = PreLoadBmp(ImageName, &tmpW, &tmpH); if (res) { printf("\nError %d: Image file %s not found or invalid!\n", res, ImageName); printf("Press ENTER to exit...\n"); getchar(); return 1; } imgOrgSize.height = tmpH; imgOrgSize.width = tmpW; DEBUG_MSG("Loading org image %s [%d,%d] \n", ImageName, tmpW, tmpH, *imgStride); LoadBmpAsGray(ImageName, *imgStride, imgOrgSize, imgCur); imgCur = NextImage(imgCur, *imgStride, *imgSize); } DEBUG_MSG("Images size [%d * %d * %d], stride %d \n", ImgWidth, ImgHeight, depth, *imgStride); return 0; }
void RBUITutorial::TouchDown(RudeTouch *rbt) { NextImage(); }