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.2 by greg, Tue Sep 12 13:04:20 1989 UTC vs.
Revision 2.4 by greg, Wed Jan 29 16:51:40 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          if (argc < 2)
53                  status = printp(NULL) == -1;
54          else
# Line 43 | Line 61 | char  *argv[];
61   printp(fname)                           /* print a picture */
62   char  *fname;
63   {
64 +        char  buf[64];
65          FILE  *input;
66          int  xres, yres;
67 <        COLOR  scanline[NCOLS];
67 >        COLR  scanline[NCOLS];
68          int  i;
69  
70 <        if (fname == NULL) {
70 >        if (dofilter) {
71 >                if (fname == NULL)
72 >                        fname = "";
73 >                sprintf(buf, FILTER, fname);
74 >                if ((input = popen(buf, "r")) == NULL) {
75 >                        fprintf(stderr, "Cannot execute: %s\n", buf);
76 >                        return(-1);
77 >                }
78 >                fname = buf;
79 >        } else if (fname == NULL) {
80                  input = stdin;
81                  fname = "<stdin>";
82          } else if ((input = fopen(fname, "r")) == NULL) {
# Line 56 | Line 84 | char  *fname;
84                  return(-1);
85          }
86                                  /* discard header */
87 <        getheader(input, NULL);
87 >        if (checkheader(input, COLRFMT, NULL) < 0) {
88 >                fprintf(stderr, "%s: not a Radiance picture\n", fname);
89 >                return(-1);
90 >        }
91                                  /* get picture dimensions */
92 <        if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
92 >        if (fgetresolu(&xres, &yres, input) < 0) {
93                  fprintf(stderr, "%s: bad picture size\n", fname);
94                  return(-1);
95          }
# Line 66 | Line 97 | char  *fname;
97                  fprintf(stderr, "%s: resolution mismatch\n", fname);
98                  return(-1);
99          }
100 <
101 <        fputs("\033A\014\0332", stdout);
102 <        
100 >                                /* set line spacing (overlap for knitting) */
101 >        fputs("\0333\042", stdout);
102 >                                /* clear line buffer */
103 >        clearlbuf();
104 > #ifdef _IOLBF
105 >        stdout->_flag &= ~_IOLBF;
106 > #endif
107 >                                /* put out scanlines */
108          for (i = yres-1; i >= 0; i--) {
109 <                if (freadscan(scanline, xres, input) < 0) {
109 >                if (freadcolrs(scanline, xres, input) < 0) {
110                          fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
111                          return(-1);
112                  }
113 +                normcolrs(scanline, xres, 0);
114                  plotscan(scanline, xres, i);
115          }
116 <
116 >                                /* advance page */
117          putchar('\f');
118          
119 <        fclose(input);
119 >        if (dofilter)
120 >                pclose(input);
121 >        else
122 >                fclose(input);
123  
124          return(0);
125   }
126  
127  
128   plotscan(scan, len, y)                  /* plot a scanline */
129 < COLOR  scan[];
129 > COLR  scan[];
130   int  len;
131   int  y;
132   {
93        static long  pat[NCOLS][3];
133          int  bpos;
134          register long  c;
135          register int  i, j;
136  
137 <        if (bpos = y % 24) {
137 >        if (bpos = y % 23) {
138  
139                  for (j = 0; j < 3; j++)
140                          for (i = 0; i < len; i++)
141 <                                pat[i][j] |= (long)colbit(scan[i],i,j) << bpos;
141 >                                lpat[i][j] |= (long)colbit(scan[i],i,j) << bpos;
142  
143          } else {
144  
145                  fputs("\033\031", stdout);
146  
147                  for (j = 0; j < 3; j++) {
148 +                        i = (NCOLS + len)/2;            /* center image */
149                          fputs("\033%O", stdout);
150 <                        putchar(len & 255);
151 <                        putchar(len >> 8);
150 >                        putchar(i & 255);
151 >                        putchar(i >> 8);
152 >                        while (i-- > len) {
153 >                                putchar(0);
154 >                                putchar(0);
155 >                                putchar(0);
156 >                        }
157                          for (i = 0; i < len; i++) {
158 <                                c = pat[i][j] | colbit(scan[i],i,j);
159 <                                pat[i][j] = 0;
158 >                                c = lpat[i][j] | colbit(scan[i],i,j);
159 >                                                        /* repeat this row */
160 >                                lpat[i][j] = (c & 1) << 23;
161                                  putchar(c>>16);
162                                  putchar(c>>8 & 255);
163                                  putchar(c & 255);
# Line 119 | Line 165 | int  y;
165                          putchar('\r');
166                  }
167                  putchar('\n');
168 +                fflush(stdout);
169          }
170   }
171  
172  
173   colbit(col, x, s)               /* determine bit value for primary at x */
174 < COLOR  col;
174 > COLR  col;
175   register int  x;
176   int  s;
177   {
178 <        static float  cerr[NCOLS][3];
179 <        static double  err[3];
180 <        double  b;
178 >        static int  cerr[NCOLS][3];
179 >        static int  err[3];
180 >        int  b, errp;
181          register int  a, ison;
182  
183          a = sub_add(s);                 /* use additive primary */
184 <        b = colval(col,a);
185 <        if (b > 1.0) b = 1.0;
184 >        b = col[a];
185 >        errp = err[a];
186          err[a] += b + cerr[x][a];
187 <        ison = err[a] < 0.5;
188 <        if (!ison) err[a] -= 1.0;
189 <        cerr[x][a] = err[a] *= 0.5;
187 >        ison = err[a] < 128;
188 >        if (!ison) err[a] -= 256;
189 >        err[a] /= 3;
190 >        cerr[x][a] = err[a] + errp;
191          return(ison);
192   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines