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

# Content
1 /* Copyright (c) 1992 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 #include <math.h>
13 #include "color.h"
14 #include "resolu.h"
15
16 #ifdef MSDOS
17 #include <fcntl.h>
18 #endif
19
20 extern char *malloc();
21
22 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
35 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 fprintf(stderr, "%s: can't open output \"%s\"\n",
63 progname, argv[i+1]);
64 exit(1);
65 }
66 #ifdef MSDOS
67 setmode(fileno(stdin), O_BINARY);
68 setmode(fileno(stdout), O_BINARY);
69 #endif
70 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 static char ourfmt[LPICFMT+1] = PICFMT;
93 int order;
94 int xmax, ymax;
95 COLR *scanin;
96 int y;
97 /* get header info. */
98 if ((y = checkheader(stdin, ourfmt, stdout)) < 0 ||
99 (order = fgetresolu(&xmax, &ymax, stdin)) < 0)
100 quiterr("bad picture format");
101 if (!y)
102 strcpy(ourfmt, COLRFMT);
103 fputs(progname, stdout);
104 if (bradj)
105 fprintf(stdout, " -e %+d", bradj);
106 if (!doflat)
107 fputs(" -r", stdout);
108 fputc('\n', stdout);
109 if (bradj)
110 fputexpos(pow(2.0, (double)bradj), stdout);
111 fputformat(ourfmt, stdout);
112 fputc('\n', stdout);
113 fputresolu(order, xmax, ymax, stdout);
114 /* 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; 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 quiterr("error writing output picture");
130 }
131 /* free scanline */
132 free((char *)scanin);
133 }