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

1.1     ! root        1: #include <jerq.h>
        !             2: 
        !             3: #define SHORTSIZE      16
        !             4: 
        !             5: #define outword(w)     ((*ouch)(w) < 0 ? -1 : (*ouch)((w)>>8))
        !             6: #define outpoint(p)    (outword((p).x) < 0 ? -1 : outword((p).y))
        !             7: #define outrect(r)     (outpoint((r).origin) < 0 ? -1 : outpoint((r).corner))
        !             8: 
        !             9: static Word buffer[XMAX/WORDSIZE];
        !            10: 
        !            11: static Bitmap bbuffer = { buffer, XMAX/WORDSIZE, 0, 0, XMAX, 1, };
        !            12: 
        !            13: static int ctype, count, rastwid, (*ouch)(); static short *p1;
        !            14: 
        !            15: outbitmap(bp, r, oucharg)
        !            16: Bitmap *bp; Rectangle r; int (*oucharg)();
        !            17: {
        !            18:        Rectangle rrast;
        !            19: 
        !            20:        ouch = oucharg;
        !            21: 
        !            22:        rastwid = (r.corner.x-r.origin.x+SHORTSIZE-1)/SHORTSIZE;
        !            23:        if (outword(0) < 0 || outrect(r) < 0)
        !            24:                return -1;
        !            25: 
        !            26:        rectf(&bbuffer, bbuffer.rect, F_CLR);
        !            27:        rrast=r;
        !            28:        rectf(bp, r, F_XOR);
        !            29: 
        !            30:        while (rrast.origin.y < r.corner.y) {
        !            31:                rrast.corner.y = rrast.origin.y+1;
        !            32:                rectf(bp, rrast, F_XOR);
        !            33:                bitblt(bp, rrast, &bbuffer, Pt(0,0), F_XOR);
        !            34:                if (outrast((short *)buffer) < 0) {
        !            35:                        rrast.origin.y++;
        !            36:                        rectf(bp, Rpt(rrast.origin, r.corner), F_XOR);
        !            37:                        return -1;
        !            38:                }
        !            39:                bitblt(bp, rrast, &bbuffer, Pt(0,0), F_STORE);
        !            40:                rrast.origin.y++;
        !            41:        }
        !            42:        return 0;
        !            43: }
        !            44: 
        !            45: static outrast(p2)
        !            46: register short *p2;
        !            47: {
        !            48:        short *endraster;
        !            49:        p1 = p2;
        !            50:        endraster = p2+rastwid-1;
        !            51:        do {
        !            52:                if (p1 >= p2) {
        !            53:                        p2=p1+1; count=2;
        !            54:                        ctype=(*p1 == *p2);
        !            55: 
        !            56:                } else if ((*p2 == *(p2+1)) == ctype) {
        !            57:                        if (++count >= 127) {
        !            58:                                if (outbits() < 0)
        !            59:                                        return -1;
        !            60:                                p1=p2+2;
        !            61:                        } else p2++;
        !            62: 
        !            63:                } else if (ctype) {
        !            64:                        if (outbits() < 0)
        !            65:                                return -1;
        !            66:                        p1=p2+1;
        !            67:                        ctype=0;
        !            68: 
        !            69:                } else {
        !            70:                        count--;
        !            71:                        if (outbits() < 0)
        !            72:                                return -1;
        !            73:                        p1=p2;
        !            74:                        ctype=1;
        !            75:                }
        !            76:        } while (p2 < endraster);
        !            77: 
        !            78:        if (p1 > endraster)
        !            79:                return 0;
        !            80:        if (p2 > endraster)
        !            81:                count--;
        !            82:        if (outbits() < 0)
        !            83:                return -1;
        !            84:        return 0;
        !            85: }
        !            86: 
        !            87: static outbits()
        !            88: {
        !            89:        register c; register char *pout;
        !            90:        c = count;
        !            91:        if (ctype)
        !            92:                c += 128, count=1;
        !            93:        if ((*ouch)(c) < 0)
        !            94:                return -1;
        !            95:        c = sizeof(short)*count;
        !            96:        pout = (char *)p1;
        !            97:        while (--c >= 0)
        !            98:                if ((*ouch)(*pout++) < 0)
        !            99:                        return -1;
        !           100:        return 0;
        !           101: }

unix.superglobalmegacorp.com

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