3 #if defined(__cplusplus)
9 typedef struct Cachefont Cachefont;
10 typedef struct Cacheinfo Cacheinfo;
11 typedef struct Cachesubf Cachesubf;
12 typedef struct Display Display;
13 typedef struct Font Font;
14 typedef struct Fontchar Fontchar;
15 typedef struct Image Image;
16 typedef struct Mouse Mouse;
17 typedef struct Point Point;
18 typedef struct Rectangle Rectangle;
19 typedef struct RGB RGB;
20 typedef struct Screen Screen;
21 typedef struct Subfont Subfont;
23 extern int Rfmt(Fmt*);
24 extern int Pfmt(Fmt*);
26 #define DOpaque 0xFFFFFFFF
27 #define DTransparent 0x00000000 /* only useful for allocimage memfillcolor */
28 #define DBlack 0x000000FF
29 #define DWhite 0xFFFFFFFF
30 #define DRed 0xFF0000FF
31 #define DGreen 0x00FF00FF
32 #define DBlue 0x0000FFFF
33 #define DCyan 0x00FFFFFF
34 #define DMagenta 0xFF00FFFF
35 #define DYellow 0xFFFF00FF
36 #define DPaleyellow 0xFFFFAAFF
37 #define DDarkyellow 0xEEEE9EFF
38 #define DDarkgreen 0x448844FF
39 #define DPalegreen 0xAAFFAAFF
40 #define DMedgreen 0x88CC88FF
41 #define DDarkblue 0x000055FF
42 #define DPalebluegreen 0xAAFFFFFF
43 #define DPaleblue 0x0000BBFF
44 #define DBluegreen 0x008888FF
45 #define DGreygreen 0x55AAAAFF
46 #define DPalegreygreen 0x9EEEEEFF
47 #define DYellowgreen 0x99994CFF
48 #define DMedblue 0x000099FF
49 #define DGreyblue 0x005DBBFF
50 #define DPalegreyblue 0x4993DDFF
51 #define DPurpleblue 0x8888CCFF
53 #define DNotacolor 0xFFFFFF00
54 #define DNofill DNotacolor
58 Displaybufsize = 8000,
70 #define NOREFRESH ((void*)-1)
81 #define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
85 /* Porter-Duff compositing operators */
94 SoverD = SinD|SoutD|DoutS,
99 DoverS = DinS|DoutS|SoutD,
101 DxorS = DoutS|SoutD, /* == SxorD */
107 * image channel descriptors
120 #define __DC(type, nbits) ((((type)&15)<<4)|((nbits)&15))
121 #define CHAN1(a,b) __DC(a,b)
122 #define CHAN2(a,b,c,d) (CHAN1((a),(b))<<8|__DC((c),(d)))
123 #define CHAN3(a,b,c,d,e,f) (CHAN2((a),(b),(c),(d))<<8|__DC((e),(f)))
124 #define CHAN4(a,b,c,d,e,f,g,h) (CHAN3((a),(b),(c),(d),(e),(f))<<8|__DC((g),(h)))
126 #define NBITS(c) ((c)&15)
127 #define TYPE(c) (((c)>>4)&15)
130 GREY1 = CHAN1(CGrey, 1),
131 GREY2 = CHAN1(CGrey, 2),
132 GREY4 = CHAN1(CGrey, 4),
133 GREY8 = CHAN1(CGrey, 8),
134 CMAP8 = CHAN1(CMap, 8),
135 RGB15 = CHAN4(CIgnore, 1, CRed, 5, CGreen, 5, CBlue, 5),
136 RGB16 = CHAN3(CRed, 5, CGreen, 6, CBlue, 5),
137 RGB24 = CHAN3(CRed, 8, CGreen, 8, CBlue, 8),
138 BGR24 = CHAN3(CBlue, 8, CGreen, 8, CRed, 8),
139 RGBA32 = CHAN4(CRed, 8, CGreen, 8, CBlue, 8, CAlpha, 8),
140 ARGB32 = CHAN4(CAlpha, 8, CRed, 8, CGreen, 8, CBlue, 8), /* stupid VGAs */
141 XRGB32 = CHAN4(CIgnore, 8, CRed, 8, CGreen, 8, CBlue, 8),
142 XBGR32 = CHAN4(CIgnore, 8, CBlue, 8, CGreen, 8, CRed, 8),
145 extern char* chantostr(char*, u32int);
146 extern u32int strtochan(char*);
147 extern int chantodepth(u32int);
161 typedef void (*Reffn)(Image*, Rectangle, void*);
165 Display *display; /* display holding data */
166 int id; /* id of system-held Screen */
167 Image *image; /* unused; for reference only */
168 Image *fill; /* color to paint behind windows */
174 int locking; /*program is using lockdisplay */
178 void (*error)(Display*, char*);
195 Subfont *defaultsubfont;
203 Display *display; /* display holding data */
204 int id; /* id of system-held Image */
205 Rectangle r; /* rectangle in data area, local coords */
206 Rectangle clipr; /* clipping region */
207 int depth; /* number of bits per pixel */
209 int repl; /* flag: data replicates to tile clipr */
210 Screen *screen; /* 0 if not a window */
211 Image *next; /* next in list of windows */
224 * given char c, Subfont *f, Fontchar *i, and Point p, one says
226 * void(b, Rect(p.x+i->left, p.y+i->top,
227 * p.x+i->left+((i+1)->x-i->x), p.y+i->bottom),
228 * color, f->bits, Pt(i->x, i->top));
230 * to draw characters in the specified color (itself an Image) in Image b.
235 int x; /* left edge of bits */
236 uchar top; /* first non-zero scan-line */
237 uchar bottom; /* last non-zero scan-line + 1 */
238 char left; /* offset of baseline */
239 uchar width; /* width of baseline */
245 short n; /* number of chars in font */
246 uchar height; /* height of image */
247 char ascent; /* top of image to baseline */
248 Fontchar *info; /* n+1 character descriptors */
249 Image *bits; /* of font */
255 /* starting values */
257 NFCACHE = (1<<LOG2NFCACHE), /* #chars cached */
258 NFLOOK = 5, /* #chars to scan in cache */
259 NFSUBF = 2, /* #subfonts to cache */
261 MAXFCACHE = 1024+NFLOOK, /* upper limit */
262 MAXSUBF = 50, /* generous upper limit */
272 Rune min; /* lowest rune value to be taken from subfont */
273 Rune max; /* highest rune value+1 to be taken from subfont */
274 int offset; /* position in subfont of character at min */
275 char *name; /* stored in font */
276 char *subfontname; /* to access subfont */
281 ushort x; /* left edge of bits */
282 uchar width; /* width of baseline */
283 schar left; /* offset of baseline */
284 Rune value; /* value of character at this slot in cache */
290 u32int age; /* for replacement */
291 Cachefont *cf; /* font info that owns us */
292 Subfont *f; /* attached subfont */
299 short height; /* max height of image, interline spacing */
300 short ascent; /* top of image to baseline */
301 short width; /* widest so far; used in caching only */
302 short nsub; /* number of subfonts */
303 u32int age; /* increasing counter; used for LRU */
304 int maxdepth; /* maximum depth of all loaded subfonts */
305 int ncache; /* size of cache */
306 int nsubf; /* size of subfont list */
309 Cachefont **sub; /* as read from file */
313 #define Dx(r) ((r).max.x-(r).min.x)
314 #define Dy(r) ((r).max.y-(r).min.y)
319 extern Image* _allocimage(Image*, Display*, Rectangle, u32int, int, u32int, int, int);
320 extern Image* allocimage(Display*, Rectangle, u32int, int, u32int);
321 extern uchar* bufimage(Display*, int);
322 extern int bytesperline(Rectangle, int);
323 extern void closedisplay(Display*);
324 extern void drawerror(Display*, char*);
325 extern int flushimage(Display*, int);
326 extern int freeimage(Image*);
327 extern int _freeimage1(Image*);
328 extern int geninitdraw(char*, void(*)(Display*, char*), char*, char*, char*, int);
329 extern int initdraw(void(*)(Display*, char*), char*, char*);
330 extern int newwindow(char*);
331 extern int loadimage(Image*, Rectangle, uchar*, int);
332 extern int cloadimage(Image*, Rectangle, uchar*, int);
333 extern int getwindow(Display*, int);
334 extern int gengetwindow(Display*, char*, Image**, Screen**, int);
335 extern Image* readimage(Display*, int, int);
336 extern Image* creadimage(Display*, int, int);
337 extern int unloadimage(Image*, Rectangle, uchar*, int);
338 extern int wordsperline(Rectangle, int);
339 extern int writeimage(int, Image*, int);
340 extern Image* namedimage(Display*, char*);
341 extern int nameimage(Image*, char*, int);
342 extern Image* allocimagemix(Display*, u32int, u32int);
343 extern int drawsetlabel(char*);
348 extern void readcolmap(Display*, RGB*);
349 extern void writecolmap(Display*, RGB*);
350 extern u32int setalpha(u32int, uchar);
355 extern Screen* allocscreen(Image*, Image*, int);
356 extern Image* _allocwindow(Image*, Screen*, Rectangle, int, u32int);
357 extern Image* allocwindow(Screen*, Rectangle, int, u32int);
358 extern void bottomnwindows(Image**, int);
359 extern void bottomwindow(Image*);
360 extern int freescreen(Screen*);
361 extern Screen* publicscreen(Display*, int, u32int);
362 extern void topnwindows(Image**, int);
363 extern void topwindow(Image*);
364 extern int originwindow(Image*, Point, Point);
369 extern Point Pt(int, int);
370 extern Rectangle Rect(int, int, int, int);
371 extern Rectangle Rpt(Point, Point);
372 extern Point addpt(Point, Point);
373 extern Point subpt(Point, Point);
374 extern Point divpt(Point, int);
375 extern Point mulpt(Point, int);
376 extern int eqpt(Point, Point);
377 extern int eqrect(Rectangle, Rectangle);
378 extern Rectangle insetrect(Rectangle, int);
379 extern Rectangle rectaddpt(Rectangle, Point);
380 extern Rectangle rectsubpt(Rectangle, Point);
381 extern Rectangle canonrect(Rectangle);
382 extern int rectXrect(Rectangle, Rectangle);
383 extern int rectinrect(Rectangle, Rectangle);
384 extern void combinerect(Rectangle*, Rectangle);
385 extern int rectclip(Rectangle*, Rectangle);
386 extern int ptinrect(Point, Rectangle);
387 extern void replclipr(Image*, int, Rectangle);
388 extern int drawreplxy(int, int, int); /* used to be drawsetxy */
389 extern Point drawrepl(Rectangle, Point);
390 extern int rgb2cmap(int, int, int);
391 extern int cmap2rgb(int);
392 extern int cmap2rgba(int);
393 extern void icossin(int, int*, int*);
394 extern void icossin2(int, int, int*, int*);
399 extern void draw(Image*, Rectangle, Image*, Image*, Point);
400 extern void drawop(Image*, Rectangle, Image*, Image*, Point, Drawop);
401 extern void gendraw(Image*, Rectangle, Image*, Point, Image*, Point);
402 extern void gendrawop(Image*, Rectangle, Image*, Point, Image*, Point, Drawop);
403 extern void line(Image*, Point, Point, int, int, int, Image*, Point);
404 extern void lineop(Image*, Point, Point, int, int, int, Image*, Point, Drawop);
405 extern void poly(Image*, Point*, int, int, int, int, Image*, Point);
406 extern void polyop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
407 extern void fillpoly(Image*, Point*, int, int, Image*, Point);
408 extern void fillpolyop(Image*, Point*, int, int, Image*, Point, Drawop);
409 extern Point string(Image*, Point, Image*, Point, Font*, char*);
410 extern Point stringop(Image*, Point, Image*, Point, Font*, char*, Drawop);
411 extern Point stringn(Image*, Point, Image*, Point, Font*, char*, int);
412 extern Point stringnop(Image*, Point, Image*, Point, Font*, char*, int, Drawop);
413 extern Point runestring(Image*, Point, Image*, Point, Font*, Rune*);
414 extern Point runestringop(Image*, Point, Image*, Point, Font*, Rune*, Drawop);
415 extern Point runestringn(Image*, Point, Image*, Point, Font*, Rune*, int);
416 extern Point runestringnop(Image*, Point, Image*, Point, Font*, Rune*, int, Drawop);
417 extern Point stringbg(Image*, Point, Image*, Point, Font*, char*, Image*, Point);
418 extern Point stringbgop(Image*, Point, Image*, Point, Font*, char*, Image*, Point, Drawop);
419 extern Point stringnbg(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point);
420 extern Point stringnbgop(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point, Drawop);
421 extern Point runestringbg(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point);
422 extern Point runestringbgop(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point, Drawop);
423 extern Point runestringnbg(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point);
424 extern Point runestringnbgop(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point, Drawop);
425 extern Point _string(Image*, Point, Image*, Point, Font*, char*, Rune*, int, Rectangle, Image*, Point, Drawop);
426 extern Point stringsubfont(Image*, Point, Image*, Subfont*, char*);
427 extern int bezier(Image*, Point, Point, Point, Point, int, int, int, Image*, Point);
428 extern int bezierop(Image*, Point, Point, Point, Point, int, int, int, Image*, Point, Drawop);
429 extern int bezspline(Image*, Point*, int, int, int, int, Image*, Point);
430 extern int bezsplineop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
431 extern int bezsplinepts(Point*, int, Point**);
432 extern int fillbezier(Image*, Point, Point, Point, Point, int, Image*, Point);
433 extern int fillbezierop(Image*, Point, Point, Point, Point, int, Image*, Point, Drawop);
434 extern int fillbezspline(Image*, Point*, int, int, Image*, Point);
435 extern int fillbezsplineop(Image*, Point*, int, int, Image*, Point, Drawop);
436 extern void ellipse(Image*, Point, int, int, int, Image*, Point);
437 extern void ellipseop(Image*, Point, int, int, int, Image*, Point, Drawop);
438 extern void fillellipse(Image*, Point, int, int, Image*, Point);
439 extern void fillellipseop(Image*, Point, int, int, Image*, Point, Drawop);
440 extern void arc(Image*, Point, int, int, int, Image*, Point, int, int);
441 extern void arcop(Image*, Point, int, int, int, Image*, Point, int, int, Drawop);
442 extern void fillarc(Image*, Point, int, int, Image*, Point, int, int);
443 extern void fillarcop(Image*, Point, int, int, Image*, Point, int, int, Drawop);
444 extern void border(Image*, Rectangle, int, Image*, Point);
445 extern void borderop(Image*, Rectangle, int, Image*, Point, Drawop);
450 extern Font* openfont(Display*, char*);
451 extern Font* buildfont(Display*, char*, char*);
452 extern void freefont(Font*);
453 extern Font* mkfont(Subfont*, Rune);
454 extern int cachechars(Font*, char**, Rune**, ushort*, int, int*, char**);
455 extern void agefont(Font*);
456 extern Subfont* allocsubfont(char*, int, int, int, Fontchar*, Image*);
457 extern Subfont* lookupsubfont(Display*, char*);
458 extern void installsubfont(char*, Subfont*);
459 extern void uninstallsubfont(Subfont*);
460 extern void freesubfont(Subfont*);
461 extern Subfont* readsubfont(Display*, char*, int, int);
462 extern Subfont* readsubfonti(Display*, char*, int, Image*, int);
463 extern int writesubfont(int, Subfont*);
464 extern void _unpackinfo(Fontchar*, uchar*, int);
465 extern Point stringsize(Font*, char*);
466 extern int stringwidth(Font*, char*);
467 extern int stringnwidth(Font*, char*, int);
468 extern Point runestringsize(Font*, Rune*);
469 extern int runestringwidth(Font*, Rune*);
470 extern int runestringnwidth(Font*, Rune*, int);
471 extern Point strsubfontwidth(Subfont*, char*);
472 extern int loadchar(Font*, Rune, Cacheinfo*, int, int, char**);
473 extern char* subfontname(char*, char*, int);
474 extern Subfont* _getsubfont(Display*, char*);
475 extern Subfont* getdefont(Display*);
476 extern void lockdisplay(Display*);
477 extern void unlockdisplay(Display*);
478 extern int drawlsetrefresh(u32int, int, void*, void*);
483 extern uchar defontdata[];
484 extern int sizeofdefont;
489 * Set up by initdraw()
491 extern Display *display;
493 extern Image *screen;
494 extern Screen *_screen;
495 extern int _cursorfd;
496 extern int _drawdebug; /* set to 1 to see errors from flushimage */
497 extern void _setdrawop(Display*, Drawop);
498 extern Display *_initdisplay(void(*)(Display*,char*), char*);
500 #define BGSHORT(p) (((p)[0]<<0) | ((p)[1]<<8))
501 #define BGLONG(p) ((BGSHORT(p)<<0) | (BGSHORT(p+2)<<16))
502 #define BPSHORT(p, v) ((p)[0]=(v), (p)[1]=((v)>>8))
503 #define BPLONG(p, v) (BPSHORT(p, (v)), BPSHORT(p+2, (v)>>16))
506 * Compressed image file parameters and helper routines
508 #define NMATCH 3 /* shortest match possible */
509 #define NRUN (NMATCH+31) /* longest match possible */
510 #define NMEM 1024 /* window size */
511 #define NDUMP 128 /* maximum length of dump */
512 #define NCBLOCK 6000 /* size of compressed blocks */
513 extern void _twiddlecompressed(uchar*, int);
514 extern int _compblocksize(Rectangle, int);
516 /* XXX backwards helps; should go */
517 extern u32int drawld2chan[];
518 extern void drawsetdebug(int);
527 char *getsnarf(void);
528 void putsnarf(char*);
530 void drawtopwindow(void);
531 void drawresizewindow(Rectangle);
532 extern char *winsize;
537 int _drawmsgread(Display*, void*, int);
538 int _drawmsgwrite(Display*, void*, int);
539 int _latin1(Rune*, int);
541 int mousescrollsize(int);
543 #if defined(__cplusplus)