ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ttyimage.c
Revision: 2.6
Committed: Fri Jul 19 17:37:56 2019 UTC (4 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R3, HEAD
Changes since 2.5: +2 -4 lines
Log Message:
Moved declarations and definitions for header.c from resolu.h to rtio.h

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: ttyimage.c,v 2.5 2004/03/28 20:33:14 schorsch Exp $";
3 #endif
4 /*
5 * ttyimage.c - program to dump pixel file to dumb terminal.
6 *
7 * 8/15/85
8 */
9
10 #include "rtio.h"
11 #include "platform.h"
12 #include "color.h"
13 #include "resolu.h"
14
15
16 #define NCOLS 133
17
18 static int shade(COLR clr);
19
20
21 int
22 main(int argc, char **argv)
23 {
24 FILE *input;
25 int xres, yres;
26 COLR scanline[NCOLS];
27 register int i, j;
28
29 if (argc < 2)
30 input = stdin;
31 else if ((input = fopen(argv[1], "r")) == NULL) {
32 fprintf(stderr, "%s: can't open file \"%s\"\n", argv[0], argv[1]);
33 exit(1);
34 }
35 SET_FILE_BINARY(input);
36 /* get picture dimensions */
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) {
43 fprintf(stderr, "%s: resolution mismatch\n", argv[0]);
44 exit(1);
45 }
46
47 for (i = 0; i < yres; i++) {
48 if (freadcolrs(scanline, xres, input) < 0) {
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');
56 }
57
58 exit(0);
59 }
60
61
62 static int
63 shade( /* return character for color */
64 COLR clr
65 )
66 {
67 #define NSHADES 13
68
69 static char shadech[NSHADES+1] = " .,:;+?%&*$@#";
70
71 return(shadech[normbright(clr)*NSHADES/256]);
72
73 #undef NSHADES
74 }