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