Annotation of researchv9/jtools/src/blitblt/sendbitmap.c, revision 1.1

1.1     ! root        1: #include <jerq.h>
        !             2: #include <stdio.h>
        !             3: 
        !             4: #ifdef SUNTOOLS
        !             5: #undef F_STORE
        !             6: #define        F_STORE (PIX_DONTCLIP|PIX_SRC)
        !             7: #endif SUNTOOLS
        !             8: 
        !             9: #define SHORTSIZE      16
        !            10: #define SHORT          short
        !            11: 
        !            12: #define sendword(w)    (sendch(w&255),sendch((w>>8)&255))
        !            13: 
        !            14: SHORT buffer[2048/SHORTSIZE], raster[2048/SHORTSIZE];  /* Room to spare */
        !            15: 
        !            16: static int ctype, count; static SHORT *p1, *endraster;
        !            17: FILE *filep, *popen();
        !            18: 
        !            19: sendbitmap(bp,r,filnam)
        !            20: Bitmap *bp; Rectangle r; char *filnam;
        !            21: {
        !            22:        register i; int nrasters, rastwid; Rectangle rrast;
        !            23:        int pflag = 0;
        !            24:        Bitmap *bbuffer;
        !            25: 
        !            26:        if (filnam[0] != '|')
        !            27:                filep=fopen(filnam, "w");
        !            28:        else
        !            29:                filep=popen(filnam+2, "w"), pflag = 1;
        !            30:        if (!filep) {
        !            31:                pflag = 0;
        !            32:                return 1;
        !            33:        }
        !            34: 
        !            35:        nrasters = r.corner.y-r.origin.y;
        !            36:        i        = r.corner.x-r.origin.x;
        !            37:        rastwid  =(i+SHORTSIZE-1)/SHORTSIZE;
        !            38:        bbuffer = balloc(Rect(0,0,rastwid*SHORTSIZE+32,1));
        !            39:        endraster= raster+rastwid-1;
        !            40:        sendword(0);
        !            41:        sendword(r.origin.x - Jfscreen.rect.origin.x);
        !            42:        sendword(r.origin.y - Jfscreen.rect.origin.y);
        !            43:        sendword(r.corner.x - Jfscreen.rect.origin.x);
        !            44:        sendword(r.corner.y - Jfscreen.rect.origin.y);
        !            45: 
        !            46:        rectf(bbuffer,bbuffer->rect,F_CLR);
        !            47:        for (i=0; i<rastwid; i++) raster[i] = 0;
        !            48:        rrast=r;
        !            49:        rectf(bp,r,F_XOR);
        !            50: 
        !            51:        for (; rrast.origin.y<r.corner.y; rrast.origin.y++) {
        !            52:                rrast.corner.y = rrast.origin.y+1;
        !            53:                rectf(bp,rrast,F_XOR);
        !            54:                bitblt(bp,rrast,bbuffer,Pt(0,0),F_STORE);
        !            55:                getrast(bbuffer,buffer);
        !            56:                for (i=0; i<rastwid; i++) raster[i] ^= buffer[i];
        !            57:                sendrast();
        !            58:                for (i=0; i<rastwid; i++) raster[i]  = buffer[i];
        !            59:        }
        !            60: 
        !            61:        bfree(bbuffer);
        !            62:        if (!pflag)
        !            63:                fclose(filep);
        !            64:        else
        !            65:                pclose(filep);
        !            66:        return 0;
        !            67: }
        !            68: 
        !            69: static sendrast()
        !            70: {
        !            71:        SHORT *p2;
        !            72: 
        !            73:        p1=p2=raster;
        !            74:        do {
        !            75:                if (p1 >= p2) {
        !            76:                        p2=p1+1; count=2;
        !            77:                        ctype=(*p1 == *p2);
        !            78: 
        !            79:                } else if ((*p2 == *(p2+1)) == ctype) {
        !            80:                        if (++count >= 127) {
        !            81:                                sendbits();
        !            82:                                p1=p2+2;
        !            83:                        } else p2++;
        !            84: 
        !            85:                } else if (ctype) {
        !            86:                        sendbits();
        !            87:                        p1=p2+1;
        !            88:                        ctype=0;
        !            89: 
        !            90:                } else {
        !            91:                        count--; sendbits();
        !            92:                        p1=p2;
        !            93:                        ctype=1;
        !            94:                }
        !            95:        } while (p2<endraster);
        !            96: 
        !            97:        if (p1 > endraster) return;
        !            98:        if (p2 > endraster) count--;
        !            99:        sendbits();
        !           100: }
        !           101: 
        !           102: static sendbits()
        !           103: {
        !           104:        int c;
        !           105:        c=count; if (ctype) { c += 128; count=1; }
        !           106:        sendch(c);
        !           107:        sendnch(sizeof(SHORT)*count,(char *)p1);
        !           108: }
        !           109: 
        !           110: sendch(c)
        !           111: int c;
        !           112: {
        !           113:        putc(c, filep);
        !           114: }
        !           115: 
        !           116: sendnch(n,str)
        !           117: register int n; register char *str;
        !           118: {
        !           119:        while (n-- > 0)
        !           120:                putc(*str++, filep);
        !           121: }

unix.superglobalmegacorp.com

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