|
|
1.1 ! root 1: /* ! 2: * Type-specific code for TYPE=pico ! 3: * Not a standard type, but supported for Gerard. ! 4: * Doesn't work on pipes because it calls lseek. ! 5: */ ! 6: #include <picfile.h> ! 7: #include <libc.h> ! 8: int PRD_pco(f, buf) ! 9: PICFILE *f; ! 10: char *buf; ! 11: { ! 12: register char *bufp, *ein, *inp; ! 13: int i, n; ! 14: long offs; ! 15: if(f->line==0){ ! 16: f->buf=malloc(f->width); ! 17: if(f->buf==0){ ! 18: PIC_error="Can't allocate buffer"; ! 19: return 0; ! 20: } ! 21: } ! 22: if(f->line==f->height){ ! 23: PIC_error="Read past end of picture"; ! 24: return 0; ! 25: } ! 26: offs=lseek(f->fd, 0L, 1); ! 27: ein=f->buf+f->width; ! 28: for(i=0;i!=f->nchan;i++){ ! 29: n=read(f->fd, f->buf, f->width); ! 30: if(n!=f->width){ ! 31: if(n==0) PIC_error="End of file reading picture"; ! 32: return 0; ! 33: } ! 34: inp=f->buf; ! 35: for(bufp=buf+i;inp!=ein;bufp+=f->nchan) ! 36: *bufp=*inp++; ! 37: lseek(f->fd, (long)f->width*(f->height-1), 1); ! 38: } ! 39: lseek(f->fd, offs+f->width, 0); ! 40: f->line++; ! 41: return 1; ! 42: } ! 43: int PWR_pco(f, buf) ! 44: PICFILE *f; ! 45: char *buf; ! 46: { ! 47: register char *bufp, *eout, *outp; ! 48: int i, n; ! 49: long offs; ! 50: if(f->line==0){ ! 51: f->buf=malloc(f->width); ! 52: if(f->buf==0){ ! 53: PIC_error="Can't allocate buffer"; ! 54: return 0; ! 55: } ! 56: PWR_header(f); ! 57: } ! 58: if(f->line==f->height){ ! 59: PIC_error="Write past end of picture"; ! 60: return 0; ! 61: } ! 62: offs=lseek(f->fd, 0L, 1); ! 63: eout=f->buf+f->width; ! 64: for(i=0;i!=f->nchan;i++){ ! 65: outp=f->buf; ! 66: for(bufp=buf+i;outp!=eout;bufp+=f->nchan) ! 67: *outp++=*bufp; ! 68: n=write(f->fd, f->buf, f->width); ! 69: if(n!=f->width) return 0; ! 70: lseek(f->fd, (long)f->width*(f->height-1), 1); ! 71: } ! 72: lseek(f->fd, offs+f->width, 0); ! 73: f->line++; ! 74: return 1; ! 75: } ! 76: int PCL_pco(f) ! 77: PICFILE *f; ! 78: { ! 79: free(f->buf); ! 80: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.