ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/paintjet.c
Revision: 1.5
Committed: Thu Apr 18 14:35:13 1991 UTC (33 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.4: +4 -1 lines
Log Message:
added format information to headers

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 greg 1.5 if (checkheader(input, COLRFMT, NULL) < 0) {
52     fprintf(stderr, "%s: not a Radiance picture\n", fname);
53     return(-1);
54     }
55 greg 1.1 /* get picture dimensions */
56     if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
57     fprintf(stderr, "%s: bad picture size\n", fname);
58     return(-1);
59     }
60     if (xres > NCOLS) {
61     fprintf(stderr, "%s: resolution mismatch\n", fname);
62     return(-1);
63     }
64     /*
65     * Set 180 dpi, 3 planes, left margin and width.
66     */
67     printf("\033*t180R\033*r3U\033&a%dH\033*r%dS\033*r1A",
68     ((NCOLS-xres)>>4)<<5, xres);
69    
70     for (i = yres-1; i >= 0; i--) {
71 greg 1.2 if (freadcolrs(scanline, xres, input) < 0)
72 greg 1.1 return(-1);
73 greg 1.4 normcolrs(scanline, xres, 0);
74 greg 1.1 plotscan(scanline, xres, i);
75     }
76    
77     printf("\033*r0B\f");
78    
79     fclose(input);
80    
81     return(0);
82 greg 1.2 }
83    
84    
85 greg 1.1 plotscan(scan, len, y) /* plot a scanline */
86 greg 1.2 COLR scan[];
87 greg 1.1 int len;
88     int y;
89     {
90     int c;
91     register int x, b;
92    
93     for (c = 0; c < 3; c++) {
94     printf("\033*b%d%c", (len+7)>>3, c<2 ? 'V' : 'W');
95     b = 0;
96     for (x = 0; x < len; x++) {
97     b = b<<1 | colbit(scan[x], x, c);
98     if ((x&7) == 7) {
99     putc(b, stdout);
100     b = 0;
101     }
102     }
103     if (x & 7)
104     putc(b, stdout);
105     }
106     }
107    
108    
109     colbit(col, x, a) /* determine bit value for primary at x */
110 greg 1.2 COLR col;
111 greg 1.1 register int x;
112     register int a;
113     {
114 greg 1.2 static int cerr[NCOLS][3];
115     static int err[3];
116     int b;
117 greg 1.1 register int ison;
118    
119 greg 1.2 b = col[a];
120 greg 1.1 err[a] += b + cerr[x][a];
121 greg 1.2 ison = err[a] > 128;
122     if (ison) err[a] -= 256;
123     cerr[x][a] = err[a] /= 2;
124 greg 1.1 return(ison);
125     }