ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_rgbe.c
Revision: 2.3
Committed: Mon Sep 21 12:15:13 1992 UTC (31 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +12 -2 lines
Log Message:
Changes for PC port

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 #ifdef MSDOS
13 #include <fcntl.h>
14 #endif
15
16 #include "color.h"
17 #include "resolu.h"
18
19 extern char *malloc();
20
21 int bradj = 0; /* brightness adjustment */
22
23 int doflat = 1; /* produce flat file */
24
25 char *progname;
26
27
28 main(argc, argv)
29 int argc;
30 char *argv[];
31 {
32 int i;
33 #ifdef MSDOS
34 extern int _fmode;
35 _fmode = O_BINARY;
36 setmode(fileno(stdin), O_BINARY);
37 setmode(fileno(stdout), O_BINARY);
38 #endif
39 progname = argv[0];
40
41 for (i = 1; i < argc; i++)
42 if (argv[i][0] == '-')
43 switch (argv[i][1]) {
44 case 'r':
45 doflat = !doflat;
46 break;
47 case 'e':
48 if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
49 goto userr;
50 bradj = atoi(argv[++i]);
51 break;
52 default:
53 goto userr;
54 }
55 else
56 break;
57
58 if (i < argc-2)
59 goto userr;
60 if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) {
61 fprintf(stderr, "%s: can't open input \"%s\"\n",
62 progname, argv[i]);
63 exit(1);
64 }
65 if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) {
66 fprintf(stderr, "can't open output \"%s\"\n",
67 progname, argv[i+1]);
68 exit(1);
69 }
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 extern double pow();
93 int order;
94 int xmax, ymax;
95 COLR *scanin;
96 register int x;
97 int y;
98 /* get header info. */
99 if (checkheader(stdin, COLRFMT, stdout) < 0 ||
100 (order = fgetresolu(&xmax, &ymax, stdin)) < 0)
101 quiterr("bad picture format");
102 fputs(progname, stdout);
103 if (bradj)
104 printf(" -e %+d", bradj);
105 if (doflat)
106 fputs("\n", stdout);
107 else {
108 fputs(" -r\n", stdout);
109 fputformat(COLRFMT, stdout);
110 }
111 if (bradj)
112 fputexpos(pow(2.0, (double)bradj), stdout);
113 fputs("\n", stdout);
114 fputresolu(order, xmax, ymax, stdout);
115 /* allocate scanline */
116 scanin = (COLR *)malloc(xmax*sizeof(COLR));
117 if (scanin == NULL)
118 quiterr("out of memory in transfer");
119 /* convert image */
120 for (y = ymax-1; y >= 0; y--) {
121 if (freadcolrs(scanin, xmax, stdin) < 0)
122 quiterr("error reading input picture");
123 if (bradj)
124 shiftcolrs(scanin, xmax, bradj);
125 if (doflat)
126 fwrite((char *)scanin, sizeof(COLR), xmax, stdout);
127 else
128 fwritecolrs(scanin, xmax, stdout);
129 if (ferror(stdout))
130 quiterr("error writing rasterfile");
131 }
132 /* free scanline */
133 free((char *)scanin);
134 }