/* * fromsun.c - * convert any sun image file to Iris format. * * This program should handle 1-bit, 8-bit, 24-bit, and 32-bit * sun rasterfiles. * * to comile in IRIS: * cc -I/usr/include/gl fromsun.c -o fromsun -limage * * Paul Haeberli - 1989 * */ #include "image.h" #include "rasterfile.h" #define MAXWIDTH 8192 char cbuf[4*MAXWIDTH]; short rbuf[MAXWIDTH]; short gbuf[MAXWIDTH]; short bbuf[MAXWIDTH]; unsigned char rmap[256]; unsigned char gmap[256]; unsigned char bmap[256]; main(argc,argv) int argc; char **argv; { IMAGE *image; FILE *inf; int xsize, ysize, zsize, rowbytes; int y, depth, maplen, rastype, raslength; struct rasterfile hdr; unsigned char *fb, *fbptr; int fblength; if(argc<3) { fprintf(stderr,"usage: fromsun sunimage irisimage\n"); exit(1); } inf = fopen(argv[1],"r"); if(!inf) { fprintf(stderr,"fromsun: can't open %s\n",argv[1]); exit(1); } fread(&hdr,1,sizeof(hdr),inf); hdr.ras_magic = RAS_MAGIC; xsize = hdr.ras_width; ysize = hdr.ras_height; depth = hdr.ras_depth; rastype = hdr.ras_type; rowbytes = hdr.ras_length; maplen = hdr.ras_maplength; raslength = hdr.ras_length; if(depth != 1 && depth != 8 && depth != 24 && depth != 32) { fprintf(stderr,"fromsun: bad ras_depth is %d\n",hdr.ras_depth); exit(1); } if(maplen == 0 && depth == 8) { fprintf(stderr,"fromsun: no map on 8 bit image\n"); exit(1); } if(maplen > 0) { fread(rmap,maplen/3,1,inf); fread(gmap,maplen/3,1,inf); fread(bmap,maplen/3,1,inf); } switch(rastype) { case RT_OLD: rowbytes = linebytes(xsize,depth); hdr.ras_length = ysize*rowbytes; break; case RT_STANDARD: rowbytes = hdr.ras_length/ysize; break; case RT_BYTE_ENCODED: rowbytes = linebytes(xsize,depth); break; default: fprintf(stderr,"fromsun: bad ras_type is %d\n",rastype); exit(1); break; } if(depth == 1) image = iopen(argv[2],"w",RLE(1),2,xsize,ysize,1); else image = iopen(argv[2],"w",RLE(1),3,xsize,ysize,3); if(rastype == RT_BYTE_ENCODED) { fblength = rowbytes*ysize; fb = (unsigned char *)malloc(fblength); getrledata(inf,raslength,fb,fblength); fbptr = fb; for(y=0; yspace) count = space; while(count--) *expdat++ = c; } else { *expdat++ = ESCAPE; } } else { *expdat++ = c; } } } linebytes(xsize,depth) int xsize, depth; { return (((xsize*depth)+15) >> 3) & ~1; } bitstorow(bits,sbuf,n) unsigned char *bits; short *sbuf; int n; { int i, val, nbytes; nbytes = ((n-1)/8)+1; for(i = 0; i