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 2.3 by greg, Mon Sep 21 12:15:02 1992 UTC vs.
Revision 2.12 by schorsch, Sun Mar 28 20:33:14 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  program to convert between RADIANCE and 24-bit rasterfiles.
6   */
7  
8   #include  <stdio.h>
9 + #include  <time.h>
10 + #include  <math.h>
11 + #include  <string.h>
12  
13 < #ifdef MSDOS
14 < #include  <fcntl.h>
15 < #endif
16 <
13 > #include  "platform.h"
14   #include  "rasterfile.h"
18
15   #include  "color.h"
20
16   #include  "resolu.h"
17  
18 < extern double  pow();
24 <
25 < extern char  *malloc();
26 <
27 < double  gamma = 2.2;                    /* gamma correction */
28 <
18 > double  gamcor = 2.2;                   /* gamma correction */
19   int  bradj = 0;                         /* brightness adjustment */
30
20   char  *progname;
32
21   int  xmax, ymax;
22  
23 + static void quiterr(char  *err);
24 + static void pr2ra(int   rf, int pad);
25 + static void ra2pr(int   rf, int pad);
26  
27 < main(argc, argv)
28 < int  argc;
29 < char  *argv[];
27 >
28 > int
29 > main(int  argc, char  *argv[])
30   {
31          struct rasterfile  head;
32          int  reverse = 0;
33          int  i;
34 < #ifdef MSDOS
35 <        extern int  _fmode;
36 <        _fmode = O_BINARY;
46 <        setmode(fileno(stdin), O_BINARY);
47 <        setmode(fileno(stdout), O_BINARY);
48 < #endif
34 >        SET_DEFAULT_BINARY();
35 >        SET_FILE_BINARY(stdin);
36 >        SET_FILE_BINARY(stdout);
37          progname = argv[0];
38  
39          head.ras_type = RT_STANDARD;
# Line 53 | Line 41 | char  *argv[];
41                  if (argv[i][0] == '-')
42                          switch (argv[i][1]) {
43                          case 'g':
44 <                                gamma = atof(argv[++i]);
44 >                                gamcor = atof(argv[++i]);
45                                  break;
46                          case 'e':
47                                  if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
# Line 80 | Line 68 | char  *argv[];
68                  exit(1);
69          }
70          if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) {
71 <                fprintf(stderr, "can't open output \"%s\"\n",
71 >                fprintf(stderr, "%s: can't open output \"%s\"\n",
72                                  progname, argv[i+1]);
73                  exit(1);
74          }
75 <        setcolrgam(gamma);
75 >        setcolrgam(gamcor);
76          if (reverse) {
77                                          /* get header */
78                  if (fread((char *)&head, sizeof(head), 1, stdin) != 1)
# Line 99 | Line 87 | char  *argv[];
87                                  || head.ras_depth != 24)
88                          quiterr("incompatible format");
89                                          /* put header */
90 +                newheader("RADIANCE", stdout);
91                  printargs(i, argv, stdout);
92                  fputformat(COLRFMT, stdout);
93                  putchar('\n');
94                  fprtresolu(xmax, ymax, stdout);
95                                          /* convert file */
96 <                pr2ra(head.ras_type);
96 >                pr2ra(head.ras_type, head.ras_length/ymax - xmax*3);
97          } else {
98                                          /* get header info. */
99                  if (checkheader(stdin, COLRFMT, NULL) < 0 ||
# Line 112 | Line 101 | char  *argv[];
101                          quiterr("bad picture format");
102                                          /* write rasterfile header */
103                  head.ras_magic = RAS_MAGIC;
104 <                head.ras_width = xmax;
104 >                head.ras_width = xmax + (xmax&1);
105                  head.ras_height = ymax;
106                  head.ras_depth = 24;
107 <                head.ras_length = xmax*ymax*3;
107 >                head.ras_length = head.ras_width*head.ras_height*3;
108                  head.ras_maptype = RMT_NONE;
109                  head.ras_maplength = 0;
110                  fwrite((char *)&head, sizeof(head), 1, stdout);
111                                          /* convert file */
112 <                ra2pr(head.ras_type);
112 >                ra2pr(head.ras_type, head.ras_length/ymax - xmax*3);
113          }
114          exit(0);
115   userr:
# Line 130 | Line 119 | userr:
119   }
120  
121  
122 < quiterr(err)            /* print message and exit */
123 < char  *err;
122 > static void
123 > quiterr(                /* print message and exit */
124 >        char  *err
125 > )
126   {
127          if (err != NULL) {
128                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 141 | Line 132 | char  *err;
132   }
133  
134  
135 < pr2ra(rf)               /* convert 24-bit scanlines to Radiance picture */
136 < int     rf;
135 > static void
136 > pr2ra(          /* convert 24-bit scanlines to Radiance picture */
137 >        int     rf,
138 >        int     pad
139 > )
140   {
141          COLR    *scanout;
142          register int    x;
# Line 165 | Line 159 | int    rf;
159                                  scanout[x][GRN] = getc(stdin);
160                                  scanout[x][RED] = getc(stdin);
161                          }
162 +                for (x = pad; x--; getc(stdin));
163                  if (feof(stdin) || ferror(stdin))
164                          quiterr("error reading rasterfile");
165                  gambs_colrs(scanout, xmax);
# Line 174 | Line 169 | int    rf;
169                          quiterr("error writing Radiance picture");
170          }
171                                                  /* free scanline */
172 <        free((char *)scanout);
172 >        free((void *)scanout);
173   }
174  
175  
176 < ra2pr(rf)               /* convert Radiance scanlines to 24-bit rasterfile */
177 < int  rf;
176 > static void
177 > ra2pr(          /* convert Radiance scanlines to 24-bit rasterfile */
178 >        int     rf,
179 >        int     pad
180 > )
181   {
182 +        int     ord[3];
183          COLR    *scanin;
184          register int    x;
185          int     y;
# Line 188 | Line 187 | int  rf;
187          scanin = (COLR *)malloc(xmax*sizeof(COLR));
188          if (scanin == NULL)
189                  quiterr("out of memory in ra2pr");
190 +        if (rf == RT_FORMAT_RGB) {
191 +                ord[0] = RED; ord[1] = GRN; ord[2] = BLU;
192 +        } else {
193 +                ord[0] = BLU; ord[1] = GRN; ord[2] = RED;
194 +        }
195                                                  /* convert image */
196          for (y = ymax-1; y >= 0; y--) {
197                  if (freadcolrs(scanin, xmax, stdin) < 0)
# Line 207 | Line 211 | int  rf;
211                                  putc(scanin[x][GRN], stdout);
212                                  putc(scanin[x][RED], stdout);
213                          }
214 +                for (x = 0; x < pad; x++)
215 +                        putc(scanin[xmax-1][ord[x%3]], stdout);
216                  if (ferror(stdout))
217                          quiterr("error writing rasterfile");
218          }
219                                                  /* free scanline */
220 <        free((char *)scanin);
220 >        free((void *)scanin);
221   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines