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.3 by greg, Sat Oct 20 11:41:29 1990 UTC

# Line 60 | Line 60 | char  *argv[];
60                                  progname, argv[i+1]);
61                  exit(1);
62          }
63 +        setcolrgam(gamma);
64          if (reverse) {
65                                          /* get header */
66                  if (fread((char *)&head, sizeof(head), 1, stdin) != 1)
# Line 118 | Line 119 | char  *err;
119  
120   pr2ra()                 /* convert 24-bit scanlines to Radiance picture */
121   {
122 <        float   gmap[256];
122 <        int     r, g, b;
123 <        COLOR   *scanout;
122 >        COLR    *scanout;
123          register int    x;
124          int     y;
125                                                  /* allocate scanline */
126 <        scanout = (COLOR *)malloc(xmax*sizeof(COLOR));
126 >        scanout = (COLR *)malloc(xmax*sizeof(COLR));
127          if (scanout == NULL)
128                  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);
129                                                  /* convert image */
130          for (y = ymax-1; y >= 0; y--) {
131                  for (x = 0; x < xmax; x++) {
132 <                        r = getc(stdin); g = getc(stdin);
133 <                        if ((b = getc(stdin)) == EOF)
134 <                                quiterr("error reading rasterfile");
139 <                        setcolor(scanout[x], gmap[r], gmap[g], gmap[b]);
132 >                        scanout[x][RED] = getc(stdin);
133 >                        scanout[x][GRN] = getc(stdin);
134 >                        scanout[x][BLU] = getc(stdin);
135                  }
136 <                if (fwritescan(scanout, xmax, stdout) < 0)
136 >                if (feof(stdin) || ferror(stdin))
137 >                        quiterr("error reading rasterfile");
138 >                gambs_colrs(scanout, xmax);
139 >                if (fwritecolrs(scanout, xmax, stdout) < 0)
140                          quiterr("error writing Radiance picture");
141          }
142                                                  /* free scanline */
# Line 148 | Line 146 | pr2ra()                        /* convert 24-bit scanlines to Radiance pict
146  
147   ra2pr()                 /* convert Radiance scanlines to 24-bit rasterfile */
148   {
149 < #define map(v)  ((v)>=1.0 ? 255 : gmap[(int)(1024.*(v))])
152 <        unsigned char   gmap[1024];
153 <        COLOR   *scanin;
149 >        COLR    *scanin;
150          register int    x;
155        register int    c;
151          int     y;
152                                                  /* allocate scanline */
153 <        scanin = (COLOR *)malloc(xmax*sizeof(COLOR));
153 >        scanin = (COLR *)malloc(xmax*sizeof(COLR));
154          if (scanin == NULL)
155                  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);
156                                                  /* convert image */
157          for (y = ymax-1; y >= 0; y--) {
158 <                if (freadscan(scanin, xmax, stdin) < 0)
158 >                if (freadcolrs(scanin, xmax, stdin) < 0)
159                          quiterr("error reading Radiance picture");
160 +                colrs_gambs(scanin, xmax);
161                  for (x = 0; x < xmax; x++) {
162 <                        c = map(colval(scanin[x],RED));
163 <                        putc(c, stdout);
164 <                        c = map(colval(scanin[x],GRN));
172 <                        putc(c, stdout);
173 <                        c = map(colval(scanin[x],BLU));
174 <                        putc(c, stdout);
162 >                        putc(scanin[x][RED], stdout);
163 >                        putc(scanin[x][GRN], stdout);
164 >                        putc(scanin[x][BLU], stdout);
165                  }
166                  if (ferror(stdout))
167                          quiterr("error writing rasterfile");
168          }
169                                                  /* free scanline */
170          free((char *)scanin);
181 #undef map
171   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines