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