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.9 by greg, Tue Jul 10 09:07:48 1990 UTC vs.
Revision 2.10 by greg, Mon Aug 2 14:39:07 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 6 | Line 6 | static char SCCSid[] = "$SunId$ LBL";
6  
7   /*
8   *  oki20c.c - program to dump pixel file to OkiMate 20 color printer.
9 *
10 *     6/10/87
9   */
10  
11   #include  <stdio.h>
12 + #ifdef MSDOS
13 + #include  <fcntl.h>
14 + #endif
15  
16   #include  "color.h"
17 + #include  "resolu.h"
18  
19 + #define  NROWS          1440            /* 10" at 144 dpi */
20 + #define  NCOLS          960             /* 8" at 120 dpi */
21  
22 < #define  NROWS          1440            /* 10" at 144 dpi */
19 < #define  NCOLS          960             /* 8" at 120 dpi */
22 > #define  ASPECT         (120./144.)     /* pixel aspect ratio */
23  
24 + #define  FILTER         "pfilt -1 -x %d -y %d -p %f %s",NCOLS,NROWS,ASPECT
25 +
26   /*
27 < *  Subtractive primaries are ordered:  Yellow, Magenta, Cyan.
27 > *  Subtractive primaries are ordered:  Yellow, Magenta, Cyan.
28   */
29  
30 < #define  sub_add(sub)   (2-(sub))       /* map subtractive to additive pri. */
30 > #define  sub_add(sub)   (2-(sub))       /* map subtractive to additive pri. */
31  
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
32   long  lpat[NCOLS][3];
33  
34 + int  dofilter = 0;              /* filter through pfilt first? */
35  
36 + extern FILE  *popen();
37 +
38 +
39   main(argc, argv)
40   int  argc;
41   char  *argv[];
42   {
43          int  i, status = 0;
44 <        
44 > #ifdef MSDOS
45 >        extern int  _fmode;
46 >        _fmode = O_BINARY;
47 >        setmode(fileno(stdin), O_BINARY);
48 >        setmode(fileno(stdout), O_BINARY);
49 > #endif
50 >        if (argc > 1 && !strcmp(argv[1], "-p")) {
51 >                dofilter++;
52 >                argv++; argc--;
53 >        }
54          if (argc < 2)
55                  status = printp(NULL) == -1;
56          else
# Line 51 | Line 63 | char  *argv[];
63   printp(fname)                           /* print a picture */
64   char  *fname;
65   {
66 +        char  buf[64];
67          FILE  *input;
68          int  xres, yres;
69          COLR  scanline[NCOLS];
70          int  i;
71  
72 <        if (fname == NULL) {
72 >        if (dofilter) {
73 >                if (fname == NULL) {
74 >                        sprintf(buf, FILTER, "");
75 >                        fname = "<stdin>";
76 >                } else
77 >                        sprintf(buf, FILTER, fname);
78 >                if ((input = popen(buf, "r")) == NULL) {
79 >                        fprintf(stderr, "Cannot execute: %s\n", buf);
80 >                        return(-1);
81 >                }
82 >        } else if (fname == NULL) {
83                  input = stdin;
84                  fname = "<stdin>";
85          } else if ((input = fopen(fname, "r")) == NULL) {
# Line 64 | Line 87 | char  *fname;
87                  return(-1);
88          }
89                                  /* discard header */
90 <        getheader(input, NULL);
90 >        if (checkheader(input, COLRFMT, NULL) < 0) {
91 >                fprintf(stderr, "%s: not a Radiance picture\n", fname);
92 >                return(-1);
93 >        }
94                                  /* get picture dimensions */
95 <        if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
95 >        if (fgetresolu(&xres, &yres, input) < 0) {
96                  fprintf(stderr, "%s: bad picture size\n", fname);
97                  return(-1);
98          }
99 <        if (xres > NCOLS || yres > NROWS) {
99 >        if (xres > NCOLS) {
100                  fprintf(stderr, "%s: resolution mismatch\n", fname);
101                  return(-1);
102          }
103                                  /* set line spacing (overlap for knitting) */
104          fputs("\0333\042", stdout);
79                                /* clear line buffer */
80        clearlbuf();
105                                  /* put out scanlines */
106          for (i = yres-1; i >= 0; i--) {
107                  if (freadcolrs(scanline, xres, input) < 0) {
# Line 90 | Line 114 | char  *fname;
114                                  /* advance page */
115          putchar('\f');
116          
117 <        fclose(input);
117 >        if (dofilter)
118 >                pclose(input);
119 >        else
120 >                fclose(input);
121  
122          return(0);
123   }
# Line 110 | Line 137 | int  y;
137                  for (j = 0; j < 3; j++)
138                          for (i = 0; i < len; i++)
139                                  lpat[i][j] |= (long)colbit(scan[i],i,j) << bpos;
140 +                return;
141 +        }
142 +        fputs("\033\031", stdout);
143  
144 <        } else {
145 <
146 <                fputs("\033\031", stdout);
147 <
148 <                for (j = 0; j < 3; j++) {
149 <                        fputs("\033%O", stdout);
150 <                        putchar(len & 255);
151 <                        putchar(len >> 8);
152 <                        for (i = 0; i < len; i++) {
153 <                                c = lpat[i][j] | colbit(scan[i],i,j);
154 <                                                        /* repeat this row */
144 >        for (j = 0; j < 3; j++) {
145 >                i = (NCOLS + len)/2;            /* center image */
146 >                fputs("\033%O", stdout);
147 >                putchar(i & 255);
148 >                putchar(i >> 8);
149 >                while (i-- > len) {
150 >                        putchar(0);
151 >                        putchar(0);
152 >                        putchar(0);
153 >                }
154 >                for (i = 0; i < len; i++) {
155 >                        c = lpat[i][j] | colbit(scan[i],i,j);
156 >                        putchar((int)(c>>16));
157 >                        putchar((int)(c>>8 & 255));
158 >                        putchar((int)(c & 255));
159 >                        if (y)                  /* repeat this row */
160                                  lpat[i][j] = (c & 1) << 23;
161 <                                putchar(c>>16);
162 <                                putchar(c>>8 & 255);
128 <                                putchar(c & 255);
129 <                        }
130 <                        putchar('\r');
161 >                        else                    /* or clear for next image */
162 >                                lpat[i][j] = 0L;
163                  }
164 <                putchar('\n');
164 >                putchar('\r');
165          }
166 +        putchar('\n');
167 +        fflush(stdout);
168   }
169  
170  
# Line 141 | Line 175 | int  s;
175   {
176          static int  cerr[NCOLS][3];
177          static int  err[3];
178 <        int  b;
178 >        int  b, errp;
179          register int  a, ison;
180  
181          a = sub_add(s);                 /* use additive primary */
182          b = col[a];
183 +        errp = err[a];
184          err[a] += b + cerr[x][a];
185          ison = err[a] < 128;
186          if (!ison) err[a] -= 256;
187 <        cerr[x][a] = err[a] /= 2;
187 >        err[a] /= 3;
188 >        cerr[x][a] = err[a] + errp;
189          return(ison);
190   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines