ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_rgbe.c
Revision: 1.1
Committed: Fri Aug 23 17:37:14 1991 UTC (32 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1991 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    
13     #include "color.h"
14    
15     int bradj = 0; /* brightness adjustment */
16    
17     int doflat = 1; /* produce flat file */
18    
19     char *progname;
20    
21    
22     main(argc, argv)
23     int argc;
24     char *argv[];
25     {
26     int i;
27    
28     progname = argv[0];
29    
30     for (i = 1; i < argc; i++)
31     if (argv[i][0] == '-')
32     switch (argv[i][1]) {
33     case 'r':
34     doflat = !doflat;
35     break;
36     case 'e':
37     if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
38     goto userr;
39     bradj = atoi(argv[++i]);
40     break;
41     default:
42     goto userr;
43     }
44     else
45     break;
46    
47     if (i < argc-2)
48     goto userr;
49     if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) {
50     fprintf(stderr, "%s: can't open input \"%s\"\n",
51     progname, argv[i]);
52     exit(1);
53     }
54     if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) {
55     fprintf(stderr, "can't open output \"%s\"\n",
56     progname, argv[i+1]);
57     exit(1);
58     }
59     transfer();
60     exit(0);
61     userr:
62     fprintf(stderr, "Usage: %s [-r][-e +/-stops] [input [output]]\n",
63     progname);
64     exit(1);
65     }
66    
67    
68     quiterr(err) /* print message and exit */
69     char *err;
70     {
71     if (err != NULL) {
72     fprintf(stderr, "%s: %s\n", progname, err);
73     exit(1);
74     }
75     exit(0);
76     }
77    
78    
79     transfer() /* transfer Radiance picture */
80     {
81     extern double pow();
82     int xmax, ymax;
83     COLR *scanin;
84     register int x;
85     int y;
86     /* get header info. */
87     if (checkheader(stdin, COLRFMT, stdout) < 0 ||
88     fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR))
89     quiterr("bad picture format");
90     if (bradj)
91     fputexpos(pow(2.0, (double)bradj), stdout);
92     if (!doflat) {
93     fputformat(COLRFMT, stdout);
94     printf("%s -r\n\n", progname);
95     } else
96     printf("%s\n\n", progname);
97     fputresolu(YMAJOR|YDECR, xmax, ymax, stdout);
98     /* allocate scanline */
99     scanin = (COLR *)malloc(xmax*sizeof(COLR));
100     if (scanin == NULL)
101     quiterr("out of memory in transfer");
102     /* convert image */
103     for (y = ymax-1; y >= 0; y--) {
104     if (freadcolrs(scanin, xmax, stdin) < 0)
105     quiterr("error reading input picture");
106     if (bradj)
107     shiftcolrs(scanin, xmax, bradj);
108     if (doflat)
109     fwrite((char *)scanin, sizeof(COLR), xmax, stdout);
110     else
111     fwritecolrs(scanin, xmax, stdout);
112     if (ferror(stdout))
113     quiterr("error writing rasterfile");
114     }
115     /* free scanline */
116     free((char *)scanin);
117     }