Annotation of lucent/sys/src/libgnot/gballoc.c, revision 1.1.1.1

1.1       root        1: #include <u.h>
                      2: #include <libc.h>
                      3: #include <libg.h>
                      4: #include <gnot.h>
                      5: 
                      6: #define OKRECT(r)      ((r).min.x<(r).max.x && (r).min.y<(r).max.y)
                      7: 
                      8: GBitmap *
                      9: gballoc(Rectangle r, int ldepth)
                     10: {
                     11:        long lsize;
                     12:        int wsize;      /* word size in pixels */
                     13:        GBitmap *bp;
                     14: 
                     15:        if(ldepth<0 || ldepth>3 || !OKRECT(r))
                     16:                return 0;
                     17:        wsize = 1<<(5-ldepth);  /* ldepth==0 is 32 pixels per word */
                     18:        if(r.max.x >= 0)
                     19:                lsize = (r.max.x+wsize-1)/wsize;
                     20:        else
                     21:                lsize = r.max.x/wsize;
                     22:        if(r.min.x >= 0)
                     23:                lsize -= r.min.x/wsize;
                     24:        else
                     25:                lsize -= (r.min.x-wsize+1)/wsize;
                     26:        if((bp=malloc(sizeof(GBitmap))) == 0)
                     27:                return 0;
                     28:        bp->zero = lsize*r.min.y;
                     29:        if(r.min.x >= 0)
                     30:                bp->zero += r.min.x/wsize;
                     31:        else
                     32:                bp->zero += (r.min.x-wsize+1)/wsize;
                     33:        bp->zero = -bp->zero;
                     34:        bp->width = lsize;
                     35:        bp->ldepth = ldepth;
                     36:        bp->r = r;
                     37:        bp->clipr = r;
                     38:        bp->cache = 0;
                     39:        lsize *= Dy(r);
                     40:        lsize *= sizeof(ulong);
                     41:        bp->base = malloc(lsize);
                     42:        if(bp->base == 0){
                     43:                free(bp);
                     44:                return 0;
                     45:        }
                     46:        memset(bp->base, 0, lsize);
                     47:        return bp;
                     48: }
                     49: 
                     50: void
                     51: gbfree(GBitmap *bp)
                     52: {
                     53:        if(bp){
                     54:                if(bp->base)
                     55:                        free(bp->base);
                     56:                free(bp);
                     57:        }
                     58: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.