1 #ifdef VAX
2 /*
3    Copyright (c) 1992 - 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_uis.c: VAX/VMS UIS previewer of project "hp2xx"
26  **
27  ** 92/04/15  V 1.00  HWW  Originating, based on mandel.c (V 1.02)
28  **                        Raw coding, not tested yet!
29  ** 92/04/24  V 1.01  HWW  Tested and accelerated on uVAX, VMS 4.7
30  ** 92/04/27  V 1.02  HWW  Cleaned up
31  ** 92/05/25  V 1.02b HWW  Abort if color mode (due to lack of
32  **			   test facilities) -- Color support desired!
33  ** 93/09/01  V 1.02c HWW  Minor fixes (courtesy G. Steger)
34  ** 94/02/14  V 1.10a HWW  Adapted to changes in hp2xx.h
35  **
36  ** NOTE: Due to lack of testing facilities, I will not be able to maintain
37  **       this file any longer. Volunteers are welcome!
38  **/
39 
40 
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <ctype.h>
44 #include <descrip.h>
45 #include <uisentry.h>
46 /* #include <uisusrdef.h> */
47 #include "bresnham.h"
48 #include "hp2xx.h"
49 
50 
51 
PicBuf_to_UIS(const GEN_PAR * pg,const OUT_PAR * po)52 int PicBuf_to_UIS(const GEN_PAR * pg, const OUT_PAR * po)
53 {
54 	int byte_c, xoff, yoff;
55 	unsigned long row_c, x1, x2, rw, rh, bpp, zero = 0, two = 2;
56 	const RowBuf *row;
57 	const PicBuf *pb;
58 
59 	float x0f, y0f, x1f, y1f, w, h;
60 	int c_old, c_new, i;
61 	unsigned vd_id, wd_id;
62 	char *target = "sys$workstation";
63 	static float intens[2] = { 1.0, 0.0 };
64 	static unsigned atb = 1;
65 
66 	struct dsc$descriptor_s s_desc;
67 
68 	if (pg == NULL || po == NULL)
69 		return ERROR;
70 	pb = po->picbuf;
71 	if (pb == NULL)
72 		return ERROR;
73 
74 	if (pb->depth > 1) {
75 		Eprintf
76 		    ("\nUIS preview does not support colors yet -- sorry\n");
77 		return ERROR;
78 	}
79 
80 	if (!pg->quiet) {
81 		Eprintf("\nUIS preview follows\n");
82 		Eprintf("Press <return> to end\n");
83 	}
84 
85 	xoff = po->xoff * po->dpi_x / 25.4;
86 	yoff = po->yoff * po->dpi_y / 25.4;
87 
88 	if ((!pg->quiet) &&
89 	    (((pb->nb << 3) + xoff > 1024) || (pb->nr + yoff > 1024))) {
90 		Eprintf("\n\007WARNING: Picture won't fit!\n");
91 		Eprintf("Current range: (%d..%d) x (%d..%d) pels\n",
92 			xoff, (pb->nb << 3) + xoff, yoff, pb->nr + yoff);
93 		Eprintf("Continue anyway (y/n)?: ");
94 		if (toupper(getchar()) != 'Y')
95 			return;
96 	}
97 
98 	x0f = y0f = 0.0;	/* No offsets yet       */
99 	x1f = (float) (pb->nb << 3);
100 	y1f = (float) pb->nr;
101 	w = (float) po->width / 10.0;	/* VAX needs cm, not mm */
102 	h = (float) po->height / 10.0;
103 
104 	vd_id = uis$create_display(&x0f, &y0f, &x1f, &y1f, &w, &h);
105 	uis$disable_display_list(&vd_id);
106 	uis$set_intensities(&vd_id, &zero, &two, intens);
107 
108 	s_desc.dsc$w_length = strlen(target);
109 	s_desc.dsc$a_pointer = target;
110 	s_desc.dsc$b_class = DSC$K_CLASS_S;
111 	s_desc.dsc$b_dtype = DSC$K_DTYPE_T;
112 	wd_id = uis$create_window(&vd_id, &s_desc);
113 
114 	x1 = 0;
115 	x2 = pb->nc;
116 	rw = pb->nc;
117 	rh = 1;
118 	bpp = 1;
119 
120 	for (row_c = 0; row_c < pb->nr; row_c++) {	/* for all pixel rows */
121 /**
122  ** Unfortunately, we need a bit reversal in each byte here:
123  **/
124 		row = get_RowBuf(pb, row_c);
125 		if (row == NULL)
126 			continue;
127 		for (byte_c = 0; byte_c < pb->nb; byte_c++) {
128 			c_old = row->buf[byte_c];
129 
130 			if (c_old == 0)	/* all white        */
131 				continue;
132 			if (c_old == 0xff)	/* all black        */
133 				continue;
134 
135 			for (i = 0, c_new = 0;;) {
136 				if (c_old & 1)
137 					c_new |= 1;
138 				if (++i == 8)	/* 8 bits, 7 shifts */
139 					break;
140 				c_new <<= 1;
141 				c_old >>= 1;
142 			}
143 			row->buf[byte_c] = c_new;
144 		}
145 
146 		uisdc$image(&wd_id, &atb, &x1, &row_c, &x2, &row_c,
147 			    &rw, &rh, &bpp, row->buf);
148 	}
149 	getchar();
150 	uis$delete_display(&vd_id);
151 	return 0;
152 }
153 #endif
154