1 #ifdef HAS_DOS_DJGR
2 /*
3    Copyright (c) 1991 - 1994 Heinz W. Werntges.  All rights reserved.
4    Distributed by Free Software Foundation, Inc.
5 
6 This file is part of HP2xx.
7 
8 HP2xx is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
10 to anyone for the consequences of using it or for whether it serves any
11 particular purpose or works at all, unless he says so in writing.  Refer
12 to the GNU General Public License, Version 2 or later, for full details.
13 
14 Everyone is granted permission to copy, modify and redistribute
15 HP2xx, but only under the conditions described in the GNU General Public
16 License.  A copy of this license is supposed to have been
17 given to you along with HP2xx so you can know your rights and
18 responsibilities.  It should be in a file named COPYING.  Among other
19 things, the copyright notice and this notice must be preserved on all
20 copies.
21 
22 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23 */
24 
25 /** to_dj_gr.c: GNU-C++ (DJ's DOS port) preview part of project "hp2xx",
26  **             based on DJ Delorie's grapics lib "gr"
27  **
28  ** 92/01/29  V 1.00  HWW  Originating
29  ** 92/05/19  V 1.01  HWW  Abort if color mode
30  ** 92/05/25  V 1.02  HWW  B/W mode also if color; index_from_RowBuf() used
31  ** 92/06/12  V 1.02c HWW  getchar(), B/W warning ...
32  ** 94/02/14  V 1.10a HWW  Adapted to changes in hp2xx.h
33  **
34  ** NOTE: This previewer worked fine on my machine. However, I do not intend
35  **       to maintain DJ Delorie's go32 DOS extender version of hp2xx in the
36  **       future as I favor E. Mattes' extender "emx" which supports OS/2
37  **	  as well.
38  **
39  **       For those of you who are familiar with go32 and don't need
40  **	  OS/2 support -- this previewer is what you might prefer.
41  **/
42 
43 
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <ctype.h>
47 #include <graphics.h>
48 #include "bresnham.h"
49 #include "hp2xx.h"
50 #include "pendef.h"
51 
52 
53 
PicBuf_to_DJ_GR(const GEN_PAR * pg,const OUT_PAR * po)54 int PicBuf_to_DJ_GR(const GEN_PAR * pg, const OUT_PAR * po)
55 {
56 	int row_c, i, x, xoff, y, yoff, color_index;
57 	const PicBuf *pb;
58 	const RowBuf *row;
59 
60 	if (!pg->quiet) {
61 		Eprintf("\nDJ_GR preview follows.\n");
62 		Eprintf("Press <return> to start and end graphics mode\n");
63 		SilentWait();
64 	}
65 	pb = po->picbuf;
66 
67 	xoff = po->xoff * po->dpi_x / 25.4;
68 	yoff = po->yoff * po->dpi_y / 25.4;
69 
70 	if ((!pg->quiet) &&
71 	    (((pb->nb << 3) + xoff > 639) || (pb->nr + yoff > 480))) {
72 		Eprintf
73 		    ("\n\007WARNING: Picture won't fit on a standard VGA!\n");
74 		Eprintf("Current range: (%d..%d) x (%d..%d) pels\n", xoff,
75 			(pb->nb << 3) + xoff, yoff, pb->nr + yoff);
76 		Eprintf("Continue anyway (y/n)?: ");
77 		while (getchar() != '\n');	/* Simple: Chance for ^C */
78 	}
79 
80 	if (pg->is_color)
81 		GrSetColor(0, 160, 160, 160);
82 	else
83 		GrSetColor(0, 180, 180, 180);
84 
85 	GrSetColor(1, 0, 0, 0);
86 	for (i = 2; i < 8; i++)	/* assuming that we indeed get indices 2 ... 7 */
87 		if (i !=
88 		    GrAllocColor(pt.clut[i][0], pt.clut[i][1],
89 				 pt.clut[i][2]))
90 			Eprintf
91 			    ("WARNING: Color code %d may yield wrong color!\n",
92 			     i);
93 
94 	GrSetMode(GR_default_graphics, 800, 600);
95 
96 	for (row_c = 0, y = pb->nr + yoff - 1; row_c < pb->nr;
97 	     row_c++, y--) {
98 		row = get_RowBuf(pb, row_c);
99 		if (row == NULL)
100 			continue;
101 		for (x = 0; x < pb->nc; x++) {
102 			color_index = index_from_RowBuf(row, x, pb);
103 			if (color_index != xxBackground)
104 				GrPlot(x + xoff, y, color_index);
105 		}
106 	}
107 
108 	SilentWait();
109 	GrSetMode(GR_80_25_text, 80, 25);
110 	return 0;
111 }
112 #endif
113