|
|
1.1 ! root 1: #include <jstructs.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 int (*inch)(); ! 9: ! 10: Bitmap * ! 11: inbitmap(incharg) ! 12: int (*incharg)(); ! 13: { ! 14: Bitmap *bp; ! 15: register y, i, rastwid, deltarow; ! 16: register short *p; ! 17: int dummy; ! 18: Rectangle r; ! 19: ! 20: inch = incharg; ! 21: ! 22: if (inword(&dummy) < 0 || inrect(&r) < 0) ! 23: return 0; ! 24: i = r.origin.x % WORDSIZE; ! 25: r.corner.x -= i; r.origin.x -= i; ! 26: if ((bp = balloc(r)) == 0) ! 27: return 0; ! 28: rastwid = (r.corner.x - r.origin.x + SHORTSIZE - 1)/SHORTSIZE; ! 29: deltarow = bp->width*(sizeof(Word)/sizeof(short)); ! 30: p = (short *)bp->base; ! 31: for (y = r.origin.y; y < r.corner.y; y++) { ! 32: if (getrast(p, rastwid) < 0) { ! 33: bfree(bp); ! 34: return 0; ! 35: } ! 36: if (y > r.origin.y) ! 37: for (i=0; i < rastwid; i++) ! 38: p[i] ^= p[i-deltarow]; ! 39: p += deltarow; ! 40: } ! 41: return bp; ! 42: } ! 43: ! 44: static ! 45: getrast(p, nwords) /* receive single compressed raster */ ! 46: register short *p; int nwords; ! 47: { ! 48: int count, same; ! 49: ! 50: while (nwords > 0) { ! 51: if ((count = (*inch)()) <= 0) ! 52: return -1; ! 53: same = count&128; count &= 127; ! 54: nwords -= count; ! 55: ! 56: if (same) { ! 57: if (innchars(sizeof(short), (char *)p) < 0) ! 58: return -1; ! 59: for (count--; count>0; count--) { ! 60: *(p+1) = *p; p++; ! 61: } ! 62: p++; ! 63: } else { ! 64: if (innchars(sizeof(short)*count, (char *)p) < 0) ! 65: return -1; ! 66: p += count; ! 67: } ! 68: } ! 69: return (nwords == 0 ? 0 : -1); ! 70: } ! 71: ! 72: static ! 73: inword(wp) ! 74: short *wp; ! 75: { ! 76: register lo, hi; ! 77: if ((lo = (*inch)()) < 0 || (hi = (*inch)()) < 0) ! 78: return -1; ! 79: *wp = (hi << 8) | lo; ! 80: return 0; ! 81: } ! 82: ! 83: static ! 84: innchars(n, p) ! 85: register n; register char *p; ! 86: { ! 87: register c; ! 88: while (--n >= 0) ! 89: if ((c = (*inch)()) < 0) ! 90: return -1; ! 91: else ! 92: *p++ = c; ! 93: return 0; ! 94: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.