ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/paintjet.c
Revision: 2.3
Committed: Mon Sep 21 12:13:43 1992 UTC (31 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +11 -3 lines
Log Message:
Changes for PC port

File Contents

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