ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_skel.c
Revision: 2.8
Committed: Thu Nov 18 09:55:24 1993 UTC (30 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.7: +1 -1 lines
Log Message:
minor compiler warning fixes

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 #include <math.h>
23 #ifdef MSDOS
24 #include <fcntl.h>
25 #endif
26 #include "color.h"
27 #include "resolu.h"
28
29 extern char *malloc();
30
31 double gamcor = 2.2; /* gamma correction */
32
33 int bradj = 0; /* brightness adjustment */
34
35 char *progname;
36
37 int xmax, ymax;
38
39
40 main(argc, argv)
41 int argc;
42 char *argv[];
43 {
44 int reverse = 0;
45 int i;
46
47 progname = argv[0];
48
49 for (i = 1; i < argc; i++)
50 if (argv[i][0] == '-')
51 switch (argv[i][1]) {
52 case 'g': /* gamma correction */
53 gamcor = atof(argv[++i]);
54 break;
55 case 'e': /* exposure adjustment */
56 if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
57 goto userr;
58 bradj = atoi(argv[++i]);
59 break;
60 case 'r': /* reverse conversion */
61 reverse = 1;
62 break;
63 default:
64 goto userr;
65 }
66 else
67 break;
68
69 if (i < argc-2)
70 goto userr;
71 if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) {
72 fprintf(stderr, "%s: can't open input \"%s\"\n",
73 progname, argv[i]);
74 exit(1);
75 }
76 if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) {
77 fprintf(stderr, "%s: can't open output \"%s\"\n",
78 progname, argv[i+1]);
79 exit(1);
80 }
81 #ifdef MSDOS
82 setmode(fileno(stdin), O_BINARY);
83 setmode(fileno(stdout), O_BINARY);
84 #endif
85 setcolrgam(gamcor); /* set up gamma correction */
86 if (reverse) {
87 /* get their image resolution */
88 read_skel_head(&xmax, &ymax);
89 /* put our header */
90 printargs(i, argv, stdout);
91 fputformat(COLRFMT, stdout);
92 putchar('\n');
93 fprtresolu(xmax, ymax, stdout);
94 /* convert file */
95 skel2ra();
96 } else {
97 /* get our header */
98 if (checkheader(stdin, COLRFMT, NULL) < 0 ||
99 fgetresolu(&xmax, &ymax, stdin) < 0)
100 quiterr("bad picture format");
101 /* write their header */
102 write_skel_head(xmax, ymax);
103 /* convert file */
104 ra2skel();
105 }
106 exit(0);
107 userr:
108 fprintf(stderr,
109 "Usage: %s [-r][-g gamma][-e +/-stops] [input [output]]\n",
110 progname);
111 exit(1);
112 }
113
114
115 quiterr(err) /* print message and exit */
116 char *err;
117 {
118 if (err != NULL) {
119 fprintf(stderr, "%s: %s\n", progname, err);
120 exit(1);
121 }
122 exit(0);
123 }
124
125
126 skel2ra() /* convert 24-bit scanlines to Radiance picture */
127 {
128 COLR *scanout;
129 register int x;
130 int y;
131 /* allocate scanline */
132 scanout = (COLR *)malloc(xmax*sizeof(COLR));
133 if (scanout == NULL)
134 quiterr("out of memory in skel2ra");
135 /* convert image */
136 for (y = ymax-1; y >= 0; y--) {
137 for (x = 0; x < xmax; x++) {
138 scanout[x][RED] = getc(stdin);
139 scanout[x][GRN] = getc(stdin);
140 scanout[x][BLU] = getc(stdin);
141 }
142 if (feof(stdin) | ferror(stdin))
143 quiterr("error reading skel image");
144 /* undo gamma */
145 gambs_colrs(scanout, xmax);
146 if (bradj) /* adjust exposure */
147 shiftcolrs(scanout, xmax, bradj);
148 if (fwritecolrs(scanout, xmax, stdout) < 0)
149 quiterr("error writing Radiance picture");
150 }
151 /* free scanline */
152 free((char *)scanout);
153 }
154
155
156 ra2skel() /* convert Radiance scanlines to 24-bit */
157 {
158 COLR *scanin;
159 register int x;
160 int y;
161 /* allocate scanline */
162 scanin = (COLR *)malloc(xmax*sizeof(COLR));
163 if (scanin == NULL)
164 quiterr("out of memory in ra2skel");
165 /* convert image */
166 for (y = ymax-1; y >= 0; y--) {
167 if (freadcolrs(scanin, xmax, stdin) < 0)
168 quiterr("error reading Radiance picture");
169 if (bradj) /* adjust exposure */
170 shiftcolrs(scanin, xmax, bradj);
171 colrs_gambs(scanin, xmax); /* gamma correction */
172 for (x = 0; x < xmax; x++) {
173 putc(scanin[x][RED], stdout);
174 putc(scanin[x][GRN], stdout);
175 putc(scanin[x][BLU], stdout);
176 }
177 if (ferror(stdout))
178 quiterr("error writing skel file");
179 }
180 /* free scanline */
181 free((char *)scanin);
182 }