vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

memdraw.h (6143B)


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