2 This header file is an extension to ANSI/POSIX
7 #pragma src "/sys/src/ape/lib/draw"
8 #pragma lib "/$M/lib/ape/libdraw.a"
14 typedef struct Cachefont Cachefont;
15 typedef struct Cacheinfo Cacheinfo;
16 typedef struct Cachesubf Cachesubf;
17 typedef struct Display Display;
18 typedef struct Font Font;
19 typedef struct Fontchar Fontchar;
20 typedef struct Image Image;
21 typedef struct Mouse Mouse;
22 typedef struct Point Point;
23 typedef struct Rectangle Rectangle;
24 typedef struct RGB RGB;
25 typedef struct Screen Screen;
26 typedef struct Subfont Subfont;
28 #pragma varargck type "R" Rectangle
29 #pragma varargck type "P" Point
30 extern int Rfmt(Fmt*);
31 extern int Pfmt(Fmt*);
36 DTransparent = 0x00000000, /* only useful for allocimage, memfillcolor */
43 DMagenta = 0xFF00FFFF,
45 DPaleyellow = 0xFFFFAAFF,
46 DDarkyellow = 0xEEEE9EFF,
47 DDarkgreen = 0x448844FF,
48 DPalegreen = 0xAAFFAAFF,
49 DMedgreen = 0x88CC88FF,
50 DDarkblue = 0x000055FF,
51 DPalebluegreen= 0xAAFFFFFF,
52 DPaleblue = 0x0000BBFF,
53 DBluegreen = 0x008888FF,
54 DGreygreen = 0x55AAAAFF,
55 DPalegreygreen = 0x9EEEEEFF,
56 DYellowgreen = 0x99994CFF,
57 DMedblue = 0x000099FF,
58 DGreyblue = 0x005DBBFF,
59 DPalegreyblue = 0x4993DDFF,
60 DPurpleblue = 0x8888CCFF,
62 DNotacolor = 0xFFFFFF00,
69 Displaybufsize = 8000,
81 #define NOREFRESH ((void*)-1)
92 #define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
96 /* Porter-Duff compositing operators */
105 SoverD = SinD|SoutD|DoutS,
110 DoverS = DinS|DoutS|SoutD,
112 DxorS = DoutS|SoutD, /* == SxorD */
118 * image channel descriptors
131 #define __DC(type, nbits) ((((type)&15)<<4)|((nbits)&15))
132 #define CHAN1(a,b) __DC(a,b)
133 #define CHAN2(a,b,c,d) (CHAN1((a),(b))<<8|__DC((c),(d)))
134 #define CHAN3(a,b,c,d,e,f) (CHAN2((a),(b),(c),(d))<<8|__DC((e),(f)))
135 #define CHAN4(a,b,c,d,e,f,g,h) (CHAN3((a),(b),(c),(d),(e),(f))<<8|__DC((g),(h)))
137 #define NBITS(c) ((c)&15)
138 #define TYPE(c) (((c)>>4)&15)
141 GREY1 = CHAN1(CGrey, 1),
142 GREY2 = CHAN1(CGrey, 2),
143 GREY4 = CHAN1(CGrey, 4),
144 GREY8 = CHAN1(CGrey, 8),
145 CMAP8 = CHAN1(CMap, 8),
146 RGB15 = CHAN4(CIgnore, 1, CRed, 5, CGreen, 5, CBlue, 5),
147 RGB16 = CHAN3(CRed, 5, CGreen, 6, CBlue, 5),
148 RGB24 = CHAN3(CRed, 8, CGreen, 8, CBlue, 8),
149 RGBA32 = CHAN4(CRed, 8, CGreen, 8, CBlue, 8, CAlpha, 8),
150 ARGB32 = CHAN4(CAlpha, 8, CRed, 8, CGreen, 8, CBlue, 8), /* stupid VGAs */
151 XRGB32 = CHAN4(CIgnore, 8, CRed, 8, CGreen, 8, CBlue, 8),
152 BGR24 = CHAN3(CBlue, 8, CGreen, 8, CRed, 8),
153 ABGR32 = CHAN4(CAlpha, 8, CBlue, 8, CGreen, 8, CRed, 8),
154 XBGR32 = CHAN4(CIgnore, 8, CBlue, 8, CGreen, 8, CRed, 8),
157 extern char* chantostr(char*, ulong);
158 extern ulong strtochan(char*);
159 extern int chantodepth(ulong);
173 typedef void (*Reffn)(Image*, Rectangle, void*);
177 Display *display; /* display holding data */
178 int id; /* id of system-held Screen */
179 Image *image; /* unused; for reference only */
180 Image *fill; /* color to paint behind windows */
186 int locking; /*program is using lockdisplay */
193 void (*error)(Display*, char*);
207 Subfont *defaultsubfont;
215 Display *display; /* display holding data */
216 int id; /* id of system-held Image */
217 Rectangle r; /* rectangle in data area, local coords */
218 Rectangle clipr; /* clipping region */
219 int depth; /* number of bits per pixel */
221 int repl; /* flag: data replicates to tile clipr */
222 Screen *screen; /* 0 if not a window */
223 Image *next; /* next in list of windows */
236 * given char c, Subfont *f, Fontchar *i, and Point p, one says
238 * draw(b, Rect(p.x+i->left, p.y+i->top,
239 * p.x+i->left+((i+1)->x-i->x), p.y+i->bottom),
240 * color, f->bits, Pt(i->x, i->top));
242 * to draw characters in the specified color (itself an Image) in Image b.
247 int x; /* left edge of bits */
248 uchar top; /* first non-zero scan-line */
249 uchar bottom; /* last non-zero scan-line + 1 */
250 char left; /* offset of baseline */
251 uchar width; /* width of baseline */
257 short n; /* number of chars in font */
258 uchar height; /* height of image */
259 char ascent; /* top of image to baseline */
260 Fontchar *info; /* n+1 character descriptors */
261 Image *bits; /* of font */
267 /* starting values */
269 NFCACHE = (1<<LOG2NFCACHE), /* #chars cached */
270 NFLOOK = 5, /* #chars to scan in cache */
271 NFSUBF = 2, /* #subfonts to cache */
273 MAXFCACHE = 1024+NFLOOK, /* upper limit */
274 MAXSUBF = 50, /* generous upper limit */
284 Rune min; /* lowest rune value to be taken from subfont */
285 Rune max; /* highest rune value+1 to be taken from subfont */
286 int offset; /* position in subfont of character at min */
287 char *name; /* stored in font */
288 char *subfontname; /* to access subfont */
293 ushort x; /* left edge of bits */
294 uchar width; /* width of baseline */
295 schar left; /* offset of baseline */
296 Rune value; /* value of character at this slot in cache */
302 ulong age; /* for replacement */
303 Cachefont *cf; /* font info that owns us */
304 Subfont *f; /* attached subfont */
311 short height; /* max height of image, interline spacing */
312 short ascent; /* top of image to baseline */
313 short width; /* widest so far; used in caching only */
314 short nsub; /* number of subfonts */
315 ulong age; /* increasing counter; used for LRU */
316 int maxdepth; /* maximum depth of all loaded subfonts */
317 int ncache; /* size of cache */
318 int nsubf; /* size of subfont list */
321 Cachefont **sub; /* as read from file */
325 #define Dx(r) ((r).max.x-(r).min.x)
326 #define Dy(r) ((r).max.y-(r).min.y)
335 extern Image* _allocimage(Image*, Display*, Rectangle, ulong, int, ulong, int, int);
336 extern Image* allocimage(Display*, Rectangle, ulong, int, ulong);
337 extern uchar* bufimage(Display*, int);
338 extern int bytesperline(Rectangle, int);
339 extern void closedisplay(Display*);
340 extern void drawerror(Display*, char*);
341 extern int flushimage(Display*, int);
342 extern int freeimage(Image*);
343 extern int _freeimage1(Image*);
344 extern int geninitdraw(char*, void(*)(Display*, char*), char*, char*, char*, int);
345 extern int initdraw(void(*)(Display*, char*), char*, char*);
346 extern int newwindow(char*);
347 extern Display* initdisplay(char*, char*, void(*)(Display*, char*));
348 extern int loadimage(Image*, Rectangle, uchar*, int);
349 extern int cloadimage(Image*, Rectangle, uchar*, int);
350 extern int getwindow(Display*, int);
351 extern int gengetwindow(Display*, char*, Image**, Screen**, int);
352 extern Image* readimage(Display*, int, int);
353 extern Image* creadimage(Display*, int, int);
354 extern int unloadimage(Image*, Rectangle, uchar*, int);
355 extern int wordsperline(Rectangle, int);
356 extern int writeimage(int, Image*, int);
357 extern Image* namedimage(Display*, char*);
358 extern int nameimage(Image*, char*, int);
359 extern Image* allocimagemix(Display*, ulong, ulong);
364 extern void readcolmap(Display*, RGB*);
365 extern void writecolmap(Display*, RGB*);
366 extern ulong setalpha(ulong, uchar);
371 extern Screen* allocscreen(Image*, Image*, int);
372 extern Image* _allocwindow(Image*, Screen*, Rectangle, int, ulong);
373 extern Image* allocwindow(Screen*, Rectangle, int, ulong);
374 extern void bottomnwindows(Image**, int);
375 extern void bottomwindow(Image*);
376 extern int freescreen(Screen*);
377 extern Screen* publicscreen(Display*, int, ulong);
378 extern void topnwindows(Image**, int);
379 extern void topwindow(Image*);
380 extern int originwindow(Image*, Point, Point);
385 extern Point Pt(int, int);
386 extern Rectangle Rect(int, int, int, int);
387 extern Rectangle Rpt(Point, Point);
388 extern Point addpt(Point, Point);
389 extern Point subpt(Point, Point);
390 extern Point divpt(Point, int);
391 extern Point mulpt(Point, int);
392 extern int eqpt(Point, Point);
393 extern int eqrect(Rectangle, Rectangle);
394 extern Rectangle insetrect(Rectangle, int);
395 extern Rectangle rectaddpt(Rectangle, Point);
396 extern Rectangle rectsubpt(Rectangle, Point);
397 extern Rectangle canonrect(Rectangle);
398 extern int rectXrect(Rectangle, Rectangle);
399 extern int rectinrect(Rectangle, Rectangle);
400 extern void combinerect(Rectangle*, Rectangle);
401 extern int rectclip(Rectangle*, Rectangle);
402 extern int ptinrect(Point, Rectangle);
403 extern void replclipr(Image*, int, Rectangle);
404 extern int drawreplxy(int, int, int); /* used to be drawsetxy */
405 extern Point drawrepl(Rectangle, Point);
406 extern int rgb2cmap(int, int, int);
407 extern int cmap2rgb(int);
408 extern int cmap2rgba(int);
409 extern void icossin(int, int*, int*);
410 extern void icossin2(int, int, int*, int*);
411 extern int badrect(Rectangle);
416 extern void draw(Image*, Rectangle, Image*, Image*, Point);
417 extern void drawop(Image*, Rectangle, Image*, Image*, Point, Drawop);
418 extern void gendraw(Image*, Rectangle, Image*, Point, Image*, Point);
419 extern void gendrawop(Image*, Rectangle, Image*, Point, Image*, Point, Drawop);
420 extern void line(Image*, Point, Point, int, int, int, Image*, Point);
421 extern void lineop(Image*, Point, Point, int, int, int, Image*, Point, Drawop);
422 extern void poly(Image*, Point*, int, int, int, int, Image*, Point);
423 extern void polyop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
424 extern void fillpoly(Image*, Point*, int, int, Image*, Point);
425 extern void fillpolyop(Image*, Point*, int, int, Image*, Point, Drawop);
426 extern Point string(Image*, Point, Image*, Point, Font*, char*);
427 extern Point stringop(Image*, Point, Image*, Point, Font*, char*, Drawop);
428 extern Point stringn(Image*, Point, Image*, Point, Font*, char*, int);
429 extern Point stringnop(Image*, Point, Image*, Point, Font*, char*, int, Drawop);
430 extern Point runestring(Image*, Point, Image*, Point, Font*, Rune*);
431 extern Point runestringop(Image*, Point, Image*, Point, Font*, Rune*, Drawop);
432 extern Point runestringn(Image*, Point, Image*, Point, Font*, Rune*, int);
433 extern Point runestringnop(Image*, Point, Image*, Point, Font*, Rune*, int, Drawop);
434 extern Point stringbg(Image*, Point, Image*, Point, Font*, char*, Image*, Point);
435 extern Point stringbgop(Image*, Point, Image*, Point, Font*, char*, Image*, Point, Drawop);
436 extern Point stringnbg(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point);
437 extern Point stringnbgop(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point, Drawop);
438 extern Point runestringbg(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point);
439 extern Point runestringbgop(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point, Drawop);
440 extern Point runestringnbg(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point);
441 extern Point runestringnbgop(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point, Drawop);
442 extern Point _string(Image*, Point, Image*, Point, Font*, char*, Rune*, int, Rectangle, Image*, Point, Drawop);
443 extern Point stringsubfont(Image*, Point, Image*, Subfont*, char*);
444 extern int bezier(Image*, Point, Point, Point, Point, int, int, int, Image*, Point);
445 extern int bezierop(Image*, Point, Point, Point, Point, int, int, int, Image*, Point, Drawop);
446 extern int bezspline(Image*, Point*, int, int, int, int, Image*, Point);
447 extern int bezsplineop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
448 extern int bezsplinepts(Point*, int, Point**);
449 extern int fillbezier(Image*, Point, Point, Point, Point, int, Image*, Point);
450 extern int fillbezierop(Image*, Point, Point, Point, Point, int, Image*, Point, Drawop);
451 extern int fillbezspline(Image*, Point*, int, int, Image*, Point);
452 extern int fillbezsplineop(Image*, Point*, int, int, Image*, Point, Drawop);
453 extern void ellipse(Image*, Point, int, int, int, Image*, Point);
454 extern void ellipseop(Image*, Point, int, int, int, Image*, Point, Drawop);
455 extern void fillellipse(Image*, Point, int, int, Image*, Point);
456 extern void fillellipseop(Image*, Point, int, int, Image*, Point, Drawop);
457 extern void arc(Image*, Point, int, int, int, Image*, Point, int, int);
458 extern void arcop(Image*, Point, int, int, int, Image*, Point, int, int, Drawop);
459 extern void fillarc(Image*, Point, int, int, Image*, Point, int, int);
460 extern void fillarcop(Image*, Point, int, int, Image*, Point, int, int, Drawop);
461 extern void border(Image*, Rectangle, int, Image*, Point);
462 extern void borderop(Image*, Rectangle, int, Image*, Point, Drawop);
467 extern Font* openfont(Display*, char*);
468 extern Font* buildfont(Display*, char*, char*);
469 extern void freefont(Font*);
470 extern Font* mkfont(Subfont*, Rune);
471 extern int cachechars(Font*, char**, Rune**, ushort*, int, int*, char**);
472 extern void agefont(Font*);
473 extern Subfont* allocsubfont(char*, int, int, int, Fontchar*, Image*);
474 extern Subfont* lookupsubfont(Display*, char*);
475 extern void installsubfont(char*, Subfont*);
476 extern void uninstallsubfont(Subfont*);
477 extern void freesubfont(Subfont*);
478 extern Subfont* readsubfont(Display*, char*, int, int);
479 extern Subfont* readsubfonti(Display*, char*, int, Image*, int);
480 extern int writesubfont(int, Subfont*);
481 extern void _unpackinfo(Fontchar*, uchar*, int);
482 extern Point stringsize(Font*, char*);
483 extern int stringwidth(Font*, char*);
484 extern int stringnwidth(Font*, char*, int);
485 extern Point runestringsize(Font*, Rune*);
486 extern int runestringwidth(Font*, Rune*);
487 extern int runestringnwidth(Font*, Rune*, int);
488 extern Point strsubfontwidth(Subfont*, char*);
489 extern int loadchar(Font*, Rune, Cacheinfo*, int, int, char**);
490 extern char* subfontname(char*, char*, int);
491 extern Subfont* _getsubfont(Display*, char*);
492 extern Subfont* getdefont(Display*);
493 extern void lockdisplay(Display*);
494 extern void unlockdisplay(Display*);
495 extern int drawlsetrefresh(ulong, int, void*, void*);
500 extern uchar defontdata[];
501 extern int sizeofdefont;
506 * Set up by initdraw()
508 extern Display *display;
510 extern Image *screen;
511 extern Screen *_screen;
512 extern int _cursorfd;
513 extern int _drawdebug; /* set to 1 to see errors from flushimage */
514 extern void _setdrawop(Display*, Drawop);
516 #define BGSHORT(p) (((p)[0]<<0) | ((p)[1]<<8))
517 #define BGLONG(p) ((BGSHORT(p)<<0) | (BGSHORT(p+2)<<16))
518 #define BPSHORT(p, v) ((p)[0]=(v), (p)[1]=((v)>>8))
519 #define BPLONG(p, v) (BPSHORT(p, (v)), BPSHORT(p+2, (v)>>16))
522 * Compressed image file parameters and helper routines
524 #define NMATCH 3 /* shortest match possible */
525 #define NRUN (NMATCH+31) /* longest match possible */
526 #define NMEM 1024 /* window size */
527 #define NDUMP 128 /* maximum length of dump */
528 #define NCBLOCK 6000 /* size of compressed blocks */
529 extern void _twiddlecompressed(uchar*, int);
530 extern int _compblocksize(Rectangle, int);
532 /* XXX backwards helps; should go */
533 extern ulong drawld2chan[];
534 extern void drawsetdebug(int);