2 /* Copyright (c) 1995, 1998 by Arkkra Enterprises */
3 /* All rights reserved */
5 /* Functions for displaying Mup/Ghostscript output on screen using
18 /* hard code X and Y sizes for the moment */
22 /* image to be calloc'ed has 6 header bytes, then each row consecutively */
23 #define BITS2BYTES(bits) (((bits) + 7) / 8) /* round upwards */
24 #define SIZEIMAGE (6 + ((long)BITS2BYTES(XSIZE)*4) * (long)YSIZE)
27 static void zapblock P((char *area, long size));
30 /* initialize graphics driver, etc */
36 struct videoconfig vidinfo;
39 /* initalize best graphics mode */
40 if (_setvideomode(_VRES16COLOR) == 0) {
41 fprintf(stderr, "can't set graphics mode\n");
45 _getvideoconfig(&vidinfo);
47 if (vidinfo.numxpixels != XSIZE || vidinfo.numypixels != YSIZE) {
48 _setvideomode(_DEFAULTMODE);
49 fprintf(stderr, "video mode %dx%d not supported\n",
50 vidinfo.numxpixels, vidinfo.numypixels);
55 * Allocate the image buffer. Note that both parameters must be less
56 * than 65536, but the total size (product) can be greater. The +1
57 * is to allow room for the header bytes (and then some).
59 Image = (char *)calloc(BITS2BYTES(YSIZE)*4 + 1, XSIZE);
61 _setvideomode(_DEFAULTMODE);
62 fprintf(stderr, "can't allocate image buffer\n");
66 /* set aspect ratio adjust */
67 Conf_info_p->adjust = 1.375 * (double) vidinfo.numypixels
68 / (double) vidinfo.numxpixels;
69 Conf_info_p->vlines = vidinfo.numypixels;
71 /* set screen to all white */
72 _setbkcolor(_BRIGHTWHITE);
73 _clearscreen(_GCLEARSCREEN);
77 /* before exiting, clean up graphics, then call the general cleanup routine */
80 dos_cleanup(int status)
82 _setvideomode(_DEFAULTMODE);
83 generalcleanup(status);
87 /* draw a screen worth of the bitmap, starting at specified raster line */
92 int line; /* start at this raster line */
93 int small; /* YES or NO for small or large page image */
96 int r; /* row index */
97 long offset; /* into bitmap file */
98 int fd; /* file descriptor */
99 int himage_bytes; /* horizontal image bytes */
100 char *row_ptr; /* point at a row of the image */
101 int n; /* loop variable */
104 /* make sure we have a valid page to draw */
105 if (Currpage_p == (struct Pginfo *) 0) {
106 ( *(Conf_info_p->error) ) ("page # out of range");
110 /* figure out where in the bitmap file this page is */
111 offset = Currpage_p->seqnum * BYTES_PER_PAGE;
112 fd = gen1file(small);
113 lseek(fd, offset + (long)line * BYTES_PER_LINE, SEEK_SET);
115 /* zero out the image buffer */
116 zapblock(Image, SIZEIMAGE);
118 /* number of bytes representing one horizontal row in full page image */
119 himage_bytes = BITS2BYTES(XSIZE) * 4;
121 /* set the header bytes in the image */
122 Image[0] = XSIZE % 256;
123 Image[1] = XSIZE / 256;
124 Image[2] = YSIZE % 256;
125 Image[3] = YSIZE / 256;
129 /* set screen to all white */
130 _setbkcolor(_BRIGHTWHITE);
131 _clearscreen(_GCLEARSCREEN);
134 for (r = 0; r < Conf_info_p->vlines; r++) {
135 /* read it directly into the image */
136 row_ptr = &Image[ 6 + r * himage_bytes ];
137 if (read(fd, row_ptr, BYTES_PER_LINE) != BYTES_PER_LINE) {
142 /* black out the unused strip on the right */
143 for (n = BITS_PER_LINE; n < XSIZE; n++)
144 row_ptr[n/8] |= 1 << (7 - n%8);
147 /* put at upper left corner, (0, 0) */
148 _putimage(0, 0, Image, _GPSET);
152 /* for now we just beep on errors */
164 /* for user interface, call command processor for each character read */
171 int special = 0; /* 1 = got a null, which is first character
172 * of special key sequence */
208 /* display a raster centered on window */
211 dos_raster(bitmap, width, height)
213 unsigned char *bitmap; /* what to display */
214 int width, height; /* of bitmap, width is in bytes */
217 int r, c; /* row and column indices */
218 int b; /* index through bits */
219 int x, y; /* upper left corner of where to put bitmap,
221 int himage_bytes; /* bytes needed for one row in image */
222 int n; /* loop variable */
223 char *row_ptr; /* point at a row of the image */
226 himage_bytes = 4 * width;
228 /* figure out how to center on screen */
229 x = (BYTES_PER_LINE - width) / 2 * 8;
230 y = (Conf_info_p->vlines - height) / 2;
232 /* zero out the image buffer */
233 zapblock(Image, SIZEIMAGE);
235 /* set the header bytes in the image */
236 Image[0] = (width * 8) % 256;
237 Image[1] = (width * 8) / 256;
238 Image[2] = height % 256;
239 Image[3] = height / 256;
244 for (r = 0; r < height; r++) {
245 row_ptr = &Image[ 6 + r * himage_bytes ];
246 for (c = 0; c < width; c++) {
247 for (b = 0; b < 8; b++) {
248 if (bitmap[r*width+c] & (1 << (7-b))) {
249 /* white (15); set 4 copies of bit */
250 for (n = 0; n < 4; n++)
251 row_ptr[n*width + c] |=
254 /* black (8); set only the first */
255 row_ptr[c] |= (1 << (7-b));
261 _putimage(x, y, Image, _GPSET);
264 /* zero out a block of memory that may be bigger than 32K */
266 #define BLOCKSIZE 0x3fff
278 * memset's third parm is "unsigned int", so we can't do the whole
281 for (k = 0; k < size; k += BLOCKSIZE) {
282 if (size - k >= BLOCKSIZE)
283 (void)memset(&area[k], 0, BLOCKSIZE);
285 (void)memset(&area[k], 0, size - k);
291 /* some compilers don't like empty files, so if __WATCOMC__ isn't defined,
292 * put something here to keep those compilers happy */