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