home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / IMGPROC.ZIP / C5GVIDEO.ZIP / PVIDEO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-06  |  3.9 KB  |  135 lines

  1. /*  
  2. Copyright 1990 by John Wiley & Sons, Inc.
  3.           All Rights Reserved.
  4. */
  5. /****************************************/
  6. /*    Focus Window Digitizer Program    */
  7. /*        written in Turbo C 2.0        */
  8. /*                 by                   */
  9. /*          Craig A. Lindley            */
  10. /*                                      */
  11. /*   Vers: 1.0  Last Update: 09/14/89   */
  12. /****************************************/
  13.  
  14. /*
  15. This program is capable of the full utilization of the
  16. Video Digitizer hardware. It can cause the digitizer to
  17. digitize any portion of a video display. All aspects of
  18. a digitized image from acquisition to display
  19. are computed dynamically. The ImageReq structure is
  20. passed to the low level code to command the digitizer.
  21. */
  22.  
  23. #include <stdio.h>
  24. #include <conio.h>
  25. #include <dos.h>
  26. #include <process.h>
  27. #include <graphics.h>
  28. #include <alloc.h>
  29. #include "misc.h"
  30. #include "pcx.h"
  31. #include "vga.h"
  32. #include "digitizer.h"
  33.  
  34. /*
  35. The two defines offset the focus window so it
  36. is displayed in the center on the VGA screen.
  37. */
  38.  
  39. #define ColCenterOffset 110
  40. #define RowCenterOffset  50
  41.  
  42. /* Global Variables to this file */
  43.  
  44. static struct     ImageReq Req;
  45. static char huge *PictureData;
  46.  
  47. /* display the digitized image */
  48. void DisplayPictData (char huge *PictData)
  49. {
  50.    register unsigned Col, Row, Color;
  51.    unsigned ColSpan, RowSpan;
  52.    unsigned long PixelBufOffset;
  53.  
  54.    ColSpan = Req.LastPixel - Req.FirstPixel;
  55.    RowSpan = Req.LastLine  - Req.FirstLine;
  56.    for (Col=0; Col < ColSpan; Col++)
  57.    {
  58.       PixelBufOffset = (long) RowSpan * Col;
  59.       for (Row=0; Row < RowSpan; Row++)
  60.       {
  61.      Color = PictData[PixelBufOffset + Row];
  62.          Color >>= 2;
  63.      PutPixel256(Col+ColCenterOffset,
  64.              Row+RowCenterOffset,Color);
  65.       }
  66.    }
  67. }
  68.  
  69. /* main digitizer program */
  70.  
  71. void main(void)
  72. {
  73.    unsigned long RasterSize;
  74.  
  75.    InitGraphics();           /* initialize graphics subsystem */
  76.  
  77.    printf("Focus Window Test Program\n\n");
  78.    printf("This program will continually digitize and display\n");
  79.    printf("a small portion of the video field\n\n");
  80.  
  81.    /*
  82.    Build a structure that defines what the digitizer should acquire. this
  83.    will be passed to the digitizer by a call to InitializeDigitizer
  84.    function
  85.    */
  86.  
  87.    Req.ComputerType   = PS220;
  88.    Req.PrtBase        = 0x3BC;
  89.    Req.HMode          = LowRes;   /* 320x200 resolution mode */
  90.    Req.VMode          = NonInterlace;
  91.    Req.NumberOfPasses = 1;
  92.    Req.Flags          = 0L;
  93.    Req.FirstLine      = 50;      /* set up focus window */
  94.    Req.FirstPixel     = 110;
  95.    Req.LastLine       = 150;
  96.    Req.LastPixel      = 210;
  97.  
  98.    RasterSize = (Req.LastLine  - Req.FirstLine) *
  99.                 (Req.LastPixel - Req.FirstPixel);
  100.  
  101.    /* allocate picture buffer and set it to zeros */
  102.    printf("Allocating Image Buffer - RasterSize is %lu bytes\n\n",RasterSize);
  103.  
  104.    if ((PictureData = (char huge *) farcalloc(RasterSize,
  105.         (unsigned long) sizeof(char))) == NULL)
  106.    {
  107.       printf("Digitize - Not enough memory\n");
  108.       exit(ENoMemory);
  109.    }
  110.  
  111.    printf("Hit any key to terminate program\n\n");
  112.    printf("Acquiring Image . . .\n");
  113.  
  114.    Req.PictBuf = PictureData;
  115.  
  116.    InitializeDigitizer(&Req);
  117.  
  118.    delay(5000);              /* allow messages to be read */
  119.  
  120.    Set256ColorMode();        /* 320x200 256 color VGA mode 13H */
  121.  
  122.    LoadGray16Palette();      /* load the gray scale palette */
  123.  
  124.    while (!kbhit())          /* acquire a picture continually */
  125.    {                         /* until operator hits key */
  126.       GetPicture();
  127.       DisplayPictData(PictureData);
  128.    }
  129.    getch();                  /* empty key buffer */
  130.    restorecrtmode();         /* back to text mode */
  131.    farfree((char far *)PictureData); /* give back the memory */
  132.    closegraph();             /* close up shop */
  133. }
  134.  
  135.