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