2 *************************************************************************
\r
4 * WR_DEMO.C - PCX_LIB PCX Image File Write Demonstration Program
\r
8 * History: 91/02/14 - Created
\r
9 * 91/04/01 - Release 1.00A
\r
10 * 91/04/06 - Release 1.00B
\r
12 * Compiler: Microsoft C V6.0
\r
14 * Author: Ian Ashdown, P.Eng.
\r
16 * 620 Ballantree Road
\r
17 * West Vancouver, B.C.
\r
19 * Tel. (604) 922-6148
\r
20 * Fax. (604) 987-7621
\r
22 * Copyright: Public Domain
\r
24 *************************************************************************
\r
33 #include "pcx_ext.h"
\r
35 /* FORWARD REFERENCES */
\r
39 static char *use_msg[] = /* Program usage message */
\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
58 /* PUBLIC FUNCTIONS */
\r
61 *************************************************************************
\r
63 * MAIN - Executive Function
\r
65 * Purpose: To write a PCX-format image file.
\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
77 * Return: 0 if successful; otherwise 2.
\r
81 * WR_DEMO filename video_mode
\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
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
99 *************************************************************************
\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
113 vsbp = (PCX_VSB *) NULL; /* Initialize video services buffer ptr */
\r
115 /* Display program title */
\r
117 puts("\nWR_DEMO - PCX Image File Write Demonstration Program\n");
\r
119 if (argc == 3) /* Check for filename and video mode parameters */
\r
121 vmode = atoi(argv[2]); /* Get the video mode */
\r
123 /* Validate the video mode (must be valid MS-DOS graphics mode) */
\r
125 if ((vmode >= 4 && vmode <= 6) || (vmode >= 13 && vmode <= 19))
\r
129 if (status == TRUE)
\r
131 if (_setvideomode(vmode) == 0) /* Set the video mode */
\r
136 "ERROR: could not set display adapter to mode %d.\n", vmode);
\r
141 if (vmode >= 13 && vmode <= 18) /* EGA-compatible video mode ? */
\r
143 if (pcx_isvga() == TRUE) /* Is a VGA display present ? */
\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
149 status = pcx_init_dsa(&vsbp);
\r
153 if (status == TRUE)
\r
155 /* Read and display the file (assume video page zero) */
\r
157 if ((status = pcx_read(argv[1], vmode, 0)) == TRUE)
\r
159 /* Capture the entire screen as a PCX-format file */
\r
161 status = pcx_write("PCX_DEMO.PCX", vmode, 0, 640, 480);
\r
163 (void) _setvideomode(_DEFAULTMODE); /* Reset the video mode */
\r
165 if (status == FALSE)
\r
170 "\nWR_DEMO - PCX Image File Write Demonstration");
\r
172 " Program\n\nERROR: Could not write file %s.\n", argv[1]);
\r
177 (void) _setvideomode(_DEFAULTMODE); /* Reset the video mode */
\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
186 /* Free the Dynamic Save Area (if necessary) */
\r
188 if (vsbp != (PCX_VSB *) NULL)
\r
189 pcx_free_dsa(vsbp);
\r
193 (void) _setvideomode(_DEFAULTMODE); /* Reset the video mode */
\r
195 fputs("ERROR: out of memory.\n", stderr); /* Report error */
\r
198 else /* Display usage information */
\r
200 while (use_msg[i] != (unsigned char *) NULL)
\r
201 fputs(use_msg[i++], stderr);
\r
204 if (status == TRUE)
\r