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