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