ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/paintjet.c
Revision: 1.7
Committed: Mon Nov 11 14:01:36 1991 UTC (32 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.6: +3 -2 lines
Log Message:
Improved handling of scanline ordering

File Contents

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