Home | History | Annotate | Line # | Download | only in rcons
raster.h revision 1.2
      1 /*	$NetBSD: raster.h,v 1.2 1995/10/04 23:57:19 pk Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1991, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to the Computer Systems
      8  * Engineering Group at Lawrence Berkeley Laboratory and to the University
      9  * of California at Berkeley by Jef Poskanzer.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the University of
     22  *	California, Berkeley and its contributors.
     23  * 4. Neither the name of the University nor the names of its contributors
     24  *    may be used to endorse or promote products derived from this software
     25  *    without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37  * SUCH DAMAGE.
     38  *
     39  *	@(#)raster.h	8.1 (Berkeley) 6/11/93
     40  */
     41 
     42 /*
     43  * Simple raster and frame buffer routines.
     44  *
     45  * Currently this set of routines is fairly minimal.  It's enough to
     46  * implement a console terminal emulator on monochrome and pseudocolor
     47  * screens, and that's about it.
     48  *
     49  * Future additions might be other kinds of frame buffers (direct color?),
     50  * lines, dashed lines, three-operand blits (stipples/stencils), etc.
     51  */
     52 
     53 #ifndef _RASTER_H_
     54 #define _RASTER_H_
     55 
     56 /* Configurable definitions. */
     57 
     58 
     59 #include <machine/endian.h>
     60 #if BYTE_ORDER == BIG_ENDIAN
     61 /* CONFIGURE: define or undef for your machine's byte order */
     62 #define MSBYTE_FIRST
     63 /* CONFIGURE: define or under for your frame buffer's bit order */
     64 #define MSBIT_FIRST
     65 #endif
     66 
     67 /* CONFIGURE: The text routines can optionally keep a cache of 8-bit
     68 ** characters.  This uses about 30K, but makes text on a color screen
     69 ** go 3.2 times faster.
     70 */
     71 #undef COLORFONT_CACHE
     72 
     73 
     74 /* Definitions. */
     75 
     76 /* ANSI prototype conditionalizer.  */
     77 #ifndef ARGS
     78 #if __STDC__
     79 #define ARGS(alist) alist
     80 #else /*__STDC__*/
     81 #define ARGS(alist) ()
     82 #endif /*__STDC__*/
     83 #endif /*ARGS*/
     84 
     85 /* Raster struct. */
     86 struct raster {
     87     int width, height;	/* size in pixels */
     88     int depth;		/* bits per pixel - 1 or 8 */
     89     int linelongs;	/* longs from one line to the next - for padding */
     90     u_long* pixels;	/* pointer to the actual bits */
     91     caddr_t data;	/* special pointer for frame buffers and subregions */
     92     };
     93 
     94 /* Colormap struct. */
     95 struct raster_colormap {
     96     int length;
     97     u_char* red;
     98     u_char* grn;
     99     u_char* blu;
    100     };
    101 
    102 /* Font character struct. */
    103 struct raster_char {
    104     struct raster* r;
    105     int homex, homey;
    106     int nextx, nexty;
    107     };
    108 
    109 #ifdef COLORFONT_CACHE
    110 struct raster_fontcache {
    111     struct raster* cr[256];
    112     u_char color[256];
    113     };
    114 #endif /*COLORFONT_CACHE*/
    115 
    116 /* Font struct. */
    117 struct raster_font {
    118     int width, height, ascent;	/* nominal character size */
    119     int flags;
    120 #define RASFONT_FIXEDWIDTH		0x1
    121 #define RASFONT_NOVERTICALMOVEMENT	0x2
    122     struct raster_char chars[256];
    123 #ifdef COLORFONT_CACHE
    124     struct raster_fontcache* cache;
    125 #endif /*COLORFONT_CACHE*/
    126     };
    127 
    128 /* Defines for the raster_op() and raster_text() rop parameter - the bitblit
    129 ** operation.  A rop can be some Boolean combination of RAS_SRC and
    130 ** RAS_DST.  For instance, just RAS_SRC means copy the source to the
    131 ** destination without modification.  RAS_SRC|RAS_DST means "or" the source
    132 ** and destination together, while "xor" would be RAS_SRC^RAS_DST.  The
    133 ** RAS_NOT macro should be used to express negation - RAS_NOT(RAS_SRC)&RAS_DST
    134 ** would "and" the complement of the source with the destination.
    135 **
    136 ** Or, you can just use one of the pre-defined ops.  There are only 16
    137 ** possible combinations, so all 16 are defined here.
    138 **
    139 ** For color rasters, you specify the color of the operation by simply
    140 ** oring RAS_COLOR(color) into the rop.
    141 */
    142 
    143 #define RAS_NOT(op) ( 0xf & ( ~ (op) ) )
    144 
    145 #define RAS_CLEAR		0x0	/* 0 */
    146 #define RAS_NOTOR		0x1	/* !( src | dst ) */
    147 #define RAS_NOTSRC_AND_DST	0x2	/* !src & dst */
    148 #define RAS_INVERTSRC		0x3	/* !src */
    149 #define RAS_SRC_AND_NOTDST	0x4	/* src & !dst */
    150 #define RAS_INVERT		0x5	/* !dst */
    151 #define RAS_XOR			0x6	/* src ^ dst */
    152 #define RAS_NOTAND		0x7	/* !( src & dst ) */
    153 #define RAS_AND			0x8	/* src & dst */
    154 #define RAS_NOTXOR		0x9	/* !( src ^ dst ) */
    155 #define RAS_DST			0xa	/* dst */
    156 #define RAS_NOTSRC_OR_DST	0xb	/* !src | dst */
    157 #define RAS_SRC			0xc	/* src */
    158 #define RAS_SRC_OR_NOTDST	0xd	/* src | !dst */
    159 #define RAS_OR			0xe	/* src | dst */
    160 #define RAS_SET			0xf	/* 1 */
    161 
    162 #define RAS_COLOR(color) ( ( (color) & 0xff ) << 4 )
    163 
    164 /* Get the op from a rop. */
    165 #define RAS_GETOP(op) ( (op) & 0xf )
    166 /* Get the color from a rop. */
    167 #define RAS_GETCOLOR(op) ( ( (op) >> 4 ) & 0xff )
    168 /* Get the longword address of a pixel. */
    169 #define RAS_ADDR( r, x, y ) \
    170     ( (r)->pixels + (y) * (r)->linelongs + (x) * (r)->depth / 32 )
    171 
    172 
    173 /* Raster routines. */
    174 
    175 extern struct raster* raster_alloc ARGS(( int width, int height, int depth ));
    176 /* Allocates a raster.  Returns (struct raster*) 0 on failure. */
    177 
    178 extern void raster_free ARGS(( struct raster* r ));
    179 /* Frees/closes a raster. */
    180 
    181 extern int raster_get ARGS(( struct raster* r, int x, int y ));
    182 /* Gets a single pixel from a raster. */
    183 
    184 extern void raster_put ARGS(( struct raster* r, int x, int y, int v ));
    185 /* Puts a single pixel into a raster. */
    186 
    187 extern struct raster* raster_subregion ARGS(( struct raster* r, int x, int y, int width, int height ));
    188 /* Makes a raster that points to a region of another.  Returns
    189 ** (struct raster*) 0 on failure.
    190 */
    191 
    192 
    193 /* Raster operations.  */
    194 
    195 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 ));
    196 /* Performs a bitblit.  Returns 0 on success, -1 on failure.  */
    197 
    198 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 ));
    199 /* Bitblit without clipping.  Returns 0 on success, -1 on failure. */
    200 
    201 extern int raster_op_nosrc_noclip ARGS(( struct raster* dst, int dx, int dy, int w, int h, int rop ));
    202 /* No-src bitblit without clipping.  Returns 0 on success, -1 on failure. */
    203 
    204 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 ));
    205 /* Tiles the src to fit the dst.  Returns 0 on success, -1 on failure.  Only
    206 ** implements RAS_SRC.
    207 */
    208 
    209 
    210 /* Raster text routines */
    211 
    212 extern struct raster_font* raster_fontopen ARGS(( char* fontname ));
    213 /* Opens a font. Returns (struct raster_font*) 0 on failure. */
    214 
    215 extern int raster_text ARGS(( struct raster* r, int x, int y, int rop, struct raster_font* rf, unsigned char* text ));
    216 /* Draws text.  Returns 0 on success, -1 on failure. */
    217 
    218 extern int raster_textn ARGS(( struct raster* r, int x, int y, int rop, struct raster_font* rf, unsigned char* text, int len ));
    219 /* Draws n characters of text.  Returns 0 on success, -1 on failure. */
    220 
    221 extern void raster_fontclose ARGS(( struct raster_font* rf ));
    222 /* Closes a font. */
    223 
    224 
    225 /* Frame buffer routines. */
    226 
    227 extern struct raster* raster_open ARGS(( char* fbname ));
    228 /* Opens a frame buffer as a raster.  Returns (struct raster*) 0 on failure. */
    229 
    230 extern struct raster* raster_coloropen ARGS(( void ));
    231 /* Opens a color frame buffer if there is one.  Returns (struct raster*) 0 on
    232 ** failure.
    233 */
    234 
    235 extern int raster_video_off ARGS(( struct raster* r ));
    236 /* Blanks the screen.  Returns 0 on success, -1 on failure.  This might
    237 ** be implemented as actual video blanking, or it might just load black
    238 ** into all colormap entries (and disable further colormap changes).
    239 */
    240 
    241 extern int raster_video_on ARGS(( struct raster* r ));
    242 /* Re-enables video.  Returns 0 on success, -1 on failure. */
    243 
    244 extern struct raster_colormap* raster_colormap_alloc ARGS(( int length ));
    245 /* Allocates a colormap structure, returns 0 on failure. */
    246 
    247 extern struct raster_colormap* raster_colormap_get ARGS(( struct raster* r ));
    248 /* Allocates a colormap structure and returns the frame buffer's
    249 ** current colormap, or (struct raster_colormap*) 0 on failure.  The raster
    250 ** must be one returned by raster_open(), not raster_alloc().
    251 */
    252 
    253 extern int raster_colormap_set ARGS(( struct raster* r, struct raster_colormap* cm ));
    254 /* Sets a frame buffer's colormap.  The raster must be one returned
    255 ** by raster_open(), not raster_alloc().  Returns 0 on success, -1 on
    256 ** failure.
    257 */
    258 
    259 extern void raster_colormap_free ARGS(( struct raster_colormap* cm ));
    260 /* Frees a colormap. */
    261 
    262 #endif /*_RASTER_H_*/
    263