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.3 by greg, Fri Oct 20 10:28:59 1989 UTC vs.
Revision 2.16 by schorsch, Sun Mar 28 20:33:14 2004 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",NCOLS,NROWS,ASPECT
22 + #define  FILTER_F       "pfilt -1 -x %d -y %d -p %f \"%s\"",NCOLS,NROWS,ASPECT
23 +
24   /*
25 < *  Subtractive primaries are ordered:  Yellow, Magenta, Cyan.
25 > *  Subtractive primaries are ordered:  Yellow, Magenta, Cyan.
26   */
27  
28 < #define  sub_add(sub)   (2-(sub))       /* map subtractive to additive pri. */
28 > #define  sub_add(sub)   (2-(sub))       /* map subtractive to additive pri. */
29  
30 + long  lpat[NCOLS][3];
31  
32 < main(argc, argv)
33 < int  argc;
34 < char  *argv[];
32 > int  dofilter = 0;              /* filter through pfilt first? */
33 >
34 > static int printp(char  *fname);
35 > static void plotscan(COLR  scan[], int  len, int  y);
36 > static int colbit(COLR  col, int  x, int  s);
37 >
38 >
39 > int
40 > main(
41 >        int  argc,
42 >        char  *argv[]
43 > )
44   {
45          int  i, status = 0;
46 <        
46 >        SET_DEFAULT_BINARY();
47 >        SET_FILE_BINARY(stdin);
48 >        SET_FILE_BINARY(stdout);
49 >        if (argc > 1 && !strcmp(argv[1], "-p")) {
50 >                dofilter++;
51 >                argv++; argc--;
52 >        }
53          if (argc < 2)
54                  status = printp(NULL) == -1;
55          else
# Line 40 | Line 59 | char  *argv[];
59   }
60  
61  
62 < printp(fname)                           /* print a picture */
63 < char  *fname;
62 > static int
63 > printp(                         /* print a picture */
64 >        char  *fname
65 > )
66   {
67 +        char  buf[PATH_MAX];
68          FILE  *input;
69          int  xres, yres;
70 <        COLOR  scanline[NCOLS];
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_F, 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          }
100 <        if (xres > NCOLS || yres > NROWS) {
100 >        if (xres > NCOLS) {
101                  fprintf(stderr, "%s: resolution mismatch\n", fname);
102                  return(-1);
103          }
# Line 70 | Line 105 | char  *fname;
105          fputs("\0333\042", stdout);
106                                  /* put out scanlines */
107          for (i = yres-1; i >= 0; i--) {
108 <                if (freadscan(scanline, xres, input) < 0) {
108 >                if (freadcolrs(scanline, xres, input) < 0) {
109                          fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
110                          return(-1);
111                  }
112 +                normcolrs(scanline, xres, 0);
113                  plotscan(scanline, xres, i);
114          }
115                                  /* advance page */
116          putchar('\f');
117          
118 <        fclose(input);
118 >        if (dofilter)
119 >                pclose(input);
120 >        else
121 >                fclose(input);
122  
123          return(0);
124   }
125  
126  
127 < plotscan(scan, len, y)                  /* plot a scanline */
128 < COLOR  scan[];
129 < int  len;
130 < int  y;
127 > static void
128 > plotscan(                       /* plot a scanline */
129 >        COLR  scan[],
130 >        int  len,
131 >        int  y
132 > )
133   {
93        static long  pat[NCOLS][3];
134          int  bpos;
135          register long  c;
136          register int  i, j;
137  
138 <        if (bpos = y % 23) {
138 >        if ( (bpos = y % 23) ) {
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 >                return;
144 >        }
145 >        fputs("\033\031", stdout);
146  
147 <        } else {
148 <
149 <                fputs("\033\031", stdout);
150 <
151 <                for (j = 0; j < 3; j++) {
152 <                        fputs("\033%O", stdout);
153 <                        putchar(len & 255);
154 <                        putchar(len >> 8);
155 <                        for (i = 0; i < len; i++) {
113 <                                if (y!=0 & i+j) {       /* knit bit */
114 <                                        c = pat[i][j];
115 <                                        pat[i][j] = colbit(scan[i],i,j) << 23;
116 <                                } else {
117 <                                        c = pat[i][j] | colbit(scan[i],i,j);
118 <                                        pat[i][j] = 0;
119 <                                }
120 <                                putchar(c>>16);
121 <                                putchar(c>>8 & 255);
122 <                                putchar(c & 255);
123 <                        }
124 <                        putchar('\r');
147 >        for (j = 0; j < 3; j++) {
148 >                i = (NCOLS + len)/2;            /* center image */
149 >                fputs("\033%O", stdout);
150 >                putchar(i & 255);
151 >                putchar(i >> 8);
152 >                while (i-- > len) {
153 >                        putchar(0);
154 >                        putchar(0);
155 >                        putchar(0);
156                  }
157 <                putchar('\n');
157 >                for (i = 0; i < len; i++) {
158 >                        c = lpat[i][j] | colbit(scan[i],i,j);
159 >                        putchar((int)(c>>16));
160 >                        putchar((int)(c>>8 & 255));
161 >                        putchar((int)(c & 255));
162 >                        if (y)                  /* repeat this row */
163 >                                lpat[i][j] = (c & 1) << 23;
164 >                        else                    /* or clear for next image */
165 >                                lpat[i][j] = 0L;
166 >                }
167 >                putchar('\r');
168          }
169 +        putchar('\n');
170 +        fflush(stdout);
171   }
172  
173  
174 < colbit(col, x, s)               /* determine bit value for primary at x */
175 < COLOR  col;
176 < register int  x;
177 < int  s;
174 > static int
175 > colbit(         /* determine bit value for primary at x */
176 >        COLR  col,
177 >        register int  x,
178 >        int  s
179 > )
180   {
181 <        static float  cerr[NCOLS][3];
182 <        static double  err[3];
183 <        double  b;
181 >        static int  cerr[NCOLS][3];
182 >        static int  err[3];
183 >        int  b, errp;
184          register int  a, ison;
185  
186          a = sub_add(s);                 /* use additive primary */
187 <        b = colval(col,a);
188 <        if (b > 1.0) b = 1.0;
187 >        b = col[a];
188 >        errp = err[a];
189          err[a] += b + cerr[x][a];
190 <        ison = err[a] < 0.5;
191 <        if (!ison) err[a] -= 1.0;
192 <        cerr[x][a] = err[a] *= 0.5;
190 >        ison = err[a] < 128;
191 >        if (!ison) err[a] -= 256;
192 >        err[a] /= 3;
193 >        cerr[x][a] = err[a] + errp;
194          return(ison);
195   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines