Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!oliveb!sun!falk From: falk@sun.Eng.Sun.COM (Ed Falk) Newsgroups: comp.graphics Subject: Re: venera img format conversion programs Message-ID: <107516@sun.Eng.Sun.COM> Date: 1 Jun 89 02:32:26 GMT References: <1939@deimos.cis.ksu.edu> Organization: Sun Microsystems, Inc. - Mtn View, CA Lines: 163 In article <1939@deimos.cis.ksu.edu>, bmc@phobos.cis.ksu.edu (Brett McCoy - CTA) writes: > Does anyone have a program that will convert the format that > venera.isi.edu (128.9.0.32) uses to store the pixmaps there. The call > it IMG. I would like to convert them to something like Sun rasterfiles > or GIF files. I thought that I would see if there already existed a > program for doing this before I spent the time writing one myself. #include #include static char *usage = "usage: \"img2ras [ infile [ outfile]]\"\n" ; extern int errno ; extern char *sys_errlist[] ; main(argc,argv) int argc ; char *argv[] ; { struct rasterfile header ; colormap_t colormap ; int linebytes ; unsigned char red[256], green[256], blue[256] ; unsigned char buffer[4096] ; int len, cmaplen ; register int i,j ; register unsigned char *inptr, *outptr ; if( argc >= 2 ) if (freopen(argv[1], "r", stdin) == NULL) { fprintf(stderr, "img2ras: can't open input file %s, %s\n%s", argv[1],sys_errlist[errno],usage) ; exit(1) ; } if( argc >= 3 ) { if (freopen(argv[2], "w", stdout) == NULL) { fprintf(stderr, "img2ras: can't open output file %s, %s\n%s", argv[2],sys_errlist[errno],usage) ; exit(1) ; } } /* get signature */ fread(buffer, 8, 1, stdin) ; buffer[8] = '\0' ; header.ras_magic = RAS_MAGIC ; header.ras_depth = 8 ; header.ras_length = 0 ; header.ras_type = RT_STANDARD ; header.ras_maptype = RMT_NONE ; header.ras_maplength = 0 ; colormap.type = RMT_NONE ; colormap.length = 0 ; /* get entries */ for(;;) { if( fread( buffer, 2,1, stdin) != 1 ) exit(0) ; if( strncmp(buffer, "AT", 2) == 0 ) { if( fread( buffer, 8,1, stdin) != 1 ) die( "bad attributes header" ) ; buffer[8] = '\0' ; len = atoi(buffer) ; if( fread( buffer, len,1, stdin) != 1 ) die( "bad attributes buffer") ; buffer[len] = '\0' ; sscanf(buffer, "%4u%4u%4u", &header.ras_width, &header.ras_height, &cmaplen) ; linebytes = header.ras_width ; linebytes += linebytes%2 ; header.ras_length = linebytes * header.ras_height ; } else if( strncmp(buffer, "CM", 2) == 0 ) { if( fread( buffer, 8,1, stdin) != 1 ) die( "bad colormap header" ) ; buffer[8] = '\0' ; len = atoi(buffer) ; if( fread( buffer, len,1, stdin) != 1 ) die( "bad colormap buffer") ; if( cmaplen*3 != len ) { fprintf(stderr, "img2ras: cmaplen, %d and colormap buffer length %d do not match", cmaplen, len) ; if( cmaplen*3 > len ) cmaplen = len/3 ; } header.ras_maptype = RMT_EQUAL_RGB ; header.ras_maplength = cmaplen*3 ; { register unsigned char *r, *g, *b, *ip ; r = red ; g = green ; b = blue ; ip = buffer ; for(i=0; i