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.3 by greg, Sat Oct 20 11:41:29 1990 UTC vs.
Revision 2.2 by greg, Thu Dec 19 14:52:17 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1990 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include  "color.h"
16  
17 < extern double  atof(), pow();
17 > #include  "resolu.h"
18  
19 < double  gamma = 2.0;                    /* gamma correction */
19 > extern double  pow();
20  
21 + double  gamma = 2.2;                    /* gamma correction */
22 +
23 + int  bradj = 0;                         /* brightness adjustment */
24 +
25   char  *progname;
26  
27   int  xmax, ymax;
# Line 33 | Line 37 | char  *argv[];
37          
38          progname = argv[0];
39  
40 +        head.ras_type = RT_STANDARD;
41          for (i = 1; i < argc; i++)
42                  if (argv[i][0] == '-')
43                          switch (argv[i][1]) {
44                          case 'g':
45                                  gamma = atof(argv[++i]);
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                          case 'r':
53 <                                reverse = !reverse;
53 >                                if (!strcmp(argv[i], "-rgb"))
54 >                                        head.ras_type = RT_FORMAT_RGB;
55 >                                else
56 >                                        reverse = 1;
57                                  break;
58                          default:
59                                  goto userr;
# Line 69 | Line 82 | char  *argv[];
82                          quiterr("bad raster format");
83                  xmax = head.ras_width;
84                  ymax = head.ras_height;
85 <                if (head.ras_type != RT_STANDARD ||
86 <                                head.ras_maptype != RMT_NONE ||
87 <                                head.ras_depth != 24)
85 >                if ((head.ras_type != RT_STANDARD
86 >                                        && head.ras_type != RT_FORMAT_RGB)
87 >                                || head.ras_maptype != RMT_NONE
88 >                                || head.ras_depth != 24)
89                          quiterr("incompatible format");
90                                          /* put header */
91                  printargs(i, argv, stdout);
92 +                fputformat(COLRFMT, stdout);
93                  putchar('\n');
94 <                fputresolu(YMAJOR|YDECR, xmax, ymax, stdout);
94 >                fprtresolu(xmax, ymax, stdout);
95                                          /* convert file */
96 <                pr2ra();
96 >                pr2ra(head.ras_type);
97          } else {
98 <                                        /* discard input header */
99 <                getheader(stdin, NULL);
100 <                                        /* get resolution */
101 <                if (fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR))
87 <                        quiterr("bad picture size");
98 >                                        /* get header info. */
99 >                if (checkheader(stdin, COLRFMT, NULL) < 0 ||
100 >                                fgetresolu(&xmax, &ymax, stdin) < 0)
101 >                        quiterr("bad picture format");
102                                          /* write rasterfile header */
103                  head.ras_magic = RAS_MAGIC;
104                  head.ras_width = xmax;
105                  head.ras_height = ymax;
106                  head.ras_depth = 24;
107                  head.ras_length = xmax*ymax*3;
94                head.ras_type = RT_STANDARD;
108                  head.ras_maptype = RMT_NONE;
109                  head.ras_maplength = 0;
110                  fwrite((char *)&head, sizeof(head), 1, stdout);
111                                          /* convert file */
112 <                ra2pr();
112 >                ra2pr(head.ras_type);
113          }
114          exit(0);
115   userr:
116 <        fprintf(stderr, "Usage: %s [-r][-g gamma] [input [output]]\n",
116 >        fprintf(stderr, "Usage: %s [-r][-g gamma][-e +/-stops] [input [output]]\n",
117                          progname);
118          exit(1);
119   }
# Line 117 | Line 130 | char  *err;
130   }
131  
132  
133 < pr2ra()                 /* convert 24-bit scanlines to Radiance picture */
133 > pr2ra(rf)               /* convert 24-bit scanlines to Radiance picture */
134 > int     rf;
135   {
136          COLR    *scanout;
137          register int    x;
# Line 128 | Line 142 | pr2ra()                        /* convert 24-bit scanlines to Radiance pict
142                  quiterr("out of memory in pr2ra");
143                                                  /* convert image */
144          for (y = ymax-1; y >= 0; y--) {
145 <                for (x = 0; x < xmax; x++) {
146 <                        scanout[x][RED] = getc(stdin);
147 <                        scanout[x][GRN] = getc(stdin);
148 <                        scanout[x][BLU] = getc(stdin);
149 <                }
145 >                if (rf == RT_FORMAT_RGB)
146 >                        for (x = 0; x < xmax; x++) {
147 >                                scanout[x][RED] = getc(stdin);
148 >                                scanout[x][GRN] = getc(stdin);
149 >                                scanout[x][BLU] = getc(stdin);
150 >                        }
151 >                else
152 >                        for (x = 0; x < xmax; x++) {
153 >                                scanout[x][BLU] = getc(stdin);
154 >                                scanout[x][GRN] = getc(stdin);
155 >                                scanout[x][RED] = getc(stdin);
156 >                        }
157                  if (feof(stdin) || ferror(stdin))
158                          quiterr("error reading rasterfile");
159                  gambs_colrs(scanout, xmax);
160 +                if (bradj)
161 +                        shiftcolrs(scanout, xmax, bradj);
162                  if (fwritecolrs(scanout, xmax, stdout) < 0)
163                          quiterr("error writing Radiance picture");
164          }
# Line 144 | Line 167 | pr2ra()                        /* convert 24-bit scanlines to Radiance pict
167   }
168  
169  
170 < ra2pr()                 /* convert Radiance scanlines to 24-bit rasterfile */
170 > ra2pr(rf)               /* convert Radiance scanlines to 24-bit rasterfile */
171 > int  rf;
172   {
173          COLR    *scanin;
174          register int    x;
# Line 152 | Line 176 | ra2pr()                        /* convert Radiance scanlines to 24-bit rast
176                                                  /* allocate scanline */
177          scanin = (COLR *)malloc(xmax*sizeof(COLR));
178          if (scanin == NULL)
179 <                quiterr("out of memory in pr2ra");
179 >                quiterr("out of memory in ra2pr");
180                                                  /* convert image */
181          for (y = ymax-1; y >= 0; y--) {
182                  if (freadcolrs(scanin, xmax, stdin) < 0)
183                          quiterr("error reading Radiance picture");
184 +                if (bradj)
185 +                        shiftcolrs(scanin, xmax, bradj);
186                  colrs_gambs(scanin, xmax);
187 <                for (x = 0; x < xmax; x++) {
188 <                        putc(scanin[x][RED], stdout);
189 <                        putc(scanin[x][GRN], stdout);
190 <                        putc(scanin[x][BLU], stdout);
191 <                }
187 >                if (rf == RT_FORMAT_RGB)
188 >                        for (x = 0; x < xmax; x++) {
189 >                                putc(scanin[x][RED], stdout);
190 >                                putc(scanin[x][GRN], stdout);
191 >                                putc(scanin[x][BLU], stdout);
192 >                        }
193 >                else
194 >                        for (x = 0; x < xmax; x++) {
195 >                                putc(scanin[x][BLU], stdout);
196 >                                putc(scanin[x][GRN], stdout);
197 >                                putc(scanin[x][RED], stdout);
198 >                        }
199                  if (ferror(stdout))
200                          quiterr("error writing rasterfile");
201          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines