ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/paintjet.c
Revision: 1.6
Committed: Mon May 6 13:14:26 1991 UTC (33 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.5: +4 -2 lines
Log Message:
improved dithering slightly

File Contents

# Content
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 COLR scanline[NCOLS];
41 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 if (checkheader(input, COLRFMT, NULL) < 0) {
52 fprintf(stderr, "%s: not a Radiance picture\n", fname);
53 return(-1);
54 }
55 /* 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 if (freadcolrs(scanline, xres, input) < 0)
72 return(-1);
73 normcolrs(scanline, xres, 0);
74 plotscan(scanline, xres, i);
75 }
76
77 printf("\033*r0B\f");
78
79 fclose(input);
80
81 return(0);
82 }
83
84
85 plotscan(scan, len, y) /* plot a scanline */
86 COLR scan[];
87 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 COLR col;
111 register int x;
112 register int a;
113 {
114 static int cerr[NCOLS][3];
115 static int err[3], errp[3];
116 int b;
117 register int ison;
118
119 b = col[a];
120 errp[a] = err[a];
121 err[a] += b + cerr[x][a];
122 ison = err[a] > 128;
123 if (ison) err[a] -= 256;
124 err[a] /= 3;
125 cerr[x][a] = err[a] + errp[a];
126 return(ison);
127 }