ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_rgbe.c
Revision: 2.5
Committed: Tue Apr 27 12:37:23 1993 UTC (31 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.4: +1 -1 lines
Log Message:
fixed incorrect error message

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, "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 register int x;
97 int y;
98 /* get header info. */
99 if (checkheader(stdin, COLRFMT, stdout) < 0 ||
100 (order = fgetresolu(&xmax, &ymax, stdin)) < 0)
101 quiterr("bad picture format");
102 fputs(progname, stdout);
103 if (bradj)
104 printf(" -e %+d", bradj);
105 if (doflat)
106 fputs("\n", stdout);
107 else {
108 fputs(" -r\n", stdout);
109 fputformat(COLRFMT, stdout);
110 }
111 if (bradj)
112 fputexpos(pow(2.0, (double)bradj), stdout);
113 fputs("\n", stdout);
114 fputresolu(order, xmax, ymax, stdout);
115 /* allocate scanline */
116 scanin = (COLR *)malloc(xmax*sizeof(COLR));
117 if (scanin == NULL)
118 quiterr("out of memory in transfer");
119 /* convert image */
120 for (y = ymax-1; y >= 0; y--) {
121 if (freadcolrs(scanin, xmax, stdin) < 0)
122 quiterr("error reading input picture");
123 if (bradj)
124 shiftcolrs(scanin, xmax, bradj);
125 if (doflat)
126 fwrite((char *)scanin, sizeof(COLR), xmax, stdout);
127 else
128 fwritecolrs(scanin, xmax, stdout);
129 if (ferror(stdout))
130 quiterr("error writing output picture");
131 }
132 /* free scanline */
133 free((char *)scanin);
134 }