ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/paintjet.c
Revision: 2.2
Committed: Mon Dec 23 22:35:34 1991 UTC (32 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +4 -4 lines
Log Message:
removed unnecessary static declarations

File Contents

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