ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ttyimage.c
Revision: 1.1
Committed: Thu Feb 2 10:49:42 1989 UTC (35 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# Content
1 /* Copyright (c) 1986 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * ttyimage.c - program to dump pixel file to dumb terminal.
9 *
10 * 8/15/85
11 */
12
13 #include <stdio.h>
14
15 #include "color.h"
16
17
18 #define NCOLS 133
19
20 char shadech[] = " .,:;+?%&*$@#";
21
22 #define NSHADES (sizeof(shadech)-1)
23
24 #define shade(col) ( bright(col)>=1.0 ? NSHADES-1 : \
25 (int)(bright(col)*NSHADES) )
26
27 char *progname;
28
29
30 main(argc, argv)
31 int argc;
32 char **argv;
33 {
34 FILE *input;
35 int xres, yres;
36 COLOR scanline[NCOLS];
37 char sbuf[256];
38 register int i, j;
39
40 progname = argv[0];
41
42 if (argc < 2)
43 input = stdin;
44 else if ((input = fopen(argv[1], "r")) == NULL) {
45 fprintf(stderr, "%s: can't open file \"%s\"\n", progname, argv[1]);
46 exit(1);
47 }
48
49 /* discard header */
50 while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n')
51 ;
52 /* get picture dimensions */
53 if (fgets(sbuf, sizeof(sbuf), input) == NULL ||
54 sscanf(sbuf, "-Y %d +X %d\n", &yres, &xres) != 2) {
55 fprintf(stderr, "%s: bad picture size\n", progname);
56 exit(1);
57 }
58 if (xres > NCOLS) {
59 fprintf(stderr, "%s: resolution mismatch\n", progname);
60 exit(1);
61 }
62
63 for (i = 0; i < yres; i++) {
64 if (freadscan(scanline, xres, input) < 0) {
65 fprintf(stderr, "%s: read error\n", progname);
66 exit(1);
67 }
68 for (j = 0; j < xres; j++)
69 putchar(shadech[shade(scanline[j])]);
70 putchar('\n');
71 }
72
73 exit(0);
74 }