ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_rgbe.c
Revision: 2.6
Committed: Thu Nov 18 09:55:20 1993 UTC (30 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.5: +1 -2 lines
Log Message:
minor compiler warning fixes

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 greg 2.3 #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 greg 1.1 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 greg 2.6 fprintf(stderr, "%s: can't open output \"%s\"\n",
68 greg 1.1 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 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     if (checkheader(stdin, COLRFMT, stdout) < 0 ||
99 greg 1.2 (order = fgetresolu(&xmax, &ymax, stdin)) < 0)
100 greg 1.1 quiterr("bad picture format");
101 greg 2.2 fputs(progname, stdout);
102 greg 1.1 if (bradj)
103 greg 2.2 printf(" -e %+d", bradj);
104     if (doflat)
105     fputs("\n", stdout);
106     else {
107     fputs(" -r\n", stdout);
108     fputformat(COLRFMT, stdout);
109     }
110     if (bradj)
111 greg 1.1 fputexpos(pow(2.0, (double)bradj), stdout);
112 greg 2.2 fputs("\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     for (y = ymax-1; y >= 0; y--) {
120     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     }