--- ray/src/px/ra_t8.c 2003/06/05 19:29:34 2.12 +++ ray/src/px/ra_t8.c 2018/03/20 18:45:04 2.15 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ra_t8.c,v 2.12 2003/06/05 19:29:34 schorsch Exp $"; +static const char RCSid[] = "$Id: ra_t8.c,v 2.15 2018/03/20 18:45:04 greg Exp $"; #endif /* * ra_t8.c - program to convert between RADIANCE and @@ -9,12 +9,16 @@ static const char RCSid[] = "$Id: ra_t8.c,v 2.12 2003/ */ #include +#include #include #include #include "platform.h" +#include "rtio.h" +#include "rtmisc.h" #include "color.h" #include "resolu.h" +#include "clrtab.h" #include "targa.h" @@ -24,34 +28,36 @@ static const char RCSid[] = "$Id: ra_t8.c,v 2.12 2003/ #define my_mapType(h) ((h)->mapType==CM_HASMAP && \ ((h)->CMapBits==24 || (h)->CMapBits==32)) -#define taralloc(h) (BYTE *)emalloc((h)->x*(h)->y) +#define taralloc(h) (uby8 *)emalloc((h)->x*(h)->y) -BYTE clrtab[256][3]; - +uby8 clrtab[256][3]; extern int samplefac; - -extern char *ecalloc(), *emalloc(); - -extern long ftell(); - double gamv = 2.2; /* gamv correction */ - int bradj = 0; /* brightness adjustment */ - char *progname; - char errmsg[128]; - COLR *inl; - -BYTE *tarData; - +uby8 *tarData; int xmax, ymax; +static int getint2(FILE *fp); +static void putint2(int i, FILE *fp); +static void quiterr(char *err); +static int getthead(struct hdStruct *hp, char *ip, FILE *fp); +static int putthead(struct hdStruct *hp, char *ip, FILE *fp); +static int getrhead(struct hdStruct *h, FILE *fp); +static void tg2ra(struct hdStruct *hp); +static void getmapped(int nc, int dith); +static void getgrey(int nc); +static void writetarga(struct hdStruct *h, uby8 *d, FILE *fp); +static void readtarga(struct hdStruct *h, uby8 *data, FILE *fp); -main(argc, argv) -int argc; -char *argv[]; + +int +main( + int argc, + char *argv[] +) { struct hdStruct head; int dither = 1; @@ -147,9 +153,10 @@ userr: } -int -getint2(fp) /* get a 2-byte positive integer */ -register FILE *fp; +static int +getint2( /* get a 2-byte positive integer */ + register FILE *fp +) { register int b1, b2; @@ -160,17 +167,21 @@ register FILE *fp; } -putint2(i, fp) /* put a 2-byte positive integer */ -register int i; -register FILE *fp; +static void +putint2( /* put a 2-byte positive integer */ + register int i, + register FILE *fp +) { putc(i&0xff, fp); putc(i>>8&0xff, fp); } -quiterr(err) /* print message and exit */ -char *err; +static void +quiterr( /* print message and exit */ + char *err +) { if (err != NULL) { fprintf(stderr, "%s: %s\n", progname, err); @@ -196,10 +207,12 @@ int code; } -getthead(hp, ip, fp) /* read header from input */ -struct hdStruct *hp; -char *ip; -register FILE *fp; +static int +getthead( /* read header from input */ + struct hdStruct *hp, + char *ip, + register FILE *fp +) { int nidbytes; @@ -229,10 +242,12 @@ register FILE *fp; } -putthead(hp, ip, fp) /* write header to output */ -struct hdStruct *hp; -char *ip; -register FILE *fp; +static int +putthead( /* write header to output */ + struct hdStruct *hp, + char *ip, + register FILE *fp +) { if (ip != NULL) putc(strlen(ip), fp); @@ -257,9 +272,11 @@ register FILE *fp; } -getrhead(h, fp) /* load RADIANCE input file header */ -register struct hdStruct *h; -FILE *fp; +static int +getrhead( /* load RADIANCE input file header */ + register struct hdStruct *h, + FILE *fp +) { /* get header info. */ if (checkheader(fp, COLRFMT, NULL) < 0 || @@ -287,12 +304,14 @@ FILE *fp; } -tg2ra(hp) /* targa file to RADIANCE file */ -struct hdStruct *hp; +static void +tg2ra( /* targa file to RADIANCE file */ + struct hdStruct *hp +) { union { - BYTE c3[256][3]; - BYTE c4[256][4]; + uby8 c3[256][3]; + uby8 c4[256][4]; } map; COLR ctab[256]; COLR *scanline; @@ -336,9 +355,11 @@ struct hdStruct *hp; } -getmapped(nc, dith) /* read in and quantize image */ -int nc; /* number of colors to use */ -int dith; /* use dithering? */ +static void +getmapped( /* read in and quantize image */ + int nc, /* number of colors to use */ + int dith /* use dithering? */ +) { long fpos; register int y; @@ -384,11 +405,13 @@ int dith; /* use dithering? */ } -getgrey(nc) /* read in and convert to greyscale image */ -int nc; /* number of colors to use */ +static void +getgrey( /* read in and convert to greyscale image */ + int nc /* number of colors to use */ +) { int y; - register BYTE *dp; + register uby8 *dp; register int x; setcolrgam(gamv); @@ -416,10 +439,12 @@ int nc; /* number of colors to use */ } -writetarga(h, d, fp) /* write out targa data */ -struct hdStruct *h; -BYTE *d; -FILE *fp; +static void +writetarga( /* write out targa data */ + struct hdStruct *h, + uby8 *d, + FILE *fp +) { register int i, j; @@ -427,7 +452,7 @@ FILE *fp; for (j = 2; j >= 0; j--) putc(clrtab[i][j], fp); if (h->dataType == IM_CMAP) { /* uncompressed */ - if (fwrite((char *)d,h->x*sizeof(BYTE),h->y,fp) != h->y) + if (fwrite((char *)d,h->x*sizeof(uby8),h->y,fp) != h->y) quiterr("error writing targa file"); return; } @@ -435,16 +460,18 @@ FILE *fp; } -readtarga(h, data, fp) /* read in targa data */ -struct hdStruct *h; -BYTE *data; -FILE *fp; +static void +readtarga( /* read in targa data */ + struct hdStruct *h, + uby8 *data, + FILE *fp +) { register int cnt, c; - register BYTE *dp; + register uby8 *dp; if (h->dataType == IM_CMAP) { /* uncompressed */ - if (fread((char *)data,h->x*sizeof(BYTE),h->y,fp) != h->y) + if (fread((char *)data,h->x*sizeof(uby8),h->y,fp) != h->y) goto readerr; return; }