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 |
10 |
> |
#include <time.h> |
11 |
> |
|
12 |
> |
#include "platform.h" |
13 |
|
#include "color.h" |
14 |
|
#include "resolu.h" |
15 |
|
|
16 |
< |
extern char *malloc(); |
16 |
> |
double gamcor = 2.2; /* gamma correction */ |
17 |
|
|
21 |
– |
double gamma = 2.2; /* gamma correction */ |
22 |
– |
|
18 |
|
int bradj = 0; /* brightness adjustment */ |
19 |
|
|
20 |
|
char *progname; |
36 |
|
if (argv[i][0] == '-') |
37 |
|
switch (argv[i][1]) { |
38 |
|
case 'g': /* gamma correction */ |
39 |
< |
gamma = atof(argv[++i]); |
39 |
> |
gamcor = atof(argv[++i]); |
40 |
|
break; |
41 |
|
case 'e': /* exposure adjustment */ |
42 |
|
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
60 |
|
exit(1); |
61 |
|
} |
62 |
|
if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) { |
63 |
< |
fprintf(stderr, "can't open output \"%s\"\n", |
63 |
> |
fprintf(stderr, "%s: can't open output \"%s\"\n", |
64 |
|
progname, argv[i+1]); |
65 |
|
exit(1); |
66 |
|
} |
67 |
< |
#ifdef MSDOS |
68 |
< |
setmode(fileno(stdin), O_BINARY); |
69 |
< |
setmode(fileno(stdout), O_BINARY); |
75 |
< |
#endif |
76 |
< |
setcolrgam(gamma); /* set up gamma correction */ |
67 |
> |
SET_FILE_BINARY(stdin); |
68 |
> |
SET_FILE_BINARY(stdout); |
69 |
> |
setcolrgam(gamcor); /* set up gamma correction */ |
70 |
|
if (reverse) { |
71 |
|
/* get their image resolution */ |
72 |
|
xmax = getint(4, stdin); |
73 |
|
ymax = getint(4, stdin); |
74 |
+ |
if (feof(stdin)) |
75 |
+ |
quiterr("empty input file"); |
76 |
|
/* put our header */ |
77 |
+ |
newheader("RADIANCE", stdout); |
78 |
|
printargs(i, argv, stdout); |
79 |
|
fputformat(COLRFMT, stdout); |
80 |
|
putchar('\n'); |
123 |
|
quiterr("out of memory in avs2ra"); |
124 |
|
/* convert image */ |
125 |
|
for (y = ymax-1; y >= 0; y--) { |
126 |
< |
(void)getc(stdin); /* toss alpha */ |
127 |
< |
scanout[x][RED] = getc(stdin); |
128 |
< |
scanout[x][GRN] = getc(stdin); |
129 |
< |
scanout[x][BLU] = getc(stdin); |
130 |
< |
if (feof(stdin) || ferror(stdin)) |
126 |
> |
for (x = 0; x < xmax; x++) { |
127 |
> |
(void)getc(stdin); /* toss alpha */ |
128 |
> |
scanout[x][RED] = getc(stdin); |
129 |
> |
scanout[x][GRN] = getc(stdin); |
130 |
> |
scanout[x][BLU] = getc(stdin); |
131 |
> |
} |
132 |
> |
if (feof(stdin) | ferror(stdin)) |
133 |
|
quiterr("error reading AVS image"); |
134 |
|
/* undo gamma */ |
135 |
|
gambs_colrs(scanout, xmax); |
139 |
|
quiterr("error writing Radiance picture"); |
140 |
|
} |
141 |
|
/* free scanline */ |
142 |
< |
free((char *)scanout); |
142 |
> |
free((void *)scanout); |
143 |
|
} |
144 |
|
|
145 |
|
|
169 |
|
quiterr("error writing AVS file"); |
170 |
|
} |
171 |
|
/* free scanline */ |
172 |
< |
free((char *)scanin); |
172 |
> |
free((void *)scanin); |
173 |
|
} |