| 1 |
greg |
1.1 |
#ifndef lint |
| 2 |
schorsch |
2.4 |
static const char RCSid[] = "$Id: ttyimage.c,v 2.3 2003/02/22 02:07:28 greg Exp $"; |
| 3 |
greg |
1.1 |
#endif |
| 4 |
|
|
/* |
| 5 |
|
|
* ttyimage.c - program to dump pixel file to dumb terminal. |
| 6 |
|
|
* |
| 7 |
|
|
* 8/15/85 |
| 8 |
|
|
*/ |
| 9 |
|
|
|
| 10 |
|
|
#include <stdio.h> |
| 11 |
greg |
2.3 |
#include <time.h> |
| 12 |
greg |
1.1 |
|
| 13 |
schorsch |
2.4 |
#include "platform.h" |
| 14 |
greg |
1.1 |
#include "color.h" |
| 15 |
greg |
1.8 |
#include "resolu.h" |
| 16 |
greg |
1.1 |
|
| 17 |
|
|
|
| 18 |
greg |
2.2 |
#define NCOLS 133 |
| 19 |
greg |
1.1 |
|
| 20 |
|
|
|
| 21 |
|
|
main(argc, argv) |
| 22 |
|
|
int argc; |
| 23 |
|
|
char **argv; |
| 24 |
|
|
{ |
| 25 |
|
|
FILE *input; |
| 26 |
|
|
int xres, yres; |
| 27 |
greg |
1.3 |
COLR scanline[NCOLS]; |
| 28 |
greg |
1.1 |
register int i, j; |
| 29 |
|
|
|
| 30 |
|
|
if (argc < 2) |
| 31 |
|
|
input = stdin; |
| 32 |
|
|
else if ((input = fopen(argv[1], "r")) == NULL) { |
| 33 |
greg |
1.3 |
fprintf(stderr, "%s: can't open file \"%s\"\n", argv[0], argv[1]); |
| 34 |
greg |
1.1 |
exit(1); |
| 35 |
|
|
} |
| 36 |
schorsch |
2.4 |
SET_FILE_BINARY(input); |
| 37 |
greg |
1.1 |
/* get picture dimensions */ |
| 38 |
greg |
1.7 |
if (checkheader(input, COLRFMT, NULL) < 0 || |
| 39 |
greg |
1.8 |
fgetresolu(&xres, &yres, input) < 0) { |
| 40 |
greg |
1.7 |
fprintf(stderr, "%s: bad picture format\n", argv[0]); |
| 41 |
greg |
1.1 |
exit(1); |
| 42 |
|
|
} |
| 43 |
|
|
if (xres > NCOLS) { |
| 44 |
greg |
1.3 |
fprintf(stderr, "%s: resolution mismatch\n", argv[0]); |
| 45 |
greg |
1.1 |
exit(1); |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
for (i = 0; i < yres; i++) { |
| 49 |
greg |
1.3 |
if (freadcolrs(scanline, xres, input) < 0) { |
| 50 |
|
|
fprintf(stderr, "%s: read error\n", argv[0]); |
| 51 |
greg |
1.1 |
exit(1); |
| 52 |
|
|
} |
| 53 |
greg |
1.6 |
normcolrs(scanline, xres, 0); |
| 54 |
greg |
1.1 |
for (j = 0; j < xres; j++) |
| 55 |
greg |
1.3 |
putchar(shade(scanline[j])); |
| 56 |
greg |
1.1 |
putchar('\n'); |
| 57 |
|
|
} |
| 58 |
|
|
|
| 59 |
|
|
exit(0); |
| 60 |
greg |
1.3 |
} |
| 61 |
|
|
|
| 62 |
|
|
|
| 63 |
|
|
int |
| 64 |
|
|
shade(clr) /* return character for color */ |
| 65 |
|
|
COLR clr; |
| 66 |
|
|
{ |
| 67 |
greg |
2.2 |
#define NSHADES 13 |
| 68 |
greg |
1.3 |
|
| 69 |
|
|
static char shadech[NSHADES+1] = " .,:;+?%&*$@#"; |
| 70 |
|
|
|
| 71 |
greg |
1.4 |
return(shadech[normbright(clr)*NSHADES/256]); |
| 72 |
greg |
1.3 |
|
| 73 |
|
|
#undef NSHADES |
| 74 |
greg |
1.1 |
} |