ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_rgbe.c
Revision: 2.6
Committed: Thu Nov 18 09:55:20 1993 UTC (30 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.5: +1 -2 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 * program to convert from RADIANCE RLE to flat format
9 */
10
11 #include <stdio.h>
12 #include <math.h>
13 #include "color.h"
14 #include "resolu.h"
15
16 #ifdef MSDOS
17 #include <fcntl.h>
18 #endif
19
20 extern char *malloc();
21
22 int bradj = 0; /* brightness adjustment */
23
24 int doflat = 1; /* produce flat file */
25
26 char *progname;
27
28
29 main(argc, argv)
30 int argc;
31 char *argv[];
32 {
33 int i;
34 #ifdef MSDOS
35 extern int _fmode;
36 _fmode = O_BINARY;
37 setmode(fileno(stdin), O_BINARY);
38 setmode(fileno(stdout), O_BINARY);
39 #endif
40 progname = argv[0];
41
42 for (i = 1; i < argc; i++)
43 if (argv[i][0] == '-')
44 switch (argv[i][1]) {
45 case 'r':
46 doflat = !doflat;
47 break;
48 case 'e':
49 if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
50 goto userr;
51 bradj = atoi(argv[++i]);
52 break;
53 default:
54 goto userr;
55 }
56 else
57 break;
58
59 if (i < argc-2)
60 goto userr;
61 if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) {
62 fprintf(stderr, "%s: can't open input \"%s\"\n",
63 progname, argv[i]);
64 exit(1);
65 }
66 if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) {
67 fprintf(stderr, "%s: can't open output \"%s\"\n",
68 progname, argv[i+1]);
69 exit(1);
70 }
71 transfer();
72 exit(0);
73 userr:
74 fprintf(stderr, "Usage: %s [-r][-e +/-stops] [input [output]]\n",
75 progname);
76 exit(1);
77 }
78
79
80 quiterr(err) /* print message and exit */
81 char *err;
82 {
83 if (err != NULL) {
84 fprintf(stderr, "%s: %s\n", progname, err);
85 exit(1);
86 }
87 exit(0);
88 }
89
90
91 transfer() /* transfer Radiance picture */
92 {
93 int order;
94 int xmax, ymax;
95 COLR *scanin;
96 int y;
97 /* get header info. */
98 if (checkheader(stdin, COLRFMT, stdout) < 0 ||
99 (order = fgetresolu(&xmax, &ymax, stdin)) < 0)
100 quiterr("bad picture format");
101 fputs(progname, stdout);
102 if (bradj)
103 printf(" -e %+d", bradj);
104 if (doflat)
105 fputs("\n", stdout);
106 else {
107 fputs(" -r\n", stdout);
108 fputformat(COLRFMT, stdout);
109 }
110 if (bradj)
111 fputexpos(pow(2.0, (double)bradj), stdout);
112 fputs("\n", stdout);
113 fputresolu(order, xmax, ymax, stdout);
114 /* allocate scanline */
115 scanin = (COLR *)malloc(xmax*sizeof(COLR));
116 if (scanin == NULL)
117 quiterr("out of memory in transfer");
118 /* convert image */
119 for (y = ymax-1; y >= 0; y--) {
120 if (freadcolrs(scanin, xmax, stdin) < 0)
121 quiterr("error reading input picture");
122 if (bradj)
123 shiftcolrs(scanin, xmax, bradj);
124 if (doflat)
125 fwrite((char *)scanin, sizeof(COLR), xmax, stdout);
126 else
127 fwritecolrs(scanin, xmax, stdout);
128 if (ferror(stdout))
129 quiterr("error writing output picture");
130 }
131 /* free scanline */
132 free((char *)scanin);
133 }