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

  1. /*  
  2. Copyright 1990 by John Wiley & Sons, Inc.
  3.           All Rights Reserved.
  4. */
  5. /****************************************/
  6. /*   Generic Video Digitizer Program    */
  7. /*       Digitizes 320x200 Images       */
  8. /* Images displayed with both 16 and 64 */
  9. /*           levels of gray             */
  10. /*       written in Turbo C 2.0         */
  11. /*                 by                   */
  12. /*          Craig A. Lindley            */
  13. /*                                      */
  14. /*   Vers: 1.0  Last Update: 09/14/89   */
  15. /****************************************/
  16.  
  17. #include <stdio.h>
  18. #include <conio.h>
  19. #include <process.h>
  20. #include <graphics.h>
  21. #include <alloc.h>
  22. #include "misc.h"
  23. #include "pcx.h"
  24. #include "vga.h"
  25. #include "digitizer.h"
  26.  
  27. /* Global Variables */
  28.  
  29. static struct ImageReq Req;
  30. static char huge *PictureData;
  31.  
  32.  
  33. /*
  34. This function displays the digitized image with a 16
  35. level gray scale palette. Notice the video data in
  36. PictData is shifted to the right twice. This scales
  37. the 6 bit data to 4 bits as required for
  38. a 16 color display. Notice also that this function is
  39. driven by parameters in the ImageReq structure. That means
  40. DisplayPictData will automatically configure itself as
  41. the image parameters change.
  42. */
  43.  
  44. void DisplayPictData16Gray (char huge *PictData)
  45. {
  46.    register unsigned Col, Row, Color;
  47.    unsigned ColSpan, RowSpan;
  48.    unsigned long PixelBufOffset;
  49.  
  50.    ColSpan = Req.LastPixel - Req.FirstPixel;
  51.    RowSpan = Req.LastLine  - Req.FirstLine;
  52.    for (Col=0; Col < ColSpan; Col++)
  53.    {
  54.       PixelBufOffset = (long) RowSpan * Col;
  55.       for (Row=0; Row < RowSpan; Row++)
  56.       {
  57.      Color = PictData[PixelBufOffset + Row];
  58.          Color >>= 2;
  59.      /* use special VGA mode 13h putpixel function */
  60.      /* required for 320x200 images */
  61.      PutPixel256(Col,Row,Color);
  62.       }
  63.    }
  64. }
  65.  
  66. /*
  67. This function displays the digitized image with a 64
  68. level gray scale palette. Notice the video data in
  69. is not scaled in this case as all 6 bits are needed
  70. to index the correct color register.
  71. */
  72.  
  73. void DisplayPictData64Gray (char huge *PictData)
  74. {
  75.    register unsigned Col, Row, Color;
  76.    unsigned ColSpan, RowSpan;
  77.    unsigned long PixelBufOffset;
  78.  
  79.    ColSpan = Req.LastPixel - Req.FirstPixel;
  80.    RowSpan = Req.LastLine  - Req.FirstLine;
  81.    for (Col=0; Col < ColSpan; Col++)
  82.    {
  83.       PixelBufOffset = (long) RowSpan * Col;
  84.       for (Row=0; Row < RowSpan; Row++)
  85.       {
  86.      Color = PictData[PixelBufOffset + Row];
  87.      /* use special VGA mode 13h putpixel function */
  88.      /* required for 320x200 images */
  89.      PutPixel256(Col,Row,Color);
  90.       }
  91.    }
  92. }
  93.  
  94. /* main digitizer program */
  95.  
  96. void main(void)
  97. {
  98.    unsigned Count;
  99.    unsigned long RasterSize;
  100.  
  101.    InitGraphics();           /* initialize graphics subsystem */
  102.  
  103.    clrscr();
  104.    printf("Generic Digitizer Test Program\n\n");
  105.    printf("This program digitizes a 320x200 pixel image then\n");
  106.    printf("displays it first with 16 and then with 64 levels\n");
  107.    printf("of gray.\n\n");
  108.  
  109.    /*
  110.    Build a structure that defines what the digitizer should acquire. this
  111.    will be passed to the digitizer by a call to InitializeDigitizer
  112.    function
  113.    */
  114.  
  115.    Req.ComputerType   = PS220;
  116.    Req.PrtBase        = 0x3BC;
  117.    Req.HMode          = LowRes;
  118.    Req.VMode          = NonInterlace;
  119.    Req.NumberOfPasses = 1;
  120.    Req.Flags          = 0L;
  121.    Req.FirstLine      = 0;
  122.    Req.FirstPixel     = 0;
  123.    Req.LastLine       = 200;      /* set up 320x200 image */
  124.    Req.LastPixel      = 320;
  125.  
  126.    RasterSize = (Req.LastLine  - Req.FirstLine) *
  127.                 (Req.LastPixel - Req.FirstPixel);
  128.  
  129.    /* allocate picture buffer from the far heap and set it to zeros */
  130.    printf("Allocating Image Buffer - RasterSize is %lu bytes\n\n",RasterSize);
  131.  
  132.    if ((PictureData = (char huge *) farcalloc(RasterSize,
  133.         (unsigned long) sizeof(char))) == NULL)
  134.    {
  135.       printf("Digitize - Not enough memory\n");
  136.       exit(ENoMemory);
  137.    }
  138.  
  139.    /* place address of image buffer in the ImageReq structure */
  140.    Req.PictBuf = PictureData;
  141.  
  142.    /* inform digitizer of image parameters */
  143.    InitializeDigitizer(&Req);
  144.  
  145.    /* run a test of the digitizer */
  146.    printf("SyncPerField Digitizer Synchronization Test\n\n");
  147.    for (Count = 0; Count < 10; Count++)
  148.       printf("SPF=%d\n",SyncsPerField());
  149.  
  150.    printf("\nPress any key to terminate image display\n\n");
  151.    printf("Acquiring Image . . .\n");
  152.  
  153.    GetPicture();             /* acquire requested image */
  154.  
  155.    Set256ColorMode();        /* 320x200 256 color VGA mode */
  156.  
  157.    LoadGray16Palette();      /* load the gray scale palette */
  158.  
  159.    DisplayPictData16Gray(PictureData);  /* display the image */
  160.  
  161.    getch();                  /* operator terminates display */
  162.  
  163.    LoadGray64Palette();      /* load the new gray scale palette */
  164.  
  165.    DisplayPictData64Gray(PictureData);  /* display the image */
  166.  
  167.    getch();                  /* operator terminates display */
  168.  
  169.    restorecrtmode();         /* back to text mode */
  170.    farfree((char far *)PictureData);  /* give memory back */
  171.    closegraph();             /* close up shop */
  172. }
  173.  
  174.