ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ttyimage.c
Revision: 1.8
Committed: Mon Nov 11 14:01:29 1991 UTC (32 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.7: +3 -2 lines
Log Message:
Improved handling of scanline ordering

File Contents

# User Rev Content
1 greg 1.8 /* Copyright (c) 1991 Regents of the University of California */
2 greg 1.1
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 greg 1.8 #include "resolu.h"
17 greg 1.1
18    
19     #define NCOLS 133
20    
21    
22     main(argc, argv)
23     int argc;
24     char **argv;
25     {
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    
38     /* 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     int
65     shade(clr) /* return character for color */
66     COLR clr;
67     {
68     #define NSHADES 13
69    
70     static char shadech[NSHADES+1] = " .,:;+?%&*$@#";
71    
72 greg 1.4 return(shadech[normbright(clr)*NSHADES/256]);
73 greg 1.3
74     #undef NSHADES
75 greg 1.1 }