1 /* $NetBSD: raster.h,v 1.5 2000/09/29 06:29:47 deberg 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. XXX: it will also break 2bpp displays. 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, 2, or 8 */ 89 int linelongs; /* longs from one line to the next - for padding */ 90 u_int32_t *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 #ifndef RCONS_16BPP 163 #define RAS_COLOR(color) ( ( (color) & 0xff ) << 4 ) 164 #else 165 #define RAS_COLOR(color) ( ( (color) & 0xffff ) << 4 ) 166 #endif 167 168 /* Get the op from a rop. */ 169 #define RAS_GETOP(op) ( (op) & 0xf ) 170 /* Get the color from a rop. */ 171 #ifndef RCONS_16BPP 172 #define RAS_GETCOLOR(op) ( ( (op) >> 4 ) & 0xff ) 173 #else 174 #define RAS_GETCOLOR(op) ( ( (op) >> 4 ) & 0xffff ) 175 #endif 176 /* Get the longword address of a pixel. */ 177 #define RAS_ADDR( r, x, y ) \ 178 ( (r)->pixels + (y) * (r)->linelongs + (x) * (r)->depth / 32 ) 179 180 181 /* Raster routines. */ 182 183 extern struct raster* raster_alloc ARGS(( int width, int height, int depth )); 184 /* Allocates a raster. Returns (struct raster*) 0 on failure. */ 185 186 extern void raster_free ARGS(( struct raster* r )); 187 /* Frees/closes a raster. */ 188 189 extern int raster_get ARGS(( struct raster* r, int x, int y )); 190 /* Gets a single pixel from a raster. */ 191 192 extern void raster_put ARGS(( struct raster* r, int x, int y, int v )); 193 /* Puts a single pixel into a raster. */ 194 195 extern struct raster* raster_subregion ARGS(( struct raster* r, int x, int y, int width, int height )); 196 /* Makes a raster that points to a region of another. Returns 197 ** (struct raster*) 0 on failure. 198 */ 199 200 201 /* Raster operations. */ 202 203 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 )); 204 /* Performs a bitblit. Returns 0 on success, -1 on failure. */ 205 206 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 )); 207 /* Bitblit without clipping. Returns 0 on success, -1 on failure. */ 208 209 extern int raster_op_nosrc_noclip ARGS(( struct raster* dst, int dx, int dy, int w, int h, int rop )); 210 /* No-src bitblit without clipping. Returns 0 on success, -1 on failure. */ 211 212 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 )); 213 /* Tiles the src to fit the dst. Returns 0 on success, -1 on failure. Only 214 ** implements RAS_SRC. 215 */ 216 217 218 /* Raster text routines */ 219 220 extern struct raster_font* raster_fontopen ARGS(( char* fontname )); 221 /* Opens a font. Returns (struct raster_font*) 0 on failure. */ 222 223 extern int raster_text ARGS(( struct raster* r, int x, int y, int rop, struct raster_font* rf, unsigned char* text )); 224 /* Draws text. Returns 0 on success, -1 on failure. */ 225 226 extern int raster_textn ARGS(( struct raster* r, int x, int y, int rop, struct raster_font* rf, unsigned char* text, int len )); 227 /* Draws n characters of text. Returns 0 on success, -1 on failure. */ 228 229 extern void raster_fontclose ARGS(( struct raster_font* rf )); 230 /* Closes a font. */ 231 232 233 /* Frame buffer routines. */ 234 235 extern struct raster* raster_open ARGS(( char* fbname )); 236 /* Opens a frame buffer as a raster. Returns (struct raster*) 0 on failure. */ 237 238 extern struct raster* raster_coloropen ARGS(( void )); 239 /* Opens a color frame buffer if there is one. Returns (struct raster*) 0 on 240 ** failure. 241 */ 242 243 extern int raster_video_off ARGS(( struct raster* r )); 244 /* Blanks the screen. Returns 0 on success, -1 on failure. This might 245 ** be implemented as actual video blanking, or it might just load black 246 ** into all colormap entries (and disable further colormap changes). 247 */ 248 249 extern int raster_video_on ARGS(( struct raster* r )); 250 /* Re-enables video. Returns 0 on success, -1 on failure. */ 251 252 extern struct raster_colormap* raster_colormap_alloc ARGS(( int length )); 253 /* Allocates a colormap structure, returns 0 on failure. */ 254 255 extern struct raster_colormap* raster_colormap_get ARGS(( struct raster* r )); 256 /* Allocates a colormap structure and returns the frame buffer's 257 ** current colormap, or (struct raster_colormap*) 0 on failure. The raster 258 ** must be one returned by raster_open(), not raster_alloc(). 259 */ 260 261 extern int raster_colormap_set ARGS(( struct raster* r, struct raster_colormap* cm )); 262 /* Sets a frame buffer's colormap. The raster must be one returned 263 ** by raster_open(), not raster_alloc(). Returns 0 on success, -1 on 264 ** failure. 265 */ 266 267 extern void raster_colormap_free ARGS(( struct raster_colormap* cm )); 268 /* Frees a colormap. */ 269 270 #endif /*_RASTER_H_*/ 271