home *** CD-ROM | disk | FTP | other *** search
- // WINVP.C
- // Editor's Tab stops are 4.
-
- //---------------------------Include & define (start)------------------------
- #include <windows.h>
- #include "video.h"
- #include "winv.h"
-
- #define _8_Bits_Gray 1 // for demo 256-color gray scale
- #define _15_Bits 2 // for demo 32K HiColor
- #define _16_Bits 3 // for demo 64K HiColor
- #define _24_Bits 4 // for demo True Color
-
- // Please modify this line for your image format.
- #define _What_Data_Format _24_Bits
-
- //----------------------------Global variable (start)------------------------
- WORD gwWidth, gwHeight;
-
-
- //-------------------------Local Function Declaration------------------------
- long FAR PASCAL MainWndProc(HWND, UINT, WPARAM, LPARAM);
- void NEAR PASCAL _LoadSample(WORD wBitsPerPixel);
- void NEAR PASCAL _SaveSample(WORD wBitsPerPixel);
-
-
- //-------------------------------WinMain (start)-----------------------------
- /*---------------------------------------------------------------------------
- | |
- | Function: WinMain(HANDLE, HANDLE, LPSTR, int) |
- | |
- | Purpose: Entry point of Windows application. |
- | |
- ---------------------------------------------------------------------------*/
- int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine,
- int nCmdShow)
- {
- MSG msg;
-
- if(!hPrevInstance)
- if(!InitApplication(hInstance))
- return (FALSE);
-
- if (!InitInstance(hInstance, nCmdShow))
- return (FALSE);
-
- while (GetMessage(&msg, NULL, NULL, NULL)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-
- return (msg.wParam);
- }
-
-
- /*---------------------------------------------------------------------------
- | |
- | Function: InitApplication(HANDLE) |
- | |
- | Purpose: Initialize window class. |
- | |
- ---------------------------------------------------------------------------*/
- BOOL InitApplication(HANDLE hInstance)
- {
- WNDCLASS wc;
-
- wc.style = NULL;
- wc.lpfnWndProc = MainWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(hInstance, "VPDemoIcon");
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = GetStockObject(WHITE_BRUSH);
- wc.lpszMenuName = "VPDemoMenu";
- wc.lpszClassName = "VPDemoWClass";
-
- return (RegisterClass(&wc));
- }
-
-
- /*---------------------------------------------------------------------------
- | |
- | Function: InitInstance(HANDLE, int) |
- | |
- | Purpose: Initialize and create window. |
- | |
- ---------------------------------------------------------------------------*/
- BOOL InitInstance(HANDLE hInstance, int nCmdShow)
- {
- HWND hWnd;
-
- hWnd = CreateWindowEx(
- WS_EX_TOPMOST,
- "VPDemoWClass",
- "Video Demo",
- WS_OVERLAPPED | WS_CAPTION | WS_BORDER | WS_SYSMENU,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 320,
- 280,
- NULL,
- NULL,
- hInstance,
- NULL
- );
-
- if (!hWnd)
- return (FALSE);
-
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
-
- return (TRUE);
- }
-
-
- //-------------------------Window function (start)---------------------------
- /*---------------------------------------------------------------------------
- | |
- | Function: MainWndProc(HWND, UINT, WPARAM, LPARAM) |
- | |
- | Purpose: Window function of main video window. |
- | |
- ---------------------------------------------------------------------------*/
- long FAR PASCAL MainWndProc(HWND hWnd, UINT message, WPARAM wParam,
- LPARAM lParam )
- {
- FARPROC lpProcAbout;
- RECT rect;
- POINT pTemp;
- HDC hDC;
- PAINTSTRUCT ps;
- HBRUSH hGrayBrush;
-
- switch (message) {
- case WM_CREATE:
- gwWidth = 320;
- gwHeight = 240;
- VIDEO_Initialize();
- VIDEO_FreezeVideo();
- //for Windows 3.1
- //VIDEO_SetVideoPos(0, 0, gwWidth, gwHeight);
- VIDEO_SetVideoSource(1);
- VIDEO_SetInputFormat(VIDEO_NTSC);
- VIDEO_SetHorizontalAlignment(102);
- VIDEO_SetVerticalAlignment(15);
- VIDEO_SetHorizontalCrop(640);
- VIDEO_SetVerticalCrop(480);
- break;
-
- case WM_PAINT:
- hDC = BeginPaint(hWnd, &ps);
- hGrayBrush = CreateSolidBrush(RGB(192, 192, 192));
- GetClientRect(hWnd, (LPRECT)&rect);
- FillRect(hDC, &rect, hGrayBrush);
- DeleteObject(hGrayBrush);
- EndPaint(hWnd, &ps);
-
- pTemp.x = rect.left;
- pTemp.y = rect.top;
- ClientToScreen(hWnd, &pTemp);
- rect.left = pTemp.x;
- rect.top = pTemp.y;
-
- pTemp.x = rect.right;
- pTemp.y = rect.bottom;
- ClientToScreen(hWnd, &pTemp);
- rect.right = pTemp.x;
- rect.bottom = pTemp.y;
-
- VIDEO_SetVideoPos(
- rect.left,
- rect.top,
- rect.right - rect.left,
- rect.bottom - rect.top
- );
-
- VIDEO_UnfreezeVideo();
- break;
-
- case WM_NCLBUTTONDOWN:
- VIDEO_FreezeVideo();
- return (DefWindowProc(hWnd, message, wParam, lParam));
-
- case WM_SIZE:
- case WM_MOVE:
- InvalidateRect(hWnd, NULL, TRUE);
- break;
-
- case WM_COMMAND:
- switch(wParam) {
- case IDM_SIZE4:
- gwWidth = 320;
- gwHeight = 240;
- VIDEO_UnfreezeVideo();
- SetWindowPos(
- hWnd,
- (HWND)NULL,
- 0,
- 0,
- gwWidth,
- gwHeight+40,
- SWP_NOZORDER | SWP_NOMOVE
- );
- break;
-
- case IDM_SIZE16:
- gwWidth = 160;
- gwHeight = 120;
- VIDEO_UnfreezeVideo();
- SetWindowPos(
- hWnd,
- (HWND)NULL,
- 0,
- 0,
- gwWidth,
- gwHeight + 40,
- SWP_NOZORDER | SWP_NOMOVE
- );
- break;
-
- case IDM_LOAD:
- _LoadSample(_What_Data_Format);
- break;
-
- case IDM_SAVE:
- _SaveSample(_What_Data_Format);
- break;
-
- case IDM_DISABLE_VIDEO:
- VIDEO_DisableVideo();
- InvalidateRect(hWnd, NULL, TRUE);
- break;
-
- case IDM_ENABLE_VIDEO:
- VIDEO_EnableVideo();
- break;
-
- case IDM_FREEZE_VIDEO:
- VIDEO_FreezeVideo();
- break;
-
- case IDM_UNFREEZE_VIDEO:
- VIDEO_UnfreezeVideo();
- //InvalidateRect(hWnd, NULL, TRUE);
- break;
-
- case IDM_SAVETO_TBMP:
- VIDEO_SaveImageFile("t.bmp", 0, 0, 100, 100, VIDEO_BMP24);
- break;
-
- default:
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- break;
-
- case WM_DESTROY:
- VIDEO_DisableVideo();
- VIDEO_End();
- PostQuitMessage(0);
- break;
-
- default:
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- return (NULL);
- }
-
-
- static BYTE ImageBuffer16[50*50*2];
- static BYTE ImageBuffer24[50*50*3];
- void NEAR PASCAL _LoadSample(WORD wBitsPerPixel)
- {
- VIDEO_FreezeVideo();
-
- switch(wBitsPerPixel) {
- case _8_Bits_Gray:
- VIDEO_LoadImageRect((BYTE _huge *)ImageBuffer16,
- 10, 10, 50, 50,
- VIDEO_BMP_8_GRAY, 0);
- break;
-
- case _15_Bits:
- VIDEO_LoadImageRect((BYTE _huge *)ImageBuffer16,
- 10, 10, 50, 50,
- VIDEO_BMP_15, 0);
- break;
-
- case _16_Bits:
- VIDEO_LoadImageRect((BYTE _huge *)ImageBuffer16,
- 10, 10, 50, 50,
- VIDEO_BMP_16, 0);
- break;
-
- case _24_Bits:
- VIDEO_LoadImageRect((BYTE _huge *)ImageBuffer24,
- 10, 10, 50, 50,
- VIDEO_BMP_24, 0);
- break;
- }
- VIDEO_UnfreezeVideo();
- }
-
-
- void NEAR PASCAL _SaveSample(WORD wBitsPerPixel)
- {
- int idx, *pDat;
-
- VIDEO_FreezeVideo();
-
- switch(wBitsPerPixel) {
- case _8_Bits_Gray:
- for(idx=0; idx<50*50*2; idx++)
- ImageBuffer16[idx] = 0xff - ImageBuffer16[idx];
- VIDEO_RestoreImageRect((BYTE _huge *)ImageBuffer16,
- 10, 10, 50, 50,
- VIDEO_BMP_8_GRAY, 0);
- break;
-
- case _15_Bits:
- pDat = (int *)ImageBuffer16;
- for(idx=0; idx<50*50; idx++)
- pDat[idx] = 0x7fff - pDat[idx];
- VIDEO_RestoreImageRect((BYTE _huge *)ImageBuffer16,
- 10, 10, 50, 50,
- VIDEO_BMP_15, 0);
- break;
-
- case _16_Bits:
- for(idx=0; idx<50*50*2; idx++)
- ImageBuffer16[idx] = 0xff - ImageBuffer16[idx];
- VIDEO_RestoreImageRect((BYTE _huge *)ImageBuffer16,
- 10, 10, 50, 50,
- VIDEO_BMP_16, 0);
- break;
-
- case _24_Bits:
- for(idx=0; idx<50*50*3; idx++)
- ImageBuffer24[idx] = 0xff - ImageBuffer24[idx];
- VIDEO_RestoreImageRect((BYTE _huge *)ImageBuffer24,
- 10, 10, 50, 50,
- VIDEO_BMP_24, 0);
- break;
- }
- }
-
- //-----------------------------------(end)-----------------------------------
-