1 #pragma src "/sys/src/libdraw"
2 #pragma lib "libdraw.a"
4 typedef struct Cachefont Cachefont;
5 typedef struct Cacheinfo Cacheinfo;
6 typedef struct Cachesubf Cachesubf;
7 typedef struct Display Display;
8 typedef struct Font Font;
9 typedef struct Fontchar Fontchar;
10 typedef struct Image Image;
11 typedef struct Mouse Mouse;
12 typedef struct Point Point;
13 typedef struct Rectangle Rectangle;
14 typedef struct RGB RGB;
15 typedef struct Screen Screen;
16 typedef struct Subfont Subfont;
18 #pragma incomplete Mouse
20 #pragma varargck type "R" Rectangle
21 #pragma varargck type "P" Point
22 extern int Rfmt(Fmt*);
23 extern int Pfmt(Fmt*);
28 DTransparent = 0x00000000, /* only useful for allocimage, memfillcolor */
35 DMagenta = 0xFF00FFFF,
37 DPaleyellow = 0xFFFFAAFF,
38 DDarkyellow = 0xEEEE9EFF,
39 DDarkgreen = 0x448844FF,
40 DPalegreen = 0xAAFFAAFF,
41 DMedgreen = 0x88CC88FF,
42 DDarkblue = 0x000055FF,
43 DPalebluegreen= 0xAAFFFFFF,
44 DPaleblue = 0x0000BBFF,
45 DBluegreen = 0x008888FF,
46 DGreygreen = 0x55AAAAFF,
47 DPalegreygreen = 0x9EEEEEFF,
48 DYellowgreen = 0x99994CFF,
49 DMedblue = 0x000099FF,
50 DGreyblue = 0x005DBBFF,
51 DPalegreyblue = 0x4993DDFF,
52 DPurpleblue = 0x8888CCFF,
54 DNotacolor = 0xFFFFFF00,
61 Displaybufsize = 8000,
73 #define NOREFRESH ((void*)-1)
84 #define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
88 /* Porter-Duff compositing operators */
97 SoverD = SinD|SoutD|DoutS,
102 DoverS = DinS|DoutS|SoutD,
104 DxorS = DoutS|SoutD, /* == SxorD */
110 * image channel descriptors
123 #define __DC(type, nbits) ((((type)&15)<<4)|((nbits)&15))
124 #define CHAN1(a,b) __DC(a,b)
125 #define CHAN2(a,b,c,d) (CHAN1((a),(b))<<8|__DC((c),(d)))
126 #define CHAN3(a,b,c,d,e,f) (CHAN2((a),(b),(c),(d))<<8|__DC((e),(f)))
127 #define CHAN4(a,b,c,d,e,f,g,h) (CHAN3((a),(b),(c),(d),(e),(f))<<8|__DC((g),(h)))
129 #define NBITS(c) ((c)&15)
130 #define TYPE(c) (((c)>>4)&15)
133 GREY1 = CHAN1(CGrey, 1),
134 GREY2 = CHAN1(CGrey, 2),
135 GREY4 = CHAN1(CGrey, 4),
136 GREY8 = CHAN1(CGrey, 8),
137 CMAP8 = CHAN1(CMap, 8),
138 RGB15 = CHAN4(CIgnore, 1, CRed, 5, CGreen, 5, CBlue, 5),
139 RGB16 = CHAN3(CRed, 5, CGreen, 6, CBlue, 5),
140 RGB24 = CHAN3(CRed, 8, CGreen, 8, CBlue, 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 BGR24 = CHAN3(CBlue, 8, CGreen, 8, CRed, 8),
145 ABGR32 = CHAN4(CAlpha, 8, CBlue, 8, CGreen, 8, CRed, 8),
146 XBGR32 = CHAN4(CIgnore, 8, CBlue, 8, CGreen, 8, CRed, 8),
149 extern char* chantostr(char*, ulong);
150 extern ulong strtochan(char*);
151 extern int chantodepth(ulong);
165 typedef void (*Reffn)(Image*, Rectangle, void*);
169 Display *display; /* display holding data */
170 int id; /* id of system-held Screen */
171 Image *image; /* unused; for reference only */
172 Image *fill; /* color to paint behind windows */
178 int locking; /*program is using lockdisplay */
185 void (*error)(Display*, char*);
199 Subfont *defaultsubfont;
207 Display *display; /* display holding data */
208 int id; /* id of system-held Image */
209 Rectangle r; /* rectangle in data area, local coords */
210 Rectangle clipr; /* clipping region */
211 int depth; /* number of bits per pixel */
213 int repl; /* flag: data replicates to tile clipr */
214 Screen *screen; /* 0 if not a window */
215 Image *next; /* next in list of windows */
228 * given char c, Subfont *f, Fontchar *i, and Point p, one says
230 * draw(b, Rect(p.x+i->left, p.y+i->top,
231 * p.x+i->left+((i+1)->x-i->x), p.y+i->bottom),
232 * color, f->bits, Pt(i->x, i->top));
234 * to draw characters in the specified color (itself an Image) in Image b.
239 int x; /* left edge of bits */
240 uchar top; /* first non-zero scan-line */
241 uchar bottom; /* last non-zero scan-line + 1 */
242 char left; /* offset of baseline */
243 uchar width; /* width of baseline */
249 short n; /* number of chars in font */
250 uchar height; /* height of image */
251 char ascent; /* top of image to baseline */
252 Fontchar *info; /* n+1 character descriptors */
253 Image *bits; /* of font */
259 /* starting values */
261 NFCACHE = (1<<LOG2NFCACHE), /* #chars cached */
262 NFLOOK = 5, /* #chars to scan in cache */
263 NFSUBF = 2, /* #subfonts to cache */
265 MAXFCACHE = 1024+NFLOOK, /* upper limit */
266 MAXSUBF = 50, /* generous upper limit */
276 Rune min; /* lowest rune value to be taken from subfont */
277 Rune max; /* highest rune value+1 to be taken from subfont */
278 int offset; /* position in subfont of character at min */
279 char *name; /* stored in font */
280 char *subfontname; /* to access subfont */
285 ushort x; /* left edge of bits */
286 uchar width; /* width of baseline */
287 schar left; /* offset of baseline */
288 Rune value; /* value of character at this slot in cache */
294 ulong age; /* for replacement */
295 Cachefont *cf; /* font info that owns us */
296 Subfont *f; /* attached subfont */
303 short height; /* max height of image, interline spacing */
304 short ascent; /* top of image to baseline */
305 short width; /* widest so far; used in caching only */
306 short nsub; /* number of subfonts */
307 ulong age; /* increasing counter; used for LRU */
308 int maxdepth; /* maximum depth of all loaded subfonts */
309 int ncache; /* size of cache */
310 int nsubf; /* size of subfont list */
313 Cachefont **sub; /* as read from file */
317 #define Dx(r) ((r).max.x-(r).min.x)
318 #define Dy(r) ((r).max.y-(r).min.y)
323 extern int mousescrollsize(int);
328 extern Image* _allocimage(Image*, Display*, Rectangle, ulong, int, ulong, int, int);
329 extern Image* allocimage(Display*, Rectangle, ulong, int, ulong);
330 extern uchar* bufimage(Display*, int);
331 extern int bytesperline(Rectangle, int);
332 extern void closedisplay(Display*);
333 extern void drawerror(Display*, char*);
334 extern int flushimage(Display*, int);
335 extern int freeimage(Image*);
336 extern int _freeimage1(Image*);
337 extern int geninitdraw(char*, void(*)(Display*, char*), char*, char*, char*, int);
338 extern int initdraw(void(*)(Display*, char*), char*, char*);
339 extern int newwindow(char*);
340 extern Display* initdisplay(char*, char*, void(*)(Display*, char*));
341 extern int loadimage(Image*, Rectangle, uchar*, int);
342 extern int cloadimage(Image*, Rectangle, uchar*, int);
343 extern int getwindow(Display*, int);
344 extern int gengetwindow(Display*, char*, Image**, Screen**, int);
345 extern Image* readimage(Display*, int, int);
346 extern Image* creadimage(Display*, int, int);
347 extern int unloadimage(Image*, Rectangle, uchar*, int);
348 extern int wordsperline(Rectangle, int);
349 extern int writeimage(int, Image*, int);
350 extern Image* namedimage(Display*, char*);
351 extern int nameimage(Image*, char*, int);
352 extern Image* allocimagemix(Display*, ulong, ulong);
357 extern void readcolmap(Display*, RGB*);
358 extern void writecolmap(Display*, RGB*);
359 extern ulong setalpha(ulong, uchar);
364 extern Screen* allocscreen(Image*, Image*, int);
365 extern Image* _allocwindow(Image*, Screen*, Rectangle, int, ulong);
366 extern Image* allocwindow(Screen*, Rectangle, int, ulong);
367 extern void bottomnwindows(Image**, int);
368 extern void bottomwindow(Image*);
369 extern int freescreen(Screen*);
370 extern Screen* publicscreen(Display*, int, ulong);
371 extern void topnwindows(Image**, int);
372 extern void topwindow(Image*);
373 extern int originwindow(Image*, Point, Point);
378 extern Point Pt(int, int);
379 extern Rectangle Rect(int, int, int, int);
380 extern Rectangle Rpt(Point, Point);
381 extern Point addpt(Point, Point);
382 extern Point subpt(Point, Point);
383 extern Point divpt(Point, int);
384 extern Point mulpt(Point, int);
385 extern int eqpt(Point, Point);
386 extern int eqrect(Rectangle, Rectangle);
387 extern Rectangle insetrect(Rectangle, int);
388 extern Rectangle rectaddpt(Rectangle, Point);
389 extern Rectangle rectsubpt(Rectangle, Point);
390 extern Rectangle canonrect(Rectangle);
391 extern int rectXrect(Rectangle, Rectangle);
392 extern int rectinrect(Rectangle, Rectangle);
393 extern void combinerect(Rectangle*, Rectangle);
394 extern int rectclip(Rectangle*, Rectangle);
395 extern int ptinrect(Point, Rectangle);
396 extern void replclipr(Image*, int, Rectangle);
397 extern int drawreplxy(int, int, int); /* used to be drawsetxy */
398 extern Point drawrepl(Rectangle, Point);
399 extern int rgb2cmap(int, int, int);
400 extern int cmap2rgb(int);
401 extern int cmap2rgba(int);
402 extern void icossin(int, int*, int*);
403 extern void icossin2(int, int, int*, int*);
408 extern void draw(Image*, Rectangle, Image*, Image*, Point);
409 extern void drawop(Image*, Rectangle, Image*, Image*, Point, Drawop);
410 extern void gendraw(Image*, Rectangle, Image*, Point, Image*, Point);
411 extern void gendrawop(Image*, Rectangle, Image*, Point, Image*, Point, Drawop);
412 extern void line(Image*, Point, Point, int, int, int, Image*, Point);
413 extern void lineop(Image*, Point, Point, int, int, int, Image*, Point, Drawop);
414 extern void poly(Image*, Point*, int, int, int, int, Image*, Point);
415 extern void polyop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
416 extern void fillpoly(Image*, Point*, int, int, Image*, Point);
417 extern void fillpolyop(Image*, Point*, int, int, Image*, Point, Drawop);
418 extern Point string(Image*, Point, Image*, Point, Font*, char*);
419 extern Point stringop(Image*, Point, Image*, Point, Font*, char*, Drawop);
420 extern Point stringn(Image*, Point, Image*, Point, Font*, char*, int);
421 extern Point stringnop(Image*, Point, Image*, Point, Font*, char*, int, Drawop);
422 extern Point runestring(Image*, Point, Image*, Point, Font*, Rune*);
423 extern Point runestringop(Image*, Point, Image*, Point, Font*, Rune*, Drawop);
424 extern Point runestringn(Image*, Point, Image*, Point, Font*, Rune*, int);
425 extern Point runestringnop(Image*, Point, Image*, Point, Font*, Rune*, int, Drawop);
426 extern Point stringbg(Image*, Point, Image*, Point, Font*, char*, Image*, Point);
427 extern Point stringbgop(Image*, Point, Image*, Point, Font*, char*, Image*, Point, Drawop);
428 extern Point stringnbg(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point);
429 extern Point stringnbgop(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point, Drawop);
430 extern Point runestringbg(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point);
431 extern Point runestringbgop(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point, Drawop);
432 extern Point runestringnbg(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point);
433 extern Point runestringnbgop(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point, Drawop);
434 extern Point _string(Image*, Point, Image*, Point, Font*, char*, Rune*, int, Rectangle, Image*, Point, Drawop);
435 extern Point stringsubfont(Image*, Point, Image*, Subfont*, char*);
436 extern int bezier(Image*, Point, Point, Point, Point, int, int, int, Image*, Point);
437 extern int bezierop(Image*, Point, Point, Point, Point, int, int, int, Image*, Point, Drawop);
438 extern int bezspline(Image*, Point*, int, int, int, int, Image*, Point);
439 extern int bezsplineop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
440 extern int bezsplinepts(Point*, int, Point**);
441 extern int fillbezier(Image*, Point, Point, Point, Point, int, Image*, Point);
442 extern int fillbezierop(Image*, Point, Point, Point, Point, int, Image*, Point, Drawop);
443 extern int fillbezspline(Image*, Point*, int, int, Image*, Point);
444 extern int fillbezsplineop(Image*, Point*, int, int, Image*, Point, Drawop);
445 extern void ellipse(Image*, Point, int, int, int, Image*, Point);
446 extern void ellipseop(Image*, Point, int, int, int, Image*, Point, Drawop);
447 extern void fillellipse(Image*, Point, int, int, Image*, Point);
448 extern void fillellipseop(Image*, Point, int, int, Image*, Point, Drawop);
449 extern void arc(Image*, Point, int, int, int, Image*, Point, int, int);
450 extern void arcop(Image*, Point, int, int, int, Image*, Point, int, int, Drawop);
451 extern void fillarc(Image*, Point, int, int, Image*, Point, int, int);
452 extern void fillarcop(Image*, Point, int, int, Image*, Point, int, int, Drawop);
453 extern void border(Image*, Rectangle, int, Image*, Point);
454 extern void borderop(Image*, Rectangle, int, Image*, Point, Drawop);
459 extern Font* openfont(Display*, char*);
460 extern Font* buildfont(Display*, char*, char*);
461 extern void freefont(Font*);
462 extern Font* mkfont(Subfont*, Rune);
463 extern int cachechars(Font*, char**, Rune**, ushort*, int, int*, char**);
464 extern void agefont(Font*);
465 extern Subfont* allocsubfont(char*, int, int, int, Fontchar*, Image*);
466 extern Subfont* lookupsubfont(Display*, char*);
467 extern void installsubfont(char*, Subfont*);
468 extern void uninstallsubfont(Subfont*);
469 extern void freesubfont(Subfont*);
470 extern Subfont* readsubfont(Display*, char*, int, int);
471 extern Subfont* readsubfonti(Display*, char*, int, Image*, int);
472 extern int writesubfont(int, Subfont*);
473 extern void _unpackinfo(Fontchar*, uchar*, int);
474 extern Point stringsize(Font*, char*);
475 extern int stringwidth(Font*, char*);
476 extern int stringnwidth(Font*, char*, int);
477 extern Point runestringsize(Font*, Rune*);
478 extern int runestringwidth(Font*, Rune*);
479 extern int runestringnwidth(Font*, Rune*, int);
480 extern Point strsubfontwidth(Subfont*, char*);
481 extern int loadchar(Font*, Rune, Cacheinfo*, int, int, char**);
482 extern char* subfontname(char*, char*, int);
483 extern Subfont* _getsubfont(Display*, char*);
484 extern Subfont* getdefont(Display*);
485 extern void lockdisplay(Display*);
486 extern void unlockdisplay(Display*);
487 extern int drawlsetrefresh(ulong, int, void*, void*);
492 extern uchar defontdata[];
493 extern int sizeofdefont;
498 * Set up by initdraw()
500 extern Display *display;
502 extern Image *screen;
503 extern Screen *_screen;
504 extern int _cursorfd;
505 extern int _drawdebug; /* set to 1 to see errors from flushimage */
506 extern void _setdrawop(Display*, Drawop);
508 #define BGSHORT(p) (((p)[0]<<0) | ((p)[1]<<8))
509 #define BGLONG(p) ((BGSHORT(p)<<0) | (BGSHORT(p+2)<<16))
510 #define BPSHORT(p, v) ((p)[0]=(v), (p)[1]=((v)>>8))
511 #define BPLONG(p, v) (BPSHORT(p, (v)), BPSHORT(p+2, (v)>>16))
514 * Compressed image file parameters and helper routines
516 #define NMATCH 3 /* shortest match possible */
517 #define NRUN (NMATCH+31) /* longest match possible */
518 #define NMEM 1024 /* window size */
519 #define NDUMP 128 /* maximum length of dump */
520 #define NCBLOCK 6000 /* size of compressed blocks */
521 extern void _twiddlecompressed(uchar*, int);
522 extern int _compblocksize(Rectangle, int);
524 /* XXX backwards helps; should go */
525 // extern int log2[]; /* was used by libmemlayer/line.c */
526 extern ulong drawld2chan[];
527 extern void drawsetdebug(int);