ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ttyimage.c
(Generate patch)

Comparing ray/src/px/ttyimage.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:49:42 1989 UTC vs.
Revision 1.7 by greg, Thu Apr 18 14:35:47 1991 UTC

# Line 17 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17  
18   #define  NCOLS          133
19  
20 char  shadech[] = " .,:;+?%&*$@#";
20  
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
21   main(argc, argv)
22   int  argc;
23   char  **argv;
24   {
25          FILE  *input;
26          int  xres, yres;
27 <        COLOR  scanline[NCOLS];
37 <        char  sbuf[256];
27 >        COLR  scanline[NCOLS];
28          register int  i, j;
29          
40        progname = argv[0];
41
30          if (argc < 2)
31                  input = stdin;
32          else if ((input = fopen(argv[1], "r")) == NULL) {
33 <                fprintf(stderr, "%s: can't open file \"%s\"\n", progname, argv[1]);
33 >                fprintf(stderr, "%s: can't open file \"%s\"\n", argv[0], argv[1]);
34                  exit(1);
35          }
36          
49                                /* discard header */
50        while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n')
51                ;
37                                  /* get picture dimensions */
38 <        if (fgets(sbuf, sizeof(sbuf), input) == NULL ||
39 <                        sscanf(sbuf, "-Y %d +X %d\n", &yres, &xres) != 2) {
40 <                fprintf(stderr, "%s: bad picture size\n", progname);
38 >        if (checkheader(input, COLRFMT, NULL) < 0 ||
39 >                        fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
40 >                fprintf(stderr, "%s: bad picture format\n", argv[0]);
41                  exit(1);
42          }
43          if (xres > NCOLS) {
44 <                fprintf(stderr, "%s: resolution mismatch\n", progname);
44 >                fprintf(stderr, "%s: resolution mismatch\n", argv[0]);
45                  exit(1);
46          }
47          
48          for (i = 0; i < yres; i++) {
49 <                if (freadscan(scanline, xres, input) < 0) {
50 <                        fprintf(stderr, "%s: read error\n", progname);
49 >                if (freadcolrs(scanline, xres, input) < 0) {
50 >                        fprintf(stderr, "%s: read error\n", argv[0]);
51                          exit(1);
52                  }
53 +                normcolrs(scanline, xres, 0);
54                  for (j = 0; j < xres; j++)
55 <                        putchar(shadech[shade(scanline[j])]);
55 >                        putchar(shade(scanline[j]));
56                  putchar('\n');
57          }
58  
59          exit(0);
60 + }
61 +
62 +
63 + int
64 + shade(clr)                      /* return character for color */
65 + COLR  clr;
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   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines