1 |
– |
/* Copyright (c) 1986 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* ttyimage.c - program to dump pixel file to dumb terminal. |
6 |
|
* |
8 |
|
*/ |
9 |
|
|
10 |
|
#include <stdio.h> |
11 |
+ |
#ifdef MSDOS |
12 |
+ |
#include <fcntl.h> |
13 |
+ |
#endif |
14 |
+ |
#include <time.h> |
15 |
|
|
16 |
|
#include "color.h" |
17 |
+ |
#include "resolu.h" |
18 |
|
|
19 |
|
|
20 |
< |
#define NCOLS 133 |
20 |
> |
#define NCOLS 133 |
21 |
|
|
22 |
|
|
23 |
|
main(argc, argv) |
27 |
|
FILE *input; |
28 |
|
int xres, yres; |
29 |
|
COLR scanline[NCOLS]; |
28 |
– |
char sbuf[256]; |
30 |
|
register int i, j; |
31 |
|
|
32 |
|
if (argc < 2) |
35 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", argv[0], argv[1]); |
36 |
|
exit(1); |
37 |
|
} |
38 |
< |
|
39 |
< |
/* discard header */ |
40 |
< |
while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n') |
40 |
< |
; |
38 |
> |
#ifdef MSDOS |
39 |
> |
setmode(fileno(input), O_BINARY); |
40 |
> |
#endif |
41 |
|
/* get picture dimensions */ |
42 |
< |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
43 |
< |
fprintf(stderr, "%s: bad picture size\n", argv[0]); |
42 |
> |
if (checkheader(input, COLRFMT, NULL) < 0 || |
43 |
> |
fgetresolu(&xres, &yres, input) < 0) { |
44 |
> |
fprintf(stderr, "%s: bad picture format\n", argv[0]); |
45 |
|
exit(1); |
46 |
|
} |
47 |
|
if (xres > NCOLS) { |
54 |
|
fprintf(stderr, "%s: read error\n", argv[0]); |
55 |
|
exit(1); |
56 |
|
} |
57 |
+ |
normcolrs(scanline, xres, 0); |
58 |
|
for (j = 0; j < xres; j++) |
59 |
|
putchar(shade(scanline[j])); |
60 |
|
putchar('\n'); |
68 |
|
shade(clr) /* return character for color */ |
69 |
|
COLR clr; |
70 |
|
{ |
71 |
< |
#define NSHADES 13 |
71 |
> |
#define NSHADES 13 |
72 |
|
|
73 |
|
static char shadech[NSHADES+1] = " .,:;+?%&*$@#"; |
72 |
– |
COLR nclr; |
73 |
– |
register int b; |
74 |
|
|
75 |
< |
colr_norm(clr, nclr); |
76 |
< |
b = norm_bright(nclr); |
77 |
< |
b = b*NSHADES/256; |
78 |
< |
return(shadech[b]); |
75 |
> |
return(shadech[normbright(clr)*NSHADES/256]); |
76 |
|
|
77 |
|
#undef NSHADES |
78 |
|
} |