ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/paintjet.c
Revision: 1.2
Committed: Fri Oct 20 16:44:37 1989 UTC (34 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +23 -12 lines
Log Message:
eliminated unnecessary use of floating point color

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 getheader(input, NULL);
52 /* get picture dimensions */
53 if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
54 fprintf(stderr, "%s: bad picture size\n", fname);
55 return(-1);
56 }
57 if (xres > NCOLS) {
58 fprintf(stderr, "%s: resolution mismatch\n", fname);
59 return(-1);
60 }
61 /*
62 * Set 180 dpi, 3 planes, left margin and width.
63 */
64 printf("\033*t180R\033*r3U\033&a%dH\033*r%dS\033*r1A",
65 ((NCOLS-xres)>>4)<<5, xres);
66
67 for (i = yres-1; i >= 0; i--) {
68 if (freadcolrs(scanline, xres, input) < 0)
69 return(-1);
70 normscan(scanline, xres);
71 plotscan(scanline, xres, i);
72 }
73
74 printf("\033*r0B\f");
75
76 fclose(input);
77
78 return(0);
79 }
80
81
82 normscan(scan, len) /* normalize a scanline */
83 register COLR scan[];
84 int len;
85 {
86 register int i;
87
88 for (i = 0; i < len; i++)
89 colr_norm(scan[i], scan[i]);
90 }
91
92
93 plotscan(scan, len, y) /* plot a scanline */
94 COLR scan[];
95 int len;
96 int y;
97 {
98 int c;
99 register int x, b;
100
101 for (c = 0; c < 3; c++) {
102 printf("\033*b%d%c", (len+7)>>3, c<2 ? 'V' : 'W');
103 b = 0;
104 for (x = 0; x < len; x++) {
105 b = b<<1 | colbit(scan[x], x, c);
106 if ((x&7) == 7) {
107 putc(b, stdout);
108 b = 0;
109 }
110 }
111 if (x & 7)
112 putc(b, stdout);
113 }
114 }
115
116
117 colbit(col, x, a) /* determine bit value for primary at x */
118 COLR col;
119 register int x;
120 register int a;
121 {
122 static int cerr[NCOLS][3];
123 static int err[3];
124 int b;
125 register int ison;
126
127 b = col[a];
128 err[a] += b + cerr[x][a];
129 ison = err[a] > 128;
130 if (ison) err[a] -= 256;
131 cerr[x][a] = err[a] /= 2;
132 return(ison);
133 }