1
0

memdraw.h 5.5 KB

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