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.13 by greg, Wed Oct 4 12:30:58 1995 UTC vs.
Revision 2.17 by gregl, Thu Sep 18 15:16:23 1997 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1997 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4 < static char SCCSid[] = "$SunId$ LBL";
4 > static char SCCSid[] = "$SunId$ SGI";
5   #endif
6  
7   /*
# 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 CODE6GAM        1.47                    /* gamma for 6-bit codes */
19 > #define DEFDGAM         1.0                     /* default device gamma */
20  
21   #define GRY             -1                      /* artificial index for grey */
22  
# Line 35 | Line 36 | char  code[] =                 /* 6-bit code lookup table */
36   int  wrongformat = 0;                   /* input in wrong format? */
37   double  pixaspect = 1.0;                /* pixel aspect ratio */
38  
39 + double  devgam = DEFDGAM;               /* device gamma response */
40   int  docolor = 0;                       /* produce color image? */
41   int  bradj = 0;                         /* brightness adjustment */
42   int  ncopies = 1;                       /* number of copies */
43  
44 + extern int      Aputprim(), Bputprim(), Cputprim();
45 +
46 + int  (*putprim)() = Aputprim;           /* function for writing scanline */
47 +
48   char  *progname;
49  
50   int  xmax, ymax;
# Line 70 | Line 76 | char  *argv[];
76          for (i = 1; i < argc; i++)
77                  if (argv[i][0] == '-')
78                          switch (argv[i][1]) {
79 +                        case 'b':               /* produce b&w PostScript */
80 +                                docolor = 0;
81 +                                break;
82                          case 'c':               /* produce color PostScript */
83 <                                docolor++;
83 >                                docolor = 1;
84                                  break;
85 +                        case 'A':               /* standard ASCII encoding */
86 +                                putprim = Aputprim;
87 +                                break;
88 +                        case 'B':               /* standard binary encoding */
89 +                                putprim = Bputprim;
90 +                                break;
91 +                        case 'C':               /* compressed ASCII encoding */
92 +                                putprim = Cputprim;
93 +                                break;
94 +                        case 'g':
95 +                                devgam = atof(argv[++i]);
96 +                                break;
97                          case 'e':               /* exposure adjustment */
98                                  if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
99                                          goto userr;
# Line 107 | Line 128 | char  *argv[];
128          if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0)
129                  quiterr("bad picture format");
130                                  /* gamma compression */
131 <        setcolrgam(GAMVAL);
131 >        if (putprim == Cputprim)
132 >                setcolrgam(CODE6GAM/devgam);
133 >        else if (devgam != 1.)
134 >                setcolrgam(1./devgam);
135                                  /* write header */
136          PSheader(i <= argc-1 ? argv[i] : "<stdin>");
137                                  /* convert file */
# Line 116 | Line 140 | char  *argv[];
140          PStrailer();
141          exit(0);
142   userr:
143 <        fprintf(stderr, "Usage: %s [-c][-e +/-stops] [input [output]]\n",
143 >        fprintf(stderr, "Usage: %s [-b|c][-A|B|C][-e +/-stops][-g gamma] [input [output]]\n",
144                          progname);
145          exit(1);
146   }
# Line 136 | Line 160 | char  *err;
160   PSheader(name)                  /* print PostScript header */
161   char  *name;
162   {
163 +        char  *rstr;
164          int  landscape = 0;
165          double  pwidth, pheight;
166          double  iwidth, iheight;
# Line 176 | Line 201 | char  *name;
201                                  VMARGIN+(pheight-iheight)*.5+iheight);
202          puts("%%EndComments");
203          puts("gsave save");
204 <        puts("64 dict begin");
204 >        puts("17 dict begin");
205                                          /* define image reader */
206          if (docolor) {
207                  printf("/redline %d string def\n", xmax);
208                  printf("/grnline %d string def\n", xmax);
209                  printf("/bluline %d string def\n", xmax);
210 <                printf("/rgbline %d string def\n", 3*xmax);
211 <                PSprocdef("read6bitRLE", "interleave");
212 <        } else {
213 <                printf("/greyline %d string def\n", xmax);
214 <                PSprocdef("read6bitRLE", NULL);
190 <        }
210 >        } else
211 >                printf("/gryline %d string def\n", xmax);
212 >                                        /* use compressed encoding? */
213 >        if (putprim == Cputprim)
214 >                PSprocdef("read6bitRLE");
215                                          /* set up transformation matrix */
216          printf("%f %f translate\n", HMARGIN, VMARGIN);
217          if (pwidth == PHEIGHT) {
218 <                printf("0 %f translate\n", PHEIGHT);
219 <                puts("-90 rotate");
218 >                printf("%f 0 translate\n", PWIDTH);
219 >                puts("90 rotate");
220          }
221          printf("%f %f translate\n", (pwidth-iwidth)*.5, (pheight-iheight)*.5);
222          printf("%f %f scale\n", iwidth, iheight);
223          puts("%%EndProlog");
224                                          /* start image procedure */
225 <        printf("%d %d 8 [%d 0 0 %d 0 %d] ", xmax, ymax, xmax, -ymax, ymax);
226 <        if (docolor) {
227 <                puts("{redline read6bitRLE grnline read6bitRLE");
228 <                puts("\tbluline read6bitRLE rgbline interleave} false 3 colorimage");
229 <        } else
230 <                puts("{greyline read6bitRLE} image");
225 >        printf("%d %d 8 [%d 0 0 %d 0 %d]\n", xmax, ymax, xmax, -ymax, ymax);
226 >        if (putprim == Cputprim) {
227 >                if (docolor) {
228 >                        puts("{redline read6bitRLE}");
229 >                        puts("{grnline read6bitRLE}");
230 >                        puts("{bluline read6bitRLE}");
231 >                        puts("true 3 colorimage");
232 >                } else
233 >                        puts("{gryline read6bitRLE} image");
234 >        } else {
235 >                rstr = putprim==Aputprim ? "readhexstring" : "readstring";
236 >                if (docolor) {
237 >                        printf("{currentfile redline %s pop}\n", rstr);
238 >                        printf("{currentfile grnline %s pop}\n", rstr);
239 >                        printf("{currentfile bluline %s pop}\n", rstr);
240 >                        puts("true 3 colorimage");
241 >                } else
242 >                        printf("{currentfile gryline %s pop} image\n", rstr);
243 >        }
244   }
245  
246  
# Line 219 | Line 256 | PStrailer()                    /* print PostScript trailer */
256   }
257  
258  
259 < PSprocdef(nam, inam)            /* define PS procedure to read image */
260 < char  *nam, *inam;
259 > PSprocdef(nam)                  /* define PS procedure to read image */
260 > char  *nam;
261   {
262          short  itab[128];
263          register int  i;
# Line 228 | Line 265 | char  *nam, *inam;
265          for (i = 0; i < 128; i++)       /* clear */
266                  itab[i] = -1;
267          for (i = 1; i < 63; i++)        /* assign greys */
268 <                itab[code[i]] = 256.0*pow(((i<<2)+2.5)/256.0, GAMVAL);
268 >                itab[code[i]] = 256.0*pow((i+.5)/64.0, CODE6GAM);
269          itab[code[0]] = 0;              /* black is black */
270          itab[code[63]] = 255;           /* and white is white */
271          printf("/codetab [");
# Line 256 | Line 293 | char  *nam, *inam;
293          printf("\t\t} for\n");
294          printf("\t} stopped {pop pop 0 string} {scanline} ifelse\n");
295          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");
296   }
297  
298  
# Line 286 | Line 308 | ra2ps()                                /* convert Radiance scanlines to 6-bit */
308          for (y = ymax-1; y >= 0; y--) {
309                  if (freadcolrs(scanin, xmax, stdin) < 0)
310                          quiterr("error reading Radiance picture");
311 <                if (bradj)                      /* adjust exposure */
312 <                        shiftcolrs(scanin, xmax, bradj);
313 <                colrs_gambs(scanin, xmax);      /* gamma compression */
311 >                if (putprim == Cputprim || devgam != 1.) {
312 >                        if (bradj)                      /* adjust exposure */
313 >                                shiftcolrs(scanin, xmax, bradj);
314 >                        colrs_gambs(scanin, xmax);      /* gamma compression */
315 >                } else
316 >                        normcolrs(scanin, xmax, bradj);
317                  if (docolor) {
318 <                        putprim(scanin, RED);
319 <                        putprim(scanin, GRN);
320 <                        putprim(scanin, BLU);
318 >                        (*putprim)(scanin, RED);
319 >                        (*putprim)(scanin, GRN);
320 >                        (*putprim)(scanin, BLU);
321                  } else
322 <                        putprim(scanin, GRY);
322 >                        (*putprim)(scanin, GRY);
323                  if (ferror(stdout))
324                          quiterr("error writing PostScript file");
325          }
# Line 304 | Line 329 | ra2ps()                                /* convert Radiance scanlines to 6-bit */
329   }
330  
331  
332 < putprim(scn, pri)               /* put out one primary from scanline */
332 > int
333 > Aputprim(scn, pri)              /* put out hex ASCII primary from scanline */
334 > COLR    *scn;
335 > int     pri;
336 > {
337 >        static char     hexdigit[] = "0123456789ABCDEF";
338 >        static int      col = 0;
339 >        register int    x, c;
340 >
341 >        for (x = 0; x < xmax; x++) {
342 >                if (pri == GRY)
343 >                        c = normbright(scn[x]);
344 >                else
345 >                        c = scn[x][pri];
346 >                if (c > 255) c = 255;
347 >                putchar(hexdigit[c>>4]);
348 >                putchar(hexdigit[c&0xf]);
349 >                if ((col += 2) >= 72) {
350 >                        putchar('\n');
351 >                        col = 0;
352 >                }
353 >        }
354 > }
355 >
356 >
357 > int
358 > Bputprim(scn, pri)              /* put out binary primary from scanline */
359 > COLR    *scn;
360 > int     pri;
361 > {
362 >        register int    x, c;
363 >
364 >        for (x = 0; x < xmax; x++) {
365 >                if (pri == GRY)
366 >                        c = normbright(scn[x]);
367 >                else
368 >                        c = scn[x][pri];
369 >                if (c > 255) c = 255;
370 >                putchar(c);
371 >        }
372 > }
373 >
374 >
375 > int
376 > Cputprim(scn, pri)              /* put out compressed primary from scanline */
377   COLR    *scn;
378   int     pri;
379   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines