memdraw.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #pragma src "/sys/src/libmemdraw"
  2. #pragma lib "libmemdraw.a"
  3. typedef struct Memimage Memimage;
  4. typedef struct Memdata Memdata;
  5. typedef struct Memsubfont Memsubfont;
  6. typedef struct Memlayer Memlayer;
  7. typedef struct Memcmap Memcmap;
  8. typedef struct Memdrawparam Memdrawparam;
  9. /*
  10. * Memdata is allocated from main pool, but .data from the image pool.
  11. * Memdata is allocated separately to permit patching its pointer after
  12. * compaction when windows share the image data.
  13. * The first word of data is a back pointer to the Memdata, to find
  14. * The word to patch.
  15. */
  16. struct Memdata
  17. {
  18. ulong *base; /* allocated data pointer */
  19. uchar *bdata; /* pointer to first byte of actual data; word-aligned */
  20. int ref; /* number of Memimages using this data */
  21. void* imref;
  22. int allocd; /* is this malloc'd? */
  23. };
  24. enum {
  25. Frepl = 1<<0, /* is replicated */
  26. Fsimple = 1<<1, /* is 1x1 */
  27. Fgrey = 1<<2, /* is grey */
  28. Falpha = 1<<3, /* has explicit alpha */
  29. Fcmap = 1<<4, /* has cmap channel */
  30. Fbytes = 1<<5, /* has only 8-bit channels */
  31. };
  32. struct Memimage
  33. {
  34. Rectangle r; /* rectangle in data area, local coords */
  35. Rectangle clipr; /* clipping region */
  36. int depth; /* number of bits of storage per pixel */
  37. int nchan; /* number of channels */
  38. ulong chan; /* channel descriptions */
  39. Memcmap *cmap;
  40. Memdata *data; /* pointer to data; shared by windows in this image */
  41. int zero; /* data->bdata+zero==&byte containing (0,0) */
  42. ulong width; /* width in words of a single scan line */
  43. Memlayer *layer; /* nil if not a layer*/
  44. ulong flags;
  45. int shift[NChan];
  46. int mask[NChan];
  47. int nbits[NChan];
  48. };
  49. struct Memcmap
  50. {
  51. uchar cmap2rgb[3*256];
  52. uchar rgb2cmap[16*16*16];
  53. };
  54. /*
  55. * Subfonts
  56. *
  57. * given char c, Subfont *f, Fontchar *i, and Point p, one says
  58. * i = f->info+c;
  59. * draw(b, Rect(p.x+i->left, p.y+i->top,
  60. * p.x+i->left+((i+1)->x-i->x), p.y+i->bottom),
  61. * color, f->bits, Pt(i->x, i->top));
  62. * p.x += i->width;
  63. * to draw characters in the specified color (itself a Memimage) in Memimage b.
  64. */
  65. struct Memsubfont
  66. {
  67. char *name;
  68. short n; /* number of chars in font */
  69. uchar height; /* height of bitmap */
  70. char ascent; /* top of bitmap to baseline */
  71. Fontchar *info; /* n+1 character descriptors */
  72. Memimage *bits; /* of font */
  73. };
  74. /*
  75. * Encapsulated parameters and information for sub-draw routines.
  76. */
  77. enum {
  78. Simplesrc=1<<0,
  79. Simplemask=1<<1,
  80. Replsrc=1<<2,
  81. Replmask=1<<3,
  82. Fullmask=1<<4,
  83. };
  84. struct Memdrawparam
  85. {
  86. Memimage *dst;
  87. Rectangle r;
  88. Memimage *src;
  89. Rectangle sr;
  90. Memimage *mask;
  91. Rectangle mr;
  92. int op;
  93. ulong state;
  94. ulong mval; /* if Simplemask, the mask pixel in mask format */
  95. ulong mrgba; /* mval in rgba */
  96. ulong sval; /* if Simplesrc, the source pixel in src format */
  97. ulong srgba; /* sval in rgba */
  98. ulong sdval; /* sval in dst format */
  99. };
  100. /*
  101. * Memimage management
  102. */
  103. extern Memimage* allocmemimage(Rectangle, ulong);
  104. extern Memimage* allocmemimaged(Rectangle, ulong, Memdata*);
  105. extern Memimage* readmemimage(int);
  106. extern Memimage* creadmemimage(int);
  107. extern int writememimage(int, Memimage*);
  108. extern void freememimage(Memimage*);
  109. extern int loadmemimage(Memimage*, Rectangle, uchar*, int);
  110. extern int cloadmemimage(Memimage*, Rectangle, uchar*, int);
  111. extern int unloadmemimage(Memimage*, Rectangle, uchar*, int);
  112. extern ulong* wordaddr(Memimage*, Point);
  113. extern uchar* byteaddr(Memimage*, Point);
  114. extern int drawclip(Memimage*, Rectangle*, Memimage*, Point*, Memimage*, Point*, Rectangle*, Rectangle*);
  115. extern void memfillcolor(Memimage*, ulong);
  116. extern int memsetchan(Memimage*, ulong);
  117. /*
  118. * Graphics
  119. */
  120. extern void memdraw(Memimage*, Rectangle, Memimage*, Point, Memimage*, Point, int);
  121. extern void memline(Memimage*, Point, Point, int, int, int, Memimage*, Point, int);
  122. extern void mempoly(Memimage*, Point*, int, int, int, int, Memimage*, Point, int);
  123. extern void memfillpoly(Memimage*, Point*, int, int, Memimage*, Point, int);
  124. extern void _memfillpolysc(Memimage*, Point*, int, int, Memimage*, Point, int, int, int, int);
  125. extern void memimagedraw(Memimage*, Rectangle, Memimage*, Point, Memimage*, Point, int);
  126. extern int hwdraw(Memdrawparam*);
  127. extern void memimageline(Memimage*, Point, Point, int, int, int, Memimage*, Point, int);
  128. extern void _memimageline(Memimage*, Point, Point, int, int, int, Memimage*, Point, Rectangle, int);
  129. extern Point memimagestring(Memimage*, Point, Memimage*, Point, Memsubfont*, char*);
  130. extern void memellipse(Memimage*, Point, int, int, int, Memimage*, Point, int);
  131. extern void memarc(Memimage*, Point, int, int, int, Memimage*, Point, int, int, int);
  132. extern Rectangle memlinebbox(Point, Point, int, int, int);
  133. extern int memlineendsize(int);
  134. extern void _memmkcmap(void);
  135. extern void memimageinit(void);
  136. /*
  137. * Subfont management
  138. */
  139. extern Memsubfont* allocmemsubfont(char*, int, int, int, Fontchar*, Memimage*);
  140. extern Memsubfont* openmemsubfont(char*);
  141. extern void freememsubfont(Memsubfont*);
  142. extern Point memsubfontwidth(Memsubfont*, char*);
  143. extern Memsubfont* getmemdefont(void);
  144. /*
  145. * Predefined
  146. */
  147. extern Memimage* memwhite;
  148. extern Memimage* memblack;
  149. extern Memimage* memopaque;
  150. extern Memimage* memtransparent;
  151. extern Memcmap *memdefcmap;
  152. /*
  153. * Kernel interface
  154. */
  155. void memimagemove(void*, void*);
  156. /*
  157. * Kernel cruft
  158. */
  159. extern void rdb(void);
  160. extern int iprint(char*, ...);
  161. #pragma varargck argpos iprint 1
  162. extern int drawdebug;
  163. /*
  164. * doprint interface: numbconv bit strings
  165. */
  166. #pragma varargck type "llb" vlong
  167. #pragma varargck type "llb" uvlong
  168. #pragma varargck type "lb" long
  169. #pragma varargck type "lb" ulong
  170. #pragma varargck type "b" int
  171. #pragma varargck type "b" uint