home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 350_01 / wr_demo.c < prev    next >
C/C++ Source or Header  |  1991-12-01  |  7KB  |  212 lines

  1. /*
  2.  *************************************************************************
  3.  *
  4.  *  WR_DEMO.C - PCX_LIB PCX Image File Write Demonstration Program
  5.  *
  6.  *  Version:    1.00C
  7.  *
  8.  *  History:    91/02/14 - Created
  9.  *              91/04/01 - Release 1.00A
  10.  *              91/04/06 - Release 1.00B
  11.  *              91/11/18 - Initialized scratch counter in "main".
  12.  *              91/12/01 - Release 1.00C
  13.  *
  14.  *  Compiler:   Microsoft C V6.0
  15.  *
  16.  *  Author:     Ian Ashdown, P.Eng.
  17.  *              byHeart Software
  18.  *              620 Ballantree Road
  19.  *              West Vancouver, B.C.
  20.  *              Canada V7S 1W3
  21.  *              Tel. (604) 922-6148
  22.  *              Fax. (604) 987-7621
  23.  *
  24.  *  Copyright:  Public Domain
  25.  *
  26.  *************************************************************************
  27.  */
  28.  
  29. /*      INCLUDE FILES                                                   */
  30.  
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <conio.h>
  34. #include <graph.h>
  35. #include "pcx_ext.h"
  36.  
  37. /*      FORWARD REFERENCES                                              */
  38.  
  39. /*      GLOBALS                                                         */
  40.  
  41. static char *use_msg[] =        /* Program usage message                */
  42. {
  43.   "  Synopsis:  This public domain program displays a Paintbrush (R) PCX",
  44.   "-format\n             image file, then captures the image directly fr",
  45.   "om the display\n             and writes it to the file PCX_DEMO.PCX.",
  46.   "\n\n  Usage:     WR_DEMO filename video_mode\n\n             where \"",
  47.   "filename\" is the name of the PCX-format image file to be\n          ",
  48.   "   written and \"video_mode\" is an MS-DOS video mode.  Valid values",
  49.   "\n             are:\n\n                4   - 320 x 200 4-color CGA\n ",
  50.   "               5   - 320 x 200 4-color CGA (color burst off)\n       ",
  51.   "         6   - 640 x 200 2-color CGA\n               13   - 320 x 200",
  52.   " 16-color EGA/VGA\n               14   - 640 x 200 16-color EGA/VGA\n",
  53.   "               15   - 640 x 350 2-color EGA/VGA\n               16   ",
  54.   "- 640 x 350 16-color EGA/VGA\n               17   - 640 x 480 2-color",
  55.   " VGA\n               18   - 640 x 480 16-color VGA\n               19",
  56.   "   - 320 x 200 256-color VGA\n",
  57.   (unsigned char *) NULL
  58. };
  59.  
  60. /*      PUBLIC FUNCTIONS                                                */
  61.  
  62. /*
  63.  *************************************************************************
  64.  *
  65.  *  MAIN - Executive Function
  66.  *
  67.  *  Purpose:    To write a PCX-format image file.
  68.  *
  69.  *  Setup:      int main
  70.  *              (
  71.  *                int argc,
  72.  *                char **argv
  73.  *              )
  74.  *
  75.  *  Where:      argc is the number of command-line arguments.
  76.  *              argv is a pointer to an array of command-line argument
  77.  *                strings.
  78.  *
  79.  *  Return:     0 if successful; otherwise 2.
  80.  *
  81.  *  Note:       Usage is:
  82.  *
  83.  *                WR_DEMO filename video_mode
  84.  *
  85.  *              where:
  86.  *
  87.  *                filename is the name of a PCX-format image file.
  88.  *                video_mode is the MS-DOS video mode.  Valid values are:
  89.  *
  90.  *                    4 -        320 x 200 4-color CGA
  91.  *                    5 -        320 x 200 4-color CGA (color burst off)
  92.  *                    6 -        640 x 200 2-color CGA
  93.  *                   13 -        320 x 200 16-color EGA/VGA
  94.  *                   14 -        640 x 200 16-color EGA/VGA
  95.  *                   15 -        640 x 350 2-color EGA/VGA
  96.  *                   16 -        640 x 350 16-color EGA/VGA
  97.  *                   17 -        640 x 480 2-color VGA
  98.  *                   18 -        640 x 480 16-color VGA
  99.  *                   19 -        320 x 200 256-color VGA
  100.  *
  101.  *************************************************************************
  102.  */
  103.  
  104. int main
  105. (
  106.   int argc,
  107.   char **argv
  108. )
  109. {
  110.   int i = 0;            /* Scratch counter                              */
  111.   int vmode;            /* Video mode                                   */
  112.   BOOL status = FALSE;  /* Return status                                */
  113.   PCX_VSB *vsbp;        /* Video services data save buffer ptr          */
  114.  
  115.   vsbp = (PCX_VSB *) NULL;      /* Initialize video services buffer ptr */
  116.  
  117.   /* Display program title                                              */
  118.  
  119.   puts("\nWR_DEMO - PCX Image File Write Demonstration Program\n");
  120.  
  121.   if (argc == 3)        /* Check for filename and video mode parameters */
  122.   {
  123.     vmode = atoi(argv[2]);      /* Get the video mode                   */
  124.  
  125.     /* Validate the video mode (must be valid MS-DOS graphics mode)     */
  126.  
  127.     if ((vmode >= 4 && vmode <= 6) || (vmode >= 13 && vmode <= 19))
  128.       status = TRUE;
  129.   }
  130.  
  131.   if (status == TRUE)
  132.   {
  133.     if (_setvideomode(vmode) == 0)      /* Set the video mode           */
  134.     {
  135.       /* Report error                                                   */
  136.  
  137.       fprintf(stderr,
  138.           "ERROR: could not set display adapter to mode %d.\n", vmode);
  139.  
  140.       return (2);
  141.     }
  142.  
  143.     if (vmode >= 13 && vmode <= 18)     /* EGA-compatible video mode ?  */
  144.     {
  145.       if (pcx_isvga() == TRUE)  /* Is a VGA display present ?           */
  146.       {
  147.         /* An EGA display adapter is present - instantiate a Dynamic    */
  148.         /* Save Area buffer to capture the color palette settings each  */
  149.         /* time the palette is updated                                  */
  150.  
  151.         status = pcx_init_dsa(&vsbp);
  152.       }
  153.     }
  154.  
  155.     if (status == TRUE)
  156.     {
  157.       /* Read and display the file (assume video page zero)             */
  158.  
  159.       if ((status = pcx_read(argv[1], vmode, 0)) == TRUE)
  160.       {
  161.         /* Capture the entire screen as a PCX-format file               */
  162.  
  163.         status = pcx_write("PCX_DEMO.PCX", vmode, 0, 640, 480);
  164.  
  165.         (void) _setvideomode(_DEFAULTMODE);     /* Reset the video mode */
  166.  
  167.         if (status == FALSE)
  168.         {
  169.           /* Report error                                               */
  170.  
  171.           fprintf(stderr,
  172.               "\nWR_DEMO - PCX Image File Write Demonstration");
  173.           fprintf(stderr,
  174.               " Program\n\nERROR: Could not write file %s.\n", argv[1]);
  175.         }
  176.       }
  177.       else
  178.       {
  179.         (void) _setvideomode(_DEFAULTMODE);     /* Reset the video mode */
  180.  
  181.         /* Report error                                                 */
  182.  
  183.         fprintf(stderr, "\nWR_DEMO - PCX Image File Write Demonstration");
  184.         fprintf(stderr, " Program\n\nERROR: Could not read file %s.\n",
  185.             argv[1]);
  186.       }
  187.  
  188.       /* Free the Dynamic Save Area (if necessary)                      */
  189.  
  190.       if (vsbp != (PCX_VSB *) NULL)
  191.         pcx_free_dsa(vsbp);
  192.     }
  193.     else
  194.     {
  195.       (void) _setvideomode(_DEFAULTMODE);       /* Reset the video mode */
  196.  
  197.       fputs("ERROR: out of memory.\n", stderr);         /* Report error */
  198.     }
  199.   }
  200.   else          /* Display usage information                            */
  201.   {
  202.     while (use_msg[i] != (unsigned char *) NULL)
  203.       fputs(use_msg[i++], stderr);
  204.   }
  205.  
  206.   if (status == TRUE)
  207.     return (0);
  208.   else
  209.     return (2);
  210. }
  211.  
  212.