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

  1. /*  
  2. Copyright 1990 by John Wiley & Sons, Inc.
  3.           All Rights Reserved.
  4. */
  5. /****************************************/
  6. /*All Resolution Video Digitizer Program*/
  7. /* Digitizes, Displays and Saves Images */
  8. /*   in all supported digitizer modes   */
  9. /*       written in Turbo C 2.0         */
  10. /*                 by                   */
  11. /*          Craig A. Lindley            */
  12. /*                                      */
  13. /*   Vers: 1.0  Last Update: 09/28/89   */
  14. /****************************************/
  15.  
  16. #include <stdio.h>
  17. #include <conio.h>
  18. #include <dos.h>
  19. #include <process.h>
  20. #include <string.h>
  21. #include <graphics.h>
  22. #include <alloc.h>
  23. #include "misc.h"
  24. #include "pcx.h"
  25. #include "vga.h"
  26. #include "digitizer.h"
  27.  
  28.  
  29. #define MaxFileNameLen 13    /* filename str length including null */
  30.  
  31. /*
  32. The two defines offset the focus window so it
  33. is displayed in the center on the VGA screen.
  34. */
  35.  
  36. #define ColCenterOffsetAmount 110
  37. #define RowCenterOffsetAmount  50
  38.  
  39. /* Global Variables */
  40.  
  41. struct     ImageReq Req;
  42. char huge *PictureData;
  43. unsigned   ColCenterOffset, RowCenterOffset;
  44.  
  45.  
  46. /* display the digitized image in VGA mode 13h with 64 levels of gray */
  47. void DisplayPictData1 (char huge *PictData)
  48. {
  49.    register unsigned Col, Row, Color;
  50.    unsigned ColSpan, RowSpan;
  51.    unsigned long PixelBufOffset;
  52.  
  53.    ColSpan = Req.LastPixel - Req.FirstPixel;
  54.    RowSpan = Req.LastLine  - Req.FirstLine;
  55.    for (Col=0; Col < ColSpan; Col++)
  56.    {
  57.       PixelBufOffset = (long) RowSpan * Col;
  58.       for (Row=0; Row < RowSpan; Row++)
  59.       {
  60.      Color = PictData[PixelBufOffset + Row];
  61.      PutPixel256(Col+ColCenterOffset,
  62.              Row+RowCenterOffset,Color);
  63.       }
  64.    }
  65. }
  66.  
  67. /* display the digitized image in normal 16 color VGA modes */
  68. void DisplayPictData2 (char huge *PictData)
  69. {
  70.    register unsigned Col, Row, Color;
  71.    unsigned ColSpan, RowSpan;
  72.    unsigned long PixelBufOffset;
  73.  
  74.    ColSpan = Req.LastPixel - Req.FirstPixel;
  75.    RowSpan = Req.LastLine  - Req.FirstLine;
  76.    for (Col=0; Col < ColSpan; Col++)
  77.    {
  78.       PixelBufOffset = (long) RowSpan * Col;
  79.       for (Row=0; Row < RowSpan; Row++)
  80.       {
  81.      Color = PictData[PixelBufOffset + Row];
  82.          Color >>= 2;        /* scale data to 0 ..15 */
  83.      putpixel(Col,Row,Color);
  84.       }
  85.    }
  86. }
  87.  
  88. /*
  89. This function provides help in the advent of operator error. Program
  90. terminates after help is given
  91. */
  92.  
  93. void ShowHelp( void )
  94. {
  95.    printf("\nThis program digitizes, displays and optionally\n");
  96.    printf("saves in PCX format a single digitized image in\n");
  97.    printf("three different resolutions. Its usage is as follows:\n\n");
  98.    printf("allvideo [-o] filename <cr>\n");
  99.    printf("  -o creates output PCX files\n");
  100.    printf("  filename is name given to the PCX file(s). Do not\n");
  101.    printf("  specify a file extension, it will be provided.\n\n");
  102.    exit(1);
  103. }
  104.  
  105. /* main digitizer program */
  106.  
  107. void main(short argc, char *argv[])
  108. {
  109.    unsigned long RasterSize;
  110.    unsigned GenPCXFile;
  111.    unsigned FileNameCounter, ArgIndex, StrLength;
  112.    char    *ImageFileName;
  113.    char     ProcessedFileName[MaxFileNameLen];
  114.    char     LRName[MaxFileNameLen];
  115.    char     MRName[MaxFileNameLen];
  116.    char     HRName[MaxFileNameLen];
  117.  
  118.  
  119.    InitGraphics();
  120.  
  121.    clrscr();
  122.    printf("Digitize and Display Gray Scale Images in Many Resolutions\n\n");
  123.  
  124.    /* install default options */
  125.    GenPCXFile = FALSE;                 /* don't generate a. PCX file */
  126.  
  127.    /* parse command line arguments */
  128.  
  129.    FileNameCounter = 0;                /* count of user specified filenames */
  130.    for (ArgIndex=1; ArgIndex < argc; ArgIndex++)
  131.    {
  132.       if (*argv[ArgIndex] != '-')      /* if not a cmd line switch */
  133.       {                                /* must be a filename */
  134.      if (*argv[ArgIndex] == '?')   /* help requested ? */
  135.         ShowHelp();
  136.      if (FileNameCounter > 1)      /* only one filename allowed */
  137.             ShowHelp();                /* if more then error exit */
  138.      ImageFileName = argv[ArgIndex];  /* save image filename */
  139.          FileNameCounter++;            /* inc count for error check */
  140.       }
  141.       else                             /* its a cmd line switch */
  142.       {
  143.      switch (*(argv[ArgIndex]+1))  /* parse the cmd line */
  144.          {
  145.         case 'o':                  /* o or O = output files */
  146.         case 'O':
  147.           GenPCXFile = TRUE;
  148.               break;
  149.         default:
  150.           printf("Error - invalid cmd line switch encountered\n");
  151.           ShowHelp();
  152.          }
  153.       }
  154.    }
  155.    if (GenPCXFile && (FileNameCounter != 1))
  156.    {
  157.       printf("Error - single filename required for PCX files\n");
  158.       ShowHelp();
  159.    }
  160.  
  161.    /*
  162.    Preprocess any filename input from the cmd line. Strip
  163.    off any specified extension and limit the filename
  164.    length to six characters max. This will allow the
  165.    designations LR.PCX, MR.PCX and HR.PCX to be appended.
  166.    */
  167.  
  168.    if (GenPCXFile)           /* only process if necessary */
  169.    {
  170.  
  171.       strcpy(ProcessedFileName,"");    /* empty string */
  172.  
  173.       /* find filename length minus the extension */
  174.       StrLength = strcspn(ImageFileName,".");
  175.  
  176.       if (StrLength > 6)     /* exceeds max length ? */
  177.      strncat(ProcessedFileName,ImageFileName,6); /* cat only 6 chars */
  178.       else
  179.      strncat(ProcessedFileName,ImageFileName,StrLength);
  180.       /*
  181.       Copy the processed file name to each of the PCX
  182.       filename storage areas and append the appropriate string.
  183.       */
  184.       strcpy(LRName,ProcessedFileName);
  185.       strcat(LRName,"LR.PCX");
  186.       strupr(LRName);
  187.  
  188.       strcpy(MRName,ProcessedFileName);
  189.       strcat(MRName,"MR.PCX");
  190.       strupr(MRName);
  191.  
  192.       strcpy(HRName,ProcessedFileName);
  193.       strcat(HRName,"HR.PCX");
  194.       strupr(HRName);
  195.    }
  196.  
  197.    printf("Use focus window to focus camera. Then press\n");
  198.    printf("any key to start the digitization process.\n");
  199.    printf("Image resolutions are: 320x200, 640x200 and 640x480\n\n");
  200.  
  201.    if (GenPCXFile)
  202.    {
  203.       printf("Image filenames will be:\n\n");
  204.       printf("  %s for the low  resolution 320x200 image\n",LRName);
  205.       printf("  %s for the mid  resolution 640x200 image\n",MRName);
  206.       printf("  %s for the high resolution 640x480 image\n",HRName);
  207.    }
  208.    else
  209.       printf("PCX files will not be generated\n");
  210.  
  211.    printf("\nPress any key after third image to terminate program.\n\n");
  212.    delay(4000);
  213.  
  214.    /* pick largest size image buffer required */
  215.  
  216.    RasterSize = 307200L;     /* big enough for 640x480 image */
  217.  
  218.    /* allocate picture buffer and set it to zeros */
  219.  
  220.    if ((PictureData = (char huge *) farcalloc(RasterSize,
  221.         (unsigned long) sizeof(char))) == NULL)
  222.    {
  223.       printf("Digitize - Not enough memory\n");
  224.       exit(ENoMemory);
  225.    }
  226.  
  227.    /*
  228.    Build a structure that defines what the digitizer should acquire. this
  229.    will be passed to the digitizer by a call to InitializeDigitizer
  230.    function. The following portion of the ImageReq structure does
  231.    not change as the image resolution changes.
  232.    */
  233.  
  234.    Req.ComputerType   = PS220;
  235.    Req.PrtBase        = 0x3BC;
  236.    Req.NumberOfPasses = 1;
  237.    Req.Flags          = 0L;
  238.    Req.PictBuf        = PictureData;     /* put buffer addr into ImageReq */
  239.  
  240.    /*
  241.    This portion of the structure changes with image resolution
  242.    */
  243.  
  244.    Req.HMode          = LowRes;
  245.    Req.VMode          = NonInterlace;
  246.    Req.FirstLine      = 50;  /* focus window dimensions */
  247.    Req.FirstPixel     = 110;
  248.    Req.LastLine       = 150;
  249.    Req.LastPixel      = 210;
  250.  
  251.    InitializeDigitizer(&Req);/* initialize digitizer */
  252.  
  253.    Set256ColorMode();        /* 320x200 256 color VGA mode */
  254.    LoadGray64Palette();      /* load the gray scale palette */
  255.  
  256.    /* offset focus window to the center of the screen */
  257.    ColCenterOffset = ColCenterOffsetAmount;
  258.    RowCenterOffset = RowCenterOffsetAmount;
  259.  
  260.    while (!kbhit())          /* acquire a picture continually */
  261.    {                         /* until operator hits key */
  262.       GetPicture();
  263.       DisplayPictData1(PictureData);
  264.    }
  265.    getch();                  /* empty key buffer */
  266.  
  267.    /* now digitize a full 320x200 image */
  268.  
  269.    Req.HMode          = LowRes;
  270.    Req.VMode          = NonInterlace;
  271.    Req.FirstLine      = 0;
  272.    Req.FirstPixel     = 0;
  273.    Req.LastLine       = 200;      /* do a 320x200 image */
  274.    Req.LastPixel      = 320;
  275.  
  276.    InitializeDigitizer(&Req);     /* initialize digitizer */
  277.  
  278.    GetPicture();                  /* acquire the picture */
  279.  
  280.    /* remove display offset as required for full image display */
  281.    ColCenterOffset = 0;
  282.    RowCenterOffset = 0;
  283.  
  284.    DisplayPictData1(PictureData); /* display the picture */
  285.  
  286.    if (GenPCXFile)                /* write out the PCX file */
  287.       WritePCXFile(LRName,8,320,200,1,320);
  288.  
  289.    /* now digitize a full 640x200 image */
  290.  
  291.    Req.HMode          = HighRes;
  292.    Req.VMode          = NonInterlace;
  293.    Req.LastLine       = 200;      /* do a 640x200 image */
  294.    Req.LastPixel      = 640;
  295.  
  296.    InitializeDigitizer(&Req);     /* initialize digitizer */
  297.  
  298.    GetPicture();                  /* acquire the picture */
  299.    setgraphmode(VGALO);
  300.    LoadGray16Palette();           /* load the gray scale palette */
  301.    DisplayPictData2(PictureData); /* display the picture */
  302.  
  303.    if (GenPCXFile)                /* write out the PCX file */
  304.       WritePCXFile(MRName,1,640,200,4,80);
  305.  
  306.    /* now digitize a full 640x480 image */
  307.  
  308.    Req.HMode          = HighRes;
  309.    Req.VMode          = Interlace;
  310.    Req.LastLine       = 480;      /* do a 640x480 image */
  311.    Req.LastPixel      = 640;
  312.  
  313.    InitializeDigitizer(&Req);     /* initialize digitizer */
  314.  
  315.    GetPicture();                  /* acquire the picture */
  316.    setgraphmode(VGAHI);
  317.    LoadGray16Palette();           /* load the gray scale palette */
  318.    DisplayPictData2(PictureData); /* display the picture */
  319.  
  320.    if (GenPCXFile)                /* write out the PCX file */
  321.       WritePCXFile(HRName,1,640,480,4,80);
  322.  
  323.    getch();                       /* wait for operator */
  324.    restorecrtmode();              /* clean up and quit */
  325.    farfree((char far *)PictureData);
  326.    closegraph();
  327. }
  328.  
  329.