xref: /csrg-svn/sys/sparc/rcons/raster.h (revision 63321)
155131Storek /*-
2*63321Sbostic  * Copyright (c) 1991, 1993
3*63321Sbostic  *	The Regents of the University of California.  All rights reserved.
455131Storek  *
555131Storek  * This code is derived from software contributed to the Computer Systems
655131Storek  * Engineering Group at Lawrence Berkeley Laboratory and to the University
755131Storek  * of California at Berkeley by Jef Poskanzer.
855131Storek  *
955131Storek  * %sccs.include.redist.c%
1055131Storek  *
11*63321Sbostic  *	@(#)raster.h	8.1 (Berkeley) 06/11/93
1255131Storek  *
1355131Storek  * from: $Header: raster.h,v 1.14 92/06/17 08:14:43 torek Exp $
1455131Storek  */
1555131Storek 
1655131Storek /*
1755131Storek  * Simple raster and frame buffer routines.
1855131Storek  *
1955131Storek  * Currently this set of routines is fairly minimal.  It's enough to
2055131Storek  * implement a console terminal emulator on monochrome and pseudocolor
2155131Storek  * screens, and that's about it.
2255131Storek  *
2355131Storek  * Future additions might be other kinds of frame buffers (direct color?),
2455131Storek  * lines, dashed lines, three-operand blits (stipples/stencils), etc.
2555131Storek  */
2655131Storek 
2755131Storek #ifndef _RASTER_H_
2855131Storek #define _RASTER_H_
2955131Storek 
3055131Storek /* Configurable definitions. */
3155131Storek 
3255131Storek /* CONFIGURE: define or undef for your machine's byte order */
3355131Storek #define MSBYTE_FIRST
3455131Storek 
3555131Storek /* CONFIGURE: define or under for your frame buffer's bit order */
3655131Storek #define MSBIT_FIRST
3755131Storek 
3855131Storek /* CONFIGURE: The text routines can optionally keep a cache of 8-bit
3955131Storek ** characters.  This uses about 30K, but makes text on a color screen
4055131Storek ** go 3.2 times faster.
4155131Storek */
4255131Storek #undef COLORFONT_CACHE
4355131Storek 
4455131Storek 
4555131Storek /* Definitions. */
4655131Storek 
4755131Storek /* ANSI prototype conditionalizer.  */
4855131Storek #ifndef ARGS
4955131Storek #if __STDC__
5055131Storek #define ARGS(alist) alist
5155131Storek #else /*__STDC__*/
5255131Storek #define ARGS(alist) ()
5355131Storek #endif /*__STDC__*/
5455131Storek #endif /*ARGS*/
5555131Storek 
5655131Storek /* Raster struct. */
5755131Storek struct raster {
5855131Storek     int width, height;	/* size in pixels */
5955131Storek     int depth;		/* bits per pixel - 1 or 8 */
6055131Storek     int linelongs;	/* longs from one line to the next - for padding */
6155131Storek     u_long* pixels;	/* pointer to the actual bits */
6255131Storek     caddr_t data;	/* special pointer for frame buffers and subregions */
6355131Storek     };
6455131Storek 
6555131Storek /* Colormap struct. */
6655131Storek struct raster_colormap {
6755131Storek     int length;
6855131Storek     u_char* red;
6955131Storek     u_char* grn;
7055131Storek     u_char* blu;
7155131Storek     };
7255131Storek 
7355131Storek /* Font character struct. */
7455131Storek struct raster_char {
7555131Storek     struct raster* r;
7655131Storek     int homex, homey;
7755131Storek     int nextx, nexty;
7855131Storek     };
7955131Storek 
8055131Storek #ifdef COLORFONT_CACHE
8155131Storek struct raster_fontcache {
8255131Storek     struct raster* cr[256];
8355131Storek     u_char color[256];
8455131Storek     };
8555131Storek #endif /*COLORFONT_CACHE*/
8655131Storek 
8755131Storek /* Font struct. */
8855131Storek struct raster_font {
8955131Storek     int width, height;	/* nominal character size */
9055131Storek     int flags;
9155131Storek #define RASFONT_FIXEDWIDTH		0x1
9255131Storek #define RASFONT_NOVERTICALMOVEMENT	0x2
9355131Storek     struct raster_char chars[256];
9455131Storek #ifdef COLORFONT_CACHE
9555131Storek     struct raster_fontcache* cache;
9655131Storek #endif /*COLORFONT_CACHE*/
9755131Storek     };
9855131Storek 
9955131Storek /* Defines for the raster_op() and raster_text() rop parameter - the bitblit
10055131Storek ** operation.  A rop can be some Boolean combination of RAS_SRC and
10155131Storek ** RAS_DST.  For instance, just RAS_SRC means copy the source to the
10255131Storek ** destination without modification.  RAS_SRC|RAS_DST means "or" the source
10355131Storek ** and destination together, while "xor" would be RAS_SRC^RAS_DST.  The
10455131Storek ** RAS_NOT macro should be used to express negation - RAS_NOT(RAS_SRC)&RAS_DST
10555131Storek ** would "and" the complement of the source with the destination.
10655131Storek **
10755131Storek ** Or, you can just use one of the pre-defined ops.  There are only 16
10855131Storek ** possible combinations, so all 16 are defined here.
10955131Storek **
11055131Storek ** For color rasters, you specify the color of the operation by simply
11155131Storek ** oring RAS_COLOR(color) into the rop.
11255131Storek */
11355131Storek 
11455131Storek #define RAS_NOT(op) ( 0xf & ( ~ (op) ) )
11555131Storek 
11655131Storek #define RAS_CLEAR		0x0	/* 0 */
11755131Storek #define RAS_NOTOR		0x1	/* !( src | dst ) */
11855131Storek #define RAS_NOTSRC_AND_DST	0x2	/* !src & dst */
11955131Storek #define RAS_INVERTSRC		0x3	/* !src */
12055131Storek #define RAS_SRC_AND_NOTDST	0x4	/* src & !dst */
12155131Storek #define RAS_INVERT		0x5	/* !dst */
12255131Storek #define RAS_XOR			0x6	/* src ^ dst */
12355131Storek #define RAS_NOTAND		0x7	/* !( src & dst ) */
12455131Storek #define RAS_AND			0x8	/* src & dst */
12555131Storek #define RAS_NOTXOR		0x9	/* !( src ^ dst ) */
12655131Storek #define RAS_DST			0xa	/* dst */
12755131Storek #define RAS_NOTSRC_OR_DST	0xb	/* !src | dst */
12855131Storek #define RAS_SRC			0xc	/* src */
12955131Storek #define RAS_SRC_OR_NOTDST	0xd	/* src | !dst */
13055131Storek #define RAS_OR			0xe	/* src | dst */
13155131Storek #define RAS_SET			0xf	/* 1 */
13255131Storek 
13355131Storek #define RAS_COLOR(color) ( ( (color) & 0xff ) << 4 )
13455131Storek 
13555131Storek /* Get the op from a rop. */
13655131Storek #define RAS_GETOP(op) ( (op) & 0xf )
13755131Storek /* Get the color from a rop. */
13855131Storek #define RAS_GETCOLOR(op) ( ( (op) >> 4 ) & 0xff )
13955131Storek /* Get the longword address of a pixel. */
14055131Storek #define RAS_ADDR( r, x, y ) \
14155131Storek     ( (r)->pixels + (y) * (r)->linelongs + (x) * (r)->depth / 32 )
14255131Storek 
14355131Storek 
14455131Storek /* Raster routines. */
14555131Storek 
14655131Storek extern struct raster* raster_alloc ARGS(( int width, int height, int depth ));
14755131Storek /* Allocates a raster.  Returns (struct raster*) 0 on failure. */
14855131Storek 
14955131Storek extern void raster_free ARGS(( struct raster* r ));
15055131Storek /* Frees/closes a raster. */
15155131Storek 
15255131Storek extern int raster_get ARGS(( struct raster* r, int x, int y ));
15355131Storek /* Gets a single pixel from a raster. */
15455131Storek 
15555131Storek extern void raster_put ARGS(( struct raster* r, int x, int y, int v ));
15655131Storek /* Puts a single pixel into a raster. */
15755131Storek 
15855131Storek extern struct raster* raster_subregion ARGS(( struct raster* r, int x, int y, int width, int height ));
15955131Storek /* Makes a raster that points to a region of another.  Returns
16055131Storek ** (struct raster*) 0 on failure.
16155131Storek */
16255131Storek 
16355131Storek 
16455131Storek /* Raster operations.  */
16555131Storek 
16655131Storek 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 ));
16755131Storek /* Performs a bitblit.  Returns 0 on success, -1 on failure.  */
16855131Storek 
16955131Storek 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 ));
17055131Storek /* Bitblit without clipping.  Returns 0 on success, -1 on failure. */
17155131Storek 
17255131Storek extern int raster_op_nosrc_noclip ARGS(( struct raster* dst, int dx, int dy, int w, int h, int rop ));
17355131Storek /* No-src bitblit without clipping.  Returns 0 on success, -1 on failure. */
17455131Storek 
17555131Storek 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 ));
17655131Storek /* Tiles the src to fit the dst.  Returns 0 on success, -1 on failure.  Only
17755131Storek ** implements RAS_SRC.
17855131Storek */
17955131Storek 
18055131Storek 
18155131Storek /* Raster text routines */
18255131Storek 
18355131Storek extern struct raster_font* raster_fontopen ARGS(( char* fontname ));
18455131Storek /* Opens a font. Returns (struct raster_font*) 0 on failure. */
18555131Storek 
18655131Storek extern int raster_text ARGS(( struct raster* r, int x, int y, int rop, struct raster_font* rf, char* text ));
18755131Storek /* Draws text.  Returns 0 on success, -1 on failure. */
18855131Storek 
18955131Storek extern int raster_textn ARGS(( struct raster* r, int x, int y, int rop, struct raster_font* rf, char* text, int len ));
19055131Storek /* Draws n characters of text.  Returns 0 on success, -1 on failure. */
19155131Storek 
19255131Storek extern void raster_fontclose ARGS(( struct raster_font* rf ));
19355131Storek /* Closes a font. */
19455131Storek 
19555131Storek 
19655131Storek /* Frame buffer routines. */
19755131Storek 
19855131Storek extern struct raster* raster_open ARGS(( char* fbname ));
19955131Storek /* Opens a frame buffer as a raster.  Returns (struct raster*) 0 on failure. */
20055131Storek 
20155131Storek extern struct raster* raster_coloropen ARGS(( void ));
20255131Storek /* Opens a color frame buffer if there is one.  Returns (struct raster*) 0 on
20355131Storek ** failure.
20455131Storek */
20555131Storek 
20655131Storek extern int raster_video_off ARGS(( struct raster* r ));
20755131Storek /* Blanks the screen.  Returns 0 on success, -1 on failure.  This might
20855131Storek ** be implemented as actual video blanking, or it might just load black
20955131Storek ** into all colormap entries (and disable further colormap changes).
21055131Storek */
21155131Storek 
21255131Storek extern int raster_video_on ARGS(( struct raster* r ));
21355131Storek /* Re-enables video.  Returns 0 on success, -1 on failure. */
21455131Storek 
21555131Storek extern struct raster_colormap* raster_colormap_alloc ARGS(( int length ));
21655131Storek /* Allocates a colormap structure, returns 0 on failure. */
21755131Storek 
21855131Storek extern struct raster_colormap* raster_colormap_get ARGS(( struct raster* r ));
21955131Storek /* Allocates a colormap structure and returns the frame buffer's
22055131Storek ** current colormap, or (struct raster_colormap*) 0 on failure.  The raster
22155131Storek ** must be one returned by raster_open(), not raster_alloc().
22255131Storek */
22355131Storek 
22455131Storek extern int raster_colormap_set ARGS(( struct raster* r, struct raster_colormap* cm ));
22555131Storek /* Sets a frame buffer's colormap.  The raster must be one returned
22655131Storek ** by raster_open(), not raster_alloc().  Returns 0 on success, -1 on
22755131Storek ** failure.
22855131Storek */
22955131Storek 
23055131Storek extern void raster_colormap_free ARGS(( struct raster_colormap* cm ));
23155131Storek /* Frees a colormap. */
23255131Storek 
23355131Storek #endif /*_RASTER_H_*/
234