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.8 by greg, Wed Aug 7 08:36:29 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 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   char  errmsg[128];
# Line 45 | Line 47 | char  *argv[];
47                          case 'r':
48                                  reverse = !reverse;
49                                  break;
50 +                        case 'e':
51 +                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
52 +                                        goto userr;
53 +                                bradj = atoi(argv[++i]);
54 +                                break;
55                          default:
56                                  goto userr;
57                          }
58                  else
59                          break;
60 +                                                /* set gamma correction */
61 +        setcolrgam(gamma);
62  
63          if (reverse) {
64                  if (i > argc-1 || i < argc-2)
# Line 67 | Line 76 | char  *argv[];
76                  }
77                                          /* put header */
78                  printargs(i, argv, rafp);
79 +                fputformat(COLRFMT, rafp);
80                  putc('\n', rafp);
81                  fputresolu(YMAJOR|YDECR, xmax, ymax, rafp);
82                                          /* convert file */
# Line 82 | Line 92 | char  *argv[];
92                          quiterr(errmsg);
93                  }
94                                          /* get header */
95 <                getheader(rafp, NULL);
96 <                if (fgetresolu(&xmax, &ymax, rafp) != (YMAJOR|YDECR))
95 >                if (checkheader(rafp, COLRFMT, NULL) < 0 ||
96 >                        fgetresolu(&xmax, &ymax, rafp) != (YMAJOR|YDECR))
97                          quiterr("bad RADIANCE format");
98                  if (openbarney(argv[i+1], "w") < 0) {
99                          sprintf(errmsg, "cannot open output \"%s\"", argv[i+1]);
# Line 94 | Line 104 | char  *argv[];
104          }
105          quiterr(NULL);
106   userr:
107 <        fprintf(stderr, "Usage: %s {input|-} output\n", progname);
98 <        fprintf(stderr, "   or: %s -r [-g gamma] input [output|-]\n",
107 >        fprintf(stderr, "Usage: %s [-g gamma][-e +/-stops] {input|-} output\n",
108                          progname);
109 +        fprintf(stderr, "   or: %s -r [-g gamma][-e +/-stops] input [output|-]\n",
110 +                        progname);
111          exit(1);
112   }
113  
# Line 165 | Line 176 | register FILE  *fp;
176  
177   ra2bn()                                 /* convert radiance to barneyscan */
178   {
179 <        unsigned char   gmap[1024];
180 <        register int    i,k,c;
170 <        register COLOR  *inline;
179 >        register int    i;
180 >        register COLR   *inl;
181          int     j;
182  
183 <        if ((inline = (COLOR *)malloc(xmax*sizeof(COLOR))) == NULL)
183 >        if ((inl = (COLR *)malloc(xmax*sizeof(COLR))) == NULL)
184                  quiterr("out of memory");
175        for (i = 0; i < 1024; i++)
176                gmap[i] = 256.*pow((i+.5)/1024., 1./gamma);
185          for (j = 0; j < ymax; j++) {
186 <                if (freadscan(inline, xmax, rafp) < 0)
186 >                if (freadcolrs(inl, xmax, rafp) < 0)
187                          quiterr("error reading RADIANCE file");
188 <                for (i = 0; i < xmax; i++)
189 <                        for (k = 0; k < 3; k++) {
190 <                                c = 1024.*colval(inline[i],k);
191 <                                if (c >= 1024)
192 <                                        c = 1023;
193 <                                putc(gmap[c], bnfp[k]);
194 <                        }
188 >                if (bradj)
189 >                        shiftcolrs(inl, xmax, bradj);
190 >                colrs_gambs(inl, xmax);
191 >                for (i = 0; i < xmax; i++) {
192 >                        putc(inl[i][RED], bnfp[0]);
193 >                        putc(inl[i][GRN], bnfp[1]);
194 >                        putc(inl[i][BLU], bnfp[2]);
195 >                }
196 >                if (ferror(bnfp[0]) || ferror(bnfp[1]) || ferror(bnfp[2]))
197 >                        quiterr("error writing Barney files");
198          }
199 <        free((char *)inline);
199 >        free((char *)inl);
200   }
201  
202  
203   bn2ra()                                 /* convert barneyscan to radiance */
204   {
205 <        float   gmap[256];
206 <        register int    i,k,c;
196 <        register COLOR  *outline;
205 >        register int    i;
206 >        register COLR   *outline;
207          int     j;
208  
209 <        if ((outline = (COLOR *)malloc(xmax*sizeof(COLOR))) == NULL)
209 >        if ((outline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL)
210                  quiterr("out of memory");
201        for (i = 0; i < 256; i++)
202                gmap[i] = pow((i+.5)/256., gamma);
211          for (j = 0; j < ymax; j++) {
212 <                for (i = 0; i < xmax; i++)
213 <                        for (k = 0; k < 3; k++)
214 <                                if ((c = getc(bnfp[k])) == EOF)
215 <                                        quiterr("error reading barney file");
216 <                                else
217 <                                        colval(outline[i],k) = gmap[c];
218 <                if (fwritescan(outline, xmax, rafp) < 0)
212 >                for (i = 0; i < xmax; i++) {
213 >                        outline[i][RED] = getc(bnfp[0]);
214 >                        outline[i][GRN] = getc(bnfp[1]);
215 >                        outline[i][BLU] = getc(bnfp[2]);
216 >                }
217 >                if (feof(bnfp[0]) || feof(bnfp[1]) || feof(bnfp[2]))
218 >                        quiterr("error reading barney file");
219 >                gambs_colrs(outline, xmax);
220 >                if (bradj)
221 >                        shiftcolrs(outline, xmax, bradj);
222 >                if (fwritecolrs(outline, xmax, rafp) < 0)
223                          quiterr("error writing RADIANCE file");
224          }
225          free((char *)outline);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines