| 1 |
greg |
1.1 |
/* Copyright (c) 1986 Regents of the University of California */
|
| 2 |
|
|
|
| 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 |
|
|
|
| 17 |
|
|
#define NCOLS 880 /* for wide carriage */
|
| 18 |
|
|
|
| 19 |
|
|
|
| 20 |
|
|
main(argc, argv)
|
| 21 |
|
|
int argc;
|
| 22 |
|
|
char *argv[];
|
| 23 |
|
|
{
|
| 24 |
|
|
int i;
|
| 25 |
|
|
int status = 0;
|
| 26 |
|
|
|
| 27 |
|
|
if (argc < 2)
|
| 28 |
|
|
status += printp(NULL) == -1;
|
| 29 |
|
|
else
|
| 30 |
|
|
for (i = 1; i < argc; i++)
|
| 31 |
|
|
status += printp(argv[i]) == -1;
|
| 32 |
|
|
exit(status);
|
| 33 |
|
|
}
|
| 34 |
|
|
|
| 35 |
|
|
|
| 36 |
|
|
printp(fname) /* print a picture */
|
| 37 |
|
|
char *fname;
|
| 38 |
|
|
{
|
| 39 |
|
|
FILE *input;
|
| 40 |
|
|
int xres, yres;
|
| 41 |
|
|
COLOR scanline[NCOLS];
|
| 42 |
|
|
char sbuf[256];
|
| 43 |
|
|
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 |
|
|
while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n')
|
| 54 |
|
|
;
|
| 55 |
|
|
/* get picture dimensions */
|
| 56 |
greg |
1.2 |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
|
| 57 |
greg |
1.1 |
fprintf(stderr, "%s: bad picture size\n", fname);
|
| 58 |
|
|
return(-1);
|
| 59 |
|
|
}
|
| 60 |
|
|
if (xres > NCOLS) {
|
| 61 |
|
|
fprintf(stderr, "%s: resolution mismatch\n", fname);
|
| 62 |
|
|
return(-1);
|
| 63 |
|
|
}
|
| 64 |
|
|
|
| 65 |
|
|
fputs("\033[6~\033[7z", stdout);
|
| 66 |
|
|
|
| 67 |
|
|
for (i = yres-1; i >= 0; i--) {
|
| 68 |
|
|
if (freadscan(scanline, xres, input) < 0) {
|
| 69 |
|
|
fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
|
| 70 |
|
|
return(-1);
|
| 71 |
|
|
}
|
| 72 |
|
|
plotscan(scanline, xres, i);
|
| 73 |
|
|
}
|
| 74 |
|
|
|
| 75 |
|
|
fputs("\f\033[6~", stdout);
|
| 76 |
|
|
|
| 77 |
|
|
fclose(input);
|
| 78 |
|
|
|
| 79 |
|
|
return(0);
|
| 80 |
|
|
}
|
| 81 |
|
|
|
| 82 |
|
|
|
| 83 |
|
|
plotscan(scan, len, y) /* plot a scanline */
|
| 84 |
|
|
COLOR scan[];
|
| 85 |
|
|
int len;
|
| 86 |
|
|
int y;
|
| 87 |
|
|
{
|
| 88 |
|
|
static BYTE pat[NCOLS];
|
| 89 |
|
|
int bpos;
|
| 90 |
|
|
register int i;
|
| 91 |
|
|
|
| 92 |
|
|
if (bpos = y & 7) {
|
| 93 |
|
|
|
| 94 |
|
|
for (i = 0; i < len; i++)
|
| 95 |
|
|
pat[i] |= bit(scan[i], i) << bpos;
|
| 96 |
|
|
|
| 97 |
|
|
} else {
|
| 98 |
|
|
|
| 99 |
|
|
fputs("\033%5", stdout);
|
| 100 |
|
|
putchar(len & 255);
|
| 101 |
|
|
putchar(len >> 8);
|
| 102 |
|
|
|
| 103 |
|
|
for (i = 0; i < len; i++) {
|
| 104 |
|
|
pat[i] |= bit(scan[i], i);
|
| 105 |
|
|
putchar(pat[i]);
|
| 106 |
|
|
pat[i] = 0;
|
| 107 |
|
|
}
|
| 108 |
|
|
putchar('\r');
|
| 109 |
|
|
putchar('\n');
|
| 110 |
|
|
}
|
| 111 |
|
|
}
|
| 112 |
|
|
|
| 113 |
|
|
|
| 114 |
|
|
bit(col, x) /* return bit for color at x */
|
| 115 |
|
|
COLOR col;
|
| 116 |
|
|
register int x;
|
| 117 |
|
|
{
|
| 118 |
|
|
static float cerr[NCOLS];
|
| 119 |
|
|
static double err;
|
| 120 |
|
|
double b;
|
| 121 |
|
|
register int isblack;
|
| 122 |
|
|
|
| 123 |
|
|
b = bright(col);
|
| 124 |
|
|
if (b > 1.0) b = 1.0;
|
| 125 |
|
|
err += b + cerr[x];
|
| 126 |
|
|
isblack = err < 0.5;
|
| 127 |
|
|
if (!isblack) err -= 1.0;
|
| 128 |
|
|
cerr[x] = err *= 0.5;
|
| 129 |
|
|
return(isblack);
|
| 130 |
|
|
}
|