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 |
|
* |
7 |
|
* 8/15/85 |
8 |
|
*/ |
9 |
|
|
10 |
< |
#include <stdio.h> |
11 |
< |
|
10 |
> |
#include "rtio.h" |
11 |
> |
#include "platform.h" |
12 |
|
#include "color.h" |
13 |
+ |
#include "resolu.h" |
14 |
|
|
15 |
|
|
16 |
< |
#define NCOLS 133 |
16 |
> |
#define NCOLS 133 |
17 |
|
|
18 |
+ |
static int shade(COLR clr); |
19 |
|
|
20 |
< |
main(argc, argv) |
21 |
< |
int argc; |
22 |
< |
char **argv; |
20 |
> |
|
21 |
> |
int |
22 |
> |
main(int argc, char **argv) |
23 |
|
{ |
24 |
|
FILE *input; |
25 |
|
int xres, yres; |
26 |
|
COLR scanline[NCOLS]; |
28 |
– |
char sbuf[256]; |
27 |
|
register int i, j; |
28 |
|
|
29 |
|
if (argc < 2) |
32 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", argv[0], argv[1]); |
33 |
|
exit(1); |
34 |
|
} |
35 |
< |
|
38 |
< |
/* discard header */ |
39 |
< |
while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n') |
40 |
< |
; |
35 |
> |
SET_FILE_BINARY(input); |
36 |
|
/* get picture dimensions */ |
37 |
< |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
38 |
< |
fprintf(stderr, "%s: bad picture size\n", argv[0]); |
37 |
> |
if (checkheader(input, COLRFMT, NULL) < 0 || |
38 |
> |
fgetresolu(&xres, &yres, input) < 0) { |
39 |
> |
fprintf(stderr, "%s: bad picture format\n", argv[0]); |
40 |
|
exit(1); |
41 |
|
} |
42 |
|
if (xres > NCOLS) { |
49 |
|
fprintf(stderr, "%s: read error\n", argv[0]); |
50 |
|
exit(1); |
51 |
|
} |
52 |
+ |
normcolrs(scanline, xres, 0); |
53 |
|
for (j = 0; j < xres; j++) |
54 |
|
putchar(shade(scanline[j])); |
55 |
|
putchar('\n'); |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
< |
int |
63 |
< |
shade(clr) /* return character for color */ |
64 |
< |
COLR clr; |
62 |
> |
static int |
63 |
> |
shade( /* return character for color */ |
64 |
> |
COLR clr |
65 |
> |
) |
66 |
|
{ |
67 |
< |
#define NSHADES 13 |
67 |
> |
#define NSHADES 13 |
68 |
|
|
69 |
|
static char shadech[NSHADES+1] = " .,:;+?%&*$@#"; |
72 |
– |
COLR nclr; |
73 |
– |
register int b; |
70 |
|
|
71 |
< |
colr_norm(clr, nclr); |
76 |
< |
b = norm_bright(nclr); |
77 |
< |
b = b*NSHADES/256; |
78 |
< |
return(shadech[b]); |
71 |
> |
return(shadech[normbright(clr)*NSHADES/256]); |
72 |
|
|
73 |
|
#undef NSHADES |
74 |
|
} |