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.10 by greg, Wed Sep 27 13:29:52 1995 UTC vs.
Revision 2.14 by greg, Wed Oct 4 16:01:32 1995 UTC

# Line 9 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
9   */
10  
11   #include  <stdio.h>
12 + #include  <math.h>
13   #ifdef MSDOS
14   #include  <fcntl.h>
15   #endif
16   #include  "color.h"
17  
18 + #define GAMVAL          1.5                     /* gamma value for pixels */
19 +
20 + #define GRY             -1                      /* artificial index for grey */
21 +
22   #define HMARGIN         (.5*72)                 /* horizontal margin */
23   #define VMARGIN         (.5*72)                 /* vertical margin */
24   #define PWIDTH          (8.5*72-2*HMARGIN)      /* width of device */
# Line 30 | Line 35 | char  code[] =                 /* 6-bit code lookup table */
35   int  wrongformat = 0;                   /* input in wrong format? */
36   double  pixaspect = 1.0;                /* pixel aspect ratio */
37  
38 + int  docolor = 0;                       /* produce color image? */
39   int  bradj = 0;                         /* brightness adjustment */
40   int  ncopies = 1;                       /* number of copies */
41  
# Line 64 | Line 70 | char  *argv[];
70          for (i = 1; i < argc; i++)
71                  if (argv[i][0] == '-')
72                          switch (argv[i][1]) {
73 +                        case 'c':               /* produce color PostScript */
74 +                                docolor++;
75 +                                break;
76                          case 'e':               /* exposure adjustment */
77                                  if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
78                                          goto userr;
# Line 97 | Line 106 | char  *argv[];
106          getheader(stdin, headline, NULL);
107          if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0)
108                  quiterr("bad picture format");
109 +                                /* gamma compression */
110 +        setcolrgam(GAMVAL);
111                                  /* write header */
112          PSheader(i <= argc-1 ? argv[i] : "<stdin>");
113                                  /* convert file */
# Line 105 | Line 116 | char  *argv[];
116          PStrailer();
117          exit(0);
118   userr:
119 <        fprintf(stderr, "Usage: %s [-e +/-stops] [input [output]]\n", progname);
119 >        fprintf(stderr, "Usage: %s [-c][-e +/-stops] [input [output]]\n",
120 >                        progname);
121          exit(1);
122   }
123  
# Line 128 | Line 140 | char  *name;
140          double  pwidth, pheight;
141          double  iwidth, iheight;
142                                          /* EPS comments */
143 <        puts("%%!PS-Adobe-2.0 EPSF-2.0");
143 >        puts("%!PS-Adobe-2.0 EPSF-2.0");
144          printf("%%%%Title: %s\n", name);
145          printf("%%%%Creator: %s = %s\n", progname, SCCSid);
146          printf("%%%%Pages: %d\n", ncopies);
# Line 163 | Line 175 | char  *name;
175                                  HMARGIN+(pwidth-iwidth)*.5+iwidth,
176                                  VMARGIN+(pheight-iheight)*.5+iheight);
177          puts("%%EndComments");
178 <        puts("save");
178 >        puts("gsave save");
179          puts("64 dict begin");
180                                          /* define image reader */
181 <        PSprocdef("read6bitRLE");
181 >        if (docolor) {
182 >                printf("/redline %d string def\n", xmax);
183 >                printf("/grnline %d string def\n", xmax);
184 >                printf("/bluline %d string def\n", xmax);
185 >                printf("/rgbline %d string def\n", 3*xmax);
186 >                PSprocdef("read6bitRLE", "interleave");
187 >        } else {
188 >                printf("/greyline %d string def\n", xmax);
189 >                PSprocdef("read6bitRLE", NULL);
190 >        }
191                                          /* set up transformation matrix */
192          printf("%f %f translate\n", HMARGIN, VMARGIN);
193          if (pwidth == PHEIGHT) {
194 <                printf("0 %f translate\n", PHEIGHT);
195 <                puts("-90 rotate");
194 >                printf("%f 0 translate\n", PWIDTH);
195 >                puts("90 rotate");
196          }
197          printf("%f %f translate\n", (pwidth-iwidth)*.5, (pheight-iheight)*.5);
198          printf("%f %f scale\n", iwidth, iheight);
199 <        puts("%%%%EndProlog");
199 >        puts("%%EndProlog");
200                                          /* start image procedure */
201 <        printf("%d %d 8 [%d 0 0 %d 0 %d] {read6bitRLE} image\n", xmax, ymax,
202 <                        xmax, -ymax, ymax);
201 >        printf("%d %d 8 [%d 0 0 %d 0 %d] ", xmax, ymax, xmax, -ymax, ymax);
202 >        if (docolor) {
203 >                puts("{redline read6bitRLE grnline read6bitRLE");
204 >                puts("\tbluline read6bitRLE rgbline interleave} false 3 colorimage");
205 >        } else
206 >                puts("{greyline read6bitRLE} image");
207   }
208  
209  
# Line 189 | Line 214 | PStrailer()                    /* print PostScript trailer */
214                  printf("/#copies %d def\n", ncopies);
215          puts("showpage");
216          puts("end");
217 <        puts("restore");
217 >        puts("restore grestore");
218          puts("%%EOF");
219   }
220  
221  
222 < PSprocdef(nam)                  /* define PS procedure to read image */
223 < char  *nam;
222 > PSprocdef(nam, inam)            /* define PS procedure to read image */
223 > char  *nam, *inam;
224   {
225          short  itab[128];
226          register int  i;
# Line 203 | Line 228 | char  *nam;
228          for (i = 0; i < 128; i++)       /* clear */
229                  itab[i] = -1;
230          for (i = 1; i < 63; i++)        /* assign greys */
231 <                itab[code[i]] = i<<2 | 2;
231 >                itab[code[i]] = 256.0*pow(((i<<2)+2.5)/256.0, GAMVAL);
232          itab[code[0]] = 0;              /* black is black */
233          itab[code[63]] = 255;           /* and white is white */
234          printf("/codetab [");
# Line 213 | Line 238 | char  *nam;
238                  printf(" %3d", itab[i]);
239          }
240          printf("\n] def\n");
216        printf("/scanline %d string def\n", xmax);
241          printf("/nrept 0 def\n");
242 <        printf("/readbyte { currentfile read not {stop} if } def\n");
243 <        printf("/decode { codetab exch get } def\n");
244 <        printf("/%s {\n", nam);
242 >        printf("/readbyte { currentfile read not {stop} if } bind def\n");
243 >        printf("/decode { codetab exch get } bind def\n");
244 >        printf("/%s {\t%% scanbuffer\n", nam);
245 >        printf("\t/scanline exch def\n");
246          printf("\t{ 0 1 %d { scanline exch\n", xmax-1);
247          printf("\t\tnrept 0 le\n");
248          printf("\t\t\t{ { readbyte dup %d eq\n", RUNCHR);
# Line 231 | Line 256 | char  *nam;
256          printf("\t\t} for\n");
257          printf("\t} stopped {pop pop 0 string} {scanline} ifelse\n");
258          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");
274   }
275  
276  
277   ra2ps()                         /* convert Radiance scanlines to 6-bit */
278   {
279          register COLR   *scanin;
240        register int    c;
241        int     lastc, cnt;
242        register int    x;
280          int     y;
281                                                  /* allocate scanline */
282          scanin = (COLR *)malloc(xmax*sizeof(COLR));
# Line 249 | Line 286 | ra2ps()                                /* convert Radiance scanlines to 6-bit */
286          for (y = ymax-1; y >= 0; y--) {
287                  if (freadcolrs(scanin, xmax, stdin) < 0)
288                          quiterr("error reading Radiance picture");
289 <                normcolrs(scanin, xmax, bradj); /* normalize */
290 <                lastc = -1; cnt = 0;
291 <                for (x = 0; x < xmax; x++) {
292 <                        c = normbright(scanin[x]) + 2;
293 <                        if (c > 255) c = 255;
294 <                        c = code[c>>2];
295 <                        if (c == lastc && cnt < MAXRUN)
296 <                                cnt++;
297 <                        else {
261 <                                putrle(cnt, lastc);
262 <                                lastc = c;
263 <                                cnt = 1;
264 <                        }
265 <                }
266 <                putrle(cnt, lastc);
289 >                if (bradj)                      /* adjust exposure */
290 >                        shiftcolrs(scanin, xmax, bradj);
291 >                colrs_gambs(scanin, xmax);      /* gamma compression */
292 >                if (docolor) {
293 >                        putprim(scanin, RED);
294 >                        putprim(scanin, GRN);
295 >                        putprim(scanin, BLU);
296 >                } else
297 >                        putprim(scanin, GRY);
298                  if (ferror(stdout))
299                          quiterr("error writing PostScript file");
300          }
301          putchar('\n');
302                                                  /* free scanline */
303          free((char *)scanin);
304 + }
305 +
306 +
307 + putprim(scn, pri)               /* put out one primary from scanline */
308 + COLR    *scn;
309 + int     pri;
310 + {
311 +        register int    c;
312 +        register int    x;
313 +        int     lastc, cnt;
314 +
315 +        lastc = -1; cnt = 0;
316 +        for (x = 0; x < xmax; x++) {
317 +                if (pri == GRY)
318 +                        c = normbright(scn[x]) + 2;
319 +                else
320 +                        c = scn[x][pri] + 2;
321 +                if (c > 255) c = 255;
322 +                c = code[c>>2];
323 +                if (c == lastc && cnt < MAXRUN)
324 +                        cnt++;
325 +                else {
326 +                        putrle(cnt, lastc);
327 +                        lastc = c;
328 +                        cnt = 1;
329 +                }
330 +        }
331 +        putrle(cnt, lastc);
332   }
333  
334  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines