|
|
1.1 ! root 1: /* ! 2: * Type-specific code for TYPE=bitmap ! 3: */ ! 4: #include <picfile.h> ! 5: #include <libc.h> ! 6: int PRD_bit(f, buf) ! 7: PICFILE *f; ! 8: char *buf; ! 9: { ! 10: register char *bufp, *ebuf, *bitp; ! 11: register int bit; ! 12: int n, bwid=(f->width+15)/16*2; ! 13: if(f->line==0){ ! 14: f->buf=malloc(bwid); ! 15: if(f->buf==0){ ! 16: PIC_error="Can't allocate buffer"; ! 17: return 0; ! 18: } ! 19: } ! 20: if(f->line==f->height){ ! 21: PIC_error="Read past end of picture"; ! 22: return 0; ! 23: } ! 24: bitp=f->buf; ! 25: n=read(f->fd, bitp, bwid); ! 26: if(n!=bwid){ ! 27: if(n==0) PIC_error="End of file reading picture"; ! 28: return 0; ! 29: } ! 30: ebuf=buf+f->width; ! 31: bit=128; ! 32: for(bufp=buf;bufp!=ebuf;){ ! 33: *bufp++=*bitp&bit?0:255; ! 34: bit>>=1; ! 35: if(bit==0){ ! 36: bitp++; ! 37: bit=128; ! 38: } ! 39: } ! 40: f->line++; ! 41: return 1; ! 42: } ! 43: int PWR_bit(f, buf) ! 44: PICFILE *f; ! 45: char *buf; ! 46: { ! 47: register char *bufp, *ebuf, *bitp; ! 48: register int bit, byte; ! 49: int n, bwid=(f->width+15)/16*2; ! 50: if(f->line==0){ ! 51: f->buf=malloc(bwid); ! 52: f->buf[bwid-1]=0; /* might be a slack byte */ ! 53: if(f->buf==0){ ! 54: PIC_error="Can't allocate buffer"; ! 55: return 0; ! 56: } ! 57: PWR_header(f); ! 58: } ! 59: if(f->line==f->height){ ! 60: PIC_error="Write past end of picture"; ! 61: return 0; ! 62: } ! 63: bitp=f->buf; ! 64: ebuf=buf+f->width; ! 65: byte=0; ! 66: bit=128; ! 67: for(bufp=buf;bufp!=ebuf;){ ! 68: if((*bufp++&255)<128) ! 69: byte|=bit; ! 70: bit>>=1; ! 71: if(bit==0){ ! 72: *bitp++=byte; ! 73: bit=128; ! 74: byte=0; ! 75: } ! 76: } ! 77: if(bit!=128) *bitp=byte; ! 78: f->line++; ! 79: n=write(f->fd, f->buf, bwid); ! 80: if(n!=bwid) return 0; ! 81: return 1; ! 82: } ! 83: int PCL_bit(f) ! 84: PICFILE *f; ! 85: { ! 86: free(f->buf); ! 87: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.