ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/paintjet.c
Revision: 2.4
Committed: Sat Feb 22 02:07:27 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.3: +2 -4 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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