| 
    #include <u.h> 
    #include <libc.h> 
    #include <draw.h> 
     
    typedef 
    struct Image 
    { 
    
     |   | 
        Display     *display; /* display holding data */ 
        int          id;          /* id of system–held Image */ 
        Rectangle r;           /* rectangle in data area, local coords */ 
        Rectangle clipr;      /* clipping region */ 
        ulong       chan;       /* pixel channel format descriptor */ 
        int          depth;      /* number of bits per pixel */ 
        int          repl;       /* flag: data replicates to tile clipr */ 
        Screen      *screen;    /* 0 if not a window */ 
        Image       *next;      /* next in list of windows */ 
        
     |   
    } Image; 
      
    typedef enum 
    { 
    
     |   | 
        /* Porter–Duff compositing operators */ 
        Clear       = 0, 
        SinD = 8, 
        DinS = 4, 
        SoutD       = 2, 
        DoutS       = 1, 
        S           = SinD|SoutD, 
        SoverD      = SinD|SoutD|DoutS, 
        SatopD      = SinD|DoutS, 
        SxorD       = SoutD|DoutS, 
        D           = DinS|DoutS, 
        DoverS      = DinS|DoutS|SoutD, 
        DatopS      = DinS|SoutD, 
        DxorS       = DoutS|SoutD, /* == SxorD */ 
        Ncomp = 12, 
        
     |   
    } Drawop; 
      
    void    draw(Image *dst, Rectangle r, Image *src, 
     
    
    
     
    void    drawop(Image *dst, Rectangle r, Image *src, 
     
     |   | 
        
         |   | 
            Image *mask, Point p, Drawop op) 
            
         |   
        
     |   
    
    
    void    gendraw(Image *dst, Rectangle r, Image *src, Point sp, 
     
    
    
    
    void    gendrawop(Image *dst, Rectangle r, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Image *mask, Point mp, Drawop op) 
            
         |   
        
     |   
    
    
    int     drawreplxy(int min, int max, int x) 
     
    Point drawrepl(Rectangle r, Point p) 
      
    void    replclipr(Image *i, int repl, Rectangle clipr) 
      
    void    line(Image *dst, Point p0, Point p1, int end0, int end1, 
     
     |   | 
        
         |   | 
            int radius, Image *src, Point sp) 
            
         |   
        
     |   
    
     
    void    lineop(Image *dst, Point p0, Point p1, int end0, int end1, 
     
     |   | 
        
         |   | 
            int radius, Image *src, Point sp, Drawop op) 
            
         |   
        
     |   
    
    
    void    poly(Image *dst, Point *p, int np, int end0, int end1, 
     
     |   | 
        
         |   | 
            int radius, Image *src, Point sp) 
            
         |   
        
     |   
    
    
    void    polyop(Image *dst, Point *p, int np, int end0, int end1, 
     
     |   | 
        
         |   | 
            int radius, Image *src, Point sp, Drawop op) 
            
         |   
        
     |   
    
    
    void    fillpoly(Image *dst, Point *p, int np, int wind, 
     
    
    
    
    void    fillpolyop(Image *dst, Point *p, int np, int wind, 
     
     |   | 
        
         |   | 
            Image *src, Point sp, Drawop op) 
            
         |   
        
     |   
    
    
    int     bezier(Image *dst, Point p0, Point p1, Point p2, Point p3, 
     
     |   | 
        
         |   | 
            int end0, int end1, int radius, Image *src, Point sp) 
            
         |   
        
     |   
    
    
    int     bezierop(Image *dst, Point p0, Point p1, Point p2, Point p3, 
     
     |   | 
        
         |   | 
            int end0, int end1, int radius, Image *src, Point sp, 
             Drawop op) 
            
         |   
        
     |   
    
    
    int     bezspline(Image *dst, Point *pt, int npt, int end0, int end1, 
     
     |   | 
        
         |   | 
            int radius, Image *src, Point sp) 
            
         |   
        
     |   
    
    
    int     bezsplineop(Image *dst, Point *pt, int npt, int end0, int
    end1, 
     
     |   | 
        
         |   | 
            int radius, Image *src, Point sp, Drawop op) 
            
         |   
        
     |   
    
    
    int     bezsplinepts(Point *pt, int npt, Point **pp) 
     
    int     fillbezier(Image *dst, Point p0, Point p1, Point p2, Point
    p3, 
     
     |   | 
        
         |   | 
            int w, Image *src, Point sp) 
            
         |   
        
     |   
    
     
    int     fillbezierop(Image *dst, Point p0, Point p1, Point p2, Point
    p3, 
     
     |   | 
        
         |   | 
            int w, Image *src, Point sp, Drawop op) 
            
         |   
        
     |   
    
    
    int     fillbezspline(Image *dst, Point *pt, int npt, int w, 
     
    
    
    
    int     fillbezsplineop(Image *dst, Point *pt, int npt, int w, 
     
     |   | 
        
         |   | 
            Image *src, Point sp, Drawop op) 
            
         |   
        
     |   
    
    
    void    ellipse(Image *dst, Point c, int a, int b, int thick, 
     
    
    
    
    void    ellipseop(Image *dst, Point c, int a, int b, int thick, 
     
     |   | 
        
         |   | 
            Image *src, Point sp, Drawop op) 
            
         |   
        
     |   
    
    
    void    fillellipse(Image *dst, Point c, int a, int b, 
     
    
    
    
    void    fillellipseop(Image *dst, Point c, int a, int b, 
     
     |   | 
        
         |   | 
            Image *src, Point sp, Drawop op) 
            
         |   
        
     |   
    
    
    void    arc(Image *dst, Point c, int a, int b, int thick, 
     
     |   | 
        
         |   | 
            Image *src, Point sp, int alpha, int phi) 
            
         |   
        
     |   
    
    
    void    arcop(Image *dst, Point c, int a, int b, int thick, 
     
     |   | 
        
         |   | 
            Image *src, Point sp, int alpha, int phi, Drawop op) 
            
         |   
        
     |   
    
    
    void    fillarc(Image *dst, Point c, int a, int b, Image *src, 
     
     |   | 
        
         |   | 
            Point sp, int alpha, int phi) 
            
         |   
        
     |   
    
    
    void    fillarcop(Image *dst, Point c, int a, int b, Image *src, 
     
     |   | 
        
         |   | 
            Point sp, int alpha, int phi, Drawop op) 
            
         |   
        
     |   
    
    
    int     icossin(int deg, int *cosp, int *sinp) 
     
    int     icossin2(int x, int y, int *cosp, int *sinp) 
      
    void    border(Image *dst, Rectangle r, int i, Image *color, Point
    sp) 
      
    Point string(Image *dst, Point p, Image *src, Point sp, 
     
    
    
     
    Point stringop(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, char *s, Drawop op) 
            
         |   
        
     |   
    
    
    Point stringn(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, char *s, int len) 
            
         |   
        
     |   
    
    
    Point stringnop(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, char *s, int len, Drawop op) 
            
         |   
        
     |   
    
    
    Point runestring(Image *dst, Point p, Image *src, Point sp, 
     
    
    
    
    Point runestringop(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, Rune *r, Drawop op) 
            
         |   
        
     |   
    
    
    Point runestringn(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, Rune *r, int len) 
            
         |   
        
     |   
    
    
    Point runestringnop(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, Rune *r, int len, Drawop op) 
            
         |   
        
     |   
    
    
    Point stringbg(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, char *s, Image *bg, Point bgp) 
            
         |   
        
     |   
    
    
    Point stringbgop(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, char *s, Image *bg, Point bgp, Drawop op) 
            
         |   
        
     |   
    
    
    Point stringnbg(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, char *s, int len, Image *bg, Point bgp) 
            
         |   
        
     |   
    
    
    Point stringnbgop(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, char *s, int len, Image *bg, Point bgp, Drawop op) 
            
         |   
        
     |   
    
    
    Point runestringbg(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, Rune *r, Image *bg, Point bgp) 
            
         |   
        
     |   
    
    
    Point runestringbgop(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, Rune *r, Image *bg, Point bgp, Drawop op) 
            
         |   
        
     |   
    
    
    Point runestringnbg(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, Rune *r, int len, Image *bg, Point bgp) 
            
         |   
        
     |   
    
    
    Point runestringnbgop(Image *dst, Point p, Image *src, Point sp, 
     
     |   | 
        
         |   | 
            Font *f, Rune *r, int len, Image *bg, Point bgp, Drawop op) 
            
         |   
        
     |   
    
    
    Point _string(Image *dst, Point p, Image *src, 
     
     |   | 
        
         |   | 
            Point sp, Font *f, char *s, Rune *r, int len, 
             Rectangle clipr, Image *bg, Point bgp, Drawop op) 
            
         |   
        
     |   
    
    
    void    drawsetdebug(int on) 
     
    enum 
    { 
    
     |   | 
        
         |   | 
            /* line ends */ 
            Endsquare    = 0, 
            Enddisc       = 1, 
            Endarrow = 2, 
            Endmask       = 0x1F 
            
         |   
        
     |   
    }; 
      
    #define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23)) 
    
  |