ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/paintjet.c
Revision: 2.6
Committed: Sun Mar 28 20:33:14 2004 UTC (20 years, 1 month ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6P1, rad3R6
Changes since 2.5: +26 -14 lines
Log Message:
Continued ANSIfication, and other fixes and clarifications.

File Contents

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