ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_bn.c
(Generate patch)

Comparing ray/src/px/ra_bn.c (file contents):
Revision 1.3 by greg, Fri Feb 9 13:59:17 1990 UTC vs.
Revision 1.9 by greg, Mon Nov 11 14:01:48 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 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 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include  "color.h"
16  
17 + #include  "resolu.h"
18 +
19   extern double  atof(), pow();
20  
21   double  gamma = 2.0;                    /* gamma correction */
22  
23 + int  bradj = 0;                         /* brightness adjustment */
24 +
25   char  *progname;
26  
27   char  errmsg[128];
# Line 45 | Line 49 | char  *argv[];
49                          case 'r':
50                                  reverse = !reverse;
51                                  break;
52 +                        case 'e':
53 +                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
54 +                                        goto userr;
55 +                                bradj = atoi(argv[++i]);
56 +                                break;
57                          default:
58                                  goto userr;
59                          }
60                  else
61                          break;
62 +                                                /* set gamma correction */
63 +        setcolrgam(gamma);
64  
65          if (reverse) {
66                  if (i > argc-1 || i < argc-2)
# Line 67 | Line 78 | char  *argv[];
78                  }
79                                          /* put header */
80                  printargs(i, argv, rafp);
81 +                fputformat(COLRFMT, rafp);
82                  putc('\n', rafp);
83 <                fputresolu(YMAJOR|YDECR, xmax, ymax, rafp);
83 >                fprtresolu(xmax, ymax, rafp);
84                                          /* convert file */
85                  bn2ra();
86          } else {
# Line 82 | Line 94 | char  *argv[];
94                          quiterr(errmsg);
95                  }
96                                          /* get header */
97 <                getheader(rafp, NULL);
98 <                if (fgetresolu(&xmax, &ymax, rafp) != (YMAJOR|YDECR))
97 >                if (checkheader(rafp, COLRFMT, NULL) < 0 ||
98 >                                fgetresolu(&xmax, &ymax, rafp) < 0)
99                          quiterr("bad RADIANCE format");
100                  if (openbarney(argv[i+1], "w") < 0) {
101                          sprintf(errmsg, "cannot open output \"%s\"", argv[i+1]);
# Line 94 | Line 106 | char  *argv[];
106          }
107          quiterr(NULL);
108   userr:
109 <        fprintf(stderr, "Usage: %s {input|-} output\n", progname);
98 <        fprintf(stderr, "   or: %s -r [-g gamma] input [output|-]\n",
109 >        fprintf(stderr, "Usage: %s [-g gamma][-e +/-stops] {input|-} output\n",
110                          progname);
111 +        fprintf(stderr, "   or: %s -r [-g gamma][-e +/-stops] input [output|-]\n",
112 +                        progname);
113          exit(1);
114   }
115  
# Line 165 | Line 178 | register FILE  *fp;
178  
179   ra2bn()                                 /* convert radiance to barneyscan */
180   {
181 <        unsigned char   gmap[1024];
182 <        register int    i,k,c;
170 <        register COLOR  *inline;
181 >        register int    i;
182 >        register COLR   *inl;
183          int     j;
184  
185 <        if ((inline = (COLOR *)malloc(xmax*sizeof(COLOR))) == NULL)
185 >        if ((inl = (COLR *)malloc(xmax*sizeof(COLR))) == NULL)
186                  quiterr("out of memory");
175        for (i = 0; i < 1024; i++)
176                gmap[i] = 256.*pow((i+.5)/1024., 1./gamma);
187          for (j = 0; j < ymax; j++) {
188 <                if (freadscan(inline, xmax, rafp) < 0)
188 >                if (freadcolrs(inl, xmax, rafp) < 0)
189                          quiterr("error reading RADIANCE file");
190 <                for (i = 0; i < xmax; i++)
191 <                        for (k = 0; k < 3; k++) {
192 <                                c = 1024.*colval(inline[i],k);
193 <                                if (c >= 1024)
194 <                                        c = 1023;
195 <                                putc(gmap[c], bnfp[k]);
196 <                        }
190 >                if (bradj)
191 >                        shiftcolrs(inl, xmax, bradj);
192 >                colrs_gambs(inl, xmax);
193 >                for (i = 0; i < xmax; i++) {
194 >                        putc(inl[i][RED], bnfp[0]);
195 >                        putc(inl[i][GRN], bnfp[1]);
196 >                        putc(inl[i][BLU], bnfp[2]);
197 >                }
198 >                if (ferror(bnfp[0]) || ferror(bnfp[1]) || ferror(bnfp[2]))
199 >                        quiterr("error writing Barney files");
200          }
201 <        free((char *)inline);
201 >        free((char *)inl);
202   }
203  
204  
205   bn2ra()                                 /* convert barneyscan to radiance */
206   {
207 <        float   gmap[256];
208 <        register int    i,k,c;
196 <        register COLOR  *outline;
207 >        register int    i;
208 >        register COLR   *outline;
209          int     j;
210  
211 <        if ((outline = (COLOR *)malloc(xmax*sizeof(COLOR))) == NULL)
211 >        if ((outline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL)
212                  quiterr("out of memory");
201        for (i = 0; i < 256; i++)
202                gmap[i] = pow((i+.5)/256., gamma);
213          for (j = 0; j < ymax; j++) {
214 <                for (i = 0; i < xmax; i++)
215 <                        for (k = 0; k < 3; k++)
216 <                                if ((c = getc(bnfp[k])) == EOF)
217 <                                        quiterr("error reading barney file");
218 <                                else
219 <                                        colval(outline[i],k) = gmap[c];
220 <                if (fwritescan(outline, xmax, rafp) < 0)
214 >                for (i = 0; i < xmax; i++) {
215 >                        outline[i][RED] = getc(bnfp[0]);
216 >                        outline[i][GRN] = getc(bnfp[1]);
217 >                        outline[i][BLU] = getc(bnfp[2]);
218 >                }
219 >                if (feof(bnfp[0]) || feof(bnfp[1]) || feof(bnfp[2]))
220 >                        quiterr("error reading barney file");
221 >                gambs_colrs(outline, xmax);
222 >                if (bradj)
223 >                        shiftcolrs(outline, xmax, bradj);
224 >                if (fwritecolrs(outline, xmax, rafp) < 0)
225                          quiterr("error writing RADIANCE file");
226          }
227          free((char *)outline);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines