--- ray/src/meta/meta2tga.c 2003/09/16 06:32:21 1.3 +++ ray/src/meta/meta2tga.c 2020/05/13 00:30:13 1.9 @@ -1,38 +1,29 @@ #ifndef lint -static const char RCSid[] = "$Id: meta2tga.c,v 1.3 2003/09/16 06:32:21 greg Exp $"; +static const char RCSid[] = "$Id: meta2tga.c,v 1.9 2020/05/13 00:30:13 greg Exp $"; #endif /* * Program to convert meta-files to Targa 8-bit color-mapped format */ +#include "copyright.h" -#define MAXALLOC 5000 - -#define DXSIZE 400 /* default x resolution */ - -#define DYSIZE 400 /* default y resolution */ - -#define XCOM "pexpand +vOCImsp -DP %s | psort +y" - - - - +#include "rtprocess.h" #include "meta.h" - #include "plot.h" - #include "rast.h" - #include "targa.h" +#define MAXALLOC 100000 +#define DXSIZE 400 /* default x resolution */ +#define DYSIZE 400 /* default y resolution */ +#define XCOM "pexpand +vOCImsp -DP %s | psort +y" - char *progname; SCANBLOCK outblock; -int dxsize = DXSIZE, dysize = DYSIZE; +int dxsiz = DXSIZE, dysiz = DYSIZE; int maxalloc = MAXALLOC; @@ -48,9 +39,12 @@ static int lineno = 0; static short condonly = FALSE, conditioned = FALSE; +static int putthead(struct hdStruct *hp, char *ip, FILE *fp); + + + char * -findtack(s) /* find place to tack on suffix */ -register char *s; +findtack(char *s) /* find place to tack on suffix */ { while (*s && *s != '.') s++; @@ -58,14 +52,13 @@ register char *s; } -main(argc, argv) - -int argc; -char **argv; - +int +main( + int argc, + char **argv +) { FILE *fp; - FILE *popen(); char comargs[200], command[300]; fout = stdout; @@ -88,11 +81,11 @@ char **argv; argc--; break; case 'x': - dxsize = atoi(*++argv); + dxsiz = atoi(*++argv); argc--; break; case 'y': - dysize = atoi(*++argv); + dysiz = atoi(*++argv); argc--; break; case 'o': @@ -143,32 +136,25 @@ char **argv; } return(0); - } +} - - - - -thispage() /* rewind current file */ +void +thispage(void) /* rewind current file */ { if (lineno) error(USER, "cannot restart page in thispage"); } - -initfile() /* initialize this file */ +void +initfile(void) /* initialize this file */ { - static int filenum = 0; - /* - static unsigned char cmap[24] = {255,255,255, 255,152,0, 0,188,0, 0,0,255, - 179,179,0, 255,0,255, 0,200,200, 0,0,0}; - */ - static unsigned char cmap[24] = {0,0,0, 0,0,255, 0,188,0, 255,152,0, + static const unsigned char cmap[24] = {0,0,0, 0,0,255, 0,188,0, 255,152,0, 0,200,200, 255,0,255, 179,179,0, 255,255,255}; + static int filenum = 0; struct hdStruct thead; - register int i; + int i; if (outtack != NULL) { sprintf(outtack, "%d.tga", ++filenum); @@ -183,8 +169,8 @@ initfile() /* initialize this file */ thead.CMapBits = 24; thead.XOffset = 0; thead.YOffset = 0; - thead.x = dxsize; - thead.y = dysize; + thead.x = dxsiz; + thead.y = dysiz; thead.dataBits = 8; thead.imType = 0; putthead(&thead, NULL, fout); @@ -195,16 +181,14 @@ initfile() /* initialize this file */ } - - -nextpage() /* advance to next page */ - +void +nextpage(void) /* advance to next page */ { if (lineno == 0) return; if (fout != NULL) { - while (lineno < dysize) { + while (lineno < dysiz) { nextblock(); outputblock(); } @@ -216,20 +200,18 @@ nextpage() /* advance to next page */ } - #define MINRUN 4 - -printblock() /* output scanline block to file */ - +void +printblock(void) /* output scanline block to file */ { int i, c2; - register unsigned char *scanline; - register int j, beg, cnt; + unsigned char *scanline; + int j, beg, cnt = 0; if (lineno == 0) initfile(); - for (i = outblock.ybot; i <= outblock.ytop && i < dysize; i++) { + for (i = outblock.ybot; i <= outblock.ytop && i < dysiz; i++) { scanline = outblock.cols[i-outblock.ybot]; for (j = outblock.xleft; j <= outblock.xright; j += cnt) { for (beg = j; beg <= outblock.xright; beg += cnt) { @@ -257,19 +239,23 @@ printblock() /* output scanline block to file */ } -putint2(i, fp) /* put a 2-byte positive integer */ -register int i; -register FILE *fp; +void +putint2( /* put a 2-byte positive integer */ + int i, + FILE *fp +) { putc(i&0xff, fp); putc(i>>8&0xff, fp); } -putthead(hp, ip, fp) /* write header to output */ -struct hdStruct *hp; -char *ip; -register FILE *fp; +int +putthead( /* write header to output */ + struct hdStruct *hp, + char *ip, + FILE *fp +) { if (ip != NULL) putc(strlen(ip), fp);