ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ttyimage.c
Revision: 2.3
Committed: Sat Feb 22 02:07:28 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.2: +2 -4 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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