memdraw.h 5.7 KB

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