--- ray/src/util/glaresrc.c 1992/03/10 10:00:33 2.2 +++ ray/src/util/glaresrc.c 2022/11/29 20:45:21 2.7 @@ -1,9 +1,6 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: glaresrc.c,v 2.7 2022/11/29 20:45:21 greg Exp $"; #endif - /* * Gather samples and compute glare sources. */ @@ -17,14 +14,32 @@ static char SCCSid[] = "$SunId$ LBL"; struct source *curlist = NULL; /* current source list */ struct source *donelist = NULL; /* finished sources */ +void pict_stats(void); -struct srcspan * -newspan(l, r, v, sb) /* allocate a new source span */ -int l, r, v; -float *sb; +static struct srcspan * newspan(int l, int r, int v, float *sb); +static void addindirect(int h, int v, double br); +static void addsrcspan(struct srcspan *nss); +static void mergesource(struct source *sp, struct source *ap); +static void close_sources(int v); +static void close_allsrcs(void); +static struct srcspan * splitspan(struct srcspan *sso, double h, double v, double m); +static struct source * splitsource(struct source *so); +static void donesource(struct source *sp); +static struct source * findbuddy(struct source *s, struct source *l); +static void absorb(struct source *s); +static void freespans(struct source *sp); + + +static struct srcspan * +newspan( /* allocate a new source span */ + int l, + int r, + int v, + float *sb +) { - register struct srcspan *ss; - register int i; + struct srcspan *ss; + int i; ss = (struct srcspan *)malloc(sizeof(struct srcspan)); if (ss == NULL) @@ -39,7 +54,8 @@ float *sb; } -analyze() /* analyze our scene */ +void +analyze(void) /* analyze our scene */ { int h, v; int left; @@ -81,18 +97,21 @@ analyze() /* analyze our scene */ if (left < h) addsrcspan(newspan(left,h,v,spanbr)); } - free((char *)spanbr); + free((void *)spanbr); close_allsrcs(); } -addindirect(h, v, br) /* add brightness to indirect illuminances */ -int h, v; -double br; +static void +addindirect( /* add brightness to indirect illuminances */ + int h, + int v, + double br +) { double tanb, d; int hl; - register int i; + int i; hl = hlim(v); if (h <= -hl) { /* left region */ @@ -134,7 +153,8 @@ double br; } -comp_thresh() /* compute glare threshold */ +void +comp_thresh(void) /* compute glare threshold */ { int h, v; int nsamps; @@ -173,11 +193,13 @@ comp_thresh() /* compute glare threshold */ } -addsrcspan(nss) /* add new source span to our list */ -struct srcspan *nss; +static void +addsrcspan( /* add new source span to our list */ + struct srcspan *nss +) { struct source *last, *cs, *this; - register struct srcspan *ss; + struct srcspan *ss; cs = NULL; for (this = curlist; this != NULL; this = this->next) { @@ -211,11 +233,14 @@ struct srcspan *nss; } -mergesource(sp, ap) /* merge source ap into source sp */ -struct source *sp, *ap; +static void +mergesource( /* merge source ap into source sp */ + struct source *sp, + struct source *ap +) { struct srcspan head; - register struct srcspan *alp, *prev, *tp; + struct srcspan *alp, *prev, *tp; head.next = sp->first; prev = &head; @@ -241,15 +266,17 @@ struct source *sp, *ap; sp->brt = (sp->brt*sp->dom + ap->brt*ap->dom) / (sp->dom + ap->dom); } - free((char *)ap); + free((void *)ap); } -close_sources(v) /* close sources above v */ -int v; +static void +close_sources( /* close sources above v */ + int v +) { struct source head; - register struct source *last, *this; + struct source *last, *this; head.next = curlist; last = &head; @@ -264,9 +291,10 @@ int v; } -close_allsrcs() /* done with everything */ +static void +close_allsrcs(void) /* done with everything */ { - register struct source *this, *next; + struct source *this, *next; this = curlist; while (this != NULL) { @@ -278,12 +306,15 @@ close_allsrcs() /* done with everything */ } -struct srcspan * -splitspan(sso, h, v, m) /* divide source span at point */ -register struct srcspan *sso; -double h, v, m; +static struct srcspan * +splitspan( /* divide source span at point */ + struct srcspan *sso, + double h, + double v, + double m +) { - register struct srcspan *ssn; + struct srcspan *ssn; double d; int hs; @@ -306,13 +337,14 @@ double h, v, m; } -struct source * -splitsource(so) /* divide source in two if it's big and long */ -struct source *so; +static struct source * +splitsource( /* divide source in two if it's big and long */ + struct source *so +) { LRSUM lr; LRLIN fit; - register struct srcspan *ss, *ssn; + struct srcspan *ss, *ssn; struct srcspan *ssl, *ssnl, head; int h; double mh, mv; @@ -358,11 +390,13 @@ struct source *so; } -donesource(sp) /* finished with this source */ -register struct source *sp; +static void +donesource( /* finished with this source */ + struct source *sp +) { struct source *newsrc; - register struct srcspan *ss; + struct srcspan *ss; int h, n; double hsum, vsum, d; @@ -382,9 +416,13 @@ register struct source *sp; sp->dom += d; } } + freespans(sp); + if (sp->dom <= FTINY) { /* must be right at edge of image */ + free((void *)sp); + return; + } sp->brt /= (double)n; compdir(sp->dir, (int)(hsum/sp->dom), (int)(vsum/sp->dom)); - freespans(sp); sp->next = donelist; donelist = sp; if (verbose) @@ -395,9 +433,11 @@ register struct source *sp; } -struct source * -findbuddy(s, l) /* find close enough source to s in l*/ -register struct source *s, *l; +static struct source * +findbuddy( /* find close enough source to s in l*/ + struct source *s, + struct source *l +) { struct source *bestbuddy = NULL; double d, r, mindist = MAXBUDDY; @@ -414,10 +454,11 @@ register struct source *s, *l; } -absorb_specks() /* eliminate too-small sources */ +void +absorb_specks(void) /* eliminate too-small sources */ { struct source head, *buddy; - register struct source *last, *this; + struct source *last, *this; if (verbose) fprintf(stderr, "%s: absorbing small sources...\n", progname); @@ -438,12 +479,14 @@ absorb_specks() /* eliminate too-small sources */ } -absorb(s) /* absorb a source into indirect */ -register struct source *s; +static void +absorb( /* absorb a source into indirect */ + struct source *s +) { FVECT dir; double d; - register int i; + int i; for (i = 0; i < nglardirs; i++) { spinvector(dir, ourview.vdir, ourview.vup, indirect[i].theta); @@ -454,16 +497,19 @@ register struct source *s; indirect[i].n += d; } freespans(s); - free((char *)s); + free((void *)s); } -freespans(sp) /* free spans associated with source */ -struct source *sp; +static void +freespans( /* free spans associated with source */ + struct source *sp +) { - register struct srcspan *ss; + struct srcspan *ss; - for (ss = sp->first; ss != NULL; ss = ss->next) - free((char *)ss); - sp->first = NULL; + while ((ss = sp->first) != NULL) { + sp->first = ss->next; + free((void *)ss); + } }