home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 10 / mycd10.iso / share / os2 / graficos / qcamdd01 / qcamtest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-30  |  27.0 KB  |  759 lines

  1. /*
  2.  *  QCAMTEST.C - Sample source code demonstrating the use of the
  3.  *               QuickCam OS/2 Parallel Port Device Driver.
  4.  */
  5. #define         INCL_WIN
  6. #define         INCL_DOS
  7. #define         INCL_GPI
  8. #include        <os2.h>
  9. #include        <stdio.h>
  10. #include        <stdarg.h>
  11. #include        <string.h>
  12. #include        "qcamdd.h"
  13.  
  14. /*
  15.  *  User defined messages.
  16.  */
  17. #define         WM_USER_POSITION        WM_USER+1
  18. #define         WM_USER_SIZE            WM_USER+2
  19. #define         WM_USER_UPDATE          WM_USER+3
  20.  
  21. /*
  22.  *  Function prototypes.
  23.  */
  24. static MRESULT EXPENTRY QtestWndProc(HWND,ULONG,MPARAM,MPARAM);
  25. static void GetImage(HWND hWnd);
  26. static void UpdateImage(HWND hWnd);
  27. static LONG FormatMsgBox(HWND hwnd_PO, PSZ Format_String, ...);
  28. static USHORT InitCamera(void);
  29. static HBITMAP GetFrame(HPS hps,HAB hab);
  30. static USHORT UpdateFrame(void);
  31. static void TermCamera(void);
  32. static USHORT SetCameraBrightness(UCHAR brightness);
  33. static USHORT SetCameraContrast(UCHAR contrast);
  34. static USHORT SetCameraBalance(UCHAR balance);
  35. static USHORT SetCameraTransferMode(UCHAR mode);
  36. static USHORT SetCameraPixelDepth(UCHAR depth);
  37.  
  38. /*
  39.  *  Global variables.
  40.  */
  41. HAB             habMain;                        // Anchor block
  42. HWND            hWndScreen;                     // Image display window
  43. HWND            hWndClient;                     // Queue handler
  44. HPS             hpsFrame=NULLHANDLE;            // Image presentation space
  45.  
  46. HMTX            hmtxPS=NULLHANDLE;              // Control access to camera
  47. RECTL           rctlClient;                     // Used to size windows
  48. USHORT          SkipFrame=FALSE;                // Pace the image updates
  49. ULONG           FrameWidth=QCAM_MAX_WIDTH;      // Default size of the image
  50. ULONG           FrameHeight=QCAM_MAX_HEIGHT;
  51. UCHAR           Brightness=QCAM_DEF_BRIGHT;     // Current brightness setting
  52.  
  53. HFILE           CamHandle;                      // OS "handle" to quickcam
  54. ULONG           OpenAction;                     // Action taken on open
  55. ULONG           BytesRead=0L;                   // Image size returned by Read
  56. ULONG           BufLength=0L;                   // Size of buffer obtained
  57. ULONG           BufRetLen=0L;                   // Size of length variable
  58. UCHAR           *BufAddress=NULL;               // Address of buffer obtained
  59. ULONG           ParmLength=0L;                  // Size of parameter passed
  60. ULONG           ParmRetLen=0L;                  // Size of parameter variable
  61. APIRET          RC;                             // Return code
  62.  
  63. /*
  64.  *  For updating the camera settings.
  65.  */
  66. QCAM_SETTINGS   QcamSetup;                      // Camera setup structure
  67. USHORT          QcamRequest;                    // Request what setups to do
  68.  
  69. /*
  70.  *  For creating a bitmap.
  71.  */
  72. HDC                     hdcMemory;              // Build a memory "device
  73. HPS                     hpsMemory;              //  context" to store images
  74. BITMAPINFOHEADER2       BitmapNew;              //  from the camera
  75. struct _MYBITMAP
  76.         {
  77.         BITMAPINFOHEADER2       Header;
  78.         RGB2                    Palette[QCAM_MAX_PALETTE];
  79.         } Bitmap;
  80.  
  81.  
  82. /*
  83.  *  QuickCam test for OS/2 Parallel Port Device Driver mainline.
  84.  */
  85. int main(void)
  86.         {
  87.         HMQ     hmq;                            // Message queue
  88.         QMSG    qmsg;                           // Queue message structure
  89.         CHAR    szClientClass[]="QTEST";        // Class name
  90.         ULONG   flFrameFlags=   FCF_TITLEBAR |  // Window characteristics
  91.                                 FCF_SYSMENU |
  92.                                 FCF_BORDER |
  93.                                 FCF_SHELLPOSITION |
  94.                                 FCF_TASKLIST;
  95.  
  96.         /*
  97.          *  Initialize the camera.                      // CAMERA CODE!!!
  98.          */
  99.         if (InitCamera()==QCAM_ERROR)
  100.                 {
  101.                 return(1);
  102.                 }
  103.  
  104.         /*
  105.          *  Create a standard window.
  106.          */
  107.         habMain=WinInitialize(0);
  108.         hmq=WinCreateMsgQueue(habMain,0);
  109.         WinRegisterClass(habMain,szClientClass,(PFNWP)QtestWndProc,0,0);
  110.         hWndScreen=WinCreateStdWindow
  111.                         (HWND_DESKTOP,0,&flFrameFlags,szClientClass,
  112.                            "QuickCam Device Driver Test Program",
  113.                              0,0,1,&hWndClient);
  114.  
  115.         /*
  116.          *  Set the initial window size to the default maximums.
  117.          */
  118.         WinPostMsg(hWndClient,WM_USER_SIZE,0L,0L);
  119.  
  120.         /*
  121.          *  Process messages for window until user quits.
  122.          */
  123.         if (WinStartTimer(habMain,hWndClient,1,1000L))
  124.                 {
  125.                 while(WinGetMsg(habMain,&qmsg,0,0,0))
  126.                         {
  127.                         WinDispatchMsg(habMain,&qmsg);
  128.                         }
  129.                 WinStopTimer(habMain,hWndClient,1);
  130.                 }
  131.  
  132.         /*
  133.          *  Cleanup and exit.
  134.          */
  135.         TermCamera();                                   // CAMERA CODE!!!
  136.         WinDestroyWindow(hWndScreen);
  137.         WinDestroyMsgQueue(hmq);
  138.         WinTerminate(habMain);
  139.  
  140.         /*
  141.          *  Exit the process.
  142.          */
  143.         return(0);
  144.         }
  145.  
  146.  
  147. /*
  148.  *  Deal with messages to this window.
  149.  */
  150. MRESULT EXPENTRY QtestWndProc (HWND hWnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  151.         {
  152.         HPS     hps;                            // Handle to presentation space
  153.         BOOL    bHandled=TRUE;                  // Message handled flag
  154.         MRESULT mReturn=0;                      // Return code
  155.         SWP     winpos;                         // Position structure
  156.         POINTL  ulPoints[4];                    // Used to size window
  157.  
  158.         switch (msg)
  159.                 {
  160.                 case WM_CREATE:
  161.                         /*
  162.                          *  Get a mutually exclusive semaphore for use later.
  163.                          */
  164.                         DosCreateMutexSem((PSZ)NULL,&hmtxPS,0UL,FALSE);
  165.  
  166.                         /*
  167.                          *  Start getting the camera image in the window.
  168.                          */
  169.                         GetImage(hWnd);                 // CAMERA CODE!!!
  170.  
  171.                         /*
  172.                          *  Make the window visible.
  173.                          */
  174.                         WinShowWindow(hWnd,TRUE);
  175.                         break;
  176.  
  177.                 case WM_USER_UPDATE:
  178.                         /*
  179.                          *  Posted by the UpdateImage function. Indicates that
  180.                          *  a new image is in the memory presentation space,
  181.                          *  so ensure that we have to do a redraw.
  182.                          */
  183.                         WinQueryWindowRect(hWnd,&rctlClient);
  184.                         WinInvalidateRect(hWnd,&rctlClient,TRUE);
  185.                         break;
  186.  
  187.                 case WM_USER_SIZE:
  188.                         /*
  189.                          *  Set to client window to the current frame size.
  190.                          */
  191.                         WinQueryTaskSizePos(habMain,0,&winpos);
  192.                         WinSetWindowPos(hWndScreen,NULLHANDLE,winpos.x,
  193.                                          winpos.y,FrameWidth,FrameHeight,
  194.                                           SWP_SHOW|SWP_MOVE|SWP_SIZE);
  195.                         break;
  196.  
  197.                 case WM_CHAR:
  198.                         /*
  199.                          *  Adjust the brightness.
  200.                          */
  201.                         if ((CHARMSG(&msg)->fs & KC_KEYUP)==0)
  202.                             {
  203.                             if (CHARMSG(&msg)->fs & KC_CHAR)
  204.                                 {
  205.                                 switch (CHARMSG(&msg)->chr)
  206.                                     {
  207.                                     /*
  208.                                      *  Increase brightness.
  209.                                      */
  210.                                     case '+': Brightness+=5;
  211.                                               SetCameraBrightness(Brightness);
  212.                                               break;
  213.  
  214.                                     /*
  215.                                      *  Decrease brightness.
  216.                                      */
  217.                                     case '-': Brightness-=5;
  218.                                               SetCameraBrightness(Brightness);
  219.                                               break;
  220.  
  221.                                      default: break;
  222.                                     }
  223.                                 }
  224.                             }
  225.                         break;
  226.  
  227.                 case WM_TIMER:
  228.                         /*
  229.                          *  Update the picture once a second.  Paced by
  230.                          *  the PC ability to deliver frames.
  231.                          */
  232.                         if (SkipFrame==FALSE)
  233.                                 {
  234.                                 UpdateImage(hWnd);      // CAMERA CODE
  235.                                 }
  236.                         else    {
  237.                                 SkipFrame=FALSE;
  238.                                 }
  239.                         break;
  240.  
  241.                 case WM_PAINT:
  242.                         /*
  243.                          *  Redraw the image on the desktop.
  244.                          */
  245.                         WinQueryWindowRect(hWnd,&rctlClient);
  246.                         hps=WinBeginPaint(hWnd,NULLHANDLE,&rctlClient);
  247.                         if (hpsFrame!=NULLHANDLE)
  248.                                 {
  249.                                 /*
  250.                                  *  Setup the points array.
  251.                                  */
  252.                                 ulPoints[0].x=0;
  253.                                 ulPoints[0].y=0;
  254.                                 ulPoints[1].x=FrameWidth;
  255.                                 ulPoints[1].y=FrameHeight;
  256.                                 ulPoints[2].x=0;
  257.                                 ulPoints[2].y=0;
  258.                                 ulPoints[3].x=FrameWidth;
  259.                                 ulPoints[3].y=FrameHeight;
  260.  
  261.                                 /*
  262.                                  *  Blast the image to the screen.
  263.                                  */
  264.                                 if (GpiBitBlt(hps,hpsFrame,4L,ulPoints,
  265.                                              ROP_SRCCOPY,BBO_IGNORE)!=GPI_OK)
  266.                                         {
  267.                                         FormatMsgBox(HWND_DESKTOP,
  268.                                                         "Bitmap Copy Failed.");
  269.                                         }
  270.                                 }
  271.                         WinEndPaint(hps);
  272.                         break;
  273.  
  274.                 case WM_ERASEBACKGROUND:
  275.                         /*
  276.                          *  Don't do anything.
  277.                          */
  278.                         mReturn=MRFROMLONG(1L);
  279.                         break;
  280.  
  281.                 default:
  282.                         /*
  283.                          *  Let default processing take place.
  284.                          */
  285.                         bHandled=FALSE;
  286.                         break;
  287.                 }
  288.  
  289.         /*
  290.          *  If nothing was done, call the default processor.
  291.          */
  292.         if (!bHandled)
  293.                 {
  294.                 mReturn=WinDefWindowProc(hWnd,msg,mp1,mp2);
  295.                 }
  296.         return (mReturn);
  297.         }
  298.  
  299.  
  300. /*
  301.  *  Get the first image from the camera.
  302.  */
  303. void GetImage(HWND hWnd)
  304.         {
  305.         HPS     hps=WinGetPS(hWnd);
  306.  
  307.         /*
  308.          *  Get a frame buffer from the camera with the initial image.
  309.          */
  310.         if ((hpsFrame=GetFrame(hps,habMain))!=0)        // CAMERA CODE!!!
  311.                 {
  312.                 /*
  313.                  *  Post a message to the caller's queue that image has been
  314.                  *  updated.
  315.                  */
  316.                 WinPostMsg(hWnd,WM_USER_UPDATE,0L,0L);
  317.                 }
  318.  
  319.         WinReleasePS(hps);
  320.         }
  321.  
  322.  
  323. /*
  324.  *  Update with the next image from the camera.
  325.  */
  326. void UpdateImage(HWND hWnd)
  327.         {
  328.         /*
  329.          *  Obtain the semaphore to ensure that we are not doing an update
  330.          *  already.  If the semaphore is not available within 10ms do not
  331.          *  start another update.
  332.          */
  333.         if (DosRequestMutexSem(hmtxPS,10L)==0)
  334.                 {
  335.                 /*
  336.                  *  Have to sepaphore, so its OK to grab the next frame from
  337.                  *  the camera.
  338.                  */
  339.                 if (UpdateFrame()==QCAM_OK)             // CAMERA CODE!!!
  340.                         {
  341.                         /*
  342.                          *  Post a message to the caller's queue that image
  343.                          *  has been updated.
  344.                          */
  345.                         WinPostMsg(hWnd,WM_USER_UPDATE,0L,0L);
  346.                         }
  347.  
  348.                 /*
  349.                  *  OK to give up the semaphore now.
  350.                  */
  351.                 DosReleaseMutexSem(hmtxPS);
  352.                 }
  353.         else    {
  354.                 /*
  355.                  *  PC can't keep up so slow it down a bit.
  356.                  */
  357.                 SkipFrame=TRUE;
  358.                 }
  359.         }
  360.  
  361.  
  362. /*
  363.  *  This is a handy function for displaying messages.
  364.  */
  365. LONG FormatMsgBox(HWND hwnd_PO, PSZ Format_String, ...)
  366.         {
  367.         va_list         Arg_List;
  368.         PVOID           Buffer_Pointer;
  369.         PSZ             String_Buffer;
  370.         LONG            Item_Count;
  371.         LONG            Return_Code;
  372.  
  373.         Return_Code=DosAllocMem(&Buffer_Pointer,1024,fALLOC);
  374.  
  375.         if (Return_Code != 0)
  376.                 {
  377.                 return 0L;
  378.                 }
  379.  
  380.         String_Buffer=(PSZ) Buffer_Pointer;
  381.         va_start(Arg_List,Format_String);
  382.         Item_Count=vsprintf(String_Buffer,Format_String,Arg_List);
  383.  
  384.         WinMessageBox(HWND_DESKTOP,hwnd_PO,String_Buffer,
  385.                         "                                               ",
  386.                           1001, ( MB_OK | MB_NOICON | MB_MOVEABLE ));
  387.  
  388.         if (!Return_Code)
  389.                 {
  390.                 DosFreeMem(Buffer_Pointer);
  391.                 }
  392.         return Item_Count;
  393.         }
  394.  
  395.  
  396. /*=============================================================================
  397.  *
  398.  *  Camera specific functions follow.
  399.  *
  400.  *===========================================================================*/
  401.  
  402. /*
  403.  *  If the device driver can be "opened" initialize tha camera to its 
  404.  *  default settings.
  405.  */
  406. USHORT InitCamera(void)
  407.         {
  408.         /*
  409.          *  Attempt to "open" the QuickCam device driver.
  410.          */
  411.         RC=DosOpen(QCAM_OPEN_NAME,              // Device driver name
  412.                    &CamHandle,                  // Pointer to handle
  413.                    &OpenAction,                 // Pointer to open action
  414.                    QCAM_OPEN_SIZE,              // Not required
  415.                    QCAM_OPEN_ATTRIBUTE,         // Not Required
  416.                    QCAM_OPEN_FLAG,              // Open device
  417.                    QCAM_OPEN_MODE,              // Fail on error
  418.                    QCAM_OPEN_EABUF);            // No extended attributes
  419.         
  420.         if (RC!=0)
  421.                 {
  422.                 /*
  423.                  *  Open failed.
  424.                  */
  425.                 return QCAM_ERROR;
  426.                 }
  427.  
  428.         /*
  429.          *  Send the initialize command.  This will return the camera settings
  430.          *  in the QcamSetup structure.
  431.          */
  432.         QcamRequest=QCAM_INITIALIZE;
  433.         RC=DosDevIOCtl(CamHandle,
  434.                        QCAM_IOCTL_CATEGORY,     // Category used for Qcam
  435.                        QCAM_IOCTL_SET_CAMERA,   // Set camera function
  436.                        &QcamRequest,            // Operations to do
  437.                        sizeof(USHORT),          // Size of the request var.
  438.                        &ParmRetLen,             // Not used
  439.                        &QcamSetup,              // Settings struct. address
  440.                        sizeof(QCAM_SETTINGS),   // Size of settings struct.
  441.                        &BufRetLen);             // Not used
  442.  
  443.         if (RC!=0)
  444.                 {
  445.                 FormatMsgBox(HWND_DESKTOP,"Initialize Camera Failed [%4x].",RC);
  446.                 return QCAM_ERROR;
  447.                 }
  448.  
  449.         /*
  450.          *  Make sure camera is in EVERY_PIXEL transfer mode.
  451.          */
  452.         if (QcamSetup.transfer_mode!=QCAM_EVERY_PIXEL)
  453.                 {
  454.                 if (SetCameraTransferMode(QCAM_EVERY_PIXEL)==QCAM_ERROR)
  455.                         {
  456.                         return QCAM_ERROR;
  457.                         }
  458.                 }
  459.  
  460.         /*
  461.          *  Make sure the camera is in 6-bits per pixel mode.
  462.          */
  463.         if (QcamSetup.depth!=QCAM_DEPTH_64GRAYS)
  464.                 {
  465.                 if (SetCameraPixelDepth(QCAM_DEPTH_64GRAYS)==QCAM_ERROR)
  466.                         {
  467.                         return QCAM_ERROR;
  468.                         }
  469.                 }
  470.  
  471.         /*
  472.          *  Set the brightness to the default value.
  473.          */
  474.         if (SetCameraBrightness(Brightness)==QCAM_ERROR)
  475.                 {
  476.                 return QCAM_ERROR;
  477.                 }
  478.  
  479.         /*
  480.          *  Set the contrast to the default value.
  481.          */
  482.         if (SetCameraContrast(QCAM_DEF_CONTRAST)==QCAM_ERROR)
  483.                 {
  484.                 return QCAM_ERROR;
  485.                 }
  486.  
  487.         /*
  488.          *  Initialize went OK.
  489.          */
  490.         return QCAM_OK;
  491.         }
  492.  
  493.  
  494. /*
  495.  *  Allocate a maximally size frame buffer and fill it with an image
  496.  *  from the camera.
  497.  */
  498. HBITMAP GetFrame(HPS hps,HAB hab)
  499.         {
  500.         SIZEL           size;
  501.         HBITMAP         hbm;
  502.         UCHAR           i;
  503.  
  504.         /*
  505.          *  Allocate a buffer for the frame data.
  506.          */
  507.         RC=DosDevIOCtl(CamHandle,
  508.                        QCAM_IOCTL_CATEGORY,
  509.                        QCAM_IOCTL_ALLOC_BUF,
  510.                        &BufLength,
  511.                        sizeof(ULONG),
  512.                        &ParmRetLen,
  513.                        &BufAddress,
  514.                        sizeof(UCHAR *),
  515.                        &BufRetLen);
  516.         if (RC!=0)
  517.                 {
  518.                 /*
  519.                  *  Allocate failed.
  520.                  */
  521.                 return NULL;
  522.                 }
  523.  
  524.         /*
  525.          *  Fill the buffer allocated with an image from the camera.
  526.          */
  527.         RC=DosDevIOCtl(CamHandle,
  528.                        QCAM_IOCTL_CATEGORY,     // Category used for Qcam
  529.                        QCAM_IOCTL_GET_FRAME,    // Get frame function
  530.                        &BufLength,              // Return frame size here
  531.                        sizeof(ULONG),           // Size of FrameLength variable
  532.                        &ParmRetLen,             // Not used
  533.                        &BufAddress,             // Buffer pointer address
  534.                        sizeof(UCHAR *),         // Size of BufAddress pointer
  535.                        &BufRetLen);             // Not used
  536.         if (RC!=0)
  537.                 {
  538.                 /*
  539.                  *  Read failed.
  540.                  */
  541.                 return NULL;
  542.                 }
  543.  
  544.         /*
  545.          *  Open a memory Device Context and create a Presentation Space
  546.          *  associated with it.
  547.          */
  548.         size.cx=0;
  549.         size.cy=0;
  550.         hdcMemory=DevOpenDC(hab,OD_MEMORY,"*",0L,NULL,0L);
  551.         hpsMemory=GpiCreatePS(hab,hdcMemory,&size,
  552.                                 PU_PELS|GPIF_DEFAULT|GPIT_MICRO|GPIA_ASSOC);
  553.  
  554.         /*
  555.          *  Create a bitmap in the memory presentation space.
  556.          */
  557.         memset(&BitmapNew,0,sizeof(BITMAPINFOHEADER2));
  558.         BitmapNew.cbFix=sizeof(BITMAPINFOHEADER2);
  559.         BitmapNew.cx=320;
  560.         BitmapNew.cy=240;
  561.         BitmapNew.cPlanes=1;
  562.         BitmapNew.cBitCount=8;
  563.         hbm=GpiCreateBitmap(hps,&BitmapNew,0L,NULL,NULL);
  564.  
  565.         /*
  566.          *  Select bitmap into the memory presentation space.
  567.          */
  568.         GpiSetBitmap(hpsMemory,hbm);
  569.  
  570.         /*
  571.          *  Set bitmap bits from the camera.
  572.          */
  573.         memset(&Bitmap.Header,0,sizeof(BITMAPINFOHEADER2));
  574.         Bitmap.Header.cbFix=sizeof(BITMAPINFOHEADER2);
  575.         Bitmap.Header.cx=320;
  576.         Bitmap.Header.cy=240;
  577.         Bitmap.Header.cPlanes=1;
  578.         Bitmap.Header.cBitCount=8;
  579.         Bitmap.Header.cclrUsed=64;
  580.         for (i=0; i<QCAM_MAX_PALETTE; i++)
  581.                 {
  582.                 /*
  583.                  *  Create an evenly distributed 64-grays palette.
  584.                  */
  585.                 Bitmap.Palette[QCAM_MAX_PALETTE-1-i].fcOptions=0;
  586.                 Bitmap.Palette[QCAM_MAX_PALETTE-1-i].bRed=i<<2;
  587.                 Bitmap.Palette[QCAM_MAX_PALETTE-1-i].bGreen=i<<2;
  588.                 Bitmap.Palette[QCAM_MAX_PALETTE-1-i].bBlue=i<<2;
  589.                 }
  590.         GpiSetBitmapBits(hpsMemory,0L,240L,BufAddress,(PBITMAPINFO2)&Bitmap);
  591.  
  592.         /*
  593.          *  Return the handle to the memory presentation space created.
  594.          */
  595.         return hpsMemory;
  596.         }
  597.  
  598.  
  599. /*
  600.  *  Update the image in the frame buffer.
  601.  */
  602. USHORT UpdateFrame(void)
  603.         {
  604.         /*
  605.          *  Fill the buffer allocated with the next image from the camera.
  606.          */
  607.         RC=DosDevIOCtl(CamHandle,
  608.                        QCAM_IOCTL_CATEGORY,     // Category used for Qcam
  609.                        QCAM_IOCTL_GET_FRAME,    // Get frame function
  610.                        &BufLength,              // Return frame size here
  611.                        sizeof(ULONG),           // Size of FrameLength variable
  612.                        &ParmRetLen,             // Not used
  613.                        &BufAddress,             // Buffer pointer address
  614.                        sizeof(UCHAR *),         // Size of BufAddress pointer
  615.                        &BufRetLen);             // Not used
  616.         if (RC==0)
  617.                 {
  618.                 /*
  619.                  *  Update the bitmap with the next image.
  620.                  */
  621.                 GpiSetBitmapBits(hpsMemory,0L,FrameHeight,
  622.                                            BufAddress,(PBITMAPINFO2)&Bitmap);
  623.                 return QCAM_OK;
  624.                 }
  625.  
  626.         return QCAM_ERROR;
  627.         }
  628.  
  629.  
  630. /*
  631.  *  Free the frame and close the device.
  632.  */
  633. void TermCamera(void)
  634.         {
  635.         DosDevIOCtl(CamHandle,
  636.                     QCAM_IOCTL_CATEGORY,     // Category used for Qcam
  637.                     QCAM_IOCTL_FREE_BUF,     // Free buffer function
  638.                     &BufLength,              // Return frame size here
  639.                     sizeof(ULONG),           // Size of FrameLength variable
  640.                     &ParmRetLen,             // Not used
  641.                     &BufAddress,             // Buffer address
  642.                     sizeof(UCHAR *),         // Size of BufAddress pointer
  643.                     &BufRetLen);             // Not used
  644.  
  645.         DosClose(CamHandle);
  646.         }
  647.  
  648.  
  649. /*
  650.  *  Adjust the camera brightness.
  651.  */
  652. USHORT SetCameraBrightness(UCHAR brightness)
  653.         {
  654.         QcamRequest=QCAM_SET_EXPOSURE;
  655.         QcamSetup.exposure=brightness;
  656.         RC=DosDevIOCtl(CamHandle,
  657.                        QCAM_IOCTL_CATEGORY,     // Category used for Qcam
  658.                        QCAM_IOCTL_SET_CAMERA,   // Set camera function
  659.                        &QcamRequest,            // Operations to do
  660.                        sizeof(USHORT),          // Size of the request variable
  661.                        &ParmRetLen,             // Not used
  662.                        &QcamSetup,              // Settings structure address
  663.                        sizeof(QCAM_SETTINGS),   // Size of settings structure
  664.                        &BufRetLen);             // Not used
  665.         if (RC!=0)
  666.                 {
  667.                 FormatMsgBox(HWND_DESKTOP,"Set Brightness Failed [%4x].",RC);
  668.                 return QCAM_ERROR;
  669.                 }
  670.         /*
  671.          *  Set brightness went OK.
  672.          */
  673.         return QCAM_OK;
  674.         }
  675.  
  676.  
  677. /*
  678.  *  Adjust the camera contrast.
  679.  */
  680. USHORT SetCameraContrast(UCHAR contrast)
  681.         {
  682.         QcamRequest=QCAM_SET_CONTRAST;
  683.         QcamSetup.contrast=contrast;
  684.         RC=DosDevIOCtl(CamHandle,
  685.                        QCAM_IOCTL_CATEGORY,     // Category used for Qcam
  686.                        QCAM_IOCTL_SET_CAMERA,   // Set camera function
  687.                        &QcamRequest,            // Operations to do
  688.                        sizeof(USHORT),          // Size of the request variable
  689.                        &ParmRetLen,             // Not used
  690.                        &QcamSetup,              // Settings structure address
  691.                        sizeof(QCAM_SETTINGS),   // Size of settings structure
  692.                        &BufRetLen);             // Not used
  693.         if (RC!=0)
  694.                 {
  695.                 FormatMsgBox(HWND_DESKTOP,"Set Contrast Failed [%4x].",RC);
  696.                 return QCAM_ERROR;
  697.                 }
  698.         /*
  699.          *  Set contrast went OK.
  700.          */
  701.         return QCAM_OK;
  702.         }
  703.  
  704.  
  705. /*
  706.  *  Set the camera transfer mode.
  707.  */
  708. USHORT SetCameraTransferMode(UCHAR mode)
  709.         {
  710.         QcamRequest=QCAM_SET_TRANS_MODE;
  711.         QcamSetup.transfer_mode=mode;
  712.         RC=DosDevIOCtl(CamHandle,
  713.                        QCAM_IOCTL_CATEGORY,     // Category used for Qcam
  714.                        QCAM_IOCTL_SET_CAMERA,   // Set camera function
  715.                        &QcamRequest,            // Operations to do
  716.                        sizeof(USHORT),          // Size of the request variable
  717.                        &ParmRetLen,             // Not used
  718.                        &QcamSetup,              // Settings structure address
  719.                        sizeof(QCAM_SETTINGS),   // Size of settings structure
  720.                        &BufRetLen);             // Not used
  721.         if (RC!=0)
  722.                 {
  723.                 FormatMsgBox(HWND_DESKTOP,"Set Transfer Mode Failed [%4x].",RC);
  724.                 return QCAM_ERROR;
  725.                 }
  726.         /*
  727.          *  Set transfer mode went OK.
  728.          */
  729.         return QCAM_OK;
  730.         }
  731.  
  732.  
  733. /*
  734.  *  Set the camera pixel depth.
  735.  */
  736. USHORT SetCameraPixelDepth(UCHAR depth)
  737.         {
  738.         QcamRequest=QCAM_SET_DEPTH;
  739.         QcamSetup.depth=depth;
  740.         RC=DosDevIOCtl(CamHandle,
  741.                        QCAM_IOCTL_CATEGORY,     // Category used for Qcam
  742.                        QCAM_IOCTL_SET_CAMERA,   // Set camera function
  743.                        &QcamRequest,            // Operations to do
  744.                        sizeof(USHORT),          // Size of the request variable
  745.                        &ParmRetLen,             // Not used
  746.                        &QcamSetup,              // Settings structure address
  747.                        sizeof(QCAM_SETTINGS),   // Size of settings structure
  748.                        &BufRetLen);             // Not used
  749.         if (RC!=0)
  750.                 {
  751.                 FormatMsgBox(HWND_DESKTOP,"Set Depth Failed [%4x].",RC);
  752.                 return QCAM_ERROR;
  753.                 }
  754.         /*
  755.          *  Set depth went OK.
  756.          */
  757.         return QCAM_OK;
  758.         }
  759.