ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ttyimage.c
Revision: 2.5
Committed: Sun Mar 28 20:33:14 2004 UTC (20 years, 1 month ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R2, rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9, rad4R2P1
Changes since 2.4: +9 -7 lines
Log Message:
Continued ANSIfication, and other fixes and clarifications.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 2.5 static const char RCSid[] = "$Id: ttyimage.c,v 2.4 2003/06/05 19:29:34 schorsch 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 schorsch 2.5 static int shade(COLR clr);
21 greg 1.1
22 schorsch 2.5
23     int
24     main(int argc, char **argv)
25 greg 1.1 {
26     FILE *input;
27     int xres, yres;
28 greg 1.3 COLR scanline[NCOLS];
29 greg 1.1 register int i, j;
30    
31     if (argc < 2)
32     input = stdin;
33     else if ((input = fopen(argv[1], "r")) == NULL) {
34 greg 1.3 fprintf(stderr, "%s: can't open file \"%s\"\n", argv[0], argv[1]);
35 greg 1.1 exit(1);
36     }
37 schorsch 2.4 SET_FILE_BINARY(input);
38 greg 1.1 /* get picture dimensions */
39 greg 1.7 if (checkheader(input, COLRFMT, NULL) < 0 ||
40 greg 1.8 fgetresolu(&xres, &yres, input) < 0) {
41 greg 1.7 fprintf(stderr, "%s: bad picture format\n", argv[0]);
42 greg 1.1 exit(1);
43     }
44     if (xres > NCOLS) {
45 greg 1.3 fprintf(stderr, "%s: resolution mismatch\n", argv[0]);
46 greg 1.1 exit(1);
47     }
48    
49     for (i = 0; i < yres; i++) {
50 greg 1.3 if (freadcolrs(scanline, xres, input) < 0) {
51     fprintf(stderr, "%s: read error\n", argv[0]);
52 greg 1.1 exit(1);
53     }
54 greg 1.6 normcolrs(scanline, xres, 0);
55 greg 1.1 for (j = 0; j < xres; j++)
56 greg 1.3 putchar(shade(scanline[j]));
57 greg 1.1 putchar('\n');
58     }
59    
60     exit(0);
61 greg 1.3 }
62    
63    
64 schorsch 2.5 static int
65     shade( /* return character for color */
66     COLR clr
67     )
68 greg 1.3 {
69 greg 2.2 #define NSHADES 13
70 greg 1.3
71     static char shadech[NSHADES+1] = " .,:;+?%&*$@#";
72    
73 greg 1.4 return(shadech[normbright(clr)*NSHADES/256]);
74 greg 1.3
75     #undef NSHADES
76 greg 1.1 }