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.2 by greg, Thu Oct 18 12:21:33 1990 UTC vs.
Revision 1.10 by greg, Mon Oct 14 17:09:39 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 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   extern double  atof(), pow();
18  
19 < double  gamma = 2.0;                    /* gamma correction */
19 > double  gamma = 2.2;                    /* gamma correction */
20  
21 + int  bradj = 0;                         /* brightness adjustment */
22 +
23   char  *progname;
24  
25   int  xmax, ymax;
# Line 33 | Line 35 | char  *argv[];
35          
36          progname = argv[0];
37  
38 +        head.ras_type = RT_STANDARD;
39          for (i = 1; i < argc; i++)
40                  if (argv[i][0] == '-')
41                          switch (argv[i][1]) {
42                          case 'g':
43                                  gamma = atof(argv[++i]);
44                                  break;
45 +                        case 'e':
46 +                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
47 +                                        goto userr;
48 +                                bradj = atoi(argv[++i]);
49 +                                break;
50                          case 'r':
51 <                                reverse = !reverse;
51 >                                if (!strcmp(argv[i], "-rgb"))
52 >                                        head.ras_type = RT_FORMAT_RGB;
53 >                                else
54 >                                        reverse = 1;
55                                  break;
56                          default:
57                                  goto userr;
# Line 60 | Line 71 | char  *argv[];
71                                  progname, argv[i+1]);
72                  exit(1);
73          }
74 +        setcolrgam(gamma);
75          if (reverse) {
76                                          /* get header */
77                  if (fread((char *)&head, sizeof(head), 1, stdin) != 1)
# Line 68 | Line 80 | char  *argv[];
80                          quiterr("bad raster format");
81                  xmax = head.ras_width;
82                  ymax = head.ras_height;
83 <                if (head.ras_type != RT_STANDARD ||
84 <                                head.ras_maptype != RMT_NONE ||
85 <                                head.ras_depth != 24)
83 >                if ((head.ras_type != RT_STANDARD
84 >                                        && head.ras_type != RT_FORMAT_RGB)
85 >                                || head.ras_maptype != RMT_NONE
86 >                                || head.ras_depth != 24)
87                          quiterr("incompatible format");
88                                          /* put header */
89                  printargs(i, argv, stdout);
90 +                fputformat(COLRFMT, stdout);
91                  putchar('\n');
92                  fputresolu(YMAJOR|YDECR, xmax, ymax, stdout);
93                                          /* convert file */
94 <                pr2ra();
94 >                pr2ra(head.ras_type);
95          } else {
96 <                                        /* discard input header */
97 <                getheader(stdin, NULL);
98 <                                        /* get resolution */
99 <                if (fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR))
86 <                        quiterr("bad picture size");
96 >                                        /* get header info. */
97 >                if (checkheader(stdin, COLRFMT, NULL) < 0 ||
98 >                        fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR))
99 >                        quiterr("bad picture format");
100                                          /* write rasterfile header */
101                  head.ras_magic = RAS_MAGIC;
102                  head.ras_width = xmax;
103                  head.ras_height = ymax;
104                  head.ras_depth = 24;
105                  head.ras_length = xmax*ymax*3;
93                head.ras_type = RT_STANDARD;
106                  head.ras_maptype = RMT_NONE;
107                  head.ras_maplength = 0;
108                  fwrite((char *)&head, sizeof(head), 1, stdout);
109                                          /* convert file */
110 <                ra2pr();
110 >                ra2pr(head.ras_type);
111          }
112          exit(0);
113   userr:
114 <        fprintf(stderr, "Usage: %s [-r][-g gamma] [input [output]]\n",
114 >        fprintf(stderr, "Usage: %s [-r][-g gamma][-e +/-stops] [input [output]]\n",
115                          progname);
116          exit(1);
117   }
# Line 116 | Line 128 | char  *err;
128   }
129  
130  
131 < pr2ra()                 /* convert 24-bit scanlines to Radiance picture */
131 > pr2ra(rf)               /* convert 24-bit scanlines to Radiance picture */
132 > int     rf;
133   {
134 <        float   gmap[256];
122 <        int     r, g, b;
123 <        COLOR   *scanout;
134 >        COLR    *scanout;
135          register int    x;
136          int     y;
137                                                  /* allocate scanline */
138 <        scanout = (COLOR *)malloc(xmax*sizeof(COLOR));
138 >        scanout = (COLR *)malloc(xmax*sizeof(COLR));
139          if (scanout == NULL)
140                  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);
141                                                  /* convert image */
142          for (y = ymax-1; y >= 0; y--) {
143 <                for (x = 0; x < xmax; x++) {
144 <                        r = getc(stdin); g = getc(stdin);
145 <                        if ((b = getc(stdin)) == EOF)
146 <                                quiterr("error reading rasterfile");
147 <                        setcolor(scanout[x], gmap[r], gmap[g], gmap[b]);
148 <                }
149 <                if (fwritescan(scanout, xmax, stdout) < 0)
143 >                if (rf == RT_FORMAT_RGB)
144 >                        for (x = 0; x < xmax; x++) {
145 >                                scanout[x][RED] = getc(stdin);
146 >                                scanout[x][GRN] = getc(stdin);
147 >                                scanout[x][BLU] = getc(stdin);
148 >                        }
149 >                else
150 >                        for (x = 0; x < xmax; x++) {
151 >                                scanout[x][BLU] = getc(stdin);
152 >                                scanout[x][GRN] = getc(stdin);
153 >                                scanout[x][RED] = getc(stdin);
154 >                        }
155 >                if (feof(stdin) || ferror(stdin))
156 >                        quiterr("error reading rasterfile");
157 >                gambs_colrs(scanout, xmax);
158 >                if (bradj)
159 >                        shiftcolrs(scanout, xmax, bradj);
160 >                if (fwritecolrs(scanout, xmax, stdout) < 0)
161                          quiterr("error writing Radiance picture");
162          }
163                                                  /* free scanline */
# Line 146 | Line 165 | pr2ra()                        /* convert 24-bit scanlines to Radiance pict
165   }
166  
167  
168 < ra2pr()                 /* convert Radiance scanlines to 24-bit rasterfile */
168 > ra2pr(rf)               /* convert Radiance scanlines to 24-bit rasterfile */
169 > int  rf;
170   {
171 < #define map(v)  ((v)>=1.0 ? 255 : gmap[(int)(1024.*(v))])
152 <        unsigned char   gmap[1024];
153 <        COLOR   *scanin;
171 >        COLR    *scanin;
172          register int    x;
155        register int    c;
173          int     y;
174                                                  /* allocate scanline */
175 <        scanin = (COLOR *)malloc(xmax*sizeof(COLOR));
175 >        scanin = (COLR *)malloc(xmax*sizeof(COLR));
176          if (scanin == NULL)
177 <                quiterr("out of memory in pr2ra");
161 <                                                /* compute gamma correction */
162 <        for (x = 0; x < 1024; x++)
163 <                gmap[x] = 256.*pow((x+.5)/1024., 1./gamma);
177 >                quiterr("out of memory in ra2pr");
178                                                  /* convert image */
179          for (y = ymax-1; y >= 0; y--) {
180 <                if (freadscan(scanin, xmax, stdin) < 0)
180 >                if (freadcolrs(scanin, xmax, stdin) < 0)
181                          quiterr("error reading Radiance picture");
182 <                for (x = 0; x < xmax; x++) {
183 <                        c = map(colval(scanin[x],RED));
184 <                        putc(c, stdout);
185 <                        c = map(colval(scanin[x],GRN));
186 <                        putc(c, stdout);
187 <                        c = map(colval(scanin[x],BLU));
188 <                        putc(c, stdout);
189 <                }
182 >                if (bradj)
183 >                        shiftcolrs(scanin, xmax, bradj);
184 >                colrs_gambs(scanin, xmax);
185 >                if (rf == RT_FORMAT_RGB)
186 >                        for (x = 0; x < xmax; x++) {
187 >                                putc(scanin[x][RED], stdout);
188 >                                putc(scanin[x][GRN], stdout);
189 >                                putc(scanin[x][BLU], stdout);
190 >                        }
191 >                else
192 >                        for (x = 0; x < xmax; x++) {
193 >                                putc(scanin[x][BLU], stdout);
194 >                                putc(scanin[x][GRN], stdout);
195 >                                putc(scanin[x][RED], stdout);
196 >                        }
197                  if (ferror(stdout))
198                          quiterr("error writing rasterfile");
199          }
200                                                  /* free scanline */
201          free((char *)scanin);
181 #undef map
202   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines