ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_skel.c
Revision: 2.4
Committed: Thu Dec 17 15:50:13 1992 UTC (31 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.3: +2 -0 lines
Log Message:
fixed munged comment

File Contents

# Content
1 /* Copyright (c) 1992 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * Skeletal 24-bit image conversion program. Replace "skel"
9 * in this file with a more appropriate image type identifier.
10 *
11 * The Makefile entry should look something like this:
12 * ra_skel: ra_skel.o
13 * cc $(CFLAGS) -o ra_skel ra_skel.o -lrt -lm
14 * ra_skel.o: ../common/color.h ../common/resolu.h
15 *
16 * If you like to do things the hard way, you can link directly
17 * to the object files "color.o colrops.o resolu.o header.o" in
18 * the common subdirectory instead of using the -lrt library.
19 */
20
21 #include <stdio.h>
22 #ifdef MSDOS
23 #include <fcntl.h>
24 #endif
25 #include "color.h"
26 #include "resolu.h"
27
28 extern char *malloc();
29
30 double gamma = 2.2; /* gamma correction */
31
32 int bradj = 0; /* brightness adjustment */
33
34 char *progname;
35
36 int xmax, ymax;
37
38
39 main(argc, argv)
40 int argc;
41 char *argv[];
42 {
43 int reverse = 0;
44 int i;
45
46 progname = argv[0];
47
48 for (i = 1; i < argc; i++)
49 if (argv[i][0] == '-')
50 switch (argv[i][1]) {
51 case 'g': /* gamma correction */
52 gamma = atof(argv[++i]);
53 break;
54 case 'e': /* exposure adjustment */
55 if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
56 goto userr;
57 bradj = atoi(argv[++i]);
58 break;
59 case 'r': /* reverse conversion */
60 reverse = 1;
61 break;
62 default:
63 goto userr;
64 }
65 else
66 break;
67
68 if (i < argc-2)
69 goto userr;
70 if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) {
71 fprintf(stderr, "%s: can't open input \"%s\"\n",
72 progname, argv[i]);
73 exit(1);
74 }
75 if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) {
76 fprintf(stderr, "can't open output \"%s\"\n",
77 progname, argv[i+1]);
78 exit(1);
79 }
80 #ifdef MSDOS
81 setmode(fileno(stdin), O_BINARY);
82 setmode(fileno(stdout), O_BINARY);
83 #endif
84 setcolrgam(gamma); /* set up gamma correction */
85 if (reverse) {
86 /* get their image resolution */
87 read_skel_head(&xmax, &ymax);
88 /* put our header */
89 printargs(i, argv, stdout);
90 fputformat(COLRFMT, stdout);
91 putchar('\n');
92 fprtresolu(xmax, ymax, stdout);
93 /* convert file */
94 skel2ra();
95 } else {
96 /* get our header */
97 if (checkheader(stdin, COLRFMT, NULL) < 0 ||
98 fgetresolu(&xmax, &ymax, stdin) < 0)
99 quiterr("bad picture format");
100 /* write their header */
101 write_skel_head(xmax, ymax);
102 /* convert file */
103 ra2skel();
104 }
105 exit(0);
106 userr:
107 fprintf(stderr,
108 "Usage: %s [-r][-g gamma][-e +/-stops] [input [output]]\n",
109 progname);
110 exit(1);
111 }
112
113
114 quiterr(err) /* print message and exit */
115 char *err;
116 {
117 if (err != NULL) {
118 fprintf(stderr, "%s: %s\n", progname, err);
119 exit(1);
120 }
121 exit(0);
122 }
123
124
125 skel2ra() /* convert 24-bit scanlines to Radiance picture */
126 {
127 COLR *scanout;
128 register int x;
129 int y;
130 /* allocate scanline */
131 scanout = (COLR *)malloc(xmax*sizeof(COLR));
132 if (scanout == NULL)
133 quiterr("out of memory in skel2ra");
134 /* convert image */
135 for (y = ymax-1; y >= 0; y--) {
136 scanout[x][RED] = getc(stdin);
137 scanout[x][GRN] = getc(stdin);
138 scanout[x][BLU] = getc(stdin);
139 if (feof(stdin) || ferror(stdin))
140 quiterr("error reading skel image");
141 /* undo gamma */
142 gambs_colrs(scanout, xmax);
143 if (bradj) /* adjust exposure */
144 shiftcolrs(scanout, xmax, bradj);
145 if (fwritecolrs(scanout, xmax, stdout) < 0)
146 quiterr("error writing Radiance picture");
147 }
148 /* free scanline */
149 free((char *)scanout);
150 }
151
152
153 ra2skel() /* convert Radiance scanlines to 24-bit */
154 {
155 COLR *scanin;
156 register int x;
157 int y;
158 /* allocate scanline */
159 scanin = (COLR *)malloc(xmax*sizeof(COLR));
160 if (scanin == NULL)
161 quiterr("out of memory in ra2skel");
162 /* convert image */
163 for (y = ymax-1; y >= 0; y--) {
164 if (freadcolrs(scanin, xmax, stdin) < 0)
165 quiterr("error reading Radiance picture");
166 if (bradj) /* adjust exposure */
167 shiftcolrs(scanin, xmax, bradj);
168 colrs_gambs(scanin, xmax); /* gamma correction */
169 for (x = 0; x < xmax; x++) {
170 putc(scanin[x][RED], stdout);
171 putc(scanin[x][GRN], stdout);
172 putc(scanin[x][BLU], stdout);
173 }
174 if (ferror(stdout))
175 quiterr("error writing skel file");
176 }
177 /* free scanline */
178 free((char *)scanin);
179 }