rsc | f701258 | 2003-11-25 01:40:27 +0000 | [diff] [blame] | 1 | #ifndef _MEMDRAW_H_ |
| 2 | #define _MEMDRAW_H_ 1 |
| 3 | #if defined(__cplusplus) |
| 4 | extern "C" { |
| 5 | #endif |
rsc | eacc13e | 2006-06-25 23:49:56 +0000 | [diff] [blame] | 6 | |
| 7 | AUTOLIB(memdraw) |
| 8 | AUTOLIB(memlayer) |
| 9 | |
rsc | 55dedf7 | 2003-09-30 19:06:20 +0000 | [diff] [blame] | 10 | typedef struct Memimage Memimage; |
| 11 | typedef struct Memdata Memdata; |
| 12 | typedef struct Memsubfont Memsubfont; |
| 13 | typedef struct Memlayer Memlayer; |
| 14 | typedef struct Memcmap Memcmap; |
| 15 | typedef struct Memdrawparam Memdrawparam; |
| 16 | |
| 17 | /* |
| 18 | * Memdata is allocated from main pool, but .data from the image pool. |
| 19 | * Memdata is allocated separately to permit patching its pointer after |
| 20 | * compaction when windows share the image data. |
| 21 | * The first word of data is a back pointer to the Memdata, to find |
| 22 | * The word to patch. |
| 23 | */ |
| 24 | |
| 25 | struct Memdata |
| 26 | { |
| 27 | u32int *base; /* allocated data pointer */ |
| 28 | uchar *bdata; /* pointer to first byte of actual data; word-aligned */ |
| 29 | int ref; /* number of Memimages using this data */ |
| 30 | void* imref; |
| 31 | int allocd; /* is this malloc'd? */ |
| 32 | }; |
| 33 | |
| 34 | enum { |
| 35 | Frepl = 1<<0, /* is replicated */ |
| 36 | Fsimple = 1<<1, /* is 1x1 */ |
| 37 | Fgrey = 1<<2, /* is grey */ |
| 38 | Falpha = 1<<3, /* has explicit alpha */ |
| 39 | Fcmap = 1<<4, /* has cmap channel */ |
rsc | cbeb0b2 | 2006-04-01 19:24:03 +0000 | [diff] [blame] | 40 | Fbytes = 1<<5 /* has only 8-bit channels */ |
rsc | 55dedf7 | 2003-09-30 19:06:20 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | struct Memimage |
| 44 | { |
| 45 | Rectangle r; /* rectangle in data area, local coords */ |
| 46 | Rectangle clipr; /* clipping region */ |
| 47 | int depth; /* number of bits of storage per pixel */ |
| 48 | int nchan; /* number of channels */ |
| 49 | u32int chan; /* channel descriptions */ |
| 50 | Memcmap *cmap; |
| 51 | |
| 52 | Memdata *data; /* pointer to data; shared by windows in this image */ |
| 53 | int zero; /* data->bdata+zero==&byte containing (0,0) */ |
| 54 | u32int width; /* width in words of a single scan line */ |
| 55 | Memlayer *layer; /* nil if not a layer*/ |
| 56 | u32int flags; |
| 57 | void *X; |
rsc | 2009374 | 2003-10-11 02:50:20 +0000 | [diff] [blame] | 58 | int screenref; /* reference count if this is a screen */ |
rsc | 55dedf7 | 2003-09-30 19:06:20 +0000 | [diff] [blame] | 59 | |
| 60 | int shift[NChan]; |
| 61 | int mask[NChan]; |
| 62 | int nbits[NChan]; |
| 63 | }; |
| 64 | |
| 65 | struct Memcmap |
| 66 | { |
| 67 | uchar cmap2rgb[3*256]; |
| 68 | uchar rgb2cmap[16*16*16]; |
| 69 | }; |
| 70 | |
| 71 | /* |
| 72 | * Subfonts |
| 73 | * |
| 74 | * given char c, Subfont *f, Fontchar *i, and Point p, one says |
| 75 | * i = f->info+c; |
| 76 | * draw(b, Rect(p.x+i->left, p.y+i->top, |
| 77 | * p.x+i->left+((i+1)->x-i->x), p.y+i->bottom), |
| 78 | * color, f->bits, Pt(i->x, i->top)); |
| 79 | * p.x += i->width; |
| 80 | * to draw characters in the specified color (itself a Memimage) in Memimage b. |
| 81 | */ |
| 82 | |
| 83 | struct Memsubfont |
| 84 | { |
| 85 | char *name; |
| 86 | short n; /* number of chars in font */ |
| 87 | uchar height; /* height of bitmap */ |
| 88 | char ascent; /* top of bitmap to baseline */ |
| 89 | Fontchar *info; /* n+1 character descriptors */ |
| 90 | Memimage *bits; /* of font */ |
| 91 | }; |
| 92 | |
| 93 | /* |
| 94 | * Encapsulated parameters and information for sub-draw routines. |
| 95 | */ |
| 96 | enum { |
| 97 | Simplesrc=1<<0, |
| 98 | Simplemask=1<<1, |
| 99 | Replsrc=1<<2, |
| 100 | Replmask=1<<3, |
rsc | cbeb0b2 | 2006-04-01 19:24:03 +0000 | [diff] [blame] | 101 | Fullsrc=1<<4, |
| 102 | Fullmask=1<<5 |
rsc | 55dedf7 | 2003-09-30 19:06:20 +0000 | [diff] [blame] | 103 | }; |
| 104 | struct Memdrawparam |
| 105 | { |
| 106 | Memimage *dst; |
| 107 | Rectangle r; |
| 108 | Memimage *src; |
| 109 | Rectangle sr; |
| 110 | Memimage *mask; |
| 111 | Rectangle mr; |
| 112 | int op; |
| 113 | |
| 114 | u32int state; |
| 115 | u32int mval; /* if Simplemask, the mask pixel in mask format */ |
| 116 | u32int mrgba; /* mval in rgba */ |
| 117 | u32int sval; /* if Simplesrc, the source pixel in src format */ |
| 118 | u32int srgba; /* sval in rgba */ |
| 119 | u32int sdval; /* sval in dst format */ |
| 120 | }; |
| 121 | |
| 122 | /* |
| 123 | * Memimage management |
| 124 | */ |
| 125 | |
| 126 | extern Memimage* allocmemimage(Rectangle, u32int); |
| 127 | extern Memimage* allocmemimaged(Rectangle, u32int, Memdata*, void*); |
| 128 | extern Memimage* readmemimage(int); |
| 129 | extern Memimage* creadmemimage(int); |
| 130 | extern int writememimage(int, Memimage*); |
| 131 | extern void freememimage(Memimage*); |
| 132 | extern int loadmemimage(Memimage*, Rectangle, uchar*, int); |
| 133 | extern int cloadmemimage(Memimage*, Rectangle, uchar*, int); |
| 134 | extern int unloadmemimage(Memimage*, Rectangle, uchar*, int); |
| 135 | extern u32int* wordaddr(Memimage*, Point); |
| 136 | extern uchar* byteaddr(Memimage*, Point); |
| 137 | extern int drawclip(Memimage*, Rectangle*, Memimage*, Point*, |
| 138 | Memimage*, Point*, Rectangle*, Rectangle*); |
| 139 | extern void memfillcolor(Memimage*, u32int); |
| 140 | extern int memsetchan(Memimage*, u32int); |
| 141 | extern u32int pixelbits(Memimage*, Point); |
| 142 | |
| 143 | /* |
| 144 | * Graphics |
| 145 | */ |
| 146 | extern void memdraw(Memimage*, Rectangle, Memimage*, Point, |
| 147 | Memimage*, Point, int); |
| 148 | extern void memline(Memimage*, Point, Point, int, int, int, |
| 149 | Memimage*, Point, int); |
| 150 | extern void mempoly(Memimage*, Point*, int, int, int, int, |
| 151 | Memimage*, Point, int); |
| 152 | extern void memfillpoly(Memimage*, Point*, int, int, |
| 153 | Memimage*, Point, int); |
| 154 | extern void _memfillpolysc(Memimage*, Point*, int, int, |
| 155 | Memimage*, Point, int, int, int, int); |
| 156 | extern void memimagedraw(Memimage*, Rectangle, Memimage*, Point, |
| 157 | Memimage*, Point, int); |
| 158 | extern int hwdraw(Memdrawparam*); |
| 159 | extern void memimageline(Memimage*, Point, Point, int, int, int, |
| 160 | Memimage*, Point, int); |
| 161 | extern void _memimageline(Memimage*, Point, Point, int, int, int, |
| 162 | Memimage*, Point, Rectangle, int); |
| 163 | extern Point memimagestring(Memimage*, Point, Memimage*, Point, |
| 164 | Memsubfont*, char*); |
| 165 | extern void memellipse(Memimage*, Point, int, int, int, |
| 166 | Memimage*, Point, int); |
| 167 | extern void memarc(Memimage*, Point, int, int, int, Memimage*, |
| 168 | Point, int, int, int); |
| 169 | extern Rectangle memlinebbox(Point, Point, int, int, int); |
| 170 | extern int memlineendsize(int); |
| 171 | extern void _memmkcmap(void); |
| 172 | extern void memimageinit(void); |
| 173 | |
| 174 | /* |
| 175 | * Subfont management |
| 176 | */ |
| 177 | extern Memsubfont* allocmemsubfont(char*, int, int, int, Fontchar*, Memimage*); |
| 178 | extern Memsubfont* openmemsubfont(char*); |
| 179 | extern void freememsubfont(Memsubfont*); |
| 180 | extern Point memsubfontwidth(Memsubfont*, char*); |
| 181 | extern Memsubfont* getmemdefont(void); |
| 182 | |
| 183 | /* |
| 184 | * Predefined |
| 185 | */ |
| 186 | extern Memimage* memwhite; |
| 187 | extern Memimage* memblack; |
| 188 | extern Memimage* memopaque; |
| 189 | extern Memimage* memtransparent; |
| 190 | extern Memcmap* memdefcmap; |
| 191 | |
| 192 | /* |
| 193 | * Kernel interface |
| 194 | */ |
| 195 | void memimagemove(void*, void*); |
| 196 | |
| 197 | /* |
| 198 | * Kernel cruft |
| 199 | */ |
| 200 | extern void rdb(void); |
| 201 | extern int iprint(char*, ...); |
| 202 | extern int drawdebug; |
| 203 | |
| 204 | /* |
| 205 | * For other implementations, like x11. |
| 206 | */ |
| 207 | extern void _memfillcolor(Memimage*, u32int); |
| 208 | extern Memimage* _allocmemimage(Rectangle, u32int); |
| 209 | extern int _cloadmemimage(Memimage*, Rectangle, uchar*, int); |
| 210 | extern int _loadmemimage(Memimage*, Rectangle, uchar*, int); |
| 211 | extern void _freememimage(Memimage*); |
| 212 | extern u32int _rgbatoimg(Memimage*, u32int); |
| 213 | extern u32int _imgtorgba(Memimage*, u32int); |
| 214 | extern u32int _pixelbits(Memimage*, Point); |
| 215 | extern int _unloadmemimage(Memimage*, Rectangle, uchar*, int); |
| 216 | extern Memdrawparam* _memimagedrawsetup(Memimage*, |
| 217 | Rectangle, Memimage*, Point, Memimage*, |
| 218 | Point, int); |
| 219 | extern void _memimagedraw(Memdrawparam*); |
| 220 | extern void _drawreplacescreenimage(Memimage*); |
rsc | f701258 | 2003-11-25 01:40:27 +0000 | [diff] [blame] | 221 | |
| 222 | #if defined(__cplusplus) |
| 223 | } |
| 224 | #endif |
| 225 | #endif |