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

  1. /*
  2.  *************************************************************************
  3.  *
  4.  *  RD_DEMO.C - PCX_LIB PCX Image File Read 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.\n\n  Usage:     RD_DEMO filename vi",
  45.   "deo_mode\n\n             where \"filename\" is the name of a PCX-form",
  46.   "at image file and\n             \"video_mode\" is an MS-DOS video mod",
  47.   "e.  Valid values are:\n\n                4   - 320 x 200 4-color CGA",
  48.   "\n                5   - 320 x 200 4-color CGA (color burst off)\n    ",
  49.   "            6   - 640 x 200 2-color CGA\n               13   - 320 x ",
  50.   "200 16-color EGA/VGA\n               14   - 640 x 200 16-color EGA/VG",
  51.   "A\n               15   - 640 x 350 2-color EGA/VGA\n               16",
  52.   "   - 640 x 350 16-color EGA/VGA\n               17   - 640 x 480 2-co",
  53.   "lor VGA\n               18   - 640 x 480 16-color VGA\n              ",
  54.   " 19   - 320 x 200 256-color VGA\n\n             The file must be comp",
  55.   "atible with the indicated video mode.\n",
  56.   (unsigned char *) NULL
  57. };
  58.  
  59. /*      PUBLIC FUNCTIONS                                                */
  60.  
  61. /*
  62.  *************************************************************************
  63.  *
  64.  *  MAIN - Executive Function
  65.  *
  66.  *  Purpose:    To read and display a PCX-format image file.
  67.  *
  68.  *  Setup:      int main
  69.  *              (
  70.  *                int argc,
  71.  *                char **argv
  72.  *              )
  73.  *
  74.  *  Where:      argc is the number of command-line arguments.
  75.  *              argv is a pointer to an array of command-line argument
  76.  *                strings.
  77.  *
  78.  *  Return:     0 if successful; otherwise 2.
  79.  *
  80.  *  Note:       Usage is:
  81.  *
  82.  *                RD_DEMO filename video_mode
  83.  *
  84.  *              where:
  85.  *
  86.  *                filename is the name of a PCX-format image file.
  87.  *                video_mode is the MS-DOS video mode.  Valid values are:
  88.  *
  89.  *                    4 -        320 x 200 4-color CGA
  90.  *                    5 -        320 x 200 4-color CGA (color burst off)
  91.  *                    6 -        640 x 200 2-color CGA
  92.  *                   13 -        320 x 200 16-color EGA/VGA
  93.  *                   14 -        640 x 200 16-color EGA/VGA
  94.  *                   15 -        640 x 350 2-color EGA/VGA
  95.  *                   16 -        640 x 350 16-color EGA/VGA
  96.  *                   17 -        640 x 480 2-color VGA
  97.  *                   18 -        640 x 480 16-color VGA
  98.  *                   19 -        320 x 200 256-color VGA
  99.  *
  100.  *************************************************************************
  101.  */
  102.  
  103. int main
  104. (
  105.   int argc,
  106.   char **argv
  107. )
  108. {
  109.   int i = 0;            /* Scratch counter                              */
  110.   int vmode;            /* Video mode                                   */
  111.   BOOL status = FALSE;  /* Return status                                */
  112.  
  113.   /* Display program title                                              */
  114.  
  115.   puts("\nRD_DEMO - PCX Image File Display Demonstration Program\n");
  116.  
  117.   if (argc == 3)        /* Check for filename and video mode parameters */
  118.   {
  119.     vmode = atoi(argv[2]);      /* Get the video mode                   */
  120.  
  121.     /* Validate the video mode (must be valid MS-DOS graphics mode)     */
  122.  
  123.     if ((vmode >= 4 && vmode <= 6) || (vmode >= 13 && vmode <= 19))
  124.       status = TRUE;
  125.   }
  126.  
  127.   if (status == TRUE)
  128.   {
  129.     if (_setvideomode(vmode) == 0)      /* Set the video mode           */
  130.     {
  131.       /* Report error                                                   */
  132.  
  133.       fprintf(stderr,
  134.           "ERROR: could not set display adapter to mode %d.\n", vmode);
  135.  
  136.       return (2);
  137.     }
  138.  
  139.     /* Read and display the file (assume video page zero)               */
  140.  
  141.     if ((status = pcx_read(argv[1], vmode, 0)) == TRUE)
  142.     {
  143.       while (!kbhit())  /* Wait for a keystroke                         */
  144.         ;
  145.  
  146.       (void) getch();   /* Clear the keyboard buffer                    */
  147.     }
  148.  
  149.     (void) _setvideomode(_DEFAULTMODE);         /* Reset the video mode */
  150.  
  151.     if (status == FALSE)
  152.     {
  153.       /* Report error                                                   */
  154.  
  155.       fprintf(stderr, "\nRD_DEMO - PCX Image File Display Demonstration");
  156.       fprintf(stderr, " Program\n\nERROR: Could not read file %s.\n",
  157.           argv[1]);
  158.     }
  159.   }
  160.   else          /* Display usage information                            */
  161.   {
  162.     while (use_msg[i] != (unsigned char *) NULL)
  163.       fputs(use_msg[i++], stderr);
  164.   }
  165.  
  166.   if (status == TRUE)
  167.     return (0);
  168.   else
  169.     return (2);
  170. }
  171.  
  172.