| 1 |
greg |
1.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 |
|
|
COLOR 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 (freadscan(scanline, xres, input) < 0) |
| 69 |
|
|
return(-1); |
| 70 |
|
|
plotscan(scanline, xres, i); |
| 71 |
|
|
} |
| 72 |
|
|
|
| 73 |
|
|
printf("\033*r0B\f"); |
| 74 |
|
|
|
| 75 |
|
|
fclose(input); |
| 76 |
|
|
|
| 77 |
|
|
return(0); |
| 78 |
|
|
} |
| 79 |
|
|
|
| 80 |
|
|
|
| 81 |
|
|
plotscan(scan, len, y) /* plot a scanline */ |
| 82 |
|
|
COLOR scan[]; |
| 83 |
|
|
int len; |
| 84 |
|
|
int y; |
| 85 |
|
|
{ |
| 86 |
|
|
int c; |
| 87 |
|
|
register int x, b; |
| 88 |
|
|
|
| 89 |
|
|
for (c = 0; c < 3; c++) { |
| 90 |
|
|
printf("\033*b%d%c", (len+7)>>3, c<2 ? 'V' : 'W'); |
| 91 |
|
|
b = 0; |
| 92 |
|
|
for (x = 0; x < len; x++) { |
| 93 |
|
|
b = b<<1 | colbit(scan[x], x, c); |
| 94 |
|
|
if ((x&7) == 7) { |
| 95 |
|
|
putc(b, stdout); |
| 96 |
|
|
b = 0; |
| 97 |
|
|
} |
| 98 |
|
|
} |
| 99 |
|
|
if (x & 7) |
| 100 |
|
|
putc(b, stdout); |
| 101 |
|
|
} |
| 102 |
|
|
} |
| 103 |
|
|
|
| 104 |
|
|
|
| 105 |
|
|
colbit(col, x, a) /* determine bit value for primary at x */ |
| 106 |
|
|
COLOR col; |
| 107 |
|
|
register int x; |
| 108 |
|
|
register int a; |
| 109 |
|
|
{ |
| 110 |
|
|
static float cerr[NCOLS][3]; |
| 111 |
|
|
static double err[3]; |
| 112 |
|
|
double b; |
| 113 |
|
|
register int ison; |
| 114 |
|
|
|
| 115 |
|
|
b = colval(col,a); |
| 116 |
|
|
if (b > 1.0) b = 1.0; |
| 117 |
|
|
err[a] += b + cerr[x][a]; |
| 118 |
|
|
ison = err[a] > 0.5; |
| 119 |
|
|
if (ison) err[a] -= 1.0; |
| 120 |
|
|
cerr[x][a] = err[a] *= 0.5; |
| 121 |
|
|
return(ison); |
| 122 |
|
|
} |