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