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