1 |
– |
/* Copyright (c) 1986 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 |
|
* pfilt.c - program to post-process picture file. |
6 |
|
* |
7 |
|
* 9/26/85 |
8 |
+ |
* 6/23/93 Added additional buffers for value spreading |
9 |
|
*/ |
10 |
|
|
11 |
< |
#include <stdio.h> |
11 |
> |
#include "copyright.h" |
12 |
|
|
13 |
|
#include <signal.h> |
14 |
+ |
#include <string.h> |
15 |
|
|
16 |
+ |
#include "platform.h" |
17 |
+ |
#include "standard.h" |
18 |
+ |
#include "rtio.h" |
19 |
|
#include "color.h" |
20 |
+ |
#include "view.h" |
21 |
+ |
#include "paths.h" |
22 |
+ |
#include "pfilt.h" |
23 |
|
|
24 |
|
|
25 |
< |
extern char *malloc(); |
25 |
> |
#define FEQ(a,b) ((a) >= .98*(b) && (a) <= 1.02*(b)) |
26 |
|
|
27 |
< |
#define CHECKRAD 1.5 /* radius to check for filtering */ |
27 |
> |
double CHECKRAD = 2.0; /* radius to check for filtering */ |
28 |
|
|
29 |
+ |
#define THRESHRAD 5.0 /* maximum sample spread in output */ |
30 |
+ |
|
31 |
|
COLOR exposure = WHTCOLOR; /* exposure for the frame */ |
32 |
|
|
33 |
< |
double rad = 0.0; /* output pixel radius for filtering */ |
33 |
> |
double rad = 0.0; /* output pixel radius for filtering */ |
34 |
|
|
35 |
+ |
double thresh = 0.0; /* maximum contribution for subpixel */ |
36 |
+ |
|
37 |
|
int nrows = 0; /* number of rows for output */ |
38 |
|
int ncols = 0; /* number of columns for output */ |
39 |
|
|
40 |
< |
double x_c = 1.0; /* ratio of output x size to input */ |
41 |
< |
double y_r = 1.0; /* ratio of output y size to input */ |
40 |
> |
double x_c = 1.0; /* ratio of output x size to input */ |
41 |
> |
double y_r = 1.0; /* ratio of output y size to input */ |
42 |
|
|
43 |
|
int singlepass = 0; /* true means skip first pass */ |
44 |
|
|
45 |
|
int avghot = 0; /* true means average in bright spots */ |
46 |
|
|
47 |
< |
double hotlvl = 1000.0; /* level considered "hot" */ |
47 |
> |
double hotlvl = 100.0; /* level considered "hot" */ |
48 |
|
|
49 |
|
int npts = 0; /* (half) number of points for stars */ |
50 |
|
|
51 |
< |
double spread = 1e-4; /* spread for star points */ |
51 |
> |
double spread = 1e-4; /* spread for star points */ |
52 |
|
|
44 |
– |
#define TEMPLATE "/usr/tmp/pfXXXXXX" |
45 |
– |
|
53 |
|
char *tfname = NULL; |
54 |
|
|
55 |
+ |
char template[] = TEMPLATE; |
56 |
+ |
|
57 |
+ |
char *lampdat = "lamp.tab"; /* lamp data file */ |
58 |
+ |
|
59 |
+ |
int order; /* scanline ordering of input */ |
60 |
|
int xres, yres; /* resolution of input */ |
61 |
+ |
double inpaspect = 1.0; /* pixel aspect ratio of input */ |
62 |
+ |
int correctaspect = 0; /* aspect ratio correction? */ |
63 |
|
|
64 |
< |
int xrad; /* x window size */ |
51 |
< |
int yrad; /* y window size */ |
64 |
> |
int wrongformat = 0; |
65 |
|
|
66 |
+ |
VIEW ourview = STDVIEW; |
67 |
+ |
int gotview = 0; |
68 |
+ |
int wrapfilt = 0; /* wrap filter horizontally? */ |
69 |
+ |
|
70 |
+ |
int estatus = 0; /* exit status (for non-fatal errors) */ |
71 |
+ |
|
72 |
+ |
int xrad; /* x search radius */ |
73 |
+ |
int yrad; /* y search radius */ |
74 |
+ |
int xbrad; /* x box size */ |
75 |
+ |
int ybrad; /* y box size */ |
76 |
+ |
|
77 |
|
int barsize; /* size of input scan bar */ |
78 |
|
COLOR **scanin; /* input scan bar */ |
79 |
|
COLOR *scanout; /* output scan line */ |
80 |
+ |
COLOR **scoutbar; /* output scan bar (if thresh > 0) */ |
81 |
+ |
float **greybar; /* grey-averaged input values */ |
82 |
+ |
int obarsize = 0; /* size of output scan bar */ |
83 |
+ |
int orad = 0; /* output window radius */ |
84 |
|
|
85 |
|
char *progname; |
86 |
|
|
87 |
+ |
static gethfunc headline; |
88 |
+ |
static brightfunc_t rgb_bright; |
89 |
+ |
static brightfunc_t xyz_bright; |
90 |
+ |
static void copyfile(FILE *in, FILE *out); |
91 |
+ |
static void pass1(FILE *in); |
92 |
+ |
static void pass2(FILE *in); |
93 |
+ |
static void scan2init(void); |
94 |
+ |
static void scan2sync(int r); |
95 |
+ |
static void scan2flush(void); |
96 |
|
|
97 |
< |
main(argc, argv) |
98 |
< |
int argc; |
99 |
< |
char **argv; |
97 |
> |
|
98 |
> |
int |
99 |
> |
main( |
100 |
> |
int argc, |
101 |
> |
char **argv |
102 |
> |
) |
103 |
|
{ |
64 |
– |
extern char *mktemp(); |
65 |
– |
extern double atof(), pow(); |
66 |
– |
extern long ftell(); |
67 |
– |
extern int quit(); |
104 |
|
FILE *fin; |
105 |
+ |
float *lampcolor; |
106 |
+ |
char *lamptype = NULL; |
107 |
|
long fpos; |
108 |
< |
double d; |
109 |
< |
int i; |
110 |
< |
|
108 |
> |
double outaspect = 0.0; |
109 |
> |
double d; |
110 |
> |
int i, j; |
111 |
> |
SET_DEFAULT_BINARY(); |
112 |
> |
SET_FILE_BINARY(stdin); |
113 |
> |
SET_FILE_BINARY(stdout); |
114 |
|
if (signal(SIGINT, quit) == SIG_IGN) |
115 |
|
signal(SIGINT, SIG_IGN); |
116 |
+ |
#ifdef SIGHUP |
117 |
|
if (signal(SIGHUP, quit) == SIG_IGN) |
118 |
< |
signal(SIGINT, SIG_IGN); |
118 |
> |
signal(SIGHUP, SIG_IGN); |
119 |
> |
#endif |
120 |
|
signal(SIGTERM, quit); |
121 |
+ |
#ifdef SIGPIPE |
122 |
|
signal(SIGPIPE, quit); |
123 |
< |
#ifdef SIGXCPU |
123 |
> |
#endif |
124 |
> |
#ifdef SIGXCPU |
125 |
|
signal(SIGXCPU, quit); |
126 |
|
signal(SIGXFSZ, quit); |
127 |
|
#endif |
128 |
|
|
129 |
< |
progname = argv[0]; |
129 |
> |
progname = argv[0] = fixargv0(argv[0]); |
130 |
|
|
131 |
|
for (i = 1; i < argc; i++) |
132 |
|
if (argv[i][0] == '-') |
133 |
|
switch (argv[i][1]) { |
134 |
|
case 'x': |
135 |
|
i++; |
136 |
< |
if (argv[i][0] == '/') |
136 |
> |
if (argv[i][0] == '/') { |
137 |
|
x_c = 1.0/atof(argv[i]+1); |
138 |
< |
else |
138 |
> |
ncols = 0; |
139 |
> |
} else |
140 |
|
ncols = atoi(argv[i]); |
141 |
|
break; |
142 |
|
case 'y': |
143 |
|
i++; |
144 |
< |
if (argv[i][0] == '/') |
144 |
> |
if (argv[i][0] == '/') { |
145 |
|
y_r = 1.0/atof(argv[i]+1); |
146 |
< |
else |
146 |
> |
nrows = 0; |
147 |
> |
} else |
148 |
|
nrows = atoi(argv[i]); |
149 |
|
break; |
150 |
+ |
case 'c': |
151 |
+ |
correctaspect = !correctaspect; |
152 |
+ |
break; |
153 |
+ |
case 'p': |
154 |
+ |
i++; |
155 |
+ |
outaspect = atof(argv[i]); |
156 |
+ |
break; |
157 |
|
case 'e': |
158 |
|
if (argv[i+1][0] == '+' || argv[i+1][0] == '-') |
159 |
|
d = pow(2.0, atof(argv[i+1])); |
160 |
|
else |
161 |
|
d = atof(argv[i+1]); |
162 |
+ |
if (d < 1e-20 || d > 1e20) { |
163 |
+ |
fprintf(stderr, |
164 |
+ |
"%s: exposure out of range\n", |
165 |
+ |
argv[0]); |
166 |
+ |
quit(1); |
167 |
+ |
} |
168 |
|
switch (argv[i][2]) { |
169 |
|
case '\0': |
170 |
|
scalecolor(exposure, d); |
183 |
|
} |
184 |
|
i++; |
185 |
|
break; |
186 |
+ |
case 'f': |
187 |
+ |
lampdat = argv[++i]; |
188 |
+ |
break; |
189 |
+ |
case 't': |
190 |
+ |
lamptype = argv[++i]; |
191 |
+ |
break; |
192 |
|
case '1': |
193 |
|
singlepass = 1; |
194 |
|
break; |
195 |
< |
case 'p': |
195 |
> |
case '2': |
196 |
> |
singlepass = 0; |
197 |
> |
break; |
198 |
> |
case 'n': |
199 |
|
npts = atoi(argv[++i]) / 2; |
200 |
|
break; |
201 |
|
case 's': |
210 |
|
case 'r': |
211 |
|
rad = atof(argv[++i]); |
212 |
|
break; |
213 |
+ |
case 'm': |
214 |
+ |
thresh = atof(argv[++i]); |
215 |
+ |
if (rad <= FTINY) |
216 |
+ |
rad = 0.6; |
217 |
+ |
break; |
218 |
|
case 'b': |
219 |
< |
rad = 0.0; |
219 |
> |
rad = thresh = 0.0; |
220 |
|
break; |
221 |
|
default:; |
222 |
|
badopt: |
227 |
|
} |
228 |
|
else |
229 |
|
break; |
230 |
< |
|
230 |
> |
/* get lamp data (if necessary) */ |
231 |
> |
if (lamptype != NULL) { |
232 |
> |
if (loadlamps(lampdat) < 0) |
233 |
> |
quit(1); |
234 |
> |
if ((lampcolor = matchlamp(lamptype)) == NULL) { |
235 |
> |
fprintf(stderr, "%s: unknown lamp type\n", lamptype); |
236 |
> |
quit(1); |
237 |
> |
} |
238 |
> |
for (j = 0; j < 3; j++) |
239 |
> |
if (lampcolor[j] > 1e-4) |
240 |
> |
colval(exposure,j) /= lampcolor[j]; |
241 |
> |
freelamps(); |
242 |
> |
} |
243 |
> |
/* open input file */ |
244 |
|
if (i == argc) { |
245 |
|
if (singlepass) |
246 |
|
fin = stdin; |
247 |
|
else { |
248 |
< |
tfname = mktemp(TEMPLATE); |
248 |
> |
tfname = mktemp(template); |
249 |
|
if ((fin = fopen(tfname, "w+")) == NULL) { |
250 |
|
fprintf(stderr, "%s: can't create ", progname); |
251 |
|
fprintf(stderr, "temp file \"%s\"\n", tfname); |
267 |
|
fprintf(stderr, "%s: bad # file arguments\n", progname); |
268 |
|
quit(1); |
269 |
|
} |
270 |
< |
/* copy header */ |
271 |
< |
copyheader(fin, stdout); |
270 |
> |
/* get header */ |
271 |
> |
getheader(fin, headline, NULL); |
272 |
> |
if (wrongformat) { |
273 |
> |
fprintf(stderr, "%s: input must be a Radiance picture\n", |
274 |
> |
progname); |
275 |
> |
quit(1); |
276 |
> |
} |
277 |
|
/* add new header info. */ |
278 |
|
printargs(i, argv, stdout); |
279 |
|
/* get picture size */ |
280 |
< |
if (fscanf(fin, "-Y %d +X %d\n", &yres, &xres) != 2) { |
280 |
> |
if ((order = fgetresolu(&xres, &yres, fin)) < 0) { |
281 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
282 |
|
quit(1); |
283 |
|
} |
284 |
< |
if (ncols > 0) |
285 |
< |
x_c = (double)ncols/xres; |
286 |
< |
else |
284 |
> |
if (!(order & YMAJOR)) |
285 |
> |
inpaspect = 1.0/inpaspect; |
286 |
> |
/* wrap around for cylindrical view? */ |
287 |
> |
wrapfilt = gotview && ourview.type == VT_CYL && |
288 |
> |
ourview.horiz >= 360.-FTINY && order & YMAJOR; |
289 |
> |
/* compute output resolution */ |
290 |
> |
if (ncols <= 0) |
291 |
|
ncols = x_c*xres + .5; |
292 |
< |
if (nrows > 0) |
197 |
< |
y_r = (double)nrows/yres; |
198 |
< |
else |
292 |
> |
if (nrows <= 0) |
293 |
|
nrows = y_r*yres + .5; |
294 |
+ |
if (outaspect > .01) { |
295 |
+ |
d = inpaspect * yres/xres / outaspect; |
296 |
+ |
if (d * ncols > nrows) |
297 |
+ |
ncols = nrows / d; |
298 |
+ |
else |
299 |
+ |
nrows = ncols * d; |
300 |
+ |
} |
301 |
+ |
x_c = (double)ncols/xres; |
302 |
+ |
y_r = (double)nrows/yres; |
303 |
|
|
304 |
< |
if (singlepass) { |
202 |
< |
/* skip exposure, etc. */ |
304 |
> |
if (singlepass) { /* skip exposure, etc. */ |
305 |
|
pass1default(); |
306 |
|
pass2(fin); |
307 |
|
quit(0); |
317 |
|
} |
318 |
|
pass2(fin); |
319 |
|
|
320 |
< |
quit(0); |
320 |
> |
quit(estatus); |
321 |
> |
return estatus; /* pro forma return */ |
322 |
|
} |
323 |
|
|
324 |
|
|
325 |
< |
copyfile(in, out) /* copy a file */ |
326 |
< |
register FILE *in, *out; |
325 |
> |
static double |
326 |
> |
rgb_bright( |
327 |
> |
COLOR clr |
328 |
> |
) |
329 |
|
{ |
330 |
< |
register int c; |
330 |
> |
return(bright(clr)); |
331 |
> |
} |
332 |
|
|
333 |
+ |
|
334 |
+ |
static double |
335 |
+ |
xyz_bright( |
336 |
+ |
COLOR clr |
337 |
+ |
) |
338 |
+ |
{ |
339 |
+ |
return(clr[CIEY]); |
340 |
+ |
} |
341 |
+ |
|
342 |
+ |
|
343 |
+ |
brightfunc_t *ourbright = rgb_bright; |
344 |
+ |
|
345 |
+ |
static int |
346 |
+ |
headline( /* process line from header */ |
347 |
+ |
char *s, |
348 |
+ |
void *p |
349 |
+ |
) |
350 |
+ |
{ |
351 |
+ |
char fmt[MAXFMTLEN]; |
352 |
+ |
|
353 |
+ |
fputs(s, stdout); /* copy to output */ |
354 |
+ |
if (isaspect(s)) /* get aspect ratio */ |
355 |
+ |
inpaspect *= aspectval(s); |
356 |
+ |
else if (isexpos(s)) /* get exposure */ |
357 |
+ |
hotlvl *= exposval(s); |
358 |
+ |
else if (formatval(fmt, s)) { /* get format */ |
359 |
+ |
wrongformat = 0; |
360 |
+ |
if (!strcmp(COLRFMT, fmt)) |
361 |
+ |
ourbright = rgb_bright; |
362 |
+ |
else if (!strcmp(CIEFMT, fmt)) |
363 |
+ |
ourbright = xyz_bright; |
364 |
+ |
else |
365 |
+ |
wrongformat = !globmatch(PICFMT, fmt); |
366 |
+ |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
367 |
+ |
gotview++; |
368 |
+ |
return(0); |
369 |
+ |
} |
370 |
+ |
|
371 |
+ |
|
372 |
+ |
static void |
373 |
+ |
copyfile( /* copy a file */ |
374 |
+ |
FILE *in, |
375 |
+ |
FILE *out |
376 |
+ |
) |
377 |
+ |
{ |
378 |
+ |
int c; |
379 |
+ |
|
380 |
|
while ((c = getc(in)) != EOF) |
381 |
|
putc(c, out); |
382 |
|
|
387 |
|
} |
388 |
|
|
389 |
|
|
390 |
< |
pass1(in) /* first pass of picture file */ |
391 |
< |
FILE *in; |
390 |
> |
static void |
391 |
> |
pass1( /* first pass of picture file */ |
392 |
> |
FILE *in |
393 |
> |
) |
394 |
|
{ |
395 |
|
int i; |
396 |
|
COLOR *scan; |
404 |
|
} |
405 |
|
for (i = 0; i < yres; i++) { |
406 |
|
if (freadscan(scan, xres, in) < 0) { |
407 |
< |
nrows = nrows * i / yres; /* adjust frame */ |
407 |
> |
nrows = (long)nrows * i / yres; /* adjust frame */ |
408 |
|
if (nrows <= 0) { |
409 |
|
fprintf(stderr, "%s: empty frame\n", progname); |
410 |
|
quit(1); |
411 |
|
} |
412 |
|
fprintf(stderr, "%s: warning - partial frame (%d%%)\n", |
413 |
< |
progname, 100*i/yres); |
413 |
> |
progname, (int)(100L*i/yres)); |
414 |
|
yres = i; |
415 |
+ |
y_r = (double)nrows/yres; |
416 |
+ |
estatus++; |
417 |
|
break; |
418 |
|
} |
419 |
|
pass1scan(scan, i); |
420 |
|
} |
421 |
< |
free((char *)scan); |
421 |
> |
free((void *)scan); |
422 |
|
} |
423 |
|
|
424 |
|
|
425 |
< |
pass2(in) /* last pass on file, write to stdout */ |
426 |
< |
FILE *in; |
425 |
> |
static void |
426 |
> |
pass2( /* last pass on file, write to stdout */ |
427 |
> |
FILE *in |
428 |
> |
) |
429 |
|
{ |
430 |
|
int yread; |
431 |
|
int ycent, xcent; |
432 |
|
int r, c; |
433 |
< |
|
433 |
> |
|
434 |
|
pass2init(); |
435 |
|
scan2init(); |
436 |
|
yread = 0; |
437 |
|
for (r = 0; r < nrows; r++) { |
438 |
< |
ycent = (long)r*yres/nrows; |
438 |
> |
ycent = (r+.5)*yres/nrows; |
439 |
|
while (yread <= ycent+yrad) { |
440 |
|
if (yread < yres) { |
441 |
|
if (freadscan(scanin[yread%barsize], |
442 |
|
xres, in) < 0) { |
443 |
|
fprintf(stderr, |
444 |
< |
"%s: bad read (y=%d)\n", |
444 |
> |
"%s: truncated input (y=%d)\n", |
445 |
|
progname, yres-1-yread); |
446 |
|
quit(1); |
447 |
|
} |
449 |
|
} |
450 |
|
yread++; |
451 |
|
} |
452 |
+ |
if (obarsize > 0) |
453 |
+ |
scan2sync(r); |
454 |
|
for (c = 0; c < ncols; c++) { |
455 |
< |
xcent = (long)c*xres/ncols; |
456 |
< |
if (rad <= 0.0) |
457 |
< |
dobox(scanout[c], xcent, ycent, c, r); |
458 |
< |
else |
455 |
> |
xcent = (c+.5)*xres/ncols; |
456 |
> |
if (thresh > FTINY) |
457 |
> |
dothresh(xcent, ycent, c, r); |
458 |
> |
else if (rad > FTINY) |
459 |
|
dogauss(scanout[c], xcent, ycent, c, r); |
460 |
+ |
else |
461 |
+ |
dobox(scanout[c], xcent, ycent, c, r); |
462 |
|
} |
463 |
< |
if (fwritescan(scanout, ncols, stdout) < 0) { |
463 |
> |
if (scanout != NULL && fwritescan(scanout, ncols, stdout) < 0) { |
464 |
|
fprintf(stderr, "%s: write error in pass2\n", progname); |
465 |
|
quit(1); |
466 |
|
} |
467 |
|
} |
468 |
+ |
/* skip leftover input */ |
469 |
+ |
while (yread < yres) { |
470 |
+ |
if (freadscan(scanin[0], xres, in) < 0) |
471 |
+ |
break; |
472 |
+ |
yread++; |
473 |
+ |
} |
474 |
+ |
scan2flush(); /* flush output */ |
475 |
|
} |
476 |
|
|
477 |
|
|
478 |
< |
scan2init() /* prepare scanline arrays */ |
478 |
> |
static void |
479 |
> |
scan2init(void) /* prepare scanline arrays */ |
480 |
|
{ |
481 |
< |
double e; |
482 |
< |
register int i; |
481 |
> |
COLOR ctmp; |
482 |
> |
double d; |
483 |
> |
int i; |
484 |
|
|
485 |
< |
if (rad <= 0.0) { |
486 |
< |
xrad = xres/ncols/2 + 1; |
487 |
< |
yrad = yres/nrows/2 + 1; |
316 |
< |
} else { |
485 |
> |
xbrad = xres/ncols/2 + 1; |
486 |
> |
ybrad = yres/nrows/2 + 1; |
487 |
> |
if (rad > FTINY) { |
488 |
|
if (nrows >= yres && ncols >= xres) |
489 |
|
rad *= (y_r + x_c)/2.0; |
490 |
|
|
491 |
< |
xrad = CHECKRAD*rad/x_c + 1; |
492 |
< |
yrad = CHECKRAD*rad/y_r + 1; |
493 |
< |
|
491 |
> |
if (thresh > FTINY) { |
492 |
> |
orad = CHECKRAD*THRESHRAD*rad + 1; |
493 |
> |
xrad = orad/x_c + xbrad; |
494 |
> |
yrad = orad/y_r + ybrad; |
495 |
> |
obarsize = 2*orad + 1; |
496 |
> |
} else { |
497 |
> |
xrad = CHECKRAD*rad/x_c + 1; |
498 |
> |
yrad = CHECKRAD*rad/y_r + 1; |
499 |
> |
} |
500 |
|
initmask(); /* initialize filter table */ |
501 |
+ |
} else { |
502 |
+ |
xrad = xbrad; |
503 |
+ |
yrad = ybrad; |
504 |
|
} |
505 |
< |
barsize = 2 * yrad; |
505 |
> |
barsize = 2*yrad + 1; |
506 |
|
scanin = (COLOR **)malloc(barsize*sizeof(COLOR *)); |
507 |
+ |
if (scanin == NULL) |
508 |
+ |
goto memerr; |
509 |
|
for (i = 0; i < barsize; i++) { |
510 |
|
scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR)); |
511 |
< |
if (scanin[i] == NULL) { |
512 |
< |
fprintf(stderr, "%s: out of memory\n", progname); |
513 |
< |
quit(1); |
511 |
> |
if (scanin[i] == NULL) |
512 |
> |
goto memerr; |
513 |
> |
} |
514 |
> |
if (obarsize > 0) { |
515 |
> |
scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *)); |
516 |
> |
greybar = (float **)malloc(obarsize*sizeof(float *)); |
517 |
> |
if ((scoutbar == NULL) | (greybar == NULL)) |
518 |
> |
goto memerr; |
519 |
> |
for (i = 0; i < obarsize; i++) { |
520 |
> |
scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR)); |
521 |
> |
greybar[i] = (float *)malloc(ncols*sizeof(float)); |
522 |
> |
if ((scoutbar[i] == NULL) | (greybar[i] == NULL)) |
523 |
> |
goto memerr; |
524 |
|
} |
525 |
+ |
} else { |
526 |
+ |
scanout = (COLOR *)malloc(ncols*sizeof(COLOR)); |
527 |
+ |
if (scanout == NULL) |
528 |
+ |
goto memerr; |
529 |
|
} |
530 |
< |
scanout = (COLOR *)malloc(ncols*sizeof(COLOR)); |
531 |
< |
if (scanout == NULL) { |
532 |
< |
fprintf(stderr, "%s: out of memory\n", progname); |
533 |
< |
quit(1); |
530 |
> |
/* record pixel aspect ratio */ |
531 |
> |
if (!correctaspect) { |
532 |
> |
d = order & YMAJOR ? x_c/y_r : y_r/x_c ; |
533 |
> |
if (!FEQ(d,1.0)) |
534 |
> |
fputaspect(d, stdout); |
535 |
|
} |
536 |
< |
e = bright(exposure); |
537 |
< |
if (e < 1-1e-7 || e > 1+1e-7) /* record exposure */ |
538 |
< |
printf("EXPOSURE=%e\n", e); |
536 |
> |
/* record exposure */ |
537 |
> |
d = (*ourbright)(exposure); |
538 |
> |
if (!FEQ(d,1.0)) |
539 |
> |
fputexpos(d, stdout); |
540 |
> |
/* record color correction */ |
541 |
> |
copycolor(ctmp, exposure); |
542 |
> |
scalecolor(ctmp, 1.0/d); |
543 |
> |
if (!FEQ(colval(ctmp,RED),colval(ctmp,GRN)) || |
544 |
> |
!FEQ(colval(ctmp,GRN),colval(ctmp,BLU))) |
545 |
> |
fputcolcor(ctmp, stdout); |
546 |
|
printf("\n"); |
547 |
< |
printf("-Y %d +X %d\n", nrows, ncols); /* write picture size */ |
547 |
> |
/* write out resolution */ |
548 |
> |
fputresolu(order, ncols, nrows, stdout); |
549 |
> |
return; |
550 |
> |
memerr: |
551 |
> |
fprintf(stderr, "%s: out of memory\n", progname); |
552 |
> |
quit(1); |
553 |
|
} |
554 |
|
|
555 |
|
|
556 |
+ |
static void |
557 |
+ |
scan2sync( /* synchronize grey averages and output scan */ |
558 |
+ |
int r |
559 |
+ |
) |
560 |
+ |
{ |
561 |
+ |
static int nextrow = 0; |
562 |
+ |
COLOR ctmp; |
563 |
+ |
int ybot; |
564 |
+ |
int c; |
565 |
+ |
/* average input scanlines */ |
566 |
+ |
while (nextrow <= r+orad && nextrow < nrows) { |
567 |
+ |
ybot = (nextrow+.5)*yres/nrows; |
568 |
+ |
for (c = 0; c < ncols; c++) { |
569 |
+ |
dobox(ctmp, (int)((c+.5)*xres/ncols),ybot, c,nextrow); |
570 |
+ |
greybar[nextrow%obarsize][c] = (*ourbright)(ctmp); |
571 |
+ |
} |
572 |
+ |
/* and zero output scanline */ |
573 |
+ |
memset((char *)scoutbar[nextrow%obarsize], '\0', ncols*sizeof(COLOR)); |
574 |
+ |
nextrow++; |
575 |
+ |
} |
576 |
+ |
/* point to top scanline for output */ |
577 |
+ |
if (r-orad >= 0) |
578 |
+ |
scanout = scoutbar[(r-orad)%obarsize]; |
579 |
+ |
else |
580 |
+ |
scanout = NULL; |
581 |
+ |
} |
582 |
+ |
|
583 |
+ |
|
584 |
+ |
static void |
585 |
+ |
scan2flush(void) /* flush output buffer */ |
586 |
+ |
{ |
587 |
+ |
int r; |
588 |
+ |
|
589 |
+ |
for (r = nrows-orad; r < nrows; r++) |
590 |
+ |
if (fwritescan(scoutbar[r%obarsize], ncols, stdout) < 0) |
591 |
+ |
break; |
592 |
+ |
if (fflush(stdout) < 0) { |
593 |
+ |
fprintf(stderr, "%s: write error at end of pass2\n", progname); |
594 |
+ |
quit(1); |
595 |
+ |
} |
596 |
+ |
} |
597 |
+ |
|
598 |
+ |
|
599 |
+ |
void |
600 |
|
quit(code) /* remove temporary file and exit */ |
601 |
|
int code; |
602 |
|
{ |