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.11 by greg, Mon May 6 13:14:23 1991 UTC vs.
Revision 2.14 by schorsch, Mon Oct 27 10:24:51 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1986 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  oki20c.c - program to dump pixel file to OkiMate 20 color printer.
9 *
10 *     6/10/87
6   */
7  
8   #include  <stdio.h>
9 + #include  <time.h>
10  
11 + #include  "platform.h"
12 + #include  "rtprocess.h"
13   #include  "color.h"
14 + #include  "resolu.h"
15  
16 + #define  NROWS          1440            /* 10" at 144 dpi */
17 + #define  NCOLS          960             /* 8" at 120 dpi */
18  
19 < #define  NROWS          1440            /* 10" at 144 dpi */
19 < #define  NCOLS          960             /* 8" at 120 dpi */
19 > #define  ASPECT         (120./144.)     /* pixel aspect ratio */
20  
21 + #define  FILTER         "pfilt -1 -x %d -y %d -p %f %s",NCOLS,NROWS,ASPECT
22 +
23   /*
24 < *  Subtractive primaries are ordered:  Yellow, Magenta, Cyan.
24 > *  Subtractive primaries are ordered:  Yellow, Magenta, Cyan.
25   */
26  
27 < #define  sub_add(sub)   (2-(sub))       /* map subtractive to additive pri. */
27 > #define  sub_add(sub)   (2-(sub))       /* map subtractive to additive pri. */
28  
27 #ifdef  BSD
28 #define  clearlbuf()    bzero((char *)lpat, sizeof(lpat))
29 #else
30 #define  clearlbuf()    (void)memset((char *)lpat, 0, sizeof(lpat))
31 #endif
32
29   long  lpat[NCOLS][3];
30  
31 + int  dofilter = 0;              /* filter through pfilt first? */
32  
33 +
34   main(argc, argv)
35   int  argc;
36   char  *argv[];
37   {
38          int  i, status = 0;
39 <        
39 >        SET_DEFAULT_BINARY();
40 >        SET_FILE_BINARY(stdin);
41 >        SET_FILE_BINARY(stdout);
42 >        if (argc > 1 && !strcmp(argv[1], "-p")) {
43 >                dofilter++;
44 >                argv++; argc--;
45 >        }
46          if (argc < 2)
47                  status = printp(NULL) == -1;
48          else
# Line 51 | Line 55 | char  *argv[];
55   printp(fname)                           /* print a picture */
56   char  *fname;
57   {
58 +        char  buf[64];
59          FILE  *input;
60          int  xres, yres;
61          COLR  scanline[NCOLS];
62          int  i;
63  
64 <        if (fname == NULL) {
64 >        if (dofilter) {
65 >                if (fname == NULL) {
66 >                        sprintf(buf, FILTER, "");
67 >                        fname = "<stdin>";
68 >                } else
69 >                        sprintf(buf, FILTER, fname);
70 >                if ((input = popen(buf, "r")) == NULL) {
71 >                        fprintf(stderr, "Cannot execute: %s\n", buf);
72 >                        return(-1);
73 >                }
74 >        } else if (fname == NULL) {
75                  input = stdin;
76                  fname = "<stdin>";
77          } else if ((input = fopen(fname, "r")) == NULL) {
# Line 69 | Line 84 | char  *fname;
84                  return(-1);
85          }
86                                  /* get picture dimensions */
87 <        if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
87 >        if (fgetresolu(&xres, &yres, input) < 0) {
88                  fprintf(stderr, "%s: bad picture size\n", fname);
89                  return(-1);
90          }
91 <        if (xres > NCOLS || yres > NROWS) {
91 >        if (xres > NCOLS) {
92                  fprintf(stderr, "%s: resolution mismatch\n", fname);
93                  return(-1);
94          }
95                                  /* set line spacing (overlap for knitting) */
96          fputs("\0333\042", stdout);
82                                /* clear line buffer */
83        clearlbuf();
97                                  /* put out scanlines */
98          for (i = yres-1; i >= 0; i--) {
99                  if (freadcolrs(scanline, xres, input) < 0) {
# Line 93 | Line 106 | char  *fname;
106                                  /* advance page */
107          putchar('\f');
108          
109 <        fclose(input);
109 >        if (dofilter)
110 >                pclose(input);
111 >        else
112 >                fclose(input);
113  
114          return(0);
115   }
# Line 108 | Line 124 | int  y;
124          register long  c;
125          register int  i, j;
126  
127 <        if (bpos = y % 23) {
127 >        if ( (bpos = y % 23) ) {
128  
129                  for (j = 0; j < 3; j++)
130                          for (i = 0; i < len; i++)
131                                  lpat[i][j] |= (long)colbit(scan[i],i,j) << bpos;
132 +                return;
133 +        }
134 +        fputs("\033\031", stdout);
135  
136 <        } else {
137 <
138 <                fputs("\033\031", stdout);
139 <
140 <                for (j = 0; j < 3; j++) {
141 <                        fputs("\033%O", stdout);
142 <                        putchar(len & 255);
143 <                        putchar(len >> 8);
144 <                        for (i = 0; i < len; i++) {
145 <                                c = lpat[i][j] | colbit(scan[i],i,j);
146 <                                                        /* repeat this row */
136 >        for (j = 0; j < 3; j++) {
137 >                i = (NCOLS + len)/2;            /* center image */
138 >                fputs("\033%O", stdout);
139 >                putchar(i & 255);
140 >                putchar(i >> 8);
141 >                while (i-- > len) {
142 >                        putchar(0);
143 >                        putchar(0);
144 >                        putchar(0);
145 >                }
146 >                for (i = 0; i < len; i++) {
147 >                        c = lpat[i][j] | colbit(scan[i],i,j);
148 >                        putchar((int)(c>>16));
149 >                        putchar((int)(c>>8 & 255));
150 >                        putchar((int)(c & 255));
151 >                        if (y)                  /* repeat this row */
152                                  lpat[i][j] = (c & 1) << 23;
153 <                                putchar(c>>16);
154 <                                putchar(c>>8 & 255);
131 <                                putchar(c & 255);
132 <                        }
133 <                        putchar('\r');
153 >                        else                    /* or clear for next image */
154 >                                lpat[i][j] = 0L;
155                  }
156 <                putchar('\n');
156 >                putchar('\r');
157          }
158 +        putchar('\n');
159 +        fflush(stdout);
160   }
161  
162  
# Line 143 | Line 166 | register int  x;
166   int  s;
167   {
168          static int  cerr[NCOLS][3];
169 <        static int  err[3], errp[3];
170 <        int  b;
169 >        static int  err[3];
170 >        int  b, errp;
171          register int  a, ison;
172  
173          a = sub_add(s);                 /* use additive primary */
174          b = col[a];
175 <        errp[a] = err[a];
175 >        errp = err[a];
176          err[a] += b + cerr[x][a];
177          ison = err[a] < 128;
178          if (!ison) err[a] -= 256;
179          err[a] /= 3;
180 <        cerr[x][a] = err[a] + errp[a];
180 >        cerr[x][a] = err[a] + errp;
181          return(ison);
182   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines