Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!sun-barr!decwrl!sgi!paul@manray.sgi.com From: paul@manray.sgi.com (Paul Haeberli) Newsgroups: comp.sys.sgi Subject: Re: GIF file converter Summary: A converter from sun raster files to IRIS image format. Message-ID: <42429@sgi.sgi.com> Date: 2 Oct 89 23:36:03 GMT References: <8909292050.aa11265@SMOKE.BRL.MIL> Sender: paul@manray.sgi.com Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 193 /* * fromsun.c - * convert a sun image file to Iris format. * * This program should handle 1-bit, 8-bit and 24-bit sun rasterfiles. * Please mail paul@sgi.com if you have a problem rasterfile. This * program will not work on run length encoded raster files yet, * send me info and I might make it work for you. . . . * * To use: * 1. copy /usr/include/rasterfile.h from a sun system * 2. cc -I/usr/inlcude/gl fromsun.c -o fromsun -limage * 3. to convert: fromsun blat.im8 t.rgb * 4. to display: ipaste t.rgb * * Paul Haeberli@Silicon Graphics - 1989 * */ #include "image.h" #include "rasterfile.h" #define MAXWIDTH 4096 char cbuf[3*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; struct rasterfile hdr; if(argc<3) { fprintf(stderr,"usage: fromsun image.im8 outimage\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; if(depth != 8 && depth != 24 && depth != 1) { fprintf(stderr,"fromsun: bad ras_depth is %d\n",hdr.ras_depth); exit(1); } rowbytes = hdr.ras_length/ysize; switch(hdr.ras_type) { case RT_OLD: hdr.ras_length = ysize*linebytes(xsize,depth); rowbytes = hdr.ras_length/ysize; break; case RT_STANDARD: rowbytes = hdr.ras_length/ysize; break; case RT_BYTE_ENCODED: fprintf(stderr,"fromsun: don't know about RT_BYTE_ENCODED\n"); exit(1); break; default: fprintf(stderr,"fromsun: bad ras_type is %d\n",hdr.ras_type); exit(1); break; } maplen = hdr.ras_maplength; 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); } if(depth == 1) image = iopen(argv[2],"w",RLE(1),3,xsize,ysize,1); else image = iopen(argv[2],"w",RLE(1),3,xsize,ysize,3); for(y=0; y0) { if(*cptr & 0x80) *sptr++ = 0; else *sptr++ = 255; if(*cptr & 0x40) *sptr++ = 0; else *sptr++ = 255; if(*cptr & 0x20) *sptr++ = 0; else *sptr++ = 255; if(*cptr & 0x10) *sptr++ = 0; else *sptr++ = 255; if(*cptr & 0x08) *sptr++ = 0; else *sptr++ = 255; if(*cptr & 0x04) *sptr++ = 0; else *sptr++ = 255; if(*cptr & 0x02) *sptr++ = 0; else *sptr++ = 255; if(*cptr & 0x01) *sptr++ = 0; else *sptr++ = 255; cptr++; n -= 8; } } linebytes(xsize,depth) int xsize, depth; { return (( ((xsize*depth) + (16-1)) >> 3) &~ 1); }