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.4 by greg, Fri Oct 20 12:07:08 1989 UTC vs.
Revision 2.9 by greg, Mon Sep 21 12:13:38 1992 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  
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 > #ifdef _IOLBF
55 >        stdout->_flag &= ~_IOLBF;
56 > #endif
57          if (argc < 2)
58                  status = printp(NULL) == -1;
59          else
# Line 43 | Line 66 | char  *argv[];
66   printp(fname)                           /* print a picture */
67   char  *fname;
68   {
69 +        char  buf[64];
70          FILE  *input;
71          int  xres, yres;
72 <        COLOR  scanline[NCOLS];
72 >        COLR  scanline[NCOLS];
73          int  i;
74  
75 <        if (fname == NULL) {
75 >        if (dofilter) {
76 >                if (fname == NULL) {
77 >                        sprintf(buf, FILTER, "");
78 >                        fname = "<stdin>";
79 >                } else
80 >                        sprintf(buf, FILTER, fname);
81 >                if ((input = popen(buf, "r")) == NULL) {
82 >                        fprintf(stderr, "Cannot execute: %s\n", buf);
83 >                        return(-1);
84 >                }
85 >        } else if (fname == NULL) {
86                  input = stdin;
87                  fname = "<stdin>";
88          } else if ((input = fopen(fname, "r")) == NULL) {
# Line 56 | Line 90 | char  *fname;
90                  return(-1);
91          }
92                                  /* discard header */
93 <        getheader(input, NULL);
93 >        if (checkheader(input, COLRFMT, NULL) < 0) {
94 >                fprintf(stderr, "%s: not a Radiance picture\n", fname);
95 >                return(-1);
96 >        }
97                                  /* get picture dimensions */
98 <        if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
98 >        if (fgetresolu(&xres, &yres, input) < 0) {
99                  fprintf(stderr, "%s: bad picture size\n", fname);
100                  return(-1);
101          }
102 <        if (xres > NCOLS || yres > NROWS) {
102 >        if (xres > NCOLS) {
103                  fprintf(stderr, "%s: resolution mismatch\n", fname);
104                  return(-1);
105          }
106                                  /* set line spacing (overlap for knitting) */
107 <        fputs("\0333\036", stdout);
107 >        fputs("\0333\042", stdout);
108                                  /* put out scanlines */
109          for (i = yres-1; i >= 0; i--) {
110 <                if (freadscan(scanline, xres, input) < 0) {
110 >                if (freadcolrs(scanline, xres, input) < 0) {
111                          fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
112                          return(-1);
113                  }
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  
129   plotscan(scan, len, y)                  /* plot a scanline */
130 < COLOR  scan[];
130 > COLR  scan[];
131   int  len;
132   int  y;
133   {
93        static long  pat[NCOLS][3];
134          int  bpos;
135          register long  c;
136          register int  i, j;
137  
138 <        if (bpos = y % 20) {
138 >        if (bpos = y % 23) {
139  
140 <                if (y > 20 & bpos < 4)                  /* knit bits */
141 <                        for (j = 0; j < 3; j++)
142 <                                for (i = 0; i < len; i++)
143 <                                        pat[i][j] |= (long)colbit(scan[i],i,j)
144 <                                                << (i+j & 4 ? bpos+24 : bpos);
145 <                else
106 <                        for (j = 0; j < 3; j++)
107 <                                for (i = 0; i < len; i++)
108 <                                        pat[i][j] |= (long)colbit(scan[i],i,j)
109 <                                                        << bpos;
140 >                for (j = 0; j < 3; j++)
141 >                        for (i = 0; i < len; i++)
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 & 0xff);
154 <                        putchar(len >> 8);
155 <                        for (i = 0; i < len; i++) {
120 <                                c = pat[i][j];
121 <                                pat[i][j] = c>>4 & 0xf00000;
122 <                                if (i+j & 4)            /* knit last bit */
123 <                                        pat[i][j] |= colbit(scan[i],i,j) << 20;
124 <                                else
125 <                                        c |= colbit(scan[i],i,j);
126 <                                putchar(c>>16 & 0xff);
127 <                                putchar(c>>8 & 0xff);
128 <                                putchar(c & 0xff);
129 <                        }
130 <                        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;
175 > COLR  col;
176   register int  x;
177   int  s;
178   {
179 <        static float  cerr[NCOLS][3];
180 <        static double  err[3];
181 <        double  b;
179 >        static int  cerr[NCOLS][3];
180 >        static int  err[3];
181 >        int  b, errp;
182          register int  a, ison;
183  
184          a = sub_add(s);                 /* use additive primary */
185 <        b = colval(col,a);
186 <        if (b > 1.0) b = 1.0;
185 >        b = col[a];
186 >        errp = err[a];
187          err[a] += b + cerr[x][a];
188 <        ison = err[a] < 0.5;
189 <        if (!ison) err[a] -= 1.0;
190 <        cerr[x][a] = err[a] *= 0.5;
188 >        ison = err[a] < 128;
189 >        if (!ison) err[a] -= 256;
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