xref: /csrg-svn/sys/sparc/rcons/raster.h (revision 55131)
1*55131Storek /*-
2*55131Storek  * Copyright (c) 1991 The Regents of the University of California.
3*55131Storek  * All rights reserved.
4*55131Storek  *
5*55131Storek  * This code is derived from software contributed to the Computer Systems
6*55131Storek  * Engineering Group at Lawrence Berkeley Laboratory and to the University
7*55131Storek  * of California at Berkeley by Jef Poskanzer.
8*55131Storek  *
9*55131Storek  * %sccs.include.redist.c%
10*55131Storek  *
11*55131Storek  *	@(#)raster.h	7.1 (Berkeley) 07/13/92
12*55131Storek  *
13*55131Storek  * from: $Header: raster.h,v 1.14 92/06/17 08:14:43 torek Exp $
14*55131Storek  */
15*55131Storek 
16*55131Storek /*
17*55131Storek  * Simple raster and frame buffer routines.
18*55131Storek  *
19*55131Storek  * Currently this set of routines is fairly minimal.  It's enough to
20*55131Storek  * implement a console terminal emulator on monochrome and pseudocolor
21*55131Storek  * screens, and that's about it.
22*55131Storek  *
23*55131Storek  * Future additions might be other kinds of frame buffers (direct color?),
24*55131Storek  * lines, dashed lines, three-operand blits (stipples/stencils), etc.
25*55131Storek  */
26*55131Storek 
27*55131Storek #ifndef _RASTER_H_
28*55131Storek #define _RASTER_H_
29*55131Storek 
30*55131Storek /* Configurable definitions. */
31*55131Storek 
32*55131Storek /* CONFIGURE: define or undef for your machine's byte order */
33*55131Storek #define MSBYTE_FIRST
34*55131Storek 
35*55131Storek /* CONFIGURE: define or under for your frame buffer's bit order */
36*55131Storek #define MSBIT_FIRST
37*55131Storek 
38*55131Storek /* CONFIGURE: The text routines can optionally keep a cache of 8-bit
39*55131Storek ** characters.  This uses about 30K, but makes text on a color screen
40*55131Storek ** go 3.2 times faster.
41*55131Storek */
42*55131Storek #undef COLORFONT_CACHE
43*55131Storek 
44*55131Storek 
45*55131Storek /* Definitions. */
46*55131Storek 
47*55131Storek /* ANSI prototype conditionalizer.  */
48*55131Storek #ifndef ARGS
49*55131Storek #if __STDC__
50*55131Storek #define ARGS(alist) alist
51*55131Storek #else /*__STDC__*/
52*55131Storek #define ARGS(alist) ()
53*55131Storek #endif /*__STDC__*/
54*55131Storek #endif /*ARGS*/
55*55131Storek 
56*55131Storek /* Raster struct. */
57*55131Storek struct raster {
58*55131Storek     int width, height;	/* size in pixels */
59*55131Storek     int depth;		/* bits per pixel - 1 or 8 */
60*55131Storek     int linelongs;	/* longs from one line to the next - for padding */
61*55131Storek     u_long* pixels;	/* pointer to the actual bits */
62*55131Storek     caddr_t data;	/* special pointer for frame buffers and subregions */
63*55131Storek     };
64*55131Storek 
65*55131Storek /* Colormap struct. */
66*55131Storek struct raster_colormap {
67*55131Storek     int length;
68*55131Storek     u_char* red;
69*55131Storek     u_char* grn;
70*55131Storek     u_char* blu;
71*55131Storek     };
72*55131Storek 
73*55131Storek /* Font character struct. */
74*55131Storek struct raster_char {
75*55131Storek     struct raster* r;
76*55131Storek     int homex, homey;
77*55131Storek     int nextx, nexty;
78*55131Storek     };
79*55131Storek 
80*55131Storek #ifdef COLORFONT_CACHE
81*55131Storek struct raster_fontcache {
82*55131Storek     struct raster* cr[256];
83*55131Storek     u_char color[256];
84*55131Storek     };
85*55131Storek #endif /*COLORFONT_CACHE*/
86*55131Storek 
87*55131Storek /* Font struct. */
88*55131Storek struct raster_font {
89*55131Storek     int width, height;	/* nominal character size */
90*55131Storek     int flags;
91*55131Storek #define RASFONT_FIXEDWIDTH		0x1
92*55131Storek #define RASFONT_NOVERTICALMOVEMENT	0x2
93*55131Storek     struct raster_char chars[256];
94*55131Storek #ifdef COLORFONT_CACHE
95*55131Storek     struct raster_fontcache* cache;
96*55131Storek #endif /*COLORFONT_CACHE*/
97*55131Storek     };
98*55131Storek 
99*55131Storek /* Defines for the raster_op() and raster_text() rop parameter - the bitblit
100*55131Storek ** operation.  A rop can be some Boolean combination of RAS_SRC and
101*55131Storek ** RAS_DST.  For instance, just RAS_SRC means copy the source to the
102*55131Storek ** destination without modification.  RAS_SRC|RAS_DST means "or" the source
103*55131Storek ** and destination together, while "xor" would be RAS_SRC^RAS_DST.  The
104*55131Storek ** RAS_NOT macro should be used to express negation - RAS_NOT(RAS_SRC)&RAS_DST
105*55131Storek ** would "and" the complement of the source with the destination.
106*55131Storek **
107*55131Storek ** Or, you can just use one of the pre-defined ops.  There are only 16
108*55131Storek ** possible combinations, so all 16 are defined here.
109*55131Storek **
110*55131Storek ** For color rasters, you specify the color of the operation by simply
111*55131Storek ** oring RAS_COLOR(color) into the rop.
112*55131Storek */
113*55131Storek 
114*55131Storek #define RAS_NOT(op) ( 0xf & ( ~ (op) ) )
115*55131Storek 
116*55131Storek #define RAS_CLEAR		0x0	/* 0 */
117*55131Storek #define RAS_NOTOR		0x1	/* !( src | dst ) */
118*55131Storek #define RAS_NOTSRC_AND_DST	0x2	/* !src & dst */
119*55131Storek #define RAS_INVERTSRC		0x3	/* !src */
120*55131Storek #define RAS_SRC_AND_NOTDST	0x4	/* src & !dst */
121*55131Storek #define RAS_INVERT		0x5	/* !dst */
122*55131Storek #define RAS_XOR			0x6	/* src ^ dst */
123*55131Storek #define RAS_NOTAND		0x7	/* !( src & dst ) */
124*55131Storek #define RAS_AND			0x8	/* src & dst */
125*55131Storek #define RAS_NOTXOR		0x9	/* !( src ^ dst ) */
126*55131Storek #define RAS_DST			0xa	/* dst */
127*55131Storek #define RAS_NOTSRC_OR_DST	0xb	/* !src | dst */
128*55131Storek #define RAS_SRC			0xc	/* src */
129*55131Storek #define RAS_SRC_OR_NOTDST	0xd	/* src | !dst */
130*55131Storek #define RAS_OR			0xe	/* src | dst */
131*55131Storek #define RAS_SET			0xf	/* 1 */
132*55131Storek 
133*55131Storek #define RAS_COLOR(color) ( ( (color) & 0xff ) << 4 )
134*55131Storek 
135*55131Storek /* Get the op from a rop. */
136*55131Storek #define RAS_GETOP(op) ( (op) & 0xf )
137*55131Storek /* Get the color from a rop. */
138*55131Storek #define RAS_GETCOLOR(op) ( ( (op) >> 4 ) & 0xff )
139*55131Storek /* Get the longword address of a pixel. */
140*55131Storek #define RAS_ADDR( r, x, y ) \
141*55131Storek     ( (r)->pixels + (y) * (r)->linelongs + (x) * (r)->depth / 32 )
142*55131Storek 
143*55131Storek 
144*55131Storek /* Raster routines. */
145*55131Storek 
146*55131Storek extern struct raster* raster_alloc ARGS(( int width, int height, int depth ));
147*55131Storek /* Allocates a raster.  Returns (struct raster*) 0 on failure. */
148*55131Storek 
149*55131Storek extern void raster_free ARGS(( struct raster* r ));
150*55131Storek /* Frees/closes a raster. */
151*55131Storek 
152*55131Storek extern int raster_get ARGS(( struct raster* r, int x, int y ));
153*55131Storek /* Gets a single pixel from a raster. */
154*55131Storek 
155*55131Storek extern void raster_put ARGS(( struct raster* r, int x, int y, int v ));
156*55131Storek /* Puts a single pixel into a raster. */
157*55131Storek 
158*55131Storek extern struct raster* raster_subregion ARGS(( struct raster* r, int x, int y, int width, int height ));
159*55131Storek /* Makes a raster that points to a region of another.  Returns
160*55131Storek ** (struct raster*) 0 on failure.
161*55131Storek */
162*55131Storek 
163*55131Storek 
164*55131Storek /* Raster operations.  */
165*55131Storek 
166*55131Storek extern int raster_op ARGS(( struct raster* dst, int dx, int dy, int w, int h, int rop, struct raster* src, int sx, int sy ));
167*55131Storek /* Performs a bitblit.  Returns 0 on success, -1 on failure.  */
168*55131Storek 
169*55131Storek extern int raster_op_noclip ARGS(( struct raster* dst, int dx, int dy, int w, int h, int rop, struct raster* src, int sx, int sy ));
170*55131Storek /* Bitblit without clipping.  Returns 0 on success, -1 on failure. */
171*55131Storek 
172*55131Storek extern int raster_op_nosrc_noclip ARGS(( struct raster* dst, int dx, int dy, int w, int h, int rop ));
173*55131Storek /* No-src bitblit without clipping.  Returns 0 on success, -1 on failure. */
174*55131Storek 
175*55131Storek extern int raster_replsrc ARGS(( struct raster* dst, int dx, int dy, int w, int h, int rop, struct raster* src, int sx, int sy ));
176*55131Storek /* Tiles the src to fit the dst.  Returns 0 on success, -1 on failure.  Only
177*55131Storek ** implements RAS_SRC.
178*55131Storek */
179*55131Storek 
180*55131Storek 
181*55131Storek /* Raster text routines */
182*55131Storek 
183*55131Storek extern struct raster_font* raster_fontopen ARGS(( char* fontname ));
184*55131Storek /* Opens a font. Returns (struct raster_font*) 0 on failure. */
185*55131Storek 
186*55131Storek extern int raster_text ARGS(( struct raster* r, int x, int y, int rop, struct raster_font* rf, char* text ));
187*55131Storek /* Draws text.  Returns 0 on success, -1 on failure. */
188*55131Storek 
189*55131Storek extern int raster_textn ARGS(( struct raster* r, int x, int y, int rop, struct raster_font* rf, char* text, int len ));
190*55131Storek /* Draws n characters of text.  Returns 0 on success, -1 on failure. */
191*55131Storek 
192*55131Storek extern void raster_fontclose ARGS(( struct raster_font* rf ));
193*55131Storek /* Closes a font. */
194*55131Storek 
195*55131Storek 
196*55131Storek /* Frame buffer routines. */
197*55131Storek 
198*55131Storek extern struct raster* raster_open ARGS(( char* fbname ));
199*55131Storek /* Opens a frame buffer as a raster.  Returns (struct raster*) 0 on failure. */
200*55131Storek 
201*55131Storek extern struct raster* raster_coloropen ARGS(( void ));
202*55131Storek /* Opens a color frame buffer if there is one.  Returns (struct raster*) 0 on
203*55131Storek ** failure.
204*55131Storek */
205*55131Storek 
206*55131Storek extern int raster_video_off ARGS(( struct raster* r ));
207*55131Storek /* Blanks the screen.  Returns 0 on success, -1 on failure.  This might
208*55131Storek ** be implemented as actual video blanking, or it might just load black
209*55131Storek ** into all colormap entries (and disable further colormap changes).
210*55131Storek */
211*55131Storek 
212*55131Storek extern int raster_video_on ARGS(( struct raster* r ));
213*55131Storek /* Re-enables video.  Returns 0 on success, -1 on failure. */
214*55131Storek 
215*55131Storek extern struct raster_colormap* raster_colormap_alloc ARGS(( int length ));
216*55131Storek /* Allocates a colormap structure, returns 0 on failure. */
217*55131Storek 
218*55131Storek extern struct raster_colormap* raster_colormap_get ARGS(( struct raster* r ));
219*55131Storek /* Allocates a colormap structure and returns the frame buffer's
220*55131Storek ** current colormap, or (struct raster_colormap*) 0 on failure.  The raster
221*55131Storek ** must be one returned by raster_open(), not raster_alloc().
222*55131Storek */
223*55131Storek 
224*55131Storek extern int raster_colormap_set ARGS(( struct raster* r, struct raster_colormap* cm ));
225*55131Storek /* Sets a frame buffer's colormap.  The raster must be one returned
226*55131Storek ** by raster_open(), not raster_alloc().  Returns 0 on success, -1 on
227*55131Storek ** failure.
228*55131Storek */
229*55131Storek 
230*55131Storek extern void raster_colormap_free ARGS(( struct raster_colormap* cm ));
231*55131Storek /* Frees a colormap. */
232*55131Storek 
233*55131Storek #endif /*_RASTER_H_*/
234