1 |
– |
/* Copyright (c) 1993 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 |
|
* Convert Radiance file to/from AVS file. |
6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdio.h> |
9 |
+ |
#include <math.h> |
10 |
|
#ifdef MSDOS |
11 |
|
#include <fcntl.h> |
12 |
|
#endif |
13 |
+ |
#include <time.h> |
14 |
|
#include "color.h" |
15 |
|
#include "resolu.h" |
16 |
|
|
17 |
< |
extern char *malloc(); |
17 |
> |
double gamcor = 2.2; /* gamma correction */ |
18 |
|
|
20 |
– |
double gamma = 2.2; /* gamma correction */ |
21 |
– |
|
19 |
|
int bradj = 0; /* brightness adjustment */ |
20 |
|
|
21 |
|
char *progname; |
27 |
|
int argc; |
28 |
|
char *argv[]; |
29 |
|
{ |
30 |
+ |
extern long getint(); |
31 |
|
int reverse = 0; |
32 |
|
int i; |
33 |
|
|
37 |
|
if (argv[i][0] == '-') |
38 |
|
switch (argv[i][1]) { |
39 |
|
case 'g': /* gamma correction */ |
40 |
< |
gamma = atof(argv[++i]); |
40 |
> |
gamcor = atof(argv[++i]); |
41 |
|
break; |
42 |
|
case 'e': /* exposure adjustment */ |
43 |
|
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
61 |
|
exit(1); |
62 |
|
} |
63 |
|
if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) { |
64 |
< |
fprintf(stderr, "can't open output \"%s\"\n", |
64 |
> |
fprintf(stderr, "%s: can't open output \"%s\"\n", |
65 |
|
progname, argv[i+1]); |
66 |
|
exit(1); |
67 |
|
} |
69 |
|
setmode(fileno(stdin), O_BINARY); |
70 |
|
setmode(fileno(stdout), O_BINARY); |
71 |
|
#endif |
72 |
< |
setcolrgam(gamma); /* set up gamma correction */ |
72 |
> |
setcolrgam(gamcor); /* set up gamma correction */ |
73 |
|
if (reverse) { |
74 |
|
/* get their image resolution */ |
75 |
< |
fread((char *)&xmax, sizeof(int), 1, stdin); |
76 |
< |
fread((char *)&ymax, sizeof(int), 1, stdin); |
75 |
> |
xmax = getint(4, stdin); |
76 |
> |
ymax = getint(4, stdin); |
77 |
> |
if (feof(stdin)) |
78 |
> |
quiterr("empty input file"); |
79 |
|
/* put our header */ |
80 |
+ |
newheader("RADIANCE", stdout); |
81 |
|
printargs(i, argv, stdout); |
82 |
|
fputformat(COLRFMT, stdout); |
83 |
|
putchar('\n'); |
90 |
|
fgetresolu(&xmax, &ymax, stdin) < 0) |
91 |
|
quiterr("bad picture format"); |
92 |
|
/* write their header */ |
93 |
< |
fwrite((char *)&xmax, sizeof(int), 1, stdout); |
94 |
< |
fwrite((char *)&ymax, sizeof(int), 1, stdout); |
93 |
> |
putint((long)xmax, 4, stdout); |
94 |
> |
putint((long)ymax, 4, stdout); |
95 |
|
/* convert file */ |
96 |
|
ra2avs(); |
97 |
|
} |
126 |
|
quiterr("out of memory in avs2ra"); |
127 |
|
/* convert image */ |
128 |
|
for (y = ymax-1; y >= 0; y--) { |
129 |
< |
(void)getc(stdin); /* toss alpha */ |
130 |
< |
scanout[x][RED] = getc(stdin); |
131 |
< |
scanout[x][GRN] = getc(stdin); |
132 |
< |
scanout[x][BLU] = getc(stdin); |
133 |
< |
if (feof(stdin) || ferror(stdin)) |
129 |
> |
for (x = 0; x < xmax; x++) { |
130 |
> |
(void)getc(stdin); /* toss alpha */ |
131 |
> |
scanout[x][RED] = getc(stdin); |
132 |
> |
scanout[x][GRN] = getc(stdin); |
133 |
> |
scanout[x][BLU] = getc(stdin); |
134 |
> |
} |
135 |
> |
if (feof(stdin) | ferror(stdin)) |
136 |
|
quiterr("error reading AVS image"); |
137 |
|
/* undo gamma */ |
138 |
|
gambs_colrs(scanout, xmax); |
142 |
|
quiterr("error writing Radiance picture"); |
143 |
|
} |
144 |
|
/* free scanline */ |
145 |
< |
free((char *)scanout); |
145 |
> |
free((void *)scanout); |
146 |
|
} |
147 |
|
|
148 |
|
|
172 |
|
quiterr("error writing AVS file"); |
173 |
|
} |
174 |
|
/* free scanline */ |
175 |
< |
free((char *)scanin); |
175 |
> |
free((void *)scanin); |
176 |
|
} |