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 1.7 by greg, Wed Aug 7 08:36:33 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 18 | Line 18 | extern double  atof(), pow();
18  
19   double  gamma = 2.0;                    /* gamma correction */
20  
21 + int  bradj = 0;                         /* brightness adjustment */
22 +
23   char  *progname;
24  
25   int  xmax, ymax;
# Line 39 | Line 41 | char  *argv[];
41                          case 'g':
42                                  gamma = atof(argv[++i]);
43                                  break;
44 +                        case 'e':
45 +                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
46 +                                        goto userr;
47 +                                bradj = atoi(argv[++i]);
48 +                                break;
49                          case 'r':
50                                  reverse = !reverse;
51                                  break;
# Line 60 | Line 67 | char  *argv[];
67                                  progname, argv[i+1]);
68                  exit(1);
69          }
70 +        setcolrgam(gamma);
71          if (reverse) {
72                                          /* get header */
73                  if (fread((char *)&head, sizeof(head), 1, stdin) != 1)
# Line 68 | Line 76 | char  *argv[];
76                          quiterr("bad raster format");
77                  xmax = head.ras_width;
78                  ymax = head.ras_height;
79 <                if (head.ras_type != RT_STANDARD ||
80 <                                head.ras_maptype != RMT_NONE ||
81 <                                head.ras_depth != 24)
79 >                if ((head.ras_type != RT_STANDARD
80 >                                        && head.ras_type != RT_FORMAT_RGB)
81 >                                || head.ras_maptype != RMT_NONE
82 >                                || head.ras_depth != 24)
83                          quiterr("incompatible format");
84                                          /* put header */
85                  printargs(i, argv, stdout);
86 +                fputformat(COLRFMT, stdout);
87                  putchar('\n');
88                  fputresolu(YMAJOR|YDECR, xmax, ymax, stdout);
89                                          /* convert file */
90 <                pr2ra();
90 >                pr2ra(head.ras_type);
91          } else {
92 <                                        /* discard input header */
93 <                getheader(stdin, NULL);
94 <                                        /* get resolution */
95 <                if (fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR))
86 <                        quiterr("bad picture size");
92 >                                        /* get header info. */
93 >                if (checkheader(stdin, COLRFMT, NULL) < 0 ||
94 >                        fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR))
95 >                        quiterr("bad picture format");
96                                          /* write rasterfile header */
97                  head.ras_magic = RAS_MAGIC;
98                  head.ras_width = xmax;
# Line 99 | Line 108 | char  *argv[];
108          }
109          exit(0);
110   userr:
111 <        fprintf(stderr, "Usage: %s [-r][-g gamma] [input [output]]\n",
111 >        fprintf(stderr, "Usage: %s [-r][-g gamma][-e +/-stops] [input [output]]\n",
112                          progname);
113          exit(1);
114   }
# Line 116 | Line 125 | char  *err;
125   }
126  
127  
128 < pr2ra()                 /* convert 24-bit scanlines to Radiance picture */
128 > pr2ra(rf)               /* convert 24-bit scanlines to Radiance picture */
129 > int     rf;
130   {
131 <        float   gmap[256];
122 <        int     r, g, b;
123 <        COLOR   *scanout;
131 >        COLR    *scanout;
132          register int    x;
133          int     y;
134                                                  /* allocate scanline */
135 <        scanout = (COLOR *)malloc(xmax*sizeof(COLOR));
135 >        scanout = (COLR *)malloc(xmax*sizeof(COLR));
136          if (scanout == NULL)
137                  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);
138                                                  /* convert image */
139          for (y = ymax-1; y >= 0; y--) {
140 <                for (x = 0; x < xmax; x++) {
141 <                        r = getc(stdin); g = getc(stdin);
142 <                        if ((b = getc(stdin)) == EOF)
143 <                                quiterr("error reading rasterfile");
144 <                        setcolor(scanout[x], gmap[r], gmap[g], gmap[b]);
145 <                }
146 <                if (fwritescan(scanout, xmax, stdout) < 0)
140 >                for (x = 0; x < xmax; x++)
141 >                        if (rf == RT_FORMAT_RGB) {
142 >                                scanout[x][RED] = getc(stdin);
143 >                                scanout[x][GRN] = getc(stdin);
144 >                                scanout[x][BLU] = getc(stdin);
145 >                        } else {
146 >                                scanout[x][BLU] = getc(stdin);
147 >                                scanout[x][GRN] = getc(stdin);
148 >                                scanout[x][RED] = getc(stdin);
149 >                        }
150 >                if (feof(stdin) || ferror(stdin))
151 >                        quiterr("error reading rasterfile");
152 >                gambs_colrs(scanout, xmax);
153 >                if (bradj)
154 >                        shiftcolrs(scanout, xmax, bradj);
155 >                if (fwritecolrs(scanout, xmax, stdout) < 0)
156                          quiterr("error writing Radiance picture");
157          }
158                                                  /* free scanline */
# Line 148 | Line 162 | pr2ra()                        /* convert 24-bit scanlines to Radiance pict
162  
163   ra2pr()                 /* convert Radiance scanlines to 24-bit rasterfile */
164   {
165 < #define map(v)  ((v)>=1.0 ? 255 : gmap[(int)(1024.*(v))])
152 <        unsigned char   gmap[1024];
153 <        COLOR   *scanin;
165 >        COLR    *scanin;
166          register int    x;
155        register int    c;
167          int     y;
168                                                  /* allocate scanline */
169 <        scanin = (COLOR *)malloc(xmax*sizeof(COLOR));
169 >        scanin = (COLR *)malloc(xmax*sizeof(COLR));
170          if (scanin == NULL)
171                  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);
172                                                  /* convert image */
173          for (y = ymax-1; y >= 0; y--) {
174 <                if (freadscan(scanin, xmax, stdin) < 0)
174 >                if (freadcolrs(scanin, xmax, stdin) < 0)
175                          quiterr("error reading Radiance picture");
176 +                if (bradj)
177 +                        shiftcolrs(scanin, xmax, bradj);
178 +                colrs_gambs(scanin, xmax);
179                  for (x = 0; x < xmax; x++) {
180 <                        c = map(colval(scanin[x],RED));
181 <                        putc(c, stdout);
182 <                        c = map(colval(scanin[x],GRN));
172 <                        putc(c, stdout);
173 <                        c = map(colval(scanin[x],BLU));
174 <                        putc(c, stdout);
180 >                        putc(scanin[x][BLU], stdout);
181 >                        putc(scanin[x][GRN], stdout);
182 >                        putc(scanin[x][RED], stdout);
183                  }
184                  if (ferror(stdout))
185                          quiterr("error writing rasterfile");
186          }
187                                                  /* free scanline */
188          free((char *)scanin);
181 #undef map
189   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines