bmc@phobos.cis.ksu.edu (Brett McCoy - CTA) (05/22/89)
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.
In case anyone is interested, they have several hundred megabytes of pixmaps
there, including some 24 bit pixmaps, but they are all stored in their IMG
format, for which I have no conversion program. Any help would be greatly
appreciated.
files.
--
Brett McCoy | Technology suffeciently advanced will
BRTMAC@KSUVM.KSU.EDU | appear as magic to those who do not
bmc@phobos.cis.ksu.edu | understand it. Is it a wonder that hackers
| are sometimes thought of as wizards.
falk@sun.Eng.Sun.COM (Ed Falk) (06/01/89)
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 <stdio.h> #include <pixrect/pixrect_hs.h> 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<cmaplen; ++i) { *r++ = *ip++ ; *g++ = *ip++ ; *b++ = *ip++ ; } } colormap.type = RMT_EQUAL_RGB ; colormap.length = cmaplen ; colormap.map[0] = red ; colormap.map[1] = green ; colormap.map[2] = blue ; } else if( strncmp(buffer, "PD", 2) == 0 ) { if( fread( buffer, 8,1, stdin) != 1 ) die( "bad pixel data header" ) ; buffer[8] = '\0' ; len = atoi(buffer) ; if( len != header.ras_width * header.ras_height ) { fprintf(stderr, "img2ras: pixel data length, %d does not match image size %d\n", len, header.ras_width * header.ras_height ) ; } pr_dump_header(stdout, &header, &colormap) ; for(i=0; i<header.ras_height; ++i) { fread(buffer, 1, header.ras_width, stdin) ; fwrite(buffer, 1, linebytes, stdout) ; } fclose(stdout) ; } } } die(string) char *string ; { fprintf(stderr, "img2ras: %s\n", string) ; exit(1) ; } -- -ed falk, sun microsystems sun!falk, falk@sun.com card-carrying ACLU member.