ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_pr24.c
(Generate patch)

Comparing ray/src/px/ra_pr24.c (file contents):
Revision 1.4 by greg, Wed Jan 9 15:33:20 1991 UTC vs.
Revision 2.3 by greg, Mon Sep 21 12:15:02 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1990 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include  <stdio.h>
12  
13 + #ifdef MSDOS
14 + #include  <fcntl.h>
15 + #endif
16 +
17   #include  "rasterfile.h"
18  
19   #include  "color.h"
20  
21 < extern double  atof(), pow();
21 > #include  "resolu.h"
22  
23 < double  gamma = 2.0;                    /* gamma correction */
23 > extern double  pow();
24  
25 + extern char  *malloc();
26 +
27 + double  gamma = 2.2;                    /* gamma correction */
28 +
29 + int  bradj = 0;                         /* brightness adjustment */
30 +
31   char  *progname;
32  
33   int  xmax, ymax;
# Line 30 | Line 40 | char  *argv[];
40          struct rasterfile  head;
41          int  reverse = 0;
42          int  i;
43 <        
43 > #ifdef MSDOS
44 >        extern int  _fmode;
45 >        _fmode = O_BINARY;
46 >        setmode(fileno(stdin), O_BINARY);
47 >        setmode(fileno(stdout), O_BINARY);
48 > #endif
49          progname = argv[0];
50  
51 +        head.ras_type = RT_STANDARD;
52          for (i = 1; i < argc; i++)
53                  if (argv[i][0] == '-')
54                          switch (argv[i][1]) {
55                          case 'g':
56                                  gamma = atof(argv[++i]);
57                                  break;
58 +                        case 'e':
59 +                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
60 +                                        goto userr;
61 +                                bradj = atoi(argv[++i]);
62 +                                break;
63                          case 'r':
64 <                                reverse = !reverse;
64 >                                if (!strcmp(argv[i], "-rgb"))
65 >                                        head.ras_type = RT_FORMAT_RGB;
66 >                                else
67 >                                        reverse = 1;
68                                  break;
69                          default:
70                                  goto userr;
# Line 69 | Line 93 | char  *argv[];
93                          quiterr("bad raster format");
94                  xmax = head.ras_width;
95                  ymax = head.ras_height;
96 <                if (head.ras_type != RT_STANDARD ||
97 <                                head.ras_maptype != RMT_NONE ||
98 <                                head.ras_depth != 24)
96 >                if ((head.ras_type != RT_STANDARD
97 >                                        && head.ras_type != RT_FORMAT_RGB)
98 >                                || head.ras_maptype != RMT_NONE
99 >                                || head.ras_depth != 24)
100                          quiterr("incompatible format");
101                                          /* put header */
102                  printargs(i, argv, stdout);
103 +                fputformat(COLRFMT, stdout);
104                  putchar('\n');
105 <                fputresolu(YMAJOR|YDECR, xmax, ymax, stdout);
105 >                fprtresolu(xmax, ymax, stdout);
106                                          /* convert file */
107 <                pr2ra();
107 >                pr2ra(head.ras_type);
108          } else {
109 <                                        /* discard input header */
110 <                getheader(stdin, NULL);
111 <                                        /* get resolution */
112 <                if (fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR))
87 <                        quiterr("bad picture size");
109 >                                        /* get header info. */
110 >                if (checkheader(stdin, COLRFMT, NULL) < 0 ||
111 >                                fgetresolu(&xmax, &ymax, stdin) < 0)
112 >                        quiterr("bad picture format");
113                                          /* write rasterfile header */
114                  head.ras_magic = RAS_MAGIC;
115                  head.ras_width = xmax;
116                  head.ras_height = ymax;
117                  head.ras_depth = 24;
118                  head.ras_length = xmax*ymax*3;
94                head.ras_type = RT_STANDARD;
119                  head.ras_maptype = RMT_NONE;
120                  head.ras_maplength = 0;
121                  fwrite((char *)&head, sizeof(head), 1, stdout);
122                                          /* convert file */
123 <                ra2pr();
123 >                ra2pr(head.ras_type);
124          }
125          exit(0);
126   userr:
127 <        fprintf(stderr, "Usage: %s [-r][-g gamma] [input [output]]\n",
127 >        fprintf(stderr, "Usage: %s [-r][-g gamma][-e +/-stops] [input [output]]\n",
128                          progname);
129          exit(1);
130   }
# Line 117 | Line 141 | char  *err;
141   }
142  
143  
144 < pr2ra()                 /* convert 24-bit scanlines to Radiance picture */
144 > pr2ra(rf)               /* convert 24-bit scanlines to Radiance picture */
145 > int     rf;
146   {
147          COLR    *scanout;
148          register int    x;
# Line 128 | Line 153 | pr2ra()                        /* convert 24-bit scanlines to Radiance pict
153                  quiterr("out of memory in pr2ra");
154                                                  /* convert image */
155          for (y = ymax-1; y >= 0; y--) {
156 <                for (x = 0; x < xmax; x++) {
157 <                        scanout[x][BLU] = getc(stdin);
158 <                        scanout[x][GRN] = getc(stdin);
159 <                        scanout[x][RED] = getc(stdin);
160 <                }
156 >                if (rf == RT_FORMAT_RGB)
157 >                        for (x = 0; x < xmax; x++) {
158 >                                scanout[x][RED] = getc(stdin);
159 >                                scanout[x][GRN] = getc(stdin);
160 >                                scanout[x][BLU] = getc(stdin);
161 >                        }
162 >                else
163 >                        for (x = 0; x < xmax; x++) {
164 >                                scanout[x][BLU] = getc(stdin);
165 >                                scanout[x][GRN] = getc(stdin);
166 >                                scanout[x][RED] = getc(stdin);
167 >                        }
168                  if (feof(stdin) || ferror(stdin))
169                          quiterr("error reading rasterfile");
170                  gambs_colrs(scanout, xmax);
171 +                if (bradj)
172 +                        shiftcolrs(scanout, xmax, bradj);
173                  if (fwritecolrs(scanout, xmax, stdout) < 0)
174                          quiterr("error writing Radiance picture");
175          }
# Line 144 | Line 178 | pr2ra()                        /* convert 24-bit scanlines to Radiance pict
178   }
179  
180  
181 < ra2pr()                 /* convert Radiance scanlines to 24-bit rasterfile */
181 > ra2pr(rf)               /* convert Radiance scanlines to 24-bit rasterfile */
182 > int  rf;
183   {
184          COLR    *scanin;
185          register int    x;
# Line 152 | Line 187 | ra2pr()                        /* convert Radiance scanlines to 24-bit rast
187                                                  /* allocate scanline */
188          scanin = (COLR *)malloc(xmax*sizeof(COLR));
189          if (scanin == NULL)
190 <                quiterr("out of memory in pr2ra");
190 >                quiterr("out of memory in ra2pr");
191                                                  /* convert image */
192          for (y = ymax-1; y >= 0; y--) {
193                  if (freadcolrs(scanin, xmax, stdin) < 0)
194                          quiterr("error reading Radiance picture");
195 +                if (bradj)
196 +                        shiftcolrs(scanin, xmax, bradj);
197                  colrs_gambs(scanin, xmax);
198 <                for (x = 0; x < xmax; x++) {
199 <                        putc(scanin[x][BLU], stdout);
200 <                        putc(scanin[x][GRN], stdout);
201 <                        putc(scanin[x][RED], stdout);
202 <                }
198 >                if (rf == RT_FORMAT_RGB)
199 >                        for (x = 0; x < xmax; x++) {
200 >                                putc(scanin[x][RED], stdout);
201 >                                putc(scanin[x][GRN], stdout);
202 >                                putc(scanin[x][BLU], stdout);
203 >                        }
204 >                else
205 >                        for (x = 0; x < xmax; x++) {
206 >                                putc(scanin[x][BLU], stdout);
207 >                                putc(scanin[x][GRN], stdout);
208 >                                putc(scanin[x][RED], stdout);
209 >                        }
210                  if (ferror(stdout))
211                          quiterr("error writing rasterfile");
212          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines