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