home *** CD-ROM | disk | FTP | other *** search
/ Computer Tool Software / soft.iso / Multimed / WINFAST / WFST230 / WIN95 / EXAMPLE / WINV.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-22  |  9.6 KB  |  349 lines

  1. // WINVP.C
  2. // Editor's Tab stops are 4.
  3.  
  4. //---------------------------Include & define (start)------------------------
  5. #include    <windows.h>
  6. #include    "video.h"
  7. #include    "winv.h"
  8.  
  9. #define     _8_Bits_Gray    1   // for demo 256-color gray scale
  10. #define     _15_Bits        2   // for demo 32K HiColor 
  11. #define     _16_Bits        3   // for demo 64K HiColor
  12. #define     _24_Bits        4   // for demo True Color
  13.  
  14. // Please modify this line for your image format.
  15. #define     _What_Data_Format           _24_Bits
  16.  
  17. //----------------------------Global variable (start)------------------------
  18. WORD        gwWidth, gwHeight;
  19.  
  20.  
  21. //-------------------------Local Function Declaration------------------------
  22. long FAR  PASCAL  MainWndProc(HWND, UINT, WPARAM, LPARAM);
  23. void NEAR PASCAL  _LoadSample(WORD wBitsPerPixel);
  24. void NEAR PASCAL  _SaveSample(WORD wBitsPerPixel);
  25.  
  26.  
  27. //-------------------------------WinMain (start)-----------------------------
  28. /*---------------------------------------------------------------------------
  29. |                                                                           |
  30. |  Function: WinMain(HANDLE, HANDLE, LPSTR, int)                            |
  31. |                                                                           |
  32. |  Purpose: Entry point of Windows application.                             |
  33. |                                                                           |
  34. ---------------------------------------------------------------------------*/
  35. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine,
  36.                    int nCmdShow)
  37. {
  38.     MSG        msg;
  39.  
  40.     if(!hPrevInstance)
  41.         if(!InitApplication(hInstance))
  42.             return (FALSE);
  43.  
  44.     if (!InitInstance(hInstance, nCmdShow))
  45.         return (FALSE);
  46.  
  47.     while (GetMessage(&msg, NULL, NULL, NULL)) {
  48.         TranslateMessage(&msg);
  49.         DispatchMessage(&msg);
  50.     }
  51.  
  52.     return (msg.wParam);
  53. }
  54.  
  55.  
  56. /*---------------------------------------------------------------------------
  57. |                                                                           |
  58. |  Function: InitApplication(HANDLE)                                        |
  59. |                                                                           |
  60. |  Purpose: Initialize window class.                                        |
  61. |                                                                           |
  62. ---------------------------------------------------------------------------*/
  63. BOOL InitApplication(HANDLE hInstance)
  64. {
  65.     WNDCLASS          wc;
  66.  
  67.     wc.style          = NULL;
  68.     wc.lpfnWndProc    = MainWndProc;
  69.     wc.cbClsExtra     = 0;
  70.     wc.cbWndExtra     = 0;
  71.     wc.hInstance      = hInstance;
  72.     wc.hIcon          = LoadIcon(hInstance, "VPDemoIcon");
  73.     wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
  74.     wc.hbrBackground  = GetStockObject(WHITE_BRUSH);
  75.     wc.lpszMenuName   = "VPDemoMenu";
  76.     wc.lpszClassName  = "VPDemoWClass";
  77.  
  78.     return (RegisterClass(&wc));
  79. }
  80.  
  81.  
  82. /*---------------------------------------------------------------------------
  83. |                                                                           |
  84. |  Function: InitInstance(HANDLE, int)                                      |
  85. |                                                                           |
  86. |  Purpose: Initialize and create window.                                   |
  87. |                                                                           |
  88. ---------------------------------------------------------------------------*/
  89. BOOL InitInstance(HANDLE hInstance, int nCmdShow)
  90. {
  91.     HWND         hWnd;
  92.  
  93.     hWnd  = CreateWindowEx(
  94.                 WS_EX_TOPMOST,
  95.                 "VPDemoWClass",
  96.                 "Video Demo",
  97.                 WS_OVERLAPPED | WS_CAPTION | WS_BORDER | WS_SYSMENU,
  98.                 CW_USEDEFAULT,
  99.                 CW_USEDEFAULT,
  100.                 320,
  101.                 280,
  102.                 NULL,
  103.                 NULL,
  104.                 hInstance,
  105.                 NULL
  106.             );
  107.  
  108.     if (!hWnd)
  109.         return (FALSE);
  110.  
  111.     ShowWindow(hWnd, nCmdShow);
  112.     UpdateWindow(hWnd);
  113.  
  114.     return (TRUE);
  115. }
  116.  
  117.  
  118. //-------------------------Window function (start)---------------------------
  119. /*---------------------------------------------------------------------------
  120. |                                                                           |
  121. |  Function: MainWndProc(HWND, UINT, WPARAM, LPARAM)                        |
  122. |                                                                           |
  123. |  Purpose: Window function of main video window.                           |
  124. |                                                                           |
  125. ---------------------------------------------------------------------------*/
  126. long FAR PASCAL MainWndProc(HWND hWnd, UINT message, WPARAM wParam,
  127.                             LPARAM lParam )
  128. {
  129.     FARPROC      lpProcAbout;
  130.     RECT         rect;                                                 
  131.     POINT        pTemp;
  132.     HDC          hDC;
  133.     PAINTSTRUCT  ps;
  134.     HBRUSH       hGrayBrush;
  135.  
  136.     switch (message) {
  137.         case WM_CREATE:
  138.             gwWidth  = 320;    
  139.             gwHeight = 240;
  140.             VIDEO_Initialize();
  141.             VIDEO_FreezeVideo();
  142.             //for Windows 3.1
  143.             //VIDEO_SetVideoPos(0, 0, gwWidth, gwHeight);
  144.             VIDEO_SetVideoSource(1);
  145.             VIDEO_SetInputFormat(VIDEO_NTSC);
  146.             VIDEO_SetHorizontalAlignment(102);
  147.             VIDEO_SetVerticalAlignment(15);
  148.             VIDEO_SetHorizontalCrop(640);
  149.             VIDEO_SetVerticalCrop(480);
  150.             break;                             
  151.                                       
  152.         case WM_PAINT:
  153.             hDC         = BeginPaint(hWnd, &ps);
  154.             hGrayBrush  = CreateSolidBrush(RGB(192, 192, 192));
  155.             GetClientRect(hWnd, (LPRECT)&rect);
  156.             FillRect(hDC, &rect, hGrayBrush);
  157.             DeleteObject(hGrayBrush);
  158.             EndPaint(hWnd, &ps);
  159.  
  160.             pTemp.x     = rect.left;           
  161.             pTemp.y     = rect.top;
  162.             ClientToScreen(hWnd, &pTemp);
  163.             rect.left   = pTemp.x;             
  164.             rect.top    = pTemp.y;
  165.  
  166.             pTemp.x     = rect.right;          
  167.             pTemp.y     = rect.bottom;
  168.             ClientToScreen(hWnd, &pTemp);
  169.             rect.right  = pTemp.x;             
  170.             rect.bottom = pTemp.y;
  171.  
  172.             VIDEO_SetVideoPos(
  173.                 rect.left,
  174.                 rect.top,
  175.                 rect.right - rect.left,
  176.                 rect.bottom - rect.top
  177.             );
  178.  
  179.             VIDEO_UnfreezeVideo();
  180.             break;                     
  181.  
  182.         case WM_NCLBUTTONDOWN:
  183.             VIDEO_FreezeVideo();            
  184.             return (DefWindowProc(hWnd, message, wParam, lParam));
  185.  
  186.         case WM_SIZE:
  187.         case WM_MOVE:
  188.             InvalidateRect(hWnd, NULL, TRUE);
  189.             break;
  190.  
  191.         case WM_COMMAND:
  192.             switch(wParam) {
  193.                 case IDM_SIZE4:
  194.                     gwWidth  = 320;    
  195.                     gwHeight = 240;
  196.                     VIDEO_UnfreezeVideo();
  197.                     SetWindowPos(
  198.                         hWnd, 
  199.                         (HWND)NULL, 
  200.                         0, 
  201.                         0, 
  202.                         gwWidth, 
  203.                         gwHeight+40,
  204.                         SWP_NOZORDER | SWP_NOMOVE
  205.                     );
  206.                     break;
  207.  
  208.                 case IDM_SIZE16:
  209.                     gwWidth  = 160;     
  210.                     gwHeight = 120;
  211.                     VIDEO_UnfreezeVideo();
  212.                     SetWindowPos(
  213.                         hWnd, 
  214.                         (HWND)NULL, 
  215.                         0, 
  216.                         0, 
  217.                         gwWidth, 
  218.                         gwHeight + 40,
  219.                         SWP_NOZORDER | SWP_NOMOVE
  220.                     );
  221.                     break;
  222.  
  223.                 case IDM_LOAD:
  224.                     _LoadSample(_What_Data_Format);
  225.                     break;
  226.  
  227.                 case IDM_SAVE:
  228.                     _SaveSample(_What_Data_Format);
  229.                     break;
  230.  
  231.                 case IDM_DISABLE_VIDEO:
  232.                     VIDEO_DisableVideo();
  233.                     InvalidateRect(hWnd, NULL, TRUE);
  234.                     break;
  235.  
  236.                 case IDM_ENABLE_VIDEO:
  237.                     VIDEO_EnableVideo();
  238.                     break;
  239.  
  240.                 case IDM_FREEZE_VIDEO:
  241.                     VIDEO_FreezeVideo();
  242.                     break;
  243.  
  244.                 case IDM_UNFREEZE_VIDEO:
  245.                     VIDEO_UnfreezeVideo();
  246.                     //InvalidateRect(hWnd, NULL, TRUE);
  247.                     break;
  248.  
  249.                 case IDM_SAVETO_TBMP:
  250.                     VIDEO_SaveImageFile("t.bmp", 0, 0, 100, 100, VIDEO_BMP24);
  251.                     break;
  252.         
  253.                 default:
  254.                     return (DefWindowProc(hWnd, message, wParam, lParam));
  255.             }
  256.             break;
  257.         
  258.         case WM_DESTROY:
  259.             VIDEO_DisableVideo();
  260.             VIDEO_End();
  261.             PostQuitMessage(0);
  262.             break;
  263.  
  264.         default:                               
  265.             return (DefWindowProc(hWnd, message, wParam, lParam));
  266.     }
  267.     return (NULL);
  268. }
  269.  
  270.  
  271. static BYTE      ImageBuffer16[50*50*2];
  272. static BYTE      ImageBuffer24[50*50*3];
  273. void NEAR PASCAL _LoadSample(WORD wBitsPerPixel)
  274. {
  275.     VIDEO_FreezeVideo();
  276.  
  277.     switch(wBitsPerPixel) {
  278.         case _8_Bits_Gray:
  279.             VIDEO_LoadImageRect((BYTE _huge *)ImageBuffer16,
  280.                    10, 10, 50, 50,
  281.            VIDEO_BMP_8_GRAY, 0);
  282.             break;
  283.  
  284.         case _15_Bits:
  285.             VIDEO_LoadImageRect((BYTE _huge *)ImageBuffer16,
  286.                    10, 10, 50, 50,
  287.            VIDEO_BMP_15, 0);
  288.             break;
  289.                                           
  290.         case _16_Bits:
  291.             VIDEO_LoadImageRect((BYTE _huge *)ImageBuffer16,
  292.                    10, 10, 50, 50,
  293.            VIDEO_BMP_16, 0);
  294.             break;
  295.  
  296.         case _24_Bits:
  297.             VIDEO_LoadImageRect((BYTE _huge *)ImageBuffer24,
  298.                    10, 10, 50, 50,
  299.            VIDEO_BMP_24, 0);
  300.             break;
  301.     }
  302.     VIDEO_UnfreezeVideo();
  303. }
  304.  
  305.  
  306. void NEAR PASCAL _SaveSample(WORD wBitsPerPixel)
  307. {
  308.     int   idx, *pDat;
  309.  
  310.     VIDEO_FreezeVideo();
  311.  
  312.     switch(wBitsPerPixel) {
  313.         case _8_Bits_Gray:
  314.             for(idx=0; idx<50*50*2; idx++)
  315.                 ImageBuffer16[idx] = 0xff - ImageBuffer16[idx];
  316.             VIDEO_RestoreImageRect((BYTE _huge *)ImageBuffer16,
  317.                    10, 10, 50, 50,
  318.            VIDEO_BMP_8_GRAY, 0);
  319.             break;
  320.  
  321.         case _15_Bits:                                   
  322.             pDat = (int *)ImageBuffer16;
  323.             for(idx=0; idx<50*50; idx++)               
  324.                 pDat[idx] = 0x7fff - pDat[idx];
  325.             VIDEO_RestoreImageRect((BYTE _huge *)ImageBuffer16,
  326.                    10, 10, 50, 50,
  327.                    VIDEO_BMP_15, 0);
  328.             break;
  329.  
  330.         case _16_Bits:
  331.             for(idx=0; idx<50*50*2; idx++)
  332.                 ImageBuffer16[idx] = 0xff - ImageBuffer16[idx];
  333.             VIDEO_RestoreImageRect((BYTE _huge *)ImageBuffer16,
  334.                    10, 10, 50, 50,
  335.            VIDEO_BMP_16, 0);
  336.             break;
  337.  
  338.         case _24_Bits:
  339.             for(idx=0; idx<50*50*3; idx++)
  340.                 ImageBuffer24[idx] = 0xff - ImageBuffer24[idx];
  341.             VIDEO_RestoreImageRect((BYTE _huge *)ImageBuffer24,
  342.                    10, 10, 50, 50,
  343.                    VIDEO_BMP_24, 0);
  344.             break;
  345.     }
  346. }
  347.  
  348. //-----------------------------------(end)-----------------------------------
  349.