Path: utzoo!utgpu!water!watmath!clyde!rutgers!sri-spam!ames!sgi!paul From: paul@sgi.SGI.COM (Paul Haeberli) Newsgroups: comp.graphics Subject: Reading TARGA 24 bit per pixel image files Message-ID: <10222@sgi.SGI.COM> Date: 29 Jan 88 23:12:33 GMT Organization: Silicon Graphics Inc, Mountain View, CA Lines: 157 /* * fromtarga - * Convert from a type 2 ( RGB ) targa image into an IRIS * image. Most targa images are displayed directly on monitors * with no gamma correction. The typical gamma is about 2.2, so * you gotta gammawarp the output image by 2.2 to get it into a * linear intensity space. * * Paul Haeberli - 1988 */ #include "image.h" #include "stdio.h" main(argc,argv) int argc; char **argv; { if(argc<3) { fprintf(stderr,"usage fromtarga targa.img image.rgb\n"); exit(1); } fromtarga(argv[1],argv[2]); } typedef struct TARGA { unsigned char numid; unsigned char maptyp; unsigned char imgtyp; short maporig; short mapsize; unsigned char mapbits; short xorig; short yorig; short xsize; short ysize; unsigned char pixsize; unsigned char imgdes; } TARGA; #define MAXIWIDTH 8192 short rbuf[MAXIWIDTH]; short gbuf[MAXIWIDTH]; short bbuf[MAXIWIDTH]; fromtarga(tname,iname) char *tname, *iname; { int xsize, ysize, zsize; int y; FILE *inf; IMAGE *image; TARGA t; inf = fopen(tname,"r"); if(!inf) { fprintf(stderr,"totarga: can't open input file %s\n",tname); exit(1); } t.numid = inchar(inf); t.maptyp = inchar(inf); t.imgtyp = inchar(inf); if(t.imgtyp != 2) { fprintf(stderr,"totarga: this only works on type 2 images %s\n",tname); exit(1); } t.maporig = inshort(inf); t.mapsize = inshort(inf); t.mapbits = inchar(inf); t.xorig = inshort(inf); t.yorig = inshort(inf); t.xsize = inshort(inf); t.ysize = inshort(inf); t.pixsize = inchar(inf); t.imgdes = inshort(inf); xsize = t.xsize; ysize = t.ysize; for(y=0; ynumid); fprintf(stderr,"maptype %d\n",t->maptyp); fprintf(stderr,"imgtyp %d\n",t->imgtyp); fprintf(stderr,"maporig %d mapsize %d \n",t->maporig,t->mapsize); fprintf(stderr,"mapbits %d\n",t->mapbits); fprintf(stderr,"xorig yorig %d %d\n",t->xorig,t->xorig); fprintf(stderr,"xsize ysize %d %d \n",t->xsize,t->ysize); fprintf(stderr,"pixsize %d\n",t->pixsize); fprintf(stderr,"imgdes %d\n",t->imgdes); }