--- ray/src/gen/mkillum3.c 2004/09/28 17:54:18 2.10 +++ ray/src/gen/mkillum3.c 2023/12/16 18:35:27 2.15 @@ -1,36 +1,35 @@ #ifndef lint -static const char RCSid[] = "$Id: mkillum3.c,v 2.10 2004/09/28 17:54:18 greg Exp $"; +static const char RCSid[] = "$Id: mkillum3.c,v 2.15 2023/12/16 18:35:27 greg Exp $"; #endif /* * Routines to print mkillum objects */ #include "mkillum.h" +#include "paths.h" -#define brt(col) (.263*(col)[0]+.655*(col)[1]+.082*(col)[2]) - char DATORD[] = "RGB"; /* data ordering */ char DATSUF[] = ".dat"; /* data file suffix */ char DSTSUF[] = ".dist"; /* distribution suffix */ char FNCFNM[] = "illum.cal"; /* function file name */ -void compinv(float *rinv, float *rp, int m); -void colorout(int p, float *da, int n, int m, double mult, FILE *fp); -void fputnum(double d, FILE *fp); -void brightout(float *da, int n, int m, double mult, FILE *fp); -void fputeol(FILE *fp); -void compavg(float col[3], float *da, int n); -char * dfname(struct illum_args *il, int c); -FILE * dfopen(struct illum_args *il, int c); +static void compinv(COLORV *rinv, COLORV *rp, int m); +static void colorout(int p, COLORV *da, int n, int m, double mult, FILE *fp); +static void fputnum(double d, FILE *fp); +static void brightout(COLORV *da, int n, int m, double mult, FILE *fp); +static void fputeol(FILE *fp); +static void compavg(COLOR col, COLORV *da, int n); +static char * dfname(struct illum_args *il, int c); +static FILE * dfopen(struct illum_args *il, int c); void printobj( /* print out an object */ char *mod, - register OBJREC *obj + OBJREC *obj ) { - register int i; + int i; if (issurface(obj->otype) && !strcmp(mod, VOIDID)) return; /* don't print void surfaces */ @@ -62,7 +61,7 @@ dfname( /* return data file name */ ) { char fname[MAXSTR]; - register char *s; + char *s; s = strcpy(fname, il->datafile); s += strlen(s); @@ -76,9 +75,9 @@ dfname( /* return data file name */ } -FILE * +static FILE * dfopen( /* open data file */ - register struct illum_args *il, + struct illum_args *il, int c ) { @@ -98,10 +97,10 @@ dfopen( /* open data file */ } -extern void +void flatout( /* write hemispherical distribution */ struct illum_args *il, - float *da, + COLORV *da, int n, int m, FVECT u, @@ -109,11 +108,11 @@ flatout( /* write hemispherical distribution */ FVECT w ) { - float *Ninv; + COLORV *Ninv; FILE *dfp; int i; - if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL) + if ((Ninv = (COLORV *)malloc(3*m*sizeof(COLORV))) == NULL) error(SYSTEM, "out of memory in flatout"); compinv(Ninv, da, m); if (il->flags & IL_COLDST) { @@ -139,8 +138,8 @@ flatout( /* write hemispherical distribution */ fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", 1.+.5/n, .5/n, n+1, 0., 2.*PI, m+1); - brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp); - brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp); + brightout(Ninv, 1, m, 1./il->nsamps/bright(il->col), dfp); + brightout(da, n, m, 1./il->nsamps/bright(il->col), dfp); fputeol(dfp); fclose(dfp); printf(" %s", dfname(il, 0)); @@ -151,24 +150,24 @@ flatout( /* write hemispherical distribution */ printf("\t%f\t%f\t%f\n", v[0], v[1], v[2]); printf("\t%f\t%f\t%f\n", w[0], w[1], w[2]); il->dfnum++; - free((void *)Ninv); + free(Ninv); } -extern void +void roundout( /* write spherical distribution */ struct illum_args *il, - float *da, + COLORV *da, int n, int m ) { - float *Ninv, *Sinv; + COLORV *Ninv, *Sinv; FILE *dfp; int i; - if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL || - (Sinv = (float *)malloc(3*m*sizeof(float))) == NULL) + if ((Ninv = (COLORV *)malloc(3*m*sizeof(COLORV))) == NULL || + (Sinv = (COLORV *)malloc(3*m*sizeof(COLORV))) == NULL) error(SYSTEM, "out of memory in roundout"); compinv(Ninv, da, m); compinv(Sinv, da+3*m*(n-1), m); @@ -196,9 +195,9 @@ roundout( /* write spherical distribution */ fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", 1.+1./n, -1.-1./n, n+2, 0., 2.*PI, m+1); - brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp); - brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp); - brightout(Sinv, 1, m, 1./il->nsamps/brt(il->col), dfp); + brightout(Ninv, 1, m, 1./il->nsamps/bright(il->col), dfp); + brightout(da, n, m, 1./il->nsamps/bright(il->col), dfp); + brightout(Sinv, 1, m, 1./il->nsamps/bright(il->col), dfp); fputeol(dfp); fclose(dfp); printf(" %s", dfname(il, 0)); @@ -206,14 +205,14 @@ roundout( /* write spherical distribution */ printf("\n\t%s il_alt il_azi", FNCFNM); printf("\n0\n0\n"); il->dfnum++; - free((void *)Ninv); - free((void *)Sinv); + free(Ninv); + free(Sinv); } -extern void +void illumout( /* print illum object */ - register struct illum_args *il, + struct illum_args *il, OBJREC *ob ) { @@ -234,7 +233,7 @@ illumout( /* print illum object */ cout[1] = il->col[1]; cout[2] = il->col[2]; } else { - cout[0] = cout[1] = cout[2] = brt(il->col); + cout[0] = cout[1] = cout[2] = bright(il->col); } printf("\n0\n3 %f %f %f\n", cout[0], cout[1], cout[2]); @@ -242,35 +241,33 @@ illumout( /* print illum object */ } -void +static void compavg( /* compute average for set of data values */ - float col[3], - register float *da, + COLOR col, + COLORV *da, int n ) { - register int i; + int i; - col[0] = col[1] = col[2] = 0.; + setcolor(col, 0.0, 0.0, 0.0); i = n; while (i-- > 0) { - col[0] += *da++; - col[1] += *da++; - col[2] += *da++; + addcolor(col, da); + da += 3; } - for (i = 0; i < 3; i++) - col[i] /= (double)n; + scalecolor(col, 1./(double)n); } -void +static void compinv( /* compute other side of row average */ - register float *rinv, - register float *rp, + COLORV *rinv, + COLORV *rp, int m ) { - float avg[3]; + COLOR avg; compavg(avg, rp, m); /* row average */ while (m-- > 0) { @@ -281,10 +278,10 @@ compinv( /* compute other side of row average */ } -extern int +int average( /* evaluate average value for distribution */ - register struct illum_args *il, - float *da, + struct illum_args *il, + COLORV *da, int n ) { @@ -295,13 +292,13 @@ average( /* evaluate average value for distribution * il->col[2] /= (double)il->nsamps; } /* brighter than minimum? */ - return(brt(il->col) > il->minbrt+FTINY); + return(bright(il->col) > il->minbrt+FTINY); } static int colmcnt = 0; /* count of columns written */ -void +static void fputnum( /* put out a number to fp */ double d, FILE *fp @@ -313,9 +310,9 @@ fputnum( /* put out a number to fp */ } -void +static void fputeol( /* write end of line to fp */ - register FILE *fp + FILE *fp ) { putc('\n', fp); @@ -323,17 +320,17 @@ fputeol( /* write end of line to fp */ } -void +static void colorout( /* put out color distribution data */ int p, - register float *da, + COLORV *da, int n, int m, double mult, FILE *fp ) { - register int i, j; + int i, j; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { @@ -345,22 +342,22 @@ colorout( /* put out color distribution data */ } -void +static void brightout( /* put out brightness distribution data */ - register float *da, + COLORV *da, int n, int m, double mult, FILE *fp ) { - register int i, j; + int i, j; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { - fputnum(mult*brt(da), fp); + fputnum(mult*bright(da), fp); da += 3; } - fputnum(mult*brt(da-3*m), fp); /* wrap phi */ + fputnum(mult*bright(da-3*m), fp); /* wrap phi */ } }