ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_rgbe.c
Revision: 2.1
Committed: Tue Nov 12 16:05:45 1991 UTC (32 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +0 -0 lines
Log Message:
updated revision number for release 2.0

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