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

Comparing ray/src/px/ra_ps.c (file contents):
Revision 2.14 by greg, Wed Oct 4 16:01:32 1995 UTC vs.
Revision 2.15 by greg, Thu Oct 5 09:53:47 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1995 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 15 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15   #endif
16   #include  "color.h"
17  
18 < #define GAMVAL          1.5                     /* gamma value for pixels */
18 > #define GAMVAL          1.47                    /* gamma value for pixels */
19  
20   #define GRY             -1                      /* artificial index for grey */
21  
# Line 39 | Line 39 | int  docolor = 0;                      /* produce color image? */
39   int  bradj = 0;                         /* brightness adjustment */
40   int  ncopies = 1;                       /* number of copies */
41  
42 + extern int      Aputprim(), Bputprim(), Cputprim();
43 +
44 + int  (*putprim)() = Aputprim;           /* function for writing scanline */
45 +
46   char  *progname;
47  
48   int  xmax, ymax;
# Line 70 | Line 74 | char  *argv[];
74          for (i = 1; i < argc; i++)
75                  if (argv[i][0] == '-')
76                          switch (argv[i][1]) {
77 +                        case 'b':               /* produce b&w PostScript */
78 +                                docolor = 0;
79 +                                break;
80                          case 'c':               /* produce color PostScript */
81 <                                docolor++;
81 >                                docolor = 1;
82                                  break;
83 +                        case 'A':               /* standard ASCII encoding */
84 +                                putprim = Aputprim;
85 +                                break;
86 +                        case 'B':               /* standard binary encoding */
87 +                                putprim = Bputprim;
88 +                                break;
89 +                        case 'C':               /* compressed ASCII encoding */
90 +                                putprim = Cputprim;
91 +                                break;
92                          case 'e':               /* exposure adjustment */
93                                  if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
94                                          goto userr;
# Line 107 | Line 123 | char  *argv[];
123          if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0)
124                  quiterr("bad picture format");
125                                  /* gamma compression */
126 <        setcolrgam(GAMVAL);
126 >        if (putprim == Cputprim)
127 >                setcolrgam(GAMVAL);
128                                  /* write header */
129          PSheader(i <= argc-1 ? argv[i] : "<stdin>");
130                                  /* convert file */
# Line 116 | Line 133 | char  *argv[];
133          PStrailer();
134          exit(0);
135   userr:
136 <        fprintf(stderr, "Usage: %s [-c][-e +/-stops] [input [output]]\n",
136 >        fprintf(stderr, "Usage: %s [-b|c][-A|B|C][-e +/-stops] [input [output]]\n",
137                          progname);
138          exit(1);
139   }
# Line 136 | Line 153 | char  *err;
153   PSheader(name)                  /* print PostScript header */
154   char  *name;
155   {
156 +        char  *rstr;
157          int  landscape = 0;
158          double  pwidth, pheight;
159          double  iwidth, iheight;
# Line 176 | Line 194 | char  *name;
194                                  VMARGIN+(pheight-iheight)*.5+iheight);
195          puts("%%EndComments");
196          puts("gsave save");
197 <        puts("64 dict begin");
197 >        puts("17 dict begin");
198                                          /* define image reader */
199          if (docolor) {
200                  printf("/redline %d string def\n", xmax);
201                  printf("/grnline %d string def\n", xmax);
202                  printf("/bluline %d string def\n", xmax);
203 <                printf("/rgbline %d string def\n", 3*xmax);
204 <                PSprocdef("read6bitRLE", "interleave");
205 <        } else {
206 <                printf("/greyline %d string def\n", xmax);
207 <                PSprocdef("read6bitRLE", NULL);
190 <        }
203 >        } else
204 >                printf("/gryline %d string def\n", xmax);
205 >                                        /* use compressed encoding? */
206 >        if (putprim == Cputprim)
207 >                PSprocdef("read6bitRLE");
208                                          /* set up transformation matrix */
209          printf("%f %f translate\n", HMARGIN, VMARGIN);
210          if (pwidth == PHEIGHT) {
# Line 198 | Line 215 | char  *name;
215          printf("%f %f scale\n", iwidth, iheight);
216          puts("%%EndProlog");
217                                          /* start image procedure */
218 <        printf("%d %d 8 [%d 0 0 %d 0 %d] ", xmax, ymax, xmax, -ymax, ymax);
219 <        if (docolor) {
220 <                puts("{redline read6bitRLE grnline read6bitRLE");
221 <                puts("\tbluline read6bitRLE rgbline interleave} false 3 colorimage");
222 <        } else
223 <                puts("{greyline read6bitRLE} image");
218 >        printf("%d %d 8 [%d 0 0 %d 0 %d]\n", xmax, ymax, xmax, -ymax, ymax);
219 >        if (putprim == Cputprim) {
220 >                if (docolor) {
221 >                        puts("{redline read6bitRLE grnline read6bitRLE");
222 >                        puts("bluline read6bitRLE} true 3 colorimage");
223 >                } else
224 >                        puts("{gryline read6bitRLE} image");
225 >        } else {
226 >                rstr = putprim==Aputprim ? "readhexstring" : "readstring";
227 >                if (docolor) {
228 >                        printf("{currentfile redline %s pop}\n", rstr);
229 >                        printf("{currentfile grnline %s pop}\n", rstr);
230 >                        printf("{currentfile bluline %s pop}\n", rstr);
231 >                        puts("true 3 colorimage");
232 >                } else
233 >                        printf("{currentfile gryline %s pop} image\n", rstr);
234 >        }
235   }
236  
237  
# Line 219 | Line 247 | PStrailer()                    /* print PostScript trailer */
247   }
248  
249  
250 < PSprocdef(nam, inam)            /* define PS procedure to read image */
251 < char  *nam, *inam;
250 > PSprocdef(nam)                  /* define PS procedure to read image */
251 > char  *nam;
252   {
253          short  itab[128];
254          register int  i;
# Line 228 | Line 256 | char  *nam, *inam;
256          for (i = 0; i < 128; i++)       /* clear */
257                  itab[i] = -1;
258          for (i = 1; i < 63; i++)        /* assign greys */
259 <                itab[code[i]] = 256.0*pow(((i<<2)+2.5)/256.0, GAMVAL);
259 >                itab[code[i]] = 256.0*pow((i+.5)/64.0, GAMVAL);
260          itab[code[0]] = 0;              /* black is black */
261          itab[code[63]] = 255;           /* and white is white */
262          printf("/codetab [");
# Line 256 | Line 284 | char  *nam, *inam;
284          printf("\t\t} for\n");
285          printf("\t} stopped {pop pop 0 string} {scanline} ifelse\n");
286          printf("} bind def\n");
259        if (inam == NULL)
260                return;
261                                        /* define interleaving procedure */
262        printf("/%s {\t%% redscn grnscn bluscn rgbscn\n", inam);
263        printf("\t/rgbscan exch def /bscan exch def\n");
264        printf("\t/gscan exch def /rscan exch def\n");
265        printf("\trscan length %d eq gscan length %d eq and ", xmax, xmax);
266        printf("bscan length %d eq and \n", xmax);
267        printf("\t{ 0 1 %d { /ndx exch def\n", xmax-1);
268        printf("\t\trgbscan ndx 3 mul rscan ndx get put\n");
269        printf("\t\trgbscan ndx 3 mul 1 add gscan ndx get put\n");
270        printf("\t\trgbscan ndx 3 mul 2 add bscan ndx get put\n");
271        printf("\t\t} for rgbscan }\n");
272        printf("\t{0 string} ifelse\n");
273        printf("} bind def\n");
287   }
288  
289  
# Line 286 | Line 299 | ra2ps()                                /* convert Radiance scanlines to 6-bit */
299          for (y = ymax-1; y >= 0; y--) {
300                  if (freadcolrs(scanin, xmax, stdin) < 0)
301                          quiterr("error reading Radiance picture");
302 <                if (bradj)                      /* adjust exposure */
303 <                        shiftcolrs(scanin, xmax, bradj);
304 <                colrs_gambs(scanin, xmax);      /* gamma compression */
302 >                if (putprim == Cputprim) {
303 >                        if (bradj)                      /* adjust exposure */
304 >                                shiftcolrs(scanin, xmax, bradj);
305 >                        colrs_gambs(scanin, xmax);      /* gamma compression */
306 >                } else
307 >                        normcolrs(scanin, xmax, bradj);
308                  if (docolor) {
309 <                        putprim(scanin, RED);
310 <                        putprim(scanin, GRN);
311 <                        putprim(scanin, BLU);
309 >                        (*putprim)(scanin, RED);
310 >                        (*putprim)(scanin, GRN);
311 >                        (*putprim)(scanin, BLU);
312                  } else
313 <                        putprim(scanin, GRY);
313 >                        (*putprim)(scanin, GRY);
314                  if (ferror(stdout))
315                          quiterr("error writing PostScript file");
316          }
# Line 304 | Line 320 | ra2ps()                                /* convert Radiance scanlines to 6-bit */
320   }
321  
322  
323 < putprim(scn, pri)               /* put out one primary from scanline */
323 > int
324 > Aputprim(scn, pri)              /* put out hex ASCII primary from scanline */
325 > COLR    *scn;
326 > int     pri;
327 > {
328 >        static char     hexdigit[] = "0123456789ABCDEF";
329 >        static int      col = 0;
330 >        register int    x, c;
331 >
332 >        for (x = 0; x < xmax; x++) {
333 >                if (pri == GRY)
334 >                        c = normbright(scn[x]);
335 >                else
336 >                        c = scn[x][pri];
337 >                if (c > 255) c = 255;
338 >                putchar(hexdigit[c>>4]);
339 >                putchar(hexdigit[c&0xf]);
340 >                if ((col += 2) >= 72) {
341 >                        putchar('\n');
342 >                        col = 0;
343 >                }
344 >        }
345 > }
346 >
347 >
348 > int
349 > Bputprim(scn, pri)              /* put out binary primary from scanline */
350 > COLR    *scn;
351 > int     pri;
352 > {
353 >        register int    x, c;
354 >
355 >        for (x = 0; x < xmax; x++) {
356 >                if (pri == GRY)
357 >                        c = normbright(scn[x]);
358 >                else
359 >                        c = scn[x][pri];
360 >                if (c > 255) c = 255;
361 >                putchar(c);
362 >        }
363 > }
364 >
365 >
366 > int
367 > Cputprim(scn, pri)              /* put out compressed primary from scanline */
368   COLR    *scn;
369   int     pri;
370   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines