Annotation of researchv9/jerq/src/lib/jj/inbitmap.c, revision 1.1

1.1     ! root        1: #include <jerq.h>
        !             2: 
        !             3: #define SHORTSIZE      16
        !             4: 
        !             5: #define inpoint(pp)    (inword(&(pp)->x) < 0 ? -1 : inword(&(pp)->y))
        !             6: #define inrect(rp)     (inpoint(&(rp)->origin) < 0 ? -1 : inpoint(&(rp)->corner))
        !             7: 
        !             8: static Word buffer[XMAX/WORDSIZE];
        !             9: 
        !            10: static Bitmap bbuffer = { buffer, XMAX/WORDSIZE, 0, 0, XMAX, 1, };
        !            11: 
        !            12: static int (*inch)();
        !            13: 
        !            14: Bitmap *
        !            15: inbitmap(incharg)
        !            16: int (*incharg)();
        !            17: {
        !            18:        register Bitmap *bp;
        !            19:        register y;
        !            20:        int rastwid, dummy;
        !            21:        Rectangle r;
        !            22: 
        !            23:        inch = incharg;
        !            24: 
        !            25:        if (inword(&dummy) < 0 || inrect(&r) < 0 || (bp = balloc(r)) == 0)
        !            26:                return 0;
        !            27:        rastwid = (r.corner.x - r.origin.x + SHORTSIZE - 1)/SHORTSIZE;
        !            28:        for (y = r.origin.y; y < r.corner.y; y++) {
        !            29:                if (getrast((short *)buffer, rastwid) < 0) {
        !            30:                        bfree(bp);
        !            31:                        return 0;
        !            32:                }
        !            33:                bitblt(&bbuffer, bbuffer.rect, bp, Pt(r.origin.x, y), F_STORE);
        !            34:                if (y > r.origin.y)
        !            35:                        bitblt(bp, Rect(r.origin.x, y-1, r.corner.x, y),
        !            36:                               bp, Pt(r.origin.x, y), F_XOR);
        !            37:        }
        !            38:        return bp;
        !            39: }
        !            40: 
        !            41: static
        !            42: getrast(p, nwords)     /* receive single compressed raster */
        !            43: register short *p; int nwords;
        !            44: {
        !            45:        int count, same;
        !            46: 
        !            47:        while (nwords > 0) {
        !            48:                if ((count = (*inch)()) <= 0)
        !            49:                        return -1;
        !            50:                same = count&128; count &= 127;
        !            51:                nwords -= count;
        !            52: 
        !            53:                if (same) {
        !            54:                        if (innchars(sizeof(short), (char *)p) < 0)
        !            55:                                return -1;
        !            56:                        for (count--; count>0; count--) {
        !            57:                                *(p+1) = *p; p++;
        !            58:                        }
        !            59:                        p++;
        !            60:                } else {
        !            61:                        if (innchars(sizeof(short)*count, (char *)p) < 0)
        !            62:                                return -1;
        !            63:                        p += count;
        !            64:                }
        !            65:        }
        !            66:        return (nwords == 0 ? 0 : -1);
        !            67: }
        !            68: 
        !            69: static
        !            70: inword(wp)
        !            71: short *wp;
        !            72: {
        !            73:        register lo, hi;
        !            74:        if ((lo = (*inch)()) < 0 || (hi = (*inch)()) < 0)
        !            75:                return -1;
        !            76:        *wp = (hi << 8) | lo;
        !            77:        return 0;
        !            78: }
        !            79: 
        !            80: static
        !            81: innchars(n, p)
        !            82: register n; register char *p;
        !            83: {
        !            84:        register c;
        !            85:        while (--n >= 0)
        !            86:                if ((c = (*inch)()) < 0)
        !            87:                        return -1;
        !            88:                else
        !            89:                        *p++ = c;
        !            90:        return 0;
        !            91: }

unix.superglobalmegacorp.com

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