ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_rgbe.c
Revision: 2.2
Committed: Fri Jan 3 22:58:08 1992 UTC (32 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +11 -6 lines
Log Message:
fixed ordering of output header

File Contents

# User Rev Content
1 greg 2.2 /* Copyright (c) 1992 Regents of the University of California */
2 greg 1.1
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 greg 2.2 fputs(progname, stdout);
93 greg 1.1 if (bradj)
94 greg 2.2 printf(" -e %+d", bradj);
95     if (doflat)
96     fputs("\n", stdout);
97     else {
98     fputs(" -r\n", stdout);
99     fputformat(COLRFMT, stdout);
100     }
101     if (bradj)
102 greg 1.1 fputexpos(pow(2.0, (double)bradj), stdout);
103 greg 2.2 fputs("\n", stdout);
104 greg 1.2 fputresolu(order, xmax, ymax, stdout);
105 greg 1.1 /* allocate scanline */
106     scanin = (COLR *)malloc(xmax*sizeof(COLR));
107     if (scanin == NULL)
108     quiterr("out of memory in transfer");
109     /* convert image */
110     for (y = ymax-1; y >= 0; y--) {
111     if (freadcolrs(scanin, xmax, stdin) < 0)
112     quiterr("error reading input picture");
113     if (bradj)
114     shiftcolrs(scanin, xmax, bradj);
115     if (doflat)
116     fwrite((char *)scanin, sizeof(COLR), xmax, stdout);
117     else
118     fwritecolrs(scanin, xmax, stdout);
119     if (ferror(stdout))
120     quiterr("error writing rasterfile");
121     }
122     /* free scanline */
123     free((char *)scanin);
124     }