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.6 by greg, Mon Apr 29 11:14:10 1991 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 68 | Line 69 | char  *argv[];
69                          quiterr("bad raster format");
70                  xmax = head.ras_width;
71                  ymax = head.ras_height;
72 <                if (head.ras_type != RT_STANDARD ||
73 <                                head.ras_maptype != RMT_NONE ||
74 <                                head.ras_depth != 24)
72 >                if ((head.ras_type != RT_STANDARD
73 >                                        && head.ras_type != RT_FORMAT_RGB)
74 >                                || head.ras_maptype != RMT_NONE
75 >                                || head.ras_depth != 24)
76                          quiterr("incompatible format");
77                                          /* put header */
78                  printargs(i, argv, stdout);
79 +                fputformat(COLRFMT, stdout);
80                  putchar('\n');
81                  fputresolu(YMAJOR|YDECR, xmax, ymax, stdout);
82                                          /* convert file */
83 <                pr2ra();
83 >                pr2ra(head.ras_type);
84          } else {
85 <                                        /* discard input header */
86 <                getheader(stdin, NULL);
87 <                                        /* get resolution */
88 <                if (fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR))
86 <                        quiterr("bad picture size");
85 >                                        /* get header info. */
86 >                if (checkheader(stdin, COLRFMT, NULL) < 0 ||
87 >                        fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR))
88 >                        quiterr("bad picture format");
89                                          /* write rasterfile header */
90                  head.ras_magic = RAS_MAGIC;
91                  head.ras_width = xmax;
# Line 116 | Line 118 | char  *err;
118   }
119  
120  
121 < pr2ra()                 /* convert 24-bit scanlines to Radiance picture */
121 > pr2ra(rf)               /* convert 24-bit scanlines to Radiance picture */
122 > int     rf;
123   {
124 <        float   gmap[256];
122 <        int     r, g, b;
123 <        COLOR   *scanout;
124 >        COLR    *scanout;
125          register int    x;
126          int     y;
127                                                  /* allocate scanline */
128 <        scanout = (COLOR *)malloc(xmax*sizeof(COLOR));
128 >        scanout = (COLR *)malloc(xmax*sizeof(COLR));
129          if (scanout == NULL)
130                  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);
131                                                  /* convert image */
132          for (y = ymax-1; y >= 0; y--) {
133 <                for (x = 0; x < xmax; x++) {
134 <                        r = getc(stdin); g = getc(stdin);
135 <                        if ((b = getc(stdin)) == EOF)
136 <                                quiterr("error reading rasterfile");
137 <                        setcolor(scanout[x], gmap[r], gmap[g], gmap[b]);
138 <                }
139 <                if (fwritescan(scanout, xmax, stdout) < 0)
133 >                for (x = 0; x < xmax; x++)
134 >                        if (rf == RT_FORMAT_RGB) {
135 >                                scanout[x][RED] = getc(stdin);
136 >                                scanout[x][GRN] = getc(stdin);
137 >                                scanout[x][BLU] = getc(stdin);
138 >                        } else {
139 >                                scanout[x][BLU] = getc(stdin);
140 >                                scanout[x][GRN] = getc(stdin);
141 >                                scanout[x][RED] = getc(stdin);
142 >                        }
143 >                if (feof(stdin) || ferror(stdin))
144 >                        quiterr("error reading rasterfile");
145 >                gambs_colrs(scanout, xmax);
146 >                if (fwritecolrs(scanout, xmax, stdout) < 0)
147                          quiterr("error writing Radiance picture");
148          }
149                                                  /* free scanline */
# Line 148 | Line 153 | pr2ra()                        /* convert 24-bit scanlines to Radiance pict
153  
154   ra2pr()                 /* convert Radiance scanlines to 24-bit rasterfile */
155   {
156 < #define map(v)  ((v)>=1.0 ? 255 : gmap[(int)(1024.*(v))])
152 <        unsigned char   gmap[1024];
153 <        COLOR   *scanin;
156 >        COLR    *scanin;
157          register int    x;
155        register int    c;
158          int     y;
159                                                  /* allocate scanline */
160 <        scanin = (COLOR *)malloc(xmax*sizeof(COLOR));
160 >        scanin = (COLR *)malloc(xmax*sizeof(COLR));
161          if (scanin == NULL)
162                  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);
163                                                  /* convert image */
164          for (y = ymax-1; y >= 0; y--) {
165 <                if (freadscan(scanin, xmax, stdin) < 0)
165 >                if (freadcolrs(scanin, xmax, stdin) < 0)
166                          quiterr("error reading Radiance picture");
167 +                colrs_gambs(scanin, xmax);
168                  for (x = 0; x < xmax; x++) {
169 <                        c = map(colval(scanin[x],RED));
170 <                        putc(c, stdout);
171 <                        c = map(colval(scanin[x],GRN));
172 <                        putc(c, stdout);
173 <                        c = map(colval(scanin[x],BLU));
174 <                        putc(c, stdout);
169 >                        putc(scanin[x][BLU], stdout);
170 >                        putc(scanin[x][GRN], stdout);
171 >                        putc(scanin[x][RED], stdout);
172                  }
173                  if (ferror(stdout))
174                          quiterr("error writing rasterfile");
175          }
176                                                  /* free scanline */
177          free((char *)scanin);
181 #undef map
178   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines