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

Comparing ray/src/px/oki20c.c (file contents):
Revision 1.6 by greg, Fri Oct 20 16:44:34 1989 UTC vs.
Revision 2.6 by greg, Sat Apr 18 09:10:53 1992 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 13 | Line 13 | static char SCCSid[] = "$SunId$ LBL";
13   #include  <stdio.h>
14  
15   #include  "color.h"
16 + #include  "resolu.h"
17  
17
18   #define  NROWS          1440            /* 10" at 144 dpi */
19   #define  NCOLS          960             /* 8" at 120 dpi */
20  
21 + #define  ASPECT         (120./144.)     /* pixel aspect ratio */
22 +
23 + #define  FILTER         "pfilt -1 -x %d -y %d -p %f %s",NCOLS,NROWS,ASPECT
24 +
25   /*
26   *  Subtractive primaries are ordered:  Yellow, Magenta, Cyan.
27   */
28  
29   #define  sub_add(sub)   (2-(sub))       /* map subtractive to additive pri. */
30  
31 + #ifdef  BSD
32 + #define  clearlbuf()    bzero((char *)lpat, sizeof(lpat))
33 + #else
34 + #define  clearlbuf()    (void)memset((char *)lpat, 0, sizeof(lpat))
35 + #endif
36  
37 + long  lpat[NCOLS][3];
38 +
39 + int  dofilter = 0;              /* filter through pfilt first? */
40 +
41 +
42   main(argc, argv)
43   int  argc;
44   char  *argv[];
45   {
46          int  i, status = 0;
47          
48 +        if (argc > 1 && !strcmp(argv[1], "-p")) {
49 +                dofilter++;
50 +                argv++; argc--;
51 +        }
52 + #ifdef _IOLBF
53 +        stdout->_flag &= ~_IOLBF;
54 + #endif
55          if (argc < 2)
56                  status = printp(NULL) == -1;
57          else
# Line 43 | Line 64 | char  *argv[];
64   printp(fname)                           /* print a picture */
65   char  *fname;
66   {
67 +        char  buf[64];
68          FILE  *input;
69          int  xres, yres;
70          COLR  scanline[NCOLS];
71          int  i;
72  
73 <        if (fname == NULL) {
73 >        if (dofilter) {
74 >                if (fname == NULL) {
75 >                        sprintf(buf, FILTER, "");
76 >                        fname = "<stdin>";
77 >                } else
78 >                        sprintf(buf, FILTER, fname);
79 >                if ((input = popen(buf, "r")) == NULL) {
80 >                        fprintf(stderr, "Cannot execute: %s\n", buf);
81 >                        return(-1);
82 >                }
83 >        } else if (fname == NULL) {
84                  input = stdin;
85                  fname = "<stdin>";
86          } else if ((input = fopen(fname, "r")) == NULL) {
# Line 56 | Line 88 | char  *fname;
88                  return(-1);
89          }
90                                  /* discard header */
91 <        getheader(input, NULL);
91 >        if (checkheader(input, COLRFMT, NULL) < 0) {
92 >                fprintf(stderr, "%s: not a Radiance picture\n", fname);
93 >                return(-1);
94 >        }
95                                  /* get picture dimensions */
96 <        if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
96 >        if (fgetresolu(&xres, &yres, input) < 0) {
97                  fprintf(stderr, "%s: bad picture size\n", fname);
98                  return(-1);
99          }
# Line 68 | Line 103 | char  *fname;
103          }
104                                  /* set line spacing (overlap for knitting) */
105          fputs("\0333\042", stdout);
106 +                                /* clear line buffer */
107 +        clearlbuf();
108                                  /* put out scanlines */
109          for (i = yres-1; i >= 0; i--) {
110                  if (freadcolrs(scanline, xres, input) < 0) {
111                          fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
112                          return(-1);
113                  }
114 <                normscan(scanline, xres);
114 >                normcolrs(scanline, xres, 0);
115                  plotscan(scanline, xres, i);
116          }
117                                  /* advance page */
118          putchar('\f');
119          
120 <        fclose(input);
120 >        if (dofilter)
121 >                pclose(input);
122 >        else
123 >                fclose(input);
124  
125          return(0);
126   }
127  
128  
89 normscan(scan, len)                     /* normalize a scanline */
90 register COLR  scan[];
91 int  len;
92 {
93        register int  i;
94
95        for (i = 0; i < len; i++)
96                colr_norm(scan[i], scan[i]);
97 }
98
99
129   plotscan(scan, len, y)                  /* plot a scanline */
130   COLR  scan[];
131   int  len;
132   int  y;
133   {
105        static long  pat[NCOLS][3];
134          int  bpos;
135          register long  c;
136          register int  i, j;
# Line 111 | Line 139 | int  y;
139  
140                  for (j = 0; j < 3; j++)
141                          for (i = 0; i < len; i++)
142 <                                pat[i][j] |= (long)colbit(scan[i],i,j) << bpos;
142 >                                lpat[i][j] |= (long)colbit(scan[i],i,j) << bpos;
143  
144          } else {
145  
146                  fputs("\033\031", stdout);
147  
148                  for (j = 0; j < 3; j++) {
149 +                        i = (NCOLS + len)/2;            /* center image */
150                          fputs("\033%O", stdout);
151 <                        putchar(len & 255);
152 <                        putchar(len >> 8);
151 >                        putchar(i & 255);
152 >                        putchar(i >> 8);
153 >                        while (i-- > len) {
154 >                                putchar(0);
155 >                                putchar(0);
156 >                                putchar(0);
157 >                        }
158                          for (i = 0; i < len; i++) {
159 <                                c = pat[i][j] | colbit(scan[i],i,j);
159 >                                c = lpat[i][j] | colbit(scan[i],i,j);
160                                                          /* repeat this row */
161 <                                pat[i][j] = (c & 1) << 23;
161 >                                lpat[i][j] = (c & 1) << 23;
162                                  putchar(c>>16);
163                                  putchar(c>>8 & 255);
164                                  putchar(c & 255);
# Line 132 | Line 166 | int  y;
166                          putchar('\r');
167                  }
168                  putchar('\n');
169 +                fflush(stdout);
170          }
171   }
172  
# Line 143 | Line 178 | int  s;
178   {
179          static int  cerr[NCOLS][3];
180          static int  err[3];
181 <        int  b;
181 >        int  b, errp;
182          register int  a, ison;
183  
184          a = sub_add(s);                 /* use additive primary */
185          b = col[a];
186 +        errp = err[a];
187          err[a] += b + cerr[x][a];
188          ison = err[a] < 128;
189          if (!ison) err[a] -= 256;
190 <        cerr[x][a] = err[a] /= 2;
190 >        err[a] /= 3;
191 >        cerr[x][a] = err[a] + errp;
192          return(ison);
193   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines