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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
|
#ifndef _DRAW_H_
#define _DRAW_H_ 1
#if defined(__cplusplus)
extern "C" {
#endif
typedef struct Cachefont Cachefont;
typedef struct Cacheinfo Cacheinfo;
typedef struct Cachesubf Cachesubf;
typedef struct Display Display;
typedef struct Font Font;
typedef struct Fontchar Fontchar;
typedef struct Image Image;
typedef struct Mouse Mouse;
typedef struct Point Point;
typedef struct Rectangle Rectangle;
typedef struct RGB RGB;
typedef struct Screen Screen;
typedef struct Subfont Subfont;
extern int Rfmt(Fmt*);
extern int Pfmt(Fmt*);
#define DOpaque 0xFFFFFFFF
#define DTransparent 0x00000000 /* only useful for allocimage memfillcolor */
#define DBlack 0x000000FF
#define DWhite 0xFFFFFFFF
#define DRed 0xFF0000FF
#define DGreen 0x00FF00FF
#define DBlue 0x0000FFFF
#define DCyan 0x00FFFFFF
#define DMagenta 0xFF00FFFF
#define DYellow 0xFFFF00FF
#define DPaleyellow 0xFFFFAAFF
#define DDarkyellow 0xEEEE9EFF
#define DDarkgreen 0x448844FF
#define DPalegreen 0xAAFFAAFF
#define DMedgreen 0x88CC88FF
#define DDarkblue 0x000055FF
#define DPalebluegreen 0xAAFFFFFF
#define DPaleblue 0x0000BBFF
#define DBluegreen 0x008888FF
#define DGreygreen 0x55AAAAFF
#define DPalegreygreen 0x9EEEEEFF
#define DYellowgreen 0x99994CFF
#define DMedblue 0x000099FF
#define DGreyblue 0x005DBBFF
#define DPalegreyblue 0x4993DDFF
#define DPurpleblue 0x8888CCFF
#define DNotacolor 0xFFFFFF00
#define DNofill DNotacolor
enum
{
Displaybufsize = 8000,
ICOSSCALE = 1024,
Borderwidth = 4,
};
enum
{
/* refresh methods */
Refbackup = 0,
Refnone = 1,
Refmesg = 2
};
#define NOREFRESH ((void*)-1)
enum
{
/* line ends */
Endsquare = 0,
Enddisc = 1,
Endarrow = 2,
Endmask = 0x1F
};
#define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
typedef enum
{
/* Porter-Duff compositing operators */
Clear = 0,
SinD = 8,
DinS = 4,
SoutD = 2,
DoutS = 1,
S = SinD|SoutD,
SoverD = SinD|SoutD|DoutS,
SatopD = SinD|DoutS,
SxorD = SoutD|DoutS,
D = DinS|DoutS,
DoverS = DinS|DoutS|SoutD,
DatopS = DinS|SoutD,
DxorS = DoutS|SoutD, /* == SxorD */
Ncomp = 12,
} Drawop;
/*
* image channel descriptors
*/
enum {
CRed = 0,
CGreen,
CBlue,
CGrey,
CAlpha,
CMap,
CIgnore,
NChan,
};
#define __DC(type, nbits) ((((type)&15)<<4)|((nbits)&15))
#define CHAN1(a,b) __DC(a,b)
#define CHAN2(a,b,c,d) (CHAN1((a),(b))<<8|__DC((c),(d)))
#define CHAN3(a,b,c,d,e,f) (CHAN2((a),(b),(c),(d))<<8|__DC((e),(f)))
#define CHAN4(a,b,c,d,e,f,g,h) (CHAN3((a),(b),(c),(d),(e),(f))<<8|__DC((g),(h)))
#define NBITS(c) ((c)&15)
#define TYPE(c) (((c)>>4)&15)
enum {
GREY1 = CHAN1(CGrey, 1),
GREY2 = CHAN1(CGrey, 2),
GREY4 = CHAN1(CGrey, 4),
GREY8 = CHAN1(CGrey, 8),
CMAP8 = CHAN1(CMap, 8),
RGB15 = CHAN4(CIgnore, 1, CRed, 5, CGreen, 5, CBlue, 5),
RGB16 = CHAN3(CRed, 5, CGreen, 6, CBlue, 5),
RGB24 = CHAN3(CRed, 8, CGreen, 8, CBlue, 8),
BGR24 = CHAN3(CBlue, 8, CGreen, 8, CRed, 8),
RGBA32 = CHAN4(CRed, 8, CGreen, 8, CBlue, 8, CAlpha, 8),
ARGB32 = CHAN4(CAlpha, 8, CRed, 8, CGreen, 8, CBlue, 8), /* stupid VGAs */
XRGB32 = CHAN4(CIgnore, 8, CRed, 8, CGreen, 8, CBlue, 8),
XBGR32 = CHAN4(CIgnore, 8, CBlue, 8, CGreen, 8, CRed, 8),
};
extern char* chantostr(char*, u32int);
extern u32int strtochan(char*);
extern int chantodepth(u32int);
struct Point
{
int x;
int y;
};
struct Rectangle
{
Point min;
Point max;
};
typedef void (*Reffn)(Image*, Rectangle, void*);
struct Screen
{
Display *display; /* display holding data */
int id; /* id of system-held Screen */
Image *image; /* unused; for reference only */
Image *fill; /* color to paint behind windows */
};
struct Display
{
QLock qlock;
int locking; /*program is using lockdisplay */
int dirno;
int imageid;
int local;
void (*error)(Display*, char*);
char *devdir;
char *windir;
char oldlabel[64];
u32int dataqid;
Image *image;
Image *white;
Image *black;
Image *opaque;
Image *transparent;
uchar *buf;
int bufsize;
uchar *bufp;
uchar *obuf;
int obufsize;
uchar *obufp;
Font *defaultfont;
Subfont *defaultsubfont;
Image *windows;
Image *screenimage;
int _isnewdisplay;
};
struct Image
{
Display *display; /* display holding data */
int id; /* id of system-held Image */
Rectangle r; /* rectangle in data area, local coords */
Rectangle clipr; /* clipping region */
int depth; /* number of bits per pixel */
u32int chan;
int repl; /* flag: data replicates to tile clipr */
Screen *screen; /* 0 if not a window */
Image *next; /* next in list of windows */
};
struct RGB
{
u32int red;
u32int green;
u32int blue;
};
/*
* Subfonts
*
* given char c, Subfont *f, Fontchar *i, and Point p, one says
* i = f->info+c;
* void(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 an Image) in Image b.
*/
struct Fontchar
{
int x; /* left edge of bits */
uchar top; /* first non-zero scan-line */
uchar bottom; /* last non-zero scan-line + 1 */
char left; /* offset of baseline */
uchar width; /* width of baseline */
};
struct Subfont
{
char *name;
short n; /* number of chars in font */
uchar height; /* height of image */
char ascent; /* top of image to baseline */
Fontchar *info; /* n+1 character descriptors */
Image *bits; /* of font */
int ref;
};
enum
{
/* starting values */
LOG2NFCACHE = 6,
NFCACHE = (1<<LOG2NFCACHE), /* #chars cached */
NFLOOK = 5, /* #chars to scan in cache */
NFSUBF = 2, /* #subfonts to cache */
/* max value */
MAXFCACHE = 1024+NFLOOK, /* upper limit */
MAXSUBF = 50, /* generous upper limit */
/* deltas */
DSUBF = 4,
/* expiry ages */
SUBFAGE = 10000,
CACHEAGE = 10000
};
struct Cachefont
{
Rune min; /* lowest rune value to be taken from subfont */
Rune max; /* highest rune value+1 to be taken from subfont */
int offset; /* position in subfont of character at min */
char *name; /* stored in font */
char *subfontname; /* to access subfont */
};
struct Cacheinfo
{
ushort x; /* left edge of bits */
uchar width; /* width of baseline */
schar left; /* offset of baseline */
Rune value; /* value of character at this slot in cache */
ushort age;
};
struct Cachesubf
{
u32int age; /* for replacement */
Cachefont *cf; /* font info that owns us */
Subfont *f; /* attached subfont */
};
struct Font
{
char *name;
Display *display;
short height; /* max height of image, interline spacing */
short ascent; /* top of image to baseline */
short width; /* widest so far; used in caching only */
short nsub; /* number of subfonts */
u32int age; /* increasing counter; used for LRU */
int maxdepth; /* maximum depth of all loaded subfonts */
int ncache; /* size of cache */
int nsubf; /* size of subfont list */
Cacheinfo *cache;
Cachesubf *subf;
Cachefont **sub; /* as read from file */
Image *cacheimage;
};
#define Dx(r) ((r).max.x-(r).min.x)
#define Dy(r) ((r).max.y-(r).min.y)
/*
* Image management
*/
extern Image* _allocimage(Image*, Display*, Rectangle, u32int, int, u32int, int, int);
extern Image* allocimage(Display*, Rectangle, u32int, int, u32int);
extern uchar* bufimage(Display*, int);
extern int bytesperline(Rectangle, int);
extern void closedisplay(Display*);
extern void drawerror(Display*, char*);
extern int flushimage(Display*, int);
extern int freeimage(Image*);
extern int _freeimage1(Image*);
extern int geninitdraw(char*, void(*)(Display*, char*), char*, char*, char*, int);
extern int initdraw(void(*)(Display*, char*), char*, char*);
extern int newwindow(char*);
extern int loadimage(Image*, Rectangle, uchar*, int);
extern int cloadimage(Image*, Rectangle, uchar*, int);
extern int getwindow(Display*, int);
extern int gengetwindow(Display*, char*, Image**, Screen**, int);
extern Image* readimage(Display*, int, int);
extern Image* creadimage(Display*, int, int);
extern int unloadimage(Image*, Rectangle, uchar*, int);
extern int wordsperline(Rectangle, int);
extern int writeimage(int, Image*, int);
extern Image* namedimage(Display*, char*);
extern int nameimage(Image*, char*, int);
extern Image* allocimagemix(Display*, u32int, u32int);
extern int drawsetlabel(Display*, char*);
/*
* Colors
*/
extern void readcolmap(Display*, RGB*);
extern void writecolmap(Display*, RGB*);
extern u32int setalpha(u32int, uchar);
/*
* Windows
*/
extern Screen* allocscreen(Image*, Image*, int);
extern Image* _allocwindow(Image*, Screen*, Rectangle, int, u32int);
extern Image* allocwindow(Screen*, Rectangle, int, u32int);
extern void bottomnwindows(Image**, int);
extern void bottomwindow(Image*);
extern int freescreen(Screen*);
extern Screen* publicscreen(Display*, int, u32int);
extern void topnwindows(Image**, int);
extern void topwindow(Image*);
extern int originwindow(Image*, Point, Point);
/*
* Geometry
*/
extern Point Pt(int, int);
extern Rectangle Rect(int, int, int, int);
extern Rectangle Rpt(Point, Point);
extern Point addpt(Point, Point);
extern Point subpt(Point, Point);
extern Point divpt(Point, int);
extern Point mulpt(Point, int);
extern int eqpt(Point, Point);
extern int eqrect(Rectangle, Rectangle);
extern Rectangle insetrect(Rectangle, int);
extern Rectangle rectaddpt(Rectangle, Point);
extern Rectangle rectsubpt(Rectangle, Point);
extern Rectangle canonrect(Rectangle);
extern int rectXrect(Rectangle, Rectangle);
extern int rectinrect(Rectangle, Rectangle);
extern void combinerect(Rectangle*, Rectangle);
extern int rectclip(Rectangle*, Rectangle);
extern int ptinrect(Point, Rectangle);
extern void replclipr(Image*, int, Rectangle);
extern int drawreplxy(int, int, int); /* used to be drawsetxy */
extern Point drawrepl(Rectangle, Point);
extern int rgb2cmap(int, int, int);
extern int cmap2rgb(int);
extern int cmap2rgba(int);
extern void icossin(int, int*, int*);
extern void icossin2(int, int, int*, int*);
/*
* Graphics
*/
extern void draw(Image*, Rectangle, Image*, Image*, Point);
extern void drawop(Image*, Rectangle, Image*, Image*, Point, Drawop);
extern void gendraw(Image*, Rectangle, Image*, Point, Image*, Point);
extern void gendrawop(Image*, Rectangle, Image*, Point, Image*, Point, Drawop);
extern void line(Image*, Point, Point, int, int, int, Image*, Point);
extern void lineop(Image*, Point, Point, int, int, int, Image*, Point, Drawop);
extern void poly(Image*, Point*, int, int, int, int, Image*, Point);
extern void polyop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
extern void fillpoly(Image*, Point*, int, int, Image*, Point);
extern void fillpolyop(Image*, Point*, int, int, Image*, Point, Drawop);
extern Point string(Image*, Point, Image*, Point, Font*, char*);
extern Point stringop(Image*, Point, Image*, Point, Font*, char*, Drawop);
extern Point stringn(Image*, Point, Image*, Point, Font*, char*, int);
extern Point stringnop(Image*, Point, Image*, Point, Font*, char*, int, Drawop);
extern Point runestring(Image*, Point, Image*, Point, Font*, Rune*);
extern Point runestringop(Image*, Point, Image*, Point, Font*, Rune*, Drawop);
extern Point runestringn(Image*, Point, Image*, Point, Font*, Rune*, int);
extern Point runestringnop(Image*, Point, Image*, Point, Font*, Rune*, int, Drawop);
extern Point stringbg(Image*, Point, Image*, Point, Font*, char*, Image*, Point);
extern Point stringbgop(Image*, Point, Image*, Point, Font*, char*, Image*, Point, Drawop);
extern Point stringnbg(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point);
extern Point stringnbgop(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point, Drawop);
extern Point runestringbg(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point);
extern Point runestringbgop(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point, Drawop);
extern Point runestringnbg(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point);
extern Point runestringnbgop(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point, Drawop);
extern Point _string(Image*, Point, Image*, Point, Font*, char*, Rune*, int, Rectangle, Image*, Point, Drawop);
extern Point stringsubfont(Image*, Point, Image*, Subfont*, char*);
extern int bezier(Image*, Point, Point, Point, Point, int, int, int, Image*, Point);
extern int bezierop(Image*, Point, Point, Point, Point, int, int, int, Image*, Point, Drawop);
extern int bezspline(Image*, Point*, int, int, int, int, Image*, Point);
extern int bezsplineop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
extern int bezsplinepts(Point*, int, Point**);
extern int fillbezier(Image*, Point, Point, Point, Point, int, Image*, Point);
extern int fillbezierop(Image*, Point, Point, Point, Point, int, Image*, Point, Drawop);
extern int fillbezspline(Image*, Point*, int, int, Image*, Point);
extern int fillbezsplineop(Image*, Point*, int, int, Image*, Point, Drawop);
extern void ellipse(Image*, Point, int, int, int, Image*, Point);
extern void ellipseop(Image*, Point, int, int, int, Image*, Point, Drawop);
extern void fillellipse(Image*, Point, int, int, Image*, Point);
extern void fillellipseop(Image*, Point, int, int, Image*, Point, Drawop);
extern void arc(Image*, Point, int, int, int, Image*, Point, int, int);
extern void arcop(Image*, Point, int, int, int, Image*, Point, int, int, Drawop);
extern void fillarc(Image*, Point, int, int, Image*, Point, int, int);
extern void fillarcop(Image*, Point, int, int, Image*, Point, int, int, Drawop);
extern void border(Image*, Rectangle, int, Image*, Point);
extern void borderop(Image*, Rectangle, int, Image*, Point, Drawop);
/*
* Font management
*/
extern Font* openfont(Display*, char*);
extern Font* buildfont(Display*, char*, char*);
extern void freefont(Font*);
extern Font* mkfont(Subfont*, Rune);
extern int cachechars(Font*, char**, Rune**, ushort*, int, int*, char**);
extern void agefont(Font*);
extern Subfont* allocsubfont(char*, int, int, int, Fontchar*, Image*);
extern Subfont* lookupsubfont(Display*, char*);
extern void installsubfont(char*, Subfont*);
extern void uninstallsubfont(Subfont*);
extern void freesubfont(Subfont*);
extern Subfont* readsubfont(Display*, char*, int, int);
extern Subfont* readsubfonti(Display*, char*, int, Image*, int);
extern int writesubfont(int, Subfont*);
extern void _unpackinfo(Fontchar*, uchar*, int);
extern Point stringsize(Font*, char*);
extern int stringwidth(Font*, char*);
extern int stringnwidth(Font*, char*, int);
extern Point runestringsize(Font*, Rune*);
extern int runestringwidth(Font*, Rune*);
extern int runestringnwidth(Font*, Rune*, int);
extern Point strsubfontwidth(Subfont*, char*);
extern int loadchar(Font*, Rune, Cacheinfo*, int, int, char**);
extern char* subfontname(char*, char*, int);
extern Subfont* _getsubfont(Display*, char*);
extern Subfont* getdefont(Display*);
extern void lockdisplay(Display*);
extern void unlockdisplay(Display*);
extern int drawlsetrefresh(u32int, int, void*, void*);
/*
* Predefined
*/
extern uchar defontdata[];
extern int sizeofdefont;
extern Point ZP;
extern Rectangle ZR;
/*
* Set up by initdraw()
*/
extern Display *display;
extern Font *font;
extern Image *screen;
extern Screen *_screen;
extern int _cursorfd;
extern int _drawdebug; /* set to 1 to see errors from flushimage */
extern void _setdrawop(Display*, Drawop);
extern Display *_initdisplay(void(*)(Display*,char*), char*);
#define BGSHORT(p) (((p)[0]<<0) | ((p)[1]<<8))
#define BGLONG(p) ((BGSHORT(p)<<0) | (BGSHORT(p+2)<<16))
#define BPSHORT(p, v) ((p)[0]=(v), (p)[1]=((v)>>8))
#define BPLONG(p, v) (BPSHORT(p, (v)), BPSHORT(p+2, (v)>>16))
/*
* Compressed image file parameters and helper routines
*/
#define NMATCH 3 /* shortest match possible */
#define NRUN (NMATCH+31) /* longest match possible */
#define NMEM 1024 /* window size */
#define NDUMP 128 /* maximum length of dump */
#define NCBLOCK 6000 /* size of compressed blocks */
extern void _twiddlecompressed(uchar*, int);
extern int _compblocksize(Rectangle, int);
/* XXX backwards helps; should go */
extern u32int drawld2chan[];
extern void drawsetdebug(int);
/*
* Snarf buffer
*/
enum
{
SnarfSize = 64*1024,
};
char *getsnarf(void);
void putsnarf(char*);
void drawtopwindow(void);
void drawresizewindow(Rectangle);
extern char *winsize;
/*
* Port magic.
*/
int _drawmsgread(Display*, void*, int);
int _drawmsgwrite(Display*, void*, int);
int _latin1(Rune*, int);
#if defined(__cplusplus)
}
#endif
#endif
|