ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/paintjet.c
Revision: 1.4
Committed: Fri Jan 26 08:17:34 1990 UTC (34 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +1 -1 lines
Log Message:
added scale factor to normcolrs()

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1989 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * paintjet.c - program to dump pixel file to HP PaintJet color printer.
9     *
10     * 10/6/89
11     */
12    
13     #include <stdio.h>
14    
15     #include "color.h"
16    
17     #define NCOLS 1440 /* 8" at 180 dpi */
18    
19    
20     main(argc, argv)
21     int argc;
22     char *argv[];
23     {
24     int i, status = 0;
25    
26     if (argc < 2)
27     status = printp(NULL) == -1;
28     else
29     for (i = 1; i < argc; i++)
30     status += printp(argv[i]) == -1;
31     exit(status);
32     }
33    
34    
35     printp(fname) /* print a picture */
36     char *fname;
37     {
38     FILE *input;
39     int xres, yres;
40 greg 1.2 COLR scanline[NCOLS];
41 greg 1.1 int i;
42    
43     if (fname == NULL) {
44     input = stdin;
45     fname = "<stdin>";
46     } else if ((input = fopen(fname, "r")) == NULL) {
47     fprintf(stderr, "%s: cannot open\n", fname);
48     return(-1);
49     }
50     /* discard header */
51     getheader(input, NULL);
52     /* get picture dimensions */
53     if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
54     fprintf(stderr, "%s: bad picture size\n", fname);
55     return(-1);
56     }
57     if (xres > NCOLS) {
58     fprintf(stderr, "%s: resolution mismatch\n", fname);
59     return(-1);
60     }
61     /*
62     * Set 180 dpi, 3 planes, left margin and width.
63     */
64     printf("\033*t180R\033*r3U\033&a%dH\033*r%dS\033*r1A",
65     ((NCOLS-xres)>>4)<<5, xres);
66    
67     for (i = yres-1; i >= 0; i--) {
68 greg 1.2 if (freadcolrs(scanline, xres, input) < 0)
69 greg 1.1 return(-1);
70 greg 1.4 normcolrs(scanline, xres, 0);
71 greg 1.1 plotscan(scanline, xres, i);
72     }
73    
74     printf("\033*r0B\f");
75    
76     fclose(input);
77    
78     return(0);
79 greg 1.2 }
80    
81    
82 greg 1.1 plotscan(scan, len, y) /* plot a scanline */
83 greg 1.2 COLR scan[];
84 greg 1.1 int len;
85     int y;
86     {
87     int c;
88     register int x, b;
89    
90     for (c = 0; c < 3; c++) {
91     printf("\033*b%d%c", (len+7)>>3, c<2 ? 'V' : 'W');
92     b = 0;
93     for (x = 0; x < len; x++) {
94     b = b<<1 | colbit(scan[x], x, c);
95     if ((x&7) == 7) {
96     putc(b, stdout);
97     b = 0;
98     }
99     }
100     if (x & 7)
101     putc(b, stdout);
102     }
103     }
104    
105    
106     colbit(col, x, a) /* determine bit value for primary at x */
107 greg 1.2 COLR col;
108 greg 1.1 register int x;
109     register int a;
110     {
111 greg 1.2 static int cerr[NCOLS][3];
112     static int err[3];
113     int b;
114 greg 1.1 register int ison;
115    
116 greg 1.2 b = col[a];
117 greg 1.1 err[a] += b + cerr[x][a];
118 greg 1.2 ison = err[a] > 128;
119     if (ison) err[a] -= 256;
120     cerr[x][a] = err[a] /= 2;
121 greg 1.1 return(ison);
122     }