ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_rgbe.c
Revision: 2.7
Committed: Fri Jan 23 09:28:29 1998 UTC (26 years, 3 months ago) by gregl
Content type: text/plain
Branch: MAIN
Changes since 2.6: +16 -16 lines
Log Message:
made program work with XYZE images as well as RGBE

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 greg 2.4 #include <math.h>
13     #include "color.h"
14     #include "resolu.h"
15    
16 greg 2.3 #ifdef MSDOS
17     #include <fcntl.h>
18     #endif
19 greg 1.1
20 greg 2.3 extern char *malloc();
21    
22 greg 1.1 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 gregl 2.7
35 greg 1.1 progname = argv[0];
36    
37     for (i = 1; i < argc; i++)
38     if (argv[i][0] == '-')
39     switch (argv[i][1]) {
40     case 'r':
41     doflat = !doflat;
42     break;
43     case 'e':
44     if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
45     goto userr;
46     bradj = atoi(argv[++i]);
47     break;
48     default:
49     goto userr;
50     }
51     else
52     break;
53    
54     if (i < argc-2)
55     goto userr;
56     if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) {
57     fprintf(stderr, "%s: can't open input \"%s\"\n",
58     progname, argv[i]);
59     exit(1);
60     }
61     if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) {
62 greg 2.6 fprintf(stderr, "%s: can't open output \"%s\"\n",
63 greg 1.1 progname, argv[i+1]);
64     exit(1);
65     }
66 gregl 2.7 #ifdef MSDOS
67     setmode(fileno(stdin), O_BINARY);
68     setmode(fileno(stdout), O_BINARY);
69     #endif
70 greg 1.1 transfer();
71     exit(0);
72     userr:
73     fprintf(stderr, "Usage: %s [-r][-e +/-stops] [input [output]]\n",
74     progname);
75     exit(1);
76     }
77    
78    
79     quiterr(err) /* print message and exit */
80     char *err;
81     {
82     if (err != NULL) {
83     fprintf(stderr, "%s: %s\n", progname, err);
84     exit(1);
85     }
86     exit(0);
87     }
88    
89    
90     transfer() /* transfer Radiance picture */
91     {
92 gregl 2.7 static char ourfmt[LPICFMT+1] = PICFMT;
93 greg 1.2 int order;
94 greg 2.3 int xmax, ymax;
95 greg 1.1 COLR *scanin;
96     int y;
97     /* get header info. */
98 gregl 2.7 if ((y = checkheader(stdin, ourfmt, stdout)) < 0 ||
99 greg 1.2 (order = fgetresolu(&xmax, &ymax, stdin)) < 0)
100 greg 1.1 quiterr("bad picture format");
101 gregl 2.7 if (!y)
102     strcpy(ourfmt, COLRFMT);
103 greg 2.2 fputs(progname, stdout);
104 greg 1.1 if (bradj)
105 gregl 2.7 fprintf(stdout, " -e %+d", bradj);
106     if (!doflat)
107     fputs(" -r", stdout);
108     fputc('\n', stdout);
109 greg 2.2 if (bradj)
110 greg 1.1 fputexpos(pow(2.0, (double)bradj), stdout);
111 gregl 2.7 fputformat(ourfmt, stdout);
112     fputc('\n', stdout);
113 greg 1.2 fputresolu(order, xmax, ymax, stdout);
114 greg 1.1 /* allocate scanline */
115     scanin = (COLR *)malloc(xmax*sizeof(COLR));
116     if (scanin == NULL)
117     quiterr("out of memory in transfer");
118     /* convert image */
119 gregl 2.7 for (y = ymax; y--; ) {
120 greg 1.1 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 greg 2.5 quiterr("error writing output picture");
130 greg 1.1 }
131     /* free scanline */
132     free((char *)scanin);
133     }