1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Compute pixels for glare calculation |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
+ |
#include <string.h> |
11 |
+ |
|
12 |
+ |
#include "rtprocess.h" /* Windows: must come first because of conflicts */ |
13 |
|
#include "glare.h" |
14 |
+ |
|
15 |
|
/* maximum rtrace buffer size */ |
16 |
|
#define MAXPIX (4096/(6*sizeof(float))) |
17 |
|
|
19 |
|
#define HSIZE 317 /* size of scanline hash table */ |
20 |
|
#define NRETIRE 16 /* number of scanlines to retire at once */ |
21 |
|
|
22 |
< |
int rt_pd[3] = {-1,-1,-1}; /* process id & descriptors for rtrace */ |
22 |
> |
static SUBPROC rt_pd = SP_INACTIVE; /* process id & descriptors for rtrace */ |
23 |
|
|
24 |
|
FILE *pictfp = NULL; /* picture file pointer */ |
25 |
|
double exposure; /* picture exposure */ |
43 |
|
static SCAN *freelist; /* scanline free list */ |
44 |
|
static SCAN *hashtab[HSIZE]; /* scanline hash table */ |
45 |
|
|
46 |
+ |
static long scanbufsiz; /* size of allocated scanline buffer */ |
47 |
+ |
|
48 |
|
static long ncall = 0L; /* number of calls to getpictscan */ |
49 |
|
static long nread = 0L; /* number of scanlines read */ |
50 |
|
static long nrecl = 0L; /* number of scanlines reclaimed */ |
158 |
|
FVECT vd; |
159 |
|
{ |
160 |
|
FVECT pp; |
161 |
< |
double vpx, vpy, vpz; |
161 |
> |
FVECT ip; |
162 |
|
COLOR res; |
163 |
|
|
164 |
|
if (pictfp == NULL) |
166 |
|
pp[0] = pictview.vp[0] + vd[0]; |
167 |
|
pp[1] = pictview.vp[1] + vd[1]; |
168 |
|
pp[2] = pictview.vp[2] + vd[2]; |
169 |
< |
viewpixel(&vpx, &vpy, &vpz, &pictview, pp); |
170 |
< |
if (vpz <= FTINY || vpx < 0. || vpx >= 1. || vpy < 0. || vpy >= 1.) |
169 |
> |
viewloc(ip, &pictview, pp); |
170 |
> |
if (ip[2] <= FTINY || ip[0] < 0. || ip[0] >= 1. || |
171 |
> |
ip[1] < 0. || ip[1] >= 1.) |
172 |
|
return(-1.0); |
173 |
< |
colr_color(res, getpictscan((int)(vpy*pysiz))[(int)(vpx*pxsiz)]); |
173 |
> |
colr_color(res, getpictscan((int)(ip[1]*pysiz))[(int)(ip[0]*pxsiz)]); |
174 |
|
return(luminance(res)/exposure); |
175 |
|
} |
176 |
|
|
188 |
|
npixinvw++; |
189 |
|
if ((res = pict_val(dir)) >= 0.0) |
190 |
|
return(res); |
191 |
< |
if (rt_pd[0] == -1) { |
191 |
> |
if (rt_pd.r == -1) { |
192 |
|
npixmiss++; |
193 |
|
return(-1.0); |
194 |
|
} |
227 |
|
npixinvw++; |
228 |
|
if ((vb[vh+hsize] = pict_val(dir)) >= 0.0) |
229 |
|
continue; |
230 |
< |
if (rt_pd[0] == -1) { /* missing information */ |
230 |
> |
if (rt_pd.r == -1) { /* missing information */ |
231 |
|
npixmiss++; |
232 |
|
continue; |
233 |
|
} |
266 |
|
fprintf(stderr, "%s: sending %d samples to rtrace...\n", |
267 |
|
progname, np); |
268 |
|
#endif |
269 |
< |
bzero(pb+6*np, 6*sizeof(float)); |
270 |
< |
if (process(rt_pd, pb, pb, 3*sizeof(float)*np, |
271 |
< |
6*sizeof(float)*(np+1)) < 3*sizeof(float)*np) { |
269 |
> |
memset(pb+6*np, '\0', 6*sizeof(float)); |
270 |
> |
if (process(&rt_pd, (char *)pb, (char *)pb, 3*sizeof(float)*(np+1), |
271 |
> |
6*sizeof(float)*(np+1)) < 3*sizeof(float)*(np+1)) { |
272 |
|
fprintf(stderr, "%s: rtrace communication error\n", |
273 |
|
progname); |
274 |
|
exit(1); |
276 |
|
} |
277 |
|
|
278 |
|
|
279 |
+ |
int |
280 |
|
getexpos(s) /* get exposure from header line */ |
281 |
|
char *s; |
282 |
|
{ |
288 |
|
formatval(fmt, s); |
289 |
|
wrongformat = strcmp(fmt, COLRFMT); |
290 |
|
} |
291 |
+ |
return(0); |
292 |
|
} |
293 |
|
|
294 |
|
|
296 |
|
char *fn; |
297 |
|
{ |
298 |
|
if ((pictfp = fopen(fn, "r")) == NULL) { |
299 |
< |
fprintf("%s: cannot open\n", fn); |
299 |
> |
fprintf(stderr, "%s: cannot open\n", fn); |
300 |
|
exit(1); |
301 |
|
} |
302 |
|
exposure = 1.0; |
303 |
|
getheader(pictfp, getexpos, NULL); |
304 |
< |
if (wrongformat || |
305 |
< |
fgetresolu(&pxsiz, &pysiz, pictfp) != (YMAJOR|YDECR)) { |
298 |
< |
fprintf("%s: bad picture format\n", fn); |
304 |
> |
if (wrongformat || !fscnresolu(&pxsiz, &pysiz, pictfp)) { |
305 |
> |
fprintf(stderr, "%s: incompatible picture format\n", fn); |
306 |
|
exit(1); |
307 |
|
} |
308 |
|
initscans(); |
324 |
|
{ |
325 |
|
int rval; |
326 |
|
|
327 |
< |
rval = open_process(rt_pd, av); |
327 |
> |
rval = open_process(&rt_pd, av); |
328 |
|
if (rval < 0) { |
329 |
|
perror(progname); |
330 |
|
exit(1); |
344 |
|
{ |
345 |
|
int status; |
346 |
|
|
347 |
< |
status = close_process(rt_pd); |
347 |
> |
status = close_process(&rt_pd); |
348 |
|
if (status > 0) { |
349 |
|
fprintf(stderr, "%s: bad status (%d) from rtrace\n", |
350 |
|
progname, status); |
351 |
|
exit(1); |
352 |
|
} |
353 |
< |
rt_pd[0] = -1; |
353 |
> |
rt_pd.r = -1; |
354 |
|
} |
355 |
|
|
356 |
|
|
404 |
|
register SCAN *ptr; |
405 |
|
register int i; |
406 |
|
/* initialize positions */ |
407 |
< |
scanpos = (long *)malloc(pysiz*sizeof(long)); |
407 |
> |
scanpos = (long *)bmalloc(pysiz*sizeof(long)); |
408 |
|
if (scanpos == NULL) |
409 |
|
memerr("scanline positions"); |
410 |
|
for (i = pysiz-1; i >= 0; i--) |
415 |
|
hashtab[i] = NULL; |
416 |
|
/* allocate scanline buffers */ |
417 |
|
scansize = sizeof(SCAN) + pxsiz*sizeof(COLR); |
418 |
< |
#ifdef ALIGN |
419 |
< |
scansize = scansize+(sizeof(ALIGN)-1) & ~(sizeof(ALIGN)-1); |
418 |
> |
#ifdef ALIGNT |
419 |
> |
scansize = scansize+(sizeof(ALIGNT)-1) & ~(sizeof(ALIGNT)-1); |
420 |
|
#endif |
421 |
|
i = MAXSBUF / scansize; /* compute number to allocate */ |
422 |
|
if (i > HSIZE) |
423 |
|
i = HSIZE; |
424 |
< |
scan_buf = malloc(i*scansize); /* get in one big chunk */ |
424 |
> |
scanbufsiz = i*scansize; |
425 |
> |
scan_buf = bmalloc(scanbufsiz); /* get in one big chunk */ |
426 |
|
if (scan_buf == NULL) |
427 |
|
memerr("scanline buffers"); |
428 |
|
ptr = (SCAN *)scan_buf; |
439 |
|
|
440 |
|
donescans() /* free up scanlines */ |
441 |
|
{ |
442 |
< |
free(scan_buf); |
443 |
< |
free((char *)scanpos); |
442 |
> |
bfree(scan_buf, scanbufsiz); |
443 |
> |
bfree((char *)scanpos, pysiz*sizeof(long)); |
444 |
|
} |