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.1 by greg, Thu Oct 18 12:00:48 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 60 | Line 73 | char  *argv[];
73                                  progname, argv[i+1]);
74                  exit(1);
75          }
76 +        setcolrgam(gamma);
77          if (reverse) {
78                                          /* get header */
79                  if (fread((char *)&head, sizeof(head), 1, stdin) != 1)
# Line 68 | 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))
86 <                        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;
93                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 116 | 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 <        float   gmap[256];
122 <        int     r, g, b;
123 <        COLOR   *scanout;
136 >        COLR    *scanout;
137          register int    x;
138          int     y;
139                                                  /* allocate scanline */
140 <        scanout = (COLOR *)malloc(xmax*sizeof(COLOR));
140 >        scanout = (COLR *)malloc(xmax*sizeof(COLR));
141          if (scanout == NULL)
142                  quiterr("out of memory in pr2ra");
130                                                /* compute gamma correction */
131        for (x = 0; x < 256; x++)
132                gmap[x] = pow((x+.5)/256., gamma);
143                                                  /* convert image */
144          for (y = ymax-1; y >= 0; y--) {
145 <                for (x = 0; x < xmax; x++) {
146 <                        r = getc(stdin); g = getc(stdin);
147 <                        if ((b = getc(stdin)) == EOF)
148 <                                quiterr("error reading rasterfile");
149 <                        setcolor(scanout[x], gmap[r], gmap[g], gmap[b]);
150 <                }
151 <                if (fwritescan(scanout, xmax, stdout) < 0)
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          }
165                                                  /* free scanline */
# Line 146 | 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 < #define map(v)  ((v)>=1.0 ? 255 : gmap[(int)(1024.*(v))])
152 <        unsigned char   gmap[1024];
153 <        COLOR   *scanin;
173 >        COLR    *scanin;
174          register int    x;
155        register int    c;
175          int     y;
176                                                  /* allocate scanline */
177 <        scanin = (COLOR *)malloc(xmax*sizeof(COLOR));
177 >        scanin = (COLR *)malloc(xmax*sizeof(COLR));
178          if (scanin == NULL)
179 <                quiterr("out of memory in pr2ra");
161 <                                                /* compute gamma correction */
162 <        for (x = 0; x < 256; x++)
163 <                gmap[x] = 256.*pow((x+.5)/1024., 1./gamma);
179 >                quiterr("out of memory in ra2pr");
180                                                  /* convert image */
181          for (y = ymax-1; y >= 0; y--) {
182 <                if (freadscan(scanin, xmax, stdin) < 0)
182 >                if (freadcolrs(scanin, xmax, stdin) < 0)
183                          quiterr("error reading Radiance picture");
184 <                for (x = 0; x < xmax; x++) {
185 <                        c = map(colval(scanin[x],RED));
186 <                        putc(c, stdout);
187 <                        c = map(colval(scanin[x],GRN));
188 <                        putc(c, stdout);
189 <                        c = map(colval(scanin[x],BLU));
190 <                        putc(c, stdout);
191 <                }
184 >                if (bradj)
185 >                        shiftcolrs(scanin, xmax, bradj);
186 >                colrs_gambs(scanin, xmax);
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          }
202                                                  /* free scanline */
203          free((char *)scanin);
181 #undef map
204   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines