| 1 |
greg |
1.9 |
/* Copyright (c) 1991 Regents of the University of California */ |
| 2 |
greg |
1.1 |
|
| 3 |
|
|
#ifndef lint |
| 4 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
| 5 |
|
|
#endif |
| 6 |
|
|
|
| 7 |
|
|
/* |
| 8 |
|
|
* mt160r.c - program to dump pixel file to Mannesman-Tally 160. |
| 9 |
|
|
* |
| 10 |
|
|
* 8/16/85 |
| 11 |
|
|
*/ |
| 12 |
|
|
|
| 13 |
|
|
#include <stdio.h> |
| 14 |
|
|
|
| 15 |
|
|
#include "color.h" |
| 16 |
greg |
1.9 |
#include "resolu.h" |
| 17 |
greg |
1.1 |
|
| 18 |
|
|
#define NCOLS 880 /* for wide carriage */ |
| 19 |
|
|
|
| 20 |
|
|
|
| 21 |
|
|
main(argc, argv) |
| 22 |
|
|
int argc; |
| 23 |
|
|
char *argv[]; |
| 24 |
|
|
{ |
| 25 |
|
|
int i; |
| 26 |
|
|
int status = 0; |
| 27 |
|
|
|
| 28 |
|
|
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.3 |
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.7 |
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.9 |
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 |
|
|
fputs("\033[6~\033[7z", stdout); |
| 68 |
greg |
2.3 |
#ifdef _IOLBF |
| 69 |
|
|
stdout->_flag &= ~_IOLBF; |
| 70 |
|
|
#endif |
| 71 |
greg |
1.1 |
|
| 72 |
|
|
for (i = yres-1; i >= 0; i--) { |
| 73 |
greg |
1.3 |
if (freadcolrs(scanline, xres, input) < 0) { |
| 74 |
greg |
1.1 |
fprintf(stderr, "%s: read error (y=%d)\n", fname, i); |
| 75 |
|
|
return(-1); |
| 76 |
|
|
} |
| 77 |
greg |
1.6 |
normcolrs(scanline, xres, 0); |
| 78 |
greg |
1.1 |
plotscan(scanline, xres, i); |
| 79 |
|
|
} |
| 80 |
|
|
|
| 81 |
|
|
fputs("\f\033[6~", stdout); |
| 82 |
|
|
|
| 83 |
|
|
fclose(input); |
| 84 |
|
|
|
| 85 |
|
|
return(0); |
| 86 |
|
|
} |
| 87 |
|
|
|
| 88 |
|
|
|
| 89 |
|
|
plotscan(scan, len, y) /* plot a scanline */ |
| 90 |
greg |
1.3 |
COLR scan[]; |
| 91 |
greg |
1.1 |
int len; |
| 92 |
|
|
int y; |
| 93 |
|
|
{ |
| 94 |
|
|
static BYTE pat[NCOLS]; |
| 95 |
|
|
int bpos; |
| 96 |
|
|
register int i; |
| 97 |
|
|
|
| 98 |
|
|
if (bpos = y & 7) { |
| 99 |
|
|
|
| 100 |
|
|
for (i = 0; i < len; i++) |
| 101 |
|
|
pat[i] |= bit(scan[i], i) << bpos; |
| 102 |
|
|
|
| 103 |
|
|
} else { |
| 104 |
|
|
|
| 105 |
|
|
fputs("\033%5", stdout); |
| 106 |
|
|
putchar(len & 255); |
| 107 |
|
|
putchar(len >> 8); |
| 108 |
|
|
|
| 109 |
|
|
for (i = 0; i < len; i++) { |
| 110 |
|
|
pat[i] |= bit(scan[i], i); |
| 111 |
|
|
putchar(pat[i]); |
| 112 |
|
|
pat[i] = 0; |
| 113 |
|
|
} |
| 114 |
|
|
putchar('\r'); |
| 115 |
|
|
putchar('\n'); |
| 116 |
greg |
2.3 |
fflush(stdout); |
| 117 |
greg |
1.1 |
} |
| 118 |
|
|
} |
| 119 |
|
|
|
| 120 |
|
|
|
| 121 |
greg |
1.3 |
bit(clr, x) /* return bit for color at x */ |
| 122 |
|
|
COLR clr; |
| 123 |
greg |
1.1 |
register int x; |
| 124 |
|
|
{ |
| 125 |
greg |
1.3 |
static int cerr[NCOLS]; |
| 126 |
greg |
2.2 |
static int err; |
| 127 |
|
|
int b, errp; |
| 128 |
greg |
1.1 |
register int isblack; |
| 129 |
|
|
|
| 130 |
greg |
1.4 |
b = normbright(clr); |
| 131 |
greg |
1.8 |
errp = err; |
| 132 |
greg |
1.1 |
err += b + cerr[x]; |
| 133 |
greg |
1.3 |
isblack = err < 128; |
| 134 |
|
|
if (!isblack) err -= 256; |
| 135 |
greg |
1.8 |
err /= 3; |
| 136 |
|
|
cerr[x] = err + errp; |
| 137 |
greg |
1.1 |
return(isblack); |
| 138 |
|
|
} |